-
Notifications
You must be signed in to change notification settings - Fork 26
/
ai.h
172 lines (143 loc) · 5.3 KB
/
ai.h
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#pragma once
#include "dfhack_shared.h"
#include "config.h"
#include "room.h"
#include <ctime>
#include <fstream>
#include <functional>
#include <list>
#include <random>
#include "df/coord.h"
#include "df/interface_key.h"
#include "df/language_name.h"
#include "json/json.h"
namespace df
{
struct activity_event_conflictst;
struct history_event;
struct item;
struct job;
struct manager_order;
struct manager_order_template;
struct report;
struct unit;
struct viewscreen;
}
namespace DFHack
{
namespace Maps
{
uint16_t getTileWalkable(df::coord t);
}
}
#include "event_manager.h"
#include "population.h"
#include "plan.h"
#include "stocks.h"
#include "camera.h"
#include "trade.h"
std::string html_escape(const std::string & str);
inline std::string maybe_escape(const std::string & str, bool html)
{
return html ? html_escape(str) : str;
}
void ai_version(std::ostream & out, bool html = false);
class weblegends_handler_v1;
bool ai_weblegends_handler(weblegends_handler_v1 & out, const std::string & url);
class AI
{
public:
std::mt19937 rng;
std::ofstream logger;
std::ofstream eventsJson;
Population pop;
Plan plan;
Stocks stocks;
Camera camera;
Trade trade;
OnupdateCallback *pause_onupdate;
OnupdateCallback *tag_enemies_onupdate;
OnupdateCallback *announcements_onupdate;
std::set<std::string> seen_focus;
std::set<std::string> seen_cvname;
int32_t last_good_x, last_good_y, last_good_z;
int32_t last_pause_id, last_pause_repeats;
bool skip_persist;
int32_t last_announcement_id;
char lockstep_log_buffer[25][80];
uint8_t lockstep_log_color[25];
AI();
~AI();
static std::string timestamp(int32_t y, int32_t t);
static std::string timestamp();
static std::string describe_name(const df::language_name & name, bool in_english = false, bool only_last_part = false);
static std::string describe_item(df::item *i);
static std::string describe_unit(df::unit *u, bool html = false);
static std::string describe_job(const df::job *job);
static std::string describe_job(const df::manager_order *job);
static std::string describe_job(const df::manager_order_template *job);
static std::string describe_job(const df::unit *u);
static std::string describe_event(df::history_event *event);
static bool is_dwarfmode_viewscreen();
static void write_df(std::ostream & out, const std::string & str, const std::string & newline = "\n", const std::string & suffix = "\n", std::function<std::string(const std::string &)> translate = DF2UTF);
void write_lockstep(std::string str, uint8_t color = 7);
void debug(color_ostream & out, const std::string & str);
void event(const std::string & name, const Json::Value & payload);
command_result startup(color_ostream & out);
void unpause();
void handle_pause_event(color_ostream & out, df::report *announce);
void statechanged(color_ostream & out, state_change_event event);
static void abandon(color_ostream & out);
bool tag_enemies(color_ostream & out);
void watch_announcements();
static df::unit *is_attacking_citizen(df::unit *u);
static df::unit *is_hunting_target(df::unit *u);
static bool is_in_conflict(df::unit *u, std::function<bool(df::activity_event_conflictst *)> filter = [](df::activity_event_conflictst *) -> bool { return true; });
void timeout_sameview(int32_t seconds, std::function<void(color_ostream &)> cb);
void timeout_sameview(std::function<void(color_ostream &)> cb)
{
timeout_sameview(5, cb);
}
void ignore_pause(int32_t x, int32_t y, int32_t z);
static std::string describe_room(room *r, bool html = false);
static std::string describe_furniture(furniture *f, bool html = false);
static void dig_tile(df::coord t, df::tile_dig_designation dig = tile_dig_designation::Default);
df::coord fort_entrance_pos();
room *find_room(room_type::type type);
room *find_room(room_type::type type, std::function<bool(room *)> b);
room *find_room_at(df::coord t);
inline bool map_tile_intersects_room(df::coord t)
{
for (int dx = -1; dx <= 1; dx++)
{
for (int dy = -1; dy <= 1; dy++)
{
if (find_room_at(t + df::coord(dx, dy, 0)) != nullptr)
{
return true;
}
}
}
return false;
}
static df::coord spiral_search(df::coord t, int16_t max, int16_t min, int16_t step, std::function<bool(df::coord)> b);
static inline df::coord spiral_search(df::coord t, int16_t max, int16_t min, std::function<bool(df::coord)> b)
{
return spiral_search(t, max, min, 1, b);
}
static inline df::coord spiral_search(df::coord t, int16_t max, std::function<bool(df::coord)> b)
{
return spiral_search(t, max, 0, 1, b);
}
static inline df::coord spiral_search(df::coord t, std::function<bool(df::coord)> b)
{
return spiral_search(t, 100, 0, 1, b);
}
command_result onupdate_register(color_ostream & out);
command_result onupdate_unregister(color_ostream & out);
std::string status();
std::string report(bool html = false);
command_result persist(color_ostream & out);
command_result unpersist(color_ostream & out);
bool is_embarking();
};