Skip to content
Open
6 changes: 4 additions & 2 deletions src/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "state/actor/soldier.h"
#include "state/actor/villager.h"
#include "state/command_giver.h"
#include "state/gold_manager/gold_manager.h"
#include "state/map/map.h"
#include "state/path_planner/path_planner.h"
#include "state/player_state.h"
Expand Down Expand Up @@ -90,11 +91,12 @@ unique_ptr<Map> BuildMap() {
}

unique_ptr<GoldManager> BuildGoldManager() {
std::vector<std::unique_ptr<GoldMine>> gold_mines;
return make_unique<GoldManager>(
array<int64_t, 2>{GOLD_START, GOLD_START}, GOLD_MAX,
SOLDIER_KILL_REWARD_AMOUNT, VILLAGER_KILL_REWARD_AMOUNT,
FACTORY_KILL_REWARD_AMOUNT, FACTORY_SUICIDE_PENALTY, VILLAGER_COST,
SOLDIER_COST, FACTORY_COST, MINING_REWARD);
FACTORY_KILL_REWARD_AMOUNT, VILLAGER_COST, SOLDIER_COST, FACTORY_COST,
MINING_REWARD, std::move(gold_mines));
}

unique_ptr<PathPlanner> BuildPathPlanner(Map *map) {
Expand Down
1 change: 1 addition & 0 deletions src/state/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ set(SOURCE_FILES
src/actor/factory.cpp
src/map/map.cpp
src/gold_manager/gold_manager.cpp
src/gold_manager/gold_mine.cpp
src/actor/soldier_states/soldier_state.cpp
src/actor/soldier_states/soldier_idle_state.cpp
src/actor/soldier_states/soldier_attack_state.cpp
Expand Down
11 changes: 11 additions & 0 deletions src/state/include/state/actor/actor.fwd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @file actor.fwd.h
* Forward declaration for the Actor class
*/

#pragma once

namespace state {

class Actor;
}
12 changes: 5 additions & 7 deletions src/state/include/state/actor/actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@
#pragma once

#include "physics/vector.hpp"
#include "state/gold_manager/gold_manager.h"
#include "state/interfaces/i_gold_manager.h"
#include "state/interfaces/i_updatable.h"
#include "state/state_export.h"
#include "state/utilities.h"
#include <cstdint>
#include <memory>

namespace state {
/**
* Actor base class
*/

class STATE_EXPORT Actor : public IUpdatable {
protected:
/**
Expand Down Expand Up @@ -58,13 +56,13 @@ class STATE_EXPORT Actor : public IUpdatable {
/**
* Gold manager instance to perform transactions
*/
GoldManager *gold_manager;
IGoldManager *gold_manager;

public:
Actor();

Actor(ActorId id, PlayerId player_id, ActorType actor_type, int64_t hp,
int64_t max_hp, DoubleVec2D position, GoldManager *gold_manager);
int64_t max_hp, DoubleVec2D position, IGoldManager *gold_manager);

virtual ~Actor() {}

Expand Down Expand Up @@ -118,7 +116,7 @@ class STATE_EXPORT Actor : public IUpdatable {
*
* @return gold_manager Unit's GoldManager Pointer
*/
GoldManager *GetGoldManager();
IGoldManager *GetGoldManager();

/**
* Get the maximum hp of the actor
Expand Down
2 changes: 1 addition & 1 deletion src/state/include/state/actor/factory.fwd.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @file soldier.fwd.h
* @file factory.fwd.h
* Forward declaration for the Factory class
*/

Expand Down
3 changes: 2 additions & 1 deletion src/state/include/state/actor/factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "state/actor/factory_states/factory_state.h"
#include "state/actor/soldier.h"
#include "state/actor/villager.h"
#include "state/interfaces/i_gold_manager.h"
#include "state/state_export.h"
#include "state/utilities.h"

Expand Down Expand Up @@ -79,7 +80,7 @@ class STATE_EXPORT Factory : public Actor {
Factory();

Factory(ActorId id, PlayerId player_id, ActorType actor_type, int64_t hp,
int64_t max_hp, DoubleVec2D position, GoldManager *gold_manager,
int64_t max_hp, DoubleVec2D position, IGoldManager *gold_manager,
int64_t construction_complete, int64_t construction_total,
ActorType production_state, int64_t villager_frequency,
int64_t soldier_frequency,
Expand Down
2 changes: 1 addition & 1 deletion src/state/include/state/actor/soldier.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class STATE_EXPORT Soldier : public Unit {
Soldier();

Soldier(ActorId id, PlayerId player_id, ActorType actor_type, int64_t hp,
int64_t max_hp, DoubleVec2D position, GoldManager *gold_manager,
int64_t max_hp, DoubleVec2D position, IGoldManager *gold_manager,
PathPlanner *path_planner, int64_t speed, int64_t attack_range,
int64_t attack_damage);

Expand Down
2 changes: 1 addition & 1 deletion src/state/include/state/actor/unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class STATE_EXPORT Unit : public Actor {
Unit();

Unit(ActorId id, PlayerId player_id, ActorType actor_type, int64_t hp,
int64_t max_hp, DoubleVec2D position, GoldManager *gold_manager,
int64_t max_hp, DoubleVec2D position, IGoldManager *gold_manager,
PathPlanner *path_planner, int64_t speed, int64_t attack_range,
int64_t attack_damage);

Expand Down
3 changes: 1 addition & 2 deletions src/state/include/state/actor/villager.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "state/actor/factory.fwd.h"
#include "state/actor/unit.h"
#include "state/actor/villager_states/villager_state.h"
#include "state/gold_manager/gold_manager.h"

namespace state {

Expand Down Expand Up @@ -62,7 +61,7 @@ class STATE_EXPORT Villager : public Unit {
Villager();

Villager(ActorId id, PlayerId player_id, ActorType actor_type, int64_t hp,
int64_t max_hp, DoubleVec2D position, GoldManager *gold_manager,
int64_t max_hp, DoubleVec2D position, IGoldManager *gold_manager,
PathPlanner *path_planner, int64_t speed, int64_t attack_range,
int64_t attack_damage, int64_t build_effort, int64_t build_range,
int64_t mine_range);
Expand Down
64 changes: 42 additions & 22 deletions src/state/include/state/gold_manager/gold_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@

#pragma once

#include "state/interfaces/i_gold_manager.h"
#include "state/state_export.h"
#include "state/utilities.h"

#include <array>
#include <cstdint>
#include <memory>
#include <unordered_map>
#include <vector>

namespace state {

Expand All @@ -21,7 +25,7 @@ class Actor;
/**
* Gold Manager class that handles player gold
*/
class STATE_EXPORT GoldManager {
class STATE_EXPORT GoldManager : public IGoldManager {

private:
/**
Expand Down Expand Up @@ -49,11 +53,6 @@ class STATE_EXPORT GoldManager {
*/
int64_t factory_kill_reward_amount;

/**
* Penalty amount for a suicide of a factory
*/
int64_t factory_suicide_penalty_amount;

/**
* Amount of gold to create a villager
*/
Expand All @@ -74,6 +73,23 @@ class STATE_EXPORT GoldManager {
*/
int64_t mining_reward;

/**
* Vector of the gold mines
*/
std::vector<std::unique_ptr<GoldMine>> gold_mines;

/**
* Map to manage user build requests
* It maps each gold mine to number of requests made by the player to mine
* that location
*/
std::array<std::unordered_map<GoldMine *, int64_t>, 2> mine_requests;

/**
* Function to return gold mine given the Vec2D offset
*/
GoldMine *GetGoldMine(Vec2D offset);

public:
/**
* Constructor for Gold Manager class
Expand All @@ -83,10 +99,10 @@ class STATE_EXPORT GoldManager {
GoldManager(std::array<int64_t, 2> player_gold, int64_t max_gold,
int64_t soldier_kill_reward_amount,
int64_t villager_kill_reward_amount,
int64_t factory_kill_reward_amount,
int64_t factory_suicide_penalty_amount, int64_t villager_cost,
int64_t soldier_cost, int64_t soldier_factory_cost,
int64_t mining_reward);
int64_t factory_kill_reward_amount, int64_t villager_cost,
int64_t soldier_cost, int64_t factory_cost,
int64_t mining_reward,
std::vector<std::unique_ptr<GoldMine>> gold_mines);

/**
* Method to increase player money
Expand All @@ -98,7 +114,7 @@ class STATE_EXPORT GoldManager {
*
* @throw std::out_of_range If the amount is not positive
*/
void Increase(PlayerId player_id, int64_t amount);
void Increase(PlayerId player_id, int64_t amount) override;

/**
* Method to decrease player money
Expand All @@ -109,28 +125,28 @@ class STATE_EXPORT GoldManager {
* @throw std::out_of_range If the amount is not positive
* player has insufficuent balance
*/
void Decrease(PlayerId player_id, int64_t amount);
void Decrease(PlayerId player_id, int64_t amount) override;

/**
* Reward the player for killing an enemy actor
*
* @param[in] enemy_actor Pointer to the killed enemy
*/
void RewardKill(Actor *enemy_actor);
void RewardKill(Actor *enemy_actor) override;

/**
* Returns the cost for creating a particular unit
*
* @param[in] actor_type ActorType to fetch cost
*/
int64_t GetCreateUnitCost(ActorType unit_type);
int64_t GetCreateUnitCost(ActorType unit_type) override;

/**
* Decreases player's gold for creating specific actor type
*
* @param[in] actor_type Pointer to the actor which player wants to build
*/
void DeductUnitCreateCost(PlayerId player_id, Actor *actor);
void DeductUnitCreateCost(PlayerId player_id, Actor *actor) override;

/**
* Get the current balance amount of the PlayerId passed
Expand All @@ -139,27 +155,31 @@ class STATE_EXPORT GoldManager {
*
* @return The balance.
*/
int64_t GetBalance(PlayerId player_id);
int64_t GetBalance(PlayerId player_id) override;

/**
* Gets the maximum balance.
*
* @return The maximum possible balance.
*/
int64_t GetMaxGold();
int64_t GetMaxGold() override;

/**
* Penalty for player triggering suicide
*
* @param[in] player_id Player who triggered the suicide
*/
void DeductFactorySuicidePenalty(PlayerId player_id);
void RewardMineGold(PlayerId player_id, GoldMine *gold_mine,
int64_t mining_reward) override;

/**
* Penalty for player triggering suicide
*
* @param[in] player_id Player who triggered the suicide
* Function to add build request to current requests
*/
void AddMineRequest(PlayerId player_id, Vec2D offset) override;

/**
* Function to assign amount of gold to be given to each player
*/
void RewardMineGold(PlayerId player_id);
void Update() override;
};
} // namespace state
31 changes: 31 additions & 0 deletions src/state/include/state/gold_manager/gold_mine.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "physics/vector.hpp"

namespace state {

class GoldMine {
public:
/**
* A vector to hold the offset where the gold mine is located
*/
Vec2D offset;

/**
* Holds the amount of gold reserve that the gold mine has
*/
int64_t value;

/**
* Constructors
*/

GoldMine();

GoldMine(Vec2D offset, int64_t value);

/**
* Helper function to extract valid amount of gold depending on amount of
* gold left in the gold mine
*/
int64_t ExtractGold(int64_t ext_amount);
};
} // namespace state
Loading