︙ | | |
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
-
+
-
|
}
void
savestate(OFIRI *IRI)
{
stop();
f = gzopen([IRI.fileSystemRepresentation
cStringWithEncoding:OFLocale.encoding],
cStringWithEncoding: OFLocale.encoding], "wb9");
"wb9");
if (!f) {
conoutf(@"could not write %@", IRI.string);
return;
}
gzwrite(f, (void *)"CUBESAVE", 8);
gzputc(f, islittleendian);
gzputi(SAVEGAMEVERSION);
|
︙ | | |
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
|
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
|
-
+
-
-
-
+
+
+
+
-
+
-
|
for (id player in players) {
gzput(player == [OFNull null]);
data = [player dataBySerializing];
gzwrite(f, data.items, data.count);
}
}
COMMAND(savegame, ARG_1STR, (^(OFString *name) {
COMMAND(savegame, ARG_1STR, (^ (OFString *name) {
if (!m_classicsp) {
conoutf(@"can only save classic sp games");
return;
}
OFString *path = [OFString stringWithFormat:@"savegames/%@.csgz", name];
OFIRI *IRI =
[Cube.sharedInstance.userDataIRI IRIByAppendingPathComponent:path];
OFString *path = [OFString stringWithFormat:
@"savegames/%@.csgz", name];
OFIRI *IRI = [Cube.sharedInstance.userDataIRI
IRIByAppendingPathComponent: path];
savestate(IRI);
stop();
conoutf(@"wrote %@", IRI.string);
}))
void
loadstate(OFIRI *IRI)
{
stop();
if (multiplayer())
return;
f = gzopen([IRI.fileSystemRepresentation
cStringWithEncoding:OFLocale.encoding],
cStringWithEncoding: OFLocale.encoding], "rb9");
"rb9");
if (!f) {
conoutf(@"could not open %@", IRI.string);
return;
}
char mapname[_MAXDEFSTR] = { 0 };
char buf[8];
|
︙ | | |
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
-
-
-
-
+
+
+
+
+
|
return;
out:
conoutf(@"aborting: savegame/demo from a different version of "
@"cube or cpu architecture");
stop();
}
COMMAND(loadgame, ARG_1STR, (^(OFString *name) {
OFString *path = [OFString stringWithFormat:@"savegames/%@.csgz", name];
OFIRI *IRI =
[Cube.sharedInstance.userDataIRI IRIByAppendingPathComponent:path];
COMMAND(loadgame, ARG_1STR, (^ (OFString *name) {
OFString *path = [OFString stringWithFormat:
@"savegames/%@.csgz", name];
OFIRI *IRI = [Cube.sharedInstance.userDataIRI
IRIByAppendingPathComponent: path];
loadstate(IRI);
}))
void
loadgameout()
{
stop();
|
︙ | | |
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
|
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
|
-
-
+
+
-
+
-
+
-
+
-
+
-
-
-
+
+
+
|
if (e.type == CARROT && !e.spawned)
trigger(e.attr1, e.attr2, true);
}
restoreserverstate(ents);
OFMutableData *data =
[OFMutableData dataWithCapacity:DynamicEntity.serializedSize];
[data increaseCountBy:DynamicEntity.serializedSize];
[OFMutableData dataWithCapacity: DynamicEntity.serializedSize];
[data increaseCountBy: DynamicEntity.serializedSize];
gzread(f, data.mutableItems, data.count);
[Player.player1 setFromSerializedData:data];
[Player.player1 setFromSerializedData: data];
Player.player1.lastAction = lastmillis;
int nmonsters = gzgeti();
OFArray<Monster *> *monsters = Monster.monsters;
if (nmonsters != monsters.count)
return loadgameout();
for (Monster *monster in monsters) {
gzread(f, data.mutableItems, data.count);
[monster setFromSerializedData:data];
[monster setFromSerializedData: data];
// lazy, could save id of enemy instead
monster.enemy = Player.player1;
// also lazy, but no real noticable effect on game
monster.lastAction = monster.trigger = lastmillis + 500;
if (monster.state == CS_DEAD)
monster.lastAction = 0;
}
[Monster restoreAll];
int nplayers = gzgeti();
for (int i = 0; i < nplayers; i++) {
if (!gzget()) {
Player *d = getclient(i);
assert(d);
gzread(f, data.mutableItems, data.count);
[d setFromSerializedData:data];
[d setFromSerializedData: data];
}
}
conoutf(@"savegame restored");
if (demoloading)
startdemo();
else
stop();
}
// demo functions
int starttime = 0;
int playbacktime = 0;
int ddamage, bdamage;
OFVector3D dorig;
COMMAND(record, ARG_1STR, (^(OFString *name) {
COMMAND(record, ARG_1STR, (^ (OFString *name) {
if (m_sp) {
conoutf(@"cannot record singleplayer games");
return;
}
int cn = getclientnum();
if (cn < 0)
return;
OFString *path = [OFString stringWithFormat:@"demos/%@.cdgz", name];
OFIRI *IRI =
[Cube.sharedInstance.userDataIRI IRIByAppendingPathComponent:path];
OFString *path = [OFString stringWithFormat: @"demos/%@.cdgz", name];
OFIRI *IRI = [Cube.sharedInstance.userDataIRI
IRIByAppendingPathComponent: path];
savestate(IRI);
gzputi(cn);
conoutf(@"started recording demo to %@", IRI.string);
demorecording = true;
starttime = lastmillis;
ddamage = bdamage = 0;
}))
|
︙ | | |
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
|
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
|
-
-
-
-
+
+
+
+
|
ddamage = 0;
}
// FIXME: add all other client state which is not send through
// the network
}
}
COMMAND(demo, ARG_1STR, (^(OFString *name) {
OFString *path = [OFString stringWithFormat:@"demos/%@.cdgz", name];
OFIRI *IRI =
[Cube.sharedInstance.userDataIRI IRIByAppendingPathComponent:path];
COMMAND(demo, ARG_1STR, (^ (OFString *name) {
OFString *path = [OFString stringWithFormat: @"demos/%@.cdgz", name];
OFIRI *IRI = [Cube.sharedInstance.userDataIRI
IRIByAppendingPathComponent: path];
loadstate(IRI);
demoloading = true;
}))
void
stopreset()
{
|
︙ | | |
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
|
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
|
-
+
-
+
|
playerhistory.lastObject.lastUpdate != playbacktime)) {
Player *d = [target copy];
d.lastUpdate = playbacktime;
if (playerhistory == nil)
playerhistory = [[OFMutableArray alloc] init];
[playerhistory addObject:d];
[playerhistory addObject: d];
if (playerhistory.count > 20)
[playerhistory removeObjectAtIndex:0];
[playerhistory removeObjectAtIndex: 0];
}
readdemotime();
}
if (!demoplayback)
return;
|
︙ | | |
538
539
540
541
542
543
544
545
546
547
548
549
550
551
|
538
539
540
541
542
543
544
545
546
547
548
549
550
551
|
-
+
|
}
break;
}
}
// if(player1->state!=CS_DEAD) showscores(false);
}
COMMAND(stop, ARG_NONE, ^{
COMMAND(stop, ARG_NONE, ^ {
if (demoplayback)
stopreset();
else
stop();
conoutf(@"demo stopped");
})
|