aboutsummaryrefslogtreecommitdiff
path: root/game/entity.h
blob: a15ebdb449428b3ac5b301c999102e9bfe5e64b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef ENTITIES_H
#define ENTITIES_H

#include <vector>
#include <string>

#include <iostream>

#include "../umath/vec2.h"


class EntityInfo {
    public:
    EntityInfo() { spritebounds = vec2 { 16*6, 16 }; }
    
    enum Class { inf, cav, ran, sie, bld };
    Class ent_class;
    
    std::string name;
    
    int id;
    int level;
    
    float hp;
    float attack;
    float defence;
    int range;
    float sight;
    int move;
    int unit;
    std::vector<int> abilities;
    std::vector<int> build;
    std::vector<int> train_id;
    std::vector<Class> train_class;
    
    std::vector<float> prod { 0, 0 };
    std::vector<float> cost { 0, 0 };
    
    std::vector<int> adjacent;
    std::vector<int> diagonal;
    float defence_bonus { 0 };
    int upgrade { -1 };
    
    vec2 spritebounds;
};

namespace EntityClass {
    int from_string(std::string str);
}

class Entity {
    public:
    Entity (int x, int y, EntityInfo *info, int owner) 
        : x(x), y(y), info(info), owner(owner) { moved = 0; hp = 100; }
    
    // copy constructor
    Entity (const Entity& rhs) { 
        building = rhs.building; hp = rhs.hp; x = rhs.x; y = rhs.y;
        done = rhs.done; moved = rhs.moved; info = rhs.info;
        fights = rhs.fights; owner = rhs.owner;
    }
    Entity& operator=(const Entity& rhs) {
        building = rhs.building; hp = rhs.hp; x = rhs.x; y = rhs.y;
        done = rhs.done; moved = rhs.moved; info = rhs.info;
        fights = rhs.fights; owner = rhs.owner;
    };

    bool operator==(Entity oth) { 
        return x == oth.x && y == oth.y && info->unit == oth.info->unit;
    }

    int building { 0 };
    float hp;
    int x, y;
    bool done = false;
    int moved;
    EntityInfo *info;
    int fights { 0 };
    int owner;
};

#endif