void ReturnResource(CUnit* unit) { CUnit* dest; if (unit->CurrentResource == 0 || unit->ResourcesHeld == 0) { SendResponseMessage("Unit has no resources to return.\n", 3); return; } dest = FindDeposit(unit, unit->X, unit->Y, FIND_RESOURCE_RANGE, unit->CurrentResource); if (dest != NoUnitP) { SendCommandReturnGoods(unit, dest, 1); // TODO: don't know what StopResourceFlag corresponds to in 2.2.4 code // unit->StopResourceFlag = 1; } else { SendResponseMessage("Unable to find location to return resource within range.\n", 3); return; } SendResponseMessage("OK\n", 3); }
/** ** 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); // } } }
/** ** Do next replay */ static void DoNextReplay() { Assert(ReplayStep != 0); NextLogCycle = ReplayStep->GameCycle; if (NextLogCycle != GameCycle) { return; } const int unitSlot = ReplayStep->UnitNumber; const char *action = ReplayStep->Action.c_str(); const int flags = ReplayStep->Flush; const Vec2i pos(ReplayStep->PosX, ReplayStep->PosY); const int arg1 = ReplayStep->PosX; const int arg2 = ReplayStep->PosY; CUnit *unit = unitSlot != -1 ? &UnitManager.GetSlotUnit(unitSlot) : NULL; CUnit *dunit = (ReplayStep->DestUnitNumber != -1 ? &UnitManager.GetSlotUnit(ReplayStep->DestUnitNumber) : NULL); const char *val = ReplayStep->Value.c_str(); const int num = ReplayStep->Num; Assert(unitSlot == -1 || ReplayStep->UnitIdent == unit->Type->Ident); if (SyncRandSeed != ReplayStep->SyncRandSeed) { #ifdef DEBUG if (!ReplayStep->SyncRandSeed) { // Replay without the 'sync info ThisPlayer->Notify("%s", _("No sync info for this replay !")); } else { ThisPlayer->Notify(_("Replay got out of sync (%lu) !"), GameCycle); DebugPrint("OUT OF SYNC %u != %u\n" _C_ SyncRandSeed _C_ ReplayStep->SyncRandSeed); DebugPrint("OUT OF SYNC GameCycle %lu \n" _C_ GameCycle); Assert(0); // ReplayStep = 0; // NextLogCycle = ~0UL; // return; } #else ThisPlayer->Notify("%s", _("Replay got out of sync !")); ReplayStep = 0; NextLogCycle = ~0UL; return; #endif } if (!strcmp(action, "stop")) { SendCommandStopUnit(*unit); } else if (!strcmp(action, "stand-ground")) { SendCommandStandGround(*unit, flags); } else if (!strcmp(action, "defend")) { SendCommandDefend(*unit, *dunit, flags); } else if (!strcmp(action, "follow")) { SendCommandFollow(*unit, *dunit, flags); } else if (!strcmp(action, "move")) { SendCommandMove(*unit, pos, flags); //Wyrmgus start } else if (!strcmp(action, "pick-up")) { SendCommandPickUp(*unit, *dunit, flags); //Wyrmgus end } else if (!strcmp(action, "repair")) { SendCommandRepair(*unit, pos, dunit, flags); } else if (!strcmp(action, "auto-repair")) { SendCommandAutoRepair(*unit, arg1); } else if (!strcmp(action, "attack")) { SendCommandAttack(*unit, pos, dunit, flags); } else if (!strcmp(action, "attack-ground")) { SendCommandAttackGround(*unit, pos, flags); //Wyrmgus start } else if (!strcmp(action, "use")) { SendCommandUse(*unit, *dunit, flags); } else if (!strcmp(action, "trade")) { SendCommandTrade(*unit, *dunit, flags); //Wyrmgus end } else if (!strcmp(action, "patrol")) { SendCommandPatrol(*unit, pos, flags); } else if (!strcmp(action, "board")) { SendCommandBoard(*unit, *dunit, flags); } else if (!strcmp(action, "unload")) { SendCommandUnload(*unit, pos, dunit, flags); } else if (!strcmp(action, "build")) { SendCommandBuildBuilding(*unit, pos, *UnitTypeByIdent(val), flags); } else if (!strcmp(action, "dismiss")) { SendCommandDismiss(*unit); } else if (!strcmp(action, "resource-loc")) { SendCommandResourceLoc(*unit, pos, flags); } else if (!strcmp(action, "resource")) { SendCommandResource(*unit, *dunit, flags); } else if (!strcmp(action, "return")) { SendCommandReturnGoods(*unit, dunit, flags); } else if (!strcmp(action, "train")) { //Wyrmgus start // SendCommandTrainUnit(*unit, *UnitTypeByIdent(val), flags); SendCommandTrainUnit(*unit, *UnitTypeByIdent(val), num, flags); //Wyrmgus end } else if (!strcmp(action, "cancel-train")) { SendCommandCancelTraining(*unit, num, (val && *val) ? UnitTypeByIdent(val) : NULL); } else if (!strcmp(action, "upgrade-to")) { SendCommandUpgradeTo(*unit, *UnitTypeByIdent(val), flags); } else if (!strcmp(action, "cancel-upgrade-to")) { SendCommandCancelUpgradeTo(*unit); //Wyrmgus start } else if (!strcmp(action, "transform-into")) { SendCommandTransformInto(*unit, *UnitTypeByIdent(val), flags); //Wyrmgus end } else if (!strcmp(action, "research")) { //Wyrmgus start // SendCommandResearch(*unit, *CUpgrade::Get(val), flags); SendCommandResearch(*unit, *CUpgrade::Get(val), num, flags); //Wyrmgus end } else if (!strcmp(action, "cancel-research")) { SendCommandCancelResearch(*unit); //Wyrmgus start } else if (!strcmp(action, "learn-ability")) { SendCommandLearnAbility(*unit, *CUpgrade::Get(val)); //Wyrmgus end } else if (!strcmp(action, "spell-cast")) { SendCommandSpellCast(*unit, pos, dunit, num, flags); } else if (!strcmp(action, "auto-spell-cast")) { SendCommandAutoSpellCast(*unit, num, arg1); //Wyrmgus start } else if (!strcmp(action, "rally-point")) { SendCommandRallyPoint(*unit, pos); } else if (!strcmp(action, "quest")) { SendCommandQuest(*unit, GetQuest(val)); } else if (!strcmp(action, "buy")) { SendCommandBuy(*unit, dunit, num); } else if (!strcmp(action, "produce-resource")) { SendCommandProduceResource(*unit, num); } else if (!strcmp(action, "sell-resource")) { SendCommandSellResource(*unit, arg1, num); } else if (!strcmp(action, "buy-resource")) { SendCommandBuyResource(*unit, arg1, num); //Wyrmgus end } else if (!strcmp(action, "diplomacy")) { int state; if (!strcmp(val, "neutral")) { state = DiplomacyNeutral; } else if (!strcmp(val, "allied")) { state = DiplomacyAllied; } else if (!strcmp(val, "enemy")) { state = DiplomacyEnemy; //Wyrmgus start } else if (!strcmp(val, "overlord")) { state = DiplomacyOverlord; } else if (!strcmp(val, "vassal")) { state = DiplomacyVassal; //Wyrmgus end } else if (!strcmp(val, "crazy")) { state = DiplomacyCrazy; } else { DebugPrint("Invalid diplomacy command: %s" _C_ val); state = -1; } SendCommandDiplomacy(arg1, state, arg2); } else if (!strcmp(action, "shared-vision")) { bool state; state = atoi(val) ? true : false; SendCommandSharedVision(arg1, state, arg2); } else if (!strcmp(action, "input")) { if (val[0] == '-') { CclCommand(val + 1, false); } else { HandleCheats(val); } } else if (!strcmp(action, "chat")) { SetMessage("%s", val); PlayGameSound(GameSounds.ChatMessage.Sound, MaxSampleVolume); } else if (!strcmp(action, "quit")) { CommandQuit(arg1); } else { DebugPrint("Invalid action: %s" _C_ action); } ReplayStep = ReplayStep->Next; NextLogCycle = ReplayStep ? (unsigned)ReplayStep->GameCycle : ~0UL; }