/* =========================================================================== Copyright (C) 2015 the OpenMoHAA team This file is part of OpenMoHAA source code. OpenMoHAA source code 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. OpenMoHAA source code 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 OpenMoHAA source code; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA =========================================================================== */ // player_util.cpp: This file is used to hold the utility functions that are issued by the // player at the console. Most of these are developer commands #include "player.h" #include "object.h" #include "g_spawn.h" #include "scriptexception.h" extern Event EV_Entity_Start; //==================== //Player::ActorInfo //==================== void Player::ActorInfo ( Event *ev ) { int num; Entity *ent; if ( ev->NumArgs() != 1 ) { gi.SendServerCommand( edict-g_entities, "print \"Usage: actorinfo \n\"" ); return; } num = ev->GetInteger( 1 ); if ( ( num < 0 ) || ( num >= globals.max_entities ) ) { gi.SendServerCommand( edict-g_entities, "print \"Value out of range. Possible values range from 0 to %d.\n\"", globals.max_entities ); return; } ent = G_GetEntity( num ); if ( !ent || !ent->isSubclassOf( Actor ) ) { gi.SendServerCommand( edict-g_entities, "print \"Entity not an Actor.\n\"" ); } else { ( ( Actor * )ent )->ShowInfo(); } } //==================== //Player::WhatIs //==================== void Player::WhatIs ( Event *ev ) { int num; Entity *ent; if ( ev->NumArgs() != 1 ) { gi.SendServerCommand( edict-g_entities, "print \"Usage: whatis \n\"" ); return; } num = ev->GetInteger( 1 ); if ( ( num < 0 ) || ( num >= globals.max_entities ) ) { gi.SendServerCommand( edict-g_entities, "print \"Value out of range. Possible values range from 0 to %d.\n\"", globals.max_entities ); return; } ent = G_GetEntity( num ); if ( !ent ) { gi.SendServerCommand( edict-g_entities, "print \"Entity not in use.\n\"", globals.max_entities ); } else { const char * animname; animname = NULL; if ( gi.modeltiki( ent->model ) ) { animname = gi.Anim_NameForNum( ent->edict->tiki, ent->edict->s.frameInfo[ 0 ].index & ANIM_MASK ); } if ( !animname ) { animname = "( N/A )"; } gi.SendServerCommand( edict-g_entities, "print \"" "Entity # : %d\n" "Class ID : %s\n" "Classname : %s\n" "Targetname : %s\n" "Modelname : %s\n" "Animname : %s\n" "Origin : ( %f, %f, %f )\n" "Angles : ( %f, %f, %f )\n" "Bounds : Mins( %.2f, %.2f, %.2f ) Maxs( %.2f, %.2f, %.2f )\n" "Velocity : ( %f, %f, %f )\n" "SVFLAGS : %x\n" "Movetype : %i\n" "Solidtype : %i\n" "Contents : %x\n" "Areanum : %i\n" "Parent : %i\n" "Health : %.1f\n" "Max Health : %.1f\n" "Edict Owner: %i\n\"", num, ent->getClassID(), ent->getClassname(), ent->TargetName().c_str(), ent->model.c_str(), animname, ent->origin.x, ent->origin.y, ent->origin.z, ent->angles.x, ent->angles.y, ent->angles.z, ent->mins.x, ent->mins.y, ent->mins.z, ent->maxs.x, ent->maxs.y, ent->maxs.z, ent->velocity.x, ent->velocity.y, ent->velocity.z, ent->edict->r.svFlags, ent->movetype, ent->edict->solid, ent->edict->r.contents, ent->edict->r.areanum, ent->edict->s.parent, ent->health, ent->max_health, ent->edict->r.ownerNum ); } } //==================== //Player::KillEnt //==================== void Player::KillEnt ( Event * ev ) { int num; Entity *ent; if ( ev->NumArgs() != 1 ) { gi.SendServerCommand( edict-g_entities, "print \"Usage: killent \n\"" ); return; } num = ev->GetInteger( 1 ); if ( ( num < 0 ) || ( num >= globals.max_entities ) ) { gi.SendServerCommand( edict-g_entities, "print \"Value out of range. Possible values range from 0 to %d.\n\"", globals.max_entities ); return; } ent = G_GetEntity( num ); ent->Damage( world, world, ent->max_health + 25, origin, vec_zero, vec_zero, 0, 0, 0 ); } //==================== //Player::RemoveEnt //==================== void Player::RemoveEnt ( Event * ev ) { int num; Entity *ent; if ( ev->NumArgs() != 1 ) { gi.SendServerCommand( edict-g_entities, "print \"Usage: removeent \n\"" ); return; } num = ev->GetInteger( 1 ); if ( ( num < 0 ) || ( num >= globals.max_entities ) ) { gi.SendServerCommand( edict-g_entities, "print \"Value out of range. Possible values range from 0 to %d.\n\"", globals.max_entities ); return; } ent = G_GetEntity( num ); ent->PostEvent( Event( EV_Remove ), 0 ); } //==================== //Player::KillClass //==================== void Player::KillClass ( Event * ev ) { int except; str classname; gentity_t * from; Entity *ent; if ( ev->NumArgs() < 1 ) { gi.SendServerCommand( edict-g_entities, "print \"Usage: killclass [except entity number]\n\"" ); return; } classname = ev->GetString( 1 ); except = 0; if ( ev->NumArgs() == 2 ) { except = ev->GetInteger( 1 ); } for ( from = this->edict + 1; from < &g_entities[ globals.num_entities ]; from++ ) { if ( !from->inuse ) { continue; } assert( from->entity ); ent = from->entity; if ( ent->entnum == except ) { continue; } if ( ent->inheritsFrom( classname.c_str() ) ) { ent->Damage( world, world, ent->max_health + 25, origin, vec_zero, vec_zero, 0, 0, 0 ); } } } //==================== //Player::RemoveClass //==================== void Player::RemoveClass ( Event * ev ) { int except; str classname; gentity_t * from; Entity *ent; if ( ev->NumArgs() < 1 ) { gi.SendServerCommand( edict-g_entities, "print \"Usage: removeclass [except entity number]\n\"" ); return; } classname = ev->GetString( 1 ); except = 0; if ( ev->NumArgs() == 2 ) { except = ev->GetInteger( 1 ); } for ( from = this->edict + 1; from < &g_entities[ globals.num_entities ]; from++ ) { if ( !from->inuse ) { continue; } assert( from->entity ); ent = from->entity; if ( ent->entnum == except ) continue; if ( ent->inheritsFrom( classname.c_str() ) ) { ent->PostEvent( Event( EV_Remove ), 0 ); } } } //==================== //Player::TestThread //==================== void Player::TestThread ( Event *ev ) { const char *scriptfile; const char *label = NULL; if ( ev->NumArgs() < 1 ) { gi.SendServerCommand( edict-g_entities, "print \"Syntax: testthread scriptfile