mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
Merge pull request #204 from devZoGok/bf-1-map-crashes
Bf 1 map crashes
This commit is contained in:
@@ -41,13 +41,14 @@ mappings = {
|
||||
{bind = 50, trigger = 85, action = true, bindType = 0, inOptions = false},
|
||||
{bind = 51, trigger = 79, action = true, bindType = 0, inOptions = false},
|
||||
|
||||
{bind = 0, trigger = 0, action = true, bindType = 1, inOptions = false},
|
||||
{bind = 7, trigger = 312, action = false, bindType = 2, inOptions = false},
|
||||
{bind = 8, trigger = 313, action = false, bindType = 2, inOptions = false},
|
||||
{bind = 9, trigger = 310, action = false, bindType = 2, inOptions = false},
|
||||
{bind = 10, trigger = 311, action = false, bindType = 2, inOptions = false},
|
||||
{bind = 11, trigger = 1, action = true, bindType = 1, inOptions = false},
|
||||
{bind = 11, trigger = 2, action = true, bindType = 1, inOptions = false},
|
||||
{bind = 13, trigger = 1, action = true, bindType = 1, inOptions = false},
|
||||
{bind = 33, trigger = 256, action = true, bindType = 0, inOptions = false},
|
||||
{bind = 0, trigger = 0, action = true, bindType = 1, inOptions = false},
|
||||
{bind = 34, trigger = 67, action = true, bindType = 0, inOptions = false},
|
||||
{bind = 35, trigger = 86, action = true, bindType = 0, inOptions = false},
|
||||
{bind = 36, trigger = 312, action = false, bindType = 2, inOptions = false},
|
||||
|
||||
@@ -327,6 +327,7 @@ namespace battleship{
|
||||
bool resources = (listboxType == RESOURCE_DEPOSITS);
|
||||
sol::table gameObjTable = SOL_LUA_STATE[resources ? "resources" : "units"];
|
||||
int numGameObjs = gameObjTable.size();
|
||||
std::vector<int> gameObjIds;
|
||||
|
||||
for(int i = 0; i < numGameObjs; i++){
|
||||
bool canAdd = true;
|
||||
@@ -337,15 +338,17 @@ namespace battleship{
|
||||
canAdd = (v == vehicles);
|
||||
}
|
||||
|
||||
if(canAdd)
|
||||
if(canAdd){
|
||||
lines.push_back(gameObjTable[i + 1]["name"]);
|
||||
gameObjIds.push_back(i);
|
||||
}
|
||||
}
|
||||
|
||||
numLines = lines.size();
|
||||
closable = true;
|
||||
maxDisplay = (numLines > numMaxDisplay ? numMaxDisplay : numLines);
|
||||
|
||||
listbox = new GameObjectListbox(!resources, pos, size, lines, maxDisplay, fontPath);
|
||||
listbox = new GameObjectListbox(!resources, pos, size, lines, gameObjIds, maxDisplay, fontPath);
|
||||
break;
|
||||
}
|
||||
case SKYBOX_TEXTURES:
|
||||
|
||||
Vendored
+1
-1
Submodule external/vb01 updated: 0e76154324...79c33f2f2a
@@ -10,12 +10,15 @@ namespace battleship{
|
||||
using namespace vb01Gui;
|
||||
using namespace gameBase;
|
||||
|
||||
GameObjectListbox::GameObjectListbox(bool ul, Vector3 pos, Vector2 size, vector<string> lines, int maxDisplay, string fontPath) : Listbox(pos, size, lines, maxDisplay, fontPath), unitListbox(ul) {}
|
||||
GameObjectListbox::GameObjectListbox(bool ul, Vector3 pos, Vector2 size, vector<string> lines, vector<int> objIds, int maxDisplay, string fontPath) :
|
||||
Listbox(pos, size, lines, maxDisplay, fontPath),
|
||||
unitListbox(ul),
|
||||
gameObjIds(objIds) {}
|
||||
|
||||
void GameObjectListbox::onClose(){
|
||||
GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton();
|
||||
GameObject::Type type = (unitListbox ? GameObject::Type::UNIT : GameObject::Type::RESOURCE_DEPOSIT);
|
||||
ufCtr->addGameObjectFrame(GameObjectFrame(selectedOption, type));
|
||||
ufCtr->addGameObjectFrame(GameObjectFrame(gameObjIds[selectedOption], type));
|
||||
ufCtr->setPlacingOnSurface(true);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -6,10 +6,11 @@
|
||||
namespace battleship{
|
||||
class GameObjectListbox : public vb01Gui::Listbox{
|
||||
public:
|
||||
GameObjectListbox(bool, vb01::Vector3, vb01::Vector2, std::vector<std::string>, int, std::string);
|
||||
GameObjectListbox(bool, vb01::Vector3, vb01::Vector2, std::vector<std::string>, std::vector<int>, int, std::string);
|
||||
void onClose();
|
||||
private:
|
||||
bool unitListbox;
|
||||
std::vector<int> gameObjIds;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -421,41 +421,50 @@ namespace battleship{
|
||||
}
|
||||
|
||||
void Map::loadPlayerGameObjects(Player *player, sol::table playerTbl){
|
||||
string resDepInd = "resourceDeposits";
|
||||
sol::state_view SOL_LUA_VIEW = generateView();
|
||||
sol::table resDepTbl = playerTbl["resourceDeposits"];
|
||||
int numNpcObjs = resDepTbl.size();
|
||||
|
||||
for(int j = 0; j < numNpcObjs; j++){
|
||||
sol::table npcObjTable = resDepTbl[j + 1];
|
||||
int id = npcObjTable["id"];
|
||||
string resDepInd = "resourceDeposits";
|
||||
sol::optional<sol::table> resDepTblOpt = playerTbl[resDepInd];
|
||||
|
||||
sol::table posTable = npcObjTable["pos"];
|
||||
Vector3 pos = Vector3(posTable["x"], posTable["y"], posTable["z"]);
|
||||
if(resDepTblOpt != sol::nullopt){
|
||||
sol::table resDepTbl = playerTbl[resDepInd];
|
||||
int numNpcObjs = resDepTbl.size();
|
||||
|
||||
sol::table rotTable = npcObjTable["rot"];
|
||||
Quaternion rot = Quaternion(rotTable["w"], rotTable["x"], rotTable["y"], rotTable["z"]);
|
||||
int initAmmount = resDepTbl[j + 1]["initAmmount"];
|
||||
for(int j = 0; j < numNpcObjs; j++){
|
||||
sol::table npcObjTable = resDepTbl[j + 1];
|
||||
int id = npcObjTable["id"];
|
||||
|
||||
player->addResourceDeposit(GameObjectFactory::createResourceDeposit(player, id, pos, rot, initAmmount));
|
||||
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"];
|
||||
|
||||
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];
|
||||
sol::optional<sol::table> unitsTblOpt = playerTbl[unitInd];
|
||||
|
||||
string posInd = "pos";
|
||||
Vector3 pos = Vector3(unitTable[posInd]["x"], unitTable[posInd]["y"], unitTable[posInd]["z"]);
|
||||
if(unitsTblOpt != sol::nullopt){
|
||||
sol::table unitsTbl = playerTbl[unitInd];
|
||||
int numUnits = unitsTbl.size();
|
||||
|
||||
for(int j = 0; j < numUnits; j++){
|
||||
sol::table unitTable = unitsTbl[j + 1];
|
||||
|
||||
string rotInd = "rot";
|
||||
Quaternion rot = Quaternion(unitTable[rotInd]["w"], unitTable[rotInd]["x"], unitTable[rotInd]["x"], unitTable[rotInd]["x"]);
|
||||
string posInd = "pos";
|
||||
Vector3 pos = Vector3(unitTable[posInd]["x"], unitTable[posInd]["y"], unitTable[posInd]["z"]);
|
||||
|
||||
int id = unitTable["id"];
|
||||
int buildStatus = unitTable["buildStatus"].get_or(0);
|
||||
player->addUnit(GameObjectFactory::createUnit(player, id, pos, rot, buildStatus));
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -477,6 +486,8 @@ namespace battleship{
|
||||
}
|
||||
|
||||
void Map::preprareScene(bool empty){
|
||||
Game::getSingleton()->setCivilianPlayer(new Player(0, 0, 0, .5 * Vector3::VEC_IJK));
|
||||
|
||||
Root *root = Root::getSingleton();
|
||||
Node *rootNode = root->getRootNode();
|
||||
string libPath = root->getLibPath();
|
||||
@@ -514,8 +525,8 @@ namespace battleship{
|
||||
//TODO implement toggleable cell rendering
|
||||
void Map::loadCells(){
|
||||
sol::state_view SOL_LUA_VIEW = generateView();
|
||||
int numCells = SOL_LUA_VIEW[mapTable]["numCells"];
|
||||
sol::table cellsTable = SOL_LUA_VIEW[mapTable]["cells"];
|
||||
int numCells = cellsTable.size();
|
||||
|
||||
for(int i = 0; i < numCells; i++){
|
||||
sol::table cellTable = cellsTable[i + 1], posTable = cellTable["pos"];
|
||||
@@ -573,15 +584,18 @@ namespace battleship{
|
||||
|
||||
sol::table sizeTable = SOL_LUA_STATE[mapTable]["size"];
|
||||
mapSize = Vector3(sizeTable["x"], sizeTable["y"], sizeTable["z"]);
|
||||
int numWaterbodies = SOL_LUA_STATE[mapTable]["numWaterBodies"];
|
||||
sol::table wbTbl = SOL_LUA_STATE[mapTable]["waterbodies"];
|
||||
int numWaterbodies = wbTbl.size();
|
||||
|
||||
for(int i = 0; i < numWaterbodies; i++)
|
||||
loadTerrainObject(i);
|
||||
}
|
||||
|
||||
void Map::create(string mapName){
|
||||
void Map::create(string mapName, Vector3 mapSize){
|
||||
this->mapName = mapName;
|
||||
addSpawnPoint(Vector3::VEC_ZERO);
|
||||
this->mapSize = mapSize;
|
||||
|
||||
//addSpawnPoint(Vector3::VEC_ZERO);
|
||||
preprareScene(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace battleship{
|
||||
static std::vector<Edge> generateAdjacentNodeEdges(int, int, int, int, int);
|
||||
void update();
|
||||
void load(std::string);
|
||||
void create(std::string);
|
||||
void create(std::string, vb01::Vector3);
|
||||
void unload();
|
||||
std::vector<vb01::RayCaster::CollisionResult> raycastTerrain(vb01::Vector3, vb01::Vector3, bool);
|
||||
int getCellId(vb01::Vector3, bool = true);
|
||||
|
||||
+86
-80
@@ -59,8 +59,7 @@ namespace battleship{
|
||||
|
||||
if(newMap){
|
||||
game->addPlayer(new Player(0, 0, 0, Vector3(1, 1, 1)));
|
||||
map->setMapSize(Vector3(size.x, 0, size.y));
|
||||
map->create(name);
|
||||
map->create(name, Vector3(size.x, 0, size.y));
|
||||
generatePlane(size);
|
||||
}
|
||||
else{
|
||||
@@ -286,7 +285,7 @@ namespace battleship{
|
||||
XMLElement *meshEl = doc->NewElement("mesh");
|
||||
MeshData meshData = map->getNodeParent()->getChild(0)->getMesh(0)->getMeshBase();
|
||||
meshEl->SetAttribute("name", "mesh");
|
||||
meshEl->SetAttribute("num_vertex_pos", meshData.numPos);
|
||||
meshEl->SetAttribute("num_vertex_pos", 3 * meshData.numTris);
|
||||
meshEl->SetAttribute("num_faces", meshData.numTris);
|
||||
meshEl->SetAttribute("num_vertex_groups", 0);
|
||||
meshEl->SetAttribute("num_shape_keys", 0);
|
||||
@@ -433,14 +432,56 @@ namespace battleship{
|
||||
stbi_write_jpg(string(mapFolder + "minimap.jpg").c_str(), width, height, numChannels, imgData, 100);
|
||||
}
|
||||
|
||||
string MapEditorAppState::MapEditor::generatePlayerTableStr(Player* player){
|
||||
string mapScript = "";
|
||||
vector<ResourceDeposit*> resourceDeposits = player->getResourceDeposits();
|
||||
|
||||
if(!resourceDeposits.empty()){
|
||||
mapScript += "\t\t\tresourceDeposits = {\n";
|
||||
|
||||
for(ResourceDeposit *rd : resourceDeposits){
|
||||
Vector3 pos = rd->getPos();
|
||||
string posStr = "x = " + to_string(pos.x) + ", y = " + to_string(pos.y) + ", z = " + to_string(pos.z);
|
||||
|
||||
Quaternion rot = rd->getRot();
|
||||
string rotStr = "w = " + to_string(rot.w) + ", x = " + to_string(rot.x) + ", y = " + to_string(rot.y) + ", z = " + to_string(rot.z);
|
||||
|
||||
mapScript += "\t\t\t\t{id = " + to_string(rd->getId()) + ", pos = {" + posStr + "}, rot = {" + rotStr + "}},\n";
|
||||
}
|
||||
|
||||
mapScript += "\t\t\t},\n";
|
||||
}
|
||||
|
||||
vector<Unit*> units = player->getUnits();
|
||||
|
||||
if(!units.empty()){
|
||||
mapScript += "\t\t\tunits = {\n";
|
||||
|
||||
for(Unit *unit : units){
|
||||
string idStr = "id = " + to_string(unit->getId());
|
||||
|
||||
Vector3 unitPos = unit->getPos();
|
||||
string posStr = "pos = {x = " + to_string(unitPos.x) + ", y = " + to_string(unitPos.y) + ", z = " + to_string(unitPos.z) + "}";
|
||||
|
||||
Quaternion unitRot = unit->getRot();
|
||||
string rotStr = "rot = {w = " + to_string(unitRot.w) + ", x = " + to_string(unitRot.x) + ", y = " + to_string(unitRot.y) + ", z = " + to_string(unitRot.z) + "}";
|
||||
|
||||
mapScript += "\t\t\t\t{" + idStr + ", " + posStr + ", " + rotStr + "},\n";
|
||||
}
|
||||
|
||||
mapScript += "\t\t\t}\n";
|
||||
}
|
||||
|
||||
return mapScript;
|
||||
}
|
||||
|
||||
void MapEditorAppState::MapEditor::generateMapScript(vector<Map::Cell> &cells){
|
||||
int numWaterBodies = map->getNodeParent()->getNumChildren() - 1;
|
||||
vector<Player*> players = Game::getSingleton()->getPlayers();
|
||||
|
||||
string mapScript = "map = {\nlights = {\n";
|
||||
string mapScript = "map = {\n\tlights = {";
|
||||
|
||||
for(Node *light : map->getLights()){
|
||||
mapScript += "{type = " + to_string((int)light->getLight(0)->getLightType());
|
||||
mapScript += "\n\t\t{type = " + to_string((int)light->getLight(0)->getLightType());
|
||||
|
||||
if(light->getLight(0)->getLightType() == Light::Type::DIRECTIONAL){
|
||||
Vector3 dir = light->getGlobalAxis(2);
|
||||
@@ -451,78 +492,33 @@ namespace battleship{
|
||||
mapScript += ", color = {x = " + to_string(color.x) + ", y = " + to_string(color.y) + ", z = " + to_string(color.z) + "}},";
|
||||
}
|
||||
|
||||
mapScript += "\n\t},\n";
|
||||
Vector3 mapSize = map->getMapSize();
|
||||
mapScript += "}\nnumWaterBodies = " + to_string(numWaterBodies) + ",\n";
|
||||
mapScript += "size = {x = " + to_string(mapSize.x) + ", y = " + to_string(mapSize.y) + ", z = " + to_string(mapSize.z) + "},\n";
|
||||
mapScript += "impassibleNodeValue = " + to_string(IMPASS_NODE_VAL) + ",\n";
|
||||
mapScript += "numPlayers = " + to_string(players.size()) + ",\n";
|
||||
mapScript += "\tsize = {x = " + to_string(mapSize.x) + ", y = " + to_string(mapSize.y) + ", z = " + to_string(mapSize.z) + "},\n";
|
||||
mapScript += "\timpassibleNodeValue = " + to_string(IMPASS_NODE_VAL) + ",\n";
|
||||
|
||||
int numSpawnPoints = map->getNumSpawnPoints();
|
||||
mapScript += "numSpawnPoints = " + to_string(numSpawnPoints) + ",\n";
|
||||
mapScript += "spawnPoints = {\n";
|
||||
mapScript += "\tspawnPoints = {\n";
|
||||
|
||||
for(int i = 0; i < numSpawnPoints; i++){
|
||||
Vector3 sp = map->getSpawnPoint(i);
|
||||
mapScript += "{x = " + to_string(sp.x) + ", y = " + to_string(sp.y) + ", z = " + to_string(sp.z) + "},\n";
|
||||
mapScript += "\t\t{x = " + to_string(sp.x) + ", y = " + to_string(sp.y) + ", z = " + to_string(sp.z) + "},\n";
|
||||
}
|
||||
|
||||
mapScript += "},\nplayers = {\n";
|
||||
mapScript += "\t},\n";
|
||||
mapScript += "\tchoosablePlayers = {";
|
||||
Game *game = Game::getSingleton();
|
||||
|
||||
for(int i = 0; i < players.size(); i++){
|
||||
mapScript += "{\n";
|
||||
for(Player *player : game->getPlayers())
|
||||
mapScript += "\n\t\t{\n" + generatePlayerTableStr(player) + "\n\t\t},\n";
|
||||
|
||||
if(i > 0)
|
||||
mapScript += "spawnPoint = 0,\n";
|
||||
else{
|
||||
vector<ResourceDeposit*> resourceDeposits = players[0]->getResourceDeposits();
|
||||
mapScript += "numResourceDeposits = " + to_string(resourceDeposits.size()) + ",\n";
|
||||
mapScript += "resourceDeposits = {\n";
|
||||
|
||||
for(ResourceDeposit *rd : resourceDeposits){
|
||||
Vector3 pos = rd->getPos();
|
||||
string posStr = "x = " + to_string(pos.x) + ", y = " + to_string(pos.y) + ", z = " + to_string(pos.z);
|
||||
|
||||
Quaternion rot = rd->getRot();
|
||||
string rotStr = "w = " + to_string(rot.w) + ", x = " + to_string(rot.x) + ", y = " + to_string(rot.y) + ", z = " + to_string(rot.z);
|
||||
|
||||
mapScript += "{id = " + to_string(rd->getId()) + ", pos = {" + posStr + "}, rot = {" + rotStr + "}},\n";
|
||||
}
|
||||
|
||||
mapScript += "},\n";
|
||||
}
|
||||
|
||||
int numUnits = players[i]->getNumUnits();
|
||||
mapScript += "numUnits = " + to_string(numUnits) + ",\n";
|
||||
|
||||
if(numUnits > 0){
|
||||
mapScript += "units = {\n";
|
||||
|
||||
for(int j = 0; j < numUnits; j++){
|
||||
Unit *unit = Game::getSingleton()->getPlayer(i)->getUnit(j);
|
||||
|
||||
string idStr = "id = " + to_string(unit->getId());
|
||||
|
||||
Vector3 unitPos = unit->getPos();
|
||||
string posStr = "pos = {x = " + to_string(unitPos.x) + ", y = " + to_string(unitPos.y) + ", z = " + to_string(unitPos.z) + "}";
|
||||
|
||||
Quaternion unitRot = unit->getRot();
|
||||
string rotStr = "rot = {w = " + to_string(unitRot.w) + ", x = " + to_string(unitRot.x) + ", y = " + to_string(unitRot.y) + ", z = " + to_string(unitRot.z) + "}";
|
||||
|
||||
mapScript += "{" + idStr + ", " + posStr + ", " + rotStr + "},\n";
|
||||
}
|
||||
|
||||
mapScript += "}\n,";
|
||||
}
|
||||
|
||||
mapScript += "}\n";
|
||||
}
|
||||
|
||||
mapScript += "},\nnumCells = " + to_string(cells.size()) + ",\n";
|
||||
mapScript += "cells = {\n";
|
||||
mapScript += "\t},\n";
|
||||
mapScript += "\tcivilianPlayer = {\n" + generatePlayerTableStr(game->getCivilianPlayer()) + "\n\t},\n";
|
||||
mapScript += "\tcells = {\n";
|
||||
|
||||
for(Map::Cell cell : cells){
|
||||
Vector3 p = cell.pos;
|
||||
mapScript += "{type = " + to_string((int)cell.type) + ", pos = {x = " + to_string(p.x) + ", y = " + to_string(p.y) + ", z = " + to_string(p.z) + "}, numEdges = " + to_string(cell.edges.size()) + ", edges = {";
|
||||
mapScript += "\t\t{type = " + to_string((int)cell.type) + ", pos = {x = " + to_string(p.x) + ", y = " + to_string(p.y) + ", z = " + to_string(p.z) + "}, numEdges = " + to_string(cell.edges.size()) + ", edges = {";
|
||||
|
||||
for(Map::Edge edge : cell.edges)
|
||||
mapScript += "{srcCellId = " + to_string(edge.srcCellId) + ", destCellId = " + to_string(edge.destCellId) + ", weight = " + to_string(edge.weight) + "}, ";
|
||||
@@ -539,10 +535,10 @@ namespace battleship{
|
||||
mapScript += "}";
|
||||
}
|
||||
|
||||
mapScript += "},\n";
|
||||
mapScript += "\t\t},\n";
|
||||
}
|
||||
|
||||
mapScript += "},\n";
|
||||
mapScript += "\t},\n";
|
||||
|
||||
Root *root = Root::getSingleton();
|
||||
string skyboxPath = "";
|
||||
@@ -557,20 +553,20 @@ namespace battleship{
|
||||
skyboxPath = skyboxPath.substr(slashId + 1);
|
||||
}
|
||||
|
||||
mapScript += "skybox = \"" + skyboxPath + "\",\n";
|
||||
mapScript += "terrain = {model = \"" + map->getMapName() + ".xml\", albedo = \"" + map->getMapName() + ".jpg\"},\n";
|
||||
mapScript += "waterbodies = {\n";
|
||||
mapScript += "\tskybox = \"" + skyboxPath + "\",\n";
|
||||
mapScript += "\tterrain = {model = \"" + map->getMapName() + ".xml\", albedo = \"" + map->getMapName() + ".jpg\"},\n";
|
||||
mapScript += "\twaterbodies = {\n";
|
||||
|
||||
for(int i = 0; i < numWaterBodies; i++){
|
||||
Node *waterNode = map->getNodeParent()->getChild(i + 1);
|
||||
Vector3 pos = waterNode->getPosition();
|
||||
Vector3 size = ((Quad*)waterNode->getMesh(0))->getSize();
|
||||
mapScript +=
|
||||
"{pos = {x = " + to_string(pos.x) + ", y = " + to_string(pos.y) + ", z = " + to_string(pos.z) + "},\
|
||||
"\t\t{pos = {x = " + to_string(pos.x) + ", y = " + to_string(pos.y) + ", z = " + to_string(pos.z) + "},\
|
||||
size = {x = " + to_string(size.x) + ", y = " + to_string(size.y) + "}, albedo = \"water.png\"},";
|
||||
}
|
||||
|
||||
mapScript += "}\n}";
|
||||
mapScript += "\t}\n}";
|
||||
|
||||
string file = GameManager::getSingleton()->getPath() + "Models/Maps/" + map->getMapName() + "/" + map->getMapName() + ".lua";
|
||||
|
||||
@@ -583,7 +579,7 @@ namespace battleship{
|
||||
string assetsPath = GameManager::getSingleton()->getPath();
|
||||
string mapFolder = assetsPath + "Models/Maps/" + map->getMapName() + "/";
|
||||
create_directory(mapFolder);
|
||||
copy_file(assetsPath + DEFAULT_TEXTURE, mapFolder + map->getMapName() + ".jpg");
|
||||
copy_file(assetsPath + DEFAULT_TEXTURE, mapFolder + map->getMapName() + ".jpg", filesystem::copy_options::overwrite_existing);
|
||||
|
||||
vector<Map::Cell> cells = generateMapCells();
|
||||
generateLandmassXml();
|
||||
@@ -659,26 +655,33 @@ namespace battleship{
|
||||
|
||||
switch((Bind)bind){
|
||||
case Bind::LOOK_AROUND:
|
||||
if(ufCtr->isPlacingOnSurface()){
|
||||
if(!ufCtr->isPlacingOnSurface())
|
||||
CameraController::getSingleton()->setLookingAround(isPressed);
|
||||
|
||||
break;
|
||||
case Bind::ROTATE_OBJ_FRAME:
|
||||
if(isPressed && ufCtr->isPlacingOnSurface())
|
||||
ufCtr->setRotating(true);
|
||||
else if(!isPressed && ufCtr->isRotating()){
|
||||
Player *player = Game::getSingleton()->getPlayer(0);
|
||||
GameObjectFrame &frame = ufCtr->getGameObjectFrame(0);
|
||||
Model *model = frame.getModel();
|
||||
Vector3 pos = model->getPosition();
|
||||
Quaternion rot = model->getOrientation();
|
||||
GameObject *obj;
|
||||
|
||||
if(frame.getType() == GameObject::Type::RESOURCE_DEPOSIT)
|
||||
player->addResourceDeposit(GameObjectFactory::createResourceDeposit(player, frame.getId(), pos, rot));
|
||||
else
|
||||
player->addUnit(GameObjectFactory::createUnit(player, frame.getId(), pos, rot));
|
||||
}
|
||||
else
|
||||
CameraController::getSingleton()->setLookingAround(isPressed);
|
||||
|
||||
break;
|
||||
case Bind::ROTATE_OBJ_FRAME:
|
||||
ufCtr->setRotating(false);
|
||||
}
|
||||
|
||||
break;
|
||||
case Bind::DESELECT_STRUCTURE:
|
||||
ufCtr->removeGameObjectFrames();
|
||||
ufCtr->setPlacingOnSurface(false);
|
||||
ufCtr->setRotating(false);
|
||||
break;
|
||||
case Bind::INCREASE_RADIUS:
|
||||
if(isPressed) mapEditor->updateCircleRadius(true);
|
||||
@@ -752,6 +755,7 @@ namespace battleship{
|
||||
|
||||
void MapEditorAppState::onAnalog(int bind, float strength){
|
||||
CameraController *camCtr = CameraController::getSingleton();
|
||||
GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton();
|
||||
|
||||
switch((Bind)bind){
|
||||
case Bind::LOOK_UP:
|
||||
@@ -767,6 +771,8 @@ namespace battleship{
|
||||
case Bind::LOOK_RIGHT:
|
||||
if(camCtr->isLookingAround())
|
||||
camCtr->orientCamera(Vector3(0, 1, 0), strength);
|
||||
else if(ufCtr->isRotating())
|
||||
ufCtr->rotateGameObjectFrames(100 * strength);
|
||||
|
||||
break;
|
||||
case Bind::PUSH_VERTS_UP:
|
||||
|
||||
@@ -61,6 +61,7 @@ namespace battleship{
|
||||
std::vector<Map::Cell> generateMapCells();
|
||||
void generateLandmassXml();
|
||||
void generateMinimap(std::string, std::vector<Map::Cell>&);
|
||||
std::string generatePlayerTableStr(Player*);
|
||||
void generateMapScript(std::vector<Map::Cell>&);
|
||||
void prepareTerrainObject(vb01::u32**, Map::Cell*, int[3], float, bool);
|
||||
|
||||
|
||||
@@ -66,8 +66,6 @@ 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"));
|
||||
}
|
||||
|
||||
@@ -513,15 +513,18 @@ namespace battleship{
|
||||
|
||||
//TODO select only the closest cells based on unit size
|
||||
void Unit::placeAt(Vector3 p){
|
||||
//check twice in case the unit is warped over a long distance
|
||||
Map::getSingleton()->blockCells(this);
|
||||
GameObject::placeAt(p);
|
||||
Map::getSingleton()->blockCells(this);
|
||||
|
||||
ActiveGameState *activeState = (ActiveGameState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE);
|
||||
|
||||
if(activeState && activeState->getPlayer())
|
||||
Map::Minimap::getSingleton()->updateImage();
|
||||
//check twice in case the unit is warped over a long distance
|
||||
if(activeState) Map::getSingleton()->blockCells(this);
|
||||
GameObject::placeAt(p);
|
||||
|
||||
if(activeState){
|
||||
Map::getSingleton()->blockCells(this);
|
||||
|
||||
if(activeState->getPlayer())
|
||||
Map::Minimap::getSingleton()->updateImage();
|
||||
}
|
||||
}
|
||||
|
||||
vector<Player*> Unit::getSelectingPlayers(){
|
||||
|
||||
Reference in New Issue
Block a user