From bce93977bd5bcc6295c8178d5269e379154f8a7e Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 25 Feb 2024 15:19:10 +0200 Subject: [PATCH] technologies in posession improve unit abilities --- Assets/Scripts/Abilities/abilityData.lua | 22 +++++++++-- .../Scripts/Technologies/technologyData.lua | 2 +- ability.h | 31 +++++++++++++++ defConfigs.h | 1 + engineer.cpp | 4 +- extractor.cpp | 14 +++++-- extractor.h | 2 + game.cpp | 39 +++++++++++++++++-- game.h | 3 ++ projectile.cpp | 17 ++++---- resourceRover.cpp | 17 +++++--- resourceRover.h | 1 + unit.cpp | 9 ++++- vehicle.cpp | 9 ++++- 14 files changed, 142 insertions(+), 29 deletions(-) create mode 100644 ability.h diff --git a/Assets/Scripts/Abilities/abilityData.lua b/Assets/Scripts/Abilities/abilityData.lua index 0bef041..c2dd186 100644 --- a/Assets/Scripts/Abilities/abilityData.lua +++ b/Assets/Scripts/Abilities/abilityData.lua @@ -1,5 +1,19 @@ -AbilityType = {SPEED = 0} - -ablilities = { - {type = AbilityType.SPEED, ammount = .2, units = {UnitClass.WAR_MECH}} +AbilityType = { + SPEED = 0, + HEALTH = 1, + LINE_OF_SIGHT = 1, + MAX_TURN_ANGLE = 2, + DIRECT_HIT_DAMAGE = 3, + EXPLOSION_RADIUS = 4, + EXPLOSION_DAMAGE = 5, + CAPACITY = 6, + LOAD_RATE = 7, + LOAD_SPEED = 8, + DRAW_RATE = 9, + DRAW_SPEED = 10, + HACK_RANGE = 11 +} + +abilities = { + {type = AbilityType.SPEED, gameObjType = 0, ammount = .4, gameObjIds = {UnitId.WAR_MECH}} } diff --git a/Assets/Scripts/Technologies/technologyData.lua b/Assets/Scripts/Technologies/technologyData.lua index 9d34b9f..0c7324f 100644 --- a/Assets/Scripts/Technologies/technologyData.lua +++ b/Assets/Scripts/Technologies/technologyData.lua @@ -14,7 +14,7 @@ technologies = { description = '', parents = {}, children = {}, - abilities = {}, + abilities = {0}, }, { id = TechnologyId.EFT, diff --git a/ability.h b/ability.h new file mode 100644 index 0000000..d3c92b0 --- /dev/null +++ b/ability.h @@ -0,0 +1,31 @@ +#ifndef ABILITY_H +#define ABILITY_H + +#include + +namespace battleship{ + struct Ability{ + enum class Type{ + SPEED, + HEALTH, + LINE_OF_SIGHT, + MAX_TURN_ANGLE, + DIRECT_HIT_DAMAGE, + EXPLOSION_RADIUS, + EXPLOSION_DAMAGE, + CAPACITY, + LOAD_RATE, + LOAD_SPEED, + DRAW_RATE, + DRAW_SPEED, + HACK_RANGE + }; + + Type type; + float ammount; + int gameObjType; + std::vector gameObjIds; + }; +} + +#endif diff --git a/defConfigs.h b/defConfigs.h index ea9aabe..0bcf9ff 100755 --- a/defConfigs.h +++ b/defConfigs.h @@ -52,6 +52,7 @@ namespace battleship{ "Scripts/aiAgent.lua", "Scripts/Core/player.lua", "Scripts/Technologies/technologyData.lua", + "Scripts/Abilities/abilityData.lua", }; const static Bind staticBinds[numAppStates][maxStaticBinds]{ diff --git a/engineer.cpp b/engineer.cpp index b2015d8..36a11d6 100644 --- a/engineer.cpp +++ b/engineer.cpp @@ -16,7 +16,9 @@ namespace battleship{ using namespace gameBase; Engineer::Engineer(Player *player, int id, Vector3 pos, Quaternion rot, Unit::State state) : Vehicle(player, id, pos, rot, state){ - hackRange = generateView()["units"][id + 1]["hackRange"]; + Game *game = Game::getSingleton(); + vector currTechs = player->getTechnologies(); + hackRange = generateView()["units"][id + 1]["hackRange"]; hackRange += game->calcAbilFromTech(Ability::Type::HACK_RANGE, currTechs, (int)GameObject::type, id); Vector2 size = Vector2(lenHpBar, 10); hackStatusBackground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 0, 1)); diff --git a/extractor.cpp b/extractor.cpp index 19c5692..23fcb6a 100644 --- a/extractor.cpp +++ b/extractor.cpp @@ -27,10 +27,6 @@ namespace battleship{ } } - sol::table unitTable = generateView()["units"][id + 1]; - drawRate = unitTable["drawRate"]; - drawSpeed = unitTable["drawSpeed"]; - Vector2 size = Vector2(lenHpBar, 10); ammountBackground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 0, 1)); ammountForeground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 1, 1)); @@ -41,6 +37,16 @@ namespace battleship{ removeBar(ammountBackground); } + void Extractor::initProperties(){ + Structure::initProperties(); + Game *game = Game::getSingleton(); + vector currTechs = player->getTechnologies(); + + sol::table unitTable = generateView()["units"][id + 1]; + drawRate = unitTable["drawRate"]; drawRate += game->calcAbilFromTech(Ability::Type::DRAW_RATE, currTechs, (int)GameObject::type, id); + drawSpeed = unitTable["drawSpeed"]; drawSpeed += game->calcAbilFromTech(Ability::Type::DRAW_SPEED, currTechs, (int)GameObject::type, id); + } + void Extractor::update(){ Structure::update(); diff --git a/extractor.h b/extractor.h index a070765..0002eb4 100644 --- a/extractor.h +++ b/extractor.h @@ -17,6 +17,8 @@ namespace battleship{ bool canDraw(){return vb01::getTime() - lastDrawTime > drawRate;} inline ResourceDeposit* getDeposit(){return deposit;} private: + void initProperties(); + int drawSpeed, drawRate; vb01::s64 lastDrawTime = 0; vb01::Node *ammountBackground = nullptr, *ammountForeground = nullptr; diff --git a/game.cpp b/game.cpp index 57eea48..9d65e11 100644 --- a/game.cpp +++ b/game.cpp @@ -7,6 +7,8 @@ #include "concreteGuiManager.h" #include "defConfigs.h" +#include + #include #include @@ -215,11 +217,11 @@ namespace battleship{ unit->halt(); } - vector Game::parseTechTable(int tid, string techKey, string numVarKey, string varKey){ + vector Game::parseTechTable(int tid, string key, string numVarKey, string varKey){ sol::state_view SOL_LUA_VIEW = generateView(); - SOL_LUA_VIEW.script(numVarKey + " = #" + techKey + "[" + to_string(tid + 1) + "]." + varKey); + SOL_LUA_VIEW.script(numVarKey + " = #" + key + "[" + to_string(tid + 1) + "]." + varKey); int numVar = SOL_LUA_VIEW[numVarKey]; - sol::table techTable = SOL_LUA_VIEW[techKey][tid + 1]; + sol::table techTable = SOL_LUA_VIEW[key][tid + 1]; vector varVec; @@ -252,5 +254,36 @@ namespace battleship{ technologies.push_back(t); } + + techKey = "abilities"; + SOL_LUA_VIEW.script("numAbilities = #" + techKey); + int numAbilities = SOL_LUA_VIEW["numAbilities"]; + + for(int i = 0; i < numAbilities; i++){ + sol::table techTable = SOL_LUA_VIEW[techKey][i + 1]; + + Ability ability; + ability.type = techTable["type"]; + ability.ammount = techTable["ammount"]; + ability.gameObjType = techTable["gameObjType"]; + ability.gameObjIds = parseTechTable(i, techKey, "numGameObjIds", "gameObjIds"); + abilities.push_back(ability); + } + } + + float Game::calcAbilFromTech(Ability::Type type, vector techResearch, int gameObjType, int unitId){ + float ammount = 0; + + for(int techId : techResearch) + for(int abilId : technologies[techId].abilities) + if( + abilities[abilId].type == type && + abilities[abilId].gameObjType == gameObjType && + find(abilities[abilId].gameObjIds.begin(), abilities[abilId].gameObjIds.end(), unitId) != abilities[abilId].gameObjIds.end() + ){ + ammount += abilities[abilId].ammount; + } + + return ammount; } } diff --git a/game.h b/game.h index f28e77a..294f3ee 100644 --- a/game.h +++ b/game.h @@ -3,6 +3,7 @@ #include "fx.h" #include "technology.h" +#include "ability.h" #include @@ -25,6 +26,7 @@ namespace battleship{ void explode(vb01::Vector3, int, float, sf::Sound*); void changeUnitPlayer(Unit*, Player*); void initTechnologies(); + float calcAbilFromTech(Ability::Type, std::vector, int, int); inline void addFx(Fx f){fx.push_back(f);} inline void addPlayer(Player *pl){players.push_back(pl);} inline std::vector& getPlayers(){return players;} @@ -39,6 +41,7 @@ namespace battleship{ bool paused = false, ended = false; std::vector fx; std::vector technologies; + std::vector abilities; std::vector players; }; } diff --git a/projectile.cpp b/projectile.cpp index b5a39a8..e362ca5 100755 --- a/projectile.cpp +++ b/projectile.cpp @@ -1,20 +1,21 @@ #include #include #include -#include -#include #include +#include +#include #include +#include "fx.h" #include "game.h" #include "unit.h" #include "util.h" +#include "player.h" #include "projectile.h" -#include "resourceDeposit.h" #include "defConfigs.h" +#include "resourceDeposit.h" #include "inGameAppState.h" -#include "fx.h" using namespace std; using namespace vb01; @@ -51,14 +52,16 @@ namespace battleship{ void Projectile::initProperties(){ GameObject::initProperties(); + Game *game = Game::getSingleton(); + vector currTechs = player->getTechnologies(); sol::table projTable = generateView()[GameObject::getGameObjTableName()][id + 1]; rayLength = projTable["rayLength"]; - directHitDamage = projTable["directHitDamage"]; + directHitDamage = projTable["directHitDamage"]; directHitDamage += game->calcAbilFromTech(Ability::Type::DIRECT_HIT_DAMAGE, currTechs, (int)GameObject::type, id); string explKey = "explosion"; - explosionDamage = projTable[explKey]["damage"]; - explosionRadius = projTable[explKey]["radius"]; + explosionDamage = projTable[explKey]["damage"]; explosionDamage += game->calcAbilFromTech(Ability::Type::EXPLOSION_DAMAGE, currTechs, (int)GameObject::type, id); + explosionRadius = projTable[explKey]["radius"]; explosionRadius += game->calcAbilFromTech(Ability::Type::EXPLOSION_RADIUS, currTechs, (int)GameObject::type, id); speed = projTable["speed"]; rotAngle = projTable["rotAngle"].get_or(0.0); } diff --git a/resourceRover.cpp b/resourceRover.cpp index d507268..1d32d55 100644 --- a/resourceRover.cpp +++ b/resourceRover.cpp @@ -1,6 +1,7 @@ #include "resourceRover.h" #include "resourceDeposit.h" #include "map.h" +#include "game.h" #include "player.h" #include "extractor.h" #include "structure.h" @@ -14,11 +15,6 @@ namespace battleship{ using namespace gameBase; ResourceRover::ResourceRover(Player *player, int id, Vector3 pos, Quaternion rot, Unit::State state) : Vehicle(player, id, pos, rot, state) { - sol::table unitTable = generateView()["units"][id + 1]; - capacity = unitTable["capacity"]; - loadSpeed = unitTable["loadSpeed"]; - loadRate = unitTable["loadRate"]; - Vector2 size = Vector2(lenHpBar, 10); loadBackground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 0, 1)); loadForeground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(1, 1, 0, 1)); @@ -29,6 +25,17 @@ namespace battleship{ removeBar(loadBackground); } + void ResourceRover::initProperties(){ + Vehicle::initProperties(); + Game *game = Game::getSingleton(); + vector currTechs = player->getTechnologies(); + + sol::table unitTable = generateView()["units"][id + 1]; + capacity = unitTable["capacity"]; capacity += game->calcAbilFromTech(Ability::Type::CAPACITY, currTechs, (int)GameObject::type, id); + loadSpeed = unitTable["loadSpeed"]; loadSpeed += game->calcAbilFromTech(Ability::Type::LOAD_SPEED, currTechs, (int)GameObject::type, id); + loadRate = unitTable["loadRate"]; loadRate += game->calcAbilFromTech(Ability::Type::LOAD_RATE, currTechs, (int)GameObject::type, id); + } + void ResourceRover::supply(Order order){ float minDist = .5 * Map::getSingleton()->getCellSize().x; diff --git a/resourceRover.h b/resourceRover.h index b8d4cee..bd1c637 100644 --- a/resourceRover.h +++ b/resourceRover.h @@ -15,6 +15,7 @@ namespace battleship{ ~ResourceRover(); void update(); private: + void initProperties(); void supply(Order); Unit* getClosestUnit(std::vector); inline bool canLoad(){return vb01::getTime() - lastLoadTime > loadRate && load < capacity;} diff --git a/unit.cpp b/unit.cpp index f111577..2c34719 100755 --- a/unit.cpp +++ b/unit.cpp @@ -18,6 +18,7 @@ #include "activeGameState.h" #include "defConfigs.h" #include "pathfinder.h" +#include "ability.h" using namespace glm; using namespace vb01; @@ -126,12 +127,16 @@ namespace battleship{ sol::state_view SOL_LUA_VIEW = generateView(); string objType = GameObject::getGameObjTableName(); sol::table unitTable = SOL_LUA_VIEW[objType][id + 1]; + + Game *game = Game::getSingleton(); + vector currTechs = player->getTechnologies(); + string name = unitTable["name"]; - health = unitTable["health"]; + health = unitTable["health"]; health += game->calcAbilFromTech(Ability::Type::HEALTH, currTechs, (int)GameObject::type, id); vehicle = unitTable["isVehicle"]; maxHealth = health; - lineOfSight = unitTable["lineOfSight"]; + lineOfSight = unitTable["lineOfSight"]; lineOfSight += game->calcAbilFromTech(Ability::Type::LINE_OF_SIGHT, currTechs, (int)GameObject::type, id); unitClass = (UnitClass)unitTable["unitClass"]; type = (UnitType)unitTable["unitType"]; diff --git a/vehicle.cpp b/vehicle.cpp index e95470f..45bd04a 100644 --- a/vehicle.cpp +++ b/vehicle.cpp @@ -10,6 +10,8 @@ #include "vehicle.h" #include "pathfinder.h" +#include "player.h" +#include "game.h" #include "map.h" using namespace gameBase; @@ -83,9 +85,12 @@ namespace battleship{ } void Vehicle::initProperties(){ + Game *game = Game::getSingleton(); + vector currTechs = player->getTechnologies(); + sol::table unitTable = generateView()[GameObject::getGameObjTableName()][id + 1]; - maxTurnAngle = unitTable["maxTurnAngle"]; - speed = unitTable["speed"]; + maxTurnAngle = unitTable["maxTurnAngle"]; maxTurnAngle += game->calcAbilFromTech(Ability::Type::MAX_TURN_ANGLE, currTechs, (int)GameObject::type, id); + speed = unitTable["speed"]; speed += game->calcAbilFromTech(Ability::Type::SPEED, currTechs, (int)GameObject::type, id); anglePrecision = unitTable["anglePrecision"]; garrisonCategory = unitTable["garrisonCategory"]; }