aboutsummaryrefslogtreecommitdiff
path: root/game/ai/performer.h
blob: 17be028f2e4da4430009c0a3323d1b4801bb8c0f (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
#ifndef PERFORMER_H
#define PERFORMER_H

#include <iostream>

#include <string>
#include <vector>

#include "../ground.h"
#include "../gst.h"
#include "action.h"
#include "tactic.h"

namespace ai {

class performer {
    public:
    performer (Gst &gst) : init(gst) {}
    Gst &init;
    
    Gst apply (tactic t) {
        Gst next { init };
        for (action a : t.acts) {
            next = act(next, a);
        }
        next.end_day();
        return next;
    }
    
    Gst& act (Gst &gst, action a) {
        if (a.type == actype::move) {
            Entity &ent = gst.get_at(a.x, a.y);
            ent.x = a.mx; ent.y = a.my;
            ent.moved = 1; ent.done = true;
        }
        if (a.type == actype::attack) {
            Entity &ent = gst.get_at(a.x, a.y);
            ent.x = a.mx; ent.y = a.my;
            ent.moved = 1; 
            Entity &def = gst.get_at(a.tx, a.ty);
            gst.battle(ent, def);
            ent.done = true;
        }
        return gst;
    }
};

}
#endif