More work on torpedo relaod command

should be finished now

Signed-off-by: Harry Young <hendrik.gerritzen@googlemail.com>
This commit is contained in:
Harry Young 2013-01-12 17:20:27 +01:00
parent c2e135da16
commit 76c0d8fea6
2 changed files with 65 additions and 37 deletions

View File

@ -921,6 +921,7 @@ void CG_InitConsoleCommands( void ) {
trap_AddCommand("shipdamage");
trap_AddCommand("shiphealth");
trap_AddCommand("reloadtorpedos");
trap_AddCommand("torpedolist");
/* precacheFile */
trap_AddCommand("generatePrecacheFile");

View File

@ -6004,7 +6004,7 @@ Harry Young | 12/01/2013
=================
*/
static void Cmd_reloadtorpedos_f(gentity_t *ent) {
gentity_t *torpedo=NULL, *single;
gentity_t *torpedo=NULL;
char arg[16];
char target[512];
@ -6020,11 +6020,20 @@ static void Cmd_reloadtorpedos_f(gentity_t *ent) {
}
#endif
if(trap_Argc() == 0){
G_PrintfClient(ent, "Usage: reloadtorpedos [amount] [target] where amount is the number of torpedos the launcher will have after the command executed.\n");
G_PrintfClient(ent, "Set 0 to depleet, set -1 to max out. You can not load more torpedos than the entity was designed for. If you do it will just Max out.\n");
G_PrintfClient(ent, "target is the specific targetname of the fx_torpedo that shall be reloaded and needs to be entered if there is a map with multiple fx_torpedo's with limited stock.\n");
G_PrintfClient(ent, "If set to all every limited launcher on the map will be set to amount or maxed out accordingly.\n");
trap_Argv(1, arg, sizeof(arg));
trap_Argv(2, target, sizeof(target));
if(atoi(arg) == 0 || !Q_stricmp(target, "")){
G_PrintfClient(ent, "Usage: reloadtorpedos [amount] [target] where amount is the number of torpedos the launcher will have after the command executed.");
G_PrintfClient(ent, "Set -2 to depleet, set -1 to max out. You can not load more torpedos than the entity was designed for. If you do it will just Max out.");
G_PrintfClient(ent, "target is the specific targetname of the fx_torpedo that shall be reloaded.");
G_PrintfClient(ent, "If set to all every limited launcher on the map will be set to amount or maxed out accordingly.");
G_PrintfClient(ent, "The targetnames can be extracted trough the command torpedolist.");
return;
}
if(atoi(arg) < -2){
G_PrintfClient(ent, "^1ERROR: amount must not be less than -2, aborting call.\n");
return;
}
@ -6033,41 +6042,57 @@ static void Cmd_reloadtorpedos_f(gentity_t *ent) {
return;
}
trap_Argv(1, arg, sizeof(arg));
if(trap_Argc() > 1){ //we have a specific targets or all entities shall be restocked, so let's go with that
Q_strncpyz( target, ConcatArgs( 2 ), sizeof( target ) );
while((torpedo = G_Find(torpedo, FOFS(classname), "fx_torpedo")) != NULL){
if(!Q_stricmp(torpedo->targetname, target) || !Q_stricmp(target, "all")){ //this entity is generally affectable
if(torpedo->damage > 0){ //we only need to consider this for restock if it is restockable
if(atoi(arg) < 0 || atoi(arg) > torpedo->damage)
if(atoi(arg) == -1 || atoi(arg) > torpedo->damage)
torpedo->count = torpedo->damage;
else if(atoi(arg) == -2)
torpedo->count = 0;
else
torpedo->count = atoi(arg);
}
}
}
return;
} else {
while((torpedo = G_Find(torpedo, FOFS(classname), "fx_torpedo")) != NULL){
if(torpedo->damage < 0)//we can ignore unlimited supplies, we're just concerned with limits, which need to be specific
continue;
else { //something with stock
single = torpedo; //if this is the only one we finish it right away
while((torpedo = G_Find(torpedo, FOFS(classname), "fx_torpedo")) != NULL){
if(torpedo->damage > 0){// we have 2 with stock so we can be wrong. Inform admin and abort
trap_SendServerCommand( ent-g_entities, va("print \"^1 ERROR: This map has more than one fx_torpedo with limited supply, therefore a target or all needs to be specified. Aborting call.\n\"" ) );
return;
}
}//if we got here we only have one entity to restock, so let's do that
if(atoi(arg) < 0 || atoi(arg) > single->damage)
single->count = single->damage;
}
/*
=================
Cmd_torpedolist_f
Harry Young | 02/11/2012
=================
*/
static void Cmd_torpedolist_f(gentity_t *ent) {
gentity_t *torpedo=NULL;
#ifndef SQL
if ( !IsAdmin( ent ) ) {
trap_SendServerCommand( ent-g_entities, va("print \"ERROR: You are not logged in as an admin.\n\" ") );
return;
}
#else
if ( !IsAdmin( ent ) || !G_Sql_UserDB_CheckRight(ent->client->uid, SQLF_SMS ) ) {
trap_SendServerCommand( ent-g_entities, va("print \"ERROR: You are not logged in as a user with the appropiate rights.\n\" ") );
return;
}
#endif
trap_SendServerCommand( ent-g_entities, va("print \"\nList of fx_torpedo-entities on this map: \n\n\""));
while((torpedo = G_Find(torpedo, FOFS(classname), "fx_torpedo")) != NULL){
trap_SendServerCommand( ent-g_entities, va("print \"Name of fx_torpedo: %s \n\"", torpedo->targetname ));
if(torpedo->spawnflags & 1)
trap_SendServerCommand( ent-g_entities, va("print \"Type: Quantum \n\""));
else
single->count = atoi(arg);
return;
}
trap_SendServerCommand( ent-g_entities, va("print \"Type: Photon \n\""));
if(torpedo->count == -1)
trap_SendServerCommand( ent-g_entities, va("print \"Amount: Unlimited\n\n\""));
else{
trap_SendServerCommand( ent-g_entities, va("print \"Current Amount: %i \n\"", torpedo->count));
trap_SendServerCommand( ent-g_entities, va("print \"Maximum Amount: %i \n\n\"", torpedo->damage));
}
}
trap_SendServerCommand( ent-g_entities, va("print \"End of list \n\n\""));
}
/*
@ -7702,8 +7727,10 @@ void G_Client_Command( int clientNum )
Cmd_shipdamage_f(ent);
else if (Q_stricmp(cmd, "shiphealth") == 0)
Cmd_shiphealth_f(ent);
else if (Q_stricmp(cmd, "Cmd_reloadtorpedos_f") == 0)
else if (Q_stricmp(cmd, "reloadtorpedos") == 0)
Cmd_reloadtorpedos_f(ent);
else if (Q_stricmp(cmd, "torpedolist") == 0)
Cmd_torpedolist_f(ent);
else if (Q_stricmp(cmd, "msg2") == 0)
Cmd_admin_centerprint_f(ent);
else if (Q_stricmp(cmd, "forcevote") == 0)