/
FIGH.cpp
212 lines (187 loc) · 5.18 KB
/
FIGH.cpp
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#include "simulation/ElementCommon.h"
#include "STKM.h"
static int update(UPDATE_FUNC_ARGS);
static bool createAllowed(ELEMENT_CREATE_ALLOWED_FUNC_ARGS);
static void changeType(ELEMENT_CHANGETYPE_FUNC_ARGS);
static void Free(Simulation *sim, unsigned char i);
void Element::Element_FIGH()
{
Identifier = "DEFAULT_PT_FIGH";
Name = "FIGH";
Colour = 0xFFE0A0_rgb;
MenuVisible = 1;
MenuSection = SC_SPECIAL;
Enabled = 1;
Advection = 0.5f;
AirDrag = 0.00f * CFDS;
AirLoss = 0.2f;
Loss = 1.0f;
Collision = 0.0f;
Gravity = 0.0f;
NewtonianGravity = 0.0f;
Diffusion = 0.0f;
HotAir = 0.00f * CFDS;
Falldown = 0;
Flammable = 0;
Explosive = 0;
Meltable = 0;
Hardness = 0;
Weight = 50;
DefaultProperties.temp = R_TEMP + 14.6f + 273.15f;
HeatConduct = 0;
Description = "Fighter. Tries to kill stickmen. You must first give it an element to kill him with.";
Properties = PROP_NOCTYPEDRAW;
CarriesTypeIn = 1U << FIELD_CTYPE;
LowPressure = IPL;
LowPressureTransition = NT;
HighPressure = IPH;
HighPressureTransition = NT;
LowTemperature = ITL;
LowTemperatureTransition = NT;
HighTemperature = 620.0f;
HighTemperatureTransition = PT_FIRE;
DefaultProperties.life = 100;
Update = &update;
Graphics = &Element_STKM_graphics;
CreateAllowed = &createAllowed;
ChangeType = &changeType;
}
static int update(UPDATE_FUNC_ARGS)
{
auto &sd = SimulationData::CRef();
auto &elements = sd.elements;
if (parts[i].tmp < 0 || parts[i].tmp >= MAX_FIGHTERS)
{
sim->kill_part(i);
return 1;
}
playerst* figh = &sim->fighters[(unsigned char)parts[i].tmp];
int tarx = 0, tary = 0;
parts[i].tmp2 = 0; //0 - stay in place, 1 - seek a stick man
//Set target cords
if (sim->player2.spwn)
{
if (sim->player.spwn && (pow((float)sim->player.legs[2]-x, 2) + pow((float)sim->player.legs[3]-y, 2))<=
(pow((float)sim->player2.legs[2]-x, 2) + pow((float)sim->player2.legs[3]-y, 2)))
{
tarx = (int)sim->player.legs[2];
tary = (int)sim->player.legs[3];
}
else
{
tarx = (int)sim->player2.legs[2];
tary = (int)sim->player2.legs[3];
}
parts[i].tmp2 = 1;
}
else if (sim->player.spwn)
{
tarx = (int)sim->player.legs[2];
tary = (int)sim->player.legs[3];
parts[i].tmp2 = 1;
}
switch (parts[i].tmp2)
{
case 1:
if ((pow(float(tarx-x), 2) + pow(float(tary-y), 2))<600)
{
if (figh->elem == PT_LIGH || figh->elem == PT_NEUT
|| elements[figh->elem].Properties & (PROP_DEADLY | PROP_RADIOACTIVE)
|| elements[figh->elem].DefaultProperties.temp >= 323 || elements[figh->elem].DefaultProperties.temp <= 243)
figh->comm = (int)figh->comm | 0x08;
}
else if (tarx<x)
{
if(figh->rocketBoots || !(sim->eval_move(PT_FIGH, int(figh->legs[4])-10, int(figh->legs[5])+6, NULL)
&& sim->eval_move(PT_FIGH, int(figh->legs[4])-10, int(figh->legs[5])+3, NULL)))
figh->comm = 0x01;
else
figh->comm = 0x02;
if (figh->rocketBoots)
{
if (tary<y)
figh->comm = (int)figh->comm | 0x04;
}
else if (!sim->eval_move(PT_FIGH, int(figh->legs[4])-4, int(figh->legs[5])-1, NULL)
|| !sim->eval_move(PT_FIGH, int(figh->legs[12])-4, int(figh->legs[13])-1, NULL)
|| sim->eval_move(PT_FIGH, 2*int(figh->legs[4])-int(figh->legs[6]), int(figh->legs[5])+5, NULL))
figh->comm = (int)figh->comm | 0x04;
}
else
{
if (figh->rocketBoots || !(sim->eval_move(PT_FIGH, int(figh->legs[12])+10, int(figh->legs[13])+6, NULL)
&& sim->eval_move(PT_FIGH, int(figh->legs[12])+10, int(figh->legs[13])+3, NULL)))
figh->comm = 0x02;
else
figh->comm = 0x01;
if (figh->rocketBoots)
{
if (tary<y)
figh->comm = (int)figh->comm | 0x04;
}
else if (!sim->eval_move(PT_FIGH, int(figh->legs[4])+4, int(figh->legs[5])-1, NULL)
|| !sim->eval_move(PT_FIGH, int(figh->legs[4])+4, int(figh->legs[5])-1, NULL)
|| sim->eval_move(PT_FIGH, 2*int(figh->legs[12])-int(figh->legs[14]), int(figh->legs[13])+5, NULL))
figh->comm = (int)figh->comm | 0x04;
}
break;
default:
figh->comm = 0;
break;
}
figh->pcomm = figh->comm;
Element_STKM_run_stickman(figh, UPDATE_FUNC_SUBCALL_ARGS);
return 0;
}
static bool createAllowed(ELEMENT_CREATE_ALLOWED_FUNC_ARGS)
{
return Element_FIGH_CanAlloc(sim);
}
static void changeType(ELEMENT_CHANGETYPE_FUNC_ARGS)
{
if (to == PT_FIGH)
{
sim->parts[i].tmp = Element_FIGH_Alloc(sim);
if (sim->parts[i].tmp >= 0)
Element_FIGH_NewFighter(sim, sim->parts[i].tmp, i, PT_DUST);
}
else
{
Free(sim, (unsigned char)sim->parts[i].tmp);
}
}
bool Element_FIGH_CanAlloc(Simulation *sim)
{
return sim->fighcount < MAX_FIGHTERS;
}
int Element_FIGH_Alloc(Simulation *sim)
{
if (sim->fighcount >= MAX_FIGHTERS)
return -1;
int i = 0;
while (i < MAX_FIGHTERS && sim->fighters[i].spwn==1)
i++;
if (i < MAX_FIGHTERS)
{
sim->fighters[i].spwn = 1;
sim->fighters[i].elem = PT_DUST;
sim->fighcount++;
return i;
}
else return -1;
}
static void Free(Simulation *sim, unsigned char i)
{
if (sim->fighters[i].spwn)
{
sim->fighters[i].spwn = 0;
sim->fighcount--;
}
}
void Element_FIGH_NewFighter(Simulation *sim, int fighterID, int i, int elem)
{
Element_STKM_init_legs(sim, &sim->fighters[fighterID], i);
if (elem > 0 && elem < PT_NUM)
sim->fighters[fighterID].elem = elem;
sim->fighters[fighterID].spwn = 1;
}