/** ** Get player resources. ** ** @param ptr Player ** @return Player resource vector */ local SCM CclGetPlayerResources(SCM ptr) { int i; Player* player; SCM vec; player=CclGetPlayer(ptr); vec=cons_array(gh_int2scm(MaxCosts),NIL); for( i=0; i<MaxCosts; ++i ) { aset1(vec,gh_int2scm(i),gh_int2scm(player->Resources[i])); } return vec; }
/** ** Set ai player algo. ** ** @param l Lua state. */ static int CclSetAiType(lua_State *l) { CPlayer *p; if (lua_gettop(l) < 2) { LuaError(l, "incorrect argument"); } lua_pushvalue(l, 1); p = CclGetPlayer(l); lua_pop(l, 1); p->AiName = LuaToString(l, 2); return 0; }
/** ** Set player resources. ** ** @param ptr Player ** @param vec Resources vector ** @return Old resource vector */ local SCM CclSetPlayerResources(SCM ptr,SCM vec) { int i; Player* player; SCM old; player=CclGetPlayer(ptr); old=cons_array(gh_int2scm(MaxCosts),NIL); for( i=0; i<MaxCosts; ++i ) { aset1(old,gh_int2scm(i),gh_int2scm(player->Resources[i])); } for( i=0; i<MaxCosts; ++i ) { player->Resources[i]=gh_scm2int(gh_vector_ref(vec,gh_int2scm(i))); } return old; }
/** ** Change the diplomacy from player to another player. ** ** @param player Player to change diplomacy. ** @param opponent Player number to change. ** @param state To which state this should be changed. ** ** @return FIXME: should return old state. ** ** @todo FIXME: should return old state. */ local SCM CclSetDiplomacy(SCM player,SCM state,SCM opponent) { int plynr; #if 0 Player* base; base=CclGetPlayer(player); plynr=gh_scm2int(opponent); if( gh_eq_p(state,gh_symbol2scm("allied")) ) { base->Enemy&=~(1<<plynr); base->Allied|=1<<plynr; } else if( gh_eq_p(state,gh_symbol2scm("neutral")) ) { base->Enemy&=~(1<<plynr); base->Allied&=~(1<<plynr); } else if( gh_eq_p(state,gh_symbol2scm("crazy")) ) { base->Enemy|=1<<plynr; base->Allied|=1<<plynr; } else if( gh_eq_p(state,gh_symbol2scm("enemy")) ) { base->Enemy|=1<<plynr; base->Allied&=~(1<<plynr); } #else int base; base=gh_scm2int(player); plynr=gh_scm2int(opponent); // FIXME: must send over network!! if( gh_eq_p(state,gh_symbol2scm("allied")) ) { SendCommandDiplomacy(base,DiplomacyAllied,plynr); } else if( gh_eq_p(state,gh_symbol2scm("neutral")) ) { SendCommandDiplomacy(base,DiplomacyNeutral,plynr); } else if( gh_eq_p(state,gh_symbol2scm("crazy")) ) { SendCommandDiplomacy(base,DiplomacyCrazy,plynr); } else if( gh_eq_p(state,gh_symbol2scm("enemy")) ) { SendCommandDiplomacy(base,DiplomacyEnemy,plynr); } #endif // FIXME: we can return the old state return SCM_UNSPECIFIED; }
/** ** Set player data. ** ** @param l Lua state. */ static int CclSetPlayerData(lua_State *l) { if (lua_gettop(l) < 3) { LuaError(l, "incorrect argument"); } lua_pushvalue(l, 1); CPlayer *p = CclGetPlayer(l); lua_pop(l, 1); const char *data = LuaToString(l, 2); if (!strcmp(data, "Name")) { p->SetName(LuaToString(l, 3)); } else if (!strcmp(data, "RaceName")) { const char *racename = LuaToString(l, 3); p->Race = PlayerRaces.GetRaceIndexByName(racename); if (p->Race == -1) { LuaError(l, "invalid race name '%s'" _C_ racename); } } else if (!strcmp(data, "Resources")) { LuaCheckArgs(l, 4); const std::string res = LuaToString(l, 3); const int resId = GetResourceIdByName(l, res.c_str()); p->SetResource(resId, LuaToNumber(l, 4)); } else if (!strcmp(data, "StoredResources")) { LuaCheckArgs(l, 4); const std::string res = LuaToString(l, 3); const int resId = GetResourceIdByName(l, res.c_str()); p->SetResource(resId, LuaToNumber(l, 4), STORE_BUILDING); // } else if (!strcmp(data, "UnitTypesCount")) { // } else if (!strcmp(data, "AiEnabled")) { // } else if (!strcmp(data, "TotalNumUnits")) { // } else if (!strcmp(data, "NumBuildings")) { // } else if (!strcmp(data, "Supply")) { // } else if (!strcmp(data, "Demand")) { } else if (!strcmp(data, "UnitLimit")) { p->UnitLimit = LuaToNumber(l, 3); } else if (!strcmp(data, "BuildingLimit")) { p->BuildingLimit = LuaToNumber(l, 3); } else if (!strcmp(data, "TotalUnitLimit")) { p->TotalUnitLimit = LuaToNumber(l, 3); } else if (!strcmp(data, "Score")) { p->Score = LuaToNumber(l, 3); } else if (!strcmp(data, "TotalUnits")) { p->TotalUnits = LuaToNumber(l, 3); } else if (!strcmp(data, "TotalBuildings")) { p->TotalBuildings = LuaToNumber(l, 3); } else if (!strcmp(data, "TotalResources")) { LuaCheckArgs(l, 4); const std::string res = LuaToString(l, 3); const int resId = GetResourceIdByName(l, res.c_str()); p->TotalResources[resId] = LuaToNumber(l, 4); } else if (!strcmp(data, "TotalRazings")) { p->TotalRazings = LuaToNumber(l, 3); } else if (!strcmp(data, "TotalKills")) { p->TotalKills = LuaToNumber(l, 3); } else if (!strcmp(data, "SpeedResourcesHarvest")) { LuaCheckArgs(l, 4); const std::string res = LuaToString(l, 3); const int resId = GetResourceIdByName(l, res.c_str()); p->SpeedResourcesHarvest[resId] = LuaToNumber(l, 4); } else if (!strcmp(data, "SpeedResourcesReturn")) { LuaCheckArgs(l, 4); const std::string res = LuaToString(l, 3); const int resId = GetResourceIdByName(l, res.c_str()); p->SpeedResourcesReturn[resId] = LuaToNumber(l, 4); } else if (!strcmp(data, "SpeedBuild")) { p->SpeedBuild = LuaToNumber(l, 3); } else if (!strcmp(data, "SpeedTrain")) { p->SpeedTrain = LuaToNumber(l, 3); } else if (!strcmp(data, "SpeedUpgrade")) { p->SpeedTrain = LuaToNumber(l, 3); } else if (!strcmp(data, "SpeedResearch")) { p->SpeedResearch = LuaToNumber(l, 3); } else { LuaError(l, "Invalid field: %s" _C_ data); } return 0; }
/** ** Get player data. ** ** @param l Lua state. */ static int CclGetPlayerData(lua_State *l) { if (lua_gettop(l) < 2) { LuaError(l, "incorrect argument"); } lua_pushvalue(l, 1); const CPlayer *p = CclGetPlayer(l); lua_pop(l, 1); const char *data = LuaToString(l, 2); if (!strcmp(data, "Name")) { lua_pushstring(l, p->Name.c_str()); return 1; } else if (!strcmp(data, "RaceName")) { lua_pushstring(l, PlayerRaces.Name[p->Race].c_str()); return 1; } else if (!strcmp(data, "Resources")) { LuaCheckArgs(l, 3); const std::string res = LuaToString(l, 3); const int resId = GetResourceIdByName(l, res.c_str()); lua_pushnumber(l, p->Resources[resId] + p->StoredResources[resId]); return 1; } else if (!strcmp(data, "StoredResources")) { LuaCheckArgs(l, 3); const std::string res = LuaToString(l, 3); const int resId = GetResourceIdByName(l, res.c_str()); lua_pushnumber(l, p->StoredResources[resId]); return 1; } else if (!strcmp(data, "MaxResources")) { LuaCheckArgs(l, 3); const std::string res = LuaToString(l, 3); const int resId = GetResourceIdByName(l, res.c_str()); lua_pushnumber(l, p->MaxResources[resId]); return 1; } else if (!strcmp(data, "UnitTypesCount")) { CUnitType *type; LuaCheckArgs(l, 3); type = CclGetUnitType(l); lua_pushnumber(l, p->UnitTypesCount[type->Slot]); return 1; } else if (!strcmp(data, "AiEnabled")) { lua_pushboolean(l, p->AiEnabled); return 1; } else if (!strcmp(data, "TotalNumUnits")) { lua_pushnumber(l, p->GetUnitCount()); return 1; } else if (!strcmp(data, "NumBuildings")) { lua_pushnumber(l, p->NumBuildings); return 1; } else if (!strcmp(data, "Supply")) { lua_pushnumber(l, p->Supply); return 1; } else if (!strcmp(data, "Demand")) { lua_pushnumber(l, p->Demand); return 1; } else if (!strcmp(data, "UnitLimit")) { lua_pushnumber(l, p->UnitLimit); return 1; } else if (!strcmp(data, "BuildingLimit")) { lua_pushnumber(l, p->BuildingLimit); return 1; } else if (!strcmp(data, "TotalUnitLimit")) { lua_pushnumber(l, p->TotalUnitLimit); return 1; } else if (!strcmp(data, "Score")) { lua_pushnumber(l, p->Score); return 1; } else if (!strcmp(data, "TotalUnits")) { lua_pushnumber(l, p->TotalUnits); return 1; } else if (!strcmp(data, "TotalBuildings")) { lua_pushnumber(l, p->TotalBuildings); return 1; } else if (!strcmp(data, "TotalResources")) { LuaCheckArgs(l, 3); const std::string res = LuaToString(l, 3); const int resId = GetResourceIdByName(l, res.c_str()); lua_pushnumber(l, p->TotalResources[resId]); return 1; } else if (!strcmp(data, "TotalRazings")) { lua_pushnumber(l, p->TotalRazings); return 1; } else if (!strcmp(data, "TotalKills")) { lua_pushnumber(l, p->TotalKills); return 1; } else if (!strcmp(data, "SpeedResourcesHarvest")) { LuaCheckArgs(l, 3); const std::string res = LuaToString(l, 3); const int resId = GetResourceIdByName(l, res.c_str()); lua_pushnumber(l, p->SpeedResourcesHarvest[resId]); return 1; } else if (!strcmp(data, "SpeedResourcesReturn")) { LuaCheckArgs(l, 3); const std::string res = LuaToString(l, 3); const int resId = GetResourceIdByName(l, res.c_str()); lua_pushnumber(l, p->SpeedResourcesReturn[resId]); return 1; } else if (!strcmp(data, "SpeedBuild")) { lua_pushnumber(l, p->SpeedBuild); return 1; } else if (!strcmp(data, "SpeedTrain")) { lua_pushnumber(l, p->SpeedTrain); return 1; } else if (!strcmp(data, "SpeedUpgrade")) { lua_pushnumber(l, p->SpeedUpgrade); return 1; } else if (!strcmp(data, "SpeedResearch")) { lua_pushnumber(l, p->SpeedResearch); return 1; } else { LuaError(l, "Invalid field: %s" _C_ data); } return 0; }
/** ** Set player data. ** ** @param l Lua state. */ static int CclSetPlayerData(lua_State *l) { CPlayer *p; const char *data; if (lua_gettop(l) < 3) { LuaError(l, "incorrect argument"); } lua_pushvalue(l, 1); p = CclGetPlayer(l); lua_pop(l, 1); data = LuaToString(l, 2); if (!strcmp(data, "Name")) { p->SetName(LuaToString(l, 3)); } else if (!strcmp(data, "RaceName")) { int i; const char *racename; racename = LuaToString(l, 3); p->Race = 0; for (i = 0; i < PlayerRaces.Count; ++i) { if (!strcmp(racename, PlayerRaces.Name[i])) { p->Race = i; break; } } if (i == PlayerRaces.Count) { LuaError(l, "invalid race name '%s'" _C_ racename); } } else if (!strcmp(data, "Resources")) { const char *res; int i; LuaCheckArgs(l, 4); res = LuaToString(l, 3); for (i = 0; i < MaxCosts; ++i) { if (!strcmp(res, DefaultResourceNames[i])) { break; } } if (i == MaxCosts) { LuaError(l, "Invalid resource \"%s\"" _C_ res); } p->Resources[i] = LuaToNumber(l, 4); // } else if (!strcmp(data, "UnitTypesCount")) { // } else if (!strcmp(data, "AiEnabled")) { // } else if (!strcmp(data, "TotalNumUnits")) { // } else if (!strcmp(data, "NumBuildings")) { // } else if (!strcmp(data, "Supply")) { // } else if (!strcmp(data, "Demand")) { } else if (!strcmp(data, "UnitLimit")) { p->UnitLimit = LuaToNumber(l, 3); } else if (!strcmp(data, "BuildingLimit")) { p->BuildingLimit = LuaToNumber(l, 3); } else if (!strcmp(data, "TotalUnitLimit")) { p->TotalUnitLimit = LuaToNumber(l, 3); } else if (!strcmp(data, "Score")) { p->Score = LuaToNumber(l, 3); } else if (!strcmp(data, "TotalUnits")) { p->TotalUnits = LuaToNumber(l, 3); } else if (!strcmp(data, "TotalBuildings")) { p->TotalBuildings = LuaToNumber(l, 3); } else if (!strcmp(data, "TotalResources")) { const char *res; int i; LuaCheckArgs(l, 3); res = LuaToString(l, 3); for (i = 0; i < MaxCosts; ++i) { if (!strcmp(res, DefaultResourceNames[i])) { break; } } if (i == MaxCosts) { LuaError(l, "Invalid resource \"%s\"" _C_ res); } p->TotalResources[i] = LuaToNumber(l, 4); } else if (!strcmp(data, "TotalRazings")) { p->TotalRazings = LuaToNumber(l, 3); } else if (!strcmp(data, "TotalKills")) { p->TotalKills = LuaToNumber(l, 3); } else { LuaError(l, "Invalid field: %s" _C_ data); } return 0; }
/** ** Get player data. ** ** @param l Lua state. */ static int CclGetPlayerData(lua_State *l) { CPlayer *p; const char *data; if (lua_gettop(l) < 2) { LuaError(l, "incorrect argument"); } lua_pushvalue(l, 1); p = CclGetPlayer(l); lua_pop(l, 1); data = LuaToString(l, 2); if (!strcmp(data, "Name")) { lua_pushstring(l, p->Name.c_str()); return 1; } else if (!strcmp(data, "RaceName")) { lua_pushstring(l, PlayerRaces.Name[p->Race]); return 1; } else if (!strcmp(data, "Resources")) { const char *res; int i; LuaCheckArgs(l, 3); res = LuaToString(l, 3); for (i = 0; i < MaxCosts; ++i) { if (!strcmp(res, DefaultResourceNames[i])) { break; } } if (i == MaxCosts) { LuaError(l, "Invalid resource \"%s\"" _C_ res); } lua_pushnumber(l, p->Resources[i]); return 1; } else if (!strcmp(data, "UnitTypesCount")) { CUnitType *type; LuaCheckArgs(l, 3); type = CclGetUnitType(l); lua_pushnumber(l, p->UnitTypesCount[type->Slot]); return 1; } else if (!strcmp(data, "AiEnabled")) { lua_pushboolean(l, p->AiEnabled); return 1; } else if (!strcmp(data, "TotalNumUnits")) { lua_pushnumber(l, p->TotalNumUnits); return 1; } else if (!strcmp(data, "NumBuildings")) { lua_pushnumber(l, p->NumBuildings); return 1; } else if (!strcmp(data, "Supply")) { lua_pushnumber(l, p->Supply); return 1; } else if (!strcmp(data, "Demand")) { lua_pushnumber(l, p->Demand); return 1; } else if (!strcmp(data, "UnitLimit")) { lua_pushnumber(l, p->UnitLimit); return 1; } else if (!strcmp(data, "BuildingLimit")) { lua_pushnumber(l, p->BuildingLimit); return 1; } else if (!strcmp(data, "TotalUnitLimit")) { lua_pushnumber(l, p->TotalUnitLimit); return 1; } else if (!strcmp(data, "Score")) { lua_pushnumber(l, p->Score); return 1; } else if (!strcmp(data, "TotalUnits")) { lua_pushnumber(l, p->TotalUnits); return 1; } else if (!strcmp(data, "TotalBuildings")) { lua_pushnumber(l, p->TotalBuildings); return 1; } else if (!strcmp(data, "TotalResources")) { const char *res; int i; LuaCheckArgs(l, 3); res = LuaToString(l, 3); for (i = 0; i < MaxCosts; ++i) { if (!strcmp(res, DefaultResourceNames[i])) { break; } } if (i == MaxCosts) { LuaError(l, "Invalid resource \"%s\"" _C_ res); } lua_pushnumber(l, p->TotalResources[i]); return 1; } else if (!strcmp(data, "TotalRazings")) { lua_pushnumber(l, p->TotalRazings); return 1; } else if (!strcmp(data, "TotalKills")) { lua_pushnumber(l, p->TotalKills); return 1; } else { LuaError(l, "Invalid field: %s" _C_ data); } return 0; }