Skip to content
Snippets Groups Projects
Select Git revision
  • 38a8e6eaa87e3e8cbd43749b8979f86648a7b373
  • main default protected
  • leveleditor
  • david-author
  • clang-tidy-cleanup
  • architecture-refactoring
  • cleanUpMenus
  • doxygen-cleanup
  • project-structure-refactoring
  • interpolation
  • buildingFeatures
  • win_end_screen
  • helpMenu
  • leveleditor-placement
  • text-rendering
  • updated_unit_contextmenu
  • level-from-commandline
  • unit_contextmenu
  • player
  • engine-scaling
  • clang-tidy
21 results

unit.hpp

Blame
  • unit.hpp 2.51 KiB
    #pragma once
    
    #include "engine.hpp"
    #include "weapon.hpp"
    #include <optional>
    
    namespace advanced_wars {
    
    enum class UnitFaction {
      URED = 0,
      UBLUE = 1,
      UGREEN = 2,
      UYELLOW = 3,
      UPURPLE = 4,
    };
    
    enum class UnitId {
      INFANTERY = 0,
      MECHANIZED_INFANTERY = 1,
      RECON = 2,
      MEDIUM_TANK = 3,
      HEAVY_TANK = 4,
      NEO_TANK = 5,
      APC = 6,
      ANTI_AIR_TANK = 7,
      ARTILLERY = 8,
      ROCKET_ARTILLERY = 9,
      ANTI_AIR_MISSILE_LAUNCHER = 10,
      FIGHTER = 11,
      BOMBER = 12,
      BATTLE_HELICOPTER = 13,
      TRANSPORT_HELICOPTER = 14,
      BATTLESHIP = 15,
      CRUISER = 16,
      LANDER = 17,
      SUBMARINE = 18,
    };
    
    enum class UnitState {
      IDLE = 0,
      UNAVAILABLE = 1,
      MOVEMENTLEFT = 2,
      MOVEMENTRIGHT = 3,
      MOVEMENTDOWN = 4,
      MOVEMENTUP = 5,
    };
    
    enum class MovementType {
      FOOT = 0,
      TIRES = 1,
      TREAD = 2,
      AIR = 3,
      SHIP = 4,
      LANDER = 5,
    };
    
    //Fill the MatchupTabel
    using MatchupTabel = std::unordered_map<u_int8_t, std::unordered_map<u_int8_t, int>>;
    
    class Unit {
    public:
      Unit(int x, int y, UnitFaction faction, UnitId id, UnitState state);
      ~Unit() {
            //Assuming that the destruktion of a unit triggers events
        }
    
      void render(Engine &engine, int scale);
    
      /*
      Check if attacker is in Range to initiate combat
      TODO: This should probably tie back into rendering the units differently
      If a unit is selected, it should call inRange on all other enemy units on the field
      */
    
     bool inRange(Unit &enemy);
    
      /*
      The attacker will move towards the defender and thus initiate combat
      @params Takes a reference to the defender
    
      Will Update the health for both units
      Attacker deals damage to the defender first
      */
      void attack(Unit &enemy);
    
    
      /*
      @params Takes the desired position of the unit and updates its values
      */
      void update_position(int posX, int posY);
    
      /*
      This function needs to be able to determine the possible movement-paths the unit can take
      MUST take into consideration that different units behave differently on certain terrain
      MUST show all movements possible
      */
      void calculate_movement();
    
     /*
     Load the XML and iterate over the entire datastructure
     */
    void loadXML(const char* filename);
    
    private:
      int x;
      int y;
    
      UnitFaction faction;
      UnitId id;
      UnitState state;
    
      int health; //health equals max_health at construction
      int max_health; // max_health required for damage_scaling
      int range;
      int fuel;
      int max_fuel;
    
      bool has_moved;
      bool has_attacked;
    
      // Primary weapon ammo
      int ammo;
    
      std::optional<Weapon> primary;
      std::optional<Weapon> secondary;
    };
    
    } // namespace advanced_wars