/** ** Move to forest. ** ** @param unit Pointer to worker unit. ** ** @return TRUE if reached, otherwise FALSE. */ local int MoveToWood(Unit* unit) { int x; int y; int dx; int dy; if( !HandleActionMove(unit) ) { // reached end-point return 0; } // FIXME: reached nearly must be returned by HandleActionMove! // // reached nearly? and is there wood? // if( unit->Command.Data.Move.Range ) { // FIXME: not correct on map border :( ++unit->Command.Data.Move.DX; ++unit->Command.Data.Move.DY; } x=unit->Command.Data.Move.DX; y=unit->Command.Data.Move.DY; dx=x-unit->X; dy=y-unit->Y; DebugLevel3("Why %d,%d = %d\n",dx,dy,ForestOnMap(x,y)); if( dx<-1 || dx>1 || dy<-1 || dy>1 || !ForestOnMap(x,y) ) { if( FindWoodInSight(unit ,&unit->Command.Data.Move.DX ,&unit->Command.Data.Move.DY) ) { // Move to new wood position unit->Command.Data.Move.Fast=1; unit->Command.Data.Move.Goal=NoUnitP; unit->Command.Data.Move.Range=2; unit->Command.Action=UnitActionHarvest; if( unit->Command.Data.Move.DX ) { unit->Command.Data.Move.DX--; } if( unit->Command.Data.Move.DY ) { unit->Command.Data.Move.DY--; } } return 0; } unit->Command.Action=UnitActionHarvest; // FIXME: don't chop the same wood! // turn to wood UnitNewHeadingFromXY(unit,dx,dy); if(unit -> WoodToHarvest != CHOP_FOR_WOOD) { unit -> Value = unit -> WoodToHarvest; } else { unit -> Value=CHOP_FOR_WOOD; } DebugCheck( unit->Wait!=1 ); return 1; }
bool CMap::IsTerrainResourceOnMap(const Vec2i &pos, int resource) const { // TODO: Hard coded stuff. if (resource == WoodCost) { return ForestOnMap(pos); } return false; }
/** ** Called when right button is pressed ** ** @param x X map tile position. ** @param y Y map tile position. */ global void DoRightButton(int x,int y) { int i; Unit* dest; Unit* unit; UnitType* type; int action; int acknowledged; // // No unit selected // if( !NumSelected ) { return; } // // Unit selected isn't owned by the player. // You can't select your own units + foreign unit(s). // if( Selected[0]->Player!=ThisPlayer ) { return; } acknowledged=0; for( i=0; i<NumSelected; ++i ) { unit=Selected[i]; DebugCheck( !unit ); type=unit->Type; if( !acknowledged ) { PlayUnitSound(unit,VoiceAcknowledging); acknowledged=1; } action=type->MouseAction; DebugLevel3(__FUNCTION__": Mouse action %d\n",action); // // Enter transporters? // dest=UnitOnMapTile(x,y); if( dest && dest->Type->Transporter && dest->Player==ThisPlayer && unit->Type->UnitType==UnitTypeLand ) { dest->Blink=3; DebugLevel3(__FUNCTION__": Board transporter\n"); SendCommandBoard(unit,dest); continue; } // // Peon/Peasant // if( action==MouseActionHarvest ) { DebugLevel3("Action %x\n",TheMap.ActionMap[x+y*TheMap.Width]); if( type->Type==UnitPeonWithWood || type->Type==UnitPeasantWithWood || type->Type==UnitPeonWithGold || type->Type==UnitPeasantWithGold ) { dest=UnitOnMapTile(x,y); if( dest ) { dest->Blink=3; if( dest->Type->StoresGold && (type->Type==UnitPeonWithGold || type->Type==UnitPeasantWithGold) ) { DebugLevel3("GOLD-DEPOSIT\n"); // FIXME: return to this depot?? SendCommandReturnGoods(unit); continue; } if( (dest->Type->StoresWood || dest->Type->StoresGold) && (type->Type==UnitPeonWithWood || type->Type==UnitPeasantWithWood) ) { DebugLevel3("WOOD-DEPOSIT\n"); // FIXME: return to this depot?? SendCommandReturnGoods(unit); continue; } } } else { if( ForestOnMap(x,y) ) { SendCommandHarvest(unit,x,y); continue; } if( (dest=GoldMineOnMap(x,y)) ) { dest->Blink=3; DebugLevel3("GOLD-MINE\n"); SendCommandMineGold(unit,dest); continue; } } // FIXME: repair/attack/follow/board dest=TargetOnMapTile(unit,x,y); if( dest ) { dest->Blink=3; if( dest->Player==ThisPlayer ) { // FIXME: SendCommandFollow(unit,x,y,dest); // FIXME: continue; } else { // FIXME: can I attack this unit? SendCommandAttack(unit,x,y,dest); continue; } } // cade: this is default repair action dest=UnitOnMapTile(x,y); if( dest && dest->Type && dest->Player==ThisPlayer && dest->HP<dest->Stats[dest->Player->Player].HitPoints && dest->Type->Building ) { SendCommandRepair(unit,x,y); } else { SendCommandMoveUnit(unit,x,y); } continue; } // // Tanker // if( action==MouseActionHaulOil ) { if( type->Type==UnitTankerOrcFull || type->Type==UnitTankerHumanFull ) { DebugLevel2("Should return to oil deposit\n"); } else { if( (dest=PlatformOnMap(x,y)) ) { dest->Blink=3; DebugLevel2("PLATFORM\n"); SendCommandHaulOil(unit,dest); continue; } } SendCommandMoveUnit(unit,x,y); continue; } // // Fighters // if( action==MouseActionAttack ) { // FIXME: more units on same tile dest=TargetOnMapTile(unit,x,y); if( dest ) { dest->Blink=3; if( dest->Player==ThisPlayer ) { // FIXME: SendCommandFollow(unit,x,y,dest); // FIXME: continue; } else { // FIXME: can I attack this unit? SendCommandAttack(unit,x,y,dest); continue; } } if( WallOnMap(x,y) ) { DebugLevel3("WALL ON TILE\n"); if( ThisPlayer->Race==PlayerRaceHuman && OrcWallOnMap(x,y) ) { DebugLevel3("HUMAN ATTACKS ORC\n"); SendCommandAttack(unit,x,y,NoUnitP); } if( ThisPlayer->Race==PlayerRaceOrc && HumanWallOnMap(x,y) ) { DebugLevel3("ORC ATTACKS HUMAN\n"); SendCommandAttack(unit,x,y,NoUnitP); } } SendCommandMoveUnit(unit,x,y); continue; } // FIXME: demolish!!!!!!! // FIXME: attack/follow/board ... if( action==MouseActionMove ) { } // if( !unit->Type->Building ) { SendCommandMoveUnit(unit,x,y); // } } }
/* ** Chop the wood. ** Return TRUE if ready, otherwise FALSE. */ local int ChopWood(Unit* unit) { Unit* destu; int flags; extern Animation PeonAttack[]; flags=UnitShowAnimation(unit,PeonAttack); if( (flags&AnimationSound) ) { PlayUnitSound(unit,VoiceTreeChopping); } if( unit->Reset ) { DebugCheck( unit->Wait!=1 ); // // This a work around the bug: "lumber bug" // We give a worker a new command and in the next cycle // the worker is ready chopping. // #if 0 // FIXME: johns+cade: this didn't work with the current code if( unit->NextCommand[0].Action==UnitActionHarvest || unit->NextCommand[0].Action==UnitActionMineGold ) { unit->SubAction=0; return 0; } #endif // // Wood gone while chopping? // if( !ForestOnMap(unit->Command.Data.Move.DX ,unit->Command.Data.Move.DY) ) { if( FindWoodInSight(unit ,&unit->Command.Data.Move.DX ,&unit->Command.Data.Move.DY) ) { unit->Command.Data.Move.Fast=1; unit->Command.Data.Move.Goal=NoUnitP; unit->Command.Data.Move.Range=0; // FIXME: shouldn't it be range=1 ?? DebugCheck( unit->Command.Action!=UnitActionHarvest ); unit->SubAction=0; } else { unit->Command.Action=UnitActionStill; unit->SubAction=0; DebugLevel3("NO-WOOD in sight range\n"); } return 0; } // // Ready chopping wood? // if( !(unit->WoodToHarvest = --unit->Value) ) { // Have wood if( unit->Type->Type==UnitPeon ) { unit->Type=&UnitTypes[UnitPeonWithWood]; } else if( unit->Type->Type==UnitPeasant ) { unit->Type=&UnitTypes[UnitPeasantWithWood]; } else { DebugLevel0("Wrong unit for chopping wood %d\n" ,unit->Type->Type); } // // Update the display. // if( UnitVisible(unit) ) { MustRedraw|=RedrawMap; } if( IsSelected(unit) ) { UpdateBottomPanel(); MustRedraw|=RedrawBottomPanel; } // // Update the map. // MapRemoveWood(unit->Command.Data.Move.DX ,unit->Command.Data.Move.DY); // // Find place to return wood. // unit->Command.Data.Move.SX=unit->X; unit->Command.Data.Move.SY=unit->Y; if( !(destu=FindWoodDeposit(unit->Player,unit->X,unit->Y)) ) { unit->Command.Action=UnitActionStill; unit->SubAction=0; } else { unit->Command.Data.Move.Fast=1; unit->Command.Data.Move.Range=1; unit->Command.Data.Move.Goal=destu; #if 1 // Fast movement need this?? NearestOfUnit(destu,unit->X,unit->Y ,&unit->Command.Data.Move.DX ,&unit->Command.Data.Move.DY); #else unit->Command.Data.Move.DX=destu->X; unit->Command.Data.Move.DY=destu->Y; #endif DebugLevel3("Return to %Zd=%d,%d\n" ,destu-UnitsPool ,unit->Command.Data.Move.DX ,unit->Command.Data.Move.DY); DebugCheck( unit->Command.Action!=UnitActionHarvest ); return 1; } } } return 0; }
/** ** Marks seen tile -- used mainly for the Fog Of War ** ** @param x Map X tile-position. ** @param y Map Y tile-position. */ void CMap::MarkSeenTile(const unsigned int index) { CMapField &mf = *this->Field(index); const int tile = mf.Tile; const int seentile = mf.SeenTile; // // Nothing changed? Seeing already the correct tile. // if (tile == seentile) { return; } mf.SeenTile = tile; #ifdef MINIMAP_UPDATE //rb - GRRRRRRRRRRRR const int y = index / Info.MapWidth; const int x = index - (y * Info.MapWidth); const Vec2i pos = {x, y} #endif if (this->Tileset.TileTypeTable) { #ifndef MINIMAP_UPDATE //rb - GRRRRRRRRRRRR const int y = index / Info.MapWidth; const int x = index - (y * Info.MapWidth); const Vec2i pos(x, y); #endif // Handle wood changes. FIXME: check if for growing wood correct? if (seentile != this->Tileset.RemovedTree && tile == this->Tileset.RemovedTree) { FixNeighbors(MapFieldForest, 1, pos); } else if (seentile == this->Tileset.RemovedTree && tile != this->Tileset.RemovedTree) { FixTile(MapFieldForest, 1, pos); } else if (ForestOnMap(index)) { FixTile(MapFieldForest, 1, pos); FixNeighbors(MapFieldForest, 1, pos); // Handle rock changes. } else if (seentile != this->Tileset.RemovedRock && tile == Map.Tileset.RemovedRock) { FixNeighbors(MapFieldRocks, 1, pos); } else if (seentile == this->Tileset.RemovedRock && tile != Map.Tileset.RemovedRock) { FixTile(MapFieldRocks, 1, pos); } else if (RockOnMap(index)) { FixTile(MapFieldRocks, 1, pos); FixNeighbors(MapFieldRocks, 1, pos); // Handle Walls changes. } else if (this->Tileset.TileTypeTable[tile] == TileTypeHumanWall || this->Tileset.TileTypeTable[tile] == TileTypeOrcWall || this->Tileset.TileTypeTable[seentile] == TileTypeHumanWall || this->Tileset.TileTypeTable[seentile] == TileTypeOrcWall) { MapFixSeenWallTile(pos); MapFixSeenWallNeighbors(pos); } } #ifdef MINIMAP_UPDATE UI.Minimap.UpdateXY(pos); #endif }