LCOV - code coverage report
Current view: top level - src - mob.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 3 3 100.0 %
Date: 2020-10-15 20:26:03 Functions: 6 6 100.0 %

          Line data    Source code
       1             : //
       2             : //  mob.h
       3             : //  minirl
       4             : //
       5             : //  Created by Benjamin Porter on 1/1/18.
       6             : //  Copyright © 2018 Benjamin Porter. All rights reserved.
       7             : //
       8             : 
       9             : #ifndef mob_h
      10             : #define mob_h
      11             : 
      12             : #include "entity.h"
      13             : #include "util.h"
      14             : 
      15             : #include <cstdint>
      16             : #include <string>
      17             : 
      18             : enum class MobCategory { Unknown, Rabbit, Snake, Orc, Player };
      19             : 
      20             : enum class MobType { Unknown, Rabbit, RabbitWere, Snake, OrcWeak, OrcStrong, Player };
      21             : 
      22             : inline std::string to_string(MobType type) {
      23             :     using namespace std::string_literals;
      24             : 
      25             :     switch (type) {
      26             :     default:
      27             :     case MobType::Unknown:
      28             :         return "MobType::Unknown"s;
      29             :     case MobType::Rabbit:
      30             :         return "MobType::Rabbit"s;
      31             :     case MobType::RabbitWere:
      32             :         return "MobType::RabbitWere"s;
      33             :     case MobType::Snake:
      34             :         return "MobType::Snake"s;
      35             :     case MobType::OrcWeak:
      36             :         return "MobType::OrcWeak"s;
      37             :     case MobType::OrcStrong:
      38             :         return "MobType::OrcStrong"s;
      39             :     case MobType::Player:
      40             :         return "MobType::Player"s;
      41             :     }
      42             : }
      43             : 
      44          44 : struct MobInfo {
      45             :     MobCategory category{MobCategory::Unknown};
      46             :     std::string name{};
      47             :     int32_t health = 0;
      48             :     bool attacks = false;
      49             :     int32_t strength = 0;
      50             :     int32_t speed = 4; // 1 = slowest, 10 = fastest
      51             : };
      52             : 
      53             : class Mob : public Component {
      54             : public:
      55             :     static const int TicksPerAction = 15;
      56             : 
      57           5 :     Mob() = default;
      58         200 :     Mob(const MobInfo* info) : info{info} {}
      59             :     const MobInfo* info{&sMobInfo};
      60             : 
      61             :     vec2i position{0, 0};
      62             :     int32_t health{0};
      63             :     int32_t tick{0};
      64             : 
      65             :     // type-specific data
      66             :     vec2i dir{0, 1};
      67             : 
      68             :     // additional components (references to children)
      69             :     ident extraSprite{invalid_id};
      70             :     ident extraSprite2{invalid_id};
      71             : 
      72             : private:
      73             :     static MobInfo sMobInfo;
      74             : };
      75             : 
      76             : #endif /* mob_h */

Generated by: LCOV version 1.13