X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Frace.qc;h=9cdfb7bcfab48ce9f0869b9e9dae81944eee24ff;hb=de295c2008095603d2d39b1bf1169370d60143b2;hp=fc5ba4d61b6dc50866360fb4e3a6cadb05cfe35e;hpb=e424ba544c41fc40b241b17bd7c1d9c2fc930705;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/race.qc b/qcsrc/server/race.qc index fc5ba4d61..9cdfb7bcf 100644 --- a/qcsrc/server/race.qc +++ b/qcsrc/server/race.qc @@ -9,11 +9,15 @@ #include "../common/deathtypes/all.qh" #include "../common/notifications/all.qh" #include "../common/mapinfo.qh" +#include #include "../common/triggers/subs.qh" #include "../lib/warpzone/util_server.qh" #include "../lib/warpzone/common.qh" #include "../common/mutators/mutator/waypoints/waypointsprites.qh" +IntrusiveList g_race_targets; +STATIC_INIT(g_race_targets) { g_race_targets = IL_NEW(); } + void race_InitSpectator() { if(g_race_qualifying) @@ -799,19 +803,36 @@ void trigger_race_checkpoint_verify(entity this) g_race_qualifying = qual; + IL_EACH(g_race_targets, true, + { + entity cpt = it; + FOREACH_ENTITY_STRING(target, cpt.targetname, + { + vector org = (this.absmin + this.absmax) * 0.5; + if(cpt.race_checkpoint == 0) + WaypointSprite_SpawnFixed(WP_RaceStart, org, it, sprite, RADARICON_NONE); + else + WaypointSprite_SpawnFixed(WP_RaceCheckpoint, org, it, sprite, RADARICON_NONE); + + it.sprite.waypointsprite_visible_for_player = race_waypointsprite_visible_for_player; + }); + }); + if (race_timed_checkpoint) { if (defrag_ents) { - for (entity cp = NULL; (cp = find(cp, classname, "target_startTimer"));) { - WaypointSprite_UpdateSprites(cp.sprite, WP_RaceStart, WP_Null, WP_Null); - } - for (entity cp = NULL; (cp = find(cp, classname, "target_stopTimer"));) { - WaypointSprite_UpdateSprites(cp.sprite, WP_RaceFinish, WP_Null, WP_Null); - } - for (entity cp = NULL; (cp = find(cp, classname, "target_checkpoint"));) { - if (cp.race_checkpoint == -2) { // something's wrong with the defrag cp file or it has not been written yet, set defragcpexists to -1 so that it will be rewritten when someone finishes - defragcpexists = -1; - } - } + IL_EACH(g_race_targets, true, + { + entity cpt = it; + if(it.classname == "target_startTimer" || it.classname == "target_stopTimer") { + FOREACH_ENTITY_STRING(target, cpt.targetname, { + WaypointSprite_UpdateSprites(it.sprite, ((cpt.classname == "target_startTimer") ? WP_RaceStart : WP_RaceFinish), WP_Null, WP_Null); + }); + } + if(it.classname == "target_checkpoint") { + if(it.race_checkpoint == -2) + defragcpexists = -1; // something's wrong with the defrag cp file or it has not been written yet, set defragcpexists to -1 so that it will be rewritten when someone finishes + } + }); if (defragcpexists != -1) { float largest_cp_id = 0; for (entity cp = NULL; (cp = find(cp, classname, "target_checkpoint"));) { @@ -832,15 +853,14 @@ void trigger_race_checkpoint_verify(entity this) race_timed_checkpoint = 255; } } else { - for (entity cp = NULL; (cp = find(cp, classname, "trigger_race_checkpoint")); ) { - if (cp.sprite) { - if (cp.race_checkpoint == 0) { - WaypointSprite_UpdateSprites(cp.sprite, WP_RaceStart, WP_Null, WP_Null); - } else if (cp.race_checkpoint == race_timed_checkpoint) { - WaypointSprite_UpdateSprites(cp.sprite, WP_RaceFinish, WP_Null, WP_Null); - } + IL_EACH(g_racecheckpoints, it.sprite, + { + if (it.race_checkpoint == 0) { + WaypointSprite_UpdateSprites(it.sprite, WP_RaceStart, WP_Null, WP_Null); + } else if (it.race_checkpoint == race_timed_checkpoint) { + WaypointSprite_UpdateSprites(it.sprite, WP_RaceFinish, WP_Null, WP_Null); } - } + }); } } @@ -913,7 +933,7 @@ spawnfunc(trigger_race_checkpoint) settouch(this, checkpoint_touch); o = (this.absmin + this.absmax) * 0.5; - tracebox(o, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), o - '0 0 1' * (o.z - this.absmin.z), MOVE_NORMAL, this); + tracebox(o, PL_MIN_CONST, PL_MAX_CONST, o - '0 0 1' * (o.z - this.absmin.z), MOVE_NORMAL, this); waypoint_spawnforitem_force(this, trace_endpos); this.nearestwaypointtimeout = time + 1000000000; @@ -946,25 +966,36 @@ spawnfunc(trigger_race_checkpoint) this.sprite.waypointsprite_visible_for_player = race_waypointsprite_visible_for_player; this.spawn_evalfunc = trigger_race_checkpoint_spawn_evalfunc; + IL_PUSH(g_racecheckpoints, this); + InitializeEntity(this, trigger_race_checkpoint_verify, INITPRIO_FINDTARGET); } spawnfunc(target_checkpoint) // defrag entity { - vector o; if(!g_race && !g_cts) { delete(this); return; } defrag_ents = 1; - EXACTTRIGGER_INIT; + // if this is targeted, then it probably isn't a trigger + bool is_trigger = !boolean(!this.nottargeted && this.targetname != ""); + + if(is_trigger) + EXACTTRIGGER_INIT; this.use = checkpoint_use; - if (!(this.spawnflags & 1)) + if (is_trigger && !(this.spawnflags & 1)) settouch(this, checkpoint_touch); - o = (this.absmin + this.absmax) * 0.5; - tracebox(o, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), o - '0 0 1' * (o.z - this.absmin.z), MOVE_NORMAL, this); - waypoint_spawnforitem_force(this, trace_endpos); - this.nearestwaypointtimeout = time + 1000000000; + vector org = this.origin; + + // bots should only pathfind to this if it is a valid touchable trigger + if(is_trigger) + { + org = (this.absmin + this.absmax) * 0.5; + tracebox(org, PL_MIN_CONST, PL_MAX_CONST, org - '0 0 1' * (org.z - this.absmin.z), MOVE_NORMAL, this); + waypoint_spawnforitem_force(this, trace_endpos); + this.nearestwaypointtimeout = time + 1000000000; + } if(this.message == "") this.message = "went backwards"; @@ -980,12 +1011,7 @@ spawnfunc(target_checkpoint) // defrag entity race_timed_checkpoint = 1; - if(this.race_checkpoint == 0) - WaypointSprite_SpawnFixed(WP_RaceStart, o, this, sprite, RADARICON_NONE); - else - WaypointSprite_SpawnFixed(WP_RaceCheckpoint, o, this, sprite, RADARICON_NONE); - - this.sprite.waypointsprite_visible_for_player = race_waypointsprite_visible_for_player; + IL_PUSH(g_race_targets, this); InitializeEntity(this, trigger_race_checkpoint_verify, INITPRIO_FINDTARGET); } @@ -1142,7 +1168,7 @@ float race_GetFractionalLapCount(entity e) vector o0, o1; float bestfraction, fraction; - entity lastcp, cp0, cp1; + entity lastcp; float nextcpindex, lastcpindex; nextcpindex = max(e.race_checkpoint, 0); @@ -1153,26 +1179,26 @@ float race_GetFractionalLapCount(entity e) return l; // finish bestfraction = 1; - for(cp0 = NULL; (cp0 = find(cp0, classname, "trigger_race_checkpoint")); ) + IL_EACH(g_racecheckpoints, true, { - if(cp0.race_checkpoint != lastcpindex) + if(it.race_checkpoint != lastcpindex) continue; if(lastcp) - if(cp0 != lastcp) + if(it != lastcp) continue; - o0 = (cp0.absmin + cp0.absmax) * 0.5; - for(cp1 = NULL; (cp1 = find(cp1, classname, "trigger_race_checkpoint")); ) + o0 = (it.absmin + it.absmax) * 0.5; + IL_EACH(g_racecheckpoints, true, { - if(cp1.race_checkpoint != nextcpindex) + if(it.race_checkpoint != nextcpindex) continue; - o1 = (cp1.absmin + cp1.absmax) * 0.5; + o1 = (it.absmin + it.absmax) * 0.5; if(o0 == o1) continue; fraction = bound(0.0001, vlen(e.origin - o1) / vlen(o0 - o1), 1); if(fraction < bestfraction) bestfraction = fraction; - } - } + }); + }); // we are at CP "nextcpindex - bestfraction" // race_timed_checkpoint == 4: then nextcp==4 means 0.9999x, nextcp==0 means 0.0000x