g_save.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. /*
  2. Copyright (C) 1997-2001 Id Software, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #include "g_local.h"
  16. field_t fields[] = {
  17. {"classname", FOFS(classname), F_LSTRING},
  18. {"origin", FOFS(s.origin), F_VECTOR},
  19. {"model", FOFS(model), F_LSTRING},
  20. {"spawnflags", FOFS(spawnflags), F_INT},
  21. {"speed", FOFS(speed), F_FLOAT},
  22. {"accel", FOFS(accel), F_FLOAT},
  23. {"decel", FOFS(decel), F_FLOAT},
  24. {"target", FOFS(target), F_LSTRING},
  25. {"targetname", FOFS(targetname), F_LSTRING},
  26. {"pathtarget", FOFS(pathtarget), F_LSTRING},
  27. {"deathtarget", FOFS(deathtarget), F_LSTRING},
  28. {"killtarget", FOFS(killtarget), F_LSTRING},
  29. {"combattarget", FOFS(combattarget), F_LSTRING},
  30. {"message", FOFS(message), F_LSTRING},
  31. {"team", FOFS(team), F_LSTRING},
  32. {"wait", FOFS(wait), F_FLOAT},
  33. {"delay", FOFS(delay), F_FLOAT},
  34. {"random", FOFS(random), F_FLOAT},
  35. {"move_origin", FOFS(move_origin), F_VECTOR},
  36. {"move_angles", FOFS(move_angles), F_VECTOR},
  37. {"style", FOFS(style), F_INT},
  38. {"count", FOFS(count), F_INT},
  39. {"health", FOFS(health), F_INT},
  40. {"sounds", FOFS(sounds), F_INT},
  41. {"light", 0, F_IGNORE},
  42. {"dmg", FOFS(dmg), F_INT},
  43. {"angles", FOFS(s.angles), F_VECTOR},
  44. {"angle", FOFS(s.angles), F_ANGLEHACK},
  45. {"mass", FOFS(mass), F_INT},
  46. {"volume", FOFS(volume), F_FLOAT},
  47. {"attenuation", FOFS(attenuation), F_FLOAT},
  48. {"map", FOFS(map), F_LSTRING},
  49. // temp spawn vars -- only valid when the spawn function is called
  50. {"lip", STOFS(lip), F_INT, FFL_SPAWNTEMP},
  51. {"distance", STOFS(distance), F_INT, FFL_SPAWNTEMP},
  52. {"height", STOFS(height), F_INT, FFL_SPAWNTEMP},
  53. {"noise", STOFS(noise), F_LSTRING, FFL_SPAWNTEMP},
  54. {"pausetime", STOFS(pausetime), F_FLOAT, FFL_SPAWNTEMP},
  55. {"item", STOFS(item), F_LSTRING, FFL_SPAWNTEMP},
  56. {"gravity", STOFS(gravity), F_LSTRING, FFL_SPAWNTEMP},
  57. {"sky", STOFS(sky), F_LSTRING, FFL_SPAWNTEMP},
  58. {"skyrotate", STOFS(skyrotate), F_FLOAT, FFL_SPAWNTEMP},
  59. {"skyaxis", STOFS(skyaxis), F_VECTOR, FFL_SPAWNTEMP},
  60. {"minyaw", STOFS(minyaw), F_FLOAT, FFL_SPAWNTEMP},
  61. {"maxyaw", STOFS(maxyaw), F_FLOAT, FFL_SPAWNTEMP},
  62. {"minpitch", STOFS(minpitch), F_FLOAT, FFL_SPAWNTEMP},
  63. {"maxpitch", STOFS(maxpitch), F_FLOAT, FFL_SPAWNTEMP},
  64. {"nextmap", STOFS(nextmap), F_LSTRING, FFL_SPAWNTEMP}
  65. };
  66. // -------- just for savegames ----------
  67. // all pointer fields should be listed here, or savegames
  68. // won't work properly (they will crash and burn).
  69. // this wasn't just tacked on to the fields array, because
  70. // these don't need names, we wouldn't want map fields using
  71. // some of these, and if one were accidentally present twice
  72. // it would double swizzle (fuck) the pointer.
  73. field_t savefields[] =
  74. {
  75. {"", FOFS(classname), F_LSTRING},
  76. {"", FOFS(target), F_LSTRING},
  77. {"", FOFS(targetname), F_LSTRING},
  78. {"", FOFS(killtarget), F_LSTRING},
  79. {"", FOFS(team), F_LSTRING},
  80. {"", FOFS(pathtarget), F_LSTRING},
  81. {"", FOFS(deathtarget), F_LSTRING},
  82. {"", FOFS(combattarget), F_LSTRING},
  83. {"", FOFS(model), F_LSTRING},
  84. {"", FOFS(map), F_LSTRING},
  85. {"", FOFS(message), F_LSTRING},
  86. {"", FOFS(client), F_CLIENT},
  87. {"", FOFS(item), F_ITEM},
  88. {"", FOFS(goalentity), F_EDICT},
  89. {"", FOFS(movetarget), F_EDICT},
  90. {"", FOFS(enemy), F_EDICT},
  91. {"", FOFS(oldenemy), F_EDICT},
  92. {"", FOFS(activator), F_EDICT},
  93. {"", FOFS(groundentity), F_EDICT},
  94. {"", FOFS(teamchain), F_EDICT},
  95. {"", FOFS(teammaster), F_EDICT},
  96. {"", FOFS(owner), F_EDICT},
  97. {"", FOFS(mynoise), F_EDICT},
  98. {"", FOFS(mynoise2), F_EDICT},
  99. {"", FOFS(target_ent), F_EDICT},
  100. {"", FOFS(chain), F_EDICT},
  101. {NULL, 0, F_INT}
  102. };
  103. field_t levelfields[] =
  104. {
  105. {"", LLOFS(changemap), F_LSTRING},
  106. {"", LLOFS(sight_client), F_EDICT},
  107. {"", LLOFS(sight_entity), F_EDICT},
  108. {"", LLOFS(sound_entity), F_EDICT},
  109. {"", LLOFS(sound2_entity), F_EDICT},
  110. {NULL, 0, F_INT}
  111. };
  112. field_t clientfields[] =
  113. {
  114. {"", CLOFS(pers.weapon), F_ITEM},
  115. {"", CLOFS(pers.lastweapon), F_ITEM},
  116. {"", CLOFS(newweapon), F_ITEM},
  117. {NULL, 0, F_INT}
  118. };
  119. /*
  120. ============
  121. InitGame
  122. This will be called when the dll is first loaded, which
  123. only happens when a new game is started or a save game
  124. is loaded.
  125. ============
  126. */
  127. void InitGame (void)
  128. {
  129. gi.dprintf ("==== InitGame ====\n");
  130. gun_x = gi.cvar ("gun_x", "0", 0);
  131. gun_y = gi.cvar ("gun_y", "0", 0);
  132. gun_z = gi.cvar ("gun_z", "0", 0);
  133. //FIXME: sv_ prefix is wrong for these
  134. sv_rollspeed = gi.cvar ("sv_rollspeed", "200", 0);
  135. sv_rollangle = gi.cvar ("sv_rollangle", "2", 0);
  136. sv_maxvelocity = gi.cvar ("sv_maxvelocity", "2000", 0);
  137. sv_gravity = gi.cvar ("sv_gravity", "800", 0);
  138. // noset vars
  139. dedicated = gi.cvar ("dedicated", "0", CVAR_NOSET);
  140. // latched vars
  141. sv_cheats = gi.cvar ("cheats", "0", CVAR_SERVERINFO|CVAR_LATCH);
  142. gi.cvar ("gamename", GAMEVERSION , CVAR_SERVERINFO | CVAR_LATCH);
  143. gi.cvar ("gamedate", __DATE__ , CVAR_SERVERINFO | CVAR_LATCH);
  144. maxclients = gi.cvar ("maxclients", "4", CVAR_SERVERINFO | CVAR_LATCH);
  145. deathmatch = gi.cvar ("deathmatch", "0", CVAR_LATCH);
  146. coop = gi.cvar ("coop", "0", CVAR_LATCH);
  147. skill = gi.cvar ("skill", "1", CVAR_LATCH);
  148. maxentities = gi.cvar ("maxentities", "1024", CVAR_LATCH);
  149. //ZOID
  150. //This game.dll only supports deathmatch
  151. if (!deathmatch->value) {
  152. gi.dprintf("Forcing deathmatch.");
  153. gi.cvar_set("deathmatch", "1");
  154. }
  155. //force coop off
  156. if (coop->value)
  157. gi.cvar_set("coop", "0");
  158. //ZOID
  159. // change anytime vars
  160. dmflags = gi.cvar ("dmflags", "0", CVAR_SERVERINFO);
  161. fraglimit = gi.cvar ("fraglimit", "0", CVAR_SERVERINFO);
  162. timelimit = gi.cvar ("timelimit", "0", CVAR_SERVERINFO);
  163. //ZOID
  164. capturelimit = gi.cvar ("capturelimit", "0", CVAR_SERVERINFO);
  165. instantweap = gi.cvar ("instantweap", "0", CVAR_SERVERINFO);
  166. //ZOID
  167. password = gi.cvar ("password", "", CVAR_USERINFO);
  168. filterban = gi.cvar ("filterban", "1", 0);
  169. g_select_empty = gi.cvar ("g_select_empty", "0", CVAR_ARCHIVE);
  170. run_pitch = gi.cvar ("run_pitch", "0.002", 0);
  171. run_roll = gi.cvar ("run_roll", "0.005", 0);
  172. bob_up = gi.cvar ("bob_up", "0.005", 0);
  173. bob_pitch = gi.cvar ("bob_pitch", "0.002", 0);
  174. bob_roll = gi.cvar ("bob_roll", "0.002", 0);
  175. // flood control
  176. flood_msgs = gi.cvar ("flood_msgs", "4", 0);
  177. flood_persecond = gi.cvar ("flood_persecond", "4", 0);
  178. flood_waitdelay = gi.cvar ("flood_waitdelay", "10", 0);
  179. // dm map list
  180. sv_maplist = gi.cvar ("sv_maplist", "", 0);
  181. // items
  182. InitItems ();
  183. Com_sprintf (game.helpmessage1, sizeof(game.helpmessage1), "");
  184. Com_sprintf (game.helpmessage2, sizeof(game.helpmessage2), "");
  185. // initialize all entities for this game
  186. game.maxentities = maxentities->value;
  187. g_edicts = gi.TagMalloc (game.maxentities * sizeof(g_edicts[0]), TAG_GAME);
  188. globals.edicts = g_edicts;
  189. globals.max_edicts = game.maxentities;
  190. // initialize all clients for this game
  191. game.maxclients = maxclients->value;
  192. game.clients = gi.TagMalloc (game.maxclients * sizeof(game.clients[0]), TAG_GAME);
  193. globals.num_edicts = game.maxclients+1;
  194. //ZOID
  195. CTFInit();
  196. //ZOID
  197. }
  198. //=========================================================
  199. void WriteField1 (FILE *f, field_t *field, byte *base)
  200. {
  201. void *p;
  202. int len;
  203. int index;
  204. p = (void *)(base + field->ofs);
  205. switch (field->type)
  206. {
  207. case F_INT:
  208. case F_FLOAT:
  209. case F_ANGLEHACK:
  210. case F_VECTOR:
  211. case F_IGNORE:
  212. break;
  213. case F_LSTRING:
  214. case F_GSTRING:
  215. if ( *(char **)p )
  216. len = strlen(*(char **)p) + 1;
  217. else
  218. len = 0;
  219. *(int *)p = len;
  220. break;
  221. case F_EDICT:
  222. if ( *(edict_t **)p == NULL)
  223. index = -1;
  224. else
  225. index = *(edict_t **)p - g_edicts;
  226. *(int *)p = index;
  227. break;
  228. case F_CLIENT:
  229. if ( *(gclient_t **)p == NULL)
  230. index = -1;
  231. else
  232. index = *(gclient_t **)p - game.clients;
  233. *(int *)p = index;
  234. break;
  235. case F_ITEM:
  236. if ( *(edict_t **)p == NULL)
  237. index = -1;
  238. else
  239. index = *(gitem_t **)p - itemlist;
  240. *(int *)p = index;
  241. break;
  242. default:
  243. gi.error ("WriteEdict: unknown field type");
  244. }
  245. }
  246. void WriteField2 (FILE *f, field_t *field, byte *base)
  247. {
  248. int len;
  249. void *p;
  250. p = (void *)(base + field->ofs);
  251. switch (field->type)
  252. {
  253. case F_LSTRING:
  254. case F_GSTRING:
  255. if ( *(char **)p )
  256. {
  257. len = strlen(*(char **)p) + 1;
  258. fwrite (*(char **)p, len, 1, f);
  259. }
  260. break;
  261. }
  262. }
  263. void ReadField (FILE *f, field_t *field, byte *base)
  264. {
  265. void *p;
  266. int len;
  267. int index;
  268. p = (void *)(base + field->ofs);
  269. switch (field->type)
  270. {
  271. case F_INT:
  272. case F_FLOAT:
  273. case F_ANGLEHACK:
  274. case F_VECTOR:
  275. case F_IGNORE:
  276. break;
  277. case F_LSTRING:
  278. len = *(int *)p;
  279. if (!len)
  280. *(char **)p = NULL;
  281. else
  282. {
  283. *(char **)p = gi.TagMalloc (len, TAG_LEVEL);
  284. fread (*(char **)p, len, 1, f);
  285. }
  286. break;
  287. case F_GSTRING:
  288. len = *(int *)p;
  289. if (!len)
  290. *(char **)p = NULL;
  291. else
  292. {
  293. *(char **)p = gi.TagMalloc (len, TAG_GAME);
  294. fread (*(char **)p, len, 1, f);
  295. }
  296. break;
  297. case F_EDICT:
  298. index = *(int *)p;
  299. if ( index == -1 )
  300. *(edict_t **)p = NULL;
  301. else
  302. *(edict_t **)p = &g_edicts[index];
  303. break;
  304. case F_CLIENT:
  305. index = *(int *)p;
  306. if ( index == -1 )
  307. *(gclient_t **)p = NULL;
  308. else
  309. *(gclient_t **)p = &game.clients[index];
  310. break;
  311. case F_ITEM:
  312. index = *(int *)p;
  313. if ( index == -1 )
  314. *(gitem_t **)p = NULL;
  315. else
  316. *(gitem_t **)p = &itemlist[index];
  317. break;
  318. default:
  319. gi.error ("ReadEdict: unknown field type");
  320. }
  321. }
  322. //=========================================================
  323. /*
  324. ==============
  325. WriteClient
  326. All pointer variables (except function pointers) must be handled specially.
  327. ==============
  328. */
  329. void WriteClient (FILE *f, gclient_t *client)
  330. {
  331. field_t *field;
  332. gclient_t temp;
  333. // all of the ints, floats, and vectors stay as they are
  334. temp = *client;
  335. // change the pointers to lengths or indexes
  336. for (field=clientfields ; field->name ; field++)
  337. {
  338. WriteField1 (f, field, (byte *)&temp);
  339. }
  340. // write the block
  341. fwrite (&temp, sizeof(temp), 1, f);
  342. // now write any allocated data following the edict
  343. for (field=clientfields ; field->name ; field++)
  344. {
  345. WriteField2 (f, field, (byte *)client);
  346. }
  347. }
  348. /*
  349. ==============
  350. ReadClient
  351. All pointer variables (except function pointers) must be handled specially.
  352. ==============
  353. */
  354. void ReadClient (FILE *f, gclient_t *client)
  355. {
  356. field_t *field;
  357. fread (client, sizeof(*client), 1, f);
  358. for (field=clientfields ; field->name ; field++)
  359. {
  360. ReadField (f, field, (byte *)client);
  361. }
  362. }
  363. /*
  364. ============
  365. WriteGame
  366. This will be called whenever the game goes to a new level,
  367. and when the user explicitly saves the game.
  368. Game information include cross level data, like multi level
  369. triggers, help computer info, and all client states.
  370. A single player death will automatically restore from the
  371. last save position.
  372. ============
  373. */
  374. void WriteGame (char *filename, qboolean autosave)
  375. {
  376. FILE *f;
  377. int i;
  378. char str[16];
  379. if (!autosave)
  380. SaveClientData ();
  381. f = fopen (filename, "wb");
  382. if (!f)
  383. gi.error ("Couldn't open %s", filename);
  384. memset (str, 0, sizeof(str));
  385. strcpy (str, __DATE__);
  386. fwrite (str, sizeof(str), 1, f);
  387. game.autosaved = autosave;
  388. fwrite (&game, sizeof(game), 1, f);
  389. game.autosaved = false;
  390. for (i=0 ; i<game.maxclients ; i++)
  391. WriteClient (f, &game.clients[i]);
  392. fclose (f);
  393. }
  394. void ReadGame (char *filename)
  395. {
  396. FILE *f;
  397. int i;
  398. char str[16];
  399. gi.FreeTags (TAG_GAME);
  400. f = fopen (filename, "rb");
  401. if (!f)
  402. gi.error ("Couldn't open %s", filename);
  403. fread (str, sizeof(str), 1, f);
  404. if (strcmp (str, __DATE__))
  405. {
  406. fclose (f);
  407. gi.error ("Savegame from an older version.\n");
  408. }
  409. g_edicts = gi.TagMalloc (game.maxentities * sizeof(g_edicts[0]), TAG_GAME);
  410. globals.edicts = g_edicts;
  411. fread (&game, sizeof(game), 1, f);
  412. game.clients = gi.TagMalloc (game.maxclients * sizeof(game.clients[0]), TAG_GAME);
  413. for (i=0 ; i<game.maxclients ; i++)
  414. ReadClient (f, &game.clients[i]);
  415. fclose (f);
  416. }
  417. //==========================================================
  418. /*
  419. ==============
  420. WriteEdict
  421. All pointer variables (except function pointers) must be handled specially.
  422. ==============
  423. */
  424. void WriteEdict (FILE *f, edict_t *ent)
  425. {
  426. field_t *field;
  427. edict_t temp;
  428. // all of the ints, floats, and vectors stay as they are
  429. temp = *ent;
  430. // change the pointers to lengths or indexes
  431. for (field=savefields ; field->name ; field++)
  432. {
  433. WriteField1 (f, field, (byte *)&temp);
  434. }
  435. // write the block
  436. fwrite (&temp, sizeof(temp), 1, f);
  437. // now write any allocated data following the edict
  438. for (field=savefields ; field->name ; field++)
  439. {
  440. WriteField2 (f, field, (byte *)ent);
  441. }
  442. }
  443. /*
  444. ==============
  445. WriteLevelLocals
  446. All pointer variables (except function pointers) must be handled specially.
  447. ==============
  448. */
  449. void WriteLevelLocals (FILE *f)
  450. {
  451. field_t *field;
  452. level_locals_t temp;
  453. // all of the ints, floats, and vectors stay as they are
  454. temp = level;
  455. // change the pointers to lengths or indexes
  456. for (field=levelfields ; field->name ; field++)
  457. {
  458. WriteField1 (f, field, (byte *)&temp);
  459. }
  460. // write the block
  461. fwrite (&temp, sizeof(temp), 1, f);
  462. // now write any allocated data following the edict
  463. for (field=levelfields ; field->name ; field++)
  464. {
  465. WriteField2 (f, field, (byte *)&level);
  466. }
  467. }
  468. /*
  469. ==============
  470. ReadEdict
  471. All pointer variables (except function pointers) must be handled specially.
  472. ==============
  473. */
  474. void ReadEdict (FILE *f, edict_t *ent)
  475. {
  476. field_t *field;
  477. fread (ent, sizeof(*ent), 1, f);
  478. for (field=savefields ; field->name ; field++)
  479. {
  480. ReadField (f, field, (byte *)ent);
  481. }
  482. }
  483. /*
  484. ==============
  485. ReadLevelLocals
  486. All pointer variables (except function pointers) must be handled specially.
  487. ==============
  488. */
  489. void ReadLevelLocals (FILE *f)
  490. {
  491. field_t *field;
  492. fread (&level, sizeof(level), 1, f);
  493. for (field=levelfields ; field->name ; field++)
  494. {
  495. ReadField (f, field, (byte *)&level);
  496. }
  497. }
  498. /*
  499. =================
  500. WriteLevel
  501. =================
  502. */
  503. void WriteLevel (char *filename)
  504. {
  505. int i;
  506. edict_t *ent;
  507. FILE *f;
  508. void *base;
  509. f = fopen (filename, "wb");
  510. if (!f)
  511. gi.error ("Couldn't open %s", filename);
  512. // write out edict size for checking
  513. i = sizeof(edict_t);
  514. fwrite (&i, sizeof(i), 1, f);
  515. // write out a function pointer for checking
  516. base = (void *)InitGame;
  517. fwrite (&base, sizeof(base), 1, f);
  518. // write out level_locals_t
  519. WriteLevelLocals (f);
  520. // write out all the entities
  521. for (i=0 ; i<globals.num_edicts ; i++)
  522. {
  523. ent = &g_edicts[i];
  524. if (!ent->inuse)
  525. continue;
  526. fwrite (&i, sizeof(i), 1, f);
  527. WriteEdict (f, ent);
  528. }
  529. i = -1;
  530. fwrite (&i, sizeof(i), 1, f);
  531. fclose (f);
  532. }
  533. /*
  534. =================
  535. ReadLevel
  536. SpawnEntities will allready have been called on the
  537. level the same way it was when the level was saved.
  538. That is necessary to get the baselines
  539. set up identically.
  540. The server will have cleared all of the world links before
  541. calling ReadLevel.
  542. No clients are connected yet.
  543. =================
  544. */
  545. void ReadLevel (char *filename)
  546. {
  547. int entnum;
  548. FILE *f;
  549. int i;
  550. void *base;
  551. edict_t *ent;
  552. f = fopen (filename, "rb");
  553. if (!f)
  554. gi.error ("Couldn't open %s", filename);
  555. // free any dynamic memory allocated by loading the level
  556. // base state
  557. gi.FreeTags (TAG_LEVEL);
  558. // wipe all the entities
  559. memset (g_edicts, 0, game.maxentities*sizeof(g_edicts[0]));
  560. globals.num_edicts = maxclients->value+1;
  561. // check edict size
  562. fread (&i, sizeof(i), 1, f);
  563. if (i != sizeof(edict_t))
  564. {
  565. fclose (f);
  566. gi.error ("ReadLevel: mismatched edict size");
  567. }
  568. // check function pointer base address
  569. fread (&base, sizeof(base), 1, f);
  570. if (base != (void *)InitGame)
  571. {
  572. fclose (f);
  573. gi.error ("ReadLevel: function pointers have moved");
  574. }
  575. // load the level locals
  576. ReadLevelLocals (f);
  577. // load all the entities
  578. while (1)
  579. {
  580. if (fread (&entnum, sizeof(entnum), 1, f) != 1)
  581. {
  582. fclose (f);
  583. gi.error ("ReadLevel: failed to read entnum");
  584. }
  585. if (entnum == -1)
  586. break;
  587. if (entnum >= globals.num_edicts)
  588. globals.num_edicts = entnum+1;
  589. ent = &g_edicts[entnum];
  590. ReadEdict (f, ent);
  591. // let the server rebuild world links for this ent
  592. memset (&ent->area, 0, sizeof(ent->area));
  593. gi.linkentity (ent);
  594. }
  595. fclose (f);
  596. // mark all clients as unconnected
  597. for (i=0 ; i<maxclients->value ; i++)
  598. {
  599. ent = &g_edicts[i+1];
  600. ent->client = game.clients + i;
  601. ent->client->pers.connected = false;
  602. }
  603. // do any load time things at this point
  604. for (i=0 ; i<globals.num_edicts ; i++)
  605. {
  606. ent = &g_edicts[i];
  607. if (!ent->inuse)
  608. continue;
  609. // fire any cross-level triggers
  610. if (ent->classname)
  611. if (strcmp(ent->classname, "target_crosslevel_target") == 0)
  612. ent->nextthink = level.time + ent->delay;
  613. }
  614. }