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); }
/** Gets all of the colors of the given row. */ public synchronized Color[] getRowColors(int rowNum) { Color[] rowColors = new Color[GameUtil.BOARD_WIDTH]; Square[] row = boardRows.get(rowNum); if (row != null) { assert rowColors.length == row.length; for (int i = 0; i < rowColors.length; i++) { // null array element means that square is not occupied // so set the corresponding color to GRAY (PIECE_COLORS[0]) if (row[i] == null) { rowColors[i] = GameUtil.EMPTY; } else { rowColors[i] = row[i].color; } } } // fill in falling piece squares for (int i = 0; i < playerPieces.length; i++) { if (playerPieces[i] != null) { for (Square square : playerPieces[i].squares) { if (square.y == rowNum) { rowColors[GameUtil.modulo(square.x, GameUtil.BOARD_WIDTH)] = square.color; } } } } // fill gaps with gray for (int i = 0; i < rowColors.length; i++) { if (rowColors[i] == null) { rowColors[i] = GameUtil.EMPTY; } } return rowColors; }
public static void fire_bfg( edict_t self, float[] start, float[] dir, int damage, int speed, float damage_radius) { edict_t bfg; bfg = GameUtil.G_Spawn(); Math3D.VectorCopy(start, bfg.s.origin); Math3D.VectorCopy(dir, bfg.movedir); Math3D.vectoangles(dir, bfg.s.angles); Math3D.VectorScale(dir, speed, bfg.velocity); bfg.movetype = Defines.MOVETYPE_FLYMISSILE; bfg.clipmask = Defines.MASK_SHOT; bfg.solid = Defines.SOLID_BBOX; bfg.s.effects |= Defines.EF_BFG | Defines.EF_ANIM_ALLFAST; Math3D.VectorClear(bfg.mins); Math3D.VectorClear(bfg.maxs); bfg.s.modelindex = GameBase.gi.modelindex("sprites/s_bfg1.sp2"); bfg.owner = self; bfg.touch = bfg_touch; bfg.nextthink = GameBase.level.time + 8000 / speed; bfg.think = GameUtil.G_FreeEdictA; bfg.radius_dmg = damage; bfg.dmg_radius = damage_radius; bfg.classname = "bfg blast"; bfg.s.sound = GameBase.gi.soundindex("weapons/bfg__l1a.wav"); bfg.think = bfg_think; bfg.nextthink = GameBase.level.time + Defines.FRAMETIME; bfg.teammaster = bfg; bfg.teamchain = null; if (self.client != null) check_dodge(self, bfg.s.origin, dir, speed); GameBase.gi.linkentity(bfg); }
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); }
@Override public void onStart(Intent intent, int startid) { Log.i("PlayGame", "onStart"); // Sendevent.TestClick(); play = new GamePlay(); play.stop_flag = false; play.start(); GameUtil.reset(); }
/** Returns the created target changelevel. */ public static Entity CreateTargetChangeLevel(String map) { Entity ent; ent = GameUtil.G_Spawn(); ent.classname = "target_changelevel"; level.nextmap = map; ent.map = level.nextmap; return ent; }
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; }
public static void SP_trigger_gravity(Entity self) { if (GameBase.st.gravity == null) { ServerGame.PF_dprintf( "trigger_gravity without gravity set at " + Lib.vtos(self.s.origin) + "\n"); GameUtil.G_FreeEdict(self); return; } InitTrigger(self); self.gravity = Lib.atoi(GameBase.st.gravity); self.touch = trigger_gravity_touch; }
public static void fire_grenade2( edict_t self, float[] start, float[] aimdir, int damage, int speed, float timer, float damage_radius, boolean held) { edict_t grenade; float[] dir = {0, 0, 0}; float[] forward = {0, 0, 0}, right = {0, 0, 0}, up = {0, 0, 0}; Math3D.vectoangles(aimdir, dir); Math3D.AngleVectors(dir, forward, right, up); grenade = GameUtil.G_Spawn(); Math3D.VectorCopy(start, grenade.s.origin); Math3D.VectorScale(aimdir, speed, grenade.velocity); Math3D.VectorMA(grenade.velocity, 200f + Lib.crandom() * 10.0f, up, grenade.velocity); Math3D.VectorMA(grenade.velocity, Lib.crandom() * 10.0f, right, grenade.velocity); Math3D.VectorSet(grenade.avelocity, 300f, 300f, 300f); grenade.movetype = Defines.MOVETYPE_BOUNCE; grenade.clipmask = Defines.MASK_SHOT; grenade.solid = Defines.SOLID_BBOX; grenade.s.effects |= Defines.EF_GRENADE; Math3D.VectorClear(grenade.mins); Math3D.VectorClear(grenade.maxs); grenade.s.modelindex = GameBase.gi.modelindex("models/objects/grenade2/tris.md2"); grenade.owner = self; grenade.touch = Grenade_Touch; grenade.nextthink = GameBase.level.time + timer; grenade.think = Grenade_Explode; grenade.dmg = damage; grenade.dmg_radius = damage_radius; grenade.classname = "hgrenade"; if (held) grenade.spawnflags = 3; else grenade.spawnflags = 1; grenade.s.sound = GameBase.gi.soundindex("weapons/hgrenc1b.wav"); if (timer <= 0.0) Grenade_Explode.think(grenade); else { GameBase.gi.sound( self, Defines.CHAN_WEAPON, GameBase.gi.soundindex("weapons/hgrent1a.wav"), 1, Defines.ATTN_NORM, 0); GameBase.gi.linkentity(grenade); } }
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.soundindex("weapons/bfg__x1b.wav"), 1, Defines.ATTN_NORM, 0); self.solid = Defines.SOLID_NOT; self.touch = null; Math3D.VectorMA(self.s.origin, -1 * Defines.FRAMETIME, self.velocity, self.s.origin); Math3D.VectorClear(self.velocity); self.s.modelindex = GameBase.gi.modelindex("sprites/s_bfg3.sp2"); self.s.frame = 0; self.s.sound = 0; self.s.effects &= ~Defines.EF_ANIM_ALLFAST; self.think = bfg_explode; self.nextthink = GameBase.level.time + Defines.FRAMETIME; self.enemy = other; GameBase.gi.WriteByte(Defines.svc_temp_entity); GameBase.gi.WriteByte(Defines.TE_BFG_BIGEXPLOSION); GameBase.gi.WritePosition(self.s.origin); GameBase.gi.multicast(self.s.origin, Defines.MULTICAST_PVS); }
// the trigger was just activated // ent.activator should be set to the activator so it can be held through a // delay so wait for the delay time before firing public static void multi_trigger(Entity ent) { if (ent.nextthink != 0) return; // already been triggered GameUtil.G_UseTargets(ent, ent.activator); if (ent.wait > 0) { ent.think = multi_wait; ent.nextthink = GameBase.level.time + ent.wait; } else { // we can't just remove (self) here, because this is a touch // function // called while looping through area links... ent.touch = null; ent.nextthink = GameBase.level.time + Constants.FRAMETIME; ent.think = GameUtil.G_FreeEdictA; } }
/* * QUAKED monster_gladiator (1 .5 0) (-32 -32 -24) (32 32 64) Ambush * Trigger_Spawn Sight */ public static void SP_monster_gladiator(edict_t self) { if (GameBase.deathmatch.value != 0) { GameUtil.G_FreeEdict(self); return; } sound_pain1 = GameBase.gi.soundindex("gladiator/pain.wav"); sound_pain2 = GameBase.gi.soundindex("gladiator/gldpain2.wav"); sound_die = GameBase.gi.soundindex("gladiator/glddeth2.wav"); sound_gun = GameBase.gi.soundindex("gladiator/railgun.wav"); sound_cleaver_swing = GameBase.gi.soundindex("gladiator/melee1.wav"); sound_cleaver_hit = GameBase.gi.soundindex("gladiator/melee2.wav"); sound_cleaver_miss = GameBase.gi.soundindex("gladiator/melee3.wav"); sound_idle = GameBase.gi.soundindex("gladiator/gldidle1.wav"); sound_search = GameBase.gi.soundindex("gladiator/gldsrch1.wav"); sound_sight = GameBase.gi.soundindex("gladiator/sight.wav"); self.movetype = Defines.MOVETYPE_STEP; self.solid = Defines.SOLID_BBOX; self.s.modelindex = GameBase.gi.modelindex("models/monsters/gladiatr/tris.md2"); Math3D.VectorSet(self.mins, -32, -32, -24); Math3D.VectorSet(self.maxs, 32, 32, 64); self.health = 400; self.gib_health = -175; self.mass = 400; self.pain = gladiator_pain; self.die = gladiator_die; self.monsterinfo.stand = gladiator_stand; self.monsterinfo.walk = gladiator_walk; self.monsterinfo.run = gladiator_run; self.monsterinfo.dodge = null; self.monsterinfo.attack = gladiator_attack; self.monsterinfo.melee = gladiator_melee; self.monsterinfo.sight = gladiator_sight; self.monsterinfo.idle = gladiator_idle; self.monsterinfo.search = gladiator_search; GameBase.gi.linkentity(self); self.monsterinfo.currentmove = gladiator_move_stand; self.monsterinfo.scale = MODEL_SCALE; GameAI.walkmonster_start.think(self); }
/** * Given a player, check that his/her current falling piece isn't colliding with any of the * squares already fixed or are out of the bounds of the board. */ private synchronized boolean checkNoCollisionsWithSetSquares(int player) { if (playerPieces[player] == null) { return true; } for (Square square : playerPieces[player].squares) { Square[] row = boardRows.get(square.y); if (row != null) { // check there isn't already another square occupying that space if (row[GameUtil.modulo(square.x, GameUtil.BOARD_WIDTH)] != null) { return false; } } } if (playerPieces[player].hasHitBottom()) { return false; } return true; }
public static void fire_blaster( edict_t self, float[] start, float[] dir, int damage, int speed, int effect, boolean hyper) { edict_t bolt; trace_t tr; Math3D.VectorNormalize(dir); bolt = GameUtil.G_Spawn(); bolt.svflags = Defines.SVF_DEADMONSTER; // yes, I know it looks weird that projectiles are deadmonsters // what this means is that when prediction is used against the object // (blaster/hyperblaster shots), the player won't be solid clipped // against // the object. Right now trying to run into a firing hyperblaster // is very jerky since you are predicted 'against' the shots. Math3D.VectorCopy(start, bolt.s.origin); Math3D.VectorCopy(start, bolt.s.old_origin); Math3D.vectoangles(dir, bolt.s.angles); Math3D.VectorScale(dir, speed, bolt.velocity); bolt.movetype = Defines.MOVETYPE_FLYMISSILE; bolt.clipmask = Defines.MASK_SHOT; bolt.solid = Defines.SOLID_BBOX; bolt.s.effects |= effect; Math3D.VectorClear(bolt.mins); Math3D.VectorClear(bolt.maxs); bolt.s.modelindex = GameBase.gi.modelindex("models/objects/laser/tris.md2"); bolt.s.sound = GameBase.gi.soundindex("misc/lasfly.wav"); bolt.owner = self; bolt.touch = blaster_touch; bolt.nextthink = GameBase.level.time + 2; bolt.think = GameUtil.G_FreeEdictA; bolt.dmg = damage; bolt.classname = "bolt"; if (hyper) bolt.spawnflags = 1; GameBase.gi.linkentity(bolt); if (self.client != null) check_dodge(self, bolt.s.origin, dir, speed); tr = GameBase.gi.trace(self.s.origin, null, null, bolt.s.origin, bolt, Defines.MASK_SHOT); if (tr.fraction < 1.0) { Math3D.VectorMA(bolt.s.origin, -10, dir, bolt.s.origin); bolt.touch.touch(bolt, tr.ent, GameBase.dummyplane, null); } }
public Board(int numPlayers) { this.numPlayers = numPlayers; this.sectionWidth = GameUtil.computeSectionWidth(this.numPlayers); boardRows = new HashMap<Integer, Square[]>(); playerPieces = new Piece[numPlayers]; for (int i = 0; i < playerPieces.length; i++) { playerPieces[i] = PieceFactory.generateNewPiece(i, sectionWidth); } playerUpcomingPieces = new ArrayList<Queue<Piece>>(numPlayers); for (int i = 0; i < numPlayers; i++) { Queue<Piece> nextQueue = new LinkedList<Piece>(); for (int j = 0; j < PIECE_QUEUE_SIZE; j++) { nextQueue.add(PieceFactory.generateNewPiece(i, sectionWidth)); } playerUpcomingPieces.add(nextQueue); } checkRep(); }
/** * Adds the given player's current falling piece to the squares that are already fixed at the * bottom of the board (private utility function; call when appropriate). */ private synchronized void addToSetSquares(int player) { if (playerPieces[player] != null) { // Adds the given player's current piece into the pieces // that are no longer moving (hit the bottom). for (Square square : playerPieces[player].squares) { Square[] row = boardRows.get(square.y); if (row == null) { boardRows.put(square.y, new Square[GameUtil.BOARD_WIDTH]); } boardRows.get(square.y)[GameUtil.modulo(square.x, GameUtil.BOARD_WIDTH)] = square; } /* * Update the current player's falling piece by getting it from the * next piece in that player's queue. Then, generate a new piece and * add that to the queue. */ playerPieces[player] = playerUpcomingPieces.get(player).remove(); playerUpcomingPieces.get(player).add(PieceFactory.generateNewPiece(player, sectionWidth)); } }
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); }
/* * ================= * check_dodge * * This is a support routine used when a client is firing a non-instant * attack weapon. It checks to see if a monster's dodge function should be * called. * ================= */ static void check_dodge(edict_t self, float[] start, float[] dir, int speed) { float[] end = {0, 0, 0}; float[] v = {0, 0, 0}; trace_t tr; float eta; // easy mode only ducks one quarter the time if (GameBase.skill.value == 0) { if (Lib.random() > 0.25) return; } Math3D.VectorMA(start, 8192, dir, end); tr = GameBase.gi.trace(start, null, null, end, self, Defines.MASK_SHOT); if ((tr.ent != null) && (tr.ent.svflags & Defines.SVF_MONSTER) != 0 && (tr.ent.health > 0) && (null != tr.ent.monsterinfo.dodge) && GameUtil.infront(tr.ent, self)) { Math3D.VectorSubtract(tr.endpos, start, v); eta = (Math3D.VectorLength(v) - tr.ent.maxs[0]) / speed; tr.ent.monsterinfo.dodge.dodge(tr.ent, self, eta); } }
public static void fire_grenade( edict_t self, float[] start, float[] aimdir, int damage, int speed, float timer, float damage_radius) { edict_t grenade; float[] dir = {0, 0, 0}; float[] forward = {0, 0, 0}, right = {0, 0, 0}, up = {0, 0, 0}; Math3D.vectoangles(aimdir, dir); Math3D.AngleVectors(dir, forward, right, up); grenade = GameUtil.G_Spawn(); Math3D.VectorCopy(start, grenade.s.origin); Math3D.VectorScale(aimdir, speed, grenade.velocity); Math3D.VectorMA(grenade.velocity, 200f + Lib.crandom() * 10.0f, up, grenade.velocity); Math3D.VectorMA(grenade.velocity, Lib.crandom() * 10.0f, right, grenade.velocity); Math3D.VectorSet(grenade.avelocity, 300, 300, 300); grenade.movetype = Defines.MOVETYPE_BOUNCE; grenade.clipmask = Defines.MASK_SHOT; grenade.solid = Defines.SOLID_BBOX; grenade.s.effects |= Defines.EF_GRENADE; Math3D.VectorClear(grenade.mins); Math3D.VectorClear(grenade.maxs); grenade.s.modelindex = GameBase.gi.modelindex("models/objects/grenade/tris.md2"); grenade.owner = self; grenade.touch = Grenade_Touch; grenade.nextthink = GameBase.level.time + timer; grenade.think = Grenade_Explode; grenade.dmg = damage; grenade.dmg_radius = damage_radius; grenade.classname = "grenade"; GameBase.gi.linkentity(grenade); }
public void touch(Entity self, Entity other, Plane plane, Surface surf) { if (Lib.strcmp(other.classname, "grenade") == 0) { Math3D.VectorScale(self.movedir, self.speed * 10, other.velocity); } else if (other.health > 0) { Math3D.VectorScale(self.movedir, self.speed * 10, other.velocity); if (other.client != null) { // don't take falling damage immediately from this Math3D.VectorCopy(other.velocity, other.client.oldvelocity); if (other.fly_sound_debounce_time < GameBase.level.time) { other.fly_sound_debounce_time = GameBase.level.time + 1.5f; ServerGame.PF_StartSound( other, Constants.CHAN_AUTO, windsound, (float) 1, (float) Constants.ATTN_NORM, (float) 0); } } } if ((self.spawnflags & PUSH_ONCE) != 0) GameUtil.G_FreeEdict(self); }
public static void fire_rocket( edict_t self, float[] start, float[] dir, int damage, int speed, float damage_radius, int radius_damage) { edict_t rocket; rocket = GameUtil.G_Spawn(); Math3D.VectorCopy(start, rocket.s.origin); Math3D.VectorCopy(dir, rocket.movedir); Math3D.vectoangles(dir, rocket.s.angles); Math3D.VectorScale(dir, speed, rocket.velocity); rocket.movetype = Defines.MOVETYPE_FLYMISSILE; rocket.clipmask = Defines.MASK_SHOT; rocket.solid = Defines.SOLID_BBOX; rocket.s.effects |= Defines.EF_ROCKET; Math3D.VectorClear(rocket.mins); Math3D.VectorClear(rocket.maxs); rocket.s.modelindex = GameBase.gi.modelindex("models/objects/rocket/tris.md2"); rocket.owner = self; rocket.touch = rocket_touch; rocket.nextthink = GameBase.level.time + 8000 / speed; rocket.think = GameUtil.G_FreeEdictA; rocket.dmg = damage; rocket.radius_dmg = radius_damage; rocket.dmg_radius = damage_radius; rocket.s.sound = GameBase.gi.soundindex("weapons/rockfly.wav"); rocket.classname = "rocket"; if (self.client != null) check_dodge(self, rocket.s.origin, dir, speed); GameBase.gi.linkentity(rocket); }
/** * This method finds a ctf spawnpoint for the TEAM, * but NOT the two points closest to other players. **/ public GenericSpawnpoint getSpawnpoint() { GenericSpawnpoint spawnPoint = null; GenericSpawnpoint spot1 = null; GenericSpawnpoint spot2 = null; float range1 = Float.MAX_VALUE; float range2 = Float.MAX_VALUE; int count = 0; String regKey; regKey = ( this == TEAM1 ? info_player_team1.REGISTRY_KEY : info_player_team2.REGISTRY_KEY ); // find the two ctf-team spawnpoints that are closest to any players Vector list = Game.getLevelRegistryList( regKey ); Enumeration enum = list.elements(); while (enum.hasMoreElements()) { count++; spawnPoint = (GenericSpawnpoint) enum.nextElement(); float range = q2java.baseq2.MiscUtil.nearestPlayerDistance(spawnPoint); if (range < range1) { range1 = range; spot1 = spawnPoint; } else { if (range < range2) { range2 = range; spot2 = spawnPoint; } } } if (count == 0) return null; if (count <= 2) spot1 = spot2 = null; else count -= 2; int selection = (GameUtil.randomInt() & 0x0fff) % count; spawnPoint = null; enum = list.elements(); while (enum.hasMoreElements()) { spawnPoint = (GenericSpawnpoint) enum.nextElement(); // skip the undesirable spots if ((spawnPoint == spot1) || (spawnPoint == spot2)) continue; if ((selection--) == 0) break; } return spawnPoint; }
public static WorldServer GetWorld(int Dimension) { return (GameUtil.GetServer().worldServerForDimension(Dimension)); }
public void use(Entity self, Entity other, Entity activator) { int index; if (self.item == null) return; if (activator.client == null) return; index = GameItems.ITEM_INDEX(self.item); if (activator.client.pers.inventory[index] == 0) { if (GameBase.level.time < self.touch_debounce_time) return; self.touch_debounce_time = GameBase.level.time + 5.0f; ServerGame.PF_centerprintf(activator, "You need the " + self.item.pickup_name); ServerGame.PF_StartSound( activator, Constants.CHAN_AUTO, ServerInit.SV_SoundIndex("misc/keytry.wav"), (float) 1, (float) Constants.ATTN_NORM, (float) 0); return; } ServerGame.PF_StartSound( activator, Constants.CHAN_AUTO, ServerInit.SV_SoundIndex("misc/keyuse.wav"), (float) 1, (float) Constants.ATTN_NORM, (float) 0); if (GameBase.coop.value != 0) { int player; Entity ent; if (Lib.strcmp(self.item.classname, "key_power_cube") == 0) { int cube; for (cube = 0; cube < 8; cube++) if ((activator.client.pers.power_cubes & (1 << cube)) != 0) break; for (player = 1; player <= GameBase.game.maxclients; player++) { ent = GameBase.g_edicts[player]; if (!ent.inuse) continue; if (null == ent.client) continue; if ((ent.client.pers.power_cubes & (1 << cube)) != 0) { ent.client.pers.inventory[index]--; ent.client.pers.power_cubes &= ~(1 << cube); } } } else { for (player = 1; player <= GameBase.game.maxclients; player++) { ent = GameBase.g_edicts[player]; if (!ent.inuse) continue; if (ent.client == null) continue; ent.client.pers.inventory[index] = 0; } } } else { activator.client.pers.inventory[index]--; } GameUtil.G_UseTargets(self, activator); self.use = null; }
public void use(Entity self, Entity other, Entity activator) { GameUtil.G_UseTargets(self, activator); }
/* * QUAKED trigger_always (.5 .5 .5) (-8 -8 -8) (8 8 8) This trigger will * always fire. It is activated by the world. */ public static void SP_trigger_always(Entity ent) { // we must have some delay to make sure our use targets are present if (ent.delay < 0.2f) ent.delay = 0.2f; GameUtil.G_UseTargets(ent, ent); }
/** * Select a random spawnpoint, but exclude the two points closest * to other players. * @return q2jgame.GameEntity */ public static GenericSpawnpoint getSpawnpointRandom() { GenericSpawnpoint spawnPoint = null; GenericSpawnpoint spot1 = null; GenericSpawnpoint spot2 = null; float range1 = Float.MAX_VALUE; float range2 = Float.MAX_VALUE; int count = 0; // find the two deathmatch spawnpoints that are closest to any players Vector list = Game.getLevelRegistryList(q2java.baseq2.spawn.info_player_deathmatch.REGISTRY_KEY); // if no deathmatch spawnpoint, try single-player ones if (list.size() < 1) list = Game.getLevelRegistryList(q2java.baseq2.spawn.info_player_start.REGISTRY_KEY); Enumeration enum = list.elements(); while (enum.hasMoreElements()) { count++; spawnPoint = (GenericSpawnpoint) enum.nextElement(); float range = MiscUtil.nearestPlayerDistance(spawnPoint); if (range < range1) { range1 = range; spot1 = spawnPoint; } else { if (range < range2) { range2 = range; spot2 = spawnPoint; } } } if (count == 0) return null; if (count <= 2) spot1 = spot2 = null; else count -= 2; int selection = (GameUtil.randomInt() & 0x0fff) % count; spawnPoint = null; enum = list.elements(); while (enum.hasMoreElements()) { spawnPoint = (GenericSpawnpoint) enum.nextElement(); // skip the undesirable spots if ((spawnPoint == spot1) || (spawnPoint == spot2)) continue; if ((selection--) == 0) break; } return spawnPoint; }
/** * Fire a lead projectile. * @param p q2jgame.Player * @param start q2java.Vec3 * @param aimDir q2java.Vec3 * @param damage int * @param kick int * @param teImpact int * @param hSpread int * @param vSpread int */ public static void fireLead(GameObject p, Point3f start, Vector3f aimDir, int damage, int kick, int teImpact, int hSpread, int vSpread, String obitKey) { TraceResults tr; Vector3f forward = new Vector3f(); Vector3f right = new Vector3f(); Vector3f up = new Vector3f(); Point3f end = new Point3f(); float r; float u; Point3f waterStart = null; boolean water = false; int content_mask = Engine.MASK_SHOT | Engine.MASK_WATER; tr = Engine.trace(p.fEntity.getOrigin(), start, p.fEntity, Engine.MASK_SHOT); if (!(tr.fFraction < 1.0)) { // limit the scope of "dir" { Angle3f dir = Q2Recycler.getAngle3f(); dir.set(aimDir); dir.getVectors(forward, right, up); Q2Recycler.put(dir); } r = (float) (GameUtil.cRandom() * hSpread); u = (float) (GameUtil.cRandom() * vSpread); end.scaleAdd(8192, forward, start); end.scaleAdd(r, right, end); end.scaleAdd(u, up, end); if ((Engine.getPointContents(start) & Engine.MASK_WATER) != 0) { water = true; waterStart = new Point3f(start); content_mask &= ~Engine.MASK_WATER; } tr = Engine.trace(start, end, p.fEntity, content_mask); // see if we hit water if ((tr.fContents & Engine.MASK_WATER) != 0) { int color; water = true; waterStart = new Point3f(tr.fEndPos); if (!start.equals(tr.fEndPos)) { if ((tr.fContents & Engine.CONTENTS_WATER) != 0) { if (tr.fSurfaceName.equals("*brwater")) color = Engine.SPLASH_BROWN_WATER; else color = Engine.SPLASH_BLUE_WATER; } else if ((tr.fContents & Engine.CONTENTS_SLIME) != 0) color = Engine.SPLASH_SLIME; else if ((tr.fContents & Engine.CONTENTS_LAVA) != 0) color = Engine.SPLASH_LAVA; else color = Engine.SPLASH_UNKNOWN; if (color != Engine.SPLASH_UNKNOWN) { Engine.writeByte(Engine.SVC_TEMP_ENTITY); Engine.writeByte(Engine.TE_SPLASH); Engine.writeByte(8); Engine.writePosition(tr.fEndPos); Engine.writeDir(tr.fPlaneNormal); Engine.writeByte(color); Engine.multicast(tr.fEndPos, Engine.MULTICAST_PVS); } // change bullet's course when it enters water Vector3f diff = Q2Recycler.getVector3f(); Angle3f ang = Q2Recycler.getAngle3f(); diff.sub(end, start); ang.set(diff); ang.getVectors(forward, right, up); r = (float)(GameUtil.cRandom() * hSpread * 2); u = (float)(GameUtil.cRandom() * vSpread * 2); end.scaleAdd(8192, forward, waterStart); end.scaleAdd(r, right, end); end.scaleAdd(u, up, end); Q2Recycler.put(ang); Q2Recycler.put(diff); } // re-trace ignoring water this time tr = Engine.trace(waterStart, end, p.fEntity, Engine.MASK_SHOT); } } // send gun puff / flash if ((tr.fSurfaceName == null) || ((tr.fSurfaceFlags & Engine.SURF_SKY) == 0)) { if ((tr.fFraction < 1.0) && (!tr.fSurfaceName.startsWith("sky"))) { if (tr.fEntity.getReference() instanceof GameObject) ((GameObject)tr.fEntity.getReference()).damage(p, p, aimDir, tr.fEndPos, tr.fPlaneNormal, damage, kick, GameObject.DAMAGE_BULLET, teImpact, obitKey); } } // if went through water, determine where the end and make a bubble trail if (water) { Point3f pos = Q2Recycler.getPoint3f(); Vector3f leadDir = Q2Recycler.getVector3f(); leadDir.sub(tr.fEndPos, waterStart); leadDir.normalize(); pos.scaleAdd(-2, leadDir, tr.fEndPos); // = tr.fEndPos.vectorMA(-2, dir); if ((Engine.getPointContents(pos) & Engine.MASK_WATER) != 0) tr.fEndPos = new Point3f(pos); else tr = Engine.trace(pos, waterStart, tr.fEntity, Engine.MASK_WATER); pos.add(tr.fEndPos, waterStart); pos.scale(0.5F); Engine.writeByte(Engine.SVC_TEMP_ENTITY); Engine.writeByte(Engine.TE_BUBBLETRAIL); Engine.writePosition(waterStart); Engine.writePosition(tr.fEndPos); Engine.multicast(pos, Engine.MULTICAST_PVS); Q2Recycler.put(leadDir); Q2Recycler.put(pos); } }