mirror of
https://github.com/ApfelTeeSaft/PlanetFleet.git
synced 2026-08-26 19:33:38 +00:00
factories and engineers produce and build units by their specific buildable unit tables
This commit is contained in:
@@ -38,7 +38,7 @@ function Player:trainEngineers()
|
||||
dirToCenter = Vector3:new(0, 0, 0):subtr(fort:getPos()):norm()
|
||||
|
||||
while #fort:getQueue() + #self:getUnitsByClass(UnitClass.ENGINEER, -1) < self.numStartEngis do
|
||||
fort:appendToQueue(UnitId.ENGINEER)
|
||||
fort:appendToQueue(0)
|
||||
end
|
||||
|
||||
return #self:getUnitsByClass(UnitClass.ENGINEER, -1) == self.numStartEngis
|
||||
@@ -132,7 +132,7 @@ function Player:buildHarvester()
|
||||
factory = landFactories[1]:toFactory()
|
||||
|
||||
if #factory:getQueue() == 0 then
|
||||
factory:appendToQueue(UnitId.RESOURCE_ROVER)
|
||||
factory:appendToQueue(3)
|
||||
end
|
||||
|
||||
return false
|
||||
@@ -157,10 +157,10 @@ function Player:startHarvesting()
|
||||
return true
|
||||
end
|
||||
|
||||
function Player:buildTaskforceUnitGroup(numUnits, currNumUnits, factory, unitId)
|
||||
function Player:buildTaskforceUnitGroup(numUnits, currNumUnits, factory, buId)
|
||||
if currNumUnits < numUnits then
|
||||
for i = 1, numUnits - currNumUnits do
|
||||
factory:appendToQueue(unitId)
|
||||
factory:appendToQueue(buId)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -175,9 +175,9 @@ function Player:buildTaskforce()
|
||||
currLandFactories = self:getUnitsByClass(UnitClass.LAND_FACTORY, -1)
|
||||
|
||||
for i = 1, #currLandFactories do
|
||||
currNumWarMechs = currNumWarMechs + currLandFactories[i]:toFactory():getNumQueueUnitsById(UnitId.WAR_MECH)
|
||||
currNumTanks = currNumTanks + currLandFactories[i]:toFactory():getNumQueueUnitsById(UnitId.TANK)
|
||||
currNumArtillery = currNumArtillery + currLandFactories[i]:toFactory():getNumQueueUnitsById(UnitId.ARTILLERY)
|
||||
currNumWarMechs = currNumWarMechs + currLandFactories[i]:toFactory():getNumQueueUnitsById(0)
|
||||
currNumTanks = currNumTanks + currLandFactories[i]:toFactory():getNumQueueUnitsById(1)
|
||||
currNumArtillery = currNumArtillery + currLandFactories[i]:toFactory():getNumQueueUnitsById(2)
|
||||
end
|
||||
|
||||
numWarMechs = self.numDefWarMechs + self.numTaskForceWarMechs
|
||||
@@ -190,9 +190,9 @@ function Player:buildTaskforce()
|
||||
|
||||
landFactory = currLandFactories[1]:toFactory()
|
||||
|
||||
self:buildTaskforceUnitGroup(numWarMechs, currNumWarMechs, landFactory, UnitId.WAR_MECH)
|
||||
self:buildTaskforceUnitGroup(numTanks, currNumTanks, landFactory, UnitId.TANK)
|
||||
self:buildTaskforceUnitGroup(numArtillery, currNumArtillery, landFactory, UnitId.ARTILLERY)
|
||||
self:buildTaskforceUnitGroup(numWarMechs, currNumWarMechs, landFactory, 0)
|
||||
self:buildTaskforceUnitGroup(numTanks, currNumTanks, landFactory, 1)
|
||||
self:buildTaskforceUnitGroup(numArtillery, currNumArtillery, landFactory, 2)
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
@@ -73,6 +73,7 @@ units = {
|
||||
destinationOffset = .1,
|
||||
anglePrecision = .1,
|
||||
maxTurnAngle = .1,
|
||||
guiScreen = '',
|
||||
garrisonCategory = 1
|
||||
},
|
||||
{
|
||||
@@ -96,6 +97,7 @@ units = {
|
||||
destinationOffset = .1,
|
||||
anglePrecision = .1,
|
||||
maxTurnAngle = .1,
|
||||
guiScreen = '',
|
||||
garrisonCategory = 2
|
||||
},
|
||||
{
|
||||
@@ -119,12 +121,21 @@ units = {
|
||||
destinationOffset = .1,
|
||||
anglePrecision = .1,
|
||||
maxTurnAngle = .1,
|
||||
guiScreen = '',
|
||||
garrisonCategory = 2
|
||||
},
|
||||
{
|
||||
weapons = {
|
||||
{type = WeaponClass.HITSCAN, rateOfFire = 2000, fireSfx = PATH .. 'Sounds/Units/WarMechs/fire.ogg', damage = 20, maxRange = 8},
|
||||
},
|
||||
buildableUnits = {
|
||||
{id = UnitId.LAND_FACTORY, buildable = true},
|
||||
{id = UnitId.NAVAL_FACTORY, buildable = true},
|
||||
{id = UnitId.MARKET, buildable = true},
|
||||
{id = UnitId.LAB, buildable = true},
|
||||
{id = UnitId.POINT_DEFENSE, buildable = true},
|
||||
{id = UnitId.FORT, buildable = true},
|
||||
},
|
||||
unitClass = UnitClass.ENGINEER,
|
||||
unitType = UnitType.HOVER,
|
||||
armor = {ArmorType.MECHANIC},
|
||||
@@ -140,6 +151,7 @@ units = {
|
||||
name = 'Engineer',
|
||||
basePath = PATH .. vehiclePrefix .. 'Engineers/',
|
||||
meshPath = 'engineer.xml',
|
||||
guiScreen = 'engineerCommands.lua',
|
||||
selectionSfx = PATH .. 'Sounds/Units/Engineers/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
speed = .1,
|
||||
@@ -169,6 +181,7 @@ units = {
|
||||
destinationOffset = .1,
|
||||
anglePrecision = .1,
|
||||
maxTurnAngle = .1,
|
||||
guiScreen = '',
|
||||
garrisonCategory = 3
|
||||
},
|
||||
{
|
||||
@@ -193,6 +206,7 @@ units = {
|
||||
destinationOffset = .1,
|
||||
anglePrecision = .1,
|
||||
maxTurnAngle = .1,
|
||||
guiScreen = '',
|
||||
garrisonCategory = 3
|
||||
},
|
||||
{
|
||||
@@ -219,6 +233,7 @@ units = {
|
||||
destinationOffset = .1,
|
||||
anglePrecision = .1,
|
||||
maxTurnAngle = .1,
|
||||
guiScreen = '',
|
||||
garrisonCategory = 3
|
||||
},
|
||||
{
|
||||
@@ -242,6 +257,7 @@ units = {
|
||||
destinationOffset = .1,
|
||||
anglePrecision = .1,
|
||||
maxTurnAngle = .1,
|
||||
guiScreen = '',
|
||||
garrisonCategory = 3
|
||||
},
|
||||
{
|
||||
@@ -266,6 +282,7 @@ units = {
|
||||
destinationOffset = .1,
|
||||
anglePrecision = .1,
|
||||
maxTurnAngle = .1,
|
||||
guiScreen = '',
|
||||
garrisonCategory = 3
|
||||
},
|
||||
{
|
||||
@@ -289,6 +306,7 @@ units = {
|
||||
destinationOffset = .1,
|
||||
anglePrecision = .1,
|
||||
maxTurnAngle = .1,
|
||||
guiScreen = '',
|
||||
garrisonCategory = 3
|
||||
},
|
||||
{
|
||||
@@ -312,6 +330,7 @@ units = {
|
||||
destinationOffset = .1,
|
||||
anglePrecision = .1,
|
||||
maxTurnAngle = .1,
|
||||
guiScreen = '',
|
||||
garrisonCategory = 3
|
||||
},
|
||||
{
|
||||
@@ -334,6 +353,7 @@ units = {
|
||||
destinationOffset = .1,
|
||||
anglePrecision = .1,
|
||||
maxTurnAngle = .1,
|
||||
guiScreen = '',
|
||||
garrisonCategory = 3
|
||||
},
|
||||
{
|
||||
@@ -365,6 +385,7 @@ units = {
|
||||
destinationOffset = .1,
|
||||
anglePrecision = .1,
|
||||
maxTurnAngle = .1,
|
||||
guiScreen = '',
|
||||
garrisonCategory = 3
|
||||
},
|
||||
{
|
||||
@@ -403,6 +424,7 @@ units = {
|
||||
destinationOffset = .1,
|
||||
anglePrecision = .1,
|
||||
maxTurnAngle = .1,
|
||||
guiScreen = '',
|
||||
garrisonCategory = 3
|
||||
},
|
||||
{
|
||||
@@ -434,9 +456,16 @@ units = {
|
||||
destinationOffset = .1,
|
||||
anglePrecision = .1,
|
||||
maxTurnAngle = .1,
|
||||
guiScreen = '',
|
||||
garrisonCategory = 3
|
||||
},
|
||||
{
|
||||
buildableUnits = {
|
||||
{id = UnitId.WAR_MECH, buildable = true},
|
||||
{id = UnitId.TANK, buildable = true},
|
||||
{id = UnitId.ARTILLERY, buildable = true},
|
||||
{id = UnitId.RESOURCE_ROVER, buildable = true}
|
||||
},
|
||||
unitClass = UnitClass.LAND_FACTORY,
|
||||
unitType = UnitType.LAND,
|
||||
isVehicle = false,
|
||||
@@ -449,6 +478,7 @@ units = {
|
||||
name = 'Land factory',
|
||||
basePath = PATH .. structurePrefix .. 'LandFactories/',
|
||||
meshPath = 'landFactory.xml',
|
||||
guiScreen = 'landFactoryCommands.lua',
|
||||
selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
},
|
||||
@@ -465,6 +495,7 @@ units = {
|
||||
name = 'Naval factory',
|
||||
basePath = PATH .. structurePrefix .. 'NavalFactories/',
|
||||
meshPath = 'navalFactory.xml',
|
||||
guiScreen = 'navalFactoryCommands.lua',
|
||||
selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
},
|
||||
@@ -482,6 +513,7 @@ units = {
|
||||
basePath = PATH .. structurePrefix .. 'Markets/',
|
||||
meshPath = 'market.xml',
|
||||
selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg',
|
||||
guiScreen = '',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
},
|
||||
{
|
||||
@@ -500,6 +532,7 @@ units = {
|
||||
name = 'Lab',
|
||||
basePath = PATH .. structurePrefix .. 'Labs/',
|
||||
meshPath = 'lab.xml',
|
||||
guiScreen = '',
|
||||
selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
},
|
||||
@@ -518,6 +551,7 @@ units = {
|
||||
basePath = PATH .. structurePrefix .. 'PointDefenses/',
|
||||
meshPath = 'pointDefense.xml',
|
||||
selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg',
|
||||
guiScreen = '',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
},
|
||||
{
|
||||
@@ -536,6 +570,7 @@ units = {
|
||||
basePath = PATH .. structurePrefix .. 'Extractors/',
|
||||
meshPath = 'extractor.xml',
|
||||
selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg',
|
||||
guiScreen = '',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
},
|
||||
{
|
||||
@@ -551,10 +586,12 @@ units = {
|
||||
name = 'Refinery',
|
||||
basePath = PATH .. structurePrefix .. 'Refineries/',
|
||||
meshPath = 'refinery.xml',
|
||||
guiScreen = '',
|
||||
selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
},
|
||||
{
|
||||
buildableUnits = {{id = UnitId.ENGINEER, buildable = true}},
|
||||
unitClass = UnitClass.FORT,
|
||||
unitType = UnitType.LAND,
|
||||
isVehicle = false,
|
||||
@@ -567,6 +604,7 @@ units = {
|
||||
name = 'Fort',
|
||||
basePath = PATH .. structurePrefix .. 'Forts/',
|
||||
meshPath = 'fort.xml',
|
||||
guiScreen = 'fortCommands.lua',
|
||||
selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg',
|
||||
deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg',
|
||||
},
|
||||
|
||||
@@ -9,7 +9,6 @@ gui = {
|
||||
guiType = GuiType.BUTTON,
|
||||
buttonType = ButtonType.BUILD,
|
||||
trigger = 76,
|
||||
structureId = UnitId.LAND_FACTORY
|
||||
},
|
||||
{
|
||||
pos = {x = res.x - Size.x - 200, y = res.y - 200},
|
||||
@@ -18,7 +17,6 @@ gui = {
|
||||
guiType = GuiType.BUTTON,
|
||||
buttonType = ButtonType.BUILD,
|
||||
trigger = 78,
|
||||
structureId = UnitId.NAVAL_FACTORY
|
||||
},
|
||||
{
|
||||
pos = {x = res.x - 2 * Size.x - 200, y = res.y - 200},
|
||||
@@ -27,7 +25,6 @@ gui = {
|
||||
guiType = GuiType.BUTTON,
|
||||
buttonType = ButtonType.BUILD,
|
||||
trigger = 77,
|
||||
structureId = UnitId.MARKET
|
||||
},
|
||||
{
|
||||
pos = {x = res.x - 3 * Size.x - 200, y = res.y - 200},
|
||||
@@ -36,7 +33,6 @@ gui = {
|
||||
guiType = GuiType.BUTTON,
|
||||
buttonType = ButtonType.BUILD,
|
||||
trigger = 84,
|
||||
structureId = UnitId.LAB
|
||||
},
|
||||
{
|
||||
pos = {x = res.x - 4 * Size.x - 200, y = res.y - 200},
|
||||
@@ -45,7 +41,6 @@ gui = {
|
||||
guiType = GuiType.BUTTON,
|
||||
buttonType = ButtonType.BUILD,
|
||||
trigger = 68,
|
||||
structureId = UnitId.POINT_DEFENSE
|
||||
},
|
||||
{
|
||||
pos = {x = res.x - 5 * Size.x - 200, y = res.y - 200},
|
||||
@@ -54,6 +49,5 @@ gui = {
|
||||
guiType = GuiType.BUTTON,
|
||||
buttonType = ButtonType.BUILD,
|
||||
trigger = 70,
|
||||
structureId = UnitId.FORT
|
||||
},
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ gui = {
|
||||
imagePath = '',
|
||||
guiType = GuiType.BUTTON,
|
||||
buttonType = ButtonType.FORT_TRAIN,
|
||||
trigger = 82,
|
||||
unitId = UnitId.ENGINEER
|
||||
trigger = 82
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
numGui = 2
|
||||
res = graphics.resolution
|
||||
Size = {x = 100, y = 100}
|
||||
|
||||
@@ -9,8 +8,7 @@ gui = {
|
||||
imagePath = '',
|
||||
guiType = GuiType.BUTTON,
|
||||
buttonType = ButtonType.LAND_FACTORY_TRAIN,
|
||||
trigger = 84,
|
||||
unitId = UnitId.TANK
|
||||
trigger = 87
|
||||
},
|
||||
{
|
||||
pos = {x = res.x - Size.x - 200, y = res.y - 200},
|
||||
@@ -18,7 +16,14 @@ gui = {
|
||||
imagePath = '',
|
||||
guiType = GuiType.BUTTON,
|
||||
buttonType = ButtonType.LAND_FACTORY_TRAIN,
|
||||
trigger = 65,
|
||||
unitId = UnitId.ARTILLERY
|
||||
trigger = 84
|
||||
},
|
||||
{
|
||||
pos = {x = res.x - 2 * Size.x - 200, y = res.y - 200},
|
||||
size = Size,
|
||||
imagePath = '',
|
||||
guiType = GuiType.BUTTON,
|
||||
buttonType = ButtonType.LAND_FACTORY_TRAIN,
|
||||
trigger = 65
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
numGui = 1
|
||||
res = graphics.resolution
|
||||
|
||||
gui = {
|
||||
@@ -8,7 +7,6 @@ gui = {
|
||||
imagePath = '',
|
||||
guiType = GuiType.BUTTON,
|
||||
buttonType = ButtonType.NAVAL_FACTORY_TRAIN,
|
||||
trigger = 66,
|
||||
unitId = UnitId.SCOUT_TRANSPORT
|
||||
trigger = 66
|
||||
}
|
||||
}
|
||||
|
||||
+6
-9
@@ -161,6 +161,7 @@ namespace battleship{
|
||||
|
||||
ConcreteGuiManager::getSingleton()->removeAllButtons();
|
||||
buttons.clear();
|
||||
unitGuiScreen = "";
|
||||
}
|
||||
|
||||
bool ActiveGameState::selectedUnitsAmongst(vector<Unit*> units){
|
||||
@@ -193,6 +194,7 @@ namespace battleship{
|
||||
guiManager->getText("wealth"),
|
||||
guiManager->getText("research")
|
||||
};
|
||||
vector<Unit*> selUnits = mainPlayer->getSelectedUnits();
|
||||
|
||||
|
||||
for (Unit *u : units) {
|
||||
@@ -200,16 +202,11 @@ namespace battleship{
|
||||
Vector3 dragboxSize = ((Quad*)dragboxNode->getMesh(0))->getSize();
|
||||
Vector3 dragboxOrigin = dragboxNode->getPosition(), dragboxEnd = dragboxOrigin + dragboxSize;
|
||||
Vector2 pos = u->getScreenPos();
|
||||
string guiScreen = u->getBuildableUnitGuiScreen();
|
||||
|
||||
if(buttons.empty()){
|
||||
if(selectedUnitsAmongst(mainPlayer->getUnitsByClass(UnitClass::ENGINEER)))
|
||||
guiManager->readLuaScreenScript("engineerCommands.lua", buttons, listboxes, checkboxes, sliders, textboxes, guiRects, texts);
|
||||
else if(selectedUnitsAmongst(mainPlayer->getUnitsByClass(UnitClass::FORT)))
|
||||
guiManager->readLuaScreenScript("fortCommands.lua", buttons, listboxes, checkboxes, sliders, textboxes, guiRects, texts);
|
||||
else if(selectedUnitsAmongst(mainPlayer->getUnitsByClass(UnitClass::LAND_FACTORY)))
|
||||
guiManager->readLuaScreenScript("landFactoryCommands.lua", buttons, listboxes, checkboxes, sliders, textboxes, guiRects, texts);
|
||||
else if(selectedUnitsAmongst(mainPlayer->getUnitsByClass(UnitClass::NAVAL_FACTORY)))
|
||||
guiManager->readLuaScreenScript("navalFactoryCommands.lua", buttons, listboxes, checkboxes, sliders, textboxes, guiRects, texts);
|
||||
if(!selUnits.empty() && u == selUnits[0] && guiScreen != "" && guiScreen != unitGuiScreen){
|
||||
guiManager->readLuaScreenScript(u->getBuildableUnitGuiScreen(), buttons, listboxes, checkboxes, sliders, textboxes, guiRects, texts);
|
||||
unitGuiScreen = guiScreen;
|
||||
}
|
||||
|
||||
if(isSelectionBox && fabs(pos.x - dragboxOrigin.x) < .5 * dragboxSize.x && fabs(pos.y - dragboxOrigin.y) < .5 * dragboxSize.y){
|
||||
|
||||
@@ -47,6 +47,7 @@ namespace battleship{
|
||||
|
||||
GuiAppState *guiState;
|
||||
Player *mainPlayer;
|
||||
std::string unitGuiScreen = "";
|
||||
GameObject *gameObjHoveredOn = nullptr;
|
||||
vb01::Node *dragboxNode = nullptr;
|
||||
vb01::Vector2 clickPoint;
|
||||
|
||||
+15
-6
@@ -1,8 +1,12 @@
|
||||
#include "buildButton.h"
|
||||
#include "gameManager.h"
|
||||
#include "gameObject.h"
|
||||
#include "unit.h"
|
||||
#include "activeGameState.h"
|
||||
#include "buildableUnit.h"
|
||||
#include "gameObjectFrameController.h"
|
||||
|
||||
#include <stateManager.h>
|
||||
#include <solUtil.h>
|
||||
|
||||
namespace battleship{
|
||||
@@ -12,13 +16,18 @@ namespace battleship{
|
||||
using namespace vb01Gui;
|
||||
using namespace gameBase;
|
||||
|
||||
BuildButton::BuildButton(Vector2 pos, Vector2 size, int structureId, string name, int trigger, string imagePath) : UnitButton(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, imagePath){
|
||||
this->structureId = structureId;
|
||||
}
|
||||
BuildButton::BuildButton(Vector2 pos, Vector2 size, string name, int trigger, string imagePath, int uid, int slId) :
|
||||
UnitButton(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, imagePath, uid), slotId(slId){}
|
||||
|
||||
void BuildButton::onClick(){
|
||||
GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton();
|
||||
ufCtr->addGameObjectFrame(GameObjectFrame(structureId, GameObject::Type::UNIT));
|
||||
ufCtr->setPlacingFrames(true);
|
||||
ActiveGameState *activeState = (ActiveGameState*)(GameManager::getSingleton()->getStateManager()->getAppStateByType((int)AppStateType::ACTIVE_STATE));
|
||||
Player *player = activeState->getPlayer();
|
||||
Unit* builder = player->getUnitsById(unitId)[0];
|
||||
|
||||
if(builder->getBuildableUnit(slotId).buildable){
|
||||
GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton();
|
||||
ufCtr->addGameObjectFrame(GameObjectFrame(builder->getBuildableUnit(slotId).id, GameObject::Type::UNIT));
|
||||
ufCtr->setPlacingFrames(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -6,10 +6,10 @@
|
||||
namespace battleship{
|
||||
class BuildButton : public UnitButton{
|
||||
public:
|
||||
BuildButton(vb01::Vector2, vb01::Vector2, int, std::string, int, std::string);
|
||||
BuildButton(vb01::Vector2, vb01::Vector2, std::string, int, std::string, int, int);
|
||||
void onClick();
|
||||
private:
|
||||
int structureId;
|
||||
int slotId;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+12
-8
@@ -163,30 +163,34 @@ namespace battleship{
|
||||
}
|
||||
case BUILD:
|
||||
{
|
||||
int strId = guiTable["structureId"];
|
||||
int unitId = SOL_LUA_STATE["UnitId"]["ENGINEER"];
|
||||
int strId = SOL_LUA_STATE["units"][unitId + 1]["buildableUnits"][guiId + 1]["id"];
|
||||
string buttonName = SOL_LUA_STATE["units"][strId + 1]["name"];
|
||||
button = new BuildButton(pos, size, strId, buttonName, (int)guiTable["trigger"], (string)guiTable["imagePath"]);
|
||||
button = new BuildButton(pos, size, buttonName, (int)guiTable["trigger"], (string)guiTable["imagePath"], unitId, guiId);
|
||||
break;
|
||||
}
|
||||
case LAND_FACTORY_TRAIN:
|
||||
{
|
||||
int unitId = guiTable["unitId"];
|
||||
int facId = SOL_LUA_STATE["UnitId"]["LAND_FACTORY"];
|
||||
int unitId = SOL_LUA_STATE["units"][facId + 1]["buildableUnits"][guiId + 1]["id"];
|
||||
string buttonName = SOL_LUA_STATE["units"][unitId + 1]["name"];
|
||||
button = new TrainButton(pos, size, buttonName, (int)guiTable["trigger"], (string)guiTable["imagePath"], (int)SOL_LUA_STATE["UnitId"]["LAND_FACTORY"], unitId);
|
||||
button = new TrainButton(pos, size, buttonName, (int)guiTable["trigger"], (string)guiTable["imagePath"], facId, guiId);
|
||||
break;
|
||||
}
|
||||
case NAVAL_FACTORY_TRAIN:
|
||||
{
|
||||
int unitId = guiTable["unitId"];
|
||||
int facId = SOL_LUA_STATE["UnitId"]["NAVAL_FACTORY"];
|
||||
int unitId = SOL_LUA_STATE["units"][facId + 1]["buildableUnits"][guiId + 1]["id"];
|
||||
string buttonName = SOL_LUA_STATE["units"][unitId + 1]["name"];
|
||||
button = new TrainButton(pos, size, buttonName, (int)guiTable["trigger"], (string)guiTable["imagePath"], (int)SOL_LUA_STATE["UnitId"]["NAVAL_FACTORY"], unitId);
|
||||
button = new TrainButton(pos, size, buttonName, (int)guiTable["trigger"], (string)guiTable["imagePath"], facId, guiId);
|
||||
break;
|
||||
}
|
||||
case FORT_TRAIN:
|
||||
{
|
||||
int unitId = guiTable["unitId"];
|
||||
int facId = SOL_LUA_STATE["UnitId"]["FORT"];
|
||||
int unitId = SOL_LUA_STATE["units"][facId + 1]["buildableUnits"][guiId + 1]["id"];
|
||||
string buttonName = SOL_LUA_STATE["units"][unitId + 1]["name"];
|
||||
button = new TrainButton(pos, size, buttonName, (int)guiTable["trigger"], (string)guiTable["imagePath"], (int)SOL_LUA_STATE["UnitId"]["FORT"], unitId);
|
||||
button = new TrainButton(pos, size, buttonName, (int)guiTable["trigger"], (string)guiTable["imagePath"], facId, guiId);
|
||||
break;
|
||||
}
|
||||
case STATISTICS:
|
||||
|
||||
+14
@@ -1,5 +1,6 @@
|
||||
#include "factory.h"
|
||||
#include "player.h"
|
||||
#include "game.h"
|
||||
#include "gameObjectFactory.h"
|
||||
#include "activeGameState.h"
|
||||
|
||||
@@ -24,6 +25,14 @@ namespace battleship{
|
||||
train();
|
||||
}
|
||||
|
||||
//TODO replace repetetive string literals
|
||||
void Factory::initProperties(){
|
||||
Structure::initProperties();
|
||||
Game *game = Game::getSingleton();
|
||||
vector<int> currTechs = player->getTechnologies();
|
||||
|
||||
}
|
||||
|
||||
int Factory::getNumQueueUnitsById(int unitId){
|
||||
int numUnits = 0;
|
||||
|
||||
@@ -34,6 +43,11 @@ namespace battleship{
|
||||
return numUnits;
|
||||
}
|
||||
|
||||
void Factory::appendToQueue(int buId){
|
||||
if(buId < buildableUnits.size() && buildableUnits[buId].buildable)
|
||||
unitQueue.push_back(buildableUnits[buId].id);
|
||||
}
|
||||
|
||||
void Factory::train(){
|
||||
bool training = !unitQueue.empty();
|
||||
buildStatusForeground->setVisible(training);
|
||||
|
||||
@@ -19,14 +19,14 @@ namespace battleship{
|
||||
~Factory(){}
|
||||
void update();
|
||||
int getNumQueueUnitsById(int);
|
||||
void appendToQueue(int uid){unitQueue.push_back(uid);}
|
||||
void appendToQueue(int);
|
||||
inline std::vector<int> getQueue(){return unitQueue;}
|
||||
private:
|
||||
const int MAX_LEN_QUEUE = 10;
|
||||
int trainingStatus = 0;
|
||||
vb01::s64 lastTrainTime = 0;
|
||||
std::vector<int> unitQueue;
|
||||
int maxLenQueue, trainingStatus = 0;
|
||||
vb01::s64 lastTrainTime = 0;
|
||||
|
||||
void initProperties();
|
||||
void train();
|
||||
};
|
||||
}
|
||||
|
||||
+7
-8
@@ -1,5 +1,6 @@
|
||||
#include "trainButton.h"
|
||||
#include "activeGameState.h"
|
||||
#include "buildableUnit.h"
|
||||
#include "factory.h"
|
||||
|
||||
#include <stateManager.h>
|
||||
@@ -10,19 +11,17 @@ namespace battleship{
|
||||
using namespace vb01;
|
||||
using namespace gameBase;
|
||||
|
||||
TrainButton::TrainButton(Vector2 pos, Vector2 size, string name, int trigger, string imagePath, int fid, int tuid) :
|
||||
factoryId(fid),
|
||||
trainableUnitId(tuid),
|
||||
UnitButton(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, imagePath){}
|
||||
TrainButton::TrainButton(Vector2 pos, Vector2 size, string name, int trigger, string imagePath, int uid, int slId) :
|
||||
UnitButton(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, imagePath, uid),
|
||||
slotId(slId) {}
|
||||
|
||||
void TrainButton::onClick(){
|
||||
ActiveGameState *activeState = (ActiveGameState*)(GameManager::getSingleton()->getStateManager()->getAppStateByType((int)AppStateType::ACTIVE_STATE));
|
||||
Player *player = activeState->getPlayer();
|
||||
UnitClass facClass = (UnitClass)generateView()["units"][factoryId + 1]["unitClass"];
|
||||
vector<Unit*> selUnits = player->getSelectedUnits(), factories = player->getUnitsByClass(facClass);
|
||||
vector<Unit*> selUnits = player->getSelectedUnits(), factories = player->getUnitsById(unitId);
|
||||
|
||||
for(Unit *fac : factories)
|
||||
if(find(selUnits.begin(), selUnits.end(), fac) != selUnits.end())
|
||||
((Factory*)fac)->appendToQueue(trainableUnitId);
|
||||
if(fac->getBuildableUnit(slotId).buildable && find(selUnits.begin(), selUnits.end(), fac) != selUnits.end())
|
||||
((Factory*)fac)->appendToQueue(slotId);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ namespace battleship{
|
||||
TrainButton(vb01::Vector2, vb01::Vector2, std::string, int, std::string, int, int);
|
||||
void onClick();
|
||||
private:
|
||||
int factoryId, trainableUnitId;
|
||||
int slotId;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
#include "vehicle.h"
|
||||
#include "gameObjectFactory.h"
|
||||
#include "activeGameState.h"
|
||||
#include "gameManager.h"
|
||||
#include "projectile.h"
|
||||
#include "defConfigs.h"
|
||||
#include "pathfinder.h"
|
||||
#include "ability.h"
|
||||
@@ -171,6 +173,20 @@ namespace battleship{
|
||||
armorTypes.push_back(arm);
|
||||
}
|
||||
}
|
||||
|
||||
tblName = "buildableUnits";
|
||||
sol::optional<sol::table> bu = unitTable[tblName];
|
||||
|
||||
if(bu != sol::nullopt){
|
||||
SOL_LUA_VIEW.script("numBuildableUnits = #units[" + to_string(id + 1) + "]." + tblName);
|
||||
int numBuildableUnits = SOL_LUA_VIEW["numBuildableUnits"];
|
||||
buildableUnitGuiScreen = unitTable["guiScreen"];
|
||||
|
||||
for(int i = 0; i < numBuildableUnits; i++){
|
||||
sol::table buTable = unitTable[tblName][i + 1];
|
||||
buildableUnits.push_back(BuildableUnit(buTable["id"], buTable["buildable"]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::initWeapons(){
|
||||
|
||||
@@ -8,9 +8,8 @@
|
||||
|
||||
#include <solUtil.h>
|
||||
|
||||
#include "gameManager.h"
|
||||
#include "gameObject.h"
|
||||
#include "projectile.h"
|
||||
#include "buildableUnit.h"
|
||||
|
||||
namespace sf{
|
||||
class SoundBuffer;
|
||||
@@ -31,8 +30,9 @@ namespace battleship{
|
||||
class Structure;
|
||||
class Factory;
|
||||
class Cruiser;
|
||||
class PointDefense;
|
||||
class Engineer;
|
||||
class PointDefense;
|
||||
class Projectile;
|
||||
|
||||
struct Order {
|
||||
enum class TYPE {ATTACK, BUILD, MOVE, GARRISON, EJECT, PATROL, LAUNCH, SUPPLY, HACK};
|
||||
@@ -149,6 +149,8 @@ namespace battleship{
|
||||
inline bool isTargetToTheRight(vb01::Vector3 dir, vb01::Vector3 lv){return lv.getAngleBetween(dir) > vb01::PI / 2;}
|
||||
inline Order getOrder(int i){return orders[i];}
|
||||
inline int getNumOrders(){return orders.size();}
|
||||
inline std::string getBuildableUnitGuiScreen(){return buildableUnitGuiScreen;}
|
||||
inline BuildableUnit getBuildableUnit(int i){return buildableUnits[i];}
|
||||
private:
|
||||
void renderOrderLine(bool);
|
||||
void updateScreenCoordinates();
|
||||
@@ -165,12 +167,14 @@ namespace battleship{
|
||||
UnitClass unitClass;
|
||||
UnitType type;
|
||||
std::vector<Order> orders;
|
||||
std::string buildableUnitGuiScreen = "";
|
||||
int health, maxHealth, playerId, lenHpBar = 200;
|
||||
s64 orderLineDispTime = 0, lastFireTime = 0;
|
||||
vb01::s64 orderLineDispTime = 0, lastFireTime = 0;
|
||||
float lineOfSight;
|
||||
std::vector<GarrisonSlot> garrisonSlots;
|
||||
std::vector<Armor> armorTypes;
|
||||
std::vector<Weapon*> weapons;
|
||||
std::vector<GarrisonSlot> garrisonSlots;
|
||||
std::vector<BuildableUnit> buildableUnits;
|
||||
State state = State::STAND_GROUND;
|
||||
|
||||
std::vector<Player*> getSelectingPlayers();
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ namespace battleship{
|
||||
using namespace vb01Gui;
|
||||
using namespace gameBase;
|
||||
|
||||
UnitButton::UnitButton(Vector2 pos, Vector2 size, string name, string fontPath, int trigger, string imagePath) : Button(pos, size, name, fontPath, trigger, true, imagePath){
|
||||
UnitButton::UnitButton(Vector2 pos, Vector2 size, string name, string fontPath, int trigger, string imagePath, int uid) : Button(pos, size, name, fontPath, trigger, true, imagePath), unitId(uid){
|
||||
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
|
||||
ActiveGameState *activeState = (ActiveGameState*)stateManager->getAppStateByType((int)AppStateType::ACTIVE_STATE);
|
||||
|
||||
|
||||
+2
-1
@@ -8,8 +8,9 @@ namespace battleship{
|
||||
|
||||
class UnitButton : public vb01Gui::Button{
|
||||
public:
|
||||
UnitButton(vb01::Vector2, vb01::Vector2, std::string, std::string, int, std::string);
|
||||
UnitButton(vb01::Vector2, vb01::Vector2, std::string, std::string, int, std::string, int);
|
||||
protected:
|
||||
int unitId;
|
||||
std::vector<Unit*> units;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user