diff --git a/Assets/Models/GameObjects/Units/Structures/Markets/market.blend b/Assets/Models/GameObjects/Units/Structures/TradeCenters/tradeCenter.blend similarity index 100% rename from Assets/Models/GameObjects/Units/Structures/Markets/market.blend rename to Assets/Models/GameObjects/Units/Structures/TradeCenters/tradeCenter.blend diff --git a/Assets/Models/GameObjects/Units/Structures/Markets/market.blend1 b/Assets/Models/GameObjects/Units/Structures/TradeCenters/tradeCenter.blend1 similarity index 100% rename from Assets/Models/GameObjects/Units/Structures/Markets/market.blend1 rename to Assets/Models/GameObjects/Units/Structures/TradeCenters/tradeCenter.blend1 diff --git a/Assets/Models/GameObjects/Units/Structures/Markets/market.xml b/Assets/Models/GameObjects/Units/Structures/TradeCenters/tradeCenter.xml similarity index 100% rename from Assets/Models/GameObjects/Units/Structures/Markets/market.xml rename to Assets/Models/GameObjects/Units/Structures/TradeCenters/tradeCenter.xml diff --git a/Assets/Scripts/GameObjects/Units/unitData.lua b/Assets/Scripts/GameObjects/Units/unitData.lua index 972c0e0..c413d57 100644 --- a/Assets/Scripts/GameObjects/Units/unitData.lua +++ b/Assets/Scripts/GameObjects/Units/unitData.lua @@ -17,7 +17,7 @@ UnitId = { STEALTH_SUBMARINE = 14, LAND_FACTORY = 15, NAVAL_FACTORY = 16, - MARKET = 17, + TRADE_CENTER = 17, LAB = 18, POINT_DEFENSE = 19, EXTRACTOR = 20, @@ -37,7 +37,7 @@ UnitClass = { SUBMARINE = 8, LAND_FACTORY = 9, NAVAL_FACTORY = 10, - MARKET = 11, + TRADE_CENTER = 11, LAB = 12, POINT_DEFENSE = 13, EXTRACTOR = 14, @@ -128,7 +128,7 @@ units = { buildableUnits = { {id = UnitId.LAND_FACTORY, buildable = true}, {id = UnitId.NAVAL_FACTORY, buildable = true}, - {id = UnitId.MARKET, buildable = true}, + {id = UnitId.TRADE_CENTER, buildable = true}, {id = UnitId.LAB, buildable = true}, {id = UnitId.POINT_DEFENSE, buildable = true}, {id = UnitId.FORT, buildable = false}, @@ -486,7 +486,7 @@ units = { deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg', }, { - unitClass = UnitClass.MARKET, + unitClass = UnitClass.TRADE_CENTER, unitType = UnitType.LAND, isVehicle = false, health = 500, @@ -495,9 +495,10 @@ units = { size = {x = 1, y = 1.15, z = 2}, hitboxOffset = {x = 0, y = 0, z = 0}, lineOfSight = 5, - name = 'Market', - basePath = PATH .. structurePrefix .. 'Markets/', - meshPath = 'market.xml', + name = 'Trade center', + basePath = PATH .. structurePrefix .. 'TradeCenters/', + meshPath = 'tradeCenter.xml', + guiScreen = 'tradingCenterCommands.lua', selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg', deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg', }, diff --git a/Assets/Scripts/Gui/main.lua b/Assets/Scripts/Gui/main.lua index 390113d..ee35787 100644 --- a/Assets/Scripts/Gui/main.lua +++ b/Assets/Scripts/Gui/main.lua @@ -28,7 +28,11 @@ ButtonType = { NAVAL_FACTORY_TRAIN = 24, FORT_TRAIN = 25, STATISTICS = 26, - RESEARCH = 27 + RESEARCH = 27, + BUY_REFINEDS = 28, + SELL_REFINEDS = 29, + BUY_RESEARCH = 30, + SELL_RESEARCH = 31, } ListboxType = { diff --git a/Assets/Scripts/Gui/tradingCenterCommands.lua b/Assets/Scripts/Gui/tradingCenterCommands.lua new file mode 100644 index 0000000..1c0dcb9 --- /dev/null +++ b/Assets/Scripts/Gui/tradingCenterCommands.lua @@ -0,0 +1,41 @@ +res = graphics.resolution +Size = {x = 100, y = 100} + +gui = { + { + pos = {x = res.x - 200, y = res.y - 200}, + size = Size, + name = 'Buy ref', + imagePath = '', + guiType = GuiType.BUTTON, + buttonType = ButtonType.BUY_REFINEDS, + trigger = 73, + }, + { + pos = {x = res.x - Size.x - 200, y = res.y - 200}, + size = Size, + imagePath = '', + name = 'Sell ref', + guiType = GuiType.BUTTON, + buttonType = ButtonType.SELL_REFINEDS, + trigger = 79, + }, + { + pos = {x = res.x - 200, y = res.y - 400}, + size = Size, + imagePath = '', + name = 'Buy rsch', + guiType = GuiType.BUTTON, + buttonType = ButtonType.BUY_RESEARCH, + trigger = 75, + }, + { + pos = {x = res.x - Size.x - 200, y = res.y - 400}, + size = Size, + imagePath = '', + name = 'Sell rsch', + guiType = GuiType.BUTTON, + buttonType = ButtonType.SELL_RESEARCH, + trigger = 76, + } +} diff --git a/Assets/Scripts/Trading/traderData.lua b/Assets/Scripts/Trading/traderData.lua new file mode 100644 index 0000000..6ac3ddf --- /dev/null +++ b/Assets/Scripts/Trading/traderData.lua @@ -0,0 +1,6 @@ +trading = { + refinedsRate = 10, + researchRate = 20, + fluctuationRate = 1000, + fluctuationAmmount = 2 +} diff --git a/CMakeLists.txt b/CMakeLists.txt index bb506e5..0836f53 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 trainButton.cpp researchButton.cpp) +set(UNIT_BUTTONS unitButton.cpp tradeButton.cpp buildButton.cpp trainButton.cpp researchButton.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) @@ -26,7 +26,7 @@ set(FX fx.cpp) set(VEHICLES vehicle.cpp engineer.cpp resourceRover.cpp) set(STRUCTURES structure.cpp factory.cpp pointDefense.cpp extractor.cpp researchStruct.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(CONTENT player.cpp trader.cpp pathfinder.cpp map.cpp gameObject.cpp gameObjectFrame.h resourceDeposit.cpp ${UNITS} ${PROJECTILES} ${FX}) set(GAME_SRC ${STATES} ${GUI} ${CORE} ${CONTENT} ${UTIL}) set(SFML_DIR external/SFML) diff --git a/activeGameState.cpp b/activeGameState.cpp index 3e10f66..097707c 100755 --- a/activeGameState.cpp +++ b/activeGameState.cpp @@ -84,9 +84,9 @@ namespace battleship{ void ActiveGameState::update() { ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton(); guiManager->getText("depth")->setText(L"Depth: " + to_wstring(depth)); - guiManager->getText("refineds")->setText(L"Refineds: " + to_wstring(mainPlayer->getRefineds())); - guiManager->getText("wealth")->setText(L"Wealth: " + to_wstring(mainPlayer->getWealth())); - guiManager->getText("research")->setText(L"Research: " + to_wstring(mainPlayer->getResearch())); + guiManager->getText("refineds")->setText(L"Refineds: " + to_wstring(mainPlayer->getResource(ResourceType::REFINEDS))); + guiManager->getText("wealth")->setText(L"Wealth: " + to_wstring(mainPlayer->getResource(ResourceType::WEALTH))); + guiManager->getText("research")->setText(L"Research: " + to_wstring(mainPlayer->getResource(ResourceType::RESEARCH))); if(!isSelectionBox && leftMouseClicked && getTime() - lastLeftMouseClicked > 10) isSelectionBox = true; diff --git a/addResourceCommand.cpp b/addResourceCommand.cpp index faada13..3a36278 100644 --- a/addResourceCommand.cpp +++ b/addResourceCommand.cpp @@ -1,6 +1,7 @@ #include "addResourceCommand.h" #include "game.h" #include "player.h" +#include "trader.h" namespace battleship{ void AddResourceCommand::validate(){ @@ -22,18 +23,7 @@ namespace battleship{ void AddResourceCommand::addResource(){ Player *player = Game::getSingleton()->getPlayer(playerId); - - switch(resourceId){ - case 0: - player->addRefineds(resourceAmmount); - break; - case 1: - player->addWealth(resourceAmmount); - break; - case 2: - player->addResearch(resourceAmmount); - break; - } + player->updateResource(ResourceType(resourceId), resourceAmmount, true); } void AddResourceCommand::execute(){ diff --git a/concreteGuiManager.cpp b/concreteGuiManager.cpp index 7c04e61..51f0f35 100644 --- a/concreteGuiManager.cpp +++ b/concreteGuiManager.cpp @@ -25,6 +25,7 @@ #include "trainButton.h" #include "statsButton.h" #include "researchButton.h" +#include "tradeButton.h" namespace battleship{ using namespace std; @@ -200,6 +201,18 @@ namespace battleship{ case RESEARCH: button = new ResearchButton(pos, size, name, (int)guiTable["trigger"], (string)guiTable["imagePath"], (int)SOL_LUA_STATE["UnitId"]["LAB"], (int)guiTable["techId"]); break; + case BUY_REFINEDS: + button = new TradeButton(pos, size, name, (int)guiTable["trigger"], (string)guiTable["imagePath"], (int)SOL_LUA_STATE["UnitId"]["TRADE_CENTER"], TradeButton::Type::BUY_REFINEDS); + break; + case SELL_REFINEDS: + button = new TradeButton(pos, size, name, (int)guiTable["trigger"], (string)guiTable["imagePath"], (int)SOL_LUA_STATE["UnitId"]["TRADE_CENTER"], TradeButton::Type::SELL_REFINEDS); + break; + case BUY_RESEARCH: + button = new TradeButton(pos, size, name, (int)guiTable["trigger"], (string)guiTable["imagePath"], (int)SOL_LUA_STATE["UnitId"]["TRADE_CENTER"], TradeButton::Type::BUY_RESEARCH); + break; + case SELL_RESEARCH: + button = new TradeButton(pos, size, name, (int)guiTable["trigger"], (string)guiTable["imagePath"], (int)SOL_LUA_STATE["UnitId"]["TRADE_CENTER"], TradeButton::Type::SELL_RESEARCH); + break; } int typeArr[2]{(int)GuiElementType::BUTTON, (int)type}; diff --git a/concreteGuiManager.h b/concreteGuiManager.h index d9bfb29..3a9a57c 100644 --- a/concreteGuiManager.h +++ b/concreteGuiManager.h @@ -42,7 +42,11 @@ namespace battleship{ NAVAL_FACTORY_TRAIN, FORT_TRAIN, STATISTICS, - RESEARCH + RESEARCH, + BUY_REFINEDS, + SELL_REFINEDS, + BUY_RESEARCH, + SELL_RESEARCH }; enum ListboxType { CONTROLS, diff --git a/defConfigs.h b/defConfigs.h index 0bcf9ff..abee4fb 100755 --- a/defConfigs.h +++ b/defConfigs.h @@ -53,6 +53,7 @@ namespace battleship{ "Scripts/Core/player.lua", "Scripts/Technologies/technologyData.lua", "Scripts/Abilities/abilityData.lua", + "Scripts/Trading/traderData.lua" }; const static Bind staticBinds[numAppStates][maxStaticBinds]{ diff --git a/engineer.cpp b/engineer.cpp index 36a11d6..ec1d69f 100644 --- a/engineer.cpp +++ b/engineer.cpp @@ -59,9 +59,9 @@ namespace battleship{ sol::table targTable = generateView()["units"][order.targets[0].unit->getId()]; int costRate = (int)targTable["cost"] / 100, buildRate = (int)targTable["buildTime"] / 100; - if(structure->getBuildStatus() < 100 && player->getRefineds() >= costRate && getTime() - lastIncrementTime > buildRate){ + if(structure->getBuildStatus() < 100 && player->getResource(ResourceType::REFINEDS) >= costRate && getTime() - lastIncrementTime > buildRate){ structure->incrementBuildStatus(); - player->setRefineds(player->getRefineds() - costRate); + player->updateResource(ResourceType::REFINEDS, -costRate, true); lastIncrementTime = getTime(); } else if(structure->getBuildStatus() >= 100){ diff --git a/factory.cpp b/factory.cpp index 0c02245..0ecd1ed 100644 --- a/factory.cpp +++ b/factory.cpp @@ -64,9 +64,9 @@ namespace battleship{ sol::table targTable = generateView()["units"][unitQueue[0] + 1]; int costRate = (int)targTable["cost"] / 100, trainRate = (int)targTable["buildTime"] / 100; - if(player->getRefineds() >= costRate && getTime() - lastTrainTime > trainRate){ + if(player->getResource(ResourceType::REFINEDS) >= costRate && getTime() - lastTrainTime > trainRate){ trainingStatus++; - player->setRefineds(player->getRefineds() - costRate); + player->updateResource(ResourceType::REFINEDS, -costRate, true); lastTrainTime = getTime(); } diff --git a/gameObjectFactory.cpp b/gameObjectFactory.cpp index dd39abc..1e91069 100644 --- a/gameObjectFactory.cpp +++ b/gameObjectFactory.cpp @@ -35,7 +35,7 @@ namespace battleship{ return new Extractor(player, id, pos, rot, buildStatus); case UnitClass::LAB: return new ResearchStruct(player, id, pos, rot, buildStatus); - case UnitClass::MARKET: + case UnitClass::TRADE_CENTER: case UnitClass::REFINERY: return new Structure(player, id, pos, rot, buildStatus, Unit::State::STAND_GROUND); case UnitClass::ENGINEER: diff --git a/player.cpp b/player.cpp index cec2871..cdc1ebc 100755 --- a/player.cpp +++ b/player.cpp @@ -12,11 +12,13 @@ namespace battleship{ using namespace gameBase; using namespace std; - Player::Player(int diff, int fac, int t, Vector3 col, bool cpuPl, Vector3 sp, string n) : difficulty(diff), faction(fac), team(t), color(col), cpuPlayer(cpuPl), spawnPoint(sp), name(n), refineds(30000) {} + Player::Player(int diff, int fac, int t, Vector3 col, bool cpuPl, Vector3 sp, string n) : difficulty(diff), faction(fac), team(t), color(col), cpuPlayer(cpuPl), spawnPoint(sp), name(n), refineds(30000), trader(new Trader()) {} Player::~Player() {} void Player::update() { + trader->update(); + vector units = this->units; for(Unit *u : units){ if(!u->isRemove()) @@ -187,4 +189,29 @@ namespace battleship{ void Player::addTechnology(int techId){ technologies.push_back(techId); } + + int Player::getResource(ResourceType type){ + switch(type){ + case ResourceType::REFINEDS: + return refineds; + case ResourceType::WEALTH: + return wealth; + case ResourceType::RESEARCH: + return research; + } + } + + void Player::updateResource(ResourceType type, int ammount, bool add){ + switch(type){ + case ResourceType::REFINEDS: + refineds = (add ? refineds + ammount : ammount); + break; + case ResourceType::WEALTH: + wealth = (add ? wealth + ammount : ammount); + break; + case ResourceType::RESEARCH: + research = (add ? research + ammount : ammount); + break; + } + } } diff --git a/player.h b/player.h index e14e2c7..04e3010 100755 --- a/player.h +++ b/player.h @@ -4,6 +4,7 @@ #include #include "gameManager.h" +#include "trader.h" #include "unit.h" namespace battleship{ @@ -11,6 +12,8 @@ namespace battleship{ class Projectile; class Unit; + enum class ResourceType{REFINEDS, WEALTH, RESEARCH}; + class Player { public: Player(int, int, int, vb01::Vector3, bool = true, vb01::Vector3 = vb01::Vector3::VEC_ZERO, std::string = ""); @@ -27,6 +30,9 @@ namespace battleship{ std::vector getUnitsById(int, int = -1); std::vector getUnitsByClass(UnitClass, int = -1); void addTechnology(int); + int getResource(ResourceType); + void updateResource(ResourceType, int, bool); + inline Trader* getTrader(){return trader;} inline void deselectUnits(){selectedUnits.clear();} inline Unit* getSelectedUnit(int id){return selectedUnits[id];} inline std::vector getSelectedUnits(){return selectedUnits;} @@ -47,18 +53,6 @@ namespace battleship{ inline int getNumUnits(){return units.size();} inline int getFaction(){return faction;} inline vb01::Vector3 getSpawnPoint(){return spawnPoint;} - inline int getRefineds(){return refineds;} - inline void setRefineds(int ref){this->refineds = ref;} - inline void addRefineds(int ref){this->refineds += ref;} - inline void subtractRefineds(int ref){this->refineds -= ref;} - inline int getWealth(){return wealth;} - inline void setWealth(int w){this->wealth = w;} - inline void addWealth(int w){this->wealth += w;} - inline void subtractWealth(int w){this->wealth -= w;} - inline int getResearch(){return research;} - inline void setResearch(int r){this->research = r;} - inline void addResearch(int r){this->research += r;} - inline void subtractResearch(int r){this->research -= r;} inline bool isCpuPlayer(){return cpuPlayer;} inline int getNumVehiclesBuilt(){return vehiclesBuilt;} inline int getNumVehiclesDestroyed(){return vehiclesDestroyed;} @@ -83,6 +77,7 @@ namespace battleship{ int faction, difficulty, team; int vehiclesBuilt = 0, vehiclesDestroyed = 0, vehiclesLost = 0; int structuresBuilt = 0, structuresDestroyed = 0, structuresLost = 0; + Trader *trader = nullptr; std::string name; std::vector units, selectedUnits; std::vector projectiles; diff --git a/researchStruct.cpp b/researchStruct.cpp index 0e498a4..aa57156 100644 --- a/researchStruct.cpp +++ b/researchStruct.cpp @@ -38,9 +38,9 @@ namespace battleship{ bool mainPlayerSelecting = (activeState && find(selectingPlayers.begin(), selectingPlayers.end(), mainPlayer) != selectingPlayers.end()); if(researchQueue.empty()){ - if(health > .3 * maxHealth && player->getRefineds() >= researchCost && canUpdateResearch()){ - player->addResearch(generationSpeed); - player->subtractRefineds(researchCost); + if(health > .3 * maxHealth && player->getResource(ResourceType::REFINEDS) >= researchCost && canUpdateResearch()){ + player->updateResource(ResourceType::RESEARCH, generationSpeed, true); + player->updateResource(ResourceType::REFINEDS, researchCost, true); lastUpdateTime = getTime(); } @@ -51,7 +51,7 @@ namespace battleship{ Unit::displayUnitStats(researchStatusForeground, researchStatusBackground, researchStatus, 100, mainPlayer == player && mainPlayerSelecting, Vector2(0, -10)); int techCost = Game::getSingleton()->getTechnology(researchQueue[0]).cost; - int playerResearch = player->getResearch(); + int playerResearch = player->getResource(ResourceType::RESEARCH); if(techCost > playerResearch && canUpdateResearch()){ researchStatus += int(100 * ((float)playerResearch / techCost)); diff --git a/resourceRover.cpp b/resourceRover.cpp index a7d51b0..469bfe9 100644 --- a/resourceRover.cpp +++ b/resourceRover.cpp @@ -78,7 +78,7 @@ namespace battleship{ if(nearestRefinery && nearestRefinery->getPos().getDistanceFrom(pos) <= minDist){ if(canUnload()){ load -= loadSpeed; - player->addRefineds(1); + player->updateResource(ResourceType::REFINEDS, 1, true); lastLoadTime = getTime(); } else if(load == 0 && nearestExtractor) diff --git a/tradeButton.cpp b/tradeButton.cpp new file mode 100644 index 0000000..9a25a9b --- /dev/null +++ b/tradeButton.cpp @@ -0,0 +1,42 @@ +#include "tradeButton.h" +#include "activeGameState.h" +#include "player.h" + +#include + +namespace battleship{ + using namespace std; + using namespace vb01; + using namespace gameBase; + + TradeButton::TradeButton(Vector2 pos, Vector2 size, string name, int trigger, string imagePath, int uid, Type t) : UnitButton(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", trigger, imagePath, uid), type(t){} + + void TradeButton::onClick(){ + ActiveGameState *activeState = (ActiveGameState*)(GameManager::getSingleton()->getStateManager()->getAppStateByType((int)AppStateType::ACTIVE_STATE)); + Player *player = activeState->getPlayer(); + + int resType, ammount = 10; + bool buy; + + switch(type){ + case Type::BUY_REFINEDS: + resType = (int)ResourceType::REFINEDS; + buy = true; + break; + case Type::SELL_REFINEDS: + resType = (int)ResourceType::REFINEDS; + buy = false; + break; + case Type::BUY_RESEARCH: + resType = (int)ResourceType::RESEARCH; + buy = true; + break; + case Type::SELL_RESEARCH: + resType = (int)ResourceType::RESEARCH; + buy = false; + break; + } + + player->getTrader()->trade(player, resType, ammount, buy); + } +} diff --git a/tradeButton.h b/tradeButton.h new file mode 100644 index 0000000..f59e59b --- /dev/null +++ b/tradeButton.h @@ -0,0 +1,18 @@ +#ifndef TRADE_BUTTON_H +#define TRADE_BUTTON_H + +#include "unitButton.h" + +namespace battleship{ + class TradeButton : public UnitButton{ + public: + enum class Type{BUY_REFINEDS, SELL_REFINEDS, BUY_RESEARCH, SELL_RESEARCH}; + + TradeButton(vb01::Vector2, vb01::Vector2, std::string, int, std::string, int, Type); + void onClick(); + private: + Type type; + }; +} + +#endif diff --git a/tradeCenter.cpp b/tradeCenter.cpp new file mode 100644 index 0000000..e69de29 diff --git a/tradeCenter.h b/tradeCenter.h new file mode 100644 index 0000000..780aeac --- /dev/null +++ b/tradeCenter.h @@ -0,0 +1,14 @@ +#ifndef TRADE_CENTER_H +#define TRADE_CENTER_H + +#include "structure.h" + +namespace battleship{ + class TradeCenter : public Structure{ + public: + TradeCenter(Player*, int, vb01::Vector3, vb01::Quaternion, int); + private: + }; +} + +#endif diff --git a/trader.cpp b/trader.cpp new file mode 100644 index 0000000..5e5af2e --- /dev/null +++ b/trader.cpp @@ -0,0 +1,69 @@ +#include "trader.h" +#include "player.h" + +#include + +#include + +namespace battleship{ + using namespace std; + using namespace vb01; + using namespace gameBase; + + Trader::Trader(){ + initProperties(); + } + + void Trader::initProperties(){ + sol::table traderTable = generateView()["trading"]; + fluctuationRate = traderTable["fluctuationRate"]; + fluctuationAmmount = traderTable["fluctuationAmmount"]; + refinedsRate = traderTable["refinedsRate"]; + researchRate = traderTable["researchRate"]; + } + + void Trader::update(){ + if(getTime() - lastUpdateTime > fluctuationRate){ + int flucFact = rand() % 3; + int flSpd; + + switch(flucFact){ + case 0: + flSpd = -fluctuationAmmount; + break; + case 1: + flSpd = 0; + break; + case 2: + flSpd = fluctuationAmmount; + break; + } + + refinedsRate += fluctuationAmmount; + researchRate += fluctuationAmmount; + lastUpdateTime = getTime(); + } + } + + void Trader::trade(Player *tradingPlayer, int rt, int ammount, bool buying){ + int tradeResRate; + + switch((ResourceType)rt){ + case ResourceType::REFINEDS: + tradeResRate = refinedsRate; + break; + case ResourceType::RESEARCH: + tradeResRate = researchRate; + break; + } + + if(buying && ammount * tradeResRate <= tradingPlayer->getResource(ResourceType::WEALTH)){ + tradingPlayer->updateResource((ResourceType)rt, ammount, true); + tradingPlayer->updateResource(ResourceType::WEALTH, -ammount * tradeResRate, true); + } + else if(!buying && tradingPlayer->getResource((ResourceType)rt) >= ammount){ + tradingPlayer->updateResource((ResourceType)rt, -ammount, true); + tradingPlayer->updateResource(ResourceType::WEALTH, ammount * tradeResRate, true); + } + } +} diff --git a/trader.h b/trader.h new file mode 100644 index 0000000..1121cf4 --- /dev/null +++ b/trader.h @@ -0,0 +1,22 @@ +#ifndef TRADER_H +#define TRADER_H + +#include + +namespace battleship{ + class Player; + + class Trader{ + public: + Trader(); + void update(); + void trade(Player*, int, int, bool); + private: + void initProperties(); + + vb01::s64 lastUpdateTime = 0; + int fluctuationRate, refinedsRate, researchRate, fluctuationAmmount; + }; +} + +#endif diff --git a/unit.h b/unit.h index 0d8d31e..53d78ab 100755 --- a/unit.h +++ b/unit.h @@ -69,7 +69,7 @@ namespace battleship{ SUBMARINE, LAND_FACTORY, NAVAL_FACTORY, - MARKET, + TRADE_CENTER, LAB, POINT_DEFENSE, EXTRACTOR,