aboutsummaryrefslogtreecommitdiff
path: root/game/tech.h
blob: d5a9e24ffe93c3beade2683ebd0ba526b11f9887 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#ifndef TECH_H
#define TECH_H

#include <vector>
#include <unordered_map>
#include <string>

#include <math.h>

#include <iostream>

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

class TechBonus {
    public:
    float attack { 0 };
    float defence { 0 };
    int sight { 0 };
    int range { 0 };
    int move { 0 };
    std::vector<float> cost { 0, 0 };
    std::vector<float> cost_abs { 0, 0 };
    std::vector<float> prod { 0, 0 };
    int trade { 0 } ;
    int improved_heal { 0 };
    int improved_convert { 0 };
    int req_range { 999 };
    
    std::vector<int> aff_id;
    std::vector<int> aff_class;
    int aff_level { -1 };
    int aff_all { 0 };
    
    TechBonus operator+(const TechBonus &rhs) { 
        TechBonus b;
        b.attack = attack + rhs.attack;
        b.defence = defence + rhs.defence;
        b.sight = sight + rhs.sight;
        b.move = move + rhs.move;
        for (int i=0; i<cost.size(); i++) {
            b.cost[i] = cost[i] + rhs.cost[i];
            b.cost_abs[i] = cost_abs[i] + rhs.cost_abs[i];
            b.prod[i] = prod[i] + rhs.prod[i];
        }
        b.trade = trade + rhs.trade;
        b.improved_heal = improved_heal + rhs.improved_heal;
        b.improved_convert = improved_convert + rhs.improved_convert;
        return b;
    }
    
    std::string to_string () {
        std::string str = "";
        if (attack != 0) { 
            int value = (int)roundf(attack*100);
            str += "Attack: " + std::to_string(value) + "%\n";
        }
        if (defence != 0) { 
            int value = (int)roundf(defence*100);
            str += "Defence: " + std::to_string(value) + "%\n";
        }
        if (sight != 0) { 
            str += "Sight: " + std::to_string(sight) + "\n";
        }
        if (range != 0) { 
            str += "Range: " + std::to_string(range) + "\n";
        }
        if (move != 0) { 
            str += "Range: " + std::to_string(range) + "\n";
        }
        if (cost[0] != 0 || cost[1] != 0) { 
            int vf = (int)roundf(cost[0]*100);
            int vg = (int)roundf(cost[1]*100);
            str += "Cost f: " + std::to_string(vf);
            str += "%, g: " + std::to_string(vg) + "%\n";
        }
        if (cost_abs[0] != 0 || cost_abs[1] != 0) { 
            int vf = (int)roundf(cost_abs[0]);
            int vg = (int)roundf(cost_abs[1]);
            str += "Cost f: " + std::to_string(vf);
            str += ", g: " + std::to_string(vg) + "\n";
        }
        if (prod[0] != 0 || prod[1] != 0) { 
            int vf = (int)roundf(prod[0]*100);
            int vg = (int)roundf(prod[1]*100);
            str += "Production f: " + std::to_string(vf);
            str += "%, g: " + std::to_string(vg) + "%\n";
        }
        if (trade != 0) { str += "Improves Trade Rate\n"; }
        if (improved_heal != 0) { str += "Improves Heal Ability\n"; }
        if (improved_convert != 0) { str += "Improves Convert Ability\n"; }
        if (aff_id.size() > 0) { 
            str += "of entitiy "; 
            for (int id : aff_id) str += std::to_string(id) + " ";
            str += "\n"; 
        }
        if (aff_class.size() > 0) { 
            str += "of class "; 
            for (int c : aff_class) str += std::to_string(c) + " ";
            str += "\n"; 
        }
        if (aff_level != -1) { 
            str += "of level " +  std::to_string(aff_level) + "\n"; 
        }
        return str;
    }
};

class TechLookup {
    public:
    TechLookup() {}
    
    TechBonus id (int i) { return map_id[i]; }
    
    std::unordered_map<int, TechBonus> map_id;
};

class Tech {
    public:
    Tech() {}
    
    std::string name;
    int id;
    int level;
    int req_id;
    std::vector<float> cost { 0, 0 };
    
    TechBonus bonus;
    
    vec2 spritebounds { 0, 0 };
};

#endif