Esempio n. 1
0
/**
**  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;
}
Esempio n. 2
0
/**
**	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);
//	    }
    }
}
Esempio n. 3
0
void HandleCommand() {
    char* token;
    int unitID;
    CUnit* unit;
    int actionID;
    int resourceType;
    int x, y;
    char* typeID;
    CUnitType* type;
    int destID;
    CUnit* dest;

    token = NextToken();
    if (!token) return;
    unitID = atoi(token);
    unit = GetUnitByID(unitID);
    if (!unit) {
        SendResponseMessage("Unknown unit.\n", 3);
        return;
    }

    token = NextToken();
    if (!token) return;
    actionID = atoi(token);
    switch (actionID) {
        case 0: // NOOP
            //			SendResponseMessage("OK\n", 3);
            break;

        case 1: // STOP
            SendCommandStopUnit(unit);
            //			SendResponseMessage("OK\n", 3);
            break;

        case 2: // MoveTo <X> <Y>
            token = NextToken();
            if (token == NULL) {
                SendResponseMessage("Bad arguments to Move Action.\n", 3);
                return;
            }
            x = atoi(token);
            token = NextToken();
            if (token == NULL) {
                SendResponseMessage("Bad arguments to Move Action.\n", 3);
                return;
            }
            y = atoi(token);
            SendCommandMove(unit, x, y, 1);
            //			SendResponseMessage("OK\n", 3);
            break;

        case 3: // Build <Type> <X> <Y>
            token = NextToken();
            if (token == NULL) {
                SendResponseMessage("Bad arguments to Build Action.\n", 3);
                return;
            }
            typeID = token;
            type = UnitTypeByIdent(typeID);
            if (type == NULL) {
                SendResponseMessage("Unknown type to build.\n", 3);
                return;
            }
            // If it's a building, train the unit.
            if (unit->Type->Building)
                SendCommandTrainUnit(unit, type, 1);
            else // otherwise, build a building.
            {
                token = NextToken();
                if (token == NULL) {
                    SendResponseMessage("Bad arguments to Build Action.\n", 3);
                    return;
                }
                x = atoi(token);
                token = NextToken();
                if (token == NULL) {
                    SendResponseMessage("Bad arguments to Build Action.\n", 3);
                    return;
                }
                y = atoi(token);
                SendCommandBuildBuilding(unit, x, y, type, 1);
            }
            SendResponseMessage("OK\n", 3);
            break;

        case 4: // Attack <UnitID>
            token = NextToken();
            if (!token) return;
            destID = atoi(token);
            dest = GetUnitByID(destID);
            if (!dest) {
                SendResponseMessage("Unknown unit to attack.\n", 3);
                return;
            }
            SendCommandAttack(unit, 0, 0, dest, 1);
            SendResponseMessage("OK\n", 3);
            break;

        case 5: // Repair <UnitID>
            token = NextToken();
            if (!token) return;
            destID = atoi(token);
            dest = GetUnitByID(destID);
            if (!dest) {
                SendResponseMessage("Unknown unit to repair.\n", 3);
                return;
            }
            SendCommandRepair(unit, 0, 0, dest, 1);
            SendResponseMessage("OK\n", 3);
            break;

        case 6: // Harvest <ResourceType>
            token = NextToken();
            if (!token) return;
            resourceType = atoi(token); // GOLD = 1, WOOD = 2
            FindAndGatherResource(unit, resourceType);
            break;

        case 7: // Return resource
            ReturnResource(unit);
            break;

        case 8: // Harvest unit (gold/oil) <DestUnit>
            token = NextToken();
            if (!token) {
                SendResponseMessage("Invalid harvest argument.\n", 3);
                return;
            }
            destID = atoi(token);
            dest = GetUnitByID(destID);
            if (dest == NoUnitP) {
                SendResponseMessage("Invalid resource unit ID.\n", 3);
                return;
            }
            SendCommandResource(unit, dest, 1);
            SendResponseMessage("OK\n", 3);
            break;

        case 9: // Harvest terrain (wood) <X> <Y>
            token = NextToken();
            if (!token) {
                SendResponseMessage("Invalid harvest argument.\n", 3);
                return;
            }
            x = atoi(token);
            token = NextToken();
            if (!token) {
                SendResponseMessage("Invalid harvest argument.\n", 3);
                return;
            }
            y = atoi(token);
            SendCommandResourceLoc(unit, x, y, 1);
            SendResponseMessage("OK\n", 3);
            break;

        case 10: // Harvest location <ResourceType> <X> <Y>
            token = NextToken();
            if (!token) {
                SendResponseMessage("Invalid harvest argument.\n", 3);
                return;
            }
            resourceType = atoi(token); // GOLD = 1, WOOD = 2
            token = NextToken();
            if (!token) {
                SendResponseMessage("Invalid harvest argument.\n", 3);
                return;
            }
            x = atoi(token);
            token = NextToken();
            if (!token) {
                SendResponseMessage("Invalid harvest argument.\n", 3);
                return;
            }
            y = atoi(token);
            HarvestResAtLoc(resourceType, x, y);
            break;

        default:
            SendResponseMessage("Unknown command.\n", 3);
            return;
    }
}