Exemple #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;
}
Exemple #2
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;
    }
}