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
|
/* write event chain */
uint32_t writeencounter(FILE* fd, AList* al_combat, AList* al_agents, uint32_t start_type) {
/* file byte index */
uint32_t fdindex = 0;
/* write header (16 bytes) */
char header[32];
asnprintf(&header[0], 32, "EVTC%s", g->m_version);
header[12] = 0;
*(uint16_t*)(&header[13]) = g->m_game->m_area_cbt_cid;
header[15] = 0;
fseek(fd, 0, SEEK_SET);
fwrite(&header[0], 16, 1, fd);
fdindex += 16;
/* define agent. stats range from 0-10 */
typedef struct evtc_agent {
uint64_t addr;
uint32_t prof;
uint32_t is_elite;
int16_t toughness;
int16_t concentration;
int16_t healing;
int16_t pad1;
int16_t condition;
int16_t pad2;
char name[64];
} evtc_agent;
/* count agents */
alisti itr;
uint32_t ag_count = 0;
int32_t max_toughness = 1;
int32_t max_healing = 1;
int32_t max_condition = 1;
al_agents->IInitTail(&itr);
evtc_agent* evag = (evtc_agent*)al_agents->INext(&itr);
while (evag) {
ag_count += 1;
max_toughness = MAX(evag->toughness, max_toughness);
max_healing = MAX(evag->healing, max_healing);
max_condition = MAX(evag->condition, max_condition);
evag = (evtc_agent*)al_agents->INext(&itr);
}
/* write agent count */
fseek(fd, fdindex, SEEK_SET);
fwrite(&ag_count, sizeof(uint32_t), 1, fd);
fdindex += sizeof(uint32_t);
/* write agent array */
al_agents->IInitTail(&itr);
evag = (evtc_agent*)al_agents->INext(&itr);
while (evag) {
evag->toughness = ((evag->toughness * 100) / max_toughness) / 10;
evag->healing = ((evag->healing * 100) / max_healing) / 10;
evag->condition = ((evag->condition * 100) / max_condition) / 10;
fseek(fd, fdindex, SEEK_SET);
fwrite(evag, sizeof(evtc_agent), 1, fd);
fdindex += sizeof(evtc_agent);
evag = (evtc_agent*)al_agents->INext(&itr);
}
/* count skills */
uint8_t* sk_mask = (uint8_t*)acalloc(sizeof(uint8_t) * 65535);
al_combat->IInitTail(&itr);
cbtevent* cbtev = (cbtevent*)al_combat->INext(&itr);
uint32_t skcount = 0;
while (cbtev) {
if (!sk_mask[cbtev->skillid]) {
skcount += 1;
sk_mask[cbtev->skillid] = 1;
}
cbtev = (cbtevent*)al_combat->INext(&itr);
}
/* write skill count */
fseek(fd, fdindex, SEEK_SET);
fwrite(&skcount, sizeof(uint32_t), 1, fd);
fdindex += sizeof(uint32_t);
/* define skill */
typedef struct skill {
int32_t id;
char name[64];
} skill;
/* write skill array */
skcount = 0;
while (skcount < 65535) {
if (sk_mask[skcount]) {
skill temp;
memset(&temp, 0, sizeof(skill));
temp.id = g->m_game->m_ar_sks[skcount].skillid;
asnprintf(&temp.name[0], RB_NAME_LEN, "%s", g->m_game->m_ar_sks[skcount].name);
fseek(fd, fdindex, SEEK_SET);
fwrite(&temp, sizeof(skill), 1, fd);
fdindex += sizeof(skill);
}
skcount += 1;
}
acfree(sk_mask);
/* write combat log */
al_combat->IInitTail(&itr);
cbtev = (cbtevent*)al_combat->INext(&itr);
while (cbtev) {
fseek(fd, fdindex, SEEK_SET);
fwrite(cbtev, sizeof(cbtevent), 1, fd);
fdindex += sizeof(cbtevent);
cbtev = (cbtevent*)al_combat->INext(&itr);
}
/* cleanup */
fclose(fd);
return fdindex;
}
|