X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fcommon%2Fweapons%2Fweapon%2Fminelayer.qc;h=4f1ee2aef019697a4e9f97e47003f3e983b2c95d;hp=37cb9944b4a7ed2fe0122825d3572f5384bde7d3;hb=4d01c64254bd9726c345afe727b70749879c04f6;hpb=678388b78fdaad89fc8218dadf7007432b4153c3 diff --git a/qcsrc/common/weapons/weapon/minelayer.qc b/qcsrc/common/weapons/weapon/minelayer.qc index 37cb9944b..4f1ee2aef 100644 --- a/qcsrc/common/weapons/weapon/minelayer.qc +++ b/qcsrc/common/weapons/weapon/minelayer.qc @@ -1,12 +1,13 @@ +#include "minelayer.qh" #ifndef IMPLEMENTATION CLASS(MineLayer, Weapon) -/* ammotype */ ATTRIB(MineLayer, ammo_field, .int, ammo_rockets) -/* impulse */ ATTRIB(MineLayer, impulse, int, 4) +/* ammotype */ ATTRIB(MineLayer, ammo_field, .int, ammo_rockets); +/* impulse */ ATTRIB(MineLayer, impulse, int, 4); /* flags */ ATTRIB(MineLayer, spawnflags, int, WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_RELOADABLE | WEP_TYPE_SPLASH); /* rating */ ATTRIB(MineLayer, bot_pickupbasevalue, float, BOT_PICKUP_RATING_HIGH); /* color */ ATTRIB(MineLayer, wpcolor, vector, '0.75 1 0'); /* modelname */ ATTRIB(MineLayer, mdl, string, "minelayer"); -#ifndef MENUQC +#ifdef GAMEQC /* model */ ATTRIB(MineLayer, m_model, Model, MDL_MINELAYER_ITEM); #endif /* crosshair */ ATTRIB(MineLayer, w_crosshair, string, "gfx/crosshairminelayer"); @@ -70,6 +71,8 @@ void W_MineLayer_Stick(entity this, entity to) // in order for mines to face properly when sticking to the ground, they must be a server side entity rather than a csqc projectile entity newmine = spawn(); + IL_PUSH(g_mines, newmine); + newmine.weaponentity_fld = this.weaponentity_fld; newmine.classname = this.classname; newmine.bot_dodge = this.bot_dodge; @@ -91,7 +94,7 @@ void W_MineLayer_Stick(entity this, entity to) newmine.spawnshieldtime = this.spawnshieldtime; newmine.damagedbycontents = true; - newmine.movetype = MOVETYPE_NONE; // lock the mine in place + set_movetype(newmine, MOVETYPE_NONE); // lock the mine in place newmine.projectiledeathtype = this.projectiledeathtype; newmine.mine_time = this.mine_time; @@ -101,41 +104,49 @@ void W_MineLayer_Stick(entity this, entity to) newmine.nextthink = time; newmine.cnt = this.cnt; newmine.flags = this.flags; + IL_PUSH(g_projectiles, newmine); + IL_PUSH(g_bot_dodge, newmine); - remove(this); + delete(this); if(to) SetMovetypeFollow(newmine, to); } -void W_MineLayer_Explode(entity this) +void W_MineLayer_Explode(entity this, entity directhitentity) { - if(other.takedamage == DAMAGE_AIM) - if(IS_PLAYER(other)) - if(DIFF_TEAM(this.realowner, other)) - if(!IS_DEAD(other)) - if(IsFlying(other)) + if(directhitentity.takedamage == DAMAGE_AIM) + if(IS_PLAYER(directhitentity)) + if(DIFF_TEAM(this.realowner, directhitentity)) + if(!IS_DEAD(directhitentity)) + if(IsFlying(directhitentity)) Send_Notification(NOTIF_ONE, this.realowner, MSG_ANNCE, ANNCE_ACHIEVEMENT_AIRSHOT); this.event_damage = func_null; this.takedamage = DAMAGE_NO; - RadiusDamage(this, this.realowner, WEP_CVAR(minelayer, damage), WEP_CVAR(minelayer, edgedamage), WEP_CVAR(minelayer, radius), NULL, NULL, WEP_CVAR(minelayer, force), this.projectiledeathtype, other); + RadiusDamage(this, this.realowner, WEP_CVAR(minelayer, damage), WEP_CVAR(minelayer, edgedamage), WEP_CVAR(minelayer, radius), NULL, NULL, WEP_CVAR(minelayer, force), this.projectiledeathtype, directhitentity); - if(PS(this.realowner).m_weapon == WEP_MINE_LAYER) + .entity weaponentity = this.weaponentity_fld; + if(this.realowner.(weaponentity).m_weapon == WEP_MINE_LAYER) { entity own = this.realowner; Weapon w = WEP_MINE_LAYER; - if(!w.wr_checkammo1(w, own)) + if(!w.wr_checkammo1(w, own, weaponentity)) { own.cnt = WEP_MINE_LAYER.m_id; - int slot = 0; // TODO: unhardcode + int slot = weaponslot(weaponentity); ATTACK_FINISHED(own, slot) = time; - PS(own).m_switchweapon = w_getbestweapon(own); + own.(weaponentity).m_switchweapon = w_getbestweapon(own, weaponentity); } } this.realowner.minelayer_mines -= 1; - remove(this); + delete(this); +} + +void W_MineLayer_Explode_think(entity this) +{ + W_MineLayer_Explode(this, NULL); } void W_MineLayer_DoRemoteExplode(entity this) @@ -143,25 +154,26 @@ void W_MineLayer_DoRemoteExplode(entity this) this.event_damage = func_null; this.takedamage = DAMAGE_NO; - if(this.movetype == MOVETYPE_NONE || this.movetype == MOVETYPE_FOLLOW) + if(this.move_movetype == MOVETYPE_NONE || this.move_movetype == MOVETYPE_FOLLOW) this.velocity = this.mine_orientation; // particle fx and decals need .velocity RadiusDamage(this, this.realowner, WEP_CVAR(minelayer, remote_damage), WEP_CVAR(minelayer, remote_edgedamage), WEP_CVAR(minelayer, remote_radius), NULL, NULL, WEP_CVAR(minelayer, remote_force), this.projectiledeathtype | HITTYPE_BOUNCE, NULL); - if(PS(this.realowner).m_weapon == WEP_MINE_LAYER) + .entity weaponentity = this.weaponentity_fld; + if(this.realowner.(weaponentity).m_weapon == WEP_MINE_LAYER) { entity own = this.realowner; Weapon w = WEP_MINE_LAYER; - if(!w.wr_checkammo1(w, own)) + if(!w.wr_checkammo1(w, own, weaponentity)) { own.cnt = WEP_MINE_LAYER.m_id; - int slot = 0; // TODO: unhardcode + int slot = weaponslot(weaponentity); ATTACK_FINISHED(own, slot) = time; - PS(own).m_switchweapon = w_getbestweapon(own); + own.(weaponentity).m_switchweapon = w_getbestweapon(own, weaponentity); } } this.realowner.minelayer_mines -= 1; - remove(this); + delete(this); } void W_MineLayer_RemoteExplode(entity this) @@ -192,15 +204,16 @@ void W_MineLayer_ProximityExplode(entity this) } this.mine_time = 0; - W_MineLayer_Explode(this); + W_MineLayer_Explode(this, NULL); } int W_MineLayer_Count(entity e) { int minecount = 0; - entity mine; - for(mine = NULL; (mine = find(mine, classname, "mine")); ) if(mine.realowner == e) + IL_EACH(g_mines, it.realowner == e, + { minecount += 1; + }); return minecount; } @@ -211,12 +224,12 @@ void W_MineLayer_Think(entity this) this.nextthink = time; - if(this.movetype == MOVETYPE_FOLLOW) + if(this.move_movetype == MOVETYPE_FOLLOW) { if(LostMovetypeFollow(this)) { UnsetMovetypeFollow(this); - this.movetype = MOVETYPE_NONE; + set_movetype(this, MOVETYPE_NONE); } } @@ -234,9 +247,8 @@ void W_MineLayer_Think(entity this) // TODO: Do this on team change too -- Samual: But isn't a player killed when they switch teams? if(!IS_PLAYER(this.realowner) || IS_DEAD(this.realowner) || STAT(FROZEN, this.realowner)) { - other = NULL; this.projectiledeathtype |= HITTYPE_BOUNCE; - W_MineLayer_Explode(this); + W_MineLayer_Explode(this, NULL); return; } @@ -262,7 +274,8 @@ void W_MineLayer_Think(entity this) } // remote detonation - if(PS(this.realowner).m_weapon == WEP_MINE_LAYER) + .entity weaponentity = this.weaponentity_fld; + if(this.realowner.(weaponentity).m_weapon == WEP_MINE_LAYER) if(!IS_DEAD(this.realowner)) if(this.minelayer_detonate) W_MineLayer_RemoteExplode(this); @@ -270,7 +283,7 @@ void W_MineLayer_Think(entity this) void W_MineLayer_Touch(entity this, entity toucher) { - if(this.movetype == MOVETYPE_NONE || this.movetype == MOVETYPE_FOLLOW) + if(this.move_movetype == MOVETYPE_NONE || this.move_movetype == MOVETYPE_FOLLOW) return; // we're already a stuck mine, why do we get called? TODO does this even happen? if(WarpZone_Projectile_Touch(this, toucher)) @@ -305,10 +318,10 @@ void W_MineLayer_Damage(entity this, entity inflictor, entity attacker, float da this.angles = vectoangles(this.velocity); if(this.health <= 0) - W_PrepareExplosionByDamage(this, attacker, W_MineLayer_Explode); + W_PrepareExplosionByDamage(this, attacker, W_MineLayer_Explode_think); } -void W_MineLayer_Attack(Weapon thiswep, entity actor) +void W_MineLayer_Attack(Weapon thiswep, entity actor, .entity weaponentity) { entity mine; entity flash; @@ -325,12 +338,14 @@ void W_MineLayer_Attack(Weapon thiswep, entity actor) } } - W_DecreaseAmmo(thiswep, actor, WEP_CVAR(minelayer, ammo)); + W_DecreaseAmmo(thiswep, actor, WEP_CVAR(minelayer, ammo), weaponentity); - W_SetupShot_ProjectileSize(actor, '-4 -4 -4', '4 4 4', false, 5, SND_MINE_FIRE, CH_WEAPON_A, WEP_CVAR(minelayer, damage)); + W_SetupShot_ProjectileSize(actor, weaponentity, '-4 -4 -4', '4 4 4', false, 5, SND_MINE_FIRE, CH_WEAPON_A, WEP_CVAR(minelayer, damage)); Send_Effect(EFFECT_ROCKET_MUZZLEFLASH, w_shotorg, w_shotdir * 1000, 1); mine = WarpZone_RefSys_SpawnSameRefSys(actor); + mine.weaponentity_fld = weaponentity; + IL_PUSH(g_mines, mine); mine.owner = mine.realowner = actor; if(WEP_CVAR(minelayer, detonatedelay) >= 0) mine.spawnshieldtime = time + WEP_CVAR(minelayer, detonatedelay); @@ -346,7 +361,7 @@ void W_MineLayer_Attack(Weapon thiswep, entity actor) mine.event_damage = W_MineLayer_Damage; mine.damagedbycontents = true; - mine.movetype = MOVETYPE_TOSS; + set_movetype(mine, MOVETYPE_TOSS); PROJECTILE_MAKETRIGGER(mine); mine.projectiledeathtype = WEP_MINE_LAYER.m_id; setsize(mine, '-4 -4 -4', '4 4 4'); // give it some size so it can be shot @@ -360,6 +375,8 @@ void W_MineLayer_Attack(Weapon thiswep, entity actor) mine.nextthink = time; mine.cnt = (WEP_CVAR(minelayer, lifetime) - WEP_CVAR(minelayer, lifetime_countdown)); mine.flags = FL_PROJECTILE; + IL_PUSH(g_projectiles, mine); + IL_PUSH(g_bot_dodge, mine); mine.missile_flags = MIF_SPLASH | MIF_ARC | MIF_PROXY; if(mine.cnt > 0) { mine.cnt += time; } @@ -371,7 +388,7 @@ void W_MineLayer_Attack(Weapon thiswep, entity actor) setmodel(flash, MDL_MINELAYER_MUZZLEFLASH); // precision set below SUB_SetFade(flash, time, 0.1); flash.effects = EF_ADDITIVE | EF_FULLBRIGHT | EF_LOWPRECISION; - W_AttachToShotorg(actor, flash, '5 0 0'); + W_AttachToShotorg(actor, weaponentity, flash, '5 0 0'); // common properties @@ -380,24 +397,23 @@ void W_MineLayer_Attack(Weapon thiswep, entity actor) actor.minelayer_mines = W_MineLayer_Count(actor); } -float W_MineLayer_PlacedMines(entity this, float detonate) +bool W_MineLayer_PlacedMines(entity this, bool detonate) { - entity mine; - float minfound = 0; + bool minfound = false; - for(mine = NULL; (mine = find(mine, classname, "mine")); ) if(mine.realowner == this) + IL_EACH(g_mines, it.realowner == this, { if(detonate) { - if(!mine.minelayer_detonate) + if(!it.minelayer_detonate) { - mine.minelayer_detonate = true; - minfound = 1; + it.minelayer_detonate = true; + minfound = true; } } else - minfound = 1; - } + minfound = true; + }); return minfound; } @@ -411,8 +427,7 @@ METHOD(MineLayer, wr_aim, void(entity thiswep, entity actor)) if(skill >= 2) // skill 0 and 1 bots won't detonate mines! { // decide whether to detonate mines - entity targetlist, targ; - float edgedamage, coredamage, edgeradius, recipricoledgeradius, d; + float edgedamage, coredamage, edgeradius, recipricoledgeradius; float selfdamage, teamdamage, enemydamage; edgedamage = WEP_CVAR(minelayer, edgedamage); coredamage = WEP_CVAR(minelayer, damage); @@ -421,31 +436,24 @@ METHOD(MineLayer, wr_aim, void(entity thiswep, entity actor)) selfdamage = 0; teamdamage = 0; enemydamage = 0; - targetlist = findchainfloat(bot_attack, true); - entity mine = find(NULL, classname, "mine"); - while(mine) + + IL_EACH(g_mines, it.realowner == actor, { - if(mine.realowner != actor) - { - mine = find(mine, classname, "mine"); - continue; - } - targ = targetlist; - while(targ) - { - d = vlen(targ.origin + (targ.mins + targ.maxs) * 0.5 - mine.origin); - d = bound(0, edgedamage + (coredamage - edgedamage) * sqrt(1 - d * recipricoledgeradius), 10000); + entity mine = it; + IL_EACH(g_bot_targets, it.bot_attack, + { + float d = vlen(it.origin + (it.mins + it.maxs) * 0.5 - mine.origin); + d = bound(0, edgedamage + (coredamage - edgedamage) * sqrt(1 - d * recipricoledgeradius), 10000); // count potential damage according to type of target - if(targ == actor) + if(it == actor) selfdamage = selfdamage + d; - else if(targ.team == actor.team && teamplay) + else if(SAME_TEAM(it, actor)) teamdamage = teamdamage + d; - else if(bot_shouldattack(actor, targ)) + else if(bot_shouldattack(actor, it)) enemydamage = enemydamage + d; - targ = targ.chain; - } - mine = find(mine, classname, "mine"); - } + }); + }); + float desirabledamage; desirabledamage = enemydamage; if(time > actor.invincible_finished && time > actor.spawnshieldtime) @@ -453,41 +461,35 @@ METHOD(MineLayer, wr_aim, void(entity thiswep, entity actor)) if(teamplay && actor.team) desirabledamage = desirabledamage - teamdamage; - mine = find(NULL, classname, "mine"); - while(mine) + makevectors(actor.v_angle); + IL_EACH(g_mines, it.realowner == actor, { - if(mine.realowner != actor) - { - mine = find(mine, classname, "mine"); - continue; - } - makevectors(mine.v_angle); - targ = targetlist; if(skill > 9) // normal players only do this for the target they are tracking { - targ = targetlist; - while(targ) - { - if( - (v_forward * normalize(mine.origin - targ.origin)< 0.1) - && desirabledamage > 0.1*coredamage - ) PHYS_INPUT_BUTTON_ATCK2(actor) = true; - targ = targ.chain; - } - }else{ - float distance; distance= bound(300,vlen(actor.origin-actor.enemy.origin),30000); + entity mine = it; + IL_EACH(g_bot_targets, it.bot_attack, + { + if((v_forward * normalize(mine.origin - it.origin) < 0.1) + && desirabledamage > 0.1 * coredamage + ) PHYS_INPUT_BUTTON_ATCK2(actor) = true; + }); + } + else + { //As the distance gets larger, a correct detonation gets near imposible //Bots are assumed to use the mine spawnfunc_light to see if the mine gets near a player - if(v_forward * normalize(mine.origin - actor.enemy.origin)< 0.1) - if(IS_PLAYER(actor.enemy)) - if(desirabledamage >= 0.1*coredamage) - if(random()/distance*300 > frametime*bound(0,(10-skill)*0.2,1)) - PHYS_INPUT_BUTTON_ATCK2(actor) = true; - // dprint(ftos(random()/distance*300),">");dprint(ftos(frametime*bound(0,(10-skill)*0.2,1)),"\n"); - } - - mine = find(mine, classname, "mine"); - } + if((v_forward * normalize(it.origin - actor.enemy.origin) < 0.1) + && IS_PLAYER(actor.enemy) + && (desirabledamage >= 0.1 * coredamage) + ) + { + float distance = bound(300, vlen(actor.origin - actor.enemy.origin), 30000); + if(random() / distance * 300 > frametime * bound(0, (10 - skill) * 0.2, 1)) + PHYS_INPUT_BUTTON_ATCK2(actor) = true; + } + } + }); + // if we would be doing at X percent of the core damage, detonate it // but don't fire a new shot at the same time! if(desirabledamage >= 0.75 * coredamage) //this should do group damage in rare fortunate events @@ -501,7 +503,7 @@ METHOD(MineLayer, wr_aim, void(entity thiswep, entity actor)) } METHOD(MineLayer, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) { - if(autocvar_g_balance_minelayer_reload_ammo && actor.clip_load < WEP_CVAR(minelayer, ammo)) // forced reload + if(autocvar_g_balance_minelayer_reload_ammo && actor.(weaponentity).clip_load < WEP_CVAR(minelayer, ammo)) // forced reload { // not if we're holding the minelayer without enough ammo, but can detonate existing mines if(!(W_MineLayer_PlacedMines(actor, false) && actor.(thiswep.ammo_field) < WEP_CVAR(minelayer, ammo))) { @@ -512,7 +514,7 @@ METHOD(MineLayer, wr_think, void(entity thiswep, entity actor, .entity weaponent { if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR(minelayer, refire))) { - W_MineLayer_Attack(thiswep, actor); + W_MineLayer_Attack(thiswep, actor, weaponentity); weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR(minelayer, animtime), w_ready); } } @@ -523,19 +525,19 @@ METHOD(MineLayer, wr_think, void(entity thiswep, entity actor, .entity weaponent sound(actor, CH_WEAPON_B, SND_MINE_DET, VOL_BASE, ATTN_NORM); } } -METHOD(MineLayer, wr_checkammo1, bool(entity thiswep, entity actor)) +METHOD(MineLayer, wr_checkammo1, bool(entity thiswep, entity actor, .entity weaponentity)) { //int slot = 0; // TODO: unhardcode // actually do // don't switch while placing a mine //if(ATTACK_FINISHED(actor, slot) <= time || PS(actor).m_weapon != WEP_MINE_LAYER) //{ float ammo_amount = actor.(thiswep.ammo_field) >= WEP_CVAR(minelayer, ammo); - ammo_amount += actor.(weapon_load[WEP_MINE_LAYER.m_id]) >= WEP_CVAR(minelayer, ammo); + ammo_amount += actor.(weaponentity).(weapon_load[WEP_MINE_LAYER.m_id]) >= WEP_CVAR(minelayer, ammo); return ammo_amount; //} //return true; } -METHOD(MineLayer, wr_checkammo2, bool(entity thiswep, entity actor)) +METHOD(MineLayer, wr_checkammo2, bool(entity thiswep, entity actor, .entity weaponentity)) { if(W_MineLayer_PlacedMines(actor, false)) return true; @@ -548,7 +550,7 @@ METHOD(MineLayer, wr_resetplayer, void(entity thiswep, entity actor)) } METHOD(MineLayer, wr_reload, void(entity thiswep, entity actor, .entity weaponentity)) { - W_Reload(actor, WEP_CVAR(minelayer, ammo), SND_RELOAD); + W_Reload(actor, weaponentity, WEP_CVAR(minelayer, ammo), SND_RELOAD); } METHOD(MineLayer, wr_suicidemessage, Notification(entity thiswep)) {