g_spawn.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985
  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. typedef struct
  17. {
  18. char *name;
  19. void (*spawn)(edict_t *ent);
  20. } spawn_t;
  21. void SP_item_health (edict_t *self);
  22. void SP_item_health_small (edict_t *self);
  23. void SP_item_health_large (edict_t *self);
  24. void SP_item_health_mega (edict_t *self);
  25. void SP_info_player_start (edict_t *ent);
  26. void SP_info_player_deathmatch (edict_t *ent);
  27. void SP_info_player_coop (edict_t *ent);
  28. void SP_info_player_intermission (edict_t *ent);
  29. void SP_func_plat (edict_t *ent);
  30. void SP_func_rotating (edict_t *ent);
  31. void SP_func_button (edict_t *ent);
  32. void SP_func_door (edict_t *ent);
  33. void SP_func_door_secret (edict_t *ent);
  34. void SP_func_door_rotating (edict_t *ent);
  35. void SP_func_water (edict_t *ent);
  36. void SP_func_train (edict_t *ent);
  37. void SP_func_conveyor (edict_t *self);
  38. void SP_func_wall (edict_t *self);
  39. void SP_func_object (edict_t *self);
  40. void SP_func_explosive (edict_t *self);
  41. void SP_func_timer (edict_t *self);
  42. void SP_func_areaportal (edict_t *ent);
  43. void SP_func_clock (edict_t *ent);
  44. void SP_func_killbox (edict_t *ent);
  45. void SP_trigger_always (edict_t *ent);
  46. void SP_trigger_once (edict_t *ent);
  47. void SP_trigger_multiple (edict_t *ent);
  48. void SP_trigger_relay (edict_t *ent);
  49. void SP_trigger_push (edict_t *ent);
  50. void SP_trigger_hurt (edict_t *ent);
  51. void SP_trigger_key (edict_t *ent);
  52. void SP_trigger_counter (edict_t *ent);
  53. void SP_trigger_elevator (edict_t *ent);
  54. void SP_trigger_gravity (edict_t *ent);
  55. void SP_trigger_monsterjump (edict_t *ent);
  56. void SP_target_temp_entity (edict_t *ent);
  57. void SP_target_speaker (edict_t *ent);
  58. void SP_target_explosion (edict_t *ent);
  59. void SP_target_changelevel (edict_t *ent);
  60. void SP_target_secret (edict_t *ent);
  61. void SP_target_goal (edict_t *ent);
  62. void SP_target_splash (edict_t *ent);
  63. void SP_target_spawner (edict_t *ent);
  64. void SP_target_blaster (edict_t *ent);
  65. void SP_target_crosslevel_trigger (edict_t *ent);
  66. void SP_target_crosslevel_target (edict_t *ent);
  67. void SP_target_laser (edict_t *self);
  68. void SP_target_help (edict_t *ent);
  69. void SP_target_actor (edict_t *ent);
  70. void SP_target_lightramp (edict_t *self);
  71. void SP_target_earthquake (edict_t *ent);
  72. void SP_target_character (edict_t *ent);
  73. void SP_target_string (edict_t *ent);
  74. void SP_worldspawn (edict_t *ent);
  75. void SP_viewthing (edict_t *ent);
  76. void SP_light (edict_t *self);
  77. void SP_light_mine1 (edict_t *ent);
  78. void SP_light_mine2 (edict_t *ent);
  79. void SP_info_null (edict_t *self);
  80. void SP_info_notnull (edict_t *self);
  81. void SP_path_corner (edict_t *self);
  82. void SP_point_combat (edict_t *self);
  83. void SP_misc_explobox (edict_t *self);
  84. void SP_misc_banner (edict_t *self);
  85. void SP_misc_satellite_dish (edict_t *self);
  86. void SP_misc_actor (edict_t *self);
  87. void SP_misc_gib_arm (edict_t *self);
  88. void SP_misc_gib_leg (edict_t *self);
  89. void SP_misc_gib_head (edict_t *self);
  90. void SP_misc_insane (edict_t *self);
  91. void SP_misc_deadsoldier (edict_t *self);
  92. void SP_misc_viper (edict_t *self);
  93. void SP_misc_viper_bomb (edict_t *self);
  94. void SP_misc_bigviper (edict_t *self);
  95. void SP_misc_strogg_ship (edict_t *self);
  96. void SP_misc_teleporter (edict_t *self);
  97. void SP_misc_teleporter_dest (edict_t *self);
  98. void SP_misc_blackhole (edict_t *self);
  99. void SP_misc_eastertank (edict_t *self);
  100. void SP_misc_easterchick (edict_t *self);
  101. void SP_misc_easterchick2 (edict_t *self);
  102. void SP_monster_berserk (edict_t *self);
  103. void SP_monster_gladiator (edict_t *self);
  104. void SP_monster_gunner (edict_t *self);
  105. void SP_monster_infantry (edict_t *self);
  106. void SP_monster_soldier_light (edict_t *self);
  107. void SP_monster_soldier (edict_t *self);
  108. void SP_monster_soldier_ss (edict_t *self);
  109. void SP_monster_tank (edict_t *self);
  110. void SP_monster_medic (edict_t *self);
  111. void SP_monster_flipper (edict_t *self);
  112. void SP_monster_chick (edict_t *self);
  113. void SP_monster_parasite (edict_t *self);
  114. void SP_monster_flyer (edict_t *self);
  115. void SP_monster_brain (edict_t *self);
  116. void SP_monster_floater (edict_t *self);
  117. void SP_monster_hover (edict_t *self);
  118. void SP_monster_mutant (edict_t *self);
  119. void SP_monster_supertank (edict_t *self);
  120. void SP_monster_boss2 (edict_t *self);
  121. void SP_monster_jorg (edict_t *self);
  122. void SP_monster_boss3_stand (edict_t *self);
  123. void SP_monster_commander_body (edict_t *self);
  124. void SP_turret_breach (edict_t *self);
  125. void SP_turret_base (edict_t *self);
  126. void SP_turret_driver (edict_t *self);
  127. spawn_t spawns[] = {
  128. {"item_health", SP_item_health},
  129. {"item_health_small", SP_item_health_small},
  130. {"item_health_large", SP_item_health_large},
  131. {"item_health_mega", SP_item_health_mega},
  132. {"info_player_start", SP_info_player_start},
  133. {"info_player_deathmatch", SP_info_player_deathmatch},
  134. {"info_player_coop", SP_info_player_coop},
  135. {"info_player_intermission", SP_info_player_intermission},
  136. {"func_plat", SP_func_plat},
  137. {"func_button", SP_func_button},
  138. {"func_door", SP_func_door},
  139. {"func_door_secret", SP_func_door_secret},
  140. {"func_door_rotating", SP_func_door_rotating},
  141. {"func_rotating", SP_func_rotating},
  142. {"func_train", SP_func_train},
  143. {"func_water", SP_func_water},
  144. {"func_conveyor", SP_func_conveyor},
  145. {"func_areaportal", SP_func_areaportal},
  146. {"func_clock", SP_func_clock},
  147. {"func_wall", SP_func_wall},
  148. {"func_object", SP_func_object},
  149. {"func_timer", SP_func_timer},
  150. {"func_explosive", SP_func_explosive},
  151. {"func_killbox", SP_func_killbox},
  152. {"trigger_always", SP_trigger_always},
  153. {"trigger_once", SP_trigger_once},
  154. {"trigger_multiple", SP_trigger_multiple},
  155. {"trigger_relay", SP_trigger_relay},
  156. {"trigger_push", SP_trigger_push},
  157. {"trigger_hurt", SP_trigger_hurt},
  158. {"trigger_key", SP_trigger_key},
  159. {"trigger_counter", SP_trigger_counter},
  160. {"trigger_elevator", SP_trigger_elevator},
  161. {"trigger_gravity", SP_trigger_gravity},
  162. {"trigger_monsterjump", SP_trigger_monsterjump},
  163. {"target_temp_entity", SP_target_temp_entity},
  164. {"target_speaker", SP_target_speaker},
  165. {"target_explosion", SP_target_explosion},
  166. {"target_changelevel", SP_target_changelevel},
  167. {"target_secret", SP_target_secret},
  168. {"target_goal", SP_target_goal},
  169. {"target_splash", SP_target_splash},
  170. {"target_spawner", SP_target_spawner},
  171. {"target_blaster", SP_target_blaster},
  172. {"target_crosslevel_trigger", SP_target_crosslevel_trigger},
  173. {"target_crosslevel_target", SP_target_crosslevel_target},
  174. {"target_laser", SP_target_laser},
  175. {"target_help", SP_target_help},
  176. {"target_actor", SP_target_actor},
  177. {"target_lightramp", SP_target_lightramp},
  178. {"target_earthquake", SP_target_earthquake},
  179. {"target_character", SP_target_character},
  180. {"target_string", SP_target_string},
  181. {"worldspawn", SP_worldspawn},
  182. {"viewthing", SP_viewthing},
  183. {"light", SP_light},
  184. {"light_mine1", SP_light_mine1},
  185. {"light_mine2", SP_light_mine2},
  186. {"info_null", SP_info_null},
  187. {"func_group", SP_info_null},
  188. {"info_notnull", SP_info_notnull},
  189. {"path_corner", SP_path_corner},
  190. {"point_combat", SP_point_combat},
  191. {"misc_explobox", SP_misc_explobox},
  192. {"misc_banner", SP_misc_banner},
  193. {"misc_satellite_dish", SP_misc_satellite_dish},
  194. {"misc_actor", SP_misc_actor},
  195. {"misc_gib_arm", SP_misc_gib_arm},
  196. {"misc_gib_leg", SP_misc_gib_leg},
  197. {"misc_gib_head", SP_misc_gib_head},
  198. {"misc_insane", SP_misc_insane},
  199. {"misc_deadsoldier", SP_misc_deadsoldier},
  200. {"misc_viper", SP_misc_viper},
  201. {"misc_viper_bomb", SP_misc_viper_bomb},
  202. {"misc_bigviper", SP_misc_bigviper},
  203. {"misc_strogg_ship", SP_misc_strogg_ship},
  204. {"misc_teleporter", SP_misc_teleporter},
  205. {"misc_teleporter_dest", SP_misc_teleporter_dest},
  206. {"misc_blackhole", SP_misc_blackhole},
  207. {"misc_eastertank", SP_misc_eastertank},
  208. {"misc_easterchick", SP_misc_easterchick},
  209. {"misc_easterchick2", SP_misc_easterchick2},
  210. {"monster_berserk", SP_monster_berserk},
  211. {"monster_gladiator", SP_monster_gladiator},
  212. {"monster_gunner", SP_monster_gunner},
  213. {"monster_infantry", SP_monster_infantry},
  214. {"monster_soldier_light", SP_monster_soldier_light},
  215. {"monster_soldier", SP_monster_soldier},
  216. {"monster_soldier_ss", SP_monster_soldier_ss},
  217. {"monster_tank", SP_monster_tank},
  218. {"monster_tank_commander", SP_monster_tank},
  219. {"monster_medic", SP_monster_medic},
  220. {"monster_flipper", SP_monster_flipper},
  221. {"monster_chick", SP_monster_chick},
  222. {"monster_parasite", SP_monster_parasite},
  223. {"monster_flyer", SP_monster_flyer},
  224. {"monster_brain", SP_monster_brain},
  225. {"monster_floater", SP_monster_floater},
  226. {"monster_hover", SP_monster_hover},
  227. {"monster_mutant", SP_monster_mutant},
  228. {"monster_supertank", SP_monster_supertank},
  229. {"monster_boss2", SP_monster_boss2},
  230. {"monster_boss3_stand", SP_monster_boss3_stand},
  231. {"monster_jorg", SP_monster_jorg},
  232. {"monster_commander_body", SP_monster_commander_body},
  233. {"turret_breach", SP_turret_breach},
  234. {"turret_base", SP_turret_base},
  235. {"turret_driver", SP_turret_driver},
  236. {NULL, NULL}
  237. };
  238. /*
  239. ===============
  240. ED_CallSpawn
  241. Finds the spawn function for the entity and calls it
  242. ===============
  243. */
  244. void ED_CallSpawn (edict_t *ent)
  245. {
  246. spawn_t *s;
  247. gitem_t *item;
  248. int i;
  249. if (!ent->classname)
  250. {
  251. gi.dprintf ("ED_CallSpawn: NULL classname\n");
  252. return;
  253. }
  254. // check item spawn functions
  255. for (i=0,item=itemlist ; i<game.num_items ; i++,item++)
  256. {
  257. if (!item->classname)
  258. continue;
  259. if (!strcmp(item->classname, ent->classname))
  260. { // found it
  261. SpawnItem (ent, item);
  262. return;
  263. }
  264. }
  265. // check normal spawn functions
  266. for (s=spawns ; s->name ; s++)
  267. {
  268. if (!strcmp(s->name, ent->classname))
  269. { // found it
  270. s->spawn (ent);
  271. return;
  272. }
  273. }
  274. gi.dprintf ("%s doesn't have a spawn function\n", ent->classname);
  275. }
  276. /*
  277. =============
  278. ED_NewString
  279. =============
  280. */
  281. char *ED_NewString (char *string)
  282. {
  283. char *newb, *new_p;
  284. int i,l;
  285. l = strlen(string) + 1;
  286. newb = gi.TagMalloc (l, TAG_LEVEL);
  287. new_p = newb;
  288. for (i=0 ; i< l ; i++)
  289. {
  290. if (string[i] == '\\' && i < l-1)
  291. {
  292. i++;
  293. if (string[i] == 'n')
  294. *new_p++ = '\n';
  295. else
  296. *new_p++ = '\\';
  297. }
  298. else
  299. *new_p++ = string[i];
  300. }
  301. return newb;
  302. }
  303. /*
  304. ===============
  305. ED_ParseField
  306. Takes a key/value pair and sets the binary values
  307. in an edict
  308. ===============
  309. */
  310. void ED_ParseField (char *key, char *value, edict_t *ent)
  311. {
  312. field_t *f;
  313. byte *b;
  314. float v;
  315. vec3_t vec;
  316. for (f=fields ; f->name ; f++)
  317. {
  318. if (!(f->flags & FFL_NOSPAWN) && !Q_stricmp(f->name, key))
  319. { // found it
  320. if (f->flags & FFL_SPAWNTEMP)
  321. b = (byte *)&st;
  322. else
  323. b = (byte *)ent;
  324. switch (f->type)
  325. {
  326. case F_LSTRING:
  327. *(char **)(b+f->ofs) = ED_NewString (value);
  328. break;
  329. case F_VECTOR:
  330. sscanf (value, "%f %f %f", &vec[0], &vec[1], &vec[2]);
  331. ((float *)(b+f->ofs))[0] = vec[0];
  332. ((float *)(b+f->ofs))[1] = vec[1];
  333. ((float *)(b+f->ofs))[2] = vec[2];
  334. break;
  335. case F_INT:
  336. *(int *)(b+f->ofs) = atoi(value);
  337. break;
  338. case F_FLOAT:
  339. *(float *)(b+f->ofs) = atof(value);
  340. break;
  341. case F_ANGLEHACK:
  342. v = atof(value);
  343. ((float *)(b+f->ofs))[0] = 0;
  344. ((float *)(b+f->ofs))[1] = v;
  345. ((float *)(b+f->ofs))[2] = 0;
  346. break;
  347. case F_IGNORE:
  348. break;
  349. }
  350. return;
  351. }
  352. }
  353. gi.dprintf ("%s is not a field\n", key);
  354. }
  355. /*
  356. ====================
  357. ED_ParseEdict
  358. Parses an edict out of the given string, returning the new position
  359. ed should be a properly initialized empty edict.
  360. ====================
  361. */
  362. char *ED_ParseEdict (char *data, edict_t *ent)
  363. {
  364. qboolean init;
  365. char keyname[256];
  366. char *com_token;
  367. init = false;
  368. memset (&st, 0, sizeof(st));
  369. // go through all the dictionary pairs
  370. while (1)
  371. {
  372. // parse key
  373. com_token = COM_Parse (&data);
  374. if (com_token[0] == '}')
  375. break;
  376. if (!data)
  377. gi.error ("ED_ParseEntity: EOF without closing brace");
  378. strncpy (keyname, com_token, sizeof(keyname)-1);
  379. // parse value
  380. com_token = COM_Parse (&data);
  381. if (!data)
  382. gi.error ("ED_ParseEntity: EOF without closing brace");
  383. if (com_token[0] == '}')
  384. gi.error ("ED_ParseEntity: closing brace without data");
  385. init = true;
  386. // keynames with a leading underscore are used for utility comments,
  387. // and are immediately discarded by quake
  388. if (keyname[0] == '_')
  389. continue;
  390. ED_ParseField (keyname, com_token, ent);
  391. }
  392. if (!init)
  393. memset (ent, 0, sizeof(*ent));
  394. return data;
  395. }
  396. /*
  397. ================
  398. G_FindTeams
  399. Chain together all entities with a matching team field.
  400. All but the first will have the FL_TEAMSLAVE flag set.
  401. All but the last will have the teamchain field set to the next one
  402. ================
  403. */
  404. void G_FindTeams (void)
  405. {
  406. edict_t *e, *e2, *chain;
  407. int i, j;
  408. int c, c2;
  409. c = 0;
  410. c2 = 0;
  411. for (i=1, e=g_edicts+i ; i < globals.num_edicts ; i++,e++)
  412. {
  413. if (!e->inuse)
  414. continue;
  415. if (!e->team)
  416. continue;
  417. if (e->flags & FL_TEAMSLAVE)
  418. continue;
  419. chain = e;
  420. e->teammaster = e;
  421. c++;
  422. c2++;
  423. for (j=i+1, e2=e+1 ; j < globals.num_edicts ; j++,e2++)
  424. {
  425. if (!e2->inuse)
  426. continue;
  427. if (!e2->team)
  428. continue;
  429. if (e2->flags & FL_TEAMSLAVE)
  430. continue;
  431. if (!strcmp(e->team, e2->team))
  432. {
  433. c2++;
  434. chain->teamchain = e2;
  435. e2->teammaster = e;
  436. chain = e2;
  437. e2->flags |= FL_TEAMSLAVE;
  438. }
  439. }
  440. }
  441. gi.dprintf ("%i teams with %i entities\n", c, c2);
  442. }
  443. /*
  444. ==============
  445. SpawnEntities
  446. Creates a server's entity / program execution context by
  447. parsing textual entity definitions out of an ent file.
  448. ==============
  449. */
  450. void SpawnEntities (char *mapname, char *entities, char *spawnpoint)
  451. {
  452. edict_t *ent;
  453. int inhibit;
  454. char *com_token;
  455. int i;
  456. float skill_level;
  457. skill_level = floor (skill->value);
  458. if (skill_level < 0)
  459. skill_level = 0;
  460. if (skill_level > 3)
  461. skill_level = 3;
  462. if (skill->value != skill_level)
  463. gi.cvar_forceset("skill", va("%f", skill_level));
  464. SaveClientData ();
  465. gi.FreeTags (TAG_LEVEL);
  466. memset (&level, 0, sizeof(level));
  467. memset (g_edicts, 0, game.maxentities * sizeof (g_edicts[0]));
  468. strncpy (level.mapname, mapname, sizeof(level.mapname)-1);
  469. strncpy (game.spawnpoint, spawnpoint, sizeof(game.spawnpoint)-1);
  470. // set client fields on player ents
  471. for (i=0 ; i<game.maxclients ; i++)
  472. g_edicts[i+1].client = game.clients + i;
  473. ent = NULL;
  474. inhibit = 0;
  475. // parse ents
  476. while (1)
  477. {
  478. // parse the opening brace
  479. com_token = COM_Parse (&entities);
  480. if (!entities)
  481. break;
  482. if (com_token[0] != '{')
  483. gi.error ("ED_LoadFromFile: found %s when expecting {",com_token);
  484. if (!ent)
  485. ent = g_edicts;
  486. else
  487. ent = G_Spawn ();
  488. entities = ED_ParseEdict (entities, ent);
  489. // yet another map hack
  490. if (!Q_stricmp(level.mapname, "command") && !Q_stricmp(ent->classname, "trigger_once") && !Q_stricmp(ent->model, "*27"))
  491. ent->spawnflags &= ~SPAWNFLAG_NOT_HARD;
  492. // remove things (except the world) from different skill levels or deathmatch
  493. if (ent != g_edicts)
  494. {
  495. if (deathmatch->value)
  496. {
  497. if ( ent->spawnflags & SPAWNFLAG_NOT_DEATHMATCH )
  498. {
  499. G_FreeEdict (ent);
  500. inhibit++;
  501. continue;
  502. }
  503. }
  504. else
  505. {
  506. if ( /* ((coop->value) && (ent->spawnflags & SPAWNFLAG_NOT_COOP)) || */
  507. ((skill->value == 0) && (ent->spawnflags & SPAWNFLAG_NOT_EASY)) ||
  508. ((skill->value == 1) && (ent->spawnflags & SPAWNFLAG_NOT_MEDIUM)) ||
  509. (((skill->value == 2) || (skill->value == 3)) && (ent->spawnflags & SPAWNFLAG_NOT_HARD))
  510. )
  511. {
  512. G_FreeEdict (ent);
  513. inhibit++;
  514. continue;
  515. }
  516. }
  517. ent->spawnflags &= ~(SPAWNFLAG_NOT_EASY|SPAWNFLAG_NOT_MEDIUM|SPAWNFLAG_NOT_HARD|SPAWNFLAG_NOT_COOP|SPAWNFLAG_NOT_DEATHMATCH);
  518. }
  519. ED_CallSpawn (ent);
  520. }
  521. gi.dprintf ("%i entities inhibited\n", inhibit);
  522. #ifdef DEBUG
  523. i = 1;
  524. ent = EDICT_NUM(i);
  525. while (i < globals.num_edicts) {
  526. if (ent->inuse != 0 || ent->inuse != 1)
  527. Com_DPrintf("Invalid entity %d\n", i);
  528. i++, ent++;
  529. }
  530. #endif
  531. G_FindTeams ();
  532. PlayerTrail_Init ();
  533. }
  534. //===================================================================
  535. #if 0
  536. // cursor positioning
  537. xl <value>
  538. xr <value>
  539. yb <value>
  540. yt <value>
  541. xv <value>
  542. yv <value>
  543. // drawing
  544. statpic <name>
  545. pic <stat>
  546. num <fieldwidth> <stat>
  547. string <stat>
  548. // control
  549. if <stat>
  550. ifeq <stat> <value>
  551. ifbit <stat> <value>
  552. endif
  553. #endif
  554. char *single_statusbar =
  555. "yb -24 "
  556. // health
  557. "xv 0 "
  558. "hnum "
  559. "xv 50 "
  560. "pic 0 "
  561. // ammo
  562. "if 2 "
  563. " xv 100 "
  564. " anum "
  565. " xv 150 "
  566. " pic 2 "
  567. "endif "
  568. // armor
  569. "if 4 "
  570. " xv 200 "
  571. " rnum "
  572. " xv 250 "
  573. " pic 4 "
  574. "endif "
  575. // selected item
  576. "if 6 "
  577. " xv 296 "
  578. " pic 6 "
  579. "endif "
  580. "yb -50 "
  581. // picked up item
  582. "if 7 "
  583. " xv 0 "
  584. " pic 7 "
  585. " xv 26 "
  586. " yb -42 "
  587. " stat_string 8 "
  588. " yb -50 "
  589. "endif "
  590. // timer
  591. "if 9 "
  592. " xv 262 "
  593. " num 2 10 "
  594. " xv 296 "
  595. " pic 9 "
  596. "endif "
  597. // help / weapon icon
  598. "if 11 "
  599. " xv 148 "
  600. " pic 11 "
  601. "endif "
  602. ;
  603. char *dm_statusbar =
  604. "yb -24 "
  605. // health
  606. "xv 0 "
  607. "hnum "
  608. "xv 50 "
  609. "pic 0 "
  610. // ammo
  611. "if 2 "
  612. " xv 100 "
  613. " anum "
  614. " xv 150 "
  615. " pic 2 "
  616. "endif "
  617. // armor
  618. "if 4 "
  619. " xv 200 "
  620. " rnum "
  621. " xv 250 "
  622. " pic 4 "
  623. "endif "
  624. // selected item
  625. "if 6 "
  626. " xv 296 "
  627. " pic 6 "
  628. "endif "
  629. "yb -50 "
  630. // picked up item
  631. "if 7 "
  632. " xv 0 "
  633. " pic 7 "
  634. " xv 26 "
  635. " yb -42 "
  636. " stat_string 8 "
  637. " yb -50 "
  638. "endif "
  639. // timer
  640. "if 9 "
  641. " xv 246 "
  642. " num 2 10 "
  643. " xv 296 "
  644. " pic 9 "
  645. "endif "
  646. // help / weapon icon
  647. "if 11 "
  648. " xv 148 "
  649. " pic 11 "
  650. "endif "
  651. // frags
  652. "xr -50 "
  653. "yt 2 "
  654. "num 3 14 "
  655. // spectator
  656. "if 17 "
  657. "xv 0 "
  658. "yb -58 "
  659. "string2 \"SPECTATOR MODE\" "
  660. "endif "
  661. // chase camera
  662. "if 16 "
  663. "xv 0 "
  664. "yb -68 "
  665. "string \"Chasing\" "
  666. "xv 64 "
  667. "stat_string 16 "
  668. "endif "
  669. ;
  670. /*QUAKED worldspawn (0 0 0) ?
  671. Only used for the world.
  672. "sky" environment map name
  673. "skyaxis" vector axis for rotating sky
  674. "skyrotate" speed of rotation in degrees/second
  675. "sounds" music cd track number
  676. "gravity" 800 is default gravity
  677. "message" text to print at user logon
  678. */
  679. void SP_worldspawn (edict_t *ent)
  680. {
  681. ent->movetype = MOVETYPE_PUSH;
  682. ent->solid = SOLID_BSP;
  683. ent->inuse = true; // since the world doesn't use G_Spawn()
  684. ent->s.modelindex = 1; // world model is always index 1
  685. //---------------
  686. // reserve some spots for dead player bodies for coop / deathmatch
  687. InitBodyQue ();
  688. // set configstrings for items
  689. SetItemNames ();
  690. if (st.nextmap)
  691. strcpy (level.nextmap, st.nextmap);
  692. // make some data visible to the server
  693. if (ent->message && ent->message[0])
  694. {
  695. gi.configstring (CS_NAME, ent->message);
  696. strncpy (level.level_name, ent->message, sizeof(level.level_name));
  697. }
  698. else
  699. strncpy (level.level_name, level.mapname, sizeof(level.level_name));
  700. if (st.sky && st.sky[0])
  701. gi.configstring (CS_SKY, st.sky);
  702. else
  703. gi.configstring (CS_SKY, "unit1_");
  704. gi.configstring (CS_SKYROTATE, va("%f", st.skyrotate) );
  705. gi.configstring (CS_SKYAXIS, va("%f %f %f",
  706. st.skyaxis[0], st.skyaxis[1], st.skyaxis[2]) );
  707. gi.configstring (CS_CDTRACK, va("%i", ent->sounds) );
  708. gi.configstring (CS_MAXCLIENTS, va("%i", (int)(maxclients->value) ) );
  709. // status bar program
  710. if (deathmatch->value)
  711. gi.configstring (CS_STATUSBAR, dm_statusbar);
  712. else
  713. gi.configstring (CS_STATUSBAR, single_statusbar);
  714. //---------------
  715. // help icon for statusbar
  716. gi.imageindex ("i_help");
  717. level.pic_health = gi.imageindex ("i_health");
  718. gi.imageindex ("help");
  719. gi.imageindex ("field_3");
  720. if (!st.gravity)
  721. gi.cvar_set("sv_gravity", "800");
  722. else
  723. gi.cvar_set("sv_gravity", st.gravity);
  724. snd_fry = gi.soundindex ("player/fry.wav"); // standing in lava / slime
  725. PrecacheItem (FindItem ("Blaster"));
  726. gi.soundindex ("player/lava1.wav");
  727. gi.soundindex ("player/lava2.wav");
  728. gi.soundindex ("misc/pc_up.wav");
  729. gi.soundindex ("misc/talk1.wav");
  730. gi.soundindex ("misc/udeath.wav");
  731. // gibs
  732. gi.soundindex ("items/respawn1.wav");
  733. // sexed sounds
  734. gi.soundindex ("*death1.wav");
  735. gi.soundindex ("*death2.wav");
  736. gi.soundindex ("*death3.wav");
  737. gi.soundindex ("*death4.wav");
  738. gi.soundindex ("*fall1.wav");
  739. gi.soundindex ("*fall2.wav");
  740. gi.soundindex ("*gurp1.wav"); // drowning damage
  741. gi.soundindex ("*gurp2.wav");
  742. gi.soundindex ("*jump1.wav"); // player jump
  743. gi.soundindex ("*pain25_1.wav");
  744. gi.soundindex ("*pain25_2.wav");
  745. gi.soundindex ("*pain50_1.wav");
  746. gi.soundindex ("*pain50_2.wav");
  747. gi.soundindex ("*pain75_1.wav");
  748. gi.soundindex ("*pain75_2.wav");
  749. gi.soundindex ("*pain100_1.wav");
  750. gi.soundindex ("*pain100_2.wav");
  751. // sexed models
  752. // THIS ORDER MUST MATCH THE DEFINES IN g_local.h
  753. // you can add more, max 15
  754. gi.modelindex ("#w_blaster.md2");
  755. gi.modelindex ("#w_shotgun.md2");
  756. gi.modelindex ("#w_sshotgun.md2");
  757. gi.modelindex ("#w_machinegun.md2");
  758. gi.modelindex ("#w_chaingun.md2");
  759. gi.modelindex ("#a_grenades.md2");
  760. gi.modelindex ("#w_glauncher.md2");
  761. gi.modelindex ("#w_rlauncher.md2");
  762. gi.modelindex ("#w_hyperblaster.md2");
  763. gi.modelindex ("#w_railgun.md2");
  764. gi.modelindex ("#w_bfg.md2");
  765. //-------------------
  766. gi.soundindex ("player/gasp1.wav"); // gasping for air
  767. gi.soundindex ("player/gasp2.wav"); // head breaking surface, not gasping
  768. gi.soundindex ("player/watr_in.wav"); // feet hitting water
  769. gi.soundindex ("player/watr_out.wav"); // feet leaving water
  770. gi.soundindex ("player/watr_un.wav"); // head going underwater
  771. gi.soundindex ("player/u_breath1.wav");
  772. gi.soundindex ("player/u_breath2.wav");
  773. gi.soundindex ("items/pkup.wav"); // bonus item pickup
  774. gi.soundindex ("world/land.wav"); // landing thud
  775. gi.soundindex ("misc/h2ohit1.wav"); // landing splash
  776. gi.soundindex ("items/damage.wav");
  777. gi.soundindex ("items/protect.wav");
  778. gi.soundindex ("items/protect4.wav");
  779. gi.soundindex ("weapons/noammo.wav");
  780. gi.soundindex ("infantry/inflies1.wav");
  781. sm_meat_index = gi.modelindex ("models/objects/gibs/sm_meat/tris.md2");
  782. gi.modelindex ("models/objects/gibs/arm/tris.md2");
  783. gi.modelindex ("models/objects/gibs/bone/tris.md2");
  784. gi.modelindex ("models/objects/gibs/bone2/tris.md2");
  785. gi.modelindex ("models/objects/gibs/chest/tris.md2");
  786. gi.modelindex ("models/objects/gibs/skull/tris.md2");
  787. gi.modelindex ("models/objects/gibs/head2/tris.md2");
  788. //
  789. // Setup light animation tables. 'a' is total darkness, 'z' is doublebright.
  790. //
  791. // 0 normal
  792. gi.configstring(CS_LIGHTS+0, "m");
  793. // 1 FLICKER (first variety)
  794. gi.configstring(CS_LIGHTS+1, "mmnmmommommnonmmonqnmmo");
  795. // 2 SLOW STRONG PULSE
  796. gi.configstring(CS_LIGHTS+2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
  797. // 3 CANDLE (first variety)
  798. gi.configstring(CS_LIGHTS+3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
  799. // 4 FAST STROBE
  800. gi.configstring(CS_LIGHTS+4, "mamamamamama");
  801. // 5 GENTLE PULSE 1
  802. gi.configstring(CS_LIGHTS+5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
  803. // 6 FLICKER (second variety)
  804. gi.configstring(CS_LIGHTS+6, "nmonqnmomnmomomno");
  805. // 7 CANDLE (second variety)
  806. gi.configstring(CS_LIGHTS+7, "mmmaaaabcdefgmmmmaaaammmaamm");
  807. // 8 CANDLE (third variety)
  808. gi.configstring(CS_LIGHTS+8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
  809. // 9 SLOW STROBE (fourth variety)
  810. gi.configstring(CS_LIGHTS+9, "aaaaaaaazzzzzzzz");
  811. // 10 FLUORESCENT FLICKER
  812. gi.configstring(CS_LIGHTS+10, "mmamammmmammamamaaamammma");
  813. // 11 SLOW PULSE NOT FADE TO BLACK
  814. gi.configstring(CS_LIGHTS+11, "abcdefghijklmnopqrrqponmlkjihgfedcba");
  815. // styles 32-62 are assigned by the light program for switchable lights
  816. // 63 testing
  817. gi.configstring(CS_LIGHTS+63, "a");
  818. }