CLIENT/SERVER: Add new event for screen flashing, add delay to game start

This commit is contained in:
MotoLegacy 2024-01-14 20:48:42 -05:00
parent 4deeb465ee
commit bc46399f8c
14 changed files with 158 additions and 110 deletions

BIN
source/client/.DS_Store vendored Normal file

Binary file not shown.

View file

@ -154,8 +154,11 @@ vector TEXT_ORANGE = [(235/255), (189/255), 0];
vector TEXT_GREEN = [0, (230/255), (34/255)];
vector TEXT_RED = [1, 0, 0];
float fade_time;
float fade_type;
float screenflash_type;
float screenflash_color;
float screenflash_duration;
float screenflash_worktime;
float screenflash_starttime;
.float stance;
.float points;

View file

@ -1520,29 +1520,46 @@ void() HUD_Endgame = {
HUD_Scores();
}
float oldfade_alpha;
void() HUD_Fade =
//
// HUD_Screenflash()
// Screen fade in and out behaviors.
//
void() HUD_Screenflash =
{
float alpha;
vector color = '0 0 0';
float flash_alpha = 0;
if (fade_type == 1) {
alpha = cos(fade_time - time);
if (oldfade_alpha > 0.95)
alpha = 1;
alpha = invertfloat(alpha);
drawfill ([0, 0, 0], [g_width, g_height, 0], [0, 0, 0], alpha, 0); // background
oldfade_alpha = alpha;
// Obtain the flash color
switch(screenflash_color) {
case SCREENFLASH_COLOR_BLACK: color = '0 0 0'; break;
case SCREENFLASH_COLOR_WHITE: color = '1 1 1'; break;
default: color = '1 0 0'; break;
}
else if (fade_type == 2) {
alpha = sin(((fade_time - time) * 2));
if (oldfade_alpha > 0.95)
alpha = 1;
drawfill ([0, 0, 0], [g_width, g_height, 0], [0, 0, 0], alpha, 0); // background
oldfade_alpha = alpha;
float percentage_complete = screenflash_worktime / (screenflash_duration - screenflash_starttime);
// Fade Out
if (screenflash_type == SCREENFLASH_FADE_OUT) {
flash_alpha = invertfloat(percentage_complete);
}
// Fade In
else if (screenflash_type == SCREENFLASH_FADE_IN) {
flash_alpha = percentage_complete;
}
// Fade In + Fade Out
else {
// Fade In
if (percentage_complete < 0.5) {
flash_alpha = percentage_complete;
}
// Fade Out
else {
flash_alpha = invertfloat(percentage_complete);
}
}
screenflash_worktime += frametime;
drawfill ([0, 0], [g_width, g_height, 0], color, flash_alpha, 0);
}
void(float width, float height) HUD_ScrollText = {
@ -1819,6 +1836,6 @@ void(float width, float height) HUD_Draw =
HUD_Achievements(width, height);
if (fade_time > time)
HUD_Fade();
if (screenflash_duration > time)
HUD_Screenflash();
}

View file

@ -625,7 +625,11 @@ noref void(float width, float height, float menushown) CSQC_UpdateView =
}
if(in_menu)
{
//in menu.qc
// sorta-nasty hack: flashes should still draw if we're
// drawing the menu.
if (screenflash_duration > time)
HUD_Screenflash();
Draw_Menu();
setlocaluserinfo(0, "in_menu", "1");
}
@ -907,6 +911,13 @@ noref void() CSQC_Parse_Event =
case CSQC_EVENT_PLAYERNAME:
character_name = readstring();
break;
case CSQC_EVENT_SCREENFLASH:
screenflash_color = readbyte();
screenflash_duration = time + readbyte();
screenflash_type = readbyte();
screenflash_worktime = 0;
screenflash_starttime = time;
break;
case EVENT_WEAPONRECOIL:
local vector rec;
rec_x = readcoord()/5;
@ -979,10 +990,6 @@ noref void() CSQC_Parse_Event =
case EVENT_MAPTYPE:
map_compatibility_mode = readbyte();
break;
case EVENT_BLACKOUT:
fade_time = readbyte();
fade_type = readbyte();
break;
case EVENT_WORLDDATA:
chaptertitle = readstring();
location = readstring();

BIN
source/server/.DS_Store vendored Normal file

Binary file not shown.

View file

@ -248,6 +248,26 @@ void(entity target, float broadcast_type, float broadcast_time, float player_id)
}
};
//
// nzp_screenflash(target, color, duration, type)
// FTE equivalent of nzp_screenflash builtin.
//
void(entity target, float color, float duration, float type) nzp_screenflash =
{
WriteByte(MSG_MULTICAST, SVC_CGAMEPACKET);
WriteByte(MSG_MULTICAST, CSQC_EVENT_SCREENFLASH);
WriteByte(MSG_MULTICAST, color);
WriteByte(MSG_MULTICAST, duration);
WriteByte(MSG_MULTICAST, type);
if (target != world) {
msg_entity = target;
multicast('0 0 0', MULTICAST_ONE);
} else {
multicast('0 0 0', MULTICAST_ALL);
}
};
#endif // FTE
void(float count) UpdatePlayerCount = {
@ -264,20 +284,6 @@ void(float count) UpdatePlayerCount = {
#endif // FTE
}
void(float newtime, float newtype, entity change) PromptLevelChange =
{
#ifdef FTE
WriteByte(MSG_MULTICAST, SVC_CGAMEPACKET);
WriteByte(MSG_MULTICAST, EVENT_BLACKOUT);
WriteByte(MSG_MULTICAST, newtime);
WriteByte(MSG_MULTICAST, newtype);
msg_entity = change;
multicast('0 0 0', MULTICAST_ONE);
#endif // FTE
}
#ifdef FTE
void(entity who) grenade_pulse =
{

View file

@ -38,7 +38,7 @@ void() EndGame_Restart =
// Fade to black function, creates another think for restart
void() EndGame_FadePrompt =
{
PromptLevelChange(time + 6, 2, self);
nzp_screenflash(self, SCREENFLASH_COLOR_BLACK, 6, SCREENFLASH_FADE_IN);
#ifdef FTE

View file

@ -274,7 +274,7 @@ float ()
void (entity who) nzp_bettyprompt = #504;
void (entity who, string name) nzp_setplayername = #505;
void (entity who, float version) nzp_setdoubletapver = #506;
void (entity who, float color, float duration, float type) nzp_screenflash = #507;
//
// constants
//

View file

@ -38,7 +38,6 @@ var struct powerup_struct
{
float id;
float occupied;
float flash_screen;
string model_path;
string voiceover_path;
void() function;
@ -85,7 +84,7 @@ entity() PU_GetFreeEnt =
// PU_AddToStruct(id, model_path, voiceover_path)
// Adds the Power-Up and info to the powerup struct
//
void(float id, float flash_screen, string model_path, string voiceover_path, void() function, float() requirement_function)
void(float id, string model_path, string voiceover_path, void() function, float() requirement_function)
PU_AddToStruct =
{
if (id > MAX_POWERUPS - 1)
@ -98,7 +97,6 @@ PU_AddToStruct =
// Populate the Struct at Index
powerup_array[powerup_count].id = id;
powerup_array[powerup_count].occupied = true;
powerup_array[powerup_count].flash_screen = flash_screen;
powerup_array[powerup_count].model_path = model_path;
powerup_array[powerup_count].voiceover_path = voiceover_path;
powerup_array[powerup_count].function = function;
@ -175,22 +173,6 @@ float() PU_GetNextPowerUp =
return id;
};
//
// PU_ShouldFlashScreen(id)
// Returns flash_screen from Power-Up struct.
//
float(float id) PU_ShouldFlashScreen =
{
if (id == -1)
return false;
for(float i = 0; i < MAX_POWERUPS - 1; i++) {
if (powerup_array[i].id == id)
return powerup_array[i].flash_screen;
}
return false;
};
//
// PU_ModelPath(id)
// Returns model_path from Power-Up struct.
@ -339,6 +321,9 @@ void() PU_NukeKill =
//
void() PU_Nuke =
{
// Flash the screen white
nzp_screenflash(world, SCREENFLASH_COLOR_WHITE, 1, SCREENFLASH_FADE_INANDOUT);
// if there's already one active, just increment the point multiplier
if (nuke_powerup_active == true) {
nuke_powerups_activated++;
@ -589,15 +574,15 @@ void() PU_Init =
}
// Just add all of them for now
PU_AddToStruct(PU_NUKE, true, "models/pu/nuke!.mdl", "sounds/pu/kaboom.wav", PU_Nuke,
PU_AddToStruct(PU_NUKE, "models/pu/nuke!.mdl", "sounds/pu/kaboom.wav", PU_Nuke,
PU_NullRequirement );
PU_AddToStruct(PU_INSTAKILL, false, "models/pu/instakill!.mdl", "sounds/pu/insta_kill.wav", PU_InstaKill,
PU_AddToStruct(PU_INSTAKILL, "models/pu/instakill!.mdl", "sounds/pu/insta_kill.wav", PU_InstaKill,
PU_NullRequirement );
PU_AddToStruct(PU_DOUBLEPTS, false, "models/pu/x2!.mdl", "sounds/pu/double_points.wav", PU_DoublePoints,
PU_AddToStruct(PU_DOUBLEPTS, "models/pu/x2!.mdl", "sounds/pu/double_points.wav", PU_DoublePoints,
PU_NullRequirement );
PU_AddToStruct(PU_CARPENTER, false, "models/pu/carpenter!.mdl", "sounds/pu/carpenter.wav", PU_Carpenter,
PU_AddToStruct(PU_CARPENTER, "models/pu/carpenter!.mdl", "sounds/pu/carpenter.wav", PU_Carpenter,
PU_CarpenterRequirement );
PU_AddToStruct(PU_MAXAMMO, false, "models/pu/maxammo!.mdl", "sounds/pu/maxammo.wav", PU_MaxAmmo,
PU_AddToStruct(PU_MAXAMMO, "models/pu/maxammo!.mdl", "sounds/pu/maxammo.wav", PU_MaxAmmo,
PU_NullRequirement );
// Nuke requires an extra Precache
@ -678,10 +663,6 @@ void() PU_Touch =
Light_None(self);
self.touch = SUB_Null;
// Flash the Screen if permitted
if (PU_ShouldFlashScreen(self.walktype) == true)
stuffcmd(other, "bf\n");
// Run Power-Up function
PU_LogicFunction(self.walktype);
}

View file

@ -39,6 +39,7 @@ void() main =
}
float ai_delay_time;
float time_before_gamestart;
//
// Way_SetBrushEntNonSolid(ent_name)
@ -90,6 +91,10 @@ void() StartFrame =
return;
}
// Start completely blacked out
//if (time < 5)
if (roundinit) {
Round_Core();
@ -122,19 +127,32 @@ void() StartFrame =
}
} else {
if (!time_before_gamestart) {
entity SpawnedIn;
SpawnedIn = find(world, classname, "player");
if (SpawnedIn) {
entity getdog = find(world, classname, "spawn_dog");
if (getdog)
gotdog = 1;
else
gotdog = 0;
Compat_Init();
time_before_gamestart = time + 3;
}
return;
} else if (time_before_gamestart < time) {
updateDogRound();
InitRounds();
Compat_Init();
nzp_screenflash(world, SCREENFLASH_COLOR_BLACK, 1, SCREENFLASH_FADE_OUT);
sound(self, CHAN_AUTO, "sounds/rounds/splash.wav", 1, ATTN_NONE);
entity players = find(world, classname, "player");
while(players != world) {
if (players.name != "")
nzp_setplayername(players, players.name);
players = find(players, classname, "player");
}
} else {
nzp_screenflash(world, SCREENFLASH_COLOR_BLACK, 90, SCREENFLASH_FADE_OUT);
}
}
}

View file

@ -561,9 +561,6 @@ void() PlayerPostThink =
if(self.isspec)
return;
if (time < 5 && self.name != "")
nzp_setplayername(self, self.name);
//landsound
if((self.oldvelocity_z < -212) && (self.flags & FL_ONGROUND))
{
@ -890,12 +887,6 @@ void() PlayerSpawn =
self.reviving = 0;
self.perks = G_PERKS;
if (rounds < 1 && player_count == 0) {
sound(self, CHAN_AUTO, "sounds/rounds/splash.wav", 1, ATTN_NONE);
sound(self, CHAN_ITEM, "sounds/rounds/nround.wav", 0.75, ATTN_NONE);
}
PromptLevelChange(self.nextthink + 3, 1, self);
UpdatePlayerCount(player_count);
#ifdef FTE
@ -921,6 +912,11 @@ void() PlayerSpawn =
if (G_STARTROUND != 1) {
rounds = G_STARTROUND - 1;
}
// Make sure players joining after game start are still allowed
// to see their name.
if (time >= 5 && self.name != "")
nzp_setplayername(self, self.name);
};
void() SpectatorSpawn =

View file

@ -370,4 +370,6 @@ void() Soft_Restart = {
InitRounds();
self.isspec = false;
PutClientInServer();
nzp_screenflash(world, SCREENFLASH_COLOR_BLACK, 1, SCREENFLASH_FADE_OUT);
}

BIN
source/shared/.DS_Store vendored Normal file

Binary file not shown.

View file

@ -73,20 +73,37 @@
#define CSQC_EVENT_PLAYERNAME 17 // <string> player_name
#define EVENT_UPDATE 18
#define EVENT_BLACKOUT 19
#define EVENT_WORLDDATA 20
#define CSQC_EVENT_SCREENFLASH 18 // <byte> screenflash_color
// <byte> screenflash_duration
// <byte> screenflash_type
#define EVENT_UPDATE 19
#define EVENT_BLACKOUT 20
#define EVENT_WORLDDATA 21
#define EVENT_PLAYERUPDATE 22
#define EVENT_REVIVEON 24
#define EVENT_REVIVEOFF 25
#define EVENT_REVIVECHANGE 26
#define EVENT_WEAPONRECOIL 27
#define EVENT_GRENADEPULSE 29
#define EVENT_BETTYPROMPT 30
#define EVENT_CHATMESSAGE 31
#define EVENT_DOUBLETAPUPDATE 32
#define EVENT_ENDGAME 33
#define EVENT_MAPTYPE 34
#define EVENT_REVIVEON 23
#define EVENT_REVIVEOFF 24
#define EVENT_REVIVECHANGE 25
#define EVENT_WEAPONRECOIL 26
#define EVENT_GRENADEPULSE 27
#define EVENT_BETTYPROMPT 28
#define EVENT_CHATMESSAGE 29
#define EVENT_DOUBLETAPUPDATE 30
#define EVENT_ENDGAME 31
#define EVENT_MAPTYPE 32
//
// Types of screen-flashes, global.
//
// Colors
#define SCREENFLASH_COLOR_WHITE 0
#define SCREENFLASH_COLOR_BLACK 1
// Types
#define SCREENFLASH_FADE_INANDOUT 0
#define SCREENFLASH_FADE_IN 1
#define SCREENFLASH_FADE_OUT 2
// Define our FTE platform
#ifndef STANDARD
@ -296,9 +313,10 @@ float game_over;
// invert float takes in float value between 0 and 1, inverts position
// eg: 0.1 returns 0.9, 0.34 returns 0.66
float invertfloat(float input) {
if (input <= 0 || input >= 1)
return input; // out of boundaries
if (input < 0)
return 0; // adjust to lower boundary
else if (input > 1)
return 1; // adjust to upper boundary
else
return (1 - input);
}