-
Notifications
You must be signed in to change notification settings - Fork 4
/
report.c
126 lines (99 loc) · 2.35 KB
/
report.c
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
#include "report.h"
#include "settings.h"
#include "region.h"
#include "faction.h"
#include "ship.h"
#include "building.h"
#include "unit.h"
#include "rtl.h"
#include <quicklist.h>
#include <assert.h>
#include <stdio.h>
#include <string.h>
char buf[10240];
void scat(const char *s)
{
strcat(buf, s);
}
void icat(int n)
{
char s[20];
sprintf(s, "%d", n);
scat(s);
}
const char *factionid(const faction * f)
{
static char buf[NAMESIZE + 20];
sprintf(buf, "%s (%d)", faction_getname(f), f->no);
return buf;
}
static void coor_torus(int *x, int *y)
{
*x = (*x + config.width) % config.width;
*y = (*y + config.height) % config.height;
}
static void coor_alh(int *x, int *y)
{
int ox = (*x + config.width) % config.width;
int oy = (*y + config.height) % config.height;
*x = ox;
*y = (2 *oy -ox) % config.height;
}
void coor_transform(coor_t transform, int *x, int *y) {
if (transform==COOR_TORUS) {
coor_torus(x, y);
}
else if (transform==COOR_ALH) {
coor_alh(x, y);
}
}
const char *regionid(const region * r, const faction * f)
{
int x, y;
static char buf[NAMESIZE + 20];
assert(r);
x = r->x - (f ? f->origin_x : 0);
y = r->y - (f ? f->origin_y : 0);
coor_transform(config.transform, &x, &y);
if (region_isocean(r)) {
sprintf(buf, "(%d,%d)", x, y);
}
else {
sprintf(buf, "%s (%d,%d)", region_getname(r), x, y);
}
return buf;
}
const char *buildingid(const building * b)
{
static char buf[NAMESIZE + 20];
sprintf(buf, "%s (%d)", building_getname(b), b->no);
return buf;
}
const char *shipid(const ship * sh)
{
static char buf[NAMESIZE + 20];
sprintf(buf, "%s (%d)", ship_getname(sh), sh->no);
return buf;
}
const char *unitid(const unit * u)
{
static char buf[NAMESIZE + 20];
sprintf(buf, "%s (%d)", unit_getname(u), u->no);
return buf;
}
void mistake(faction * f, const char *s, const char *comment)
{
static char buf[512];
sprintf(buf, "%s: %s.", s, comment);
ql_push(&f->mistakes, _strdup(buf));
}
void mistakes(unit * u, const char *str, const char *comment)
{
static char buf[512];
sprintf(buf, "%s: %s - %s.", unitid(u), str, comment);
ql_push(&u->faction->mistakes, _strdup(buf));
}
void mistakeu(unit * u, const char *comment)
{
mistakes(u, u->thisorder, comment);
}