Cube  Diff

Differences From Artifact [ace0df653e]:

To Artifact [1744394702]:


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
213
214
215
216
217







218
219
220
221
222
223
224
225



226
227
228
229

230
231
232
233
234










































































235
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
213
214

215
216




217
218
219
220
221

222
223
224
225
226







227
228
229
230
231
232
233
234
235
236
237
238



239
240
241
242
243
244

245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325





-
+

-
-
-
-
+
+
+
+


-
-
-
-
+
+
+
+


-
-
-
+
+
+


-
-
+
+

-
+


-
+





+
+
+
+
+











+
+
+
+
+
+
+
+
+
+
+












-
-
+
+



-
-
-
-
-
+
+
+
+
+






-
+

-
-
-
-
+
+
+
+

-
+




-
-
-
-
-
-
-
+
+
+
+
+
+
+





-
-
+
+

-
+



-
+












-
-
+
+



-
-
-
-
-
+
+
+
+
+






-
+

-
-
-
-
+
+
+
+

-
+




-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
-
-
+
+
+



-
+




















-
-
+
+



-
-
-
-
-
+
+
+
+
+






-
+

-
-
-
-
+
+
+
+

-
+




-
-
-
-
-
-
-
+
+
+
+
+
+
+





-
-
-
+
+
+



-
+





+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

#import "DynamicEntity.h"

#include "cube.h"

struct dynent {
	OFVector3D o, vel;
	OFVector3D origin, velocity;
	float yaw, pitch, roll;
	float maxspeed;
	bool outsidemap;
	bool inwater;
	bool onfloor, jumpnext;
	float maxSpeed;
	bool outsideMap;
	bool inWater;
	bool onFloor, jumpNext;
	int move, strafe;
	bool k_left, k_right, k_up, k_down;
	int timeinair;
	float radius, eyeheight, aboveeye;
	int lastupdate, plag, ping;
	int lifesequence;
	int timeInAir;
	float radius, eyeHeight, aboveEye;
	int lastUpdate, lag, ping;
	int lifeSequence;
	int state;
	int frags;
	int health, armour, armourtype, quadmillis;
	int gunselect, gunwait;
	int lastaction, lastattackgun, lastmove;
	int health, armour, armourType, quadMillis;
	int gunSelect, gunWait;
	int lastAction, lastAttackGun, lastMove;
	bool attacking;
	int ammo[NUMGUNS];
	int monsterstate;
	int mtype;
	int monsterState;
	int monsterType;
	void *enemy;
	float targetyaw;
	float targetYaw;
	bool blocked, moving;
	int trigger;
	OFVector3D attacktarget;
	OFVector3D attackTarget;
	int anger;
	char name[260], team[260];
};

@implementation DynamicEntity
+ (instancetype)entity
{
	return [[self alloc] init];
}

+ (size_t)serializedSize
{
	return sizeof(struct dynent);
}

- (instancetype)init
{
	self = [super init];

	_ammo = (int *)OFAllocZeroedMemory(NUMGUNS, sizeof(int));

	_yaw = 270;
	_maxSpeed = 22;
	_radius = 1.1f;
	_eyeHeight = 3.2f;
	_aboveEye = 0.7f;
	_lastUpdate = lastmillis;
	_name = _team = @"";
	_state = CS_ALIVE;

	[self resetToSpawnState];

	return self;
}

- (void)dealloc
{
	OFFreeMemory(_ammo);
}

- (id)copy
{
	DynamicEntity *copy = [[self.class alloc] init];

	copy->_o = _o;
	copy->_vel = _vel;
	copy->_origin = _origin;
	copy->_velocity = _velocity;
	copy->_yaw = _yaw;
	copy->_pitch = _pitch;
	copy->_roll = _roll;
	copy->_maxspeed = _maxspeed;
	copy->_outsidemap = _outsidemap;
	copy->_inwater = _inwater;
	copy->_onfloor = _onfloor;
	copy->_jumpnext = _jumpnext;
	copy->_maxSpeed = _maxSpeed;
	copy->_outsideMap = _outsideMap;
	copy->_inWater = _inWater;
	copy->_onFloor = _onFloor;
	copy->_jumpNext = _jumpNext;
	copy->_move = _move;
	copy->_strafe = _strafe;
	copy->_k_left = _k_left;
	copy->_k_right = _k_right;
	copy->_k_up = _k_up;
	copy->_k_down = _k_down;
	copy->_timeinair = _timeinair;
	copy->_timeInAir = _timeInAir;
	copy->_radius = _radius;
	copy->_eyeheight = _eyeheight;
	copy->_aboveeye = _aboveeye;
	copy->_lastupdate = _lastupdate;
	copy->_plag = _plag;
	copy->_eyeHeight = _eyeHeight;
	copy->_aboveEye = _aboveEye;
	copy->_lastUpdate = _lastUpdate;
	copy->_lag = _lag;
	copy->_ping = _ping;
	copy->_lifesequence = _lifesequence;
	copy->_lifeSequence = _lifeSequence;
	copy->_state = _state;
	copy->_frags = _frags;
	copy->_health = _health;
	copy->_armour = _armour;
	copy->_armourtype = _armourtype;
	copy->_quadmillis = _quadmillis;
	copy->_gunselect = _gunselect;
	copy->_gunwait = _gunwait;
	copy->_lastaction = _lastaction;
	copy->_lastattackgun = _lastattackgun;
	copy->_lastmove = _lastmove;
	copy->_armourType = _armourType;
	copy->_quadMillis = _quadMillis;
	copy->_gunSelect = _gunSelect;
	copy->_gunWait = _gunWait;
	copy->_lastAction = _lastAction;
	copy->_lastAttackGun = _lastAttackGun;
	copy->_lastMove = _lastMove;
	copy->_attacking = _attacking;

	for (size_t i = 0; i < NUMGUNS; i++)
		copy->_ammo[i] = _ammo[i];

	copy->_monsterstate = _monsterstate;
	copy->_mtype = _mtype;
	copy->_monsterState = _monsterState;
	copy->_monsterType = _monsterType;
	copy->_enemy = _enemy;
	copy->_targetyaw = _targetyaw;
	copy->_targetYaw = _targetYaw;
	copy->_blocked = _blocked;
	copy->_moving = _moving;
	copy->_trigger = _trigger;
	copy->_attacktarget = _attacktarget;
	copy->_attackTarget = _attackTarget;
	copy->_anger = _anger;

	copy->_name = [_name copy];
	copy->_team = [_team copy];

	return copy;
}

- (OFData *)dataBySerializing
{
	// This is frighteningly *TERRIBLE*, but the format used by existing
	// savegames.
	struct dynent data = { .o = _o,
		.vel = _vel,
	struct dynent data = { .origin = _origin,
		.velocity = _velocity,
		.yaw = _yaw,
		.pitch = _pitch,
		.roll = _roll,
		.maxspeed = _maxspeed,
		.outsidemap = _outsidemap,
		.inwater = _inwater,
		.onfloor = _onfloor,
		.jumpnext = _jumpnext,
		.maxSpeed = _maxSpeed,
		.outsideMap = _outsideMap,
		.inWater = _inWater,
		.onFloor = _onFloor,
		.jumpNext = _jumpNext,
		.move = _move,
		.strafe = _strafe,
		.k_left = _k_left,
		.k_right = _k_right,
		.k_up = _k_up,
		.k_down = _k_down,
		.timeinair = _timeinair,
		.timeInAir = _timeInAir,
		.radius = _radius,
		.eyeheight = _eyeheight,
		.aboveeye = _aboveeye,
		.lastupdate = _lastupdate,
		.plag = _plag,
		.eyeHeight = _eyeHeight,
		.aboveEye = _aboveEye,
		.lastUpdate = _lastUpdate,
		.lag = _lag,
		.ping = _ping,
		.lifesequence = _lifesequence,
		.lifeSequence = _lifeSequence,
		.state = _state,
		.frags = _frags,
		.health = _health,
		.armour = _armour,
		.armourtype = _armourtype,
		.quadmillis = _quadmillis,
		.gunselect = _gunselect,
		.gunwait = _gunwait,
		.lastaction = _lastaction,
		.lastattackgun = _lastattackgun,
		.lastmove = _lastmove,
		.armourType = _armourType,
		.quadMillis = _quadMillis,
		.gunSelect = _gunSelect,
		.gunWait = _gunWait,
		.lastAction = _lastAction,
		.lastAttackGun = _lastAttackGun,
		.lastMove = _lastMove,
		.attacking = _attacking,
		.monsterstate = _monsterstate,
		.mtype = _mtype,
		.targetyaw = _targetyaw,
		.monsterState = _monsterState,
		.monsterType = _monsterType,
		.targetYaw = _targetYaw,
		.blocked = _blocked,
		.moving = _moving,
		.trigger = _trigger,
		.attacktarget = _attacktarget,
		.attackTarget = _attackTarget,
		.anger = _anger };

	for (int i = 0; i < NUMGUNS; i++)
		data.ammo[i] = _ammo[i];

	memcpy(data.name, _name.UTF8String, min(_name.UTF8StringLength, 259));
	memcpy(data.team, _team.UTF8String, min(_team.UTF8StringLength, 259));

	return [OFData dataWithItems:&data count:sizeof(data)];
}

- (void)setFromSerializedData:(OFData *)data
{
	struct dynent d;

	if (data.count != sizeof(struct dynent))
		@throw [OFOutOfRangeException exception];

	memcpy(&d, data.items, data.count);

	_o = d.o;
	_vel = d.vel;
	_origin = d.origin;
	_velocity = d.velocity;
	_yaw = d.yaw;
	_pitch = d.pitch;
	_roll = d.roll;
	_maxspeed = d.maxspeed;
	_outsidemap = d.outsidemap;
	_inwater = d.inwater;
	_onfloor = d.onfloor;
	_jumpnext = d.jumpnext;
	_maxSpeed = d.maxSpeed;
	_outsideMap = d.outsideMap;
	_inWater = d.inWater;
	_onFloor = d.onFloor;
	_jumpNext = d.jumpNext;
	_move = d.move;
	_strafe = d.strafe;
	_k_left = d.k_left;
	_k_right = d.k_right;
	_k_up = d.k_up;
	_k_down = d.k_down;
	_timeinair = d.timeinair;
	_timeInAir = d.timeInAir;
	_radius = d.radius;
	_eyeheight = d.eyeheight;
	_aboveeye = d.aboveeye;
	_lastupdate = d.lastupdate;
	_plag = d.plag;
	_eyeHeight = d.eyeHeight;
	_aboveEye = d.aboveEye;
	_lastUpdate = d.lastUpdate;
	_lag = d.lag;
	_ping = d.ping;
	_lifesequence = d.lifesequence;
	_lifeSequence = d.lifeSequence;
	_state = d.state;
	_frags = d.frags;
	_health = d.health;
	_armour = d.armour;
	_armourtype = d.armourtype;
	_quadmillis = d.quadmillis;
	_gunselect = d.gunselect;
	_gunwait = d.gunwait;
	_lastaction = d.lastaction;
	_lastattackgun = d.lastattackgun;
	_lastmove = d.lastmove;
	_armourType = d.armourType;
	_quadMillis = d.quadMillis;
	_gunSelect = d.gunSelect;
	_gunWait = d.gunWait;
	_lastAction = d.lastAction;
	_lastAttackGun = d.lastAttackGun;
	_lastMove = d.lastMove;
	_attacking = d.attacking;

	for (int i = 0; i < NUMGUNS; i++)
		_ammo[i] = d.ammo[i];

	_monsterstate = d.monsterstate;
	_mtype = d.mtype;
	_targetyaw = d.targetyaw;
	_monsterState = d.monsterState;
	_monsterType = d.monsterType;
	_targetYaw = d.targetYaw;
	_blocked = d.blocked;
	_moving = d.moving;
	_trigger = d.trigger;
	_attacktarget = d.attacktarget;
	_attackTarget = d.attackTarget;
	_anger = d.anger;

	_name = [[OFString alloc] initWithUTF8String:d.name];
	_team = [[OFString alloc] initWithUTF8String:d.team];
}

- (void)resetMovement
{
	_k_left = false;
	_k_right = false;
	_k_up = false;
	_k_down = false;
	_jumpNext = false;
	_strafe = 0;
	_move = 0;
}

- (void)resetToSpawnState
{
	[self resetMovement];

	_velocity = OFMakeVector3D(0, 0, 0);
	_onFloor = false;
	_timeInAir = 0;
	_health = 100;
	_armour = 50;
	_armourType = A_BLUE;
	_quadMillis = 0;
	_lastAttackGun = _gunSelect = GUN_SG;
	_gunWait = 0;
	_attacking = false;
	_lastAction = 0;

	for (size_t i = 0; i < NUMGUNS; i++)
		_ammo[i] = 0;
	_ammo[GUN_FIST] = 1;

	if (m_noitems) {
		_gunSelect = GUN_RIFLE;
		_armour = 0;

		if (m_noitemsrail) {
			_health = 1;
			_ammo[GUN_RIFLE] = 100;
		} else {
			if (gamemode == 12) {
				// eihrul's secret "instafist" mode
				_gunSelect = GUN_FIST;
				return;
			}

			_health = 256;

			if (m_tarena) {
				_gunSelect = rnd(4) + 1;
				baseammo(_gunSelect);

				int gun2;
				do {
					gun2 = rnd(4) + 1;
				} while (gun2 != _gunSelect);

				baseammo(gun2);
			} else if (m_arena) {
				// insta arena
				_ammo[GUN_RIFLE] = 100;
			} else {
				// efficiency
				for (size_t i = 0; i < 4; i++)
					baseammo(i + 1);

				_gunSelect = GUN_CG;
			}

			_ammo[GUN_CG] /= 2;
		}
	} else
		_ammo[GUN_SG] = 5;
}
@end