technologies in posession improve unit abilities

This commit is contained in:
devZoGok
2024-02-25 15:19:10 +02:00
parent 309f967b2d
commit bce93977bd
14 changed files with 142 additions and 29 deletions
+18 -4
View File
@@ -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}}
}
@@ -14,7 +14,7 @@ technologies = {
description = '',
parents = {},
children = {},
abilities = {},
abilities = {0},
},
{
id = TechnologyId.EFT,
+31
View File
@@ -0,0 +1,31 @@
#ifndef ABILITY_H
#define ABILITY_H
#include <vector>
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<int> gameObjIds;
};
}
#endif
+1
View File
@@ -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]{
+3 -1
View File
@@ -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<int> 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));
+10 -4
View File
@@ -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<int> 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();
+2
View File
@@ -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;
+36 -3
View File
@@ -7,6 +7,8 @@
#include "concreteGuiManager.h"
#include "defConfigs.h"
#include <algorithm>
#include <assetManager.h>
#include <particleEmitter.h>
@@ -215,11 +217,11 @@ namespace battleship{
unit->halt();
}
vector<int> Game::parseTechTable(int tid, string techKey, string numVarKey, string varKey){
vector<int> 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<int> 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<int> 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;
}
}
+3
View File
@@ -3,6 +3,7 @@
#include "fx.h"
#include "technology.h"
#include "ability.h"
#include <vector>
@@ -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, int);
inline void addFx(Fx f){fx.push_back(f);}
inline void addPlayer(Player *pl){players.push_back(pl);}
inline std::vector<Player*>& getPlayers(){return players;}
@@ -39,6 +41,7 @@ namespace battleship{
bool paused = false, ended = false;
std::vector<Fx> fx;
std::vector<Technology> technologies;
std::vector<Ability> abilities;
std::vector<Player*> players;
};
}
+10 -7
View File
@@ -1,20 +1,21 @@
#include <node.h>
#include <model.h>
#include <material.h>
#include <particleEmitter.h>
#include <quaternion.h>
#include <rayCaster.h>
#include <quaternion.h>
#include <particleEmitter.h>
#include <stateManager.h>
#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<int> 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);
}
+12 -5
View File
@@ -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<int> 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;
+1
View File
@@ -15,6 +15,7 @@ namespace battleship{
~ResourceRover();
void update();
private:
void initProperties();
void supply(Order);
Unit* getClosestUnit(std::vector<Structure*>);
inline bool canLoad(){return vb01::getTime() - lastLoadTime > loadRate && load < capacity;}
+7 -2
View File
@@ -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<int> 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"];
+7 -2
View File
@@ -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<int> 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"];
}