From: Rene S. <sa...@us...> - 2005-01-16 21:21:14
|
Update of /cvsroot/jake2/jake2/src/jake2/game/bots In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29339/src/jake2/game/bots Added Files: Tag: RST OAK.java Log Message: This has vec3-optimize and the OAK bot. --- NEW FILE: OAK.java --- /* * Copyright (C) 1997-2001 Id Software, Inc. * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of 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 of MERCHANTABILITY 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 License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place - Suite 330, Boston, MA 02111-1307, USA. * * Author: John Crickett dl...@cr... * */ // Java Version created on 31.12.2004 by RST. // $Id: OAK.java,v 1.1.2.1 2005/01/16 21:21:05 salomo Exp $ package jake2.game.bots; import jake2.*; import jake2.client.*; import jake2.game.*; import jake2.game.monsters.*; import jake2.qcommon.*; import jake2.render.*; import jake2.server.*; import jake2.util.Math3D; public class OAK extends M_Player { static float OAK_FIND_RANGE = 700.00f; static float OAK_WALK = 16; static float OAK_RUN = 36; public static void OAK_Check_SP(edict_t ent) { // only spawn a bot in deathmatch if (GameBase.deathmatch.value != 0) { SP_Oak(); } else { GameBase.gi.cprintf(ent, Defines.PRINT_HIGH, "Sorry Oak II is a deathmatch only bot.\n"); } } /*************************************************************************** * * Function: oak_die * * Description: how to die * * Arguements: self inflictor attacker damage point * * Returns: void * **************************************************************************/ public static EntDieAdapter oak_die = new EntDieAdapter() { public void die(edict_t self, edict_t inflictor, edict_t attacker, int damage, float[] point) { int i; // throw the weapon GameBase.gi.sound(self, Defines.CHAN_BODY, GameBase.gi .soundindex("misc/udeath.wav"), 1, Defines.ATTN_NORM, 0); for (i = 0; i < 4; i++) GameAI.ThrowGib(self, "models/objects/gibs/sm_meat/tris.md2", damage, Defines.GIB_ORGANIC); self.takedamage = Defines.DAMAGE_NO; // respawn the bot OAK_Respawn(self); } }; /*************************************************************************** * * Function: oak_pain * * Description: what to do when hurt * * Arguements: self other - who hurt you kick damage * * Returns: void * **************************************************************************/ public static EntPainAdapter oak_pain = new EntPainAdapter() { public void pain(edict_t self, edict_t other, float kick, int damage) { GameBase.gi.bprintf(Defines.PRINT_HIGH, "Oak: in oak_pain ouch!\n"); OakAI_RunFrames(self, FRAME_pain101, FRAME_pain104); self.enemy = other; self.think = oak_painthink; self.nextthink = GameBase.level.time + 0.1f; self.monsterinfo.idle_time = GameBase.level.time + 0.3f; } }; /*************************************************************************** * * Function: SP_Oak * * Description: spawns a oak bot * * Arguements: void * * Returns: void * **************************************************************************/ public static void SP_Oak() { edict_t newOak; float spawn_origin[] = { 0, 0, 0 }, spawn_angles[] = { 0, 0, 0 }; // spawn the bot on a spawn spot newOak = GameUtil.G_Spawn(); PlayerClient.SelectSpawnPoint(newOak, spawn_origin, spawn_angles); Math3D.VectorCopy(spawn_origin, newOak.s.origin); newOak.s.origin[2] += 1; // make sure off ground newOak.classname = "bot"; newOak.takedamage = Defines.DAMAGE_AIM; newOak.movetype = Defines.MOVETYPE_STEP; newOak.mass = 200; newOak.solid = Defines.SOLID_BBOX; newOak.deadflag = Defines.DEAD_NO; newOak.clipmask = Defines.MASK_PLAYERSOLID; newOak.model = "players/male/tris.md2"; newOak.s.modelindex = 255; newOak.s.modelindex2 = 255; // custom gun model newOak.s.frame = 0; newOak.waterlevel = 0; newOak.watertype = 0; newOak.health = 100; newOak.max_health = 100; newOak.gib_health = -40; /* * FIXME err we need to set these!!! newOak.max_bullets = 200; * newOak.max_shells = 100; newOak.max_rockets = 50; newOak.max_grenades = * 50; newOak.max_cells = 200; newOak.max_slugs = 50; newOak.inuse = * true; */ // think functions? newOak.pain = oak_pain; newOak.die = oak_die; newOak.monsterinfo.stand = oak_stand; /* * FIXME err add these :) newOak.monsterinfo.walk = * newOak.monsterinfo.run = newOak.monsterinfo.dodge = * newOak.monsterinfo.attack = newOak.monsterinfo.melee = * newOak.monsterinfo.sight = newOak.monsterinfo.idle = */ newOak.monsterinfo.idle_time = 0; newOak.think = oak_stand; newOak.nextthink = GameBase.level.time + 1f; newOak.yaw_speed = 20; newOak.s.angles[Defines.PITCH] = 0; newOak.s.angles[Defines.YAW] = spawn_angles[Defines.YAW]; newOak.s.angles[Defines.ROLL] = 0; Math3D.VectorSet(newOak.mins, -16, -16, -32); Math3D.VectorSet(newOak.maxs, 16, 16, 32); Math3D.VectorClear(newOak.velocity); GameUtil.KillBox(newOak); GameBase.gi.linkentity(newOak); GameBase.gi.bprintf(Defines.PRINT_HIGH, "A Oak bot has entered the game\n"); } public static void OAK_Respawn(edict_t self) { float spawn_origin[] = { 0, 0, 0 }, spawn_angles[] = { 0, 0, 0 }; // spawn the bot on a spawn spot PlayerClient.SelectSpawnPoint(self, spawn_origin, spawn_angles); Math3D.VectorCopy(spawn_origin, self.s.origin); self.s.origin[2] += 1; // make sure off ground self.deadflag = Defines.DEAD_NO; self.takedamage = Defines.DAMAGE_AIM; self.model = "players/male/tris.md2"; self.s.modelindex = 255; self.s.modelindex2 = 255; // custom gun model self.s.frame = 0; self.waterlevel = 0; self.watertype = 0; self.health = 100; self.max_health = 100; self.gib_health = -40; self.pain = oak_pain; self.die = oak_die; self.monsterinfo.stand = oak_stand; Math3D.VectorSet(self.mins, -16, -16, -32); Math3D.VectorSet(self.maxs, 16, 16, 32); Math3D.VectorClear(self.velocity); self.think = oak_stand; self.nextthink = GameBase.level.time + 0.1f; GameUtil.KillBox(self); GameBase.gi.linkentity(self); GameBase.gi.bprintf(Defines.PRINT_HIGH, "A Oak bot has respawned\n"); } public static EntThinkAdapter oak_stand = new EntThinkAdapter() { public boolean think(edict_t self) { edict_t target; // gi.bprintf(PRINT_HIGH, "Oak: in oak_stand\n"); self.enemy = null; // look for a target EdictIterator edit = null; while (null != (edit = GameBase.findradius(edit, self.s.origin, OAK_FIND_RANGE))) { target = edit.o; if (GameUtil.visible(self, target)) { if (GameUtil.infront(self, target)) { if (target.classname.equals("player")) { GameBase.gi .bprintf(Defines.PRINT_HIGH, "Oak: in oak_stand selecting you as target\n"); self.enemy = target; } } } // next taget } if (self.enemy != null) { //gi.bprintf(PRINT_HIGH, "Oak: in oak_stand turning to face // you\n"); OakAI_FaceEnemy(self); OakAI_RunFrames(self, FRAME_run1, FRAME_run6); self.think = oak_run; } else { // run the anim frames OakAI_RunFrames(self, FRAME_stand01, FRAME_stand40); } self.nextthink = GameBase.level.time + 0.1f; return true; } }; /*************************************************************************** * * Function: oak_run * * Description: the general runaround think function * * Arguements: self * * Returns: void * **************************************************************************/ public static EntThinkAdapter oak_run = new EntThinkAdapter() { public boolean think(edict_t self) { OakAI_RunFrames(self, FRAME_run1, FRAME_run6); OakAI_FaceEnemy(self); OakAI_MoveToEnemy(self, OAK_RUN); self.nextthink = GameBase.level.time + 0.1f; return true; } }; public static EntThinkAdapter oak_painthink = new EntThinkAdapter() { public boolean think(edict_t self) { GameBase.gi.bprintf(Defines.PRINT_HIGH, "Oak: in oak_painthink running anim\n"); if (self.monsterinfo.idle_time >= GameBase.level.time) { OakAI_RunFrames(self, FRAME_pain101, FRAME_pain104); } else { self.think = oak_run; } self.nextthink = GameBase.level.time + 0.1f; return true; } }; /*************************************************************************** * * Function: OakAI_FaceEnemy * * Description: turn to face a enemy * * Arguements: self * * Returns: void * **************************************************************************/ public static void OakAI_FaceEnemy(edict_t self) { float v[] = { 0, 0, 0 }; Math3D.VectorSubtract(self.enemy.s.origin, self.s.origin, v); self.ideal_yaw = Math3D.vectoyaw(v); M.M_ChangeYaw(self); } /*************************************************************************** * * Function: OakAI_MoveToEnemy * * Description: moves bot towards a enemy assumes enemy dead ahead * * Arguements: self dist * * Returns: void * **************************************************************************/ public static void OakAI_MoveToEnemy(edict_t self, float dist) { OakAI_MoveToGoal(self, dist); } public static EntThinkAdapter oak_standclose = new EntThinkAdapter() { public boolean think(edict_t self) { double i; if (self.enemy != null && SV.SV_CloseEnough(self, self.enemy, OAK_RUN)) { if (((i = Math.random()) < 0.9) && (self.monsterinfo.idle_time < GameBase.level.time)) { OakAI_RunFrames(self, FRAME_stand01, FRAME_stand40); } else { if (self.monsterinfo.idle_time < GameBase.level.time) { self.monsterinfo.idle_time = GameBase.level.time + 1.0f; } OakAI_Wave(self); } } else { self.think = oak_stand; } self.nextthink = GameBase.level.time + 0.1f; return true; } }; public static void OakAI_MoveToGoal(edict_t ent, float dist) { edict_t goal; goal = ent.goalentity; if (ent.groundentity == null && 0 == (ent.flags & (Defines.FL_FLY | Defines.FL_SWIM))) return; if (ent.enemy != null && SV.SV_CloseEnough(ent, ent.enemy, dist)) { ent.think = oak_standclose; ent.nextthink = GameBase.level.time + 0.1f; return; } M.M_walkmove(ent, ent.ideal_yaw, dist); } /*************************************************************************** * * Animation Functions * **************************************************************************/ /*************************************************************************** * * Function: OakAI_RunFrames * * Description: runs the anim frames * * Arguements: start end * * Returns: void * **************************************************************************/ public static void OakAI_RunFrames(edict_t self, int start, int end) { if ((self.s.frame < end) && (self.s.frame >= start)) { self.s.frame++; } else { self.s.frame = start; } } /*************************************************************************** * * Function: OakAI_Finger * * Description: runs the anim frames * * Arguements: start end * * Returns: void * **************************************************************************/ public static void OakAI_Finger(edict_t self) { OakAI_RunFrames(self, FRAME_flip01, FRAME_flip12); } /*************************************************************************** * * Function: OakAI_Taunt * * Description: runs the anim frames * * Arguements: start end * * Returns: void * **************************************************************************/ public static void OakAI_Taunt(edict_t self) { OakAI_RunFrames(self, FRAME_taunt01, FRAME_taunt17); } /*************************************************************************** * * Function: OakAI_Wave * * Description: runs the anim frames * * Arguements: start end * * Returns: void * **************************************************************************/ public static void OakAI_Wave(edict_t self) { OakAI_RunFrames(self, FRAME_wave01, FRAME_wave11); } /*************************************************************************** * * Function: OakAI_Salute * * Description: runs the anim frames * * Arguements: start end * * Returns: void * **************************************************************************/ public static void OakAI_Salute(edict_t self) { OakAI_RunFrames(self, FRAME_salute01, FRAME_salute11); } /*************************************************************************** * * Function: OakAI_Point * * Description: runs the anim frames * * Arguements: start end * * Returns: void * **************************************************************************/ public static void OakAI_Point(edict_t self) { OakAI_RunFrames(self, FRAME_point01, FRAME_point12); } } |