Finished work on selfdestruct

Countdown Clock is working
Overall script is working again
removed some unused stuff
added a few more failsafes
did some finetuning

sometimes the sounds don't trigger but I don't think that is my fault...

Signed-off-by: Harry Young <hendrik.gerritzen@googlemail.com>
This commit is contained in:
Harry Young 2013-01-08 13:54:13 +01:00
parent b99a372ff1
commit ec431c010a
5 changed files with 89 additions and 77 deletions

View file

@ -1841,25 +1841,25 @@ static float CG_DrawSelfdestructTimer( void ) {
int mins, tens, seconds, remainder;
int msec;
//cgs.selfdestructTime = 60000; test value just to see if it works as intended
msec = cgs.selfdestructTime - cg.time;
msec = cg.selfdestructTime - cg.time;
if (msec < 0)
return 0;
if (msec > 0){
mins = msec / 60000;
tens = (msec - (mins * 60000)) / 10000;
seconds = (msec - (mins * 60000) - (tens * 10000)) / 1000;
remainder = msec - (mins * 60000) - (tens * 10000) - (seconds * 1000);
mins = msec / 60000;
tens = (msec - (mins * 60000)) / 10000;
seconds = (msec - (mins * 60000) - (tens * 10000)) / 1000;
remainder = msec - (mins * 60000) - (tens * 10000) - (seconds * 1000);
s = va( "%i:%i%i.%i", mins, tens, seconds, remainder );
w = UI_ProportionalStringWidth("SELF-DESTRTUCT IN",UI_SMALLFONT);
UI_DrawProportionalString(320 - (w / 2), 10, "SELF-DESTRTUCT IN", UI_SMALLFONT, colorTable[CT_RED]);
w = UI_ProportionalStringWidth(s,UI_SMALLFONT);
UI_DrawProportionalString(320 - (w / 2), 30, s, UI_SMALLFONT, colorTable[CT_RED]);
s = va( "%i:%i%i.%i", mins, tens, seconds, remainder );
w = UI_ProportionalStringWidth("SELF-DESTRTUCT IN",UI_SMALLFONT);
UI_DrawProportionalString(320 - (w / 2), 10, "SELF-DESTRTUCT IN", UI_SMALLFONT, colorTable[CT_RED]);
w = UI_ProportionalStringWidth(s,UI_SMALLFONT);
UI_DrawProportionalString(320 - (w / 2), 30, s, UI_SMALLFONT, colorTable[CT_RED]);
}
return 0;
}

View file

@ -451,7 +451,7 @@ void CG_EntityEvent( centity_t *cent, vec3_t position ) {
int clientNum;
clientInfo_t *ci;
vec3_t normal = { 0, 0, 1 };
int a, b;
int a, b, temp;
refEntity_t legs;
refEntity_t torso;
@ -1828,31 +1828,27 @@ case EV_SHAKE_SOUND:
case EV_SELFDESTRUCT_SETTER:
DEBUGNAME("EV_SELFDESTRUCT_SETTER");
trap_Print(va("cgs.selfdestructTime preset is %i", cgs.selfdestructTime));
if(cent->currentState.eventParm == -1)
cgs.selfdestructTime = -1;
temp = cent->currentState.eventParm * 60000 + cent->currentState.powerups;
if(temp == -1)
cg.selfdestructTime = -1;
else
cgs.selfdestructTime = cent->currentState.eventParm + cg.time;
trap_Print(va("cgs.selfdestructTime postset is %i", cgs.selfdestructTime));
cg.selfdestructTime = temp + cg.time;
break;
case EV_HULLHEALTH_SETTER:
DEBUGNAME("EV_HULLHEALTH_SETTER");
if(cent->currentState.eventParm == -1)
cgs.relativeHullStrength = -1;
cg.relativeHullStrength = -1;
else
cgs.relativeHullStrength = cent->currentState.eventParm;
cg.relativeHullStrength = cent->currentState.eventParm;
break;
case EV_SHIELDHEALTH_SETTER:
DEBUGNAME("EV_SHIELDHEALTH_SETTER");
if(cent->currentState.eventParm == -1)
cgs.relativeShieldStrength = -1;
cg.relativeShieldStrength = -1;
else
cgs.relativeShieldStrength = cent->currentState.eventParm;
cg.relativeShieldStrength = cent->currentState.eventParm;
break;
// Default

View file

@ -1009,6 +1009,13 @@ typedef struct {
// cinematics
int cinematicFade;
// selfdestruct
int selfdestructTime;
// shiphealth
int relativeHullStrength;
int relativeShieldStrength;
} cg_t;
@ -1493,13 +1500,6 @@ typedef struct {
char scannableStrings[MAX_SCANNABLES][36];
qboolean scannablePanels;
// selfdestruct
int selfdestructTime;
// shiphealth
int relativeHullStrength;
int relativeShieldStrength;
} cgs_t;
//==============================================================================

View file

@ -5795,29 +5795,27 @@ static void Cmd_selfdestruct_f(gentity_t *ent) {
destructEnt = G_Spawn();
destructEnt->classname = "target_selfdestruct";
destructEnt->wait = atoi(arg2);
destructEnt->flags = atoi(arg6);
destructEnt->spawnflags = atoi(arg6);
destructEnt->bluename = G_NewString(arg7);
destructEnt->target = G_NewString(arg8);
destructEnt->spawnflags = 1; //tells ent to free once aborted.
//we need to check a few things here to make sure the entity works properly. Else we free it.
if ( destructEnt->wait <= 0 ){
if ( destructEnt->wait <= 0 )
G_PrintfClient(ent, "^1ERROR: duration must not be 0. Removing entity.");
while((safezone = G_Find(safezone, FOFS(classname), "target_safezone")) != NULL){
if(!destructEnt->bluename && safezone->spawnflags & 2){
G_PrintfClient(ent, "^1ERROR: safezone must be given for maps consisting of multiple ships/stations (like rpg_runabout). For a list of safezonesuse the safezonelist command. Removing entity.");
destructEnt->wait = 0; //we'll use this next to free the ent
break;
}
while((safezone = G_Find(safezone, FOFS(classname), "target_safezone")) != NULL){
if(!destructEnt->bluename && safezone->spawnflags & 2){
G_PrintfClient(ent, "^1ERROR: safezone must be given for maps consisting of multiple ships/stations (like rpg_runabout). For a list of safezonesuse the safezonelist command. Removing entity.");
destructEnt->wait = 0; //we'll use this next to free the ent
break;
}
if(destructEnt->wait <= 0)
G_FreeEntity(destructEnt);
else
G_CallSpawn(destructEnt);
return;
}
if(destructEnt->wait <= 0)
G_FreeEntity(destructEnt);
else
G_CallSpawn(destructEnt);
return;
} else if (!Q_stricmp(arg, "remaining")) {
//Is there sth running alrerady?
destructEnt = G_Find(NULL, FOFS(classname), "target_selfdestruct");
@ -5826,12 +5824,15 @@ static void Cmd_selfdestruct_f(gentity_t *ent) {
return;
}
if(destructEnt->flags == 1)
if(destructEnt->spawnflags == 1)
return; //we simply don't need this while there is a visible countdown.
//we need the remaining time in minutes and seconds from that entity. Just ask them off and have the command do the math.
ETAsec = floor(modf((( floor(destructEnt->damage / 1000) - floor(level.time / 1000) ) / 60), &ETAmin)*60); //break it apart, put off the minutes and return the floored secs
trap_SendServerCommand( -1, va("servermsg \"^1Self Destruct in %.0f:%2.0f\"", ETAmin, ETAsec ));
if(ETAsec / 10 < 1) //get leading 0 for secs
trap_SendServerCommand( -1, va("servermsg \"^1Self Destruct in %.0f:0%.0f\"", ETAmin, ETAsec ));
else
trap_SendServerCommand( -1, va("servermsg \"^1Self Destruct in %.0f:%.0f\"", ETAmin, ETAsec ));
} else if (!Q_stricmp(arg, "abort")) {
//Is there sth running alrerady?
destructEnt = G_Find(NULL, FOFS(classname), "target_selfdestruct");

View file

@ -2660,7 +2660,7 @@ void SP_target_shaderremap(gentity_t *ent) {
}
//RPG-X | Harry Young | 15/10/2011 | MOD END
//RPG-X | Harry Young | 25/07/2012 | MOD START
//RPG-X | Harry Young | 25/07/2012 | MOD START AUDIO_ON
/*QUAKED target_selfdestruct (1 0 0) (-8 -8 -8) (8 8 8)
-----DESCRIPTION-----
DO NOT USE! This just sits here purely for documantation.
@ -2669,7 +2669,7 @@ For now this should only be used via the selfdestruct console command, however i
Should this thing hit 0 the killing part for everyone outside a target_safezone will be done automatically.
-----SPAWNFLAGS-----
none
1: AUDIO_ON - tells the script to display the countdown
-----KEYS-----
"wait" - total Countdown-Time in secs
@ -2725,15 +2725,16 @@ static int target_selfdestruct_get_unsafe_players(gentity_t *ents[MAX_GENTITIES]
}
void target_selfdestruct_use(gentity_t *ent, gentity_t *other, gentity_t *activator) {
if(ent->wait > 50 || (ent->spawnflags & 2 && ent->wait > 100)){//if we listed the safezones we're committed
if( ent->damage - level.time > 50 ){//if we listed the safezones we're committed
//with the use-function we're going to init aborts in a fairly simple manner: Fire warning notes...
trap_SendServerCommand( -1, va("servermsg \"Self Destruct sequence aborted.\""));
G_AddEvent(ent, EV_GLOBAL_SOUND, G_SoundIndex("sound/voice/selfdestruct/abort.mp3"));
//set wait to -1...
ent->wait = -1;
G_AddEvent( ent, EV_SELFDESTRUCT_SETTER, -1 );
//and arrange for a think in a sec
ent->nextthink = level.time + 1000;
//zero out clock...
ent->s.powerups = 0;
//and arrange for a think
ent->nextthink = level.time + 50;
}
return;
}
@ -2741,7 +2742,7 @@ void target_selfdestruct_use(gentity_t *ent, gentity_t *other, gentity_t *activa
void target_selfdestruct_think(gentity_t *ent) {
gentity_t* client;
gentity_t *healthEnt, *safezone=NULL;
int i = 0;
int i = 0, mins = 0;
//this is for calling the safezones to list. It needs to stand here to not screw up the remainder of the think.
if (ent->wait == 50) {
@ -2756,9 +2757,17 @@ void target_selfdestruct_think(gentity_t *ent) {
return;
}
if (ent->wait > 0){
//Send a sznc/signal to all clients
G_AddEvent( ent, EV_SELFDESTRUCT_SETTER, ( ent->damage - level.time ));
if (ent->wait > 0 && ent->spawnflags == 1 ){
//Send a sync/signal to all clients
ent->s.powerups = ent->damage - level.time;
if(ent->s.powerups > 60000){
mins = ent->s.powerups / 60000;
ent->s.powerups = ent->s.powerups - (60000 * mins);
G_AddEvent( ent, EV_SELFDESTRUCT_SETTER, mins );
}
else
G_AddEvent( ent, EV_SELFDESTRUCT_SETTER, mins );
ent->nextthink = level.time + 10000;
//fail horribly if we overshoot bang-time
@ -2801,16 +2810,19 @@ void target_selfdestruct_think(gentity_t *ent) {
if(ent->target)
G_UseTargets(ent, ent);
//we're done here so let's finish up in a sec.
ent->s.powerups = 0;
ent->wait = -1;
ent->nextthink = level.time + 1000;
return;
} else if (ent->wait < 0) {
} else if (ent->wait == -1) {
//we have aborted and the note should be out or ended and everyone should be dead so let's reset
ent->nextthink = -1;
G_AddEvent( ent, EV_SELFDESTRUCT_SETTER, -1 );
ent->nextthink = level.time + 50;//give the event time to be conducted
G_AddEvent( ent, EV_SELFDESTRUCT_SETTER, 0 );
ent->wait = -2;
return;
} else if (ent->wait == -2) {
G_FreeEntity(ent);
return; //And we're done.
}
}
@ -2841,9 +2853,6 @@ void SP_target_selfdestruct(gentity_t *ent) {
ent->splashRadius = 1;
}
if(ent->flags == 1)
G_AddEvent( ent, EV_SELFDESTRUCT_SETTER, ent->wait );
//we' may need the total for something so back it up...
ent->splashDamage = ent->wait;
@ -2852,10 +2861,16 @@ void SP_target_selfdestruct(gentity_t *ent) {
//time's set so let's let everyone know that we're counting. I'll need to do a language switch here sometime...
ETAsec = floor(modf((ent->wait / 60000), &ETAmin)*60);
if (ent->flags == 1)
trap_SendServerCommand( -1, va("servermsg \"^1Self Destruct in %.0f:%2.0f\"", ETAmin, ETAsec ));
if (ent->spawnflags == 1)
if(ETAsec / 10 < 1) //get leading 0 for secs
trap_SendServerCommand( -1, va("servermsg \"^1Self Destruct in %.0f:0%.0f\"", ETAmin, ETAsec ));
else
trap_SendServerCommand( -1, va("servermsg \"^1Self Destruct in %.0f:0%.0f\"", ETAmin, ETAsec ));
else
trap_SendServerCommand( -1, va("servermsg \"^1Self Destruct in %.0f:%2.0f; There will be no further audio warnings.\"", ETAmin, ETAsec ));
if(ETAsec / 10 < 1) //get leading 0 for secs
trap_SendServerCommand( -1, va("servermsg \"^1Self Destruct in %.0f:0%.0f; There will be no ^1further audio warnings.\"", ETAmin, ETAsec ));
else
trap_SendServerCommand( -1, va("servermsg \"^1Self Destruct in %.0f:%.0f; There will be no ^1further audio warnings.\"", ETAmin, ETAsec ));
ent->r.svFlags |= SVF_BROADCAST;
trap_LinkEntity(ent);
@ -2863,19 +2878,19 @@ void SP_target_selfdestruct(gentity_t *ent) {
if (ent->wait == 1200000) {
G_AddEvent(ent, EV_GLOBAL_SOUND, G_SoundIndex("sound/voice/selfdestruct/20-a1.mp3"));
} else if (ent->wait == 900000) {
if (ent->flags == 1 )
if (ent->spawnflags == 1 )
G_AddEvent(ent, EV_GLOBAL_SOUND, G_SoundIndex("sound/voice/selfdestruct/15-a1.mp3"));
else
G_AddEvent(ent, EV_GLOBAL_SOUND, G_SoundIndex("sound/voice/selfdestruct/15-a0.mp3"));
} else if (ent->wait == 600000) {
G_AddEvent(ent, EV_GLOBAL_SOUND, G_SoundIndex("sound/voice/selfdestruct/10-a1.mp3"));
} else if (ent->wait == 300000) {
if (ent->flags == 1 )
if (ent->spawnflags == 1 )
G_AddEvent(ent, EV_GLOBAL_SOUND, G_SoundIndex("sound/voice/selfdestruct/5-a1.mp3"));
else
G_AddEvent(ent, EV_GLOBAL_SOUND, G_SoundIndex("sound/voice/selfdestruct/5-a0.mp3"));
} else {
if (ent->flags == 1 )
if (ent->spawnflags == 1 )
G_AddEvent(ent, EV_GLOBAL_SOUND, G_SoundIndex("sound/voice/selfdestruct/X-a1.mp3"));
else
G_AddEvent(ent, EV_GLOBAL_SOUND, G_SoundIndex("sound/voice/selfdestruct/X-a0.mp3"));
@ -2886,8 +2901,8 @@ void SP_target_selfdestruct(gentity_t *ent) {
ent->use = target_selfdestruct_use;
ent->think = target_selfdestruct_think;
if(ent->flags == 1)
ent->nextthink = level.time + 10000; // let's hardcode this, will send refresher signals in case new clients connect.
if(ent->spawnflags == 1)
ent->nextthink = level.time + 50; // init clock over there... somehow doesn't work in spawnfunc...
else
ent->nextthink = ent->damage;