From c1e438e69743f1461d45464ca769bded89c49003 Mon Sep 17 00:00:00 2001 From: Yamagi Date: Mon, 10 Aug 2020 14:06:14 +0200 Subject: [PATCH] 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. --- src/g_func.c | 35 ++++++++++++++++++++++++++++- src/g_main.c | 1 + src/header/local.h | 1 + src/savegame/savegame.c | 3 ++- src/savegame/tables/gamefunc_decs.h | 1 + src/savegame/tables/gamefunc_list.h | 1 + 6 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/g_func.c b/src/g_func.c index 5d56f71..568e556 100644 --- a/src/g_func.c +++ b/src/g_func.c @@ -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) { diff --git a/src/g_main.c b/src/g_main.c index 4745ba4..33d9377 100644 --- a/src/g_main.c +++ b/src/g_main.c @@ -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; diff --git a/src/header/local.h b/src/header/local.h index bd75048..d032949 100644 --- a/src/header/local.h +++ b/src/header/local.h @@ -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; diff --git a/src/savegame/savegame.c b/src/savegame/savegame.c index 4d434a7..ed23ef6 100644 --- a/src/savegame/savegame.c +++ b/src/savegame/savegame.c @@ -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); diff --git a/src/savegame/tables/gamefunc_decs.h b/src/savegame/tables/gamefunc_decs.h index 92d98b0..d0ac422 100644 --- a/src/savegame/tables/gamefunc_decs.h +++ b/src/savegame/tables/gamefunc_decs.h @@ -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); diff --git a/src/savegame/tables/gamefunc_list.h b/src/savegame/tables/gamefunc_list.h index 2bab09d..21cd8e8 100644 --- a/src/savegame/tables/gamefunc_list.h +++ b/src/savegame/tables/gamefunc_list.h @@ -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}