mirror of
https://github.com/ApfelTeeSaft/PlanetFleet.git
synced 2026-08-26 19:33:38 +00:00
adding choosable and civilian players separately
This commit is contained in:
+1
-1
@@ -62,7 +62,7 @@ namespace battleship{
|
||||
|
||||
Map *map = Map::getSingleton();
|
||||
map->load(mapName);
|
||||
map->loadPlayerGameObjects();
|
||||
map->loadPlayersGameObjects();
|
||||
|
||||
Camera *cam = Root::getSingleton()->getCamera();
|
||||
cam->setPosition(Map::getSingleton()->getSpawnPoint(playerId) + Vector3(1, 1, 1) * configData::CAMERA_DISTANCE);
|
||||
|
||||
@@ -420,52 +420,59 @@ namespace battleship{
|
||||
}
|
||||
}
|
||||
|
||||
//TODO move minimap loading elsewhere
|
||||
void Map::loadPlayerGameObjects(){
|
||||
vector<Player*> players = Game::getSingleton()->getPlayers(true);
|
||||
void Map::loadPlayerGameObjects(Player *player, sol::table playerTbl){
|
||||
string resDepInd = "resourceDeposits";
|
||||
sol::state_view SOL_LUA_VIEW = generateView();
|
||||
string playerInd = "players";
|
||||
sol::table resDepTbl = playerTbl["resourceDeposits"];
|
||||
int numNpcObjs = resDepTbl.size();
|
||||
|
||||
for(int i = 0; i < players.size(); i++){
|
||||
string resDepInd = "resourceDeposits";
|
||||
SOL_LUA_VIEW.script("numResourceDeposits = #" + mapTable + "." + playerInd + "[" + to_string(i + 1) + "]." + resDepInd);
|
||||
int numNpcObjs = SOL_LUA_VIEW["numResourceDeposits"];
|
||||
Player *player = players[i];
|
||||
for(int j = 0; j < numNpcObjs; j++){
|
||||
sol::table npcObjTable = resDepTbl[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"]);
|
||||
int initAmmount = resDepTbl[j + 1]["initAmmount"];
|
||||
|
||||
sol::table rotTable = npcObjTable["rot"];
|
||||
Quaternion rot = Quaternion(rotTable["w"], rotTable["x"], rotTable["y"], rotTable["z"]);
|
||||
int initAmmount = SOL_LUA_VIEW[mapTable][playerInd][i + 1][resDepInd][j + 1]["initAmmount"];
|
||||
|
||||
player->addResourceDeposit(GameObjectFactory::createResourceDeposit(player, id, pos, rot, initAmmount));
|
||||
}
|
||||
|
||||
//int spawnPointId = SOL_LUA_STATE[mapTable]["spawnPointInd"][i + 1][spawnPointId];
|
||||
string unitInd = "units";
|
||||
SOL_LUA_VIEW.script("numUnits = #" + mapTable + "." + playerInd + "[" + to_string(i + 1) + "]." + unitInd);
|
||||
int numUnits = SOL_LUA_VIEW["numUnits"];
|
||||
|
||||
for(int j = 0; j < numUnits; j++){
|
||||
sol::table unitTable = SOL_LUA_VIEW[mapTable][playerInd][i + 1][unitInd][j + 1];
|
||||
|
||||
string posInd = "pos";
|
||||
Vector3 pos = Vector3(unitTable[posInd]["x"], unitTable[posInd]["y"], unitTable[posInd]["z"]);
|
||||
|
||||
string rotInd = "rot";
|
||||
Quaternion rot = Quaternion(unitTable[rotInd]["w"], unitTable[rotInd]["x"], unitTable[rotInd]["x"], unitTable[rotInd]["x"]);
|
||||
|
||||
int id = unitTable["id"];
|
||||
int buildStatus = unitTable["buildStatus"].get_or(0);
|
||||
player->addUnit(GameObjectFactory::createUnit(player, id, pos, rot, buildStatus));
|
||||
}
|
||||
player->addResourceDeposit(GameObjectFactory::createResourceDeposit(player, id, pos, rot, initAmmount));
|
||||
}
|
||||
|
||||
string unitInd = "units";
|
||||
sol::table unitsTbl = playerTbl["units"];
|
||||
int numUnits = unitsTbl.size();
|
||||
|
||||
for(int j = 0; j < numUnits; j++){
|
||||
sol::table unitTable = unitsTbl[j + 1];
|
||||
|
||||
string posInd = "pos";
|
||||
Vector3 pos = Vector3(unitTable[posInd]["x"], unitTable[posInd]["y"], unitTable[posInd]["z"]);
|
||||
|
||||
string rotInd = "rot";
|
||||
Quaternion rot = Quaternion(unitTable[rotInd]["w"], unitTable[rotInd]["x"], unitTable[rotInd]["x"], unitTable[rotInd]["x"]);
|
||||
|
||||
int id = unitTable["id"];
|
||||
int buildStatus = unitTable["buildStatus"].get_or(0);
|
||||
player->addUnit(GameObjectFactory::createUnit(player, id, pos, rot, buildStatus));
|
||||
}
|
||||
}
|
||||
|
||||
//TODO move minimap loading elsewhere
|
||||
void Map::loadPlayersGameObjects(){
|
||||
Game *game = Game::getSingleton();
|
||||
vector<Player*> choosablePlayers = game->getPlayers(false);
|
||||
sol::state_view SOL_LUA_VIEW = generateView();
|
||||
|
||||
for(int i = 0; i < choosablePlayers.size(); i++){
|
||||
sol::table playerTbl = SOL_LUA_VIEW[mapTable]["choosablePlayers"][i + 1];
|
||||
loadPlayerGameObjects(choosablePlayers[i], playerTbl);
|
||||
}
|
||||
|
||||
sol::table civPlayerTbl = SOL_LUA_VIEW[mapTable]["civilianPlayer"];
|
||||
loadPlayerGameObjects(game->getCivilianPlayer(), civPlayerTbl);
|
||||
|
||||
Minimap::getSingleton()->load();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#include <vector.h>
|
||||
#include <util.h>
|
||||
|
||||
#include <solUtil.h>
|
||||
|
||||
namespace vb01{
|
||||
class Model;
|
||||
class Material;
|
||||
@@ -76,7 +78,7 @@ namespace battleship{
|
||||
std::vector<vb01::RayCaster::CollisionResult> raycastTerrain(vb01::Vector3, vb01::Vector3, bool);
|
||||
int getCellId(vb01::Vector3, bool = true);
|
||||
bool isPointWithinTerrainObject(vb01::Vector3, int);
|
||||
void loadPlayerGameObjects();
|
||||
void loadPlayersGameObjects();
|
||||
int getNumMapSpawnPoints(std::string = "");
|
||||
std::vector<int> getSurroundingCells(vb01::Vector3, int);
|
||||
void blockCells(Unit*);
|
||||
@@ -111,6 +113,7 @@ namespace battleship{
|
||||
void loadLights();
|
||||
void loadSkybox();
|
||||
void loadCells();
|
||||
void loadPlayerGameObjects(Player*, sol::table);
|
||||
void loadTerrainObject(int);
|
||||
void unloadTerrainObjects();
|
||||
void unloadCells();
|
||||
@@ -121,5 +124,4 @@ namespace battleship{
|
||||
template<typename T> int bsearch(std::vector<T>, T, float);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace battleship{
|
||||
for(int i = 0; i < numPlayers; i++)
|
||||
game->addPlayer(new Player(0, 0, 0, Vector3(1, 1, 1)));
|
||||
|
||||
map->loadPlayerGameObjects();
|
||||
map->loadPlayersGameObjects();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user