trainable units

This commit is contained in:
devZoGok
2023-11-26 08:21:13 +02:00
parent 29679a0e45
commit 6a2b9d8fe8
24 changed files with 215 additions and 31 deletions
@@ -1,2 +1 @@
numStructures = 1
maxUnevenness = 0.5
@@ -1,4 +1,4 @@
speed = {.025, .025, .025, .025, .05, .05, .1, .1, .1, .1, .1, .1, .15}
destinationOffset = {.75, .75, .75, .75, 1, 1, .1, .1, .1, .1, .1, .5, .5}
anglePrecision = {.1, .1, .1, .1, .1, .1, .1, .1, .1, .1, .1, 3, 3}
maxTurnAngle = {.1, .1, .1, .1, .5, .5, 1, 1, .5, .5, 1, 2, 2}
units.speed = {.025, .025, .025, .025, .05, .05, .1, .1, .1, .1, .1, .1, .15}
units.destinationOffset = {.75, .75, .75, .75, 1, 1, .1, .1, .1, .1, .1, .5, .5}
units.anglePrecision = {.1, .1, .1, .1, .1, .1, .1, .1, .1, .1, .1, 3, 3}
units.maxTurnAngle = {.1, .1, .1, .1, .5, .5, 1, 1, .5, .5, 1, 2, 2}
+1
View File
@@ -6,6 +6,7 @@ gui = {
pos = {x = res.x - 200, y = res.y - 200},
size = {x = 100, y = 100},
name = 'Point defense',
imagePath = '',
guiType = GuiType.BUTTON,
buttonType = ButtonType.BUILD,
trigger = 66,
@@ -0,0 +1,26 @@
numGui = 2
res = graphics.resolution
Size = {x = 100, y = 100}
gui = {
{
pos = {x = res.x - 200, y = res.y - 200},
size = Size,
name = 'Tank',
imagePath = '',
guiType = GuiType.BUTTON,
buttonType = ButtonType.LAND_FACTORY_TRAIN,
trigger = 84,
unitId = 1
},
{
pos = {x = res.x - Size.x - 200, y = res.y - 200},
size = Size,
name = 'Artillery',
imagePath = '',
guiType = GuiType.BUTTON,
buttonType = ButtonType.LAND_FACTORY_TRAIN,
trigger = 65,
unitId = 2
}
}
+3 -1
View File
@@ -23,7 +23,9 @@ ButtonType = {
CONSOLE = 19,
MAIN_MENU = 20,
CONSOLE_COMMAND_OK = 21,
BUILD = 22
BUILD = 22,
LAND_FACTORY_TRAIN = 23,
NAVAL_FACTORY_TRAIN = 24
}
ListboxType = {
@@ -0,0 +1,15 @@
numGui = 1
res = graphics.resolution
gui = {
{
pos = {x = res.x - 200, y = res.y - 200},
size = {x = 100, y = 100},
name = 'Transport',
imagePath = '',
guiType = GuiType.BUTTON,
buttonType = ButtonType.NAVAL_FACTORY_TRAIN,
trigger = 66,
unitId = 4
}
}
+3 -2
View File
@@ -8,7 +8,7 @@ set(CMAKE_BUILD_TYPE Debug)
set(BUILD_TESTS ON)
cmake_policy(SET CMP0015 NEW)
set(UNIT_BUTTONS unitButton.cpp buildButton.cpp)
set(UNIT_BUTTONS unitButton.cpp buildButton.cpp trainButton.cpp)
set(OPTIONS_BUTTONS optionsButton.cpp tabButton.cpp okButton.cpp defaultsButton.cpp)
set(IN_GAME_APP_STATE_BUTTONS mainMenuButton.cpp)
set(MAP_EDITOR_BUTTONS mapEditorButton.cpp newMapButton.cpp loadMapButton.cpp exportButton.cpp)
@@ -24,7 +24,8 @@ set(CORE gameManager.cpp game.cpp defConfigs.cpp ${CONSOLE} ${CONTROLLERS})
set(PROJECTILES projectile.cpp)
set(FX fx.cpp)
set(VEHICLES vehicle.cpp engineer.cpp transport.cpp)
set(UNITS gameObjectFactory.cpp unit.cpp structure.cpp ${VEHICLES})
set(STRUCTURES structure.cpp factory.cpp)
set(UNITS gameObjectFactory.cpp unit.cpp ${STRUCTURES} ${VEHICLES})
set(CONTENT player.cpp pathfinder.cpp map.cpp gameObject.cpp gameObjectFrame.h resourceDeposit.cpp ${UNITS} ${PROJECTILES} ${FX})
set(GAME_SRC ${STATES} ${GUI} ${CORE} ${CONTENT} ${UTIL})
+7 -10
View File
@@ -190,16 +190,20 @@ namespace battleship{
for (Unit *u : p->getUnits())
units.push_back(u);
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
for (Unit *u : units) {
if (u->getPlayer() == mainPlayer){
Vector3 dragboxSize = ((Quad*)dragboxNode->getMesh(0))->getSize();
Vector3 dragboxOrigin = dragboxNode->getPosition(), dragboxEnd = dragboxOrigin + dragboxSize;
Vector2 pos = u->getScreenPos();
if(unitClassSelected(UnitClass::ENGINEER)){
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
if(!mainPlayer->getSelectedUnitsByClass(UnitClass::ENGINEER).empty())
guiManager->readLuaScreenScript("engineerCommands.lua");
}
else if(!mainPlayer->getSelectedUnitsByClass(UnitClass::LAND_FACTORY).empty())
guiManager->readLuaScreenScript("landFactoryCommands.lua");
else if(!mainPlayer->getSelectedUnitsByClass(UnitClass::NAVAL_FACTORY).empty())
guiManager->readLuaScreenScript("navalFactoryCommands.lua");
if(isSelectionBox && fabs(pos.x - dragboxOrigin.x) < .5 * dragboxSize.x && fabs(pos.y - dragboxOrigin.y) < .5 * dragboxSize.y){
if(!u->isSelected()){
@@ -310,13 +314,6 @@ namespace battleship{
}
}
bool ActiveGameState::unitClassSelected(UnitClass uc){
for(Unit *u : mainPlayer->getSelectedUnits())
if(u->getUnitClass() == uc)
return true;
return false;
}
void ActiveGameState::onAction(int bind, bool isPressed) {
GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton();
-1
View File
@@ -41,7 +41,6 @@ namespace battleship{
void castRayToTerrain();
void issueOrder(Order::TYPE, std::vector<Order::Target>, bool);
bool isInLineOfSight(vb01::Vector3, float, Unit*);
bool unitClassSelected(UnitClass);
inline bool canSelectHoveredOnGameObj(){return gameObjHoveredOn && gameObjHoveredOn->isSelectable() && gameObjHoveredOn->getPlayer() == mainPlayer;}
GuiAppState *guiState;
+2 -1
View File
@@ -13,6 +13,7 @@ namespace battleship{
using namespace gameBase;
using namespace vb01;
//TODO implement structure build status argument
void AddUnitCommand::validate(){
if(!(arguments.size() == 2 || arguments.size() == 5 || arguments.size() == 9))
return;
@@ -49,7 +50,7 @@ namespace battleship{
void AddUnitCommand::addUnit(){
Player* player = Game::getSingleton()->getPlayer(playerId);
player->addUnit(GameObjectFactory::createUnit(player, unitId, pos, rot));
player->addUnit(GameObjectFactory::createUnit(player, unitId, pos, rot, 100));
}
void AddUnitCommand::execute(){
+7 -1
View File
@@ -20,6 +20,7 @@
#include "inGameAppState.h"
#include "mainMenuButton.h"
#include "buildButton.h"
#include "trainButton.h"
namespace battleship{
using namespace std;
@@ -156,7 +157,12 @@ namespace battleship{
break;
}
case BUILD:
button = new BuildButton(pos, size, (int)guiTable["structureId"], name, (int)guiTable["trigger"], "");
button = new BuildButton(pos, size, (int)guiTable["structureId"], name, (int)guiTable["trigger"], (string)guiTable["imagePath"]);
break;
case LAND_FACTORY_TRAIN:
button = new TrainButton(pos, size, name, (int)guiTable["trigger"], (string)guiTable["imagePath"], (int)UnitClass::LAND_FACTORY, (int)guiTable["unitId"]);
case NAVAL_FACTORY_TRAIN:
button = new TrainButton(pos, size, name, (int)guiTable["trigger"], (string)guiTable["imagePath"], (int)UnitClass::NAVAL_FACTORY, (int)guiTable["unitId"]);
break;
}
+3 -1
View File
@@ -32,7 +32,9 @@ namespace battleship{
CONSOLE_SCREEN,
MAIN_MENU,
CONSOLE_COMMAND_OK,
BUILD
BUILD,
LAND_FACTORY_TRAIN,
NAVAL_FACTORY_TRAIN
};
enum ListboxType {
CONTROLS,
+46
View File
@@ -0,0 +1,46 @@
#include "factory.h"
#include "player.h"
#include "gameObjectFactory.h"
namespace battleship{
using namespace vb01;
Factory::Factory(Player *player, int id, Vector3 pos, Quaternion rot, int buildStatus) : Structure(player, id, pos, rot, buildStatus){
initProperties();
}
void Factory::initProperties(){
}
void Factory::update(){
Structure::update();
if(!unitQueue.empty())
train();
}
void Factory::appendToQueue(int uc){
unitQueue.push_back(uc);
}
void Factory::train(){
bool training = !unitQueue.empty();
buildStatusForeground->setVisible(training);
buildStatusBackground->setVisible(training);
if(training){
Unit::displayUnitStats(buildStatusForeground, buildStatusBackground, trainingStatus, 100, Vector2(0, -10));
if(canTrain()){
trainingStatus++;
lastTrainTime = getTime();
}
if(trainingStatus >= 100){
unitQueue.erase(unitQueue.begin());
trainingStatus = 0;
player->addUnit(GameObjectFactory::createUnit(player, unitQueue[0], pos + 30 * dirVec, rot));
}
}
}
}
+34
View File
@@ -0,0 +1,34 @@
#ifndef FACTORY_H
#define FACTORY_H
#include "structure.h"
#include <vector>
#include <util.h>
namespace vb01{
class Node;
}
namespace battleship{
class Player;
class Factory : public Structure{
public:
Factory(Player*, int, vb01::Vector3, vb01::Quaternion, int = 0);
~Factory(){}
void update();
void appendToQueue(int);
private:
const int MAX_LEN_QUEUE = 10;
int trainingStatus = 0, rateOfTraining = 50;
vb01::s64 lastTrainTime = 0;
std::vector<int> unitQueue;
void train();
void initProperties();
inline bool canTrain(){return vb01::getTime() - lastTrainTime > rateOfTraining;}
};
}
#endif
+4 -3
View File
@@ -1,6 +1,6 @@
#include "gameObjectFactory.h"
#include "player.h"
#include "structure.h"
#include "factory.h"
#include "engineer.h"
#include "transport.h"
#include "projectile.h"
@@ -16,7 +16,7 @@ namespace battleship{
using namespace vb01;
using namespace gameBase;
Unit* GameObjectFactory::createUnit(Player *player, int id, Vector3 pos, Quaternion rot){
Unit* GameObjectFactory::createUnit(Player *player, int id, Vector3 pos, Quaternion rot, int buildStatus){
sol::state_view SOL_LUA_STATE = generateView();
int unitClass = SOL_LUA_STATE["units"]["unitClass"][id + 1];
@@ -27,10 +27,11 @@ namespace battleship{
return new Transport(player, id, pos, rot);
case UnitClass::LAND_FACTORY:
case UnitClass::NAVAL_FACTORY:
return new Factory(player, id, pos, rot, buildStatus);
case UnitClass::MARKET:
case UnitClass::LAB:
case UnitClass::POINT_DEFENSE:
return new Structure(player, id, pos, rot);
return new Structure(player, id, pos, rot, buildStatus);
default:
return new Vehicle(player, id, pos, rot);
}
+1 -1
View File
@@ -13,7 +13,7 @@ namespace battleship{
class GameObjectFactory{
public:
enum GameObjectType{UNIT, PROJECTILE, RESOURCE_DEPOSIT};
static Unit* createUnit(Player*, int, vb01::Vector3, vb01::Quaternion);
static Unit* createUnit(Player*, int, vb01::Vector3, vb01::Quaternion, int = 0);
static Projectile* createProjectile(Unit*, int, vb01::Vector3, vb01::Quaternion);
static ResourceDeposit* createResourceDeposit(Player*, int, vb01::Vector3, vb01::Quaternion);
private:
+10
View File
@@ -157,6 +157,16 @@ namespace battleship{
return selectedUnit;
}
vector<Unit*> Player::getSelectedUnitsByClass(UnitClass uc){
vector<Unit*> selectedUnits = getSelectedUnits(), unitsByClass;
for(Unit *u : selectedUnits)
if(u->getUnitClass() == uc)
unitsByClass.push_back(u);
return unitsByClass;
}
void Player::selectUnits(vector<Unit*> selUnits){
for(Unit *u : selUnits)
u->toggleSelection(true);
+1
View File
@@ -20,6 +20,7 @@ namespace battleship{
void removeUnit(Unit*);
void removeUnit(int);
bool isThisPlayersUnit(GameObject*);
std::vector<Unit*> getSelectedUnitsByClass(UnitClass);
std::vector<Unit*> getSelectedUnits();
Unit* getSelectedUnit(int);
void selectUnits(std::vector<Unit*>);
+1 -3
View File
@@ -7,9 +7,7 @@ using namespace vb01;
using namespace std;
namespace battleship{
Structure::Structure(Player *player, int id, Vector3 pos, Quaternion rot, int buildStatus) : Unit(player, id, pos, rot){
this->buildStatus = buildStatus;
Structure::Structure(Player *player, int id, Vector3 pos, Quaternion rot, int bldSt) : buildStatus(bldSt), Unit(player, id, pos, rot){
Vector2 size = Vector2(lenHpBar, 10);
buildStatusBackground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 0, 1));
buildStatusForeground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 1, 1));
+2 -1
View File
@@ -17,7 +17,8 @@ namespace battleship{
virtual void update();
private:
int buildStatus = 0;
vb01::Node *buildStatusBackground, *buildStatusForeground;
protected:
vb01::Node *buildStatusBackground = nullptr, *buildStatusForeground = nullptr;
};
}
+27
View File
@@ -0,0 +1,27 @@
#include "trainButton.h"
#include "activeGameState.h"
#include "factory.h"
#include <stateManager.h>
#include <solUtil.h>
namespace battleship{
using namespace std;
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){}
void TrainButton::onClick(){
ActiveGameState *activeState = (ActiveGameState*)(GameManager::getSingleton()->getStateManager()->getAppStateByType((int)AppStateType::ACTIVE_STATE));
Player *player = activeState->getPlayer();
UnitClass facClass = (UnitClass)generateView()["units"]["unitClass"][factoryId + 1];
vector<Unit*> factories = player->getSelectedUnitsByClass(facClass);
for(Unit *fac : factories)
((Factory*)fac)->appendToQueue(trainableUnitId);
}
}
+16
View File
@@ -0,0 +1,16 @@
#ifndef TRAIN_BUTTON_H
#define TRAIN_BUTTON_H
#include "unitButton.h"
namespace battleship{
class TrainButton : public UnitButton{
public:
TrainButton(vb01::Vector2, vb01::Vector2, std::string, int, std::string, int, int);
void onClick();
private:
int factoryId, trainableUnitId;
};
}
#endif
+1
View File
@@ -24,6 +24,7 @@ using namespace gameBase;
using namespace std;
namespace battleship{
//TODO remove the player member field
Unit::Unit(Player *player, int id, Vector3 pos, Quaternion rot) : GameObject(GameObject::Type::UNIT, id, player, pos, rot){
this->id = id;
this->player = player;
+1 -1
View File
@@ -83,7 +83,7 @@ namespace battleship{
}
void Vehicle::initProperties(){
sol::state_view SOL_LUA_STATE = generateView();
sol::table SOL_LUA_STATE = generateView()[GameObject::getGameObjTableName()];
maxTurnAngle = SOL_LUA_STATE["maxTurnAngle"][id + 1];
speed = SOL_LUA_STATE["speed"][id + 1];
anglePrecision = SOL_LUA_STATE["anglePrecision"][id + 1];