ew-progs/ew/ewgame.qc

405 lines
9.1 KiB
C++
Raw Normal View History

2011-09-06 00:00:00 +00:00
/*
=============================
ewgame.qc
coded by
Michael Rogers a.k.a Xsniper
ssj_xsniper@yahoo.com
http://www.xsniper.net/
Description:
This file contains code that alters the way EW
functions, speed and gravity altering code for instance.
=============================
*/
/*
=============================================================
Game Speed and Gravity Altering Code Below
=============================================================
*/
void() reset_speed =
{
// set game speed back to normal
adjust_speed(0,0);
// set global world speed variable back to 0
world_speed = 0;
};
void(float gspeed, float stime) spawn_speed_timer =
{
local entity speed_timer;
// start entity and place it in world
speed_timer = spawn();
setorigin (speed_timer, self.origin);
// set size and shape
speed_timer.solid = SOLID_NOT;
setmodel (speed_timer, "");
setsize (speed_timer, '-8 -8 -12', '8 8 20');
// lets adjust the game speed here
adjust_speed(gspeed, 0);
// set up thinking
speed_timer.nextthink = time + stime;
speed_timer.think = reset_speed; //reset the game speed
};
/*
====================
adjust_speed
Adjusts the speed of the game
float gspeed: variable controlling speed of game
0: normal speed
1: double speed
2: half speed
3: slow motion
float stime: variable controlling amount of time for speed change to last before switching back
to normal game speed.
0: stay at this speed until changed manually
any other positive number will make the change last that many seconds.
====================
*/
void(float gspeed, float stime) adjust_speed =
{
local entity player;
//search for the player first, we want to use a stuffcmd so he has to do it, not a monster
player = find(world, classname, "player");
if (stime == 0) //change speed now and permanently
{
//change speed of the game based on gspeed variable
if (gspeed == 0) //normal speed
stuffcmd(player,"slowmo 1\n");
else if (gspeed == 1) //double speed
stuffcmd(player,"slowmo 2\n");
else if (gspeed == 2) //half speed
stuffcmd(player,"slowmo 0.5\n");
else if (gspeed == 3) //slow motion
stuffcmd(player,"slowmo 0.1\n");
}
else //lets spawn a timer entity to force the wait
{
//we are gonna change speed now so let the world know
world_speed = 1;
//change speed
spawn_speed_timer(gspeed,stime);
}
};
void() reset_gravity =
{
// set game speed back to normal
adjust_gravity(0,0);
// set global world gravity variable back to 0
world_gravity = 0;
};
void(float gtype, float gtime) spawn_gravity_timer =
{
local entity gravity_timer;
// start entity and place it in world
gravity_timer = spawn();
setorigin (gravity_timer, self.origin);
// set size and shape
gravity_timer.solid = SOLID_NOT;
setmodel (gravity_timer, "");
setsize (gravity_timer, '-10 -10 -10', '10 10 10');
// lets adjust the game gravity here
adjust_gravity(gtype, 0);
// set up thinking
gravity_timer.nextthink = time + gtime;
gravity_timer.think = reset_gravity; //reset the game gravity
};
/*
====================
adjust_gravity
Adjusts the gravity of the game
float gtype: variable controlling gravity of game
0: normal gravity
1: almost no gravity
2: super gravity
float gtime: variable controlling amount of time for gravity change to last before switching back
to normal gravity.
0: stay at this speed until changed manually
any other positive number will make the change last that many seconds.
====================
*/
void(float gtype, float gtime) adjust_gravity =
{
local entity player;
//search for the player first, we want to use a stuffcmd so he has to do it, not a monster
player = find(world, classname, "player");
if (gtime == 0) //change gravity now and permanently
{
//change gravity of the game based on gtype variable
if (gtype == 0) //normal gravity
stuffcmd(player,"sv_gravity 800\n");
else if (gtype == 1) //almost no gravity
stuffcmd(player,"sv_gravity 100\n");
else if (gtype == 2) //super gravity
stuffcmd(player,"sv_gravity 1600\n");
}
else //lets spawn a timer entity to force the wait
{
//we are gonna change gravity now so let the world know
world_gravity = 1;
//change gravity
spawn_gravity_timer(gtype,gtime);
}
};
/*
=============================================================
Difficulty Level Optimizations Below
=============================================================
*/
/*
=================================
remove_monster
This function will remove the monster who calls it from the game
if the game difficulty settings say he should be removed.
=================================
*/
void() remove_monster =
{
//don't do this on any of the following levels
if (mapname == "map7" || mapname == "map13" || mapname == "map15")
return;
if (cvar("skill") == 0)
{
if (self.classname == "monster_agath" && numagath < 2)
{
numagath = numagath + 1;
remove(self);
}
else if (self.classname == "monster_wraith" && numwraith < 2)
{
numwraith = numwraith + 1;
remove(self);
}
else if (self.classname == "monster_teneb" && numteneb < 3)
{
numteneb = numteneb + 1;
remove(self);
}
}
else if (cvar("skill") == 1)
{
if (self.classname == "monster_agath" && numagath < 1)
{
numagath = numagath + 1;
remove(self);
}
else if (self.classname == "monster_wraith" && numwraith < 1)
{
numwraith = numwraith + 1;
remove(self);
}
else if (self.classname == "monster_teneb" && numteneb < 2)
{
numteneb = numteneb + 1;
remove(self);
}
}
};
/*
====================
set_health
dynamically set our health based on difficulty level
float hamount: normal amount of health this monster has
====================
*/
float(float hamount) set_health =
{
local float r;
local float newhealth;
//calculate r based on skill level
if (cvar("skill") == 0)
r = 0.75;
else if (cvar("skill") == 1)
r = 0.5;
else if (cvar("skill") == 2)
r = 0.25;
else if (cvar("skill") == 3)
r = 0;
newhealth = hamount - (hamount * r);
return (newhealth);
};
/*
====================
set_speed
dynamically set our speed based on difficulty level
float samount: normal speed this monster has
====================
*/
float(float samount) set_speed =
{
local float r;
local float newspeed;
//calculate r based on skill level
if (cvar("skill") == 0)
r = 0.75;
else if (cvar("skill") == 1)
r = 0.5;
else if (cvar("skill") == 2)
r = 0.25;
else if (cvar("skill") == 3)
r = 0;
newspeed = samount - (samount * r);
return (newspeed);
};
/*
====================
set_fade
dynamically set our fade based on difficulty level
float famount: normal fade this monster has
====================
*/
float(float famount) set_fade =
{
local float newfade;
//calculate r based on skill level
if (cvar("skill") == 0)
newfade = 0.5;
else if (cvar("skill") == 1)
newfade = 0.3;
else if (cvar("skill") == 2)
newfade = 0.2;
else if (cvar("skill") == 3)
newfade = 0.1;
else
newfade = famount;
return (newfade);
};
/*
=================================
set_deathmatch
sets the cvar deathmatch to snum
=================================
*/
void(float snum) set_deathmatch =
{
local entity player;
//find the player
player = find(world, classname, "player");
//change deathmatch cvar accordingly
if (snum < 1)
stuffcmd(player, "deathmatch 0");
else if (snum < 2)
stuffcmd(player, "deathmatch 1");
else if (snum < 3)
stuffcmd(player, "deathmatch 2");
else if (snum < 4)
stuffcmd(player, "deathmatch 3");
else
stuffcmd(player, "deathmatch 3");
deathmatch = snum;
};
/*
=========================
set_skill
sets the difficulty level of the game to samount.
=========================
*/
void(float samount) set_skill =
{
local entity player;
//find the player
player = find(world, classname, "player");
//adjust difficulty level accordingly
if (samount < 1)
stuffcmd(player,"skill 0");
else if (samount < 2)
stuffcmd(player,"skill 1");
else if (samount < 3)
stuffcmd(player,"skill 2");
else
stuffcmd(player,"skill 3");
};
/*
======================
IncrementDifficulty
increases the skill level by one.
======================
*/
void() IncrementDifficulty =
{
if (cvar("skill") == 0)
set_skill(1);
else if (cvar("skill") == 1)
set_skill(2);
else if (cvar("skill") == 2)
set_skill(3);
};
/*
==================
PrintDifficulty
prints a difficulty msg to the center of the screen
==================
*/
void() PrintDifficulty =
{
if (cvar("skill") < 1)
centerprint(self,"Now Playing Eternal War\nOn Easy Difficulty.\n");
else if (cvar("skill") < 2)
centerprint(self,"Now Playing Eternal War\nOn Normal Difficulty.\n");
else if (cvar("skill") < 3)
centerprint(self,"Now Playing Eternal War\nOn Hard Difficulty!\n");
else
centerprint(self,"Now Playing Eternal War\nOn Nightmare Difficulty!!!\n");
};