📄 gameweapon.java
字号:
/*Copyright (C) 1997-2001 Id Software, Inc.This program is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*/// Created on on 12.11.2003 by RST.// $Id: GameWeapon.java,v 1.6 2005/11/20 22:18:33 salomo Exp $package jake2.game;import jake2.*;import jake2.client.*;import jake2.game.*;import jake2.qcommon.*;import jake2.render.*;import jake2.server.*;import jake2.util.Lib;import jake2.util.Math3D;public class GameWeapon { static EntTouchAdapter blaster_touch = new EntTouchAdapter() { public String getID() { return "blaster_touch"; } public void touch(edict_t self, edict_t other, cplane_t plane, csurface_t surf) { int mod; if (other == self.owner) return; if (surf != null && (surf.flags & Defines.SURF_SKY) != 0) { GameUtil.G_FreeEdict(self); return; } if (self.owner.client != null) PlayerWeapon.PlayerNoise(self.owner, self.s.origin, Defines.PNOISE_IMPACT); if (other.takedamage != 0) { if ((self.spawnflags & 1) != 0) mod = Defines.MOD_HYPERBLASTER; else mod = Defines.MOD_BLASTER; // bugfix null plane rst float[] normal; if (plane == null) normal = new float[3]; else normal = plane.normal; GameCombat.T_Damage(other, self, self.owner, self.velocity, self.s.origin, normal, self.dmg, 1, Defines.DAMAGE_ENERGY, mod); } else { GameBase.gi.WriteByte(Defines.svc_temp_entity); GameBase.gi.WriteByte(Defines.TE_BLASTER); GameBase.gi.WritePosition(self.s.origin); if (plane == null) GameBase.gi.WriteDir(Globals.vec3_origin); else GameBase.gi.WriteDir(plane.normal); GameBase.gi.multicast(self.s.origin, Defines.MULTICAST_PVS); } GameUtil.G_FreeEdict(self); } }; static EntThinkAdapter Grenade_Explode = new EntThinkAdapter() { public String getID() { return "Grenade_Explode"; } public boolean think(edict_t ent) { float[] origin = { 0, 0, 0 }; int mod; if (ent.owner.client != null) PlayerWeapon.PlayerNoise(ent.owner, ent.s.origin, Defines.PNOISE_IMPACT); //FIXME: if we are onground then raise our Z just a bit since we // are a point? if (ent.enemy != null) { float points = 0; float[] v = { 0, 0, 0 }; float[] dir = { 0, 0, 0 }; Math3D.VectorAdd(ent.enemy.mins, ent.enemy.maxs, v); Math3D.VectorMA(ent.enemy.s.origin, 0.5f, v, v); Math3D.VectorSubtract(ent.s.origin, v, v); points = ent.dmg - 0.5f * Math3D.VectorLength(v); Math3D.VectorSubtract(ent.enemy.s.origin, ent.s.origin, dir); if ((ent.spawnflags & 1) != 0) mod = Defines.MOD_HANDGRENADE; else mod = Defines.MOD_GRENADE; GameCombat.T_Damage(ent.enemy, ent, ent.owner, dir, ent.s.origin, Globals.vec3_origin, (int) points, (int) points, Defines.DAMAGE_RADIUS, mod); } if ((ent.spawnflags & 2) != 0) mod = Defines.MOD_HELD_GRENADE; else if ((ent.spawnflags & 1) != 0) mod = Defines.MOD_HG_SPLASH; else mod = Defines.MOD_G_SPLASH; GameCombat.T_RadiusDamage(ent, ent.owner, ent.dmg, ent.enemy, ent.dmg_radius, mod); Math3D.VectorMA(ent.s.origin, -0.02f, ent.velocity, origin); GameBase.gi.WriteByte(Defines.svc_temp_entity); if (ent.waterlevel != 0) { if (ent.groundentity != null) GameBase.gi.WriteByte(Defines.TE_GRENADE_EXPLOSION_WATER); else GameBase.gi.WriteByte(Defines.TE_ROCKET_EXPLOSION_WATER); } else { if (ent.groundentity != null) GameBase.gi.WriteByte(Defines.TE_GRENADE_EXPLOSION); else GameBase.gi.WriteByte(Defines.TE_ROCKET_EXPLOSION); } GameBase.gi.WritePosition(origin); GameBase.gi.multicast(ent.s.origin, Defines.MULTICAST_PHS); GameUtil.G_FreeEdict(ent); return true; } }; static EntTouchAdapter Grenade_Touch = new EntTouchAdapter() { public String getID() { return "Grenade_Touch"; } public void touch(edict_t ent, edict_t other, cplane_t plane, csurface_t surf) { if (other == ent.owner) return; if (surf != null && 0 != (surf.flags & Defines.SURF_SKY)) { GameUtil.G_FreeEdict(ent); return; } if (other.takedamage == 0) { if ((ent.spawnflags & 1) != 0) { if (Lib.random() > 0.5f) GameBase.gi.sound(ent, Defines.CHAN_VOICE, GameBase.gi .soundindex("weapons/hgrenb1a.wav"), 1, Defines.ATTN_NORM, 0); else GameBase.gi.sound(ent, Defines.CHAN_VOICE, GameBase.gi .soundindex("weapons/hgrenb2a.wav"), 1, Defines.ATTN_NORM, 0); } else { GameBase.gi.sound(ent, Defines.CHAN_VOICE, GameBase.gi .soundindex("weapons/grenlb1b.wav"), 1, Defines.ATTN_NORM, 0); } return; } ent.enemy = other; Grenade_Explode.think(ent); } }; /* * ================= * fire_rocket * ================= */ static EntTouchAdapter rocket_touch = new EntTouchAdapter() { public String getID() { return "rocket_touch"; } public void touch(edict_t ent, edict_t other, cplane_t plane, csurface_t surf) { float[] origin = { 0, 0, 0 }; int n; if (other == ent.owner) return; if (surf != null && (surf.flags & Defines.SURF_SKY) != 0) { GameUtil.G_FreeEdict(ent); return; } if (ent.owner.client != null) PlayerWeapon.PlayerNoise(ent.owner, ent.s.origin, Defines.PNOISE_IMPACT); // calculate position for the explosion entity Math3D.VectorMA(ent.s.origin, -0.02f, ent.velocity, origin); if (other.takedamage != 0) { GameCombat.T_Damage(other, ent, ent.owner, ent.velocity, ent.s.origin, plane.normal, ent.dmg, 0, 0, Defines.MOD_ROCKET); } else { // don't throw any debris in net games if (GameBase.deathmatch.value == 0 && 0 == GameBase.coop.value) { if ((surf != null) && 0 == (surf.flags & (Defines.SURF_WARP | Defines.SURF_TRANS33 | Defines.SURF_TRANS66 | Defines.SURF_FLOWING))) { n = Lib.rand() % 5; while (n-- > 0) GameMisc.ThrowDebris(ent, "models/objects/debris2/tris.md2", 2, ent.s.origin); } } } GameCombat.T_RadiusDamage(ent, ent.owner, ent.radius_dmg, other, ent.dmg_radius, Defines.MOD_R_SPLASH); GameBase.gi.WriteByte(Defines.svc_temp_entity); if (ent.waterlevel != 0) GameBase.gi.WriteByte(Defines.TE_ROCKET_EXPLOSION_WATER); else GameBase.gi.WriteByte(Defines.TE_ROCKET_EXPLOSION); GameBase.gi.WritePosition(origin); GameBase.gi.multicast(ent.s.origin, Defines.MULTICAST_PHS); GameUtil.G_FreeEdict(ent); } }; /* * ================= * fire_bfg * ================= */ static EntThinkAdapter bfg_explode = new EntThinkAdapter() { public String getID() { return "bfg_explode"; } public boolean think(edict_t self) { edict_t ent; float points; float[] v = { 0, 0, 0 }; float dist; EdictIterator edit = null; if (self.s.frame == 0) { // the BFG effect ent = null; while ((edit = GameBase.findradius(edit, self.s.origin, self.dmg_radius)) != null) { ent = edit.o; if (ent.takedamage == 0) continue; if (ent == self.owner) continue; if (!GameCombat.CanDamage(ent, self)) continue; if (!GameCombat.CanDamage(ent, self.owner)) continue; Math3D.VectorAdd(ent.mins, ent.maxs, v); Math3D.VectorMA(ent.s.origin, 0.5f, v, v); Math3D.VectorSubtract(self.s.origin, v, v); dist = Math3D.VectorLength(v); points = (float) (self.radius_dmg * (1.0 - Math.sqrt(dist / self.dmg_radius))); if (ent == self.owner) points = points * 0.5f; GameBase.gi.WriteByte(Defines.svc_temp_entity); GameBase.gi.WriteByte(Defines.TE_BFG_EXPLOSION); GameBase.gi.WritePosition(ent.s.origin); GameBase.gi.multicast(ent.s.origin, Defines.MULTICAST_PHS); GameCombat.T_Damage(ent, self, self.owner, self.velocity, ent.s.origin, Globals.vec3_origin, (int) points, 0, Defines.DAMAGE_ENERGY, Defines.MOD_BFG_EFFECT); } } self.nextthink = GameBase.level.time + Defines.FRAMETIME; self.s.frame++; if (self.s.frame == 5) self.think = GameUtil.G_FreeEdictA; return true; } }; static EntTouchAdapter bfg_touch = new EntTouchAdapter() { public String getID() { return "bfg_touch"; } public void touch(edict_t self, edict_t other, cplane_t plane, csurface_t surf) { if (other == self.owner) return; if (surf != null && (surf.flags & Defines.SURF_SKY) != 0) { GameUtil.G_FreeEdict(self); return; } if (self.owner.client != null) PlayerWeapon.PlayerNoise(self.owner, self.s.origin, Defines.PNOISE_IMPACT); // core explosion - prevents firing it into the wall/floor if (other.takedamage != 0) GameCombat.T_Damage(other, self, self.owner, self.velocity, self.s.origin, plane.normal, 200, 0, 0, Defines.MOD_BFG_BLAST); GameCombat.T_RadiusDamage(self, self.owner, 200, other, 100, Defines.MOD_BFG_BLAST); GameBase.gi.sound(self, Defines.CHAN_VOICE, GameBase.gi
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -