using a civilian player

This commit is contained in:
devZoGok
2025-06-02 19:14:51 +03:00
parent 6898fdf935
commit 575b736e0d
9 changed files with 44 additions and 42 deletions
+13 -7
View File
@@ -12,13 +12,13 @@ spawnPoints = {
},
players = {
{
resourceDeposits = {
{id = 0, pos = {x = 100.000000, y = 0.000000, z = 100.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 1000},
{id = 0, pos = {x = -200.000000, y = 0.000000, z = 50.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 1000},
},
resourceDeposits = {},
units = {
{id = 0, pos = {x = 290.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
{id = 1, pos = {x = 300.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
{id = 18, pos = {x = 300.000000, y = 0.000000, z = 100.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
{id = 2, pos = {x = 300.000000, y = 0.000000, z = 100.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
--{id = 13, pos = {x = 0.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
--{id = 19, pos = {x = 300.000000, y = 0.000000, z = 100.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, buildStatus = 100},
}
,},
{
@@ -27,9 +27,15 @@ spawnPoint = 0,
units = {
{id = 0, pos = {x = 300.000000, y = 0.000000, z = 450.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
{id = 1, pos = {x = -300.000000, y = 0.000000, z = -450.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
{id = 13, pos = {x = 0.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
}
,}
,},
{
resourceDeposits = {
{id = 0, pos = {x = 100.000000, y = 0.000000, z = 100.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 1000},
{id = 0, pos = {x = -200.000000, y = 0.000000, z = 50.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 1000},
},
units = {}
}
},
numCells = 37306,
cells = {
+2 -2
View File
@@ -337,7 +337,7 @@ namespace battleship{
void ActiveGameState::updateGameObjHoveredOn(){
vector<GameObject*> gameObjs;
vector<Player*> players = Game::getSingleton()->getPlayers();
vector<Player*> players = Game::getSingleton()->getPlayers(true);
for(Player *pl : players){
vector<ResourceDeposit*> resDeps = pl->getResourceDeposits();
@@ -482,7 +482,7 @@ namespace battleship{
vector<Unit*> units;
for (Player *p : Game::getSingleton()->getPlayers())
for (Player *p : Game::getSingleton()->getPlayers(true))
for (Unit *u : p->getUnits())
units.push_back(u);
+2 -10
View File
@@ -12,21 +12,13 @@ namespace battleship{
using namespace gameBase;
Extractor::Extractor(Player *player, int id, Vector3 pos, Quaternion rot, int buildStatus, ResourceDeposit *rd, Unit::State state) : Structure(player, id, pos, rot, buildStatus, state){
if(!rd){
vector<ResourceDeposit*> deposits;
for(Player *pl : Game::getSingleton()->getPlayers()){
vector<ResourceDeposit*> dep = pl->getResourceDeposits();
deposits.insert(deposits.end(), dep.begin(), dep.end());
}
for(ResourceDeposit *dep : deposits)
if(!rd)
for(ResourceDeposit *dep : Game::getSingleton()->getCivilianPlayer()->getResourceDeposits())
if(dep->getPos().getDistanceFrom(pos) < .001){
deposit = dep;
deposit->setExtractor(this);
break;
}
}
Vector2 size = Vector2(lenHpBar, 10);
ammountBackground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 0, 1));
+11 -3
View File
@@ -122,11 +122,11 @@ namespace battleship{
for(Projectile *proj : pl->getProjectiles())
gameObjs.push_back((GameObject*)proj);
for(ResourceDeposit *dep : pl->getResourceDeposits())
gameObjs.push_back((GameObject*)dep);
}
for(ResourceDeposit *dep : civilianPlayer->getResourceDeposits())
gameObjs.push_back((GameObject*)dep);
for(GameObject *obj : gameObjs)
obj->reinit();
}
@@ -276,4 +276,12 @@ namespace battleship{
return false;
}
vector<Player*> Game::getPlayers(bool civPl){
vector<Player*> playersVec = players;
if(civPl) playersVec.push_back(civilianPlayer);
return playersVec;
}
}
+4 -1
View File
@@ -27,11 +27,13 @@ namespace battleship{
void initTechnologies();
float calcAbilFromTech(Ability::Type, std::vector<int>, int, int);
bool isUnitUnlocked(std::vector<int>, int);
std::vector<Player*> getPlayers(bool = false);
inline void setDebug(bool d){this->debug = d;}
inline void addPlayer(Player *pl){players.push_back(pl);}
inline bool isDebug(){return debug;}
inline std::vector<Player*>& getPlayers(){return players;}
inline Player* getPlayer(int id){return players[id];}
inline void setCivilianPlayer(Player *pl){this->civilianPlayer = pl;}
inline Player* getCivilianPlayer(){return civilianPlayer;}
inline int getNumPlayers(){return players.size();}
inline Technology getTechnology(int id){return technologies[id];}
inline Ability getAbility(int id){return abilities[id];}
@@ -44,6 +46,7 @@ namespace battleship{
std::vector<Technology> technologies;
std::vector<Ability> abilities;
std::vector<Player*> players;
Player *civilianPlayer = nullptr;
};
}
+2 -10
View File
@@ -59,17 +59,9 @@ namespace battleship{
void GameObjectFrameController::snapToObj(GameObjectFrame &s, GameObject::Type type, int unitId, float maxDist){
if(s.getType() == GameObject::Type::UNIT && s.getId() == unitId){
s.status = GameObjectFrame::NOT_PLACEABLE;
vector<Player*> players = Game::getSingleton()->getPlayers();
vector<ResourceDeposit*> deposits;
for(Player *pl : players){
vector<ResourceDeposit*> deps = pl->getResourceDeposits();
for(ResourceDeposit *dep : deps)
deposits.push_back(dep);
}
Player *civPl = Game::getSingleton()->getCivilianPlayer();
for(ResourceDeposit *dep : deposits){
for(ResourceDeposit *dep : civPl->getResourceDeposits()){
Vector3 depPos = dep->getPos();
if(!dep->getExtractor() && s.getPos().getDistanceFrom(depPos) < maxDist){
+7 -8
View File
@@ -48,9 +48,8 @@ namespace battleship{
string refIconFile = SOL_STATE_VIEW["refIcon"];
string basePath = GameManager::getSingleton()->getPath() + "Textures/Icons/Minimap/";
for(Player *pl : Game::getSingleton()->getPlayers())
for(ResourceDeposit *rd : pl->getResourceDeposits())
depositIcons.push_back(initIcon(rd->getPos(), basePath + refIconFile));
for(ResourceDeposit *rd : Game::getSingleton()->getCivilianPlayer()->getResourceDeposits())
depositIcons.push_back(initIcon(rd->getPos(), basePath + refIconFile));
string camIconFile = SOL_STATE_VIEW["eyeIcon"];
camIcon = initIcon(Root::getSingleton()->getCamera()->getPosition(), basePath + camIconFile);
@@ -107,7 +106,7 @@ namespace battleship{
Vector3 mapSize = Map::getSingleton()->getMapSize();
vector<pair<Unit*, Vector2>> unitMinimapPos;
for(Player *pl : Game::getSingleton()->getPlayers())
for(Player *pl : Game::getSingleton()->getPlayers(true))
for(Unit *un : pl->getUnits()){
Vector2 coords = Vector2(
int(un->getPos().x / mapSize.x * width),
@@ -395,15 +394,15 @@ namespace battleship{
//TODO move minimap loading elsewhere
void Map::loadPlayerGameObjects(){
int numPlayers = Game::getSingleton()->getNumPlayers();
vector<Player*> players = Game::getSingleton()->getPlayers(true);
sol::state_view SOL_LUA_VIEW = generateView();
string playerInd = "players";
for(int i = 0; i < numPlayers; i++){
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 = Game::getSingleton()->getPlayer(i);
Player *player = players[i];
for(int j = 0; j < numNpcObjs; j++){
sol::table npcObjTable = SOL_LUA_VIEW[mapTable][playerInd][i + 1][resDepInd][j + 1];
@@ -587,7 +586,7 @@ namespace battleship{
}
void Map::unloadPlayerObjects(){
for(Player *pl : Game::getSingleton()->getPlayers()){
for(Player *pl : Game::getSingleton()->getPlayers(true)){
while(pl->getNumUnits() > 0){
pl->removeUnit(0);
}
+2
View File
@@ -66,6 +66,8 @@ namespace battleship{
string name = (cpuPlayer ? "CPU player #" + to_string(i) : "Player");
game->addPlayer(new Player(difficulty, faction, team, color, cpuPlayer, i, name));
}
game->setCivilianPlayer(new Player(0, 0, 0, .5 * Vector3::VEC_IJK));
handleLoadingGui(new LoadingAppState(new InGameAppState(mapName), "inGame.lua"));
}
+1 -1
View File
@@ -76,7 +76,7 @@ namespace battleship{
}
void Projectile::checkUnitCollision(){
vector<Player*> players = Game::getSingleton()->getPlayers();
vector<Player*> players = Game::getSingleton()->getPlayers(true);
vector<Unit*> targetUnits;
vector<Node*> targetNodes;