diff --git a/Assets/Scripts/Core/options.lua b/Assets/Scripts/Core/options.lua index 9218efb..e402e8d 100644 --- a/Assets/Scripts/Core/options.lua +++ b/Assets/Scripts/Core/options.lua @@ -16,8 +16,8 @@ mappings = { {bind = 12, trigger = 0, action = true, bindType = 1, inOptions = true}, {bind = 13, trigger = 1, action = true, bindType = 1, inOptions = true}, {bind = 14, trigger = 72, action = true, bindType = 0, inOptions = true}, - {bind = 15, trigger = 0, action = true, bindType = 0, inOptions = true}, - {bind = 16, trigger = 0, action = true, bindType = 0, inOptions = true}, + {bind = 15, trigger = 61, action = true, bindType = 0, inOptions = true}, + {bind = 16, trigger = 45, action = true, bindType = 0, inOptions = true}, {bind = 17, trigger = 341, action = true, bindType = 0, inOptions = true}, {bind = 18, trigger = 340, action = true, bindType = 0, inOptions = true}, {bind = 19, trigger = 80, action = true, bindType = 0, inOptions = true}, diff --git a/Assets/Scripts/GameObjects/Units/unitData.lua b/Assets/Scripts/GameObjects/Units/unitData.lua index bd141c2..b9c0b02 100644 --- a/Assets/Scripts/GameObjects/Units/unitData.lua +++ b/Assets/Scripts/GameObjects/Units/unitData.lua @@ -129,8 +129,7 @@ units = { { orderType = OrderType.ATTACK, rateOfFire = 100, - maxAmmo = 100, -- Just a test - ammo = 50, -- Just a test + ammoConsumption = 1, --Just a test maxRange = 40, damage = 50, maxFireAngle = .1, @@ -184,6 +183,8 @@ units = { health = 500, buildTime = 600, cost = 500, + maxAmmo = 100, -- Just a test + ammo = 50, -- Just a test size = {x = 6, y = 9.22, z = 2.42}, hitboxOffset = {x = 0, y = 4.5, z = 0}, lineOfSight = 25, @@ -207,6 +208,7 @@ units = { rateOfFire = 100, maxRange = 40, damage = 50, + ammoConsumption = 1, maxFireAngle = .1, nodes = {{name = 'turret', rotationSpeed = 1, angleConstraints = {min = -1.5, max = 1.5}, vertical = true}}, fireFx = { @@ -259,6 +261,8 @@ units = { health = 500, buildTime = 1000, cost = 500, + maxAmmo = 100, -- Just a test + ammo = 80, -- Just a test size = {x = 5.37, y = 6, z = 8.57}, hitboxOffset = {x = 0, y = 3.02, z = .16}, lineOfSight = 25, @@ -282,6 +286,7 @@ units = { rateOfFire = 250, maxRange = 40, damage = 50, + ammoConsumption = 1, maxFireAngle = .1, nodes = {{name = 'turret', rotationSpeed = 1, angleConstraints = {min = -1.5, max = 1.5}, vertical = true}}, fireFx = { @@ -334,6 +339,8 @@ units = { health = 500, buildTime = 1000, cost = 500, + maxAmmo = 100, -- Just a test + ammo = 80, -- Just a test size = {x = 3.25, y = 3.86, z = 3.86}, hitboxOffset = {x = 0, y = 4.27, z = .13}, lineOfSight = 25, @@ -356,6 +363,7 @@ units = { orderType = OrderType.ATTACK, rateOfFire = 1000, damage = 900, + ammoConsumption = 1, maxRange = 50, maxFireAngle = .1, nodes = {{name = 'TankASHead', rotationSpeed = .05, vertical = false}, {name = 'barell', rotationSpeed = .05, angleConstraints = {min = 0, max = .349}, vertical = true}}, @@ -392,6 +400,8 @@ units = { health = 500, buildTime = 1000, cost = 500, + maxAmmo = 100, -- Just a test + ammo = 80, -- Just a test size = {x = 11.505, y = 10.3979, z = 17.1902}, hitboxOffset = {x = 0, y = 5.46, z = .86}, lineOfSight = 75, @@ -414,6 +424,7 @@ units = { orderType = OrderType.ATTACK, rateOfFire = 1000, damage = 200, + ammoConsumption = 1, maxRange = 50, maxFireAngle = .1, nodes = {{name = 'TankGun_AM', rotationSpeed = .05, vertical = false}, {name = 'barell', rotationSpeed = .05, angleConstraints = {min = -.2, max = .74}, vertical = true}}, @@ -450,6 +461,8 @@ units = { health = 500, buildTime = 1000, cost = 500, + maxAmmo = 100, -- Just a test + ammo = 80, -- Just a test size = {x = 13.6, y = 6.79, z = 21.8}, hitboxOffset = {x = 0, y = 3.31, z = 0}, lineOfSight = 75, @@ -472,6 +485,7 @@ units = { orderType = OrderType.ATTACK, rateOfFire = 1000, damage = 200, + ammoConsumption = 1, maxRange = 50, maxFireAngle = .1, nodes = { @@ -511,6 +525,8 @@ units = { health = 500, buildTime = 1000, cost = 500, + maxAmmo = 100, -- Just a test + ammo = 80, -- Just a test size = {x = 7.2, y = 10.3, z = 15}, hitboxOffset = {x = 0, y = 5.27, z = .26}, lineOfSight = 75, @@ -592,6 +608,7 @@ units = { orderType = OrderType.ATTACK, rateOfFire = 2000, damage = 5000, + ammoConsumption = 2, maxRange = 70, maxFireAngle = .1, nodes = { @@ -628,6 +645,8 @@ units = { health = 500, buildTime = 1000, cost = 500, + maxAmmo = 100, -- Just a test + ammo = 80, -- Just a test size = {x = 10.4, y = 14, z = 12.9}, hitboxOffset = {x = 0, y = 7, z = 1.3}, lineOfSight = 90, @@ -649,7 +668,8 @@ units = { { orderType = OrderType.ATTACK, rateOfFire = 2000, - damage = 5000, + damage = 5000, + ammoConsumption = 2, maxRange = 70, maxFireAngle = .1, nodes = { @@ -687,6 +707,8 @@ units = { health = 500, buildTime = 1000, cost = 500, + maxAmmo = 100, -- Just a test + ammo = 80, -- Just a test size = {x = 6.8, y = 6.8, z = 15.2}, hitboxOffset = {x = 0, y = 1, z = 0}, lineOfSight = 30, @@ -1413,6 +1435,7 @@ units = { orderType = OrderType.ATTACK, rateOfFire = 1500, damage = 70, + ammoConsumption = 1, --Test maxRange = 50, nodes = {{name = 'frontTurret', rotationSpeed = .05, angleConstraints = {min = -2.44, max = 2.44}, vertical = false}}, fireFx = { @@ -1433,6 +1456,7 @@ units = { orderType = OrderType.ATTACK, rateOfFire = 1500, damage = 70, + ammoConsumption = 1, --Test maxRange = 50, nodes = {{name = 'rearTurret', rotationSpeed = .05, angleConstraints = {min = -2.44, max = 2.44}, vertical = false}}, fireFx = { @@ -1453,6 +1477,7 @@ units = { orderType = OrderType.ATTACK, rateOfFire = 200, damage = 10, + ammoConsumption = 1, --Test maxRange = 50, nodes = {{name = 'frontAATurret', rotationSpeed = .05, vertical = false}, {name = 'frontAATurretBarrel', rotationSpeed = .05, vertical = true}}, fireFx = { @@ -1476,6 +1501,7 @@ units = { orderType = OrderType.ATTACK, rateOfFire = 200, damage = 10, + ammoConsumption = 1, --Test maxRange = 50, nodes = {{name = 'rearAATurret', rotationSpeed = .05, vertical = false}, {name = 'rearAATurretBarrel', rotationSpeed = .05, vertical = true}}, fireFx = { @@ -1503,6 +1529,8 @@ units = { health = 500, buildTime = 1000, cost = 500, + maxAmmo = 100, -- Just a test + ammo = 100, -- Just a test size = {x = 21.2, y = 26.3, z = 85.8}, hitboxOffset = {x = 0, y = 6.92, z = .66}, lineOfSight = 5, @@ -1571,6 +1599,7 @@ units = { orderType = OrderType.ATTACK, rateOfFire = 200, damage = 10, + ammoConsumption = 1, -- Test maxRange = 50, nodes = { {name = 'aaTurret', rotationSpeed = .05, vertical = false}, @@ -1613,6 +1642,8 @@ units = { health = 500, buildTime = 1000, cost = 500, + maxAmmo = 100, -- Just a test + ammo = 80, -- Just a test size = {x = 21.1, y = 22.6, z = 67.3}, hitboxOffset = {x = 0, y = 6.42, z = 3.2}, lineOfSight = 5, @@ -2240,6 +2271,7 @@ units = { orderType = OrderType.ATTACK, projectile = {id = ProjectileId.TORPEDO, pos = {x = 0, y = -.27, z = 4.6}, rot = {w = 1, x = 0, y = 0, z = 0}}, damage = 200, + ammoConsumption = 1, --Test maxRange = 200, rateOfFire = 500, fireFx = { @@ -2257,6 +2289,8 @@ units = { health = 500, buildTime = 1000, cost = 500, + maxAmmo = 50, -- Just a test + ammo = 50, -- Just a test hitboxOffset = {x = 0, y = 1.03, z = -1.41}, size = {x = 5.37, y = 7.66, z = 43}, lineOfSight = 0, @@ -2350,6 +2384,7 @@ units = { rateOfFire = 100, maxRange = 500, damage = 0, + ammoConsumption = 1, --Test nodes = { {name = 'turret', rotationSpeed = .05, vertical = false}, {name = 'barrel', rotationSpeed = .05, angleConstraints = {min = -.523, max = .523}, vertical = true}, @@ -2373,6 +2408,8 @@ units = { health = 500, buildTime = 1000, cost = 500, + maxAmmo = 100, -- Just a test + ammo = 50, -- Just a test size = {x = 20.3, y = 12.5, z = 56.2}, hitboxOffset = {x = 0, y = 4.7, z = 0}, lineOfSight = 25, @@ -2394,7 +2431,8 @@ units = { { orderType = OrderType.ATTACK, rateOfFire = 1000, - damage = 0, + damage = 0, + ammoConsumption = 1, --Test maxRange = 25, maxFireAngle = .1, nodes = {{name = 'turret', rotationSpeed = .05, vertical = false}}, @@ -2414,6 +2452,8 @@ units = { health = 500, buildTime = 1000, cost = 500, + maxAmmo = 100, -- Just a test + ammo = 100, -- Just a test size = {x = 7.3, y = 7.15, z = 37.9}, hitboxOffset = {x = 0, y = 1.13, z = 1.83}, lineOfSight = 25, @@ -2747,6 +2787,7 @@ units = { orderType = OrderType.ATTACK, rateOfFire = 100, damage = 7, + ammoConsumption = 2, --Test maxRange = 100, maxFireAngle = .4, nodes = { @@ -2794,6 +2835,8 @@ units = { health = 500, buildTime = 1000, cost = 500, + maxAmmo = 100, -- Just a test + ammo = 80, -- Just a test size = {x = 5, y = 8, z = 5}, hitboxOffset = {x = 0, y = 4, z = 0}, lineOfSight = 55, diff --git a/defConfigs.h b/defConfigs.h index e11c178..5c0c0f4 100755 --- a/defConfigs.h +++ b/defConfigs.h @@ -151,8 +151,8 @@ namespace battleship{ GLFW_KEY_LEFT, GLFW_KEY_RIGHT, GLFW_KEY_H, - 3, - 4, + GLFW_KEY_EQUAL, // Changed zoom in to the plus/equal key + GLFW_KEY_MINUS, // Changed zoom out to the minus key GLFW_KEY_LEFT_CONTROL, GLFW_KEY_LEFT_SHIFT, GLFW_KEY_P, diff --git a/player.h b/player.h index 13afc78..b0901f6 100755 --- a/player.h +++ b/player.h @@ -95,7 +95,7 @@ namespace battleship{ bool cpuPlayer = false; std::vector technologies; int luaPlayerId; - int resources[3]{0, 0, 0}; + int resources[3]{0, 0, 0}; // This is the same as 'cargo' in resourceRover.h: capacity, loadRate, loadSpeed int faction, difficulty, team; int vehiclesBuilt = 0, vehiclesDestroyed = 0, vehiclesLost = 0; int structuresBuilt = 0, structuresDestroyed = 0, structuresLost = 0; diff --git a/resourceRover.cpp b/resourceRover.cpp index 1057c41..546b741 100644 --- a/resourceRover.cpp +++ b/resourceRover.cpp @@ -39,6 +39,10 @@ namespace battleship{ } //TODO implement a check of whether a vehicle is next to a building's outline + + /// @brief + /// @param targStruct + /// @param loadResource passed as a logical expression of whether the order is to Load void ResourceRover::loadResources(Structure *targStruct, bool loadResource){ float w = targStruct->getWidth(), l = targStruct->getLength(); bool closeEnough = (pos.getDistanceFrom(targStruct->getPos()) <= sqrt(l * l + w * w)); @@ -58,18 +62,25 @@ namespace battleship{ break; } + // If the structure the rover is targeting belongs to the player then try to load or unload resources if(player == targStruct->getPlayer()){ + // Checks if the order given was not to load and if enough time has passed since the last load and if the cargo for the resource type exists if(!loadResource && canUnload((int)resType)){ + // Add the load speed amount of the resource type to the player's current resource count player->updateResource(resType, loadSpeed, true); cargo[(int)resType] -= loadSpeed; lastLoadTime = getTime(); } + /* Checks if the order given was to load and the player is getting a valid resource type and that enough time has passed since the last load + while the loading capacity hasn't been reached */ else if(loadResource && canLoad() && player->getResource(resType) > 0){ + // Reduce the load speed amount to the player's current resource count player->updateResource(resType, -loadSpeed, true); cargo[(int)resType] += loadSpeed; lastLoadTime = getTime(); } } + // If the rover is not targeting a player structure then try to trade resources else{ vector offers = player->getTradeOffers(targStruct->getPlayer()); if(offers.empty()) return; @@ -98,6 +109,9 @@ namespace battleship{ } //TODO equate rover load and extractor draw rates + + /// @brief Get resources from extractors and refineries for the resource rover to give to other units + /// @param order void ResourceRover::collectRefineds(Order order){ vector units = player->getUnits(); vector extractors, refineries; diff --git a/resourceRover.h b/resourceRover.h index 183d0a1..eb59a5e 100644 --- a/resourceRover.h +++ b/resourceRover.h @@ -17,13 +17,15 @@ namespace battleship{ inline int getLoad(int id){return cargo[id];} inline int calcTotalLoad(){return cargo[0] + cargo[1] + cargo[2];} inline int getCapacity(){return capacity;} + // Checks if enough time has passed since the last load to keep with the rover's loading rate and that it hasn't loaded long enough to reach capacity inline bool canLoad(){return vb01::getTime() - lastLoadTime > loadRate && calcTotalLoad() < capacity;} + // Checks if enough time has passed since the last load to keep with the rover's loading rate inline bool canUnload(int id){return vb01::getTime() - lastLoadTime > loadRate && cargo[id] > 0;} private: void initProperties(); void collectRefineds(Order); void loadResources(Structure*, bool); - void handleResources(Order); + void handleResources(Order); // Overrides the handleResources function from unit class Unit* getClosestUnit(std::vector); vb01::s64 lastLoadTime = 0; diff --git a/unit.cpp b/unit.cpp index 7ac7172..4057e75 100755 --- a/unit.cpp +++ b/unit.cpp @@ -42,7 +42,7 @@ namespace battleship{ selectable = true; destructable = new Destructable(this); - + // Initiate the properties from the Lua table Unit::initProperties(); initModel(); initHitbox(); @@ -66,10 +66,12 @@ namespace battleship{ destroyModel(); } + /// @brief Sets all the unit properties from the Lua table containing the units void Unit::initProperties(){ GameObject::initProperties(); sol::state_view SOL_LUA_VIEW = generateView(); + // Returns the table name as "units" string objType = GameObject::getGameObjTableName(); sol::table unitTable = SOL_LUA_VIEW[objType][id + 1]; @@ -120,6 +122,18 @@ namespace battleship{ buildableUnits.push_back(BuildableUnit(buTable["id"], game->isUnitUnlocked(currTechs, id) | (bool)buTable["buildable"])); } } + + // Some units may not have ammo so will we do a check of maxAmmo before assigning it + sol::optional maxAmmoOpt = unitTable["maxAmmo"]; + if(maxAmmoOpt != sol::nullopt) + { + maxAmmo = unitTable["maxAmmo"].get(); + // Units that have maxAmmo should also have ammo but just in case they don't 0 will be assigned + ammo = unitTable["ammo"].get_or(0); + } + + cout << "Max Ammo " << maxAmmo << endl; + cout << "Starting Ammo " << ammo << endl; } /// @brief Initialize the weapons for this unit @@ -310,6 +324,7 @@ namespace battleship{ //TODO remove order argument from action methods void Unit::executeOrders() { + // Return if there are no orders or if the unit is not able to execute orders if(orders.empty() || condition != Condition::ABLE) return; if(!currOrderStarted) startCurrentOrder(); @@ -597,5 +612,37 @@ namespace battleship{ selectionSfx->play(); orderLineDispTime = getTime(); + + cout << "Current Ammo For Selected" << ammo << endl; } + + /// @brief Add the passed amount of ammo to the current ammo amount unless the resulting amount would exceed the max ammo for the weapon + /// @param ammoToAdd + void Unit::addAmmo(int ammoToAdd) + { + int newAmmoAmount = ammoToAdd + ammo; + if(newAmmoAmount > maxAmmo) + { + ammo = maxAmmo; + } + else + { + ammo = newAmmoAmount; + } + } + + /// @brief Reduce the amount of ammo for the unit by the passed amount + /// @param amoToLose + void Unit::reduceAmmo(int ammoToLose) + { + int newAmmoAmount = ammo - ammoToLose; + if(newAmmoAmount < 0) + { + ammo = 0; + } + else + { + ammo = newAmmoAmount; + } + } } diff --git a/unit.h b/unit.h index 216e552..1df2fc2 100755 --- a/unit.h +++ b/unit.h @@ -137,6 +137,10 @@ namespace battleship{ if(cond == Condition::EM_JAMMED) lastJamTime = vb01::getTime(); } + inline int getMaxAmmo(){return maxAmmo;} + inline int getAmmo(){return ammo;} + void addAmmo(int ammoToAdd); + void reduceAmmo(int ammoToLose); private: void renderOrderLine(bool); void initWeapons(); @@ -150,6 +154,7 @@ namespace battleship{ vb01::Node *losLightNode = nullptr; bool vehicle, currOrderStarted = false, alignToSurface = false; Condition condition = Condition::ABLE; + int maxAmmo, ammo; protected: UnitType type; UnitClass unitClass; diff --git a/weapon.cpp b/weapon.cpp index 227bf6e..b068925 100644 --- a/weapon.cpp +++ b/weapon.cpp @@ -59,14 +59,21 @@ namespace battleship{ if(fireFx) fxManager->addFx(fireFx); } - // Some weapons may not have ammo so will we do a check of maxAmmo before assigning it - sol::optional maxAmmoOpt = weaponTable["maxAmmo"]; - if(maxAmmoOpt != sol::nullopt) + // If a weapon doesn't fire it will not have an ammo consumptiopn + sol::optional ammoConsumpOpt = weaponTable["ammoConsumption"]; + if(ammoConsumpOpt != sol::nullopt) { - maxAmmo = weaponTable["maxAmmo"].get(); - // Units that have maxAmmo should also have ammo but just in case they don't 0 will be assigned - ammo = weaponTable["ammo"].get_or(0); + ammoConsumption = weaponTable["ammoConsumption"].get(); } + + // // Some weapons may not have ammo so will we do a check of maxAmmo before assigning it + // sol::optional maxAmmoOpt = weaponTable["maxAmmo"]; + // if(maxAmmoOpt != sol::nullopt) + // { + // maxAmmo = weaponTable["maxAmmo"].get(); + // // Units that have maxAmmo should also have ammo but just in case they don't 0 will be assigned + // ammo = weaponTable["ammo"].get_or(0); + // } } void Weapon::initTargetData(vector &targetVec, sol::table weaponTable, string tblKey, vector allValues){ @@ -274,7 +281,7 @@ namespace battleship{ /// @brief Fires the weapon once according to the given order /// @param order void Weapon::fire(Order order){ - // Will only fire if enuogh time has passed to stay firing at the rate of fire for the weapon and if the weapon is not out of ammo + // Will only fire if enuogh time has passed to stay firing at the rate of fire for the weapon and if the unit the weapon belongs to has enough ammo if(!canFire()) return; GameObject *target = order.targets[0].unit; @@ -311,8 +318,9 @@ namespace battleship{ unit->getPlayer()->addProjectile(GameObjectFactory::createProjectile(unit, projId, p, r)); } - // Reduce the ammo by 1 - ammo -= 1; + // Reduce the ammo by the amount the weapon consumes + unit->reduceAmmo(ammoConsumption); + cout << "Current Ammo Amount " << unit->getAmmo() << endl; lastFireTime = getTime(); } @@ -388,18 +396,18 @@ namespace battleship{ return true; } - /// @brief Add the passed amount of ammo to the current ammo amount unless the resulting amount would exceed the max ammo for the weapon - /// @param ammoToAdd - void Weapon::addAmmo(int ammoToAdd) - { - int newAmmoAmount = ammoToAdd + ammo; - if(newAmmoAmount > maxAmmo) - { - ammo = maxAmmo; - } - else - { - ammo = newAmmoAmount; - } - } + // /// @brief Add the passed amount of ammo to the current ammo amount unless the resulting amount would exceed the max ammo for the weapon + // /// @param ammoToAdd + // void Weapon::addAmmo(int ammoToAdd) + // { + // int newAmmoAmount = ammoToAdd + ammo; + // if(newAmmoAmount > maxAmmo) + // { + // ammo = maxAmmo; + // } + // else + // { + // ammo = newAmmoAmount; + // } + // } } diff --git a/weapon.h b/weapon.h index 8c0e10c..1311b89 100644 --- a/weapon.h +++ b/weapon.h @@ -51,16 +51,13 @@ namespace battleship{ inline Unit* getUnit(){return unit;} inline Type getType(){return type;} inline Order::TYPE getOrderType(){return orderType;} - inline int getMaxAmmo(){return maxAmmo;} - inline int getAmmo(){return ammo;} - void addAmmo(int ammoToAdd); private: Unit *unit = nullptr; Order::TYPE orderType; int id, projId = -1, damage = 0; std::vector targetUnits, targetProjectiles; float minRange = 0, maxRange, maxFireAngle; - int maxAmmo, ammo; + int ammoConsumption = 1; // ammount of ammo firing the weapon consumes vb01::s64 lastFireTime = 0; FxManager::Fx *fireFx = nullptr; vb01::Quaternion projRot; @@ -73,7 +70,7 @@ namespace battleship{ void initProjectileData(sol::table); void initNodes(sol::table); void useFx(FxManager::Fx*, vb01::Vector3, bool); - inline bool canFire(){return (vb01::getTime() - lastFireTime > rateOfFire && ammo > 0);} + inline bool canFire(){return (vb01::getTime() - lastFireTime > rateOfFire && unit->getAmmo() >= ammoConsumption);} protected: int rateOfFire; std::vector components;