bugfix for adding units to every player from map scripts

This commit is contained in:
devZoGok
2023-12-30 12:19:45 +02:00
parent d1bd4cc052
commit f86edaf3c0
5 changed files with 28 additions and 27 deletions
+7 -4
View File
@@ -2,14 +2,12 @@ map = {
numWaterBodies = 0,
size = {x = 123.000000, y = 100, z = 123.000000},
impassibleNodeValue = 65535,
numPlayers = 1,
numSpawnPoints = 1,
spawnPoints = {
{x = -50.000000, y = 0.000000, z = -50.000000},
{x = 0.000000, y = 0.000000, z = 0.000000},
},
players = {
{
numResourceDeposits = 12,
resourceDeposits = {
{id = 0, pos = {x = -2.211494, y = 0.000000, z = -10.615765}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
{id = 0, pos = {x = -2.211494, y = 0.000000, z = -10.615765}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
@@ -24,10 +22,15 @@ resourceDeposits = {
{id = 0, pos = {x = -5.240124, y = 0.000004, z = 11.061106}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
{id = 0, pos = {x = -5.381660, y = 0.000004, z = 11.083004}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
},
numUnits = 1,
units = {
{id = 3, pos = {x = -50.000000, y = 0.000000, z = -50.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
}
},
{
resourceDeposits = {},
units = {
{id = 3, pos = {x = 0.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}
}
}
},
numCells = 289,
+13 -14
View File
@@ -124,7 +124,7 @@ namespace battleship{
}
}
void Map::loadPlayerGameObjects(Player *player){
void Map::loadPlayerGameObjects(){
AssetManager *assetManager = AssetManager::getSingleton();
string path = GameManager::getSingleton()->getPath();
assetManager->load(path + DEFAULT_TEXTURE);
@@ -138,23 +138,22 @@ namespace battleship{
int numPlayers = SOL_LUA_VIEW["numPlayers"];
for(int i = 0; i < numPlayers; i++){
if(i == 0){
string resDepInd = "resourceDeposits";
SOL_LUA_VIEW.script("numResourceDeposits = #" + mapTable + "." + playerInd + "[" + to_string(i + 1) + "]." + resDepInd);
int numNpcObjs = SOL_LUA_VIEW["numResourceDeposits"];
string resDepInd = "resourceDeposits";
SOL_LUA_VIEW.script("numResourceDeposits = #" + mapTable + "." + playerInd + "[" + to_string(i + 1) + "]." + resDepInd);
int numNpcObjs = SOL_LUA_VIEW["numResourceDeposits"];
Player *player = Game::getSingleton()->getPlayer(i);
for(int j = 0; j < numNpcObjs; j++){
sol::table npcObjTable = SOL_LUA_VIEW[mapTable][playerInd][i + 1][resDepInd][j + 1];
int id = npcObjTable["id"];
for(int j = 0; j < numNpcObjs; j++){
sol::table npcObjTable = SOL_LUA_VIEW[mapTable][playerInd][i + 1][resDepInd][j + 1];
int id = npcObjTable["id"];
sol::table posTable = npcObjTable["pos"];
Vector3 pos = Vector3(posTable["x"], posTable["y"], posTable["z"]);
sol::table posTable = npcObjTable["pos"];
Vector3 pos = Vector3(posTable["x"], posTable["y"], posTable["z"]);
sol::table rotTable = npcObjTable["rot"];
Quaternion rot = Quaternion(rotTable["w"], rotTable["x"], rotTable["y"], rotTable["z"]);
sol::table rotTable = npcObjTable["rot"];
Quaternion rot = Quaternion(rotTable["w"], rotTable["x"], rotTable["y"], rotTable["z"]);
player->addResourceDeposit(GameObjectFactory::createResourceDeposit(player, id, pos, rot));
}
player->addResourceDeposit(GameObjectFactory::createResourceDeposit(player, id, pos, rot));
}
//int spawnPointId = SOL_LUA_STATE[mapTable]["spawnPointInd"][i + 1][spawnPointId];
+1 -1
View File
@@ -48,7 +48,7 @@ namespace battleship{
void unload();
int getCellId(vb01::Vector3);
bool isPointWithinTerrainObject(vb01::Vector3, int);
void loadPlayerGameObjects(Player*);
void loadPlayerGameObjects();
inline std::string getMapName(){return mapName;}
inline vb01::Node* getNodeParent(){return terrainNode;}
inline vb01::Vector3 getCellSize(){return CELL_SIZE;}
+4 -5
View File
@@ -63,11 +63,10 @@ namespace battleship{
else{
int numPlayers = map->getNumSpawnPoints();
for(int i = 0; i < numPlayers; i++){
Player *player = new Player(0, 0, 0, Vector3(1, 1, 1));
map->loadPlayerGameObjects(player);
addPlayer(player);
}
for(int i = 0; i < numPlayers; i++)
addPlayer(new Player(0, 0, 0, Vector3(1, 1, 1)));
map->loadPlayerGameObjects();
}
}
+3 -3
View File
@@ -39,11 +39,11 @@ namespace battleship{
for(int i = 0; i < numPlayers; i++){
bool cpuPlayer = (i < numPlayers - 1);
string name = (cpuPlayer ? "CPU player #" + to_string(i) : "Player");
Player *player = new Player(0, 0, i, Vector3(1, 1, 1), cpuPlayer, map->getSpawnPoint(i), name);
map->loadPlayerGameObjects(player);
Game::getSingleton()->addPlayer(player);
Game::getSingleton()->addPlayer(new Player(0, 0, i, Vector3(1, 1, 1), cpuPlayer, map->getSpawnPoint(i), name));
}
map->loadPlayerGameObjects();
ConcreteGuiManager::getSingleton()->readLuaScreenScript("inGame.lua");
StateManager *stateManager = GameManager::getSingleton()->getStateManager();