Commit fcf4579b authored by Mario's avatar Mario

Merge branch 'TimePath/nadesys' into 'master'

Objectify nades

Also fixes translocate grenade facing direction

See merge request !170
parents d78c1f16 384be561
......@@ -978,8 +978,8 @@ void DrawAmmoNades(vector myPos, vector mySize, bool draw_expanding, float expan
float bonusNades = getstatf(STAT_NADE_BONUS);
float bonusProgress = getstatf(STAT_NADE_BONUS_SCORE);
float bonusType = getstati(STAT_NADE_BONUS_TYPE);
vector nadeColor = Nade_Color(bonusType);
string nadeIcon = Nade_Icon(bonusType);
vector nadeColor = NADES[bonusType].m_color;
string nadeIcon = NADES[bonusType].m_icon;
vector iconPos, textPos;
......
......@@ -140,9 +140,9 @@ void CSQC_Init(void)
GetTeam(NUM_SPECTATOR, true); // add specs first
// needs to be done so early because of the constants they create
static_init();
CALL_ACCUMULATED_FUNCTION(RegisterWeapons);
CALL_ACCUMULATED_FUNCTION(RegisterMonsters);
CALL_ACCUMULATED_FUNCTION(RegisterItems);
CALL_ACCUMULATED_FUNCTION(RegisterGametypes);
CALL_ACCUMULATED_FUNCTION(RegisterNotifications);
CALL_ACCUMULATED_FUNCTION(RegisterDeathtypes);
......
......@@ -543,7 +543,7 @@ void UpdateCrosshair()
if(getstati(STAT_FROZEN))
drawfill('0 0 0', eX * vid_conwidth + eY * vid_conheight, ((getstatf(STAT_REVIVE_PROGRESS)) ? ('0.25 0.90 1' + ('1 0 0' * getstatf(STAT_REVIVE_PROGRESS)) + ('0 1 1' * getstatf(STAT_REVIVE_PROGRESS) * -1)) : '0.25 0.90 1'), autocvar_hud_colorflash_alpha, DRAWFLAG_ADDITIVE);
else if (getstatf(STAT_HEALING_ORB)>time)
drawfill('0 0 0', eX * vid_conwidth + eY * vid_conheight, Nade_Color(NADE_TYPE_HEAL), autocvar_hud_colorflash_alpha*getstatf(STAT_HEALING_ORB_ALPHA), DRAWFLAG_ADDITIVE);
drawfill('0 0 0', eX * vid_conwidth + eY * vid_conheight, NADE_TYPE_HEAL.m_color, autocvar_hud_colorflash_alpha*getstatf(STAT_HEALING_ORB_ALPHA), DRAWFLAG_ADDITIVE);
if(!intermission)
if(getstatf(STAT_NADE_TIMER) && autocvar_cl_nade_timer) // give nade top priority, as it's a matter of life and death
{
......
......@@ -114,7 +114,7 @@ void Projectile_Draw()
break;
}
if(Nade_IDFromProjectile(self.cnt) != 0)
if(Nade_FromProjectile(self.cnt) != NADE_TYPE_NULL)
rot = self.avelocity;
self.angles = AnglesTransform_ToAngles(AnglesTransform_Multiply(AnglesTransform_FromAngles(self.angles), rot * (t - self.spawntime)));
......@@ -142,7 +142,7 @@ void Projectile_Draw()
break;
}
if(Nade_IDFromProjectile(self.cnt) != 0)
if(Nade_FromProjectile(self.cnt) != NADE_TYPE_NULL)
trailorigin += v_up * 4;
if(drawn)
......@@ -318,7 +318,12 @@ void Ent_Projectile()
case PROJECTILE_RPC: setmodel(self, "models/weapons/ok_rocket.md3");self.traileffect = particleeffectnum("TR_ROCKET"); break;
default:
if(Nade_IDFromProjectile(self.cnt) != 0) { setmodel(self, "models/weapons/v_ok_grenade.md3");self.traileffect = particleeffectnum(Nade_TrailEffect(self.cnt, self.team)); break; }
if (Nade_FromProjectile(self.cnt) != NADE_TYPE_NULL)
{
setmodel(self, "models/weapons/v_ok_grenade.md3");
self.traileffect = particleeffectnum(Nade_TrailEffect(self.cnt, self.team));
break;
}
error("Received invalid CSQC projectile, can't work with this!");
break;
}
......@@ -448,12 +453,12 @@ void Ent_Projectile()
break;
}
if(Nade_IDFromProjectile(self.cnt) != 0)
if(Nade_FromProjectile(self.cnt) != NADE_TYPE_NULL)
{
int nade_type = Nade_IDFromProjectile(self.cnt);
entity nade_type = Nade_FromProjectile(self.cnt);
self.mins = '-16 -16 -16';
self.maxs = '16 16 16';
self.colormod = Nade_Color(nade_type);
self.colormod = nade_type.m_color;
self.move_movetype = MOVETYPE_BOUNCE;
self.move_touch = func_null;
self.scale = 1.5;
......
......@@ -9,6 +9,7 @@ entity ITEMS[MAX_ITEMS];
int ITEM_COUNT;
/** If you register a new item, make sure to add it to all.inc */
#define REGISTER_ITEM(id, class) REGISTER(RegisterItems, ITEM, ITEMS, ITEM_COUNT, id, class, m_id)
REGISTER_REGISTRY(RegisterItems)
#define ITEMS_FOREACH(pred, body) do { \
for (int i = 0; i < ITEM_COUNT; i++) { \
......
#ifndef NADES_H
#define NADES_H
#include "oo.qh"
#include "registry.qh"
#include "teams.qh"
.float healer_lifetime;
......@@ -21,104 +23,110 @@ const int PROJECTILE_NADE_HEAL_BURN = 81;
const int PROJECTILE_NADE_MONSTER = 82;
const int PROJECTILE_NADE_MONSTER_BURN = 83;
const int NADE_TYPE_NORMAL = 1;
const int NADE_TYPE_NAPALM = 2;
const int NADE_TYPE_ICE = 3;
const int NADE_TYPE_TRANSLOCATE = 4;
const int NADE_TYPE_SPAWN = 5;
const int NADE_TYPE_HEAL = 6;
const int NADE_TYPE_MONSTER = 7;
void RegisterNades();
const int NADES_MAX = 8;
entity NADES[NADES_MAX];
int NADES_COUNT;
#define REGISTER_NADE(id) REGISTER(RegisterNades, NADE_TYPE, NADES, NADES_COUNT, id, Nade, m_id)
REGISTER_REGISTRY(RegisterNades)
CLASS(Nade, Object)
ATTRIB(Nade, m_id, int, 0)
ATTRIB(Nade, m_color, vector, '0 0 0')
ATTRIB(Nade, m_icon, string, "nade_normal")
ATTRIBARRAY(Nade, m_projectile, int, 2)
ATTRIBARRAY(Nade, m_trail, string, 2)
ENDCLASS(Nade)
REGISTER_NADE(NULL);
#define NADE_PROJECTILE(i, projectile, trail) do { \
this.m_projectile[i] = projectile; \
this.m_trail[i] = trail; \
} while (0)
REGISTER_NADE(NORMAL) {
this.m_color = '1 1 1';
NADE_PROJECTILE(0, PROJECTILE_NADE, string_null);
NADE_PROJECTILE(1, PROJECTILE_NADE_BURN, string_null);
}
const int NADE_TYPE_LAST = 7; // a check to prevent using higher values & crashing
REGISTER_NADE(NAPALM) {
this.m_color = '2 0.5 0';
this.m_icon = "nade_napalm";
NADE_PROJECTILE(0, PROJECTILE_NADE_NAPALM, "TR_ROCKET");
NADE_PROJECTILE(1, PROJECTILE_NADE_NAPALM_BURN, "spiderbot_rocket_thrust");
}
vector Nade_Color(int nadeid)
{
switch(nadeid)
{
case NADE_TYPE_NORMAL: return '1 1 1';
case NADE_TYPE_NAPALM: return '2 0.5 0';
case NADE_TYPE_ICE: return '0 0.5 2';
case NADE_TYPE_TRANSLOCATE: return '1 0 1';
case NADE_TYPE_SPAWN: return '1 0.9 0';
case NADE_TYPE_HEAL: return '1 0 0';
case NADE_TYPE_MONSTER: return '0.25 0.75 0';
}
return '0 0 0';
REGISTER_NADE(ICE) {
this.m_color = '0 0.5 2';
this.m_icon = "nade_ice";
NADE_PROJECTILE(0, PROJECTILE_NADE_ICE, "TR_NEXUIZPLASMA");
NADE_PROJECTILE(1, PROJECTILE_NADE_ICE_BURN, "wakizashi_rocket_thrust");
}
string Nade_Icon(int nadeid)
{
switch(nadeid)
{
case NADE_TYPE_NORMAL: return "nade_normal";
case NADE_TYPE_NAPALM: return "nade_napalm";
case NADE_TYPE_ICE: return "nade_ice";
case NADE_TYPE_TRANSLOCATE: return "nade_translocate";
case NADE_TYPE_SPAWN: return "nade_spawn";
case NADE_TYPE_HEAL: return "nade_heal";
case NADE_TYPE_MONSTER: return "nade_monster";
}
return "nade_normal";
REGISTER_NADE(TRANSLOCATE) {
this.m_color = '1 0 1';
this.m_icon = "nade_translocate";
NADE_PROJECTILE(0, PROJECTILE_NADE_TRANSLOCATE, "TR_CRYLINKPLASMA");
NADE_PROJECTILE(1, PROJECTILE_NADE_TRANSLOCATE, "TR_CRYLINKPLASMA");
}
int Nade_IDFromProjectile(float proj)
{
switch(proj)
{
case PROJECTILE_NADE:
case PROJECTILE_NADE_BURN: return NADE_TYPE_NORMAL;
case PROJECTILE_NADE_NAPALM:
case PROJECTILE_NADE_NAPALM_BURN: return NADE_TYPE_NAPALM;
case PROJECTILE_NADE_ICE:
case PROJECTILE_NADE_ICE_BURN: return NADE_TYPE_ICE;
case PROJECTILE_NADE_TRANSLOCATE: return NADE_TYPE_TRANSLOCATE;
case PROJECTILE_NADE_SPAWN: return NADE_TYPE_SPAWN;
case PROJECTILE_NADE_HEAL:
case PROJECTILE_NADE_HEAL_BURN: return NADE_TYPE_HEAL;
case PROJECTILE_NADE_MONSTER:
case PROJECTILE_NADE_MONSTER_BURN: return NADE_TYPE_MONSTER;
}
return 0;
REGISTER_NADE(SPAWN) {
this.m_color = '1 0.9 0';
this.m_icon = "nade_spawn";
NADE_PROJECTILE(0, PROJECTILE_NADE_SPAWN, "nade_yellow");
NADE_PROJECTILE(1, PROJECTILE_NADE_SPAWN, "nade_yellow");
}
REGISTER_NADE(HEAL) {
this.m_color = '1 0 0';
this.m_icon = "nade_heal";
NADE_PROJECTILE(0, PROJECTILE_NADE_HEAL, "nade_red");
NADE_PROJECTILE(1, PROJECTILE_NADE_HEAL_BURN, "nade_red_burn");
}
REGISTER_NADE(MONSTER) {
this.m_color = '0.25 0.75 0';
this.m_icon = "nade_monster";
NADE_PROJECTILE(0, PROJECTILE_NADE_MONSTER, "nade_red");
NADE_PROJECTILE(1, PROJECTILE_NADE_MONSTER_BURN, "nade_red_burn");
}
int Nade_ProjectileFromID(int proj, bool burn)
entity Nade_FromProjectile(float proj)
{
switch(proj)
{
case NADE_TYPE_NORMAL: return (burn) ? PROJECTILE_NADE_BURN : PROJECTILE_NADE;
case NADE_TYPE_NAPALM: return (burn) ? PROJECTILE_NADE_NAPALM_BURN : PROJECTILE_NADE_NAPALM;
case NADE_TYPE_ICE: return (burn) ? PROJECTILE_NADE_ICE_BURN : PROJECTILE_NADE_ICE;
case NADE_TYPE_TRANSLOCATE: return PROJECTILE_NADE_TRANSLOCATE;
case NADE_TYPE_SPAWN: return PROJECTILE_NADE_SPAWN;
case NADE_TYPE_HEAL: return (burn) ? PROJECTILE_NADE_HEAL_BURN : PROJECTILE_NADE_HEAL;
case NADE_TYPE_MONSTER: return (burn) ? PROJECTILE_NADE_MONSTER_BURN : PROJECTILE_NADE_MONSTER;
}
return 0;
for (int i = 0; i < NADES_COUNT; i++)
{
entity nade = NADES[i];
for (int j = 0; j < 2; j++)
{
if (nade.m_projectile[j] == proj) return nade;
}
}
return NADE_TYPE_NULL;
}
string Nade_TrailEffect(float proj, float nade_team)
{
switch(proj)
{
case PROJECTILE_NADE: return strcat("nade_", Static_Team_ColorName_Lower(nade_team));
case PROJECTILE_NADE_BURN: return strcat("nade_", Static_Team_ColorName_Lower(nade_team), "_burn");
case PROJECTILE_NADE_NAPALM: return "TR_ROCKET";
case PROJECTILE_NADE_NAPALM_BURN: return "spiderbot_rocket_thrust";
case PROJECTILE_NADE_ICE: return "TR_NEXUIZPLASMA";
case PROJECTILE_NADE_ICE_BURN: return "wakizashi_rocket_thrust";
case PROJECTILE_NADE_TRANSLOCATE: return "TR_CRYLINKPLASMA";
case PROJECTILE_NADE_SPAWN: return "nade_yellow";
case PROJECTILE_NADE_HEAL: return "nade_red";
case PROJECTILE_NADE_HEAL_BURN: return "nade_red_burn";
case PROJECTILE_NADE_MONSTER: return "nade_red";
case PROJECTILE_NADE_MONSTER_BURN: return "nade_red_burn";
}
return "";
for (int i = 0; i < NADES_COUNT; i++)
{
entity nade = NADES[i];
for (int j = 0; j < 2; j++)
{
if (nade.m_projectile[j] == proj)
{
string trail = nade.m_trail[j];
if (trail) return trail;
break;
}
}
}
switch (proj)
{
case PROJECTILE_NADE: return strcat("nade_", Static_Team_ColorName_Lower(nade_team));
case PROJECTILE_NADE_BURN: return strcat("nade_", Static_Team_ColorName_Lower(nade_team), "_burn");
}
return "";
}
#ifdef SVQC
......
......@@ -9,11 +9,15 @@
void Register_##ns##_##id() { \
entity this = NEW(class); \
ns##_##id = this; \
this.fld = ns##_COUNT; \
this.fld = counter; \
array[counter++] = this; \
Register_##ns##_##id##_init(this); \
} \
ACCUMULATE_FUNCTION(initfunc, Register_##ns##_##id) \
REGISTER_INIT(ns, id)
void __static_init() { }
#define static_init() CALL_ACCUMULATED_FUNCTION(__static_init)
#define REGISTER_REGISTRY(func) ACCUMULATE_FUNCTION(__static_init, func)
#endif
......@@ -80,8 +80,8 @@ void m_init()
}
// needs to be done so early because of the constants they create
static_init();
CALL_ACCUMULATED_FUNCTION(RegisterWeapons);
CALL_ACCUMULATED_FUNCTION(RegisterItems);
CALL_ACCUMULATED_FUNCTION(RegisterGametypes);
RegisterSLCategories();
......
......@@ -559,9 +559,9 @@ void spawnfunc___init_dedicated_server(void)
self.classname = "worldspawn"; // safeguard against various stuff ;)
// needs to be done so early because of the constants they create
static_init();
CALL_ACCUMULATED_FUNCTION(RegisterWeapons);
CALL_ACCUMULATED_FUNCTION(RegisterMonsters);
CALL_ACCUMULATED_FUNCTION(RegisterItems);
CALL_ACCUMULATED_FUNCTION(RegisterGametypes);
CALL_ACCUMULATED_FUNCTION(RegisterNotifications);
CALL_ACCUMULATED_FUNCTION(RegisterDeathtypes);
......@@ -610,9 +610,9 @@ void spawnfunc_worldspawn (void)
server_is_dedicated = (stof(cvar_defstring("is_dedicated")) ? true : false);
// needs to be done so early because of the constants they create
static_init();
CALL_ACCUMULATED_FUNCTION(RegisterWeapons);
CALL_ACCUMULATED_FUNCTION(RegisterMonsters);
CALL_ACCUMULATED_FUNCTION(RegisterItems);
CALL_ACCUMULATED_FUNCTION(RegisterGametypes);
CALL_ACCUMULATED_FUNCTION(RegisterNotifications);
CALL_ACCUMULATED_FUNCTION(RegisterDeathtypes);
......
......@@ -23,7 +23,7 @@ void nade_timer_think()
void nade_burn_spawn(entity _nade)
{
CSQCProjectile(_nade, true, Nade_ProjectileFromID(_nade.nade_type, true), true);
CSQCProjectile(_nade, true, NADES[_nade.nade_type].m_projectile[true], true);
}
void nade_spawn(entity _nade)
......@@ -42,7 +42,7 @@ void nade_spawn(entity _nade)
_nade.effects |= EF_LOWPRECISION;
CSQCProjectile(_nade, true, Nade_ProjectileFromID(_nade.nade_type, false), true);
CSQCProjectile(_nade, true, NADES[_nade.nade_type].m_projectile[false], true);
}
void napalm_damage(float dist, float damage, float edgedamage, float burntime)
......@@ -366,7 +366,7 @@ void nade_translocate_boom()
self.realowner = self;
self = oldself;
TeleportPlayer(self, self.realowner, locout, self.realowner.mangle, v_forward * vlen(self.realowner.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
TeleportPlayer(self, self.realowner, locout, self.realowner.angles, v_forward * vlen(self.realowner.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER);
}
void nade_spawn_boom()
......@@ -490,7 +490,7 @@ void nade_boom()
string expef;
bool nade_blast = true;
switch ( self.nade_type )
switch ( NADES[self.nade_type] )
{
case NADE_TYPE_NAPALM:
nade_blast = autocvar_g_nades_napalm_blast;
......@@ -549,7 +549,7 @@ void nade_boom()
}
if(self.takedamage)
switch ( self.nade_type )
switch ( NADES[self.nade_type] )
{
case NADE_TYPE_NAPALM: nade_napalm_boom(); break;
case NADE_TYPE_ICE: nade_ice_boom(); break;
......@@ -605,7 +605,7 @@ void nade_damage(entity inflictor, entity attacker, float damage, int deathtype,
return;
}
if(self.nade_type == NADE_TYPE_TRANSLOCATE || self.nade_type == NADE_TYPE_SPAWN)
if(self.nade_type == NADE_TYPE_TRANSLOCATE.m_id || self.nade_type == NADE_TYPE_SPAWN.m_id)
return;
if(DEATH_ISWEAPON(deathtype, WEP_BLASTER))
......@@ -653,7 +653,7 @@ void nade_damage(entity inflictor, entity attacker, float damage, int deathtype,
self.health -= damage;
if ( self.nade_type != NADE_TYPE_HEAL || IS_PLAYER(attacker) )
if ( self.nade_type != NADE_TYPE_HEAL.m_id || IS_PLAYER(attacker) )
self.realowner = attacker;
if(self.health <= 0)
......@@ -724,7 +724,7 @@ void toss_nade(entity e, vector _velocity, float _time)
_nade.toss_time = time;
_nade.solid = SOLID_CORPSE; //((_nade.nade_type == NADE_TYPE_TRANSLOCATE) ? SOLID_CORPSE : SOLID_BBOX);
if(_nade.nade_type == NADE_TYPE_TRANSLOCATE || _nade.nade_type == NADE_TYPE_SPAWN)
if(_nade.nade_type == NADE_TYPE_TRANSLOCATE.m_id || _nade.nade_type == NADE_TYPE_SPAWN.m_id)
_nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
else
_nade.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
......@@ -783,7 +783,7 @@ float nade_customize()
{
//self.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION;
if(!self.traileffectnum)
self.traileffectnum = particleeffectnum(Nade_TrailEffect(Nade_ProjectileFromID(self.nade_type, false), self.team));
self.traileffectnum = particleeffectnum(Nade_TrailEffect(NADES[self.nade_type].m_projectile[false], self.team));
self.alpha = 1;
}
......@@ -817,14 +817,14 @@ void nade_prime()
n.pokenade_type = ((autocvar_g_nades_client_select) ? self.cvar_cl_pokenade_type : autocvar_g_nades_pokenade_monster_type);
}
n.nade_type = bound(1, n.nade_type, NADE_TYPE_LAST);
n.nade_type = bound(1, n.nade_type, NADES_COUNT);
setmodel(n, "models/weapons/v_ok_grenade.md3");
//setattachment(n, self, "bip01 l hand");
n.exteriormodeltoclient = self;
n.customizeentityforclient = nade_customize;
n.traileffectnum = particleeffectnum(Nade_TrailEffect(Nade_ProjectileFromID(n.nade_type, false), self.team));
n.colormod = Nade_Color(n.nade_type);
n.traileffectnum = particleeffectnum(Nade_TrailEffect(NADES[n.nade_type].m_projectile[false], self.team));
n.colormod = NADES[n.nade_type].m_color;
n.realowner = self;
n.colormap = self.colormap;
n.glowmod = self.glowmod;
......@@ -837,7 +837,7 @@ void nade_prime()
setmodel(fn, "models/weapons/h_ok_grenade.iqm");
setattachment(fn, self.weaponentity, "");
fn.realowner = fn.owner = self;
fn.colormod = Nade_Color(n.nade_type);
fn.colormod = NADES[n.nade_type].m_color;
fn.colormap = self.colormap;
fn.glowmod = self.glowmod;
fn.think = SUB_Remove;
......@@ -995,7 +995,7 @@ MUTATOR_HOOKFUNCTION(nades_PlayerPreThink)
self.pokenade_type = autocvar_g_nades_pokenade_monster_type;
}
self.nade_type = bound(1, self.nade_type, NADE_TYPE_LAST);
self.nade_type = bound(1, self.nade_type, NADES_COUNT);
if(self.bonus_nade_score >= 0 && autocvar_g_nades_bonus_score_max)
nades_GiveBonus(self, time_score / autocvar_g_nades_bonus_score_max);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment