Implemented `coop_elevator_delay` cvar (for func_plat)

In coop it's often hard to get on the same elevator together, because
they're immediately triggered once the first player steps on it.
This cvar sets a delay (1 second by default) for the elevator to wait
before moving, so other players have some time to get on it.
If you like elevators/platforms that suck, just set it to `0` :-P

Currently only used in func_plat, if it turns out that other entities
are used for automatically triggered platforms, we'll have to adapt
those as well (I guess wait_and_change() is generally useful for that).

We're not bumping the savegame version because they should only break in
an uncommon corner case: *Coop* savegames created with clients including
this change will not work on older clients - SP savegames are not
affected and old savegames on new clients also still work.
This commit is contained in:
Yamagi 2020-08-10 14:06:14 +02:00
parent 82f9f01d6b
commit c1e438e697
6 changed files with 40 additions and 2 deletions

View File

@ -579,6 +579,39 @@ Use_Plat(edict_t *ent, edict_t *other /* unused */, edict_t *activator /* unused
plat_go_down(ent);
}
void
wait_and_change_think(edict_t* ent)
{
void (*afterwaitfunc)(edict_t *) = ent->moveinfo.endfunc;
ent->moveinfo.endfunc = NULL;
afterwaitfunc(ent);
}
/*
* In coop mode, this waits for coop_elevator_delay seconds
* before calling afterwaitfunc(ent); otherwise it just calls
* afterwaitfunc(ent);
*/
static void
wait_and_change(edict_t* ent, void (*afterwaitfunc)(edict_t *))
{
float waittime = coop_elevator_delay->value;
if (coop->value && waittime > 0.0f)
{
if(ent->nextthink == 0)
{
ent->moveinfo.endfunc = afterwaitfunc;
ent->think = wait_and_change_think;
ent->nextthink = level.time + waittime;
}
}
else
{
afterwaitfunc(ent);
}
}
void
Touch_Plat_Center(edict_t *ent, edict_t *other, cplane_t *plane /* unused */,
csurface_t *surf /* unused */)
@ -602,7 +635,7 @@ Touch_Plat_Center(edict_t *ent, edict_t *other, cplane_t *plane /* unused */,
if (ent->moveinfo.state == STATE_BOTTOM)
{
plat_go_up(ent);
wait_and_change(ent, plat_go_up);
}
else if (ent->moveinfo.state == STATE_TOP)
{

View File

@ -22,6 +22,7 @@ edict_t *g_edicts;
cvar_t *deathmatch;
cvar_t *coop;
cvar_t *coop_elevator_delay;
cvar_t *coop_pickup_weapons;
cvar_t *dmflags;
cvar_t *skill;

View File

@ -501,6 +501,7 @@ extern edict_t *g_edicts;
extern cvar_t *maxentities;
extern cvar_t *deathmatch;
extern cvar_t *coop;
extern cvar_t *coop_elevator_delay;
extern cvar_t *coop_pickup_weapons;
extern cvar_t *dmflags;
extern cvar_t *skill;

View File

@ -209,7 +209,8 @@ InitGame(void)
maxspectators = gi.cvar ("maxspectators", "4", CVAR_SERVERINFO);
deathmatch = gi.cvar ("deathmatch", "0", CVAR_LATCH);
coop = gi.cvar ("coop", "0", CVAR_LATCH);
coop_pickup_weapons = gi.cvar("coop_pickup_weapons", "0", 0);
coop_elevator_delay = gi.cvar("coop_elevator_delay", "1.0", CVAR_ARCHIVE);
coop_pickup_weapons = gi.cvar("coop_pickup_weapons", "0", CVAR_ARCHIVE);
skill = gi.cvar ("skill", "1", CVAR_LATCH);
maxentities = gi.cvar ("maxentities", "1024", CVAR_LATCH);

View File

@ -1227,3 +1227,4 @@ extern void ai_walk ( edict_t * self , float dist ) ;
extern void ai_stand ( edict_t * self , float dist ) ;
extern void ai_move ( edict_t * self , float dist ) ;
extern void AI_SetSightClient ( void ) ;
extern void wait_and_change_think(edict_t* ent);

View File

@ -1227,4 +1227,5 @@
{"ai_stand", (byte *)ai_stand},
{"ai_move", (byte *)ai_move},
{"AI_SetSightClient", (byte *)AI_SetSightClient},
{"wait_and_change_think", (byte *)wait_and_change_think},
{0, 0}