[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[glob2-devel] Progress at "Harvesting area brush" http://cofundos.org/pr
From: |
Leo Wandersleb |
Subject: |
[glob2-devel] Progress at "Harvesting area brush" http://cofundos.org/project.php?id=48 |
Date: |
Mon, 07 Jan 2008 01:35:52 +0100 |
User-agent: |
Mozilla-Thunderbird 2.0.0.9 (X11/20071230) |
Hi list,
as a reaction to my offer at cofundos, Eduardo Alberto Hernández Muñoz brought
up the attached diff what he describes as follows:
However, it might be of use for someone else who wants to give this a
shot to have what I have done so far, so I attached a patch. I think
that everything related to the GUI and map is done; all that should be
left is to make the workers go to where the harvest area is and do
their job.
I tried to follow the same style the rest of the code has (even if,
like I wrote up there, I don't like it), because I believe it's better
to have a bad style than inconsistencies. Also, I planned to read the
coding style for glob2 in the site, but since I didn't completed the
bounty, I didn't got to that point :p
If anyone uses that diff in "default", please add his name to the authors file.
Please let me know as else maybe i will look into it.
Greetings, Leo Wandersleb
--
Wer mir seinen Brief im verschlossenen Kuvert schicken möchte, kann das mit
diesem Schlüssel tun:
http://wiki.leowandersleb.de/index.php/Public_Key
diff -r 5a09e0253c6f data/gfx/area24.png
Binary file data/gfx/area24.png has changed
diff -r 5a09e0253c6f data/gfx/area25.png
Binary file data/gfx/area25.png has changed
diff -r 5a09e0253c6f data/gfx/area26.png
Binary file data/gfx/area26.png has changed
diff -r 5a09e0253c6f data/gfx/area27.png
Binary file data/gfx/area27.png has changed
diff -r 5a09e0253c6f data/gfx/area28.png
Binary file data/gfx/area28.png has changed
diff -r 5a09e0253c6f data/gfx/area29.png
Binary file data/gfx/area29.png has changed
diff -r 5a09e0253c6f data/gfx/area30.png
Binary file data/gfx/area30.png has changed
diff -r 5a09e0253c6f data/gfx/area31.png
Binary file data/gfx/area31.png has changed
diff -r 5a09e0253c6f data/gfx/gamegui28.png
Binary file data/gfx/gamegui28.png has changed
diff -r 5a09e0253c6f src/AIEcho.cpp
--- a/src/AIEcho.cpp Tue Dec 04 01:29:41 2007 +0100
+++ b/src/AIEcho.cpp Thu Jan 03 00:00:30 2008 -0400
@@ -3543,6 +3543,9 @@ void AddArea::modify(Echo& echo)
case GuardArea:
echo.push_order(shared_ptr<Order>(new
OrderAlterateGuardArea(echo.player->team->teamNumber, BrushTool::MODE_ADD,
&acc)));
break;
+ case HarvestArea:
+ echo.push_order(shared_ptr<Order>(new
OrderAlterateHarvestArea(echo.player->team->teamNumber, BrushTool::MODE_ADD,
&acc)));
+ break;
}
}
}
@@ -4296,6 +4299,13 @@ bool MapInfo::is_clearing_area(int x, in
bool MapInfo::is_clearing_area(int x, int y)
{
return echo.player->map->isClearArea(x, y, echo.player->team->me);
+}
+
+
+
+bool MapInfo::is_harvest_area(int x, int y)
+{
+ return echo.player->map->isHarvestArea(x, y, echo.player->team->me);
}
diff -r 5a09e0253c6f src/AIEcho.h
--- a/src/AIEcho.h Tue Dec 04 01:29:41 2007 +0100
+++ b/src/AIEcho.h Wed Jan 02 23:56:22 2008 -0400
@@ -1300,7 +1300,8 @@ namespace AIEcho
{
ClearingArea,
ForbiddenArea,
- GuardArea
+ GuardArea,
+ HarvestArea,
};
///This management order adds a particular type of "area" to
the ground.
@@ -1533,6 +1534,7 @@ namespace AIEcho
bool is_forbidden_area(int x, int y);
bool is_guard_area(int x, int y);
bool is_clearing_area(int x, int y);
+ bool is_harvest_area(int x, int y);
bool is_discovered(int x, int y);
bool is_ressource(int x, int y, int type);
bool is_water(int x, int y);
diff -r 5a09e0253c6f src/Brush.cpp
--- a/src/Brush.cpp Tue Dec 04 01:29:41 2007 +0100
+++ b/src/Brush.cpp Tue Jan 01 00:53:22 2008 -0400
@@ -31,10 +31,21 @@ BrushTool::BrushTool()
void BrushTool::draw(int x, int y)
{
+ drawMode(x, y);
+ drawType(x, y);
+}
+
+void BrushTool::drawMode(int x, int y)
+{
globalContainer->gfx->drawSprite(x+16, y, globalContainer->brush, 0);
globalContainer->gfx->drawSprite(x+64+16, y, globalContainer->brush, 1);
+
if (mode)
globalContainer->gfx->drawSprite(x+(static_cast<int>(mode)-1)*64+16, y,
globalContainer->gamegui, 22);
+}
+
+void BrushTool::drawType(int x, int y)
+{
for (unsigned i=0; i<8; i++)
{
int decX = (i%4)*32;
diff -r 5a09e0253c6f src/Brush.h
--- a/src/Brush.h Tue Dec 04 01:29:41 2007 +0100
+++ b/src/Brush.h Tue Jan 01 00:52:15 2008 -0400
@@ -51,6 +51,8 @@ public:
BrushTool();
//! Draw the brush tool and its actual state at a given coordinate
void draw(int x, int y);
+ void drawMode(int x, int y);
+ void drawType(int x, int y);
//! Handle the click for given coordinate. Select correct mode and
figure, accept negative coordinates for y
void handleClick(int x, int y);
//! Deselect any brush
diff -r 5a09e0253c6f src/Game.cpp
--- a/src/Game.cpp Tue Dec 04 01:29:41 2007 +0100
+++ b/src/Game.cpp Sat Jan 05 23:22:47 2008 -0400
@@ -585,6 +585,52 @@ void Game::executeOrder(boost::shared_pt
// Update local map
if (oaa->teamNumber ==
players[localPlayer]->teamNumber)
map.localClearAreaMap.set(index, false);
+ }
+ orderMaskIndex++;
+ }
+ }
+ else
+ assert(false);
+ }
+ break;
+ case ORDER_ALTERATE_HARVEST_AREA:
+ {
+ fprintf(logFile, "ORDER_ALTERATE_HARVEST_AREA");
+ boost::shared_ptr<OrderAlterateHarvestArea> oaa =
boost::static_pointer_cast<OrderAlterateHarvestArea>(order);
+ if (oaa->type == BrushTool::MODE_ADD)
+ {
+ Uint32 teamMask =
Team::teamNumberToMask(oaa->teamNumber);
+ size_t orderMaskIndex = 0;
+ for (int y=oaa->centerY+oaa->minY;
y<oaa->centerY+oaa->maxY; y++)
+ for (int x=oaa->centerX+oaa->minX;
x<oaa->centerX+oaa->maxX; x++)
+ {
+ if
(oaa->mask.get(orderMaskIndex) && (x+y)%2==0 )
+ {
+ size_t index =
(x&map.wMask)+(((y&map.hMask)<<map.wDec));
+ // Update real map
+
map.cases[index].harvestArea |= teamMask;
+ // Update local map
+ if (oaa->teamNumber ==
players[localPlayer]->teamNumber)
+
map.localHarvestAreaMap.set(index, true);
+ }
+ orderMaskIndex++;
+ }
+ }
+ else if (oaa->type == BrushTool::MODE_DEL)
+ {
+ Uint32 notTeamMask =
~Team::teamNumberToMask(oaa->teamNumber);
+ size_t orderMaskIndex = 0;
+ for (int y=oaa->centerY+oaa->minY;
y<oaa->centerY+oaa->maxY; y++)
+ for (int x=oaa->centerX+oaa->minX;
x<oaa->centerX+oaa->maxX; x++)
+ {
+ if
(oaa->mask.get(orderMaskIndex))
+ {
+ size_t index =
(x&map.wMask)+(((y&map.hMask)<<map.wDec));
+ // Update real map
+
map.cases[index].clearArea &= notTeamMask;
+ // Update local map
+ if (oaa->teamNumber ==
players[localPlayer]->teamNumber)
+
map.localHarvestAreaMap.set(index, false);
}
orderMaskIndex++;
}
@@ -2105,6 +2151,7 @@ inline void Game::drawMapAreas(int left,
const int clearingAreaBaseFrame = 0;
const int guardAreaBaseFrame = 8;
const int forbiddenAreaBaseFrame = 16;
+ const int harvestAreaBaseFrame = 24;
if ((drawOptions & DRAW_AREA) != 0)
{
for (int y=top; y<bot; y++)
@@ -2157,6 +2204,22 @@ inline void Game::drawMapAreas(int left,
globalContainer->gfx->drawVertLine((x<<5), (y<<5), 32, 255, 255, 0);
if
(!map.isClearAreaLocal(x+viewportX+1, y+viewportY))
globalContainer->gfx->drawVertLine(32+(x<<5), (y<<5), 32, 255, 255, 0);
+ }
+ if (map.isHarvestAreaLocal(x+viewportX,
y+viewportY))
+ {
+ int randId = (x+viewportX) * 7451 + (y+viewportY) * 23;
+ int frame = (randId + areaAnimationTick) % 8;
+ globalContainer->gfx->drawSprite((x<<5), (y<<5),
globalContainer->areas, harvestAreaBaseFrame + frame, 200);
+
+ if
(!map.isHarvestAreaLocal(x+viewportX, y+viewportY-1))
+
globalContainer->gfx->drawHorzLine((x<<5), (y<<5), 32, 255, 126, 0);
+ if
(!map.isHarvestAreaLocal(x+viewportX, y+viewportY+1))
+
globalContainer->gfx->drawHorzLine((x<<5), 32+(y<<5), 32, 255, 126, 0);
+
+ if
(!map.isHarvestAreaLocal(x+viewportX-1, y+viewportY))
+
globalContainer->gfx->drawVertLine((x<<5), (y<<5), 32, 255, 126, 0);
+ if
(!map.isHarvestAreaLocal(x+viewportX+1, y+viewportY))
+
globalContainer->gfx->drawVertLine(32+(x<<5), (y<<5), 32, 255, 126, 0);
}
if((drawOptions &
DRAW_NO_RESSOURCE_GROWTH_AREAS) != 0)
diff -r 5a09e0253c6f src/GameGUI.cpp
--- a/src/GameGUI.cpp Tue Dec 04 01:29:41 2007 +0100
+++ b/src/GameGUI.cpp Sat Jan 05 23:15:14 2008 -0400
@@ -83,6 +83,8 @@
#define YOFFSET_PROGRESS_BAR 10
#define YOFFSET_BRUSH 56
+
+#define YOFFSET_BRUSH_MODE 36
using namespace boost;
@@ -229,10 +231,11 @@ void GameGUI::adjustLocalTeam()
assert(localTeam);
teamStats = &localTeam->stats;
- // recompute local forbidden and guard areas
+ // recompute local forbidden, guard, clear and harvest areas
game.map.computeLocalForbidden(localTeamNo);
game.map.computeLocalGuardArea(localTeamNo);
game.map.computeLocalClearArea(localTeamNo);
+ game.map.computeLocalHarvestArea(localTeamNo);
// set default event position
eventGoPosX = localTeam->startPosX;
@@ -1391,6 +1394,23 @@ void GameGUI::handleKey(SDL_keysym key,
displayMode = FLAG_VIEW;
setSelection(BRUSH_SELECTION);
toolManager.activateZoneTool(GameGUIToolManager::Clearing);
+ }
+ break;
+ case GameGUIKeyActions::SelectPlaceHarvestArea:
+ {
+ if(selectionMode != BRUSH_SELECTION)
+ clearSelection();
+
+ //The harvest area uses the biggest brush available on
31/12/07
+ brush.setFigure(7);
+
+ if (brush.getType() ==
BrushTool::MODE_NONE)
+ {
+
brush.setType(BrushTool::MODE_ADD);
+ }
+ displayMode = FLAG_VIEW;
+ setSelection(BRUSH_SELECTION);
+
toolManager.activateZoneTool(GameGUIToolManager::Harvest);
}
break;
case GameGUIKeyActions::SwitchToAddingAreas:
@@ -2122,18 +2142,47 @@ void GameGUI::handleMenuClick(int mx, in
my -= YPOS_BASE_FLAG;
if (my > YOFFSET_BRUSH)
{
- // change the brush type (forbidden, guard, clear) if
necessary
+ // change the brush type (forbidden, guard, clear,
harvest) if necessary
if (my < YOFFSET_BRUSH+40)
{
- if (mx < 44)
+ if (mx < 33)
toolManager.activateZoneTool(GameGUIToolManager::Forbidden);
- else if (mx < 84)
+ else if (mx < 65)
toolManager.activateZoneTool(GameGUIToolManager::Guard);
+ else if (mx < 97)
+
toolManager.activateZoneTool(GameGUIToolManager::Clearing);
else
-
toolManager.activateZoneTool(GameGUIToolManager::Clearing);
- }
- // anyway, update the tool
- brush.handleClick(mx, my-YOFFSET_BRUSH-40);
+ {
+ brush.setFigure(7);
+ if (brush.getType() ==
BrushTool::MODE_NONE)
+ {
+
brush.setType(BrushTool::MODE_ADD);
+ }
+
+
toolManager.activateZoneTool(GameGUIToolManager::Harvest);
+ }
+ }
+ // anyway, update the tool
+ if (toolManager.getZoneType() !=
GameGUIToolManager::Harvest)
+ brush.handleClick(mx, my-YOFFSET_BRUSH-40);
+ else
+ {
+ int y = my-YOFFSET_BRUSH-40;
+ //With the harvest brush, we don't select brush figures
+ if(y>0 && y<YOFFSET_BRUSH_MODE)
+ brush.handleClick(mx, y);
+ else if(y>36)
+ {
+ if(y < 36+YOFFSET_TEXT_PARA )
+ toolManager.setHarvestResource(Wood);
+ else if( y < 36+YOFFSET_TEXT_PARA*2)
+ toolManager.setHarvestResource(Wheat);
+ else if( y < 36+YOFFSET_TEXT_PARA*3)
+ toolManager.setHarvestResource(Papyrus);
+ else if( y < 36+YOFFSET_TEXT_PARA*4)
+ toolManager.setHarvestResource(Algae);
+ }
+ }
// set the selection
setSelection(BRUSH_SELECTION);
toolManager.activateZoneTool();
@@ -3193,42 +3242,76 @@ void GameGUI::drawPanel(void)
// draw flags
drawChoice(YPOS_BASE_FLAG, flagsChoiceName, flagsChoiceState,
3);
// draw choice of area
-
globalContainer->gfx->drawSprite(globalContainer->gfx->getW()-128+8,
YPOS_BASE_FLAG+YOFFSET_BRUSH, globalContainer->gamegui, 13);
-
globalContainer->gfx->drawSprite(globalContainer->gfx->getW()-128+48,
YPOS_BASE_FLAG+YOFFSET_BRUSH, globalContainer->gamegui, 14);
-
globalContainer->gfx->drawSprite(globalContainer->gfx->getW()-128+88,
YPOS_BASE_FLAG+YOFFSET_BRUSH, globalContainer->gamegui, 25);
+
globalContainer->gfx->drawSprite(globalContainer->gfx->getW()-128+1,
YPOS_BASE_FLAG+YOFFSET_BRUSH, globalContainer->gamegui, 13);
+
globalContainer->gfx->drawSprite(globalContainer->gfx->getW()-128+33,
YPOS_BASE_FLAG+YOFFSET_BRUSH, globalContainer->gamegui, 14);
+
globalContainer->gfx->drawSprite(globalContainer->gfx->getW()-128+65,
YPOS_BASE_FLAG+YOFFSET_BRUSH, globalContainer->gamegui, 25);
+
globalContainer->gfx->drawSprite(globalContainer->gfx->getW()-128+97,
YPOS_BASE_FLAG+YOFFSET_BRUSH, globalContainer->gamegui, 28);
if (brush.getType() != BrushTool::MODE_NONE)
{
- int decX = 8 + ((int)toolManager.getZoneType()) * 40;
+ int decX = 1 + ((int)toolManager.getZoneType()) * 32;
globalContainer->gfx->drawSprite(globalContainer->gfx->getW()-128+decX,
YPOS_BASE_FLAG+YOFFSET_BRUSH, globalContainer->gamegui, 22);
}
- // draw brush
- brush.draw(globalContainer->gfx->getW()-128,
YPOS_BASE_FLAG+YOFFSET_BRUSH+40);
- // draw brush help text
- if ((mouseX>globalContainer->gfx->getW()-128) &&
(mouseY>YPOS_BASE_FLAG+YOFFSET_BRUSH))
- {
- int buildingInfoStart = globalContainer->gfx->getH()-50;
- if (mouseY<YPOS_BASE_FLAG+YOFFSET_BRUSH+40)
- {
- int panelMouseX = mouseX -
globalContainer->gfx->getW() + 128;
- if (panelMouseX < 44)
-
drawTextCenter(globalContainer->gfx->getW()-128, buildingInfoStart-32,
"[forbidden area]");
- else if (panelMouseX < 84)
-
drawTextCenter(globalContainer->gfx->getW()-128, buildingInfoStart-32, "[guard
area]");
- else
-
drawTextCenter(globalContainer->gfx->getW()-128, buildingInfoStart-32, "[clear
area]");
- }
- else
- {
- if (toolManager.getZoneType() ==
GameGUIToolManager::Forbidden)
-
drawTextCenter(globalContainer->gfx->getW()-128, buildingInfoStart-32,
"[forbidden area]");
- else if (toolManager.getZoneType() ==
GameGUIToolManager::Guard)
-
drawTextCenter(globalContainer->gfx->getW()-128, buildingInfoStart-32, "[guard
area]");
- else if (toolManager.getZoneType() ==
GameGUIToolManager::Clearing)
-
drawTextCenter(globalContainer->gfx->getW()-128, buildingInfoStart-32, "[clear
area]");
- else
- assert(false);
- }
- }
+
+ if (toolManager.getZoneType() != GameGUIToolManager::Harvest)
+ {
+ // draw brush
+ brush.drawMode(globalContainer->gfx->getW()-128,
YPOS_BASE_FLAG+YOFFSET_BRUSH+40);
+ brush.drawType(globalContainer->gfx->getW()-128,
YPOS_BASE_FLAG+YOFFSET_BRUSH+40);
+ // draw brush help text
+ if ((mouseX>globalContainer->gfx->getW()-128) &&
(mouseY>YPOS_BASE_FLAG+YOFFSET_BRUSH))
+ {
+ int buildingInfoStart = globalContainer->gfx->getH()-50;
+ if (mouseY<YPOS_BASE_FLAG+YOFFSET_BRUSH+40)
+ {
+ int panelMouseX = mouseX - globalContainer->gfx->getW() +
128;
+ if (panelMouseX < 33)
+ drawTextCenter(globalContainer->gfx->getW()-128,
buildingInfoStart-32, "[forbidden area]");
+ else if (panelMouseX < 65)
+ drawTextCenter(globalContainer->gfx->getW()-128,
buildingInfoStart-32, "[guard area]");
+ else if (panelMouseX < 97)
+ drawTextCenter(globalContainer->gfx->getW()-128,
buildingInfoStart-32, "[clear area]");
+ else
+ drawTextCenter(globalContainer->gfx->getW()-128,
buildingInfoStart-32, "[harvest area]");
+ }
+ else
+ {
+ if (toolManager.getZoneType() ==
GameGUIToolManager::Forbidden)
+ drawTextCenter(globalContainer->gfx->getW()-128,
buildingInfoStart-32, "[forbidden area]");
+ else if (toolManager.getZoneType() ==
GameGUIToolManager::Guard)
+ drawTextCenter(globalContainer->gfx->getW()-128,
buildingInfoStart-32, "[guard area]");
+ else if (toolManager.getZoneType() ==
GameGUIToolManager::Clearing)
+ drawTextCenter(globalContainer->gfx->getW()-128,
buildingInfoStart-32, "[clear area]");
+ else if (toolManager.getZoneType() ==
GameGUIToolManager::Harvest)
+ drawTextCenter(globalContainer->gfx->getW()-128,
buildingInfoStart-32, "[harvest area]");
+ else
+ assert(false);
+ }
+ }
+ }
+ else
+ {
+ //draw resource selection
+ brush.drawMode(globalContainer->gfx->getW()-128,
YPOS_BASE_FLAG+YOFFSET_BRUSH+40);
+
+ int ypos = YPOS_BASE_FLAG+YOFFSET_BRUSH+YOFFSET_BRUSH_MODE+40;
+ int j=0;
+ for (int i=0; i<BASIC_COUNT; i++)
+ if (i!=STONE)
+ {
+
globalContainer->gfx->drawString(globalContainer->gfx->getW()-128+28, ypos,
globalContainer->littleFont,
+ getRessourceName(i));
+ int spriteId;
+ if(toolManager.getHarvestResource() == i)
+ spriteId=20;
+ else
+ spriteId=19;
+
globalContainer->gfx->drawSprite(globalContainer->gfx->getW()-128+10, ypos+2,
globalContainer->gamegui, spriteId);
+
+ ypos+=YOFFSET_TEXT_PARA;
+ j++;
+ }
+
+ }
}
else if (displayMode==STAT_TEXT_VIEW)
{
@@ -4275,29 +4358,52 @@ void GameGUI::flushScrollWheelOrders()
void GameGUI::flushScrollWheelOrders()
{
SDLMod modState = SDL_GetModState();
- if (scrollWheelChanges!=0 && selectionMode==BUILDING_SELECTION)
- {
- Building* selBuild=selection.building;
- if ((selBuild->owner->teamNumber==localTeamNo) &&
- (selBuild->buildingState==Building::ALIVE))
- {
- if ((selBuild->type->maxUnitWorking) &&
-
(!globalContainer->settings.scrollWheelEnabled ? (modState & KMOD_CTRL) :
!(SDL_GetModState()&KMOD_SHIFT)))
- {
-
selBuild->maxUnitWorkingLocal+=scrollWheelChanges;
- int
nbReq=selBuild->maxUnitWorkingLocal=std::min(20, std::max(0,
(selBuild->maxUnitWorkingLocal)));
- orderQueue.push_back(shared_ptr<Order>(new
OrderModifyBuilding(selBuild->gid, nbReq)));
-
defaultAssign.setDefaultAssignedUnits(selBuild->typeNum, nbReq);
- }
- else if ((selBuild->type->defaultUnitStayRange) &&
- (SDL_GetModState()&KMOD_SHIFT))
- {
-
selBuild->unitStayRangeLocal+=scrollWheelChanges;
- int
nbReq=selBuild->unitStayRangeLocal=std::min(selBuild->type->maxUnitStayRange,
std::max(0, (selBuild->unitStayRangeLocal)));
- orderQueue.push_back(shared_ptr<Order>(new
OrderModifyFlag(selBuild->gid, nbReq)));
- }
- }
- }
+ if (scrollWheelChanges!=0)
+ if(selectionMode==BUILDING_SELECTION)
+ {
+ Building* selBuild=selection.building;
+ if ((selBuild->owner->teamNumber==localTeamNo) &&
+ (selBuild->buildingState==Building::ALIVE))
+ {
+ if ((selBuild->type->maxUnitWorking) &&
+
(!globalContainer->settings.scrollWheelEnabled ? (modState & KMOD_CTRL) :
!(SDL_GetModState()&KMOD_SHIFT)))
+ {
+ selBuild->maxUnitWorkingLocal+=scrollWheelChanges;
+ int nbReq=selBuild->maxUnitWorkingLocal=std::min(20,
std::max(0, (selBuild->maxUnitWorkingLocal)));
+ orderQueue.push_back(shared_ptr<Order>(new
OrderModifyBuilding(selBuild->gid, nbReq)));
+ defaultAssign.setDefaultAssignedUnits(selBuild->typeNum,
nbReq);
+ }
+ else if ((selBuild->type->defaultUnitStayRange) &&
+ (SDL_GetModState()&KMOD_SHIFT))
+ {
+ selBuild->unitStayRangeLocal+=scrollWheelChanges;
+ int
nbReq=selBuild->unitStayRangeLocal=std::min(selBuild->type->maxUnitStayRange,
std::max(0, (selBuild->unitStayRangeLocal)));
+ orderQueue.push_back(shared_ptr<Order>(new
OrderModifyFlag(selBuild->gid, nbReq)));
+ }
+ }
+ }
+ else if(selectionMode==BRUSH_SELECTION && toolManager.getZoneType() ==
GameGUIToolManager::Harvest)
+ {
+ if(scrollWheelChanges > 0)
+ {
+ if(toolManager.getHarvestResource() == Wood)
+ toolManager.setHarvestResource(Algae);
+ else if(toolManager.getHarvestResource() == Wheat)
+ toolManager.setHarvestResource(Wood);
+ else if(toolManager.getHarvestResource() == Papyrus)
+ toolManager.setHarvestResource(Wheat);
+ else if(toolManager.getHarvestResource() == Algae)
+ toolManager.setHarvestResource(Papyrus);
+ }
+ else if(toolManager.getHarvestResource() == Wood)
+ toolManager.setHarvestResource(Wheat);
+ else if(toolManager.getHarvestResource() == Wheat)
+ toolManager.setHarvestResource(Papyrus);
+ else if(toolManager.getHarvestResource() == Papyrus)
+ toolManager.setHarvestResource(Algae);
+ else if(toolManager.getHarvestResource() == Algae)
+ toolManager.setHarvestResource(Wood);
+ }
scrollWheelChanges=0;
}
diff -r 5a09e0253c6f src/GameGUI.h
--- a/src/GameGUI.h Tue Dec 04 01:29:41 2007 +0100
+++ b/src/GameGUI.h Wed Jan 02 21:25:59 2008 -0400
@@ -124,6 +124,8 @@ public:
/// Sets this game as a campaign game from the provided campaign and
the provided mission
void setCampaignGame(Campaign& campaign, const std::string&
missionName);
+ // Information about the brushes
+ GameGUIToolManager::ZoneType getBrushMode() { return
toolManager.getZoneType(); }
KeyboardManager keyboardManager;
public:
diff -r 5a09e0253c6f src/GameGUIKeyActions.h
--- a/src/GameGUIKeyActions.h Tue Dec 04 01:29:41 2007 +0100
+++ b/src/GameGUIKeyActions.h Sun Dec 30 22:58:38 2007 -0400
@@ -69,6 +69,7 @@ namespace GameGUIKeyActions
SelectPlaceForbiddenArea,
SelectPlaceGuardArea,
SelectPlaceClearingArea,
+ SelectPlaceHarvestArea,
SwitchToAddingAreas,
SwitchToRemovingAreas,
SwitchToAreaBrush1,
diff -r 5a09e0253c6f src/GameGUIToolManager.cpp
--- a/src/GameGUIToolManager.cpp Tue Dec 04 01:29:41 2007 +0100
+++ b/src/GameGUIToolManager.cpp Sat Jan 05 23:18:10 2008 -0400
@@ -23,6 +23,7 @@
#include "GlobalContainer.h"
#include "GUIBase.h"
#include "FormatableString.h"
+#include <iostream>
using namespace GAGGUI;
@@ -34,6 +35,7 @@ GameGUIToolManager::GameGUIToolManager(G
hilightStrength = 0;
mode = NoTool;
zoneType = Forbidden;
+ resourceType = Wheat;
}
@@ -65,6 +67,13 @@ void GameGUIToolManager::deactivateTool(
{
if(mode == PlaceZone)
brush.unselect();
+}
+
+
+
+void GameGUIToolManager::setHarvestResource(ResourceType type)
+{
+ resourceType = type;
}
@@ -187,6 +196,7 @@ void GameGUIToolManager::drawTool(int mo
{
c = Color(170,0,0);
}
+ brush.drawBrush(mouseX, mouseY, c);
}
else if (zoneType == Guard)
{
@@ -198,6 +208,7 @@ void GameGUIToolManager::drawTool(int mo
{
c = Color(18,0,170);
}
+ brush.drawBrush(mouseX, mouseY, c);
}
else if (zoneType == Clearing)
{
@@ -210,8 +221,20 @@ void GameGUIToolManager::drawTool(int mo
{
c = Color(167,137,0);
}
- }
- brush.drawBrush(mouseX, mouseY, c);
+ brush.drawBrush(mouseX, mouseY, c);
+ }
+ else if (zoneType == Harvest)
+ {
+ if (mode == BrushTool::MODE_ADD)
+ {
+ c = Color(255,126,0);
+ }
+ else
+ {
+ c = Color(170,84,0);
+ }
+ brush.drawBrush(mouseX, mouseY, c);
+ }
}
}
@@ -227,6 +250,13 @@ GameGUIToolManager::ZoneType GameGUITool
GameGUIToolManager::ZoneType GameGUIToolManager::getZoneType() const
{
return zoneType;
+}
+
+
+
+ResourceType GameGUIToolManager::getHarvestResource() const
+{
+ return resourceType;
}
@@ -288,12 +318,19 @@ void GameGUIToolManager::handleMouseDown
{
isAlreadyOn = true;
}
+ else if(zoneType == Harvest &&
game.map.isHarvestAreaLocal(mapX, mapY))
+ {
+ isAlreadyOn = true;
+ }
unsigned mode = brush.getType();
if (((mode == BrushTool::MODE_ADD) && isAlreadyOn)
|| ((mode == BrushTool::MODE_DEL) && !isAlreadyOn))
{
- flushBrushOrders(localteam);
- brush.setType((mode == BrushTool::MODE_ADD) ?
BrushTool::MODE_DEL : BrushTool::MODE_ADD);
+ if( zoneType != Harvest || ((zoneType == Harvest) && (mapX +
mapY % 2 == 0)))
+ {
+ flushBrushOrders(localteam);
+ brush.setType((mode == BrushTool::MODE_ADD) ?
BrushTool::MODE_DEL : BrushTool::MODE_ADD);
+ }
}
}
handleZonePlacement(mouseX, mouseY, localteam, viewportX,
viewportY);
@@ -363,6 +400,11 @@ void GameGUIToolManager::handleZonePlace
game.map.localGuardAreaMap.set(game.map.w*(y&game.map.hMask)+(x&game.map.wMask),
true);
else if (zoneType == Clearing)
game.map.localClearAreaMap.set(game.map.w*(y&game.map.hMask)+(x&game.map.wMask),
true);
+ else if ((zoneType == Harvest) &&
((x+y) % 2 == 0))
+ {
+
game.map.localHarvestAreaMap.set(game.map.w*(y&game.map.hMask)+(x&game.map.wMask),
true);
+
game.map.setHarvestResource(game.map.w*(y&game.map.hMask)+(x&game.map.wMask),
getHarvestResource());
+ }
}
}
}
@@ -381,6 +423,8 @@ void GameGUIToolManager::handleZonePlace
game.map.localGuardAreaMap.set(game.map.w*(y&game.map.hMask)+(x&game.map.wMask),
false);
else if (zoneType == Clearing)
game.map.localClearAreaMap.set(game.map.w*(y&game.map.hMask)+(x&game.map.wMask),
false);
+ else if (zoneType == Harvest)
+
game.map.localHarvestAreaMap.set(game.map.w*(y&game.map.hMask)+(x&game.map.wMask),
false);
}
}
}
@@ -412,6 +456,10 @@ void GameGUIToolManager::flushBrushOrder
{
orders.push(boost::shared_ptr<Order>(new
OrderAlterateClearArea(localteam, brush.getType(), &brushAccumulator)));
}
+ else if (zoneType == Harvest)
+ {
+ orders.push(boost::shared_ptr<Order>(new
OrderAlterateHarvestArea(localteam, brush.getType(), &brushAccumulator)));
+ }
else
assert(false);
brushAccumulator.clear();
diff -r 5a09e0253c6f src/GameGUIToolManager.h
--- a/src/GameGUIToolManager.h Tue Dec 04 01:29:41 2007 +0100
+++ b/src/GameGUIToolManager.h Sat Jan 05 23:10:40 2008 -0400
@@ -26,6 +26,7 @@
#include "boost/shared_ptr.hpp"
#include "Brush.h"
#include "GameGUIDefaultAssignManager.h"
+#include "Map.h"
#include <string>
#include <queue>
@@ -50,6 +51,7 @@ public:
Forbidden=0,
Guard,
Clearing,
+ Harvest,
};
///Activates the building tool with the given building or flag type
@@ -60,9 +62,12 @@ public:
///Activates the zone tool with the last selected zone type
void activateZoneTool();
-
+
///Cancels a tool
void deactivateTool();
+
+ ///Sets the current selected resource for the harvest brush
+ void setHarvestResource(ResourceType type);
///Draws the tool on the map
void drawTool(int mouseX, int mouseY, int localteam, int viewportX, int
viewportY);
@@ -73,6 +78,9 @@ public:
///Returns the current type of zone
ZoneType getZoneType() const;
+ ///Returns the current type of zone
+ ResourceType getHarvestResource() const;
+
///Handles a mouse down
void handleMouseDown(int mouseX, int mouseY, int localteam, int
viewportX, int viewportY);
@@ -101,6 +109,8 @@ private:
std::string building;
///The type of zone when placing zones
ZoneType zoneType;
+ ///The type of resource selected for the harvest brush
+ ResourceType resourceType;
///Used to indicate the stength of hilight, because it blends during
the draw
float hilightStrength;
///Queues up orderws for this manager
diff -r 5a09e0253c6f src/Map.cpp
--- a/src/Map.cpp Tue Dec 04 01:29:41 2007 +0100
+++ b/src/Map.cpp Sat Jan 05 21:52:17 2008 -0400
@@ -929,6 +929,7 @@ void Map::setSize(int wDec, int hDec, Te
localForbiddenMap.resize(size, false);
localGuardAreaMap.resize(size, false);
localClearAreaMap.resize(size, false);
+ localHarvestAreaMap.resize(size, false);
cases=new Case[size];
Case initCase;
@@ -941,6 +942,8 @@ void Map::setSize(int wDec, int hDec, Te
initCase.hiddenForbidden = 0;
initCase.guardArea = 0;
initCase.clearArea = 0;
+ initCase.harvestArea = 0;
+ initCase.harvestResource = Wheat;
initCase.scriptAreas = 0;
initCase.canRessourcesGrow = 1;
@@ -1036,6 +1039,7 @@ bool Map::load(GAGCore::InputStream *str
localForbiddenMap.resize(size, false);
localGuardAreaMap.resize(size, false);
localClearAreaMap.resize(size, false);
+ localHarvestAreaMap.resize(size, false);
cases = new Case[size];
undermap = new Uint8[size];
listedAddr = new Uint8*[size];
@@ -1068,6 +1072,13 @@ bool Map::load(GAGCore::InputStream *str
cases[i].hiddenForbidden =
stream->readUint32("hiddenForbidden");
cases[i].guardArea = stream->readUint32("guardArea");
cases[i].clearArea = stream->readUint32("clearArea");
+#if 0
+ //This is commented out because harvest areas cannot be saved inside
maps.
+ cases[i].harvestArea = stream->readUint32("harvestArea");
+#else
+ cases[i].harvestArea = 0;
+ cases[i].harvestResource = Wheat;
+#endif
cases[i].scriptAreas = stream->readUint16("scriptAreas");
cases[i].canRessourcesGrow =
stream->readUint8("canRessourcesGrow");
@@ -1207,6 +1218,11 @@ void Map::save(GAGCore::OutputStream *st
stream->writeUint32(cases[i].hiddenForbidden,
"hiddenForbidden");
stream->writeUint32(cases[i].guardArea, "guardArea");
stream->writeUint32(cases[i].clearArea, "clearArea");
+#if 0
+ //This is commented out because harvest areas are not saved in maps
+ stream->writeUint32(cases[i].harvestArea, "harvestArea");
+ stream->writeUint32(cases[i].harvestResource,
"harvestResource");
+#endif
stream->writeUint16(cases[i].scriptAreas, "scriptAreas");
stream->writeUint8(cases[i].canRessourcesGrow,
"canRessourcesGrow");
stream->writeLeaveSection();
@@ -1450,6 +1466,16 @@ void Map::computeLocalClearArea(int loca
localClearAreaMap.set(i, true);
else
localClearAreaMap.set(i, false);
+}
+
+void Map::computeLocalHarvestArea(int localTeamNo)
+{
+ int localTeamMask = 1<<localTeamNo;
+ for (size_t i=0; i<size; i++)
+ if ((cases[i].harvestArea & localTeamMask) != 0)
+ localHarvestAreaMap.set(i, true);
+ else
+ localHarvestAreaMap.set(i, false);
}
void Map::decRessource(int x, int y)
diff -r 5a09e0253c6f src/Map.h
--- a/src/Map.h Tue Dec 04 01:29:41 2007 +0100
+++ b/src/Map.h Sat Jan 05 23:08:26 2008 -0400
@@ -46,6 +46,14 @@ class MapGenerationDescriptor;
class MapGenerationDescriptor;
class SessionGame;
+enum ResourceType
+{
+ Wood,
+ Wheat,
+ Papyrus,
+ Algae = 4, //To use getRessourceName() we need to use 4, since the value
of 3 is taken by STONE
+};
+
// a 1x1 piece of map
struct Case
{
@@ -63,6 +71,9 @@ struct Case
Uint32 hiddenForbidden; // This is a mask, one bit by team,
1=forbidden, 0=allowed
Uint32 guardArea; // This is a mask, one bit by team, 1=guard area,
0=normal
Uint32 clearArea; // This is a mask, one bit by team, 1=clear area,
0=normal
+ Uint32 harvestArea; // This is a mask, one bit by team, 1=harvest area,
0=normal
+ ResourceType harvestResource; //If harvestArea == 1, tells which resource
should NOT be harvested
+
Uint16 scriptAreas; // This is also a mask. A single bit represents an
area #n, on or off for the square
Uint8 canRessourcesGrow; // This is a boolean, it represents whether
ressources are allowed to grow into this location.
@@ -263,7 +274,40 @@ public:
{
return cases[((y&hMask)<<wDec)+(x&wMask)].clearArea&teamMask;
}
-
+
+ //! Return true if the position (x,y) is a harvest area set by the user
+ // or rather, by the team computeLocalHarvestArea was last called for
+ bool isHarvestAreaLocal(int x, int y)
+ {
+ return localHarvestAreaMap.get(((y&hMask)<<wDec)+(x&wMask));
+ }
+
+ //! Returns true if the position(x, y) is a harvest area for the given
team
+ bool isHarvestArea(int x, int y, Uint32 teamMask)
+ {
+ return cases[((y&hMask)<<wDec)+(x&wMask)].harvestArea&teamMask;
+ }
+
+ ResourceType getHarvestResource(int x, int y)
+ {
+ return cases[((y&hMask)<<wDec)+(x&wMask)].harvestResource;
+ }
+
+ ResourceType getHarvestResource(unsigned pos)
+ {
+ return (cases+pos)->harvestResource;
+ }
+
+ void setHarvestResource(int x, int y, ResourceType type)
+ {
+ cases[((y&hMask)<<wDec)+(x&wMask)].harvestResource = type;
+ }
+
+ void setHarvestResource(unsigned pos, ResourceType type)
+ {
+ (cases+pos)->harvestResource = type;
+ }
+
// note - these are only meant to be called for the LOCAL team
// (the one whose stuff is displayed on the screen)
//! Compute localForbiddenMap from cases array
@@ -272,6 +316,8 @@ public:
void computeLocalGuardArea(int localTeamNo);
//! Compute localClearAreaMap from cases array
void computeLocalClearArea(int localTeamNo);
+ //! Compute localHarvestAreaMap from cases array
+ void computeLocalHarvestArea(int localTeamNo);
//! Return the case at a given position
inline Case &getCase(int x, int y)
@@ -711,6 +757,8 @@ public:
Utilities::BitArray localGuardAreaMap;
//! true = clear area
Utilities::BitArray localClearAreaMap;
+ //! true = harvest area
+ Utilities::BitArray localHarvestAreaMap;
public:
// Used to go to ressources
diff -r 5a09e0253c6f src/MapEdit.cpp
--- a/src/MapEdit.cpp Tue Dec 04 01:29:41 2007 +0100
+++ b/src/MapEdit.cpp Tue Jan 01 00:57:25 2008 -0400
@@ -232,6 +232,12 @@ void ZoneSelector::draw()
{
globalContainer->gfx->drawSprite(area.x, area.y,
globalContainer->gamegui, 25);
if(me.brushType==MapEdit::ClearAreaBrush)
+ isSelected=true;
+ }
+ else if(zoneType==HarvestZone)
+ {
+ globalContainer->gfx->drawSprite(area.x, area.y,
globalContainer->gamegui, 28);
+ if(me.brushType==MapEdit::HarvestAreaBrush)
isSelected=true;
}
if(me.selectionMode==MapEdit::PlaceZone && isSelected)
@@ -905,9 +911,10 @@ MapEdit::MapEdit()
explorationflag = new BuildingSelectorWidget(*this,
widgetRectangle(globalContainer->gfx->getW()-128+5, 128+32+7, 32, 32), "flag
view", "explorationflag", "set place building selection explorationflag",
"explorationflag", false);
warflag = new BuildingSelectorWidget(*this,
widgetRectangle(globalContainer->gfx->getW()-128+5+42, 128+32+7, 32, 32), "flag
view", "warflag", "set place building selection warflag", "warflag", false);
clearingflag = new BuildingSelectorWidget(*this,
widgetRectangle(globalContainer->gfx->getW()-128+5+84, 128+32+7, 32, 32), "flag
view", "clearingflag", "set place building selection clearingflag",
"clearingflag", false);
- forbiddenZone = new ZoneSelector(*this,
widgetRectangle(globalContainer->gfx->getW()-128+8, 216, 32, 32), "flag view",
"forbidden zone", "select forbidden zone", ZoneSelector::ForbiddenZone);
- guardZone = new ZoneSelector(*this,
widgetRectangle(globalContainer->gfx->getW()-128+8+40, 216, 32, 32), "flag
view", "guard zone", "select guard zone", ZoneSelector::GuardingZone);
- clearingZone = new ZoneSelector(*this,
widgetRectangle(globalContainer->gfx->getW()-128+8+80, 216, 32, 32), "flag
view", "clearing zone", "select clearing zone", ZoneSelector::ClearingZone);
+ forbiddenZone = new ZoneSelector(*this,
widgetRectangle(globalContainer->gfx->getW()-128+1, 216, 32, 32), "flag view",
"forbidden zone", "select forbidden zone", ZoneSelector::ForbiddenZone);
+ guardZone = new ZoneSelector(*this,
widgetRectangle(globalContainer->gfx->getW()-128+1+32, 216, 32, 32), "flag
view", "guard zone", "select guard zone", ZoneSelector::GuardingZone);
+ clearingZone = new ZoneSelector(*this,
widgetRectangle(globalContainer->gfx->getW()-128+1+64, 216, 32, 32), "flag
view", "clearing zone", "select clearing zone", ZoneSelector::ClearingZone);
+ harvestZone = new ZoneSelector(*this,
widgetRectangle(globalContainer->gfx->getW()-128+1+96, 216, 32, 32), "flag
view", "harvest zone", "select harvest zone", ZoneSelector::HarvestZone);
zoneBrushSelector = new BrushSelector(*this,
widgetRectangle(globalContainer->gfx->getW()-128, 216+40, 128, 96), "flag
view", "zone brush selector", "handle zone click", brush);
worker = new UnitSelector(*this,
widgetRectangle(globalContainer->gfx->getW()-128+8, 360, 38, 38), "flag view",
"worker selector", "select worker", WORKER);
explorer = new UnitSelector(*this,
widgetRectangle(globalContainer->gfx->getW()-128+48, 360, 38, 38), "flag view",
"explorer selector", "select explorer", EXPLORER);
@@ -923,6 +930,7 @@ MapEdit::MapEdit()
addWidget(forbiddenZone);
addWidget(guardZone);
addWidget(clearingZone);
+ addWidget(harvestZone);
addWidget(zoneBrushSelector);
addWidget(worker);
addWidget(warrior);
@@ -1376,9 +1384,7 @@ void MapEdit::drawMap(int sx, int sy, in
globalContainer->gfx->setClipRect();
}
if(selectionMode==ChangeAreas)
- {
- brush.drawBrush(mouseX, mouseY);
- }
+ brush.drawBrush(mouseX, mouseY);
if(selectionMode==ChangeNoRessourceGrowthAreas)
brush.drawBrush(mouseX, mouseY);
}
diff -r 5a09e0253c6f src/MapEdit.h
--- a/src/MapEdit.h Tue Dec 04 01:29:41 2007 +0100
+++ b/src/MapEdit.h Mon Dec 31 23:40:38 2007 -0400
@@ -203,7 +203,7 @@ public:
};
-///This is a selector for a type of zone, like forbidden, guarding or clearing
zone. Three of these are needed to be able to select any type of zone.
+///This is a selector for a type of zone, like forbidden, guarding, clearing
or harvesting zone. Three of these are needed to be able to select any type of
zone.
class ZoneSelector : public MapEditorWidget
{
public:
@@ -212,6 +212,7 @@ public:
ForbiddenZone,
GuardingZone,
ClearingZone,
+ HarvestZone,
};
ZoneSelector(MapEdit& me, const widgetRectangle& area, const
std::string& group, const std::string& name, const std::string& action,
ZoneType zoneType);
@@ -609,6 +610,7 @@ private:
ZoneSelector* forbiddenZone;
ZoneSelector* guardZone;
ZoneSelector* clearingZone;
+ ZoneSelector* harvestZone;
BrushSelector* zoneBrushSelector;
UnitSelector* worker;
UnitSelector* explorer;
@@ -783,6 +785,7 @@ private:
ForbiddenBrush,
GuardAreaBrush,
ClearAreaBrush,
+ HarvestAreaBrush,
NoBrush,
} brushType;
diff -r 5a09e0253c6f src/NetConsts.h
--- a/src/NetConsts.h Tue Dec 04 01:29:41 2007 +0100
+++ b/src/NetConsts.h Sun Dec 30 22:24:24 2007 -0400
@@ -37,10 +37,11 @@ enum OrderTypes
ORDER_ALTERATE_FORBIDDEN=37,
ORDER_ALTERATE_GUARD_AREA=38,
ORDER_ALTERATE_CLEAR_AREA=39,
- ORDER_DELETE=40,
- ORDER_CANCEL_DELETE=41,
- ORDER_CONSTRUCTION=42,
- ORDER_CANCEL_CONSTRUCTION=43,
+ ORDER_ALTERATE_HARVEST_AREA=40,
+ ORDER_DELETE=41,
+ ORDER_CANCEL_DELETE=42,
+ ORDER_CONSTRUCTION=43,
+ ORDER_CANCEL_CONSTRUCTION=44,
ORDER_NULL=51,
ORDER_PAUSE_GAME=59,
diff -r 5a09e0253c6f src/Order.cpp
--- a/src/Order.cpp Tue Dec 04 01:29:41 2007 +0100
+++ b/src/Order.cpp Sun Dec 30 22:09:35 2007 -0400
@@ -99,6 +99,10 @@ boost::shared_ptr<Order> Order::getOrder
case ORDER_ALTERATE_CLEAR_AREA:
{
return boost::shared_ptr<Order>(new
OrderAlterateClearArea(netData+1, netDataLength-1));
+ }
+ case ORDER_ALTERATE_HARVEST_AREA:
+ {
+ return boost::shared_ptr<Order>(new
OrderAlterateHarvestArea(netData+1, netDataLength-1));
}
case ORDER_NULL:
{
diff -r 5a09e0253c6f src/Order.h
--- a/src/Order.h Tue Dec 04 01:29:41 2007 +0100
+++ b/src/Order.h Sun Dec 30 22:19:20 2007 -0400
@@ -362,6 +362,14 @@ public:
Uint8 getOrderType(void) { return ORDER_ALTERATE_CLEAR_AREA; }
};
+class OrderAlterateHarvestArea:public OrderAlterateArea
+{
+public:
+ OrderAlterateHarvestArea(const Uint8 *data, int dataLength) :
OrderAlterateArea(data, dataLength) { }
+ OrderAlterateHarvestArea(Uint8 teamNumber, Uint8 type, BrushAccumulator
*acc) : OrderAlterateArea(teamNumber, type, acc) { }
+
+ Uint8 getOrderType(void) { return ORDER_ALTERATE_HARVEST_AREA; }
+};
// Misc orders
diff -r 5a09e0253c6f src/Unit.cpp
--- a/src/Unit.cpp Tue Dec 04 01:29:41 2007 +0100
+++ b/src/Unit.cpp Sun Jan 06 01:11:57 2008 -0400
@@ -104,7 +104,7 @@ Unit::Unit(int x, int y, Uint16 gid, Sin
else
trigHP = 20;
- // warriors wait more tiem before going to eat
+ // warriors wait more time before going to eat
hungry = HUNGRY_MAX;
hungryness = race->hungryness;
if (performance[ATTACK_SPEED])
@@ -826,6 +826,25 @@ void Unit::handleActivity(void)
else
activity=ACT_RANDOM;
}
+
+ //TMP
+ //We look for harvesting area
+ int mapWidth = owner->map->getW();
+ int mapHeight = owner->map->getH();
+ for(int i = 0; i < mapWidth; i++)
+ for(int j = 0; j < mapHeight; j++)
+ if(owner->map->isHarvestAreaLocal(i,j))
+ {
+/* assert(destinationPurprose>=WALK);
+ assert(destinationPurprose<ARMOR);*/
+ activity=ACT_HARVEST_AREA;
+ targetX = i;
+ targetY = j;
+ attachedBuilding=NULL;
+ targetBuilding=NULL;
+ return;
+
+ }
}
}
}
@@ -1337,6 +1356,48 @@ void Unit::handleDisplacement(void)
}
break;
+ case ACT_HARVEST_AREA:
+ {
+#if 0
+ displacement=DIS_GOING_TO_RESSOURCE;
+ //TMP
+ validTarget=true;
+ int distance=owner->map->warpDistSquare(targetX,
targetY, posX, posY);
+// if (verbose)
+ printf("guid=(%d) ACT_HARVEST_AREA
distance=%d\n", gid, distance);
+
+ if (distance<=1)
+ {
+ validTarget=false;
+ if (typeNum==WORKER)
+ displacement=DIS_CLEARING_RESSOURCES;
+ }
+ else if (typeNum==WORKER)
+ {
+ if (distance<=5)
+ {
+ Map *map=owner->map;
+ for (int tdx=-1; tdx<=1; tdx++)
+ for (int tdy=-1; tdy<=1; tdy++)
+ {
+ int x=posX+tdx;
+ int y=posY+tdy;
+ if
(map->warpDistSquare(x, y, targetX, targetY)<=1
+ /*&&
map->isRessourceTakeable(x, y, attachedBuilding->clearingRessources)*/)
+ {
+ dx=tdx;
+ dy=tdy;
+
validTarget=false;
+
displacement=DIS_CLEARING_RESSOURCES;
+
//movement=MOV_HARVESTING;
+ return;
+ }
+ }
+ }
+ }
+#endif
+ }
+ break;
default:
{
assert(false);
diff -r 5a09e0253c6f src/Unit.h
--- a/src/Unit.h Tue Dec 04 01:29:41 2007 +0100
+++ b/src/Unit.h Thu Jan 03 00:31:39 2008 -0400
@@ -112,7 +112,8 @@ public:
ACT_RANDOM=0,
ACT_FILLING=1,
ACT_FLAG=2,
- ACT_UPGRADING=3
+ ACT_UPGRADING=3,
+ ACT_HARVEST_AREA=4,
};
enum Displacement
@@ -134,7 +135,9 @@ public:
DIS_GOING_TO_BUILDING=18,
DIS_ENTERING_BUILDING=20,
DIS_INSIDE=22,
- DIS_EXITING_BUILDING=24
+ DIS_EXITING_BUILDING=24,
+
+ DIST_GOING_TO_HARVEST_AREA=26,
};
enum Movement
- [glob2-devel] Progress at "Harvesting area brush" http://cofundos.org/project.php?id=48,
Leo Wandersleb <=