//dmsp2 declarations
entity lastmspawn;
float lasttime /* = 0.000 */;
float nspawned /* = 0.000 */;
float starttime /* = 0.000 */;
//end dmsp2

void () monsterspawner;



void () InitBodyQue;

void () main = {

   dprint ("main function\n");
   precache_file ("progs.dat");
   precache_file ("gfx.wad");
   precache_file ("quake.rc");
   precache_file ("default.cfg");
   precache_file ("end1.bin");
   precache_file2 ("end2.bin");
   precache_file ("demo1.dem");
   precache_file ("demo2.dem");
   precache_file ("demo3.dem");
   precache_file ("gfx/palette.lmp");
   precache_file ("gfx/colormap.lmp");
   precache_file2 ("gfx/pop.lmp");
   precache_file ("gfx/complete.lmp");
   precache_file ("gfx/inter.lmp");
   precache_file ("gfx/ranking.lmp");
   precache_file ("gfx/vidmodes.lmp");
   precache_file ("gfx/finale.lmp");
   precache_file ("gfx/conback.lmp");
   precache_file ("gfx/qplaque.lmp");
   precache_file ("gfx/menudot1.lmp");
   precache_file ("gfx/menudot2.lmp");
   precache_file ("gfx/menudot3.lmp");
   precache_file ("gfx/menudot4.lmp");
   precache_file ("gfx/menudot5.lmp");
   precache_file ("gfx/menudot6.lmp");
   precache_file ("gfx/menuplyr.lmp");
   precache_file ("gfx/bigbox.lmp");
   precache_file ("gfx/dim_modm.lmp");
   precache_file ("gfx/dim_drct.lmp");
   precache_file ("gfx/dim_ipx.lmp");
   precache_file ("gfx/dim_tcp.lmp");
   precache_file ("gfx/dim_mult.lmp");
   precache_file ("gfx/mainmenu.lmp");
   precache_file ("gfx/box_tl.lmp");
   precache_file ("gfx/box_tm.lmp");
   precache_file ("gfx/box_tr.lmp");
   precache_file ("gfx/box_ml.lmp");
   precache_file ("gfx/box_mm.lmp");
   precache_file ("gfx/box_mm2.lmp");
   precache_file ("gfx/box_mr.lmp");
   precache_file ("gfx/box_bl.lmp");
   precache_file ("gfx/box_bm.lmp");
   precache_file ("gfx/box_br.lmp");
   precache_file ("gfx/sp_menu.lmp");
   precache_file ("gfx/ttl_sgl.lmp");
   precache_file ("gfx/ttl_main.lmp");
   precache_file ("gfx/ttl_cstm.lmp");
   precache_file ("gfx/mp_menu.lmp");
   precache_file ("gfx/netmen1.lmp");
   precache_file ("gfx/netmen2.lmp");
   precache_file ("gfx/netmen3.lmp");
   precache_file ("gfx/netmen4.lmp");
   precache_file ("gfx/netmen5.lmp");
   precache_file ("gfx/sell.lmp");
   precache_file ("gfx/help0.lmp");
   precache_file ("gfx/help1.lmp");
   precache_file ("gfx/help2.lmp");
   precache_file ("gfx/help3.lmp");
   precache_file ("gfx/help4.lmp");
   precache_file ("gfx/help5.lmp");
   precache_file ("gfx/pause.lmp");
   precache_file ("gfx/loading.lmp");
   precache_file ("gfx/p_option.lmp");
   precache_file ("gfx/p_load.lmp");
   precache_file ("gfx/p_save.lmp");
   precache_file ("gfx/p_multi.lmp");
   precache_sound ("misc/menu1.wav");
   precache_sound ("misc/menu2.wav");
   precache_sound ("misc/menu3.wav");
   precache_sound ("ambience/water1.wav");
   precache_sound ("ambience/wind2.wav");
   precache_file ("maps/start.bsp");
   precache_file ("maps/e1m1.bsp");
   precache_file ("maps/e1m2.bsp");
   precache_file ("maps/e1m3.bsp");
   precache_file ("maps/e1m4.bsp");
   precache_file ("maps/e1m5.bsp");
   precache_file ("maps/e1m6.bsp");
   precache_file ("maps/e1m7.bsp");
   precache_file ("maps/e1m8.bsp");
   precache_file2 ("gfx/pop.lmp");
   precache_file2 ("maps/e2m1.bsp");
   precache_file2 ("maps/e2m2.bsp");
   precache_file2 ("maps/e2m3.bsp");
   precache_file2 ("maps/e2m4.bsp");
   precache_file2 ("maps/e2m5.bsp");
   precache_file2 ("maps/e2m6.bsp");
   precache_file2 ("maps/e2m7.bsp");
   precache_file2 ("maps/e3m1.bsp");
   precache_file2 ("maps/e3m2.bsp");
   precache_file2 ("maps/e3m3.bsp");
   precache_file2 ("maps/e3m4.bsp");
   precache_file2 ("maps/e3m5.bsp");
   precache_file2 ("maps/e3m6.bsp");
   precache_file2 ("maps/e3m7.bsp");
   precache_file2 ("maps/e4m1.bsp");
   precache_file2 ("maps/e4m2.bsp");
   precache_file2 ("maps/e4m3.bsp");
   precache_file2 ("maps/e4m4.bsp");
   precache_file2 ("maps/e4m5.bsp");
   precache_file2 ("maps/e4m6.bsp");
   precache_file2 ("maps/e4m7.bsp");
   precache_file2 ("maps/e4m8.bsp");
   precache_file2 ("maps/end.bsp");
   precache_file2 ("maps/dm1.bsp");
   precache_file2 ("maps/dm2.bsp");
   precache_file2 ("maps/dm3.bsp");
   precache_file2 ("maps/dm4.bsp");
   precache_file2 ("maps/dm5.bsp");
   precache_file2 ("maps/dm6.bsp");

};
entity lastspawn;

void () worldspawn = {

   lastspawn = world;

BotInit();  // FrikBot
   InitBodyQue ();
   if ( (self.model == "maps/e1m8.bsp") || (self.model == "maps/bondo8.bsp"))	//deathmatch 5 is low gravity!
      cvar_set ("sv_gravity","100");
   else
      cvar_set ("sv_gravity","800");

   W_Precache ();

//dmsp2 precache everything
   precache_sound ("demon/dland2.wav");
   precache_sound ("misc/h2ohit1.wav");
   precache_sound ("items/itembk2.wav");
   precache_sound ("player/plyrjmp8.wav");
   precache_sound ("player/land.wav");
   precache_sound ("player/land2.wav");
   precache_sound ("player/drown1.wav");
   precache_sound ("player/drown2.wav");
   precache_sound ("player/gasp1.wav");
   precache_sound ("player/gasp2.wav");
   precache_sound ("player/h2odeath.wav");
   precache_sound ("misc/talk.wav");
   precache_sound ("player/teledth1.wav");
   precache_sound ("misc/r_tele1.wav");
   precache_sound ("misc/r_tele2.wav");
   precache_sound ("misc/r_tele3.wav");
   precache_sound ("misc/r_tele4.wav");
   precache_sound ("misc/r_tele5.wav");
   precache_sound ("weapons/lock4.wav");
   precache_sound ("weapons/pkup.wav");
   precache_sound ("items/armor1.wav");
   precache_sound ("weapons/lhit.wav");
   precache_sound ("weapons/lstart.wav");
   precache_sound ("items/damage3.wav");
   precache_sound ("misc/power.wav");
   precache_sound ("player/gib.wav");
   precache_sound ("player/udeath.wav");
   precache_sound ("player/tornoff2.wav");
   precache_sound ("player/pain1.wav");
   precache_sound ("player/pain2.wav");
   precache_sound ("player/pain3.wav");
   precache_sound ("player/pain4.wav");
   precache_sound ("player/pain5.wav");
   precache_sound ("player/pain6.wav");
   precache_sound ("player/death1.wav");
   precache_sound ("player/death2.wav");
   precache_sound ("player/death3.wav");
   precache_sound ("player/death4.wav");
   precache_sound ("player/death5.wav");
   precache_sound ("weapons/ax1.wav");
   precache_sound ("player/axhit1.wav");
   precache_sound ("player/axhit2.wav");
   precache_sound ("player/h2ojump.wav");
   precache_sound ("player/slimbrn2.wav");
   precache_sound ("player/inh2o.wav");
   precache_sound ("player/inlava.wav");
   precache_sound ("misc/outwater.wav");
   precache_sound ("player/lburn1.wav");
   precache_sound ("player/lburn2.wav");
   precache_sound ("misc/water1.wav");
   precache_sound ("misc/water2.wav");
   precache_model ("progs/player.mdl");
   precache_model ("progs/eyes.mdl");
   precache_model ("progs/h_player.mdl");
   precache_model ("progs/gib1.mdl");
   precache_model ("progs/gib2.mdl");
   precache_model ("progs/gib3.mdl");
   precache_model ("progs/s_bubble.spr");
   precache_model ("progs/s_explod.spr");
   precache_model ("progs/v_axe.mdl");
   precache_model ("progs/v_shot.mdl");
   precache_model ("progs/v_nail.mdl");
   precache_model ("progs/v_rock.mdl");
   precache_model ("progs/v_shot2.mdl");
   precache_model ("progs/v_nail2.mdl");
   precache_model ("progs/v_rock2.mdl");
   precache_model ("progs/bolt.mdl");
   precache_model ("progs/bolt2.mdl");
   precache_model ("progs/bolt3.mdl");
   precache_model ("progs/lavaball.mdl");
   precache_model ("progs/missile.mdl");
   precache_model ("progs/grenade.mdl");
   precache_model ("progs/spike.mdl");
   precache_model ("progs/s_spike.mdl");
   precache_model ("progs/backpack.mdl");
   precache_model ("progs/zom_gib.mdl");
   precache_model ("progs/v_light.mdl");

   precache_model ("progs/soldier.mdl");
   precache_model ("progs/h_guard.mdl");
   precache_model ("progs/gib1.mdl");
   precache_model ("progs/gib2.mdl");
   precache_model ("progs/gib3.mdl");
   precache_sound ("soldier/death1.wav");
   precache_sound ("soldier/idle.wav");
   precache_sound ("soldier/pain1.wav");
   precache_sound ("soldier/pain2.wav");
   precache_sound ("soldier/sattck1.wav");
   precache_sound ("soldier/sight1.wav");
   precache_sound ("player/udeath.wav");
   precache_model ("progs/knight.mdl");
   precache_model ("progs/h_knight.mdl");
   precache_sound ("knight/kdeath.wav");
   precache_sound ("knight/khurt.wav");
   precache_sound ("knight/ksight.wav");
   precache_sound ("knight/sword1.wav");
   precache_sound ("knight/sword2.wav");
   precache_sound ("knight/idle.wav");
   precache_model ("progs/ogre.mdl");
   precache_model ("progs/h_ogre.mdl");
   precache_model ("progs/grenade.mdl");
   precache_sound ("ogre/ogdrag.wav");
   precache_sound ("ogre/ogdth.wav");
   precache_sound ("ogre/ogidle.wav");
   precache_sound ("ogre/ogidle2.wav");
   precache_sound ("ogre/ogpain1.wav");
   precache_sound ("ogre/ogsawatk.wav");
   precache_sound ("ogre/ogwake.wav");
   precache_model2 ("progs/enforcer.mdl");
   //precache_model2 ("progs/bigenf.mdl");
   //precache_model2 ("progs/h_bigenf.mdl");
//   precache_model2 ("progs/h_bigshm.mdl");
   precache_model2 ("progs/h_mega.mdl");
   precache_model2 ("progs/laser.mdl");
   precache_sound2 ("enforcer/death1.wav");
   precache_sound2 ("enforcer/enfire.wav");
   precache_sound2 ("enforcer/enfstop.wav");
   precache_sound2 ("enforcer/idle1.wav");
   precache_sound2 ("enforcer/pain1.wav");
   precache_sound2 ("enforcer/pain2.wav");
   precache_sound2 ("enforcer/sight1.wav");
   precache_sound2 ("enforcer/sight2.wav");
   precache_sound2 ("enforcer/sight3.wav");
   precache_sound2 ("enforcer/sight4.wav");
   precache_model ("progs/h_dog.mdl");
   precache_model ("progs/dog.mdl");
   precache_sound ("dog/dattack1.wav");
   precache_sound ("dog/ddeath.wav");
   precache_sound ("dog/dpain1.wav");
   precache_sound ("dog/dsight.wav");
   precache_sound ("dog/idle.wav");
   precache_model2 ("progs/hknight.mdl");
   precache_model2 ("progs/k_spike.mdl");
   precache_model2 ("progs/h_hellkn.mdl");
   precache_sound2 ("hknight/attack1.wav");
   precache_sound2 ("hknight/death1.wav");
   precache_sound2 ("hknight/pain1.wav");
   precache_sound2 ("hknight/sight1.wav");
   precache_sound ("hknight/hit.wav");
   precache_sound2 ("hknight/slash1.wav");
   precache_sound2 ("hknight/idle.wav");
   precache_sound2 ("hknight/grunt.wav");
   precache_sound ("knight/sword1.wav");
   precache_sound ("knight/sword2.wav");
   precache_model ("progs/wizard.mdl");
   precache_model ("progs/h_wizard.mdl");
   precache_model ("progs/w_spike.mdl");
   precache_sound ("wizard/hit.wav");
   precache_sound ("wizard/wattack.wav");
   precache_sound ("wizard/wdeath.wav");
   precache_sound ("wizard/widle1.wav");
   precache_sound ("wizard/widle2.wav");
   precache_sound ("wizard/wpain.wav");
   precache_sound ("wizard/wsight.wav");
   precache_model ("progs/zombie.mdl");
   precache_model ("progs/h_zombie.mdl");
   precache_model ("progs/zom_gib.mdl");
   precache_sound ("zombie/z_idle.wav");
   precache_sound ("zombie/z_idle1.wav");
   precache_sound ("zombie/z_shot1.wav");
   precache_sound ("zombie/z_gib.wav");
   precache_sound ("zombie/z_pain.wav");
   precache_sound ("zombie/z_pain1.wav");
   precache_sound ("zombie/z_fall.wav");
   precache_sound ("zombie/z_miss.wav");
   precache_sound ("zombie/z_hit.wav");
   precache_sound ("zombie/idle_w2.wav");
   precache_model ("progs/demon.mdl");
   precache_model ("progs/h_demon.mdl");
   precache_sound ("demon/ddeath.wav");
   precache_sound ("demon/dhit2.wav");
   precache_sound ("demon/djump.wav");
   precache_sound ("demon/dpain1.wav");
   precache_sound ("demon/idle1.wav");
   precache_sound ("demon/sight2.wav");
   precache_model ("progs/shambler.mdl");
//   precache_model ("progs/bigsham.mdl");
   precache_model ("progs/s_light.mdl");
   precache_model ("progs/h_shams.mdl");
   precache_model ("progs/bolt.mdl");
   precache_sound ("shambler/sattck1.wav");
   precache_sound ("shambler/sboom.wav");
   precache_sound ("shambler/sdeath.wav");
   precache_sound ("shambler/shurt2.wav");
   precache_sound ("shambler/sidle.wav");
   precache_sound ("shambler/ssight.wav");
   precache_sound ("shambler/melee1.wav");
   precache_sound ("shambler/melee2.wav");
   precache_sound ("shambler/smack.wav");
   precache_model2 ("progs/shalrath.mdl");
   precache_model2 ("progs/h_shal.mdl");
   precache_model2 ("progs/v_spike.mdl");
   precache_sound2 ("shalrath/attack.wav");
   precache_sound2 ("shalrath/attack2.wav");
   precache_sound2 ("shalrath/death.wav");
   precache_sound2 ("shalrath/idle.wav");
   precache_sound2 ("shalrath/pain.wav");
   precache_sound2 ("shalrath/sight.wav");

   precache_model ("progs/mangib1.mdl");
   precache_model ("progs/mangib2.mdl");
   precache_model ("progs/mangib3.mdl");
//aliens precache

   precache_model ("progs/drone.mdl");
   precache_model ("progs/giba.mdl");
   precache_model ("progs/gibl.mdl");
   precache_model ("progs/head2.mdl");
   precache_model ("progs/tail2.mdl");
   precache_sound ("demon/ddeath.wav");
   precache_sound ("demon/dhit2.wav");
   precache_sound ("demon/djump.wav");
   precache_sound ("demon/dpain1.wav");
   precache_sound ("demon/idle1.wav");
   precache_sound ("demon/sight2.wav");
   precache_sound ("wizard/wdeath.wav");
   precache_model ("progs/face.mdl");
   precache_model ("progs/leg.mdl");
   precache_model ("progs/tail.mdl");
   precache_sound ("face/facew.wav");
   precache_sound ("face/facep.wav");
   precache_model ("progs/warrior.mdl");
   precache_model ("progs/thigh.mdl");
   precache_model ("progs/head1.mdl");
   precache_model ("progs/tail2.mdl");
   precache_model ("progs/forearm.mdl");
   precache_model ("progs/body.mdl");
   precache_model ("progs/hand.mdl");
   precache_sound ("egg/pulse.wav");
   precache_sound ("egg/squish.wav");
   precache_model ("progs/queen.mdl");
   precache_model ("progs/qhead.mdl");
   precache_model ("progs/thigh.mdl");
   precache_model ("progs/tail2.mdl");
   precache_model ("progs/qbody.mdl");
   precache_model ("progs/hand.mdl");
   precache_model ("progs/egg.mdl");
   precache_model ("progs/implant.mdl");
   precache_model ("progs/b_g_key.mdl");
   precache_sound ("queen/sight1.wav");
   precache_sound2 ("misc/basekey.wav");

   lightstyle (FALSE,"m");
   lightstyle (TRUE,"mmnmmommommnonmmonqnmmo");
   lightstyle (FL_SWIM,"abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba");
   lightstyle (MOVETYPE_WALK,"mmmmmaaaaammmmmaaaaaabcdefgabcdefg");
   lightstyle (MOVETYPE_STEP,"mamamamamama");
   lightstyle (MOVETYPE_FLY,"jklmnopqrstuvwxyzyxwvutsrqponmlkj");
   lightstyle (MOVETYPE_TOSS,"nmonqnmomnmomomno");
   lightstyle (MOVETYPE_PUSH,"mmmaaaabcdefgmmmmaaaammmaamm");
   lightstyle (FL_CLIENT,"mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa");
   lightstyle (MOVETYPE_FLYMISSILE,"aaaaaaaazzzzzzzz");
   lightstyle (MOVETYPE_BOUNCE,"mmamammmmammamamaaamammma");
   lightstyle (MOVETYPE_BOUNCEMISSILE,"abcdefghijklmnopqrrqponmlkjihgfedcba");
   lightstyle (63.000,"a");

   //dmsp2
   //totalmonsterspawn = (25.000 * (cvar ("skill") + FL_SWIM)); //bondo
   totalmonsterspawn = (20.000 * (cvar ("skill") + FL_SWIM));

   if ( (cvar ("teamplay") != FALSE) ) {

      totalmonsterspawn = FALSE;
      bprint ("deathmatch mode not supported!");

   }

   lastmspawn = world;
   lasttime = (time + MOVETYPE_BOUNCE);
   nspawned = FALSE;
   starttime = time;

//end dmsp2
};

void () StartFrame = {

BotFrame(); // FrikBot

   teamplay = cvar ("teamplay");
   skill = cvar ("skill");
   framecount = (framecount + TRUE);
//dmsp2
   monsterspawner ();


};
entity bodyque_head;

void () bodyque = {


};

void () InitBodyQue = {

   local entity e;

   bodyque_head = spawn ();
   bodyque_head.classname = "bodyque";
   bodyque_head.owner = spawn ();
   bodyque_head.owner.classname = "bodyque";
   bodyque_head.owner.owner = spawn ();
   bodyque_head.owner.owner.classname = "bodyque";
   bodyque_head.owner.owner.owner = spawn ();
   bodyque_head.owner.owner.owner.classname = "bodyque";
   bodyque_head.owner.owner.owner.owner = bodyque_head;

};

void (entity ent) CopyToBodyQue = {

// MULTISKIN Addition begin
// set the corpse's skin to be the same as the player's skin.
	bodyque_head.skin = ent.skin;
// MULTISKIN Addition end
   bodyque_head.angles = ent.angles;
   bodyque_head.model = ent.model;
   bodyque_head.modelindex = ent.modelindex;
   bodyque_head.frame = ent.frame;
   bodyque_head.colormap = ent.colormap;
   bodyque_head.movetype = ent.movetype;
   bodyque_head.velocity = ent.velocity;
   bodyque_head.flags = FALSE;
   setorigin (bodyque_head,ent.origin);
   setsize (bodyque_head,ent.mins,ent.maxs);
	
   bodyque_head = bodyque_head.owner;

};

//removed for frikbot compatibility
//original dmsp2 code
/*
void () waypoint = {

   remove (self);

};
*/
