/*
+----+
|Main|
+----+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
| Scratch                                      Http://www.admdev.com/scratch |
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
| Contains some 'base' subroutines. As a general rule nothing in this file   |
| does much, except to setup basic variables and entities.                   |
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
*/

void() precaches = 
{
	precache_model ("progs/null.spr");
	precache_model ("progs/pk_gren.mdl");
	precache_model ("progs/casing.mdl");
	precache_model ("progs/player.mdl");
	precache_model ("progs/corptop.mdl");
	precache_model ("progs/corpbot.mdl");
	precache_model ("progs/corpdeth.mdl");
	precache_model ("progs/bullet.mdl");
	precache_model ("progs/sbullets.mdl");
	precache_model ("progs/target.mdl");
	precache_model ("progs/lockon.spr");
	precache_model ("progs/explode1.spr");
	precache_model ("progs/grenade.mdl");

	//vwep
	precache_model ("progs/vw_knife.mdl");
	precache_model ("progs/vw_pist.mdl");
	precache_model ("progs/vw_2pist.mdl");
	precache_model ("progs/vw_shotg.mdl");
	precache_model ("progs/vw_subm.mdl");
	//dropwep
	precache_model ("progs/dr_knife.mdl");
	precache_model ("progs/dr_pist.mdl");
	precache_model ("progs/dr_shotg.mdl");
	precache_model ("progs/dr_subm.mdl");

	precache_model ("progs/shotmuz.spr");
	precache_model ("progs/muzflash.spr");
	precache_model ("progs/bldsplt.mdl");
	precache_model ("progs/bloodp.mdl");
	precache_model ("progs/wchunk1.mdl");
	precache_model ("progs/wchunk2.mdl");
	precache_model ("progs/wchunk3.mdl");

	//Stuff to change
	precache_sound ("player/inh2o.wav");
	precache_sound ("player/inlava.wav");
	precache_sound ("player/slimbrn2.wav");
	precache_sound ("player/gasp1.wav");
	precache_sound ("player/gasp2.wav");
	precache_sound ("misc/outwater.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 ("misc/h2ohit1.wav");
	//Stuff to change

	precache_sound ("misc/talk.wav");
	precache_sound ("misc/floorhit.wav");
	precache_sound ("misc/wallhit.wav");
	precache_sound ("items/pk_tdlay.wav");
	precache_sound ("items/pk_wep.wav");
	precache_sound ("items/pk_bullt.wav");
	precache_sound ("items/pk_shell.wav");
	precache_sound ("items/itemres.wav");
	precache_sound ("items/pk_gren.wav");
	precache_sound ("player/shldsmk.wav");
	precache_sound ("weapons/shotgnb1.wav");
	precache_sound ("weapons/shotgnb2.wav");
	precache_sound ("weapons/shotgnb3.wav");
	precache_sound ("weapons/shotgun2.wav");
	precache_sound ("weapons/shotgun3.wav");
	precache_sound ("weapons/pistol.wav");
	precache_sound ("weapons/pistol2.wav");
	precache_sound ("weapons/pistol3.wav");
	precache_sound ("weapons/change.wav");
	precache_sound ("weapons/submach.wav");
	precache_sound ("weapons/submach2.wav");
	precache_sound ("weapons/submach3.wav");
	precache_sound ("weapons/submach4.wav");
	precache_sound ("weapons/knife1.wav");
	precache_sound ("weapons/knife2.wav");
	precache_sound ("weapons/grenbnc.wav");
	precache_sound ("player/step.wav");
	precache_sound ("player/death.wav");
	precache_sound ("player/death2.wav");
	precache_sound ("player/pain1.wav");
	precache_sound ("player/pain2.wav");
	precache_sound ("player/pain3.wav");
	precache_sound ("player/pain4.wav");
	precache_sound ("player/jump.wav");
	precache_sound ("player/fjump.wav");
	precache_sound ("player/fland.wav");
	precache_sound ("player/lockon.wav");
	precache_sound ("player/scream.wav");
	precache_sound ("player/scream2.wav");
};

void() main = {};

entity	lastspawn;
void() worldspawn = 
{
	lastspawn = world;
	precaches();
	BotInit();  // FrikBot

	if (self.model == "maps/start.bsp") 
	{
		if (max_clients !=4)
			localcmd ("disconnect;wait;maxplayers 4;listen 1;deathmatch 1;map start\n");
	}
	localcmd("host_framerate 0\nv_cshift 0 0 0 0\n");
};

void() SetChangeParms =
{
	if (self.health <= 0)
	{
		SetNewParms ();
		return;
	}
	
	// cap super health
	if (self.health > 100) self.health = 100;
	parm1 = self.items;
	parm2 = self.health;
	parm3 = self.ammo_nails; // bullets
	parm4 = self.ammo_shells; // shells
	parm5 = self.ammo_rockets; // grenades
	parm6 = self.weapon;
};

void() SetNewParms =
{
	parm1 = W_KNIFE | W_PISTOL;
	parm2 = 100;
	parm3 = 24;
	parm4 = 0;
	parm5 = 0;
	parm6 = 0;
};

void() DecodeLevelParms =
{
	if (world.model == "maps/start.bsp")
		SetNewParms ();		// take away all stuff at start map
	
	self.items = parm1;
	self.health = parm2;
	self.ammo_nails = parm3;
	self.ammo_shells = parm4;
	self.ammo_rockets = parm5;
	self.weapon = parm6;
};

void() StartFrame =
{
	BotFrame(); // FrikBot
	teamplay = cvar("teamplay");
	skill = cvar("skill");
	framecount = framecount + 1;
};