5551 lines
132 KiB
C
5551 lines
132 KiB
C
// SONIC ROBO BLAST 2
|
|
//-----------------------------------------------------------------------------
|
|
// Copyright (C) 1993-1996 by id Software, Inc.
|
|
// Copyright (C) 1998-2000 by DooM Legacy Team.
|
|
// Copyright (C) 1999-2020 by Sonic Team Junior.
|
|
//
|
|
// This program is free software distributed under the
|
|
// terms of the GNU General Public License, version 2.
|
|
// See the 'LICENSE' file for more details.
|
|
//-----------------------------------------------------------------------------
|
|
/// \file g_game.c
|
|
/// \brief game loop functions, events handling
|
|
|
|
#include "doomdef.h"
|
|
#include "console.h"
|
|
#include "d_main.h"
|
|
#include "d_clisrv.h"
|
|
#include "d_player.h"
|
|
#include "d_clisrv.h"
|
|
#include "f_finale.h"
|
|
#include "filesrch.h" // for refreshdirmenu
|
|
#include "m_fixed.h"
|
|
#include "p_setup.h"
|
|
#include "p_saveg.h"
|
|
#include "i_time.h"
|
|
#include "i_system.h"
|
|
#include "am_map.h"
|
|
#include "m_random.h"
|
|
#include "p_local.h"
|
|
#include "r_draw.h"
|
|
#include "r_main.h"
|
|
#include "s_sound.h"
|
|
#include "g_game.h"
|
|
#include "g_demo.h"
|
|
#include "m_cheat.h"
|
|
#include "m_misc.h"
|
|
#include "m_menu.h"
|
|
#include "m_argv.h"
|
|
#include "hu_stuff.h"
|
|
#include "st_stuff.h"
|
|
#include "z_zone.h"
|
|
#include "i_video.h"
|
|
#include "byteptr.h"
|
|
#include "i_joy.h"
|
|
#include "r_local.h"
|
|
#include "r_skins.h"
|
|
#include "y_inter.h"
|
|
#include "v_video.h"
|
|
#include "lua_hook.h"
|
|
#include "m_cond.h" // condition sets
|
|
#include "r_fps.h" // frame interpolation/uncapped
|
|
#include "lua_hud.h"
|
|
|
|
// SRB2kart
|
|
#include "k_kart.h"
|
|
#include "k_stats.h" // SRB2kart
|
|
#include "k_battle.h"
|
|
#include "k_pwrlv.h"
|
|
#include "k_color.h"
|
|
#include "k_grandprix.h"
|
|
#include "k_boss.h"
|
|
#include "k_bot.h"
|
|
#include "doomstat.h"
|
|
#include "acs/interface.h"
|
|
#include "k_director.h"
|
|
#include "g_party.h"
|
|
|
|
#ifdef HAVE_DISCORDRPC
|
|
#include "discord.h"
|
|
#endif
|
|
|
|
#ifdef HWRENDER
|
|
#include "hardware/hw_main.h" // for cv_glshearing
|
|
#endif
|
|
|
|
gameaction_t gameaction;
|
|
gamestate_t gamestate = GS_NULL;
|
|
UINT8 ultimatemode = false;
|
|
|
|
JoyType_t Joystick[MAXSPLITSCREENPLAYERS];
|
|
|
|
// SRB2kart
|
|
char gamedatafilename[64] = "kartdata.dat";
|
|
char timeattackfolder[64] = "kart";
|
|
char customversionstring[32] = "\0";
|
|
|
|
static void G_DoCompleted(void);
|
|
static void G_DoStartContinue(void);
|
|
static void G_DoContinued(void);
|
|
static void G_DoWorldDone(void);
|
|
static void G_DoStartVote(void);
|
|
|
|
char mapmusname[7]; // Music name
|
|
UINT16 mapmusflags; // Track and reset bit
|
|
UINT32 mapmusposition; // Position to jump to
|
|
UINT32 mapmusresume;
|
|
UINT8 mapmusrng; // Random selection result
|
|
|
|
INT16 gamemap = 1;
|
|
UINT32 maptol;
|
|
|
|
preciptype_t globalweather = PRECIP_NONE;
|
|
preciptype_t curWeather = PRECIP_NONE;
|
|
|
|
precipprops_t precipprops[MAXPRECIP] =
|
|
{
|
|
{"NONE", MT_NULL, 0}, // PRECIP_NONE
|
|
{"RAIN", MT_RAIN, 0}, // PRECIP_RAIN
|
|
{"SNOW", MT_SNOWFLAKE, 0}, // PRECIP_SNOW
|
|
{"STORM", MT_RAIN, PRECIPFX_THUNDER|PRECIPFX_LIGHTNING}, // PRECIP_STORM
|
|
{"STORM_NORAIN", MT_NULL, PRECIPFX_THUNDER|PRECIPFX_LIGHTNING}, // PRECIP_STORM_NORAIN
|
|
{"STORM_NOSTRIKES", MT_RAIN, PRECIPFX_THUNDER} // PRECIP_STORM_NOSTRIKES
|
|
};
|
|
|
|
preciptype_t precip_freeslot = PRECIP_FIRSTFREESLOT;
|
|
|
|
INT32 cursaveslot = 0; // Auto-save 1p savegame slot
|
|
//INT16 lastmapsaved = 0; // Last map we auto-saved at
|
|
INT16 lastmaploaded = 0; // Last map the game loaded
|
|
UINT8 gamecomplete = 0;
|
|
|
|
marathonmode_t marathonmode = 0;
|
|
tic_t marathontime = 0;
|
|
|
|
UINT8 numgameovers = 0; // for startinglives balance
|
|
SINT8 startinglivesbalance[maxgameovers+1] = {3, 5, 7, 9, 12, 15, 20, 25, 30, 40, 50, 75, 99, 0x7F};
|
|
|
|
boolean modifiedgame = false; // Set if homebrew PWAD stuff has been added.
|
|
boolean majormods = false; // Set if Lua/Gameplay SOC/replacement map has been added.
|
|
boolean savemoddata = false;
|
|
UINT8 paused;
|
|
UINT8 modeattacking = ATTACKING_NONE;
|
|
boolean imcontinuing = false;
|
|
boolean runemeraldmanager = false;
|
|
UINT16 emeraldspawndelay = 60*TICRATE;
|
|
|
|
// menu demo things
|
|
UINT8 numDemos = 0;
|
|
UINT32 demoDelayTime = 15*TICRATE;
|
|
UINT32 demoIdleTime = 3*TICRATE;
|
|
|
|
boolean netgame; // only true if packets are broadcast
|
|
boolean multiplayer;
|
|
boolean playeringame[MAXPLAYERS];
|
|
boolean addedtogame;
|
|
player_t players[MAXPLAYERS];
|
|
|
|
INT32 consoleplayer; // player taking events and displaying
|
|
INT32 displayplayers[MAXSPLITSCREENPLAYERS]; // view being displayed
|
|
INT32 g_localplayers[MAXSPLITSCREENPLAYERS];
|
|
|
|
tic_t gametic;
|
|
tic_t levelstarttic; // gametic at level start
|
|
INT16 lastmap; // last level you were at (returning from special stages)
|
|
tic_t timeinmap; // Ticker for time spent in level (used for levelcard display)
|
|
|
|
char * titlemap = NULL;
|
|
boolean hidetitlepics = false;
|
|
char * bootmap = NULL; //bootmap for loading a map on startup
|
|
|
|
char * tutorialmap = NULL; // map to load for tutorial
|
|
boolean tutorialmode = false; // are we in a tutorial right now?
|
|
|
|
boolean looptitle = true;
|
|
|
|
UINT16 skincolor_redteam = SKINCOLOR_RED;
|
|
UINT16 skincolor_blueteam = SKINCOLOR_BLUE;
|
|
UINT16 skincolor_redring = SKINCOLOR_RASPBERRY;
|
|
UINT16 skincolor_bluering = SKINCOLOR_PERIWINKLE;
|
|
|
|
boolean exitfadestarted = false;
|
|
|
|
cutscene_t *cutscenes[128];
|
|
textprompt_t *textprompts[MAX_PROMPTS];
|
|
|
|
INT16 nextmapoverride;
|
|
UINT8 skipstats;
|
|
|
|
struct quake quake;
|
|
|
|
// Map Header Information
|
|
mapheader_t** mapheaderinfo = {NULL};
|
|
INT32 nummapheaders, mapallocsize = 0;
|
|
|
|
// Kart cup definitions
|
|
cupheader_t *kartcupheaders = NULL;
|
|
UINT16 numkartcupheaders = 0;
|
|
|
|
static boolean exitgame = false;
|
|
static boolean retrying = false;
|
|
static boolean retryingmodeattack = false;
|
|
|
|
UINT8 stagefailed; // Used for GEMS BONUS? Also to see if you beat the stage.
|
|
|
|
UINT16 emeralds;
|
|
INT32 luabanks[NUM_LUABANKS];
|
|
UINT32 token; // Number of tokens collected in a level
|
|
UINT32 tokenlist; // List of tokens collected
|
|
boolean gottoken; // Did you get a token? Used for end of act
|
|
INT32 tokenbits; // Used for setting token bits
|
|
|
|
boolean gamedataloaded = false;
|
|
|
|
// Temporary holding place for nights data for the current map
|
|
//nightsdata_t ntemprecords;
|
|
|
|
UINT32 bluescore, redscore; // CTF and Team Match team scores
|
|
|
|
// ring count... for PERFECT!
|
|
INT32 nummaprings = 0;
|
|
|
|
// Elminates unnecessary searching.
|
|
boolean CheckForBustableBlocks;
|
|
boolean CheckForBouncySector;
|
|
boolean CheckForQuicksand;
|
|
boolean CheckForMarioBlocks;
|
|
boolean CheckForFloatBob;
|
|
boolean CheckForReverseGravity;
|
|
|
|
// Powerup durations
|
|
UINT16 invulntics = 20*TICRATE;
|
|
UINT16 sneakertics = 20*TICRATE;
|
|
UINT16 flashingtics = 3*TICRATE/2; // SRB2kart
|
|
UINT16 tailsflytics = 8*TICRATE;
|
|
UINT16 underwatertics = 30*TICRATE;
|
|
UINT16 spacetimetics = 11*TICRATE + (TICRATE/2);
|
|
UINT16 extralifetics = 4*TICRATE;
|
|
UINT16 nightslinktics = 2*TICRATE;
|
|
|
|
INT32 gameovertics = 15*TICRATE;
|
|
UINT8 ammoremovaltics = 2*TICRATE;
|
|
|
|
// SRB2kart
|
|
tic_t introtime = 3;
|
|
tic_t starttime = 3;
|
|
|
|
tic_t raceexittime = 5*TICRATE + (2*TICRATE/3);
|
|
tic_t battleexittime = 8*TICRATE;
|
|
|
|
INT32 hyudorotime = 7*TICRATE;
|
|
INT32 stealtime = TICRATE/2;
|
|
INT32 sneakertime = TICRATE + (TICRATE/3);
|
|
INT32 itemtime = 8*TICRATE;
|
|
INT32 bubbletime = TICRATE/2;
|
|
INT32 comebacktime = 3*TICRATE;
|
|
INT32 bumptime = 6;
|
|
INT32 greasetics = 3*TICRATE;
|
|
INT32 wipeoutslowtime = 20;
|
|
INT32 wantedreduce = 5*TICRATE;
|
|
INT32 wantedfrequency = 10*TICRATE;
|
|
|
|
UINT8 use1upSound = 0;
|
|
UINT8 maxXtraLife = 2; // Max extra lives from rings
|
|
|
|
UINT8 introtoplay;
|
|
UINT8 creditscutscene;
|
|
UINT8 useBlackRock = 1;
|
|
|
|
// Emerald locations
|
|
mobj_t *hunt1;
|
|
mobj_t *hunt2;
|
|
mobj_t *hunt3;
|
|
|
|
tic_t racecountdown, exitcountdown; // for racing
|
|
exitcondition_t g_exit;
|
|
|
|
fixed_t gravity;
|
|
fixed_t mapobjectscale;
|
|
|
|
struct maplighting maplighting;
|
|
|
|
INT16 autobalance; //for CTF team balance
|
|
INT16 teamscramble; //for CTF team scramble
|
|
INT16 scrambleplayers[MAXPLAYERS]; //for CTF team scramble
|
|
INT16 scrambleteams[MAXPLAYERS]; //for CTF team scramble
|
|
INT16 scrambletotal; //for CTF team scramble
|
|
INT16 scramblecount; //for CTF team scramble
|
|
|
|
INT32 cheats; //for multiplayer cheat commands
|
|
|
|
// SRB2Kart
|
|
// Cvars that we don't want changed mid-game
|
|
UINT8 numlaps; // Removed from Cvar hell
|
|
UINT8 gamespeed; // Game's current speed (or difficulty, or cc, or etc); 0 for easy, 1 for normal, 2 for hard
|
|
boolean encoremode = false; // Encore Mode currently enabled?
|
|
boolean prevencoremode;
|
|
boolean franticitems; // Frantic items currently enabled?
|
|
boolean comeback; // Battle Mode's karma comeback is on/off
|
|
|
|
// Voting system
|
|
INT16 votelevels[4][2]; // Levels that were rolled by the host
|
|
SINT8 votes[MAXPLAYERS]; // Each player's vote
|
|
SINT8 pickedvote; // What vote the host rolls
|
|
|
|
// Server-sided, synched variables
|
|
SINT8 battlewanted[4]; // WANTED players in battle, worth x2 points
|
|
tic_t wantedcalcdelay; // Time before it recalculates WANTED
|
|
tic_t indirectitemcooldown; // Cooldown before any more Shrink, SPB, or any other item that works indirectly is awarded
|
|
tic_t hyubgone; // Cooldown before hyudoro is allowed to be rerolled
|
|
tic_t mapreset; // Map reset delay when enough players have joined an empty game
|
|
boolean thwompsactive; // Thwomps activate on lap 2
|
|
UINT8 lastLowestLap; // Last lowest lap, for activating race lap executors
|
|
SINT8 spbplace; // SPB exists, give the person behind better items
|
|
boolean startedInFreePlay; // Map was started in free play
|
|
|
|
// Client-sided, unsynched variables (NEVER use in anything that needs to be synced with other players)
|
|
tic_t bombflashtimer = 0; // Cooldown before another FlashPal can be intialized by a bomb exploding near a displayplayer. Avoids seizures.
|
|
boolean legitimateexit; // Did this client actually finish the match?
|
|
boolean comebackshowninfo; // Have you already seen the "ATTACK OR PROTECT" message?
|
|
tic_t curlap; // Current lap time
|
|
tic_t bestlap; // Best lap time
|
|
|
|
typedef struct
|
|
{
|
|
INT16 *mapbuffer; // Pointer to zone memory
|
|
INT32 lastnummapheaders; // Reset if nummapheaders != this
|
|
UINT8 counttogametype; // Time to gametype change event
|
|
} randmaps_t;
|
|
static randmaps_t randmaps = {NULL, 0, 0};
|
|
|
|
static void G_ResetRandMapBuffer(void)
|
|
{
|
|
INT32 i;
|
|
Z_Free(randmaps.mapbuffer);
|
|
randmaps.lastnummapheaders = nummapheaders;
|
|
randmaps.mapbuffer = Z_Malloc(randmaps.lastnummapheaders * sizeof(INT16), PU_STATIC, NULL);
|
|
for (i = 0; i < randmaps.lastnummapheaders; i++)
|
|
randmaps.mapbuffer[i] = -1;
|
|
//intentionally not resetting randmaps.counttogametype here
|
|
}
|
|
|
|
// Grading
|
|
UINT32 timesBeaten;
|
|
|
|
typedef struct joystickvector2_s
|
|
{
|
|
INT32 xaxis;
|
|
INT32 yaxis;
|
|
} joystickvector2_t;
|
|
|
|
boolean precache = true; // if true, load all graphics at start
|
|
|
|
INT16 prevmap, nextmap;
|
|
|
|
INT16 kartmap2native[NEXTMAP_SPECIAL] = {0}, nativemap2kart[NEXTMAP_SPECIAL] = {0};
|
|
INT16 nextexnum = NUMMAPS;
|
|
|
|
// don't mind me putting these here, I was lazy to figure out where else I could put those without blowing up the compiler.
|
|
|
|
// chat timer thingy
|
|
static CV_PossibleValue_t chattime_cons_t[] = {{5, "MIN"}, {999, "MAX"}, {0, NULL}};
|
|
consvar_t cv_chattime = CVAR_INIT ("chattime", "8", CV_SAVE, chattime_cons_t, NULL);
|
|
|
|
// chatwidth
|
|
static CV_PossibleValue_t chatwidth_cons_t[] = {{64, "MIN"}, {150, "MAX"}, {0, NULL}};
|
|
consvar_t cv_chatwidth = CVAR_INIT ("chatwidth", "150", CV_SAVE, chatwidth_cons_t, NULL);
|
|
|
|
// chatheight
|
|
static CV_PossibleValue_t chatheight_cons_t[] = {{6, "MIN"}, {22, "MAX"}, {0, NULL}};
|
|
consvar_t cv_chatheight = CVAR_INIT ("chatheight", "8", CV_SAVE, chatheight_cons_t, NULL);
|
|
|
|
// chat notifications (do you want to hear beeps? I'd understand if you didn't.)
|
|
consvar_t cv_chatnotifications = CVAR_INIT ("chatnotifications", "On", CV_SAVE, CV_OnOff, NULL);
|
|
|
|
// chat spam protection (why would you want to disable that???)
|
|
consvar_t cv_chatspamprotection = CVAR_INIT ("chatspamprotection", "On", CV_SAVE, CV_OnOff, NULL);
|
|
|
|
// minichat text background
|
|
consvar_t cv_chatbacktint = CVAR_INIT ("chatbacktint", "On", CV_SAVE, CV_OnOff, NULL);
|
|
|
|
// old shit console chat. (mostly exists for stuff like terminal, not because I cared if anyone liked the old chat.)
|
|
static CV_PossibleValue_t consolechat_cons_t[] = {{0, "Window"}, {1, "Console"}, {2, "Window (Hidden)"}, {0, NULL}};
|
|
consvar_t cv_consolechat = CVAR_INIT ("chatmode", "Window", CV_SAVE, consolechat_cons_t, NULL);
|
|
|
|
// Shout settings
|
|
// The relevant ones are CV_NETVAR because too lazy to send them any other way
|
|
consvar_t cv_shoutname = CVAR_INIT ("shout_name", "SERVER", CV_NETVAR, NULL, NULL);
|
|
|
|
static CV_PossibleValue_t shoutcolor_cons_t[] =
|
|
{
|
|
{-1, "Player color"},
|
|
{0, "White"},
|
|
{1, "Yellow"},
|
|
{2, "Purple"},
|
|
{3, "Green"},
|
|
{4, "Blue"},
|
|
{5, "Red"},
|
|
{6, "Gray"},
|
|
{7, "Orange"},
|
|
{8, "Sky-blue"},
|
|
{9, "Gold"},
|
|
{10, "Lavender"},
|
|
{11, "Aqua-green"},
|
|
{12, "Magenta"},
|
|
{13, "Pink"},
|
|
{14, "Brown"},
|
|
{15, "Tan"},
|
|
{0, NULL}
|
|
};
|
|
consvar_t cv_shoutcolor = CVAR_INIT ("shout_color", "Red", CV_NETVAR, shoutcolor_cons_t, NULL);
|
|
|
|
// If on and you're an admin, your messages will automatically become shouts.
|
|
consvar_t cv_autoshout = CVAR_INIT ("autoshout", "Off", CV_NETVAR, CV_OnOff, NULL);
|
|
|
|
// Pause game upon window losing focus
|
|
consvar_t cv_pauseifunfocused = CVAR_INIT ("pauseifunfocused", "Yes", CV_SAVE, CV_YesNo, NULL);
|
|
|
|
// Display song credits
|
|
consvar_t cv_songcredits = CVAR_INIT ("songcredits", "On", CV_SAVE, CV_OnOff, NULL);
|
|
|
|
// Show "FREE PLAY" when you're alone. :(
|
|
consvar_t cv_showfreeplay = CVAR_INIT ("showfreeplay", "On", CV_SAVE, CV_OnOff, NULL);
|
|
|
|
// We can disable special tunes!
|
|
static CV_PossibleValue_t powermusic_cons_t[] = {{0, "Off"}, {1, "On"}, {2, "SFX"}, {0, NULL}};
|
|
consvar_t cv_growmusic = CVAR_INIT ("growmusic", "On", CV_SAVE, powermusic_cons_t, NULL);
|
|
consvar_t cv_supermusic = CVAR_INIT ("supermusic", "On", CV_SAVE, powermusic_cons_t, NULL);
|
|
|
|
consvar_t cv_invertmouse = CVAR_INIT ("invertmouse", "Off", CV_SAVE, CV_OnOff, NULL);
|
|
|
|
consvar_t cv_invincmusicfade = CVAR_INIT ("invincmusicfade", "300", CV_SAVE, CV_Unsigned, NULL);
|
|
consvar_t cv_growmusicfade = CVAR_INIT ("growmusicfade", "500", CV_SAVE, CV_Unsigned, NULL);
|
|
|
|
consvar_t cv_resetspecialmusic = CVAR_INIT ("resetspecialmusic", "Yes", CV_SAVE, CV_YesNo, NULL);
|
|
|
|
consvar_t cv_resume = CVAR_INIT ("resume", "Yes", CV_SAVE, CV_YesNo, NULL);
|
|
|
|
consvar_t cv_kickstartaccel[MAXSPLITSCREENPLAYERS] = {
|
|
CVAR_INIT ("kickstartaccel", "Off", CV_SAVE|CV_CALL, CV_OnOff, weaponPrefChange),
|
|
CVAR_INIT ("kickstartaccel2", "Off", CV_SAVE|CV_CALL, CV_OnOff, weaponPrefChange2),
|
|
CVAR_INIT ("kickstartaccel3", "Off", CV_SAVE|CV_CALL, CV_OnOff, weaponPrefChange3),
|
|
CVAR_INIT ("kickstartaccel4", "Off", CV_SAVE|CV_CALL, CV_OnOff, weaponPrefChange4)
|
|
};
|
|
|
|
consvar_t cv_shrinkme[MAXSPLITSCREENPLAYERS] = {
|
|
CVAR_INIT ("shrinkme", "Off", CV_CALL, CV_OnOff, weaponPrefChange),
|
|
CVAR_INIT ("shrinkme2", "Off", CV_CALL, CV_OnOff, weaponPrefChange2),
|
|
CVAR_INIT ("shrinkme3", "Off", CV_CALL, CV_OnOff, weaponPrefChange3),
|
|
CVAR_INIT ("shrinkme4", "Off", CV_CALL, CV_OnOff, weaponPrefChange4)
|
|
};
|
|
|
|
static CV_PossibleValue_t zerotoone_cons_t[] = {{0, "MIN"}, {FRACUNIT, "MAX"}, {0, NULL}};
|
|
consvar_t cv_deadzone[MAXSPLITSCREENPLAYERS] = {
|
|
CVAR_INIT ("deadzone", "0.25", CV_FLOAT|CV_SAVE, zerotoone_cons_t, NULL),
|
|
CVAR_INIT ("deadzone2", "0.25", CV_FLOAT|CV_SAVE, zerotoone_cons_t, NULL),
|
|
CVAR_INIT ("deadzone3", "0.25", CV_FLOAT|CV_SAVE, zerotoone_cons_t, NULL),
|
|
CVAR_INIT ("deadzone4", "0.25", CV_FLOAT|CV_SAVE, zerotoone_cons_t, NULL)
|
|
};
|
|
|
|
static CV_PossibleValue_t deadzonestyle_cons_t[] = {{0, "Kart"}, {1, "RR"}, {0, NULL}};
|
|
consvar_t cv_deadzonestyle[MAXSPLITSCREENPLAYERS] = {
|
|
CVAR_INIT ("deadzonestyle", "Kart", CV_SAVE, deadzonestyle_cons_t, NULL),
|
|
CVAR_INIT ("deadzonestyle2", "Kart", CV_SAVE, deadzonestyle_cons_t, NULL),
|
|
CVAR_INIT ("deadzonestyle3", "Kart", CV_SAVE, deadzonestyle_cons_t, NULL),
|
|
CVAR_INIT ("deadzonestyle4", "Kart", CV_SAVE, deadzonestyle_cons_t, NULL)
|
|
};
|
|
|
|
// now automatically allocated in D_RegisterClientCommands
|
|
// so that it doesn't have to be updated depending on the value of MAXPLAYERS
|
|
char player_names[MAXPLAYERS][MAXPLAYERNAME+1];
|
|
INT32 player_name_changes[MAXPLAYERS];
|
|
|
|
// What record should preset should we use?
|
|
SINT8 G_RecordPresetIndex(void)
|
|
{
|
|
boolean rings = cv_dummyattackingrings.value;
|
|
boolean stacking = cv_dummyattackingstacking.value;
|
|
boolean chaining = cv_dummyattackingchaining.value;
|
|
boolean slipdash = cv_dummyattackingslipdash.value;
|
|
boolean purpledrift = cv_dummyattackingpurpledrift.value;
|
|
|
|
if (!rings && !stacking && !chaining && !slipdash && !purpledrift)
|
|
return RP_KART;
|
|
|
|
if (stacking && chaining && !rings && !slipdash && !purpledrift)
|
|
return RP_TECH;
|
|
|
|
if (rings && stacking && chaining && slipdash && purpledrift)
|
|
return RP_BLAN;
|
|
|
|
return RP_CUST;
|
|
}
|
|
|
|
// Allocation for time and nights data
|
|
void G_AllocMainRecordData(INT16 i, SINT8 preset)
|
|
{
|
|
if (preset < 0 || preset >= MAXMAPRECORDS)
|
|
I_Error("G_AllocMainRecordData: Tried allocating invalid record index (%d)", preset);
|
|
|
|
if (i > nummapheaders || !mapheaderinfo[i])
|
|
I_Error("G_AllocMainRecordData: Internal map ID %d not found (nummapheaders = %d)\n", i, nummapheaders);
|
|
if (!mapheaderinfo[i]->mainrecord[preset])
|
|
mapheaderinfo[i]->mainrecord[preset] = Z_Malloc(sizeof(recorddata_t), PU_STATIC, NULL);
|
|
memset(mapheaderinfo[i]->mainrecord[preset], 0, sizeof(recorddata_t));
|
|
}
|
|
|
|
// MAKE SURE YOU SAVE DATA BEFORE CALLING THIS
|
|
void G_ClearRecords(void)
|
|
{
|
|
INT16 i;
|
|
SINT8 k;
|
|
|
|
for (i = 0; i < nummapheaders; ++i)
|
|
{
|
|
for (k = 0; k < MAXMAPRECORDS; k++)
|
|
{
|
|
if (mapheaderinfo[i]->mainrecord[k])
|
|
{
|
|
Z_Free(mapheaderinfo[i]->mainrecord[k]);
|
|
mapheaderinfo[i]->mainrecord[k] = NULL;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// For easy retrieval of records
|
|
tic_t G_GetBestTime(INT16 map)
|
|
{
|
|
SINT8 preset = G_RecordPresetIndex();
|
|
|
|
if (!mapheaderinfo[map] || !mapheaderinfo[map]->mainrecord[preset] || mapheaderinfo[map]->mainrecord[preset]->time <= 0)
|
|
return (tic_t)UINT32_MAX;
|
|
|
|
return mapheaderinfo[map]->mainrecord[preset]->time;
|
|
}
|
|
|
|
boolean K_EmblemsEnabled(void)
|
|
{
|
|
if (cv_dummyattackingrings.value)
|
|
return false;
|
|
|
|
if (cv_dummyattackingstacking.value)
|
|
return false;
|
|
|
|
if (cv_dummyattackingchaining.value)
|
|
return false;
|
|
|
|
if (cv_dummyattackingslipdash.value)
|
|
return false;
|
|
|
|
if (cv_dummyattackingpurpledrift.value)
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
//
|
|
// G_UpdateRecordReplays
|
|
//
|
|
// Update replay files/data, etc. for Record Attack
|
|
//
|
|
static void G_UpdateRecordReplays(void)
|
|
{
|
|
char *gpath;
|
|
char *gamemode = M_AppendGametypeAndModName();
|
|
char lastdemo[256], bestdemo[256];
|
|
UINT8 earnedEmblems;
|
|
int parts;
|
|
SINT8 preset = G_RecordPresetIndex();
|
|
|
|
// Record new best time
|
|
if (!mapheaderinfo[gamemap-1]->mainrecord[preset])
|
|
G_AllocMainRecordData(gamemap-1, preset);
|
|
|
|
if (players[consoleplayer].pflags & PF_NOCONTEST)
|
|
{
|
|
players[consoleplayer].realtime = UINT32_MAX;
|
|
}
|
|
|
|
if (((mapheaderinfo[gamemap-1]->mainrecord[preset]->time == 0) || (players[consoleplayer].realtime < mapheaderinfo[gamemap-1]->mainrecord[preset]->time))
|
|
&& (players[consoleplayer].realtime < UINT32_MAX)) // DNF
|
|
{
|
|
mapheaderinfo[gamemap-1]->mainrecord[preset]->time = players[consoleplayer].realtime;
|
|
}
|
|
|
|
if (modeattacking == ATTACKING_TIME)
|
|
{
|
|
if ((mapheaderinfo[gamemap-1]->mainrecord[preset]->lap == 0) || (bestlap < mapheaderinfo[gamemap-1]->mainrecord[preset]->lap))
|
|
mapheaderinfo[gamemap-1]->mainrecord[preset]->lap = bestlap;
|
|
}
|
|
else
|
|
{
|
|
mapheaderinfo[gamemap-1]->mainrecord[preset]->lap = 0;
|
|
}
|
|
|
|
// Save demo!
|
|
bestdemo[255] = '\0';
|
|
lastdemo[255] = '\0';
|
|
G_SetDemoTime(players[consoleplayer].realtime, bestlap);
|
|
G_CheckDemoStatus();
|
|
|
|
gpath = xva("%s"PATHSEP"media"PATHSEP"replay"PATHSEP"%s"PATHSEP"%s",
|
|
srb2home, timeattackfolder, G_BuildMapName(gamemap));
|
|
parts = M_PathParts(gpath);
|
|
M_MkdirEachUntil(gpath, parts - 4, parts - 1, 0755);
|
|
|
|
snprintf(lastdemo, 255, "%s-%s-%s-last.lmp", gpath, cv_chooseskin.string, gamemode);
|
|
|
|
if (FIL_FileExists(lastdemo))
|
|
{
|
|
UINT8 *buf;
|
|
size_t len = FIL_ReadFile(lastdemo, &buf);
|
|
|
|
snprintf(bestdemo, 255, "%s-%s-%s-time-best.lmp", gpath, cv_chooseskin.string, gamemode);
|
|
if (!FIL_FileExists(bestdemo) || G_CmpDemoTime(bestdemo, lastdemo) & 1)
|
|
{ // Better time, save this demo.
|
|
if (FIL_FileExists(bestdemo))
|
|
remove(bestdemo);
|
|
FIL_WriteFile(bestdemo, buf, len);
|
|
CONS_Printf("\x83%s\x80 %s '%s'\n", M_GetText("NEW RECORD TIME!"), M_GetText("Saved replay as"), bestdemo);
|
|
}
|
|
|
|
if (modeattacking == ATTACKING_TIME)
|
|
{
|
|
snprintf(bestdemo, 255, "%s-%s-%s-lap-best.lmp", gpath, cv_chooseskin.string, gamemode);
|
|
if (!FIL_FileExists(bestdemo) || G_CmpDemoTime(bestdemo, lastdemo) & (1<<1))
|
|
{ // Better lap time, save this demo.
|
|
if (FIL_FileExists(bestdemo))
|
|
remove(bestdemo);
|
|
FIL_WriteFile(bestdemo, buf, len);
|
|
CONS_Printf("\x83%s\x80 %s '%s'\n", M_GetText("NEW RECORD LAP!"), M_GetText("Saved replay as"), bestdemo);
|
|
}
|
|
}
|
|
|
|
//CONS_Printf("%s '%s'\n", M_GetText("Saved replay as"), lastdemo);
|
|
|
|
Z_Free(buf);
|
|
}
|
|
|
|
free(gpath);
|
|
Z_Free(gamemode);
|
|
|
|
// Check emblems when level data is updated
|
|
if ((earnedEmblems = M_CheckLevelEmblems()))
|
|
CONS_Printf(M_GetText("\x82" "Earned %hu medal%s for Record Attack records.\n"), (UINT16)earnedEmblems, earnedEmblems > 1 ? "s" : "");
|
|
|
|
if (M_UpdateUnlockablesAndExtraEmblems())
|
|
S_StartSound(NULL, sfx_ncitem);
|
|
|
|
// SRB2Kart - save here so you NEVER lose your earned times/medals.
|
|
G_SaveGameData();
|
|
}
|
|
|
|
// kinda hacky way to do this, but this sets the game to use a seperate savefile if you have addons loaded
|
|
static void G_SetSaveGameModified(void)
|
|
{
|
|
size_t filenamelen;
|
|
|
|
if (savemoddata)
|
|
return;
|
|
|
|
// save vanilla data just to be sure
|
|
G_SaveGameData();
|
|
|
|
savemoddata = true;
|
|
|
|
strlcpy(gamedatafilename, "modkartdata.dat", sizeof (gamedatafilename));
|
|
strlwr(gamedatafilename);
|
|
|
|
// Also save a time attack folder
|
|
filenamelen = strlen(gamedatafilename)-4; // Strip off the extension
|
|
filenamelen = min(filenamelen, sizeof (timeattackfolder));
|
|
memcpy(timeattackfolder, gamedatafilename, filenamelen);
|
|
timeattackfolder[min(filenamelen, sizeof (timeattackfolder) - 1)] = '\0';
|
|
|
|
strcpy(savegamename, timeattackfolder);
|
|
strlcat(savegamename, "%u.ssg", sizeof(savegamename));
|
|
// can't use sprintf since there is %u in savegamename
|
|
strcatbf(savegamename, srb2home, PATHSEP);
|
|
|
|
G_LoadGameData();
|
|
|
|
// unlock EVERYTHING.
|
|
for (UINT8 i = 0; i < MAXUNLOCKABLES; i++)
|
|
{
|
|
if (!unlockables[i].conditionset)
|
|
continue;
|
|
if (!unlockables[i].unlocked)
|
|
{
|
|
unlockables[i].unlocked = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
// for consistency among messages: this modifies the game and removes savemoddata.
|
|
void G_SetGameModified(boolean silent, boolean major)
|
|
{
|
|
if ((majormods && modifiedgame) || (refreshdirmenu & REFRESHDIR_GAMEDATA)) // new gamedata amnesty?
|
|
return;
|
|
|
|
modifiedgame = true;
|
|
|
|
if (!major)
|
|
return;
|
|
|
|
//savemoddata = false; -- there is literally no reason to do this anymore.
|
|
majormods = true;
|
|
|
|
// should this only be done when you load a "major" gameplay modifieng addon?
|
|
G_SetSaveGameModified();
|
|
|
|
if (!silent)
|
|
CONS_Alert(CONS_NOTICE, M_GetText("Record Attack data will be saved to seperate save.\n"));
|
|
|
|
// If in record attack recording, cancel it.
|
|
if (modeattacking)
|
|
M_ModeAttackEndGame(0);
|
|
else if (marathonmode)
|
|
Command_ExitGame_f();
|
|
}
|
|
|
|
/** Builds an original game map name from a map number.
|
|
*
|
|
* \param map Map number.
|
|
* \return Pointer to a static buffer containing the desired map name.
|
|
* \sa G_MapNumber
|
|
*/
|
|
const char *G_BuildMapName(INT32 map)
|
|
{
|
|
if (map > 0 && map <= nummapheaders && mapheaderinfo[map - 1] != NULL)
|
|
{
|
|
return mapheaderinfo[map - 1]->lumpname;
|
|
}
|
|
else
|
|
{
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
/** Returns the map number for map lump name.
|
|
*
|
|
* \param name Map name;
|
|
* \return Map number.
|
|
* \sa G_BuildMapName, nextmapspecial_t
|
|
*/
|
|
INT32 G_MapNumber(const char * name)
|
|
{
|
|
#ifdef NEXTMAPINSOC
|
|
if (strncasecmp("NEXTMAP_", name, 8) != 0)
|
|
#endif
|
|
{
|
|
INT32 map;
|
|
UINT32 hash = quickncasehash(name, MAXMAPLUMPNAME);
|
|
|
|
for (map = 0; map < nummapheaders; ++map)
|
|
{
|
|
if (hash != mapheaderinfo[map]->lumpnamehash)
|
|
continue;
|
|
|
|
if (strcasecmp(mapheaderinfo[map]->lumpname, name) != 0)
|
|
continue;
|
|
|
|
return map;
|
|
}
|
|
|
|
return NEXTMAP_INVALID;
|
|
}
|
|
|
|
#ifdef NEXTMAPINSOC
|
|
name += 8;
|
|
|
|
if (strcasecmp("EVALUATION", name) == 0)
|
|
return NEXTMAP_EVALUATION;
|
|
if (strcasecmp("CREDITS", name) == 0)
|
|
return NEXTMAP_CREDITS;
|
|
//if (strcasecmp("CEREMONY", name) == 0)
|
|
//return NEXTMAP_CEREMONY;
|
|
//if (strcasecmp("TITLE", name) == 0)
|
|
return NEXTMAP_TITLE;
|
|
#endif
|
|
}
|
|
|
|
// convert kart map number to native map number
|
|
INT16 G_KartMapToNative(INT16 mapnum)
|
|
{
|
|
if (mapnum > 0 && mapnum < NEXTMAP_SPECIAL)
|
|
return kartmap2native[mapnum-1]+1;
|
|
return 0;
|
|
}
|
|
|
|
// convert native map number to kart
|
|
INT16 G_NativeMapToKart(INT16 mapnum)
|
|
{
|
|
if (mapnum > 0 && mapnum < NEXTMAP_SPECIAL)
|
|
return nativemap2kart[mapnum-1]+1;
|
|
return 0;
|
|
}
|
|
|
|
/** Clips the console player's mouse aiming to the current view.
|
|
* Used whenever the player view is changed manually.
|
|
*
|
|
* \param aiming Pointer to the vertical angle to clip.
|
|
* \return The clipped angle.
|
|
*/
|
|
INT32 G_ClipAimingPitch(INT32 *aiming)
|
|
{
|
|
INT32 limitangle;
|
|
|
|
limitangle = ANGLE_90 - 1;
|
|
|
|
if (*aiming > limitangle)
|
|
*aiming = limitangle;
|
|
else if (*aiming < -limitangle)
|
|
*aiming = -limitangle;
|
|
|
|
return (*aiming);
|
|
}
|
|
|
|
INT16 G_SoftwareClipAimingPitch(INT32 *aiming)
|
|
{
|
|
INT32 limitangle;
|
|
|
|
// note: the current software mode implementation doesn't have true perspective
|
|
limitangle = ANGLE_90 - ANG10; // Some viewing fun, but not too far down...
|
|
|
|
if (*aiming > limitangle)
|
|
*aiming = limitangle;
|
|
else if (*aiming < -limitangle)
|
|
*aiming = -limitangle;
|
|
|
|
return (INT16)((*aiming)>>16);
|
|
}
|
|
|
|
void G_FinalClipAimingPitch(INT32 *aiming, player_t *player, boolean skybox)
|
|
{
|
|
#ifndef HWRENDER
|
|
(void)player;
|
|
(void)skybox;
|
|
#endif
|
|
|
|
// clip it in the case we are looking a hardware 90 degrees full aiming
|
|
// (lmps, network and use F12...)
|
|
if (rendermode == render_soft
|
|
#ifdef HWRENDER
|
|
|| (rendermode == render_opengl
|
|
&& (cv_glshearing.value == 1
|
|
|| (cv_glshearing.value == 2 && R_IsViewpointThirdPerson(player, skybox))))
|
|
#endif
|
|
)
|
|
{
|
|
G_SoftwareClipAimingPitch(aiming);
|
|
}
|
|
else
|
|
{
|
|
G_ClipAimingPitch(aiming);
|
|
}
|
|
}
|
|
|
|
// returns true if event's axis is within the deadzone for the given player
|
|
boolean G_AxisInDeadzone(UINT8 p, event_t *ev)
|
|
{
|
|
return abs(ev->data2) <= (JOYAXISRANGE * cv_deadzone[p].value) / FRACUNIT;
|
|
}
|
|
|
|
// check if the given key is bound to the given gamecontrol
|
|
// if defaults is true, also check default controls if the gamecontrol has no binds
|
|
boolean G_ControlBoundToKey(UINT8 p, INT32 gc, INT32 key, boolean defaults)
|
|
{
|
|
INT32 i;
|
|
INT32 (*map)[MAXINPUTMAPPING] = &gamecontrol[p][gc];
|
|
|
|
if (key <= 0 || key >= NUMINPUTS)
|
|
return false;
|
|
|
|
if (defaults)
|
|
{
|
|
for (i = 0; i < MAXINPUTMAPPING; i++)
|
|
if (G_KeyIsAvailable((*map)[i], cv_usejoystick[p].value, false))
|
|
goto bound;
|
|
map = &gamecontroldefault[gc];
|
|
}
|
|
bound:
|
|
|
|
for (i = 0; i < MAXINPUTMAPPING; i++)
|
|
if ((*map)[i] == key)
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
INT32 G_PlayerInputAnalog(UINT8 p, INT32 gc, boolean digital)
|
|
{
|
|
INT32 deviceID;
|
|
INT32 i;
|
|
INT32 deadzone = 0;
|
|
|
|
if (p >= MAXSPLITSCREENPLAYERS)
|
|
{
|
|
#ifdef PARANOIA
|
|
CONS_Debug(DBG_GAMELOGIC, "G_PlayerInputAnalog: Invalid player ID %d\n", p);
|
|
#endif
|
|
return 0;
|
|
}
|
|
|
|
deadzone = (JOYAXISRANGE * cv_deadzone[p].value) / FRACUNIT;
|
|
|
|
deviceID = cv_usejoystick[p].value;
|
|
|
|
retrygetcontrol:
|
|
for (i = 0; i < MAXINPUTMAPPING; i++)
|
|
{
|
|
INT32 key = gamecontrol[p][gc][i];
|
|
INT32 value = 0;
|
|
|
|
// Invalid key number.
|
|
if (!G_KeyIsAvailable(key, deviceID, digital))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
value = gamekeydown[deviceID][key];
|
|
|
|
if (value >= deadzone)
|
|
{
|
|
return value;
|
|
}
|
|
}
|
|
|
|
// If you're on controller, try your keyboard-based binds as an immediate backup.
|
|
if (deviceID > 0)
|
|
{
|
|
deviceID = 0;
|
|
goto retrygetcontrol;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
boolean G_PlayerInputDown(UINT8 p, INT32 gc, boolean digital)
|
|
{
|
|
return (G_PlayerInputAnalog(p, gc, digital) != 0);
|
|
}
|
|
|
|
// Take a magnitude of two axes, and adjust it to take out the deadzone
|
|
// Will return a value between 0 and JOYAXISRANGE
|
|
static INT32 G_BasicDeadZoneCalculation(INT32 magnitude, fixed_t deadZone)
|
|
{
|
|
const INT32 jdeadzone = (JOYAXISRANGE * deadZone) / FRACUNIT;
|
|
INT32 deadzoneAppliedValue = 0;
|
|
INT32 adjustedMagnitude = abs(magnitude);
|
|
|
|
if (jdeadzone >= JOYAXISRANGE && adjustedMagnitude >= JOYAXISRANGE) // If the deadzone and magnitude are both 100%...
|
|
return JOYAXISRANGE; // ...return 100% input directly, to avoid dividing by 0
|
|
else if (adjustedMagnitude > jdeadzone) // Otherwise, calculate how much the magnitude exceeds the deadzone
|
|
{
|
|
adjustedMagnitude = min(adjustedMagnitude, JOYAXISRANGE);
|
|
|
|
adjustedMagnitude -= jdeadzone;
|
|
|
|
deadzoneAppliedValue = (adjustedMagnitude * JOYAXISRANGE) / (JOYAXISRANGE - jdeadzone);
|
|
}
|
|
|
|
return deadzoneAppliedValue;
|
|
}
|
|
|
|
// Get the actual sensible radial value for a joystick axis when accounting for a deadzone
|
|
static void G_HandleAxisDeadZone(UINT8 splitnum, joystickvector2_t *joystickvector)
|
|
{
|
|
INT32 gamepadStyle = Joystick[splitnum].bGamepadStyle;
|
|
fixed_t deadZone = cv_deadzone[splitnum].value;
|
|
SINT8 deadZoneStyle = cv_deadzonestyle[splitnum].value;
|
|
|
|
// When gamepadstyle is "true" the values are just -1, 0, or 1. This is done in the interface code.
|
|
|
|
// v1 style deadzone == (deadZoneStyle == 0)
|
|
// Deadzone doesn't scale so shallower angles are easier to hit.
|
|
|
|
// RR style deadzone
|
|
// Dead zone scales so shallower angles are harder to hit but you have more range.
|
|
if (!gamepadStyle && (deadZoneStyle == 1))
|
|
{
|
|
// Get the total magnitude of the 2 axes
|
|
INT32 magnitude = (joystickvector->xaxis * joystickvector->xaxis) + (joystickvector->yaxis * joystickvector->yaxis);
|
|
INT32 normalisedXAxis;
|
|
INT32 normalisedYAxis;
|
|
INT32 normalisedMagnitude;
|
|
double dMagnitude = sqrt((double)magnitude);
|
|
magnitude = (INT32)dMagnitude;
|
|
|
|
// Get the normalised xy values from the magnitude
|
|
normalisedXAxis = (joystickvector->xaxis * magnitude) / JOYAXISRANGE;
|
|
normalisedYAxis = (joystickvector->yaxis * magnitude) / JOYAXISRANGE;
|
|
|
|
// Apply the deadzone to the magnitude to give a correct value between 0 and JOYAXISRANGE
|
|
normalisedMagnitude = G_BasicDeadZoneCalculation(magnitude, deadZone);
|
|
|
|
// Apply the deadzone to the xy axes
|
|
joystickvector->xaxis = (normalisedXAxis * normalisedMagnitude) / JOYAXISRANGE;
|
|
joystickvector->yaxis = (normalisedYAxis * normalisedMagnitude) / JOYAXISRANGE;
|
|
|
|
// Cap the values so they don't go above the correct maximum
|
|
joystickvector->xaxis = min(joystickvector->xaxis, JOYAXISRANGE);
|
|
joystickvector->xaxis = max(joystickvector->xaxis, -JOYAXISRANGE);
|
|
joystickvector->yaxis = min(joystickvector->yaxis, JOYAXISRANGE);
|
|
joystickvector->yaxis = max(joystickvector->yaxis, -JOYAXISRANGE);
|
|
}
|
|
}
|
|
|
|
//
|
|
// G_BuildTiccmd
|
|
// Builds a ticcmd from all of the available inputs
|
|
// or reads it from the demo buffer.
|
|
// If recording a demo, write it out
|
|
//
|
|
//
|
|
INT32 localaiming[MAXSPLITSCREENPLAYERS];
|
|
angle_t localangle[MAXSPLITSCREENPLAYERS];
|
|
|
|
// Turning was removed from G_BuildTiccmd to prevent easy client hacking.
|
|
// This brings back the camera prediction that was lost.
|
|
static void G_DoAnglePrediction(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer, player_t *player)
|
|
{
|
|
UINT8 viewnum = G_PartyPosition(g_localplayers[ssplayer-1]);
|
|
|
|
if (player->mo)
|
|
cmd->angle = K_GetKartTurnValue(player, cmd->turning);
|
|
|
|
cmd->angle *= realtics;
|
|
|
|
if (P_CanPlayerTurn(player, cmd))
|
|
localangle[viewnum] += (cmd->angle<<TICCMD_REDUCE);
|
|
|
|
cmd->angle = (INT16)(localangle[viewnum] >> TICCMD_REDUCE);
|
|
}
|
|
|
|
void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer)
|
|
{
|
|
const UINT8 forplayer = ssplayer-1;
|
|
|
|
static INT32 turnheld[MAXSPLITSCREENPLAYERS]; // for accelerative turning
|
|
static boolean resetdown[MAXSPLITSCREENPLAYERS]; // don't cam reset every frame
|
|
|
|
INT32 forward, side, tspeed;
|
|
|
|
joystickvector2_t joystickvector;
|
|
|
|
// you'd BETTER not touch the player while freecamming...
|
|
player_t *player = &players[g_localplayers[forplayer]];
|
|
camera_t *thiscam = &camera[forplayer];
|
|
boolean *rd = &resetdown[forplayer];
|
|
boolean spectating = player->spectator || thiscam->freecam;
|
|
// Is there any reason this can't just be I_BaseTiccmd?
|
|
switch (ssplayer)
|
|
{
|
|
case 2:
|
|
G_CopyTiccmd(cmd, I_BaseTiccmd2(), 1);
|
|
break;
|
|
case 3:
|
|
G_CopyTiccmd(cmd, I_BaseTiccmd3(), 1);
|
|
break;
|
|
case 4:
|
|
G_CopyTiccmd(cmd, I_BaseTiccmd4(), 1);
|
|
break;
|
|
case 1:
|
|
default:
|
|
G_CopyTiccmd(cmd, I_BaseTiccmd(), 1); // empty, or external driver
|
|
break;
|
|
}
|
|
|
|
// why build a ticcmd if we're paused?
|
|
// Or, for that matter, if we're being reborn.
|
|
if (!thiscam->freecam && (paused || P_AutoPause() || (gamestate == GS_LEVEL && player->playerstate == PST_REBORN)))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (K_PlayerUsesBotMovement(player))
|
|
{
|
|
// Bot ticcmd is generated by K_BuildBotTiccmd
|
|
return;
|
|
}
|
|
|
|
joystickvector.xaxis = G_PlayerInputAnalog(forplayer, gc_turnright, false) - G_PlayerInputAnalog(forplayer, gc_turnleft, false);
|
|
joystickvector.yaxis = 0;
|
|
G_HandleAxisDeadZone(forplayer, &joystickvector);
|
|
|
|
// For kart, I've turned the aim axis into a digital axis because we only
|
|
// use it for aiming to throw items forward/backward and the vote screen
|
|
// This mean that the turn axis will still be gradient but up/down will be 0
|
|
// until the stick is pushed far enough
|
|
joystickvector.yaxis = G_PlayerInputAnalog(forplayer, gc_aimbackward, false) - G_PlayerInputAnalog(forplayer, gc_aimforward, false);
|
|
|
|
if (encoremode)
|
|
{
|
|
joystickvector.xaxis = -joystickvector.xaxis;
|
|
}
|
|
|
|
forward = side = 0;
|
|
tspeed = joystickvector.xaxis;
|
|
|
|
// use two stage accelerative turning
|
|
// on the keyboard and (NOT!) joystick
|
|
if (joystickvector.xaxis != 0)
|
|
{
|
|
turnheld[forplayer] += realtics;
|
|
|
|
if (turnheld[forplayer] < cv_turnsmooth.value * 3)
|
|
{
|
|
// check turn input again, but this time digital only
|
|
// if it's false, an analog stick is inputting the turn; no smoothing!
|
|
if (G_PlayerInputDown(forplayer, gc_turnleft, true) || G_PlayerInputDown(forplayer, gc_turnright, true))
|
|
{
|
|
I_Assert(cv_turnsmooth.value);
|
|
tspeed /= cv_turnsmooth.value * 2;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
turnheld[forplayer] = 0;
|
|
|
|
cmd->turning = 0;
|
|
|
|
if (joystickvector.xaxis != 0)
|
|
{
|
|
cmd->turning -= (tspeed * KART_FULLTURN) / JOYAXISRANGE;
|
|
side += (joystickvector.xaxis * 4) / JOYAXISRANGE;
|
|
}
|
|
|
|
// Specator mouse turning
|
|
if (spectating)
|
|
{
|
|
INT32 mousex = gamekeydown[0][KEY_MOUSEMOVE+3] - gamekeydown[0][KEY_MOUSEMOVE+2];
|
|
cmd->turning -= (mousex * 8) * (encoremode ? -1 : 1);
|
|
}
|
|
|
|
if (spectating || objectplacing) // SRB2Kart: spectators need special controls
|
|
{
|
|
if (G_PlayerInputDown(forplayer, gc_accelerate, false))
|
|
{
|
|
cmd->buttons |= BT_ACCELERATE;
|
|
}
|
|
|
|
if (G_PlayerInputDown(forplayer, gc_brake, false))
|
|
{
|
|
cmd->buttons |= BT_BRAKE;
|
|
}
|
|
|
|
if (joystickvector.yaxis < 0)
|
|
{
|
|
forward += MAXPLMOVE;
|
|
}
|
|
|
|
if (joystickvector.yaxis > 0)
|
|
{
|
|
forward -= MAXPLMOVE;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// forward with key or button // SRB2kart - we use an accel/brake instead of forward/backward.
|
|
fixed_t value = G_PlayerInputAnalog(forplayer, gc_accelerate, false);
|
|
if (value != 0)
|
|
{
|
|
cmd->buttons |= BT_ACCELERATE;
|
|
forward += (value * MAXPLMOVE) / JOYAXISRANGE;
|
|
}
|
|
|
|
if (player->sneakertimer)
|
|
forward = MAXPLMOVE; // 50
|
|
|
|
value = G_PlayerInputAnalog(forplayer, gc_brake, false);
|
|
if (value != 0)
|
|
{
|
|
cmd->buttons |= BT_BRAKE;
|
|
forward -= (value * 25) / JOYAXISRANGE;
|
|
}
|
|
|
|
// But forward/backward IS used for aiming.
|
|
if (joystickvector.yaxis != 0)
|
|
{
|
|
cmd->throwdir -= (joystickvector.yaxis * KART_FULLTURN) / JOYAXISRANGE;
|
|
cmd->buttons |= joystickvector.yaxis < 0 ? BT_FORWARD : BT_BACKWARD;
|
|
}
|
|
}
|
|
|
|
// fire with any button/key
|
|
if (G_PlayerInputDown(forplayer, gc_fire, false))
|
|
{
|
|
cmd->buttons |= BT_ATTACK;
|
|
}
|
|
|
|
// drift with any button/key
|
|
if (G_PlayerInputDown(forplayer, gc_drift, false))
|
|
{
|
|
cmd->buttons |= BT_DRIFT;
|
|
}
|
|
|
|
// rear view with any button/key
|
|
if (G_PlayerInputDown(forplayer, gc_lookback, false))
|
|
{
|
|
cmd->buttons |= BT_LOOKBACK;
|
|
}
|
|
|
|
// Lua scriptable buttons
|
|
if (G_PlayerInputDown(forplayer, gc_custom1, false))
|
|
cmd->buttons |= BT_CUSTOM1;
|
|
if (G_PlayerInputDown(forplayer, gc_custom2, false))
|
|
cmd->buttons |= BT_CUSTOM2;
|
|
if (G_PlayerInputDown(forplayer, gc_custom3, false))
|
|
cmd->buttons |= BT_CUSTOM3;
|
|
|
|
// Reset camera
|
|
if (G_PlayerInputDown(forplayer, gc_camreset, false))
|
|
{
|
|
if (thiscam->chase && *rd == false)
|
|
P_ResetCamera(player, thiscam);
|
|
*rd = true;
|
|
}
|
|
else
|
|
*rd = false;
|
|
|
|
// spectator aiming shit, ahhhh...
|
|
{
|
|
INT32 screen_invert =
|
|
(player->mo && (player->mo->eflags & MFE_VERTICALFLIP)
|
|
&& (!thiscam->chase)) //because chasecam's not inverted
|
|
? -1 : 1; // set to -1 or 1 to multiply
|
|
|
|
INT32 axis = G_PlayerInputAnalog(forplayer, gc_lookup, false) - G_PlayerInputAnalog(forplayer, gc_lookdown, false);
|
|
|
|
// either i allow mouse binds in controls... or i just hardcode it :^)
|
|
INT32 mousey = gamekeydown[0][KEY_MOUSEMOVE+1] - gamekeydown[0][KEY_MOUSEMOVE+0];
|
|
axis += mousey * 8*2;
|
|
|
|
if (axis != 0 && spectating)
|
|
cmd->aiming += axis/2 * screen_invert; // divide by 2 to match KB_LOOKSPEED
|
|
|
|
if (G_PlayerInputDown(forplayer, gc_centerview, false)) // // No need to put a spectator limit on this one though :V
|
|
cmd->aiming = 0;
|
|
}
|
|
|
|
cmd->forwardmove += (SINT8)forward;
|
|
cmd->sidemove += (SINT8)side;
|
|
cmd->flags = 0;
|
|
|
|
if (chat_on || CON_Ready())
|
|
{
|
|
cmd->flags |= TICCMD_TYPING;
|
|
|
|
if (hu_keystrokes)
|
|
{
|
|
cmd->flags |= TICCMD_KEYSTROKE;
|
|
}
|
|
}
|
|
|
|
/* Lua: Allow this hook to overwrite ticcmd.
|
|
We check if we're actually in a level because for some reason this Hook would run in menus and on the titlescreen otherwise.
|
|
Be aware that within this hook, nothing but this player's cmd can be edited (otherwise we'd run in some pretty bad synching problems since this is clientsided, or something)
|
|
|
|
Possible usages for this are:
|
|
-Forcing the player to perform an action, which could otherwise require terrible, terrible hacking to replicate.
|
|
-Preventing the player to perform an action, which would ALSO require some weirdo hacks.
|
|
-Making some galaxy brain autopilot Lua if you're a masochist
|
|
-Making a Mario Kart 8 Deluxe tier baby mode that steers you away from walls and whatnot. You know what, do what you want!
|
|
*/
|
|
if (addedtogame && gamestate == GS_LEVEL)
|
|
{
|
|
LUA_HookTiccmd(player, cmd, HOOK(PlayerCmd));
|
|
|
|
// Send leveltime when this tic was generated to the server for control lag calculations.
|
|
// Only do this when in a level. Also do this after the hook, so that it can't overwrite this.
|
|
cmd->latency = (leveltime & TICCMD_LATENCYMASK);
|
|
}
|
|
|
|
if (cmd->forwardmove > MAXPLMOVE)
|
|
cmd->forwardmove = MAXPLMOVE;
|
|
else if (cmd->forwardmove < -MAXPLMOVE)
|
|
cmd->forwardmove = -MAXPLMOVE;
|
|
|
|
if (cmd->sidemove > MAXPLMOVE)
|
|
cmd->sidemove = MAXPLMOVE;
|
|
else if (cmd->sidemove < -MAXPLMOVE)
|
|
cmd->sidemove = -MAXPLMOVE;
|
|
|
|
if (cmd->turning > KART_FULLTURN)
|
|
cmd->turning = KART_FULLTURN;
|
|
else if (cmd->turning < -KART_FULLTURN)
|
|
cmd->turning = -KART_FULLTURN;
|
|
|
|
if (cmd->throwdir > KART_FULLTURN)
|
|
cmd->throwdir = KART_FULLTURN;
|
|
else if (cmd->throwdir < -KART_FULLTURN)
|
|
cmd->throwdir = -KART_FULLTURN;
|
|
|
|
G_DoAnglePrediction(cmd, realtics, ssplayer, player);
|
|
|
|
// Reset away view if a command is given.
|
|
if ((cmd->forwardmove || cmd->sidemove || cmd->buttons)
|
|
&& !r_splitscreen && displayplayers[0] != consoleplayer && ssplayer == 1)
|
|
{
|
|
// Call ViewpointSwitch hooks here.
|
|
// The viewpoint was forcibly changed.
|
|
LUA_HookViewpointSwitch(player, &players[consoleplayer], true);
|
|
displayplayers[0] = consoleplayer;
|
|
}
|
|
}
|
|
|
|
ticcmd_t *G_CopyTiccmd(ticcmd_t* dest, const ticcmd_t* src, const size_t n)
|
|
{
|
|
return M_Memcpy(dest, src, n*sizeof(*src));
|
|
}
|
|
|
|
ticcmd_t *G_MoveTiccmd(ticcmd_t* dest, const ticcmd_t* src, const size_t n)
|
|
{
|
|
size_t i;
|
|
for (i = 0; i < n; i++)
|
|
{
|
|
dest[i].forwardmove = src[i].forwardmove;
|
|
dest[i].sidemove = src[i].sidemove;
|
|
dest[i].turning = (INT16)SHORT(src[i].turning);
|
|
dest[i].angle = (INT16)SHORT(src[i].angle);
|
|
dest[i].throwdir = (INT16)SHORT(src[i].throwdir);
|
|
dest[i].aiming = (INT16)SHORT(src[i].aiming);
|
|
dest[i].buttons = (UINT16)SHORT(src[i].buttons);
|
|
dest[i].latency = src[i].latency;
|
|
dest[i].flags = src[i].flags;
|
|
|
|
if (dest[i].flags & TICCMD_BOT)
|
|
{
|
|
dest[i].bot.itemconfirm = src[i].bot.itemconfirm;
|
|
dest[i].bot.turnconfirm = src[i].bot.turnconfirm;
|
|
dest[i].bot.respawnconfirm = src[i].bot.respawnconfirm;
|
|
}
|
|
}
|
|
return dest;
|
|
}
|
|
|
|
void weaponPrefChange(void)
|
|
{
|
|
WeaponPref_Send(0);
|
|
}
|
|
|
|
void weaponPrefChange2(void)
|
|
{
|
|
WeaponPref_Send(1);
|
|
}
|
|
|
|
void weaponPrefChange3(void)
|
|
{
|
|
WeaponPref_Send(2);
|
|
}
|
|
|
|
void weaponPrefChange4(void)
|
|
{
|
|
WeaponPref_Send(3);
|
|
}
|
|
|
|
//
|
|
// G_DoLoadLevel
|
|
//
|
|
void G_DoLoadLevel(boolean resetplayer)
|
|
{
|
|
boolean doAutomate = false;
|
|
INT32 i;
|
|
|
|
// Make sure objectplace is OFF when you first start the level!
|
|
OP_ResetObjectplace();
|
|
|
|
levelstarttic = gametic; // for time calculation
|
|
|
|
if (wipegamestate == GS_LEVEL)
|
|
wipegamestate = -1; // force a wipe
|
|
|
|
if (gamestate == GS_INTERMISSION)
|
|
Y_EndIntermission();
|
|
if (gamestate == GS_VOTING)
|
|
Y_EndVote();
|
|
|
|
// cleanup
|
|
if (titlemapinaction == TITLEMAP_LOADING)
|
|
{
|
|
if (gamemap < 1 || gamemap > nummapheaders)
|
|
{
|
|
Z_Free(titlemap);
|
|
titlemap = NULL; // let's not infinite recursion ok
|
|
Command_ExitGame_f();
|
|
return;
|
|
}
|
|
|
|
titlemapinaction = TITLEMAP_RUNNING;
|
|
}
|
|
else
|
|
titlemapinaction = TITLEMAP_OFF;
|
|
|
|
// Doing this matches HOSTMOD behavior.
|
|
// Is that desired? IDK
|
|
doAutomate = (gamestate != GS_LEVEL);
|
|
|
|
G_SetGamestate(GS_LEVEL);
|
|
I_UpdateMouseGrab();
|
|
|
|
for (i = 0; i < MAXPLAYERS; i++)
|
|
{
|
|
if (resetplayer || (playeringame[i] && players[i].playerstate == PST_DEAD))
|
|
players[i].playerstate = PST_REBORN;
|
|
}
|
|
|
|
// Setup the level.
|
|
if (!P_LoadLevel(false, false)) // this never returns false?
|
|
{
|
|
// fail so reset game stuff
|
|
Command_ExitGame_f();
|
|
return;
|
|
}
|
|
|
|
gameaction = ga_nothing;
|
|
#ifdef PARANOIA
|
|
Z_CheckHeap(-2);
|
|
#endif
|
|
|
|
for (i = 0; i <= r_splitscreen; i++)
|
|
{
|
|
if (camera[i].chase)
|
|
P_ResetCamera(&players[displayplayers[i]], &camera[i]);
|
|
}
|
|
|
|
// clear cmd building stuff
|
|
memset(gamekeydown, 0, sizeof (gamekeydown));
|
|
memset(deviceResponding, false, sizeof (deviceResponding));
|
|
|
|
// clear hud messages remains (usually from game startup)
|
|
CON_ClearHUD();
|
|
|
|
server_lagless = cv_lagless.value;
|
|
|
|
if (doAutomate == true)
|
|
{
|
|
Automate_Run(AEV_ROUNDSTART);
|
|
}
|
|
}
|
|
|
|
//
|
|
// Start the title card.
|
|
//
|
|
void G_StartTitleCard(void)
|
|
{
|
|
// The title card has been disabled for this map.
|
|
// Oh well.
|
|
if (!G_IsTitleCardAvailable() || demo.rewinding)
|
|
{
|
|
WipeStageTitle = false;
|
|
return;
|
|
}
|
|
|
|
// clear the hud
|
|
CON_ClearHUD();
|
|
|
|
// prepare status bar
|
|
ST_startTitleCard();
|
|
|
|
// start the title card
|
|
WipeStageTitle = (!titlemapinaction);
|
|
}
|
|
|
|
//
|
|
// Run the title card before fading in to the level.
|
|
//
|
|
void G_PreLevelTitleCard(void)
|
|
{
|
|
#ifndef NOWIPE
|
|
tic_t strtime = I_GetTime();
|
|
tic_t endtime = strtime + (PRELEVELTIME*NEWTICRATERATIO);
|
|
tic_t nowtime = strtime;
|
|
tic_t lasttime = strtime;
|
|
while (nowtime < endtime)
|
|
{
|
|
// draw loop
|
|
ST_runTitleCard();
|
|
ST_preLevelTitleCardDrawer();
|
|
I_FinishUpdate(); // page flip or blit buffer
|
|
NetKeepAlive(); // Prevent timeouts
|
|
|
|
if (moviemode)
|
|
M_SaveFrame();
|
|
if (takescreenshot) // Only take screenshots after drawing.
|
|
M_DoScreenShot();
|
|
|
|
while (!((nowtime = I_GetTime()) - lasttime))
|
|
{
|
|
I_Sleep(cv_sleep.value);
|
|
I_UpdateTime(cv_timescale.value);
|
|
}
|
|
lasttime = nowtime;
|
|
}
|
|
#endif
|
|
}
|
|
|
|
//
|
|
// Returns true if the current level has a title card.
|
|
//
|
|
boolean G_IsTitleCardAvailable(void)
|
|
{
|
|
#if 0
|
|
// The current level has no name.
|
|
if (!mapheaderinfo[gamemap-1]->lvlttl[0])
|
|
return false;
|
|
#endif
|
|
|
|
// The title card is available.
|
|
return true;
|
|
}
|
|
|
|
INT32 pausedelay = 0;
|
|
boolean pausebreakkey = false;
|
|
static INT32 camtoggledelay[MAXSPLITSCREENPLAYERS];
|
|
static INT32 spectatedelay[MAXSPLITSCREENPLAYERS];
|
|
static INT32 respawndelay[MAXSPLITSCREENPLAYERS];
|
|
|
|
//
|
|
// G_Responder
|
|
// Get info needed to make ticcmd_ts for the players.
|
|
//
|
|
boolean G_Responder(event_t *ev)
|
|
{
|
|
UINT8 i;
|
|
|
|
// any other key pops up menu if in demos
|
|
if (gameaction == ga_nothing && !demo.quitafterplaying &&
|
|
((demo.playback && !modeattacking && !demo.title && !multiplayer) || gamestate == GS_TITLESCREEN))
|
|
{
|
|
if (ev->type == ev_keydown && ev->data1 != 301 && !(gamestate == GS_TITLESCREEN && finalecount < TICRATE))
|
|
{
|
|
M_StartControlPanel();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
else if (demo.playback && demo.title)
|
|
{
|
|
// Title demo uses intro responder
|
|
if (F_IntroResponder(ev))
|
|
{
|
|
// stop the title demo
|
|
G_CheckDemoStatus();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
if (gamestate == GS_LEVEL)
|
|
{
|
|
if (HU_Responder(ev))
|
|
{
|
|
hu_keystrokes = true;
|
|
return true; // chat ate the event
|
|
}
|
|
if (AM_Responder(ev))
|
|
return true; // automap ate it
|
|
// map the event (key/mouse/joy) to a gamecontrol
|
|
}
|
|
// Intro
|
|
else if (gamestate == GS_INTRO)
|
|
{
|
|
if (F_IntroResponder(ev))
|
|
{
|
|
D_StartTitle();
|
|
return true;
|
|
}
|
|
}
|
|
else if (gamestate == GS_CUTSCENE)
|
|
{
|
|
if (HU_Responder(ev))
|
|
{
|
|
hu_keystrokes = true;
|
|
return true; // chat ate the event
|
|
}
|
|
|
|
if (F_CutsceneResponder(ev))
|
|
{
|
|
D_StartTitle();
|
|
return true;
|
|
}
|
|
}
|
|
else if (gamestate == GS_CREDITS) // todo: keep ending here?
|
|
{
|
|
if (HU_Responder(ev))
|
|
{
|
|
hu_keystrokes = true;
|
|
return true; // chat ate the event
|
|
}
|
|
|
|
if (F_CreditResponder(ev))
|
|
{
|
|
// Skip credits for everyone
|
|
if (! netgame)
|
|
F_StartGameEvaluation();
|
|
else if (server || IsPlayerAdmin(consoleplayer))
|
|
SendNetXCmd(XD_EXITLEVEL, NULL, 0);
|
|
return true;
|
|
}
|
|
}
|
|
else if (gamestate == GS_BLANCREDITS)
|
|
{
|
|
if (HU_Responder(ev))
|
|
{
|
|
hu_keystrokes = true;
|
|
return true; // chat ate the event
|
|
}
|
|
|
|
if (F_CreditResponder(ev))
|
|
{
|
|
// Skip credits for everyone
|
|
if (! netgame)
|
|
F_StartGameEvaluation();
|
|
else if (server || IsPlayerAdmin(consoleplayer))
|
|
SendNetXCmd(XD_EXITLEVEL, NULL, 0);
|
|
return true;
|
|
}
|
|
}
|
|
else if (gamestate == GS_CONTINUING)
|
|
{
|
|
return true;
|
|
}
|
|
// Demo End
|
|
else if (gamestate == GS_GAMEEND)
|
|
{
|
|
return true;
|
|
}
|
|
else if (gamestate == GS_INTERMISSION || gamestate == GS_VOTING || gamestate == GS_EVALUATION)
|
|
if (HU_Responder(ev))
|
|
{
|
|
hu_keystrokes = true;
|
|
return true; // chat ate the event
|
|
}
|
|
|
|
// allow spy mode changes even during the demo
|
|
if (gamestate == GS_LEVEL && ev->type == ev_keydown
|
|
&& G_ControlBoundToKey(0, gc_viewpoint, ev->data1, false))
|
|
{
|
|
if (!demo.playback && (r_splitscreen))
|
|
g_localplayers[0] = consoleplayer;
|
|
else
|
|
{
|
|
G_AdjustView(1, 1, true);
|
|
|
|
// change statusbar also if playing back demo
|
|
if (demo.quitafterplaying)
|
|
ST_changeDemoView();
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
if (gamestate == GS_LEVEL && ev->type == ev_keydown && multiplayer && demo.playback)
|
|
{
|
|
if (G_ControlBoundToKey(1, gc_viewpoint, ev->data1, false))
|
|
{
|
|
G_AdjustView(2, 1, true);
|
|
return true;
|
|
}
|
|
else if (G_ControlBoundToKey(2, gc_viewpoint, ev->data1, false))
|
|
{
|
|
G_AdjustView(3, 1, true);
|
|
return true;
|
|
}
|
|
else if (G_ControlBoundToKey(3, gc_viewpoint, ev->data1, false))
|
|
{
|
|
G_AdjustView(4, 1, true);
|
|
return true;
|
|
}
|
|
|
|
// Allow pausing
|
|
if (G_ControlBoundToKey(0, gc_pause, ev->data1, true))
|
|
{
|
|
paused = !paused;
|
|
|
|
if (demo.rewinding)
|
|
{
|
|
G_ConfirmRewind(leveltime);
|
|
paused = true;
|
|
S_PauseAudio();
|
|
}
|
|
else if (paused)
|
|
S_PauseAudio();
|
|
else
|
|
S_ResumeAudio();
|
|
|
|
return true;
|
|
}
|
|
|
|
// open menu but only w/ esc
|
|
if (ev->data1 == 32)
|
|
{
|
|
M_StartControlPanel();
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
// update keys current state
|
|
G_MapEventsToControls(ev);
|
|
|
|
switch (ev->type)
|
|
{
|
|
case ev_keydown:
|
|
if (G_ControlBoundToKey(0, gc_pause, ev->data1, true))
|
|
{
|
|
if (modeattacking && !demo.playback && (gamestate == GS_LEVEL))
|
|
{
|
|
pausebreakkey = (ev->data1 == KEY_PAUSE);
|
|
if (menustack[0] || pausedelay < 0 || leveltime < 2)
|
|
return true;
|
|
|
|
if (pausedelay < 1+(NEWTICRATE/2))
|
|
pausedelay = 1+(NEWTICRATE/2);
|
|
else if (++pausedelay > 1+(NEWTICRATE/2)+(NEWTICRATE/3))
|
|
{
|
|
G_SetModeAttackRetryFlag();
|
|
return true;
|
|
}
|
|
pausedelay++; // counteract subsequent subtraction this frame
|
|
}
|
|
else
|
|
{
|
|
INT32 oldpausedelay = pausedelay;
|
|
pausedelay = (NEWTICRATE/7);
|
|
if (!oldpausedelay)
|
|
{
|
|
// command will handle all the checks for us
|
|
COM_ImmedExecute("pause");
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
for (i = 0; i < MAXSPLITSCREENPLAYERS; i++)
|
|
{
|
|
if (G_ControlBoundToKey(i, gc_camtoggle, ev->data1, false))
|
|
{
|
|
if (!camtoggledelay[i])
|
|
{
|
|
camtoggledelay[i] = NEWTICRATE / 7;
|
|
CV_SetValue(&cv_chasecam[i], cv_chasecam[i].value ? 0 : 1);
|
|
}
|
|
}
|
|
|
|
if (G_ControlBoundToKey(i, gc_spectate, ev->data1, false))
|
|
{
|
|
if (!spectatedelay[i])
|
|
{
|
|
char *commandname = va("changeteam");
|
|
|
|
if (i > 0)
|
|
{
|
|
// Add one for command names.
|
|
commandname = va("changeteam%d", i+1);
|
|
}
|
|
|
|
spectatedelay[i] = NEWTICRATE / 7;
|
|
COM_ImmedExecute(va("%s spectator", commandname));
|
|
}
|
|
}
|
|
|
|
if (G_ControlBoundToKey(i, gc_respawn, ev->data1, false))
|
|
{
|
|
if (!respawndelay[i])
|
|
{
|
|
char *commandname = va("respawn");
|
|
|
|
if (i > 0)
|
|
{
|
|
// Add one for command names.
|
|
commandname = va("respawn%d", i+1);
|
|
}
|
|
|
|
respawndelay[i] = NEWTICRATE / 4;
|
|
COM_ImmedExecute(commandname);
|
|
}
|
|
}
|
|
}
|
|
|
|
return true;
|
|
|
|
case ev_keyup:
|
|
return false; // always let key up events filter down
|
|
|
|
case ev_mouse:
|
|
return true; // eat events
|
|
|
|
case ev_joystick:
|
|
return true; // eat events
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
//
|
|
// G_CouldView
|
|
// Return whether a player could be viewed by any means.
|
|
//
|
|
boolean G_CouldView(INT32 playernum)
|
|
{
|
|
player_t *player;
|
|
|
|
if (playernum < 0 || playernum > MAXPLAYERS-1)
|
|
return false;
|
|
|
|
if (!playeringame[playernum])
|
|
return false;
|
|
|
|
player = &players[playernum];
|
|
|
|
if (player->spectator)
|
|
return false;
|
|
|
|
// SRB2Kart: Only go through players who are actually playing
|
|
if (player->exiting)
|
|
return false;
|
|
if (( player->pflags & PF_NOCONTEST ))
|
|
return false;
|
|
|
|
// I don't know if we want this actually, but I'll humor the suggestion anyway
|
|
if ((gametyperules & GTR_BUMPERS) && !demo.playback)
|
|
{
|
|
if (player->bumper <= 0)
|
|
return false;
|
|
}
|
|
|
|
// SRB2Kart: we have no team-based modes, YET...
|
|
if (G_GametypeHasTeams())
|
|
{
|
|
if (players[consoleplayer].ctfteam && player->ctfteam != players[consoleplayer].ctfteam)
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
//
|
|
// G_CanView
|
|
// Return whether a player can be viewed on a particular view (splitscreen).
|
|
//
|
|
boolean G_CanView(INT32 playernum, UINT8 viewnum, boolean onlyactive)
|
|
{
|
|
UINT8 splits;
|
|
UINT8 viewd;
|
|
INT32 *displayplayerp;
|
|
|
|
if (!(onlyactive ? G_CouldView(playernum) : (playeringame[playernum] && !players[playernum].spectator)))
|
|
return false;
|
|
|
|
splits = r_splitscreen+1;
|
|
if (viewnum > splits)
|
|
viewnum = splits;
|
|
|
|
for (viewd = 1; viewd < viewnum; ++viewd)
|
|
{
|
|
displayplayerp = (&displayplayers[viewd-1]);
|
|
if ((*displayplayerp) == playernum)
|
|
return false;
|
|
}
|
|
for (viewd = viewnum + 1; viewd <= splits; ++viewd)
|
|
{
|
|
displayplayerp = (&displayplayers[viewd-1]);
|
|
if ((*displayplayerp) == playernum)
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
//
|
|
// G_FindView
|
|
// Return the next player that can be viewed on a view, wraps forward.
|
|
// An out of range startview is corrected.
|
|
//
|
|
INT32 G_FindView(INT32 startview, UINT8 viewnum, boolean onlyactive, boolean reverse)
|
|
{
|
|
INT32 i, dir = reverse ? -1 : 1;
|
|
startview = min(max(startview, 0), MAXPLAYERS);
|
|
for (i = startview; i < MAXPLAYERS && i >= 0; i += dir)
|
|
{
|
|
if (G_CanView(i, viewnum, onlyactive))
|
|
return i;
|
|
}
|
|
for (i = (reverse ? MAXPLAYERS-1 : 0); i != startview; i += dir)
|
|
{
|
|
if (G_CanView(i, viewnum, onlyactive))
|
|
return i;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
INT32 G_CountPlayersPotentiallyViewable(boolean active)
|
|
{
|
|
INT32 total = 0;
|
|
INT32 i;
|
|
for (i = 0; i < MAXPLAYERS; ++i)
|
|
{
|
|
if (active ? G_CouldView(i) : (playeringame[i] && !players[i].spectator))
|
|
total++;
|
|
}
|
|
return total;
|
|
}
|
|
|
|
//
|
|
// G_ResetView
|
|
// Correct a viewpoint to playernum or the next available, wraps forward.
|
|
// Also promotes splitscreen up to available viewable players.
|
|
// An out of range playernum is corrected.
|
|
//
|
|
void G_ResetView(UINT8 viewnum, INT32 playernum, boolean onlyactive)
|
|
{
|
|
UINT8 splits;
|
|
UINT8 viewd;
|
|
|
|
INT32 *displayplayerp;
|
|
|
|
INT32 olddisplayplayer;
|
|
INT32 playersviewable;
|
|
|
|
splits = r_splitscreen+1;
|
|
|
|
/* Promote splits */
|
|
if (viewnum > splits)
|
|
{
|
|
playersviewable = G_CountPlayersPotentiallyViewable(onlyactive);
|
|
if (playersviewable < splits)/* do not demote */
|
|
return;
|
|
|
|
if (viewnum > playersviewable)
|
|
viewnum = playersviewable;
|
|
r_splitscreen = viewnum-1;
|
|
|
|
R_ExecuteSetViewSize();
|
|
}
|
|
|
|
displayplayerp = (&displayplayers[viewnum-1]);
|
|
olddisplayplayer = (*displayplayerp);
|
|
|
|
/* Check if anyone is available to view. */
|
|
if (( playernum = G_FindView(playernum, viewnum, onlyactive, playernum < olddisplayplayer) ) == -1)
|
|
{
|
|
if (G_PartySize(consoleplayer) < viewnum)
|
|
{
|
|
return;
|
|
}
|
|
|
|
/* Fall back on true self */
|
|
playernum = G_PartyMember(consoleplayer, viewnum - 1);
|
|
}
|
|
|
|
// Call ViewpointSwitch hooks here.
|
|
// The viewpoint was forcibly changed.
|
|
LUA_HookViewpointSwitch(&players[g_localplayers[viewnum - 1]], &players[playernum], true);
|
|
|
|
/* Focus our target view first so that we don't take its player. */
|
|
(*displayplayerp) = playernum;
|
|
|
|
/* If a viewpoint changes, reset the camera to clear uninitialized memory. */
|
|
if (viewnum > splits)
|
|
{
|
|
for (viewd = splits+1; viewd <= viewnum; ++viewd)
|
|
{
|
|
G_FixCamera(viewd);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if ((*displayplayerp) != olddisplayplayer)
|
|
{
|
|
G_FixCamera(viewnum);
|
|
}
|
|
}
|
|
|
|
if (demo.playback)
|
|
{
|
|
if (viewnum == 1)
|
|
consoleplayer = displayplayers[0];
|
|
|
|
G_SyncDemoParty(olddisplayplayer, r_splitscreen);
|
|
}
|
|
|
|
// change statusbar also if playing back demo
|
|
if (demo.quitafterplaying)
|
|
ST_changeDemoView();
|
|
}
|
|
|
|
//
|
|
// G_FixCamera
|
|
// Reset camera position, angle and interpolation on a view
|
|
// after changing state.
|
|
//
|
|
void G_FixCamera(UINT8 view)
|
|
{
|
|
player_t *player = &players[displayplayers[view - 1]];
|
|
|
|
// The order of displayplayers can change, which would
|
|
// invalidate localangle.
|
|
localangle[view - 1] = player->angleturn;
|
|
|
|
P_ResetCamera(player, &camera[view - 1]);
|
|
|
|
// Make sure the viewport doesn't interpolate at all into
|
|
// its new position -- just snap instantly into place.
|
|
R_ResetViewInterpolation(view);
|
|
}
|
|
|
|
//
|
|
// G_AdjustView
|
|
// Increment a viewpoint by offset from the current player. A negative value
|
|
// decrements.
|
|
//
|
|
void G_AdjustView(UINT8 viewnum, INT32 offset, boolean onlyactive)
|
|
{
|
|
INT32 *displayplayerp, oldview;
|
|
displayplayerp = &displayplayers[viewnum-1];
|
|
oldview = (*displayplayerp);
|
|
G_ResetView(viewnum, ( (*displayplayerp) + offset ), onlyactive);
|
|
|
|
// If no other view could be found, go back to what we had.
|
|
if ((*displayplayerp) == -1)
|
|
(*displayplayerp) = oldview;
|
|
}
|
|
|
|
//
|
|
// G_ResetViews
|
|
// Ensures all viewpoints are valid
|
|
// Also demotes splitscreen down to one player.
|
|
//
|
|
void G_ResetViews(void)
|
|
{
|
|
UINT8 splits;
|
|
UINT8 viewd;
|
|
|
|
INT32 playersviewable;
|
|
|
|
splits = r_splitscreen+1;
|
|
|
|
playersviewable = G_CountPlayersPotentiallyViewable(false);
|
|
/* Demote splits */
|
|
if (playersviewable < splits)
|
|
{
|
|
splits = max(playersviewable, G_PartySize(consoleplayer)); // don't delete local players
|
|
r_splitscreen = splits - 1;
|
|
R_ExecuteSetViewSize();
|
|
}
|
|
|
|
/*
|
|
Consider installing a method to focus the last
|
|
view elsewhere if all players spectate?
|
|
*/
|
|
for (viewd = 1; viewd <= splits; ++viewd)
|
|
{
|
|
G_AdjustView(viewd, 0, false);
|
|
}
|
|
}
|
|
|
|
//
|
|
// G_Ticker
|
|
// Make ticcmd_ts for the players.
|
|
//
|
|
void G_Ticker(boolean run)
|
|
{
|
|
UINT32 i;
|
|
INT32 buf;
|
|
ticcmd_t *cmd;
|
|
|
|
// see also SCR_DisplayMarathonInfo
|
|
if ((marathonmode & (MA_INIT|MA_INGAME)) == MA_INGAME && gamestate == GS_LEVEL)
|
|
marathontime++;
|
|
|
|
P_MapStart();
|
|
|
|
if (gamestate == GS_LEVEL && G_GetRetryFlag())
|
|
{
|
|
if (demo.playback == true)
|
|
{
|
|
// Stop playback!!
|
|
G_ClearRetryFlag();
|
|
// G_CheckDemoStatus() called here fails an I_Assert in g_party.cpp Console()!?
|
|
// I'm sure there's a completely logical explanation and an elegant solution
|
|
// where we can defer some sort of state change. However I'm tired, I've been
|
|
// looking after my niece, my arm hurts a bit when using mouse/keyboard, and
|
|
// we are ALMOST DONE. So I'm going to bodge this for the sake of release.
|
|
// The minimal set of calls to dump you back to the menu as soon as possible
|
|
// will have to do, so that everybody can have fun racing as rings. ~toast 050424
|
|
G_StopDemo();
|
|
Command_ExitGame_f();
|
|
}
|
|
else
|
|
{
|
|
// Or, alternatively, retry.
|
|
for (i = 0; i < MAXPLAYERS; i++)
|
|
{
|
|
if (playeringame[i])
|
|
{
|
|
if (players[i].bot == true
|
|
&& grandprixinfo.gp == true
|
|
&& grandprixinfo.masterbots == false)
|
|
{
|
|
UINT8 bot_level_decrease = 3;
|
|
|
|
if (grandprixinfo.gamespeed == KARTSPEED_EASY)
|
|
{
|
|
bot_level_decrease++;
|
|
}
|
|
else if (grandprixinfo.gamespeed == KARTSPEED_HARD)
|
|
{
|
|
bot_level_decrease--;
|
|
}
|
|
|
|
if (players[i].botvars.difficulty <= bot_level_decrease)
|
|
{
|
|
players[i].botvars.difficulty = 1;
|
|
}
|
|
else
|
|
{
|
|
players[i].botvars.difficulty -= bot_level_decrease;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
K_PlayerLoseLife(&players[i]);
|
|
}
|
|
}
|
|
}
|
|
|
|
D_MapChange(gamemap, gametype, encoremode, false, 1, false, false);
|
|
}
|
|
}
|
|
|
|
// do player reborns if needed
|
|
if (G_GamestateUsesLevel() == true)
|
|
{
|
|
boolean changed = false;
|
|
|
|
for (i = 0; i < MAXPLAYERS; i++)
|
|
{
|
|
if (playeringame[i] && players[i].playerstate == PST_REBORN)
|
|
{
|
|
G_DoReborn(i);
|
|
changed = true;
|
|
}
|
|
}
|
|
|
|
if (changed == true)
|
|
{
|
|
K_UpdateAllPlayerPositions();
|
|
}
|
|
}
|
|
|
|
P_MapEnd();
|
|
|
|
// do things to change the game state
|
|
while (gameaction != ga_nothing)
|
|
switch (gameaction)
|
|
{
|
|
case ga_completed: G_DoCompleted(); break;
|
|
case ga_startcont: G_DoStartContinue(); break;
|
|
case ga_continued: G_DoContinued(); break;
|
|
case ga_worlddone: G_DoWorldDone(); break;
|
|
case ga_startvote: G_DoStartVote(); break;
|
|
case ga_nothing: break;
|
|
default: I_Error("gameaction = %d\n", gameaction);
|
|
}
|
|
|
|
buf = gametic % BACKUPTICS;
|
|
|
|
if (!demo.playback)
|
|
{
|
|
for (i = 0; i < MAXPLAYERS; i++)
|
|
{
|
|
cmd = &players[i].cmd;
|
|
|
|
if (playeringame[i])
|
|
{
|
|
G_CopyTiccmd(cmd, &netcmds[buf][i], 1);
|
|
|
|
// Use the leveltime sent in the player's ticcmd to determine control lag
|
|
if (K_PlayerUsesBotMovement(&players[i]))
|
|
{
|
|
// Never has lag
|
|
cmd->latency = 0;
|
|
}
|
|
else
|
|
{
|
|
//@TODO add a cvar to allow setting this max
|
|
cmd->latency = min(((leveltime & TICCMD_LATENCYMASK) - cmd->latency) & TICCMD_LATENCYMASK, MAXPREDICTTICS-1);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// do main actions
|
|
switch (gamestate)
|
|
{
|
|
case GS_LEVEL:
|
|
if (demo.title)
|
|
F_TitleDemoTicker();
|
|
P_Ticker(run); // tic the game
|
|
ST_Ticker(run);
|
|
F_TextPromptTicker();
|
|
AM_Ticker();
|
|
HU_Ticker();
|
|
|
|
break;
|
|
|
|
case GS_INTERMISSION:
|
|
if (run)
|
|
Y_Ticker();
|
|
HU_Ticker();
|
|
break;
|
|
|
|
case GS_VOTING:
|
|
if (run)
|
|
Y_VoteTicker();
|
|
HU_Ticker();
|
|
break;
|
|
|
|
case GS_TIMEATTACK:
|
|
F_MenuPresTicker(run);
|
|
break;
|
|
|
|
case GS_INTRO:
|
|
if (run)
|
|
F_IntroTicker();
|
|
break;
|
|
|
|
case GS_CUTSCENE:
|
|
if (run)
|
|
F_CutsceneTicker();
|
|
HU_Ticker();
|
|
break;
|
|
|
|
case GS_GAMEEND:
|
|
if (run)
|
|
F_GameEndTicker();
|
|
break;
|
|
|
|
case GS_EVALUATION:
|
|
if (run)
|
|
F_GameEvaluationTicker();
|
|
HU_Ticker();
|
|
break;
|
|
|
|
case GS_CONTINUING:
|
|
break;
|
|
|
|
case GS_CREDITS:
|
|
if (run)
|
|
F_CreditTicker();
|
|
HU_Ticker();
|
|
break;
|
|
|
|
case GS_BLANCREDITS:
|
|
if (run)
|
|
F_BlanCreditTicker();
|
|
HU_Ticker();
|
|
break;
|
|
|
|
case GS_TITLESCREEN:
|
|
if (titlemapinaction)
|
|
P_Ticker(run);
|
|
|
|
F_TitleScreenTicker(run);
|
|
break;
|
|
|
|
case GS_WAITINGPLAYERS:
|
|
if (netgame)
|
|
F_WaitingPlayersTicker();
|
|
HU_Ticker();
|
|
break;
|
|
|
|
case GS_DEDICATEDSERVER:
|
|
case GS_NULL:
|
|
break; // do nothing
|
|
}
|
|
|
|
if (run)
|
|
{
|
|
if (G_GametypeHasSpectators()
|
|
&& (gamestate == GS_LEVEL || gamestate == GS_INTERMISSION || gamestate == GS_VOTING // definitely good
|
|
|| gamestate == GS_WAITINGPLAYERS)) // definitely a problem if we don't do it at all in this gamestate, but might need more protection?
|
|
{
|
|
K_CheckSpectateStatus(true);
|
|
}
|
|
|
|
if (pausedelay && pausedelay != INT32_MIN)
|
|
{
|
|
if (pausedelay > 0)
|
|
pausedelay--;
|
|
else
|
|
pausedelay++;
|
|
}
|
|
|
|
for (i = 0; i < MAXSPLITSCREENPLAYERS; i++)
|
|
{
|
|
if (camtoggledelay[i])
|
|
camtoggledelay[i]--;
|
|
if (spectatedelay[i])
|
|
spectatedelay[i]--;
|
|
if (respawndelay[i])
|
|
respawndelay[i]--;
|
|
}
|
|
|
|
if (gametic % NAMECHANGERATE == 0)
|
|
{
|
|
memset(player_name_changes, 0, sizeof player_name_changes);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// PLAYER STRUCTURE FUNCTIONS
|
|
// also see P_SpawnPlayer in P_Things
|
|
//
|
|
|
|
//
|
|
// G_PlayerFinishLevel
|
|
// Called when a player completes a level.
|
|
//
|
|
static inline void G_PlayerFinishLevel(INT32 player)
|
|
{
|
|
player_t *p;
|
|
|
|
p = &players[player];
|
|
|
|
p->mo->renderflags &= ~(RF_TRANSMASK|RF_BRIGHTMASK); // cancel invisibility
|
|
P_FlashPal(p, 0, 0); // Resets
|
|
|
|
p->starpostnum = 0;
|
|
p->starposttime = 0;
|
|
p->prevcheck = 0;
|
|
p->nextcheck = 0;
|
|
|
|
// SRB2kart: Increment the "matches played" counter.
|
|
if (player == consoleplayer)
|
|
{
|
|
if (legitimateexit && !demo.playback && !mapreset) // (yes you're allowed to unlock stuff this way when the game is modified)
|
|
{
|
|
kartstats.matchesplayed++;
|
|
if (M_UpdateUnlockablesAndExtraEmblems())
|
|
S_StartSound(NULL, sfx_ncitem);
|
|
G_SaveGameData();
|
|
}
|
|
|
|
legitimateexit = false;
|
|
}
|
|
}
|
|
|
|
//
|
|
// G_PlayerReborn
|
|
// Called after a player dies. Almost everything is cleared and initialized.
|
|
//
|
|
void G_PlayerReborn(INT32 player, boolean betweenmaps)
|
|
{
|
|
player_t *p;
|
|
INT32 score, roundscore;
|
|
INT32 lives;
|
|
|
|
UINT8 kartspeed;
|
|
UINT8 kartweight;
|
|
|
|
boolean followerready;
|
|
INT32 followerskin;
|
|
UINT16 followercolor;
|
|
|
|
mobj_t *follower; // old follower, will probably be removed by the time we're dead but you never know.
|
|
|
|
INT32 charflags;
|
|
UINT32 followitem;
|
|
|
|
INT32 pflags;
|
|
|
|
UINT8 ctfteam;
|
|
|
|
fixed_t starpostx;
|
|
fixed_t starposty;
|
|
fixed_t starpostz;
|
|
angle_t starpostangle;
|
|
boolean starpostflip;
|
|
INT32 starpostnum;
|
|
tic_t starposttime; // The time of the last cheatcheck you hit
|
|
INT32 prevcheck; // Distance from Previous Legacy Checkpoint
|
|
INT32 nextcheck; // Distace to Next Legacy Checkpoint
|
|
|
|
INT32 exiting;
|
|
INT32 khudcardanimation;
|
|
INT16 totalring;
|
|
UINT8 laps;
|
|
UINT8 latestlap;
|
|
UINT16 skincolor;
|
|
INT32 skin;
|
|
UINT32 availabilities;
|
|
|
|
tic_t jointime;
|
|
|
|
UINT8 splitscreenindex;
|
|
boolean spectator;
|
|
boolean bot;
|
|
UINT8 botdifficulty;
|
|
|
|
INT16 rings;
|
|
angle_t playerangleturn;
|
|
|
|
UINT8 botdiffincrease;
|
|
boolean botrival;
|
|
|
|
SINT8 xtralife;
|
|
|
|
// SRB2kart
|
|
INT32 itemtype;
|
|
INT32 itemamount;
|
|
INT32 itemroulette;
|
|
INT32 previtemroulette;
|
|
INT32 roulettetype;
|
|
INT32 growshrinktimer;
|
|
INT32 bumper;
|
|
INT32 karmapoints;
|
|
INT32 wanted;
|
|
boolean songcredit = false;
|
|
tic_t spectatorreentry;
|
|
tic_t grieftime;
|
|
UINT8 griefstrikes;
|
|
UINT16 nocontrol;
|
|
INT32 kickstartaccel;
|
|
boolean enteredGame;
|
|
UINT8 lastsafelap;
|
|
UINT8 lastsafestarpost;
|
|
UINT16 bigwaypointgap;
|
|
|
|
score = players[player].score;
|
|
lives = players[player].lives;
|
|
ctfteam = players[player].ctfteam;
|
|
|
|
jointime = players[player].jointime;
|
|
|
|
splitscreenindex = players[player].splitscreenindex;
|
|
spectator = players[player].spectator;
|
|
|
|
playerangleturn = players[player].angleturn;
|
|
|
|
skincolor = players[player].skincolor;
|
|
skin = players[player].skin;
|
|
|
|
// SRB2kart
|
|
kartspeed = players[player].kartspeed;
|
|
kartweight = players[player].kartweight;
|
|
|
|
followerready = players[player].followerready;
|
|
followercolor = players[player].followercolor;
|
|
followerskin = players[player].followerskin;
|
|
|
|
availabilities = players[player].availabilities;
|
|
|
|
charflags = players[player].charflags;
|
|
|
|
followitem = players[player].followitem;
|
|
|
|
bot = players[player].bot;
|
|
botdifficulty = players[player].botvars.difficulty;
|
|
|
|
botdiffincrease = players[player].botvars.diffincrease;
|
|
botrival = players[player].botvars.rival;
|
|
|
|
totalring = players[player].totalring;
|
|
xtralife = players[player].xtralife;
|
|
|
|
pflags = (players[player].pflags & (PF_WANTSTOJOIN|PF_KICKSTARTACCEL|PF_SHRINKME|PF_SHRINKACTIVE|PF_FLIPCAM));
|
|
|
|
// SRB2kart
|
|
if (betweenmaps || leveltime <= starttime || spectator == true)
|
|
{
|
|
itemroulette = KROULETTE_DISABLED;
|
|
previtemroulette = KROULETTE_DISABLED;
|
|
roulettetype = KROULETTETYPE_NORMAL;
|
|
itemtype = 0;
|
|
itemamount = 0;
|
|
growshrinktimer = 0;
|
|
bumper = ((gametyperules & GTR_BUMPERS) ? K_StartingBumperCount() : 0);
|
|
karmapoints = 0;
|
|
wanted = 0;
|
|
rings = 5;
|
|
kickstartaccel = 0;
|
|
lastsafelap = 0;
|
|
lastsafestarpost = 0;
|
|
bigwaypointgap = 0;
|
|
nocontrol = 0;
|
|
laps = 0;
|
|
latestlap = 0;
|
|
roundscore = 0;
|
|
exiting = 0;
|
|
khudcardanimation = 0;
|
|
starpostx =0;
|
|
starposty = 0;
|
|
starpostz = 0;
|
|
starpostangle = 0;
|
|
starpostflip = 0;
|
|
starpostnum = 0;
|
|
starposttime = 0;
|
|
prevcheck = 0;
|
|
nextcheck = 0;
|
|
xtralife = 0;
|
|
|
|
}
|
|
else
|
|
{
|
|
itemroulette = (players[player].itemroulette > KROULETTE_DISABLED ? KROULETTE_ACTIVE : KROULETTE_DISABLED);
|
|
previtemroulette = (players[player].previtemroulette > KROULETTE_DISABLED ? KROULETTE_ACTIVE : KROULETTE_DISABLED);
|
|
roulettetype = players[player].roulettetype;
|
|
|
|
if (players[player].itemflags & IF_ITEMOUT)
|
|
{
|
|
itemtype = 0;
|
|
itemamount = 0;
|
|
}
|
|
else
|
|
{
|
|
itemtype = players[player].itemtype;
|
|
itemamount = players[player].itemamount;
|
|
}
|
|
|
|
// Keep Shrink status, remove Grow status
|
|
if (players[player].growshrinktimer < 0)
|
|
growshrinktimer = players[player].growshrinktimer;
|
|
else
|
|
growshrinktimer = 0;
|
|
|
|
bumper = players[player].bumper;
|
|
karmapoints = players[player].karmapoints;
|
|
wanted = players[player].wanted;
|
|
rings = players[player].rings;
|
|
kickstartaccel = players[player].kickstartaccel;
|
|
|
|
nocontrol = players[player].nocontrol;
|
|
|
|
laps = players[player].laps;
|
|
latestlap = players[player].latestlap;
|
|
|
|
roundscore = players[player].roundscore;
|
|
|
|
exiting = players[player].exiting;
|
|
khudcardanimation = (exiting > 0) ? players[player].karthud[khud_cardanimation] : 0;
|
|
|
|
starpostx = players[player].starpostx;
|
|
starposty = players[player].starposty;
|
|
starpostz = players[player].starpostz;
|
|
starpostangle = players[player].starpostangle;
|
|
starpostflip = players[player].starpostflip;
|
|
starpostnum = players[player].starpostnum;
|
|
starposttime = players[player].starposttime;
|
|
prevcheck = players[player].prevcheck;
|
|
prevcheck = players[player].nextcheck;
|
|
lastsafelap = players[player].lastsafelap;
|
|
lastsafestarpost = players[player].lastsafestarpost;
|
|
bigwaypointgap = players[player].bigwaypointgap;
|
|
}
|
|
|
|
if (!betweenmaps)
|
|
{
|
|
// Obliterate follower from existence (if valid memory)
|
|
follower = players[player].follower;
|
|
P_SetTarget(&players[player].follower, NULL);
|
|
P_SetTarget(&players[player].awayviewmobj, NULL);
|
|
P_SetTarget(&players[player].followmobj, NULL);
|
|
}
|
|
else
|
|
{
|
|
follower = NULL;
|
|
}
|
|
|
|
spectatorreentry = players[player].spectatorreentry;
|
|
|
|
grieftime = players[player].grieftime;
|
|
griefstrikes = players[player].griefstrikes;
|
|
|
|
enteredGame = players[player].enteredGame;
|
|
|
|
p = &players[player];
|
|
memset(p, 0, sizeof (*p));
|
|
|
|
p->score = score;
|
|
p->roundscore = roundscore;
|
|
p->lives = lives;
|
|
p->pflags = pflags;
|
|
p->ctfteam = ctfteam;
|
|
p->jointime = jointime;
|
|
p->splitscreenindex = splitscreenindex;
|
|
p->spectator = spectator;
|
|
p->angleturn = playerangleturn;
|
|
p->lastsafelap = lastsafelap;
|
|
p->lastsafestarpost = lastsafestarpost;
|
|
p->bigwaypointgap = bigwaypointgap;
|
|
|
|
// save player config truth reborn
|
|
p->skincolor = skincolor;
|
|
p->skin = skin;
|
|
p->kartspeed = kartspeed;
|
|
p->kartweight = kartweight;
|
|
//
|
|
p->charflags = charflags;
|
|
p->availabilities = availabilities;
|
|
p->followitem = followitem;
|
|
|
|
p->starpostx = starpostx;
|
|
p->starposty = starposty;
|
|
p->starpostz = starpostz;
|
|
p->starpostangle = starpostangle;
|
|
p->starpostflip = starpostflip;
|
|
p->starpostnum = starpostnum;
|
|
p->starposttime = starposttime;
|
|
p->prevcheck = prevcheck;
|
|
p->nextcheck = nextcheck;
|
|
|
|
p->exiting = exiting;
|
|
p->karthud[khud_cardanimation] = khudcardanimation;
|
|
|
|
p->laps = laps;
|
|
p->latestlap = latestlap;
|
|
p->totalring = totalring;
|
|
|
|
p->bot = bot;
|
|
p->botvars.difficulty = botdifficulty;
|
|
p->rings = rings;
|
|
p->botvars.diffincrease = botdiffincrease;
|
|
p->botvars.rival = botrival;
|
|
p->xtralife = xtralife;
|
|
|
|
// SRB2kart
|
|
p->itemroulette = itemroulette;
|
|
p->previtemroulette = previtemroulette;
|
|
p->roulettetype = roulettetype;
|
|
p->itemtype = itemtype;
|
|
p->itemamount = itemamount;
|
|
p->growshrinktimer = growshrinktimer;
|
|
p->bumper = bumper;
|
|
p->karmadelay = comebacktime;
|
|
p->karmapoints = karmapoints;
|
|
p->wanted = wanted;
|
|
p->eggmanblame = -1;
|
|
p->nocontrol = nocontrol;
|
|
p->kickstartaccel = kickstartaccel;
|
|
|
|
p->ringvolume = 255;
|
|
p->ringtransparency = 255;
|
|
|
|
p->spectatorreentry = spectatorreentry;
|
|
p->grieftime = grieftime;
|
|
p->griefstrikes = griefstrikes;
|
|
|
|
p->botvars.rubberband = FRACUNIT;
|
|
p->botvars.controller = UINT16_MAX;
|
|
p->botvars.driftskill =
|
|
FixedMul(MAXDRIFTSKILL, K_BotDetermineDriftSkill(p));
|
|
p->botvars.driftstate = DRIFTSTATE_AUTO;
|
|
|
|
if (follower)
|
|
P_RemoveMobj(follower);
|
|
|
|
p->followerready = followerready;
|
|
p->followerskin = followerskin;
|
|
p->followercolor = followercolor;
|
|
//p->follower = NULL; // respawn a new one with you, it looks better.
|
|
// ^ Not necessary anyway since it will be respawned regardless considering it doesn't exist anymore.
|
|
|
|
|
|
p->playerstate = PST_LIVE;
|
|
p->panim = PA_STILL; // standing animation
|
|
|
|
// Check to make sure their color didn't change somehow...
|
|
if (G_GametypeHasTeams())
|
|
{
|
|
UINT8 i;
|
|
|
|
if (p->ctfteam == 1 && p->skincolor != skincolor_redteam)
|
|
{
|
|
for (i = 0; i <= splitscreen; i++)
|
|
{
|
|
if (p == &players[g_localplayers[i]])
|
|
{
|
|
CV_SetValue(&cv_playercolor[i], skincolor_redteam);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else if (p->ctfteam == 2 && p->skincolor != skincolor_blueteam)
|
|
{
|
|
for (i = 0; i <= splitscreen; i++)
|
|
{
|
|
if (p == &players[g_localplayers[i]])
|
|
{
|
|
CV_SetValue(&cv_playercolor[i], skincolor_blueteam);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (p->spectator == false && !betweenmaps)
|
|
{
|
|
if (enteredGame == true)
|
|
{
|
|
ACS_RunPlayerEnterScript(p);
|
|
}
|
|
else
|
|
{
|
|
ACS_RunPlayerRespawnScript(p);
|
|
}
|
|
}
|
|
|
|
if (betweenmaps)
|
|
return;
|
|
|
|
if (leveltime < starttime)
|
|
return;
|
|
|
|
if (exiting)
|
|
return;
|
|
|
|
P_RestoreMusic(p);
|
|
|
|
if (songcredit)
|
|
S_ShowMusicCredit();
|
|
|
|
if (leveltime > (starttime + (TICRATE/2)) && !p->spectator)
|
|
p->respawn = 48; // Respawn effect
|
|
}
|
|
|
|
//
|
|
// G_CheckSpot
|
|
// Returns false if the player cannot be respawned
|
|
// at the given mapthing_t spot
|
|
// because something is occupying it
|
|
//
|
|
static boolean G_CheckSpot(INT32 playernum, mapthing_t *mthing)
|
|
{
|
|
fixed_t x;
|
|
fixed_t y;
|
|
INT32 i;
|
|
|
|
// maybe there is no player start
|
|
if (!mthing)
|
|
return false;
|
|
|
|
if (!players[playernum].mo)
|
|
{
|
|
// first spawn of level
|
|
for (i = 0; i < playernum; i++)
|
|
if (playeringame[i] && players[i].mo
|
|
&& players[i].mo->x == mthing->x << FRACBITS
|
|
&& players[i].mo->y == mthing->y << FRACBITS)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
x = mthing->x << FRACBITS;
|
|
y = mthing->y << FRACBITS;
|
|
|
|
if (!K_CheckPlayersRespawnColliding(playernum, x, y))
|
|
return false;
|
|
|
|
if (!P_CheckPosition(players[playernum].mo, x, y, NULL))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
//
|
|
// G_SpawnPlayer
|
|
// Spawn a player in a spot appropriate for the gametype --
|
|
// or a not-so-appropriate spot, if it initially fails
|
|
// due to a lack of starts open or something.
|
|
//
|
|
void G_SpawnPlayer(INT32 playernum, boolean starpost)
|
|
{
|
|
if (!playeringame[playernum])
|
|
return;
|
|
|
|
P_SpawnPlayer(playernum);
|
|
G_MovePlayerToSpawnOrStarpost(playernum, starpost);
|
|
LUA_HookPlayer(&players[playernum], HOOK(PlayerSpawn)); // Lua hook for player spawning :)
|
|
}
|
|
|
|
void G_MovePlayerToSpawnOrStarpost(INT32 playernum, boolean starpost)
|
|
{
|
|
if ((leveltime > starttime) && starpost)
|
|
P_MovePlayerToStarpost(playernum);
|
|
else
|
|
P_MovePlayerToSpawn(playernum, G_FindMapStart(playernum));
|
|
}
|
|
|
|
mapthing_t *G_FindTeamStart(INT32 playernum)
|
|
{
|
|
const boolean doprints = P_IsLocalPlayer(&players[playernum]);
|
|
INT32 i,j;
|
|
|
|
if (!numredctfstarts && !numbluectfstarts) //why even bother, eh?
|
|
{
|
|
if ((gametyperules & GTR_TEAMSTARTS) && doprints)
|
|
CONS_Alert(CONS_WARNING, M_GetText("No CTF starts in this map!\n"));
|
|
return NULL;
|
|
}
|
|
|
|
if ((!players[playernum].ctfteam && numredctfstarts && (!numbluectfstarts || P_RandomChance(FRACUNIT/2))) || players[playernum].ctfteam == 1) //red
|
|
{
|
|
if (!numredctfstarts)
|
|
{
|
|
if (doprints)
|
|
CONS_Alert(CONS_WARNING, M_GetText("No Red Team starts in this map!\n"));
|
|
return NULL;
|
|
}
|
|
|
|
for (j = 0; j < 32; j++)
|
|
{
|
|
i = P_RandomKey(numredctfstarts);
|
|
if (G_CheckSpot(playernum, redctfstarts[i]))
|
|
return redctfstarts[i];
|
|
}
|
|
|
|
if (doprints)
|
|
CONS_Alert(CONS_WARNING, M_GetText("Could not spawn at any Red Team starts!\n"));
|
|
return NULL;
|
|
}
|
|
else if (!players[playernum].ctfteam || players[playernum].ctfteam == 2) //blue
|
|
{
|
|
if (!numbluectfstarts)
|
|
{
|
|
if (doprints)
|
|
CONS_Alert(CONS_WARNING, M_GetText("No Blue Team starts in this map!\n"));
|
|
return NULL;
|
|
}
|
|
|
|
for (j = 0; j < 32; j++)
|
|
{
|
|
i = P_RandomKey(numbluectfstarts);
|
|
if (G_CheckSpot(playernum, bluectfstarts[i]))
|
|
return bluectfstarts[i];
|
|
}
|
|
if (doprints)
|
|
CONS_Alert(CONS_WARNING, M_GetText("Could not spawn at any Blue Team starts!\n"));
|
|
return NULL;
|
|
}
|
|
//should never be reached but it gets stuff to shut up
|
|
return NULL;
|
|
}
|
|
|
|
mapthing_t *G_FindBattleStart(INT32 playernum)
|
|
{
|
|
const boolean doprints = P_IsLocalPlayer(&players[playernum]);
|
|
INT32 i, j;
|
|
|
|
if (numdmstarts)
|
|
{
|
|
if (modeattacking == ATTACKING_ITEMBREAK)
|
|
{
|
|
if (G_CheckSpot(playernum, deathmatchstarts[0]))
|
|
return deathmatchstarts[0];
|
|
|
|
if (doprints)
|
|
CONS_Alert(CONS_WARNING, M_GetText("Could not spawn at any Deathmatch starts for Item Breaker!\n"));
|
|
|
|
return NULL;
|
|
}
|
|
else
|
|
{
|
|
|
|
for (j = 0; j < 64; j++)
|
|
{
|
|
i = P_RandomKey(numdmstarts);
|
|
if (G_CheckSpot(playernum, deathmatchstarts[i]))
|
|
return deathmatchstarts[i];
|
|
}
|
|
if (doprints)
|
|
CONS_Alert(CONS_WARNING, M_GetText("Could not spawn at any Deathmatch starts!\n"));
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
if ((gametyperules & GTR_BATTLESTARTS) && doprints)
|
|
CONS_Alert(CONS_WARNING, M_GetText("No Deathmatch starts in this map!\n"));
|
|
return NULL;
|
|
}
|
|
|
|
mapthing_t *G_FindRaceStart(INT32 playernum)
|
|
{
|
|
const boolean doprints = P_IsLocalPlayer(&players[playernum]);
|
|
|
|
if (numcoopstarts)
|
|
{
|
|
UINT8 i;
|
|
UINT8 pos = 0;
|
|
|
|
// SRB2Kart: figure out player spawn pos from points
|
|
if (!playeringame[playernum] || players[playernum].spectator)
|
|
return playerstarts[0]; // go to first spot if you're a spectator
|
|
|
|
for (i = 0; i < MAXPLAYERS; i++)
|
|
{
|
|
if (!playeringame[i] || players[i].spectator)
|
|
continue;
|
|
if (i == playernum)
|
|
continue;
|
|
|
|
if (players[i].score < players[playernum].score)
|
|
{
|
|
UINT8 j;
|
|
UINT8 num = 0;
|
|
|
|
for (j = 0; j < MAXPLAYERS; j++) // I hate similar loops inside loops... :<
|
|
{
|
|
if (!playeringame[j] || players[j].spectator)
|
|
continue;
|
|
if (j == playernum)
|
|
continue;
|
|
if (j == i)
|
|
continue;
|
|
|
|
if ((netgame || (demo.playback && demo.netgame)) && cv_kartusepwrlv.value)
|
|
{
|
|
if (clientpowerlevels[j][PWRLV_RACE] == clientpowerlevels[i][PWRLV_RACE])
|
|
num++;
|
|
}
|
|
else
|
|
{
|
|
if (players[j].score == players[i].score)
|
|
num++;
|
|
}
|
|
}
|
|
|
|
if (num > 1) // found dupes
|
|
pos++;
|
|
}
|
|
else
|
|
{
|
|
if (i < playernum)
|
|
pos++;
|
|
else
|
|
{
|
|
if ((netgame || (demo.playback && demo.netgame)) && cv_kartusepwrlv.value)
|
|
{
|
|
if (clientpowerlevels[i][PWRLV_RACE] > clientpowerlevels[playernum][PWRLV_RACE])
|
|
pos++;
|
|
}
|
|
else
|
|
{
|
|
if (players[i].score > players[playernum].score)
|
|
pos++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (G_CheckSpot(playernum, playerstarts[pos % numcoopstarts]))
|
|
return playerstarts[pos % numcoopstarts];
|
|
|
|
// Your spot isn't available? Find whatever you can get first.
|
|
for (i = 0; i < numcoopstarts; i++)
|
|
{
|
|
if (G_CheckSpot(playernum, playerstarts[i]))
|
|
return playerstarts[i];
|
|
}
|
|
|
|
// SRB2Kart: We have solid players, so this behavior is less ideal.
|
|
// Don't bother checking to see if the player 1 start is open.
|
|
// Just spawn there.
|
|
//return playerstarts[0];
|
|
|
|
if (doprints)
|
|
CONS_Alert(CONS_WARNING, M_GetText("Could not spawn at any Race starts!\n"));
|
|
return NULL;
|
|
}
|
|
|
|
if (modeattacking != ATTACKING_ITEMBREAK)
|
|
{
|
|
if (doprints)
|
|
CONS_Alert(CONS_WARNING, M_GetText("No Race starts in this map!\n"));
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
// Find a Co-op start, or fallback into other types of starts.
|
|
static inline mapthing_t *G_FindRaceStartOrFallback(INT32 playernum)
|
|
{
|
|
mapthing_t *spawnpoint = NULL;
|
|
if (!(spawnpoint = G_FindRaceStart(playernum)) // find a Race start
|
|
&& !(spawnpoint = G_FindBattleStart(playernum))) // find a DM start
|
|
spawnpoint = G_FindTeamStart(playernum); // fallback
|
|
return spawnpoint;
|
|
}
|
|
|
|
// Find a Match start, or fallback into other types of starts.
|
|
static inline mapthing_t *G_FindBattleStartOrFallback(INT32 playernum)
|
|
{
|
|
mapthing_t *spawnpoint = NULL;
|
|
if (!(spawnpoint = G_FindBattleStart(playernum)) // find a DM start
|
|
&& !(spawnpoint = G_FindTeamStart(playernum))) // find a CTF start
|
|
spawnpoint = G_FindRaceStart(playernum); // fallback
|
|
return spawnpoint;
|
|
}
|
|
|
|
static inline mapthing_t *G_FindTeamStartOrFallback(INT32 playernum)
|
|
{
|
|
mapthing_t *spawnpoint = NULL;
|
|
if (!(spawnpoint = G_FindTeamStart(playernum)) // find a CTF start
|
|
&& !(spawnpoint = G_FindBattleStart(playernum))) // find a DM start
|
|
spawnpoint = G_FindRaceStart(playernum); // fallback
|
|
return spawnpoint;
|
|
}
|
|
|
|
mapthing_t *G_FindMapStart(INT32 playernum)
|
|
{
|
|
mapthing_t *spawnpoint;
|
|
|
|
if (!playeringame[playernum])
|
|
return NULL;
|
|
|
|
// -- Spectators --
|
|
// Order in platform gametypes: Race->DM->CTF
|
|
// And, with deathmatch starts: DM->CTF->Race
|
|
if (players[playernum].spectator)
|
|
{
|
|
// In platform gametypes, spawn in Co-op starts first
|
|
// Overriden by GTR_BATTLESTARTS.
|
|
if (gametyperules & GTR_BATTLESTARTS && bossinfo.boss == false)
|
|
spawnpoint = G_FindBattleStartOrFallback(playernum);
|
|
else
|
|
spawnpoint = G_FindRaceStartOrFallback(playernum);
|
|
}
|
|
|
|
// -- Grand Prix / Time Attack --
|
|
// Order: Race->DM->CTF
|
|
else if (grandprixinfo.gp || modeattacking)
|
|
spawnpoint = G_FindRaceStartOrFallback(playernum);
|
|
|
|
// -- CTF --
|
|
// Order: CTF->DM->Race
|
|
else if ((gametyperules & GTR_TEAMSTARTS) && players[playernum].ctfteam)
|
|
spawnpoint = G_FindTeamStartOrFallback(playernum);
|
|
|
|
// -- DM/Tag/CTF-spectator/etc --
|
|
// Order: DM->CTF->Race
|
|
else if (gametyperules & GTR_BATTLESTARTS)
|
|
spawnpoint = G_FindBattleStartOrFallback(playernum);
|
|
|
|
// -- Other game modes --
|
|
// Order: Race->DM->CTF
|
|
else
|
|
spawnpoint = G_FindRaceStartOrFallback(playernum);
|
|
|
|
//No spawns found. ANYWHERE.
|
|
if (!spawnpoint)
|
|
{
|
|
if (nummapthings)
|
|
{
|
|
if (P_IsLocalPlayer(&players[playernum]))
|
|
CONS_Alert(CONS_ERROR, M_GetText("No player spawns found, spawning at the first mapthing!\n"));
|
|
spawnpoint = &mapthings[0];
|
|
}
|
|
else
|
|
{
|
|
if (P_IsLocalPlayer(&players[playernum]))
|
|
CONS_Alert(CONS_ERROR, M_GetText("No player spawns found, spawning at the origin!\n"));
|
|
}
|
|
}
|
|
|
|
return spawnpoint;
|
|
}
|
|
|
|
// Go back through all the projectiles and remove all references to the old
|
|
// player mobj, replacing them with the new one.
|
|
void G_ChangePlayerReferences(mobj_t *oldmo, mobj_t *newmo)
|
|
{
|
|
thinker_t *th;
|
|
mobj_t *mo2;
|
|
|
|
I_Assert((oldmo != NULL) && (newmo != NULL));
|
|
|
|
// scan all thinkers
|
|
for (th = thlist[THINK_MOBJ].next; th != &thlist[THINK_MOBJ]; th = th->next)
|
|
{
|
|
if (th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed)
|
|
continue;
|
|
|
|
mo2 = (mobj_t *)th;
|
|
|
|
if (!(mo2->flags & MF_MISSILE))
|
|
continue;
|
|
|
|
if (mo2->target == oldmo)
|
|
{
|
|
P_SetTarget(&mo2->target, newmo);
|
|
mo2->flags2 |= MF2_BEYONDTHEGRAVE; // this mobj belongs to a player who has reborn
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// G_DoReborn
|
|
//
|
|
void G_DoReborn(INT32 playernum)
|
|
{
|
|
player_t *player = &players[playernum];
|
|
boolean starpost = false;
|
|
|
|
// Make sure objectplace is OFF when you first start the level!
|
|
OP_ResetObjectplace();
|
|
|
|
{
|
|
// respawn at the start
|
|
mobj_t *oldmo = NULL;
|
|
|
|
if (player->spectator)
|
|
;
|
|
else if ((player->starpostnum || ((player->nextwaypoint != NULL) && player->starposttime))
|
|
|| ((mapheaderinfo[gamemap - 1]->levelflags & LF_SECTIONRACE) && player->laps)) // SRB2kart
|
|
starpost = true;
|
|
|
|
// first dissasociate the corpse
|
|
if (player->mo)
|
|
{
|
|
oldmo = player->mo;
|
|
// Don't leave your carcass stuck 10-billion feet in the ground!
|
|
P_RemoveMobj(player->mo);
|
|
P_SetTarget(&player->mo, NULL);
|
|
}
|
|
|
|
G_SpawnPlayer(playernum, starpost);
|
|
if (oldmo)
|
|
G_ChangePlayerReferences(oldmo, players[playernum].mo);
|
|
|
|
if (!demo.playback && playernum == consoleplayer)
|
|
kartstats.respawns++;
|
|
}
|
|
|
|
ACS_RunPlayerEnterScript(player);
|
|
}
|
|
|
|
void G_AddPlayer(INT32 playernum, INT32 console)
|
|
{
|
|
CL_ClearPlayer(playernum);
|
|
G_DestroyParty(playernum);
|
|
|
|
playeringame[playernum] = true;
|
|
|
|
playerconsole[playernum] = console;
|
|
G_BuildLocalSplitscreenParty(playernum);
|
|
|
|
player_t *newplayer = &players[playernum];
|
|
|
|
newplayer->playerstate = PST_REBORN;
|
|
newplayer->jointime = 0;
|
|
|
|
demo_extradata[playernum] |= DXD_ADDPLAYER; // Set everything
|
|
}
|
|
|
|
void G_BeginLevelExit(void)
|
|
{
|
|
g_exit.losing = true;
|
|
g_exit.retry = false;
|
|
|
|
if (!G_GametypeUsesLives() || skipstats != 0)
|
|
{
|
|
g_exit.losing = false; // never force a retry
|
|
}
|
|
else if (bossinfo.boss == true)
|
|
{
|
|
UINT8 i;
|
|
|
|
for (i = 0; i < MAXPLAYERS; i++)
|
|
{
|
|
if (playeringame[i] && !players[i].spectator && !players[i].bot)
|
|
{
|
|
if (!K_IsPlayerLosing(&players[i]))
|
|
{
|
|
g_exit.losing = false;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if (grandprixinfo.gp == true && grandprixinfo.eventmode == GPEVENT_NONE)
|
|
{
|
|
g_exit.losing = (grandprixinfo.wonround != true);
|
|
}
|
|
else if (grandprixinfo.gp == true && grandprixinfo.eventmode == GPEVENT_NONE)
|
|
{
|
|
g_exit.losing = (grandprixinfo.wonround != true);
|
|
}
|
|
|
|
if (g_exit.losing)
|
|
{
|
|
// You didn't win...
|
|
|
|
UINT8 i;
|
|
|
|
for (i = 0; i < MAXPLAYERS; i++)
|
|
{
|
|
if (playeringame[i] && !players[i].spectator && !players[i].bot)
|
|
{
|
|
if (players[i].lives > 0)
|
|
{
|
|
g_exit.retry = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
exitcountdown = raceexittime+1;
|
|
|
|
if (g_exit.losing)
|
|
{
|
|
if (!g_exit.retry)
|
|
{
|
|
ACS_RunGameOverScript();
|
|
}
|
|
}
|
|
}
|
|
|
|
void G_FinishExitLevel(void)
|
|
{
|
|
|
|
if (gamestate == GS_LEVEL)
|
|
{
|
|
if (g_exit.retry)
|
|
{
|
|
// Restart cup here whenever we do Online GP
|
|
if (!netgame)
|
|
{
|
|
// We have lives, just redo this one course.
|
|
G_SetRetryFlag();
|
|
return;
|
|
}
|
|
}
|
|
else if (g_exit.losing)
|
|
{
|
|
// We were in a Special Stage.
|
|
// We can still progress to the podium when we game over here.
|
|
const boolean special = grandprixinfo.gp == true && grandprixinfo.eventmode == GPEVENT_SPECIAL;
|
|
|
|
if (!netgame && !special)
|
|
{
|
|
// Back to the menu with you.
|
|
D_QuitNetGame();
|
|
CL_Reset();
|
|
M_StartControlPanel();
|
|
return;
|
|
}
|
|
}
|
|
|
|
gameaction = ga_completed;
|
|
lastdraw = true;
|
|
|
|
// If you want your teams scrambled on map change, start the process now.
|
|
// The teams will scramble at the start of the next round.
|
|
if (cv_scrambleonchange.value && G_GametypeHasTeams())
|
|
{
|
|
if (server)
|
|
CV_SetValue(&cv_teamscramble, cv_scrambleonchange.value);
|
|
}
|
|
|
|
CON_LogMessage(M_GetText("The round has ended.\n"));
|
|
|
|
// Remove CEcho text on round end.
|
|
HU_ClearCEcho();
|
|
|
|
// Don't save demos immediately here! Let standings write first
|
|
}
|
|
else if (gamestate == GS_CREDITS || gamestate == GS_BLANCREDITS)
|
|
{
|
|
F_StartGameEvaluation();
|
|
}
|
|
}
|
|
|
|
// See also the enum GameType in doomstat.h
|
|
const char *Gametype_Names[NUMGAMETYPES] =
|
|
{
|
|
"Race", // GT_RACE
|
|
"Battle" // GT_BATTLE
|
|
};
|
|
|
|
// For dehacked
|
|
const char *Gametype_ConstantNames[NUMGAMETYPES] =
|
|
{
|
|
"GT_RACE", // GT_RACE
|
|
"GT_BATTLE" // GT_BATTLE
|
|
};
|
|
|
|
// Gametype rules
|
|
UINT32 gametypedefaultrules[NUMGAMETYPES] =
|
|
{
|
|
// Race
|
|
GTR_CIRCUIT|GTR_BOTS|GTR_RINGS|GTR_ENCORE|GTR_RACEODDS,
|
|
// Battle
|
|
GTR_BUMPERS|GTR_RINGS|GTR_KARMA|GTR_WANTED|GTR_ITEMARROWS|GTR_ITEMBREAKER|GTR_BATTLESTARTS|GTR_TIMELIMIT|GTR_BATTLEODDS
|
|
};
|
|
|
|
//
|
|
// G_SetGametype
|
|
//
|
|
// Set a new gametype, also setting gametype rules accordingly. Yay!
|
|
//
|
|
void G_SetGametype(INT16 gtype)
|
|
{
|
|
gametype = gtype;
|
|
gametyperules = gametypedefaultrules[gametype];
|
|
}
|
|
|
|
//
|
|
// G_AddGametype
|
|
//
|
|
// Add a gametype. Returns the new gametype number.
|
|
//
|
|
INT16 G_AddGametype(UINT32 rules)
|
|
{
|
|
INT16 newgtype = gametypecount;
|
|
gametypecount++;
|
|
|
|
// Set gametype rules.
|
|
gametypedefaultrules[newgtype] = rules;
|
|
Gametype_Names[newgtype] = "???";
|
|
|
|
// Update gametype_cons_t accordingly.
|
|
G_UpdateGametypeSelections();
|
|
|
|
return newgtype;
|
|
}
|
|
|
|
//
|
|
// G_AddGametypeConstant
|
|
//
|
|
// Self-explanatory. Filters out "bad" characters.
|
|
//
|
|
void G_AddGametypeConstant(INT16 gtype, const char *newgtconst)
|
|
{
|
|
size_t r = 0; // read
|
|
size_t w = 0; // write
|
|
char *gtconst = Z_Calloc(strlen(newgtconst) + 4, PU_STATIC, NULL);
|
|
char *tmpconst = Z_Calloc(strlen(newgtconst) + 1, PU_STATIC, NULL);
|
|
|
|
// Copy the gametype name.
|
|
strcpy(tmpconst, newgtconst);
|
|
|
|
// Make uppercase.
|
|
strupr(tmpconst);
|
|
|
|
// Prepare to write the new constant string now.
|
|
strcpy(gtconst, "GT_");
|
|
|
|
// Remove characters that will not be allowed in the constant string.
|
|
for (; r < strlen(tmpconst); r++)
|
|
{
|
|
boolean writechar = true;
|
|
char rc = tmpconst[r];
|
|
switch (rc)
|
|
{
|
|
// Space, at sign and question mark
|
|
case ' ':
|
|
case '@':
|
|
case '?':
|
|
// Used for operations
|
|
case '+':
|
|
case '-':
|
|
case '*':
|
|
case '/':
|
|
case '%':
|
|
case '^':
|
|
case '&':
|
|
case '!':
|
|
// Part of Lua's syntax
|
|
case '#':
|
|
case '=':
|
|
case '~':
|
|
case '<':
|
|
case '>':
|
|
case '(':
|
|
case ')':
|
|
case '{':
|
|
case '}':
|
|
case '[':
|
|
case ']':
|
|
case ':':
|
|
case ';':
|
|
case ',':
|
|
case '.':
|
|
writechar = false;
|
|
break;
|
|
}
|
|
if (writechar)
|
|
{
|
|
gtconst[3 + w] = rc;
|
|
w++;
|
|
}
|
|
}
|
|
|
|
// Free the temporary string.
|
|
Z_Free(tmpconst);
|
|
|
|
// Finally, set the constant string.
|
|
Gametype_ConstantNames[gtype] = gtconst;
|
|
}
|
|
|
|
//
|
|
// G_UpdateGametypeSelections
|
|
//
|
|
// Updates gametype_cons_t.
|
|
//
|
|
void G_UpdateGametypeSelections(void)
|
|
{
|
|
INT32 i;
|
|
for (i = 0; i < gametypecount; i++)
|
|
{
|
|
gametype_cons_t[i].value = i;
|
|
gametype_cons_t[i].strvalue = Gametype_Names[i];
|
|
}
|
|
gametype_cons_t[NUMGAMETYPES].value = 0;
|
|
gametype_cons_t[NUMGAMETYPES].strvalue = NULL;
|
|
}
|
|
|
|
INT32 gametypecolor[NUMGAMETYPES] =
|
|
{
|
|
V_SKYMAP,
|
|
V_REDMAP,
|
|
};
|
|
|
|
// Gametype rankings
|
|
INT16 gametyperankings[NUMGAMETYPES] =
|
|
{
|
|
GT_RACE,
|
|
GT_BATTLE,
|
|
};
|
|
|
|
// Gametype to TOL (Type Of Level)
|
|
UINT32 gametypetol[NUMGAMETYPES] =
|
|
{
|
|
TOL_RACE, // Race
|
|
TOL_BATTLE, // Battle
|
|
TOL_TV, // Midnight Channel effect
|
|
};
|
|
|
|
tolinfo_t TYPEOFLEVEL[NUMTOLNAMES] = {
|
|
{"RACE",TOL_RACE},
|
|
{"BATTLE",TOL_BATTLE},
|
|
{"BOSS",TOL_BOSS},
|
|
{"TV",TOL_TV},
|
|
|
|
// Compat stuff
|
|
{"MATCH",TOL_BATTLE},
|
|
{"SOLO",TOL_COMPAT1},
|
|
{"SP",TOL_COMPAT1},
|
|
{"SINGLEPLAYER",TOL_COMPAT1},
|
|
{"SINGLE",TOL_COMPAT1},
|
|
{"COOP",TOL_COMPAT2},
|
|
{"CO-OP",TOL_COMPAT2},
|
|
{"COMPETITION",TOL_COMPAT3},
|
|
{"TAG",TOL_COMPAT4},
|
|
{"CTF",TOL_COMPAT5},
|
|
{"CUSTOM",TOL_COMPAT6},
|
|
|
|
{NULL, 0}
|
|
};
|
|
|
|
UINT32 lastcustomtol = (TOL_TV<<1);
|
|
|
|
//
|
|
// G_AddTOL
|
|
//
|
|
// Adds a type of level.
|
|
//
|
|
void G_AddTOL(UINT32 newtol, const char *tolname)
|
|
{
|
|
INT32 i;
|
|
for (i = 0; TYPEOFLEVEL[i].name; i++)
|
|
;
|
|
|
|
TYPEOFLEVEL[i].name = Z_StrDup(tolname);
|
|
TYPEOFLEVEL[i].flag = newtol;
|
|
}
|
|
|
|
//
|
|
// G_AddGametypeTOL
|
|
//
|
|
// Assigns a type of level to a gametype.
|
|
//
|
|
void G_AddGametypeTOL(INT16 gtype, UINT32 newtol)
|
|
{
|
|
gametypetol[gtype] = newtol;
|
|
}
|
|
|
|
//
|
|
// G_GetGametypeByName
|
|
//
|
|
// Returns the number for the given gametype name string, or -1 if not valid.
|
|
//
|
|
INT32 G_GetGametypeByName(const char *gametypestr)
|
|
{
|
|
INT32 i;
|
|
|
|
for (i = 0; i < gametypecount; i++)
|
|
if (!stricmp(gametypestr, Gametype_Names[i]))
|
|
return i;
|
|
|
|
return -1; // unknown gametype
|
|
}
|
|
|
|
//
|
|
// G_IsSpecialStage
|
|
//
|
|
// Returns TRUE if
|
|
// the given map is a special stage.
|
|
//
|
|
boolean G_IsSpecialStage(INT32 mapnum)
|
|
{
|
|
mapnum--; // gamemap-based to 0 indexed
|
|
|
|
if (mapnum > nummapheaders || !mapheaderinfo[mapnum])
|
|
return false;
|
|
|
|
if (!mapheaderinfo[mapnum]->cup || mapheaderinfo[mapnum]->cup->cachedlevels[CUPCACHE_SPECIAL] != mapnum)
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
//
|
|
// G_GametypeUsesLives
|
|
//
|
|
// Returns true if the current gametype uses
|
|
// the lives system. False otherwise.
|
|
//
|
|
boolean G_GametypeUsesLives(void)
|
|
{
|
|
if (modeattacking || metalrecording) // NOT in Record Attack
|
|
return false;
|
|
|
|
if ((grandprixinfo.gp == true) // In Grand Prix
|
|
&& (gametype == GT_RACE) // NOT in bonus round
|
|
&& grandprixinfo.eventmode == GPEVENT_NONE) // NOT in bonus
|
|
{
|
|
return true;
|
|
}
|
|
|
|
if (bossinfo.boss == true) // Fighting a boss?
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
//
|
|
// G_GametypeHasTeams
|
|
//
|
|
// Returns true if the current gametype uses
|
|
// Red/Blue teams. False otherwise.
|
|
//
|
|
boolean G_GametypeHasTeams(void)
|
|
{
|
|
if (gametyperules & GTR_TEAMS)
|
|
{
|
|
// Teams forced on by this gametype
|
|
return true;
|
|
}
|
|
else if (gametyperules & GTR_NOTEAMS)
|
|
{
|
|
// Teams forced off by this gametype
|
|
return false;
|
|
}
|
|
|
|
// Teams are determined by the "teamplay" modifier!
|
|
return false; // teamplay
|
|
}
|
|
|
|
//
|
|
// G_GametypeHasSpectators
|
|
//
|
|
// Returns true if the current gametype supports
|
|
// spectators. False otherwise.
|
|
//
|
|
boolean G_GametypeHasSpectators(void)
|
|
{
|
|
return (netgame || (multiplayer && demo.netgame));
|
|
}
|
|
|
|
//
|
|
// G_SometimesGetDifferentGametype
|
|
//
|
|
// Oh, yeah, and we sometimes flip encore mode on here too.
|
|
//
|
|
INT16 G_SometimesGetDifferentGametype(UINT8 prefgametype)
|
|
{
|
|
// Most of the gametype references in this condition are intentionally not prefgametype.
|
|
// This is so a server CAN continue playing a gametype if they like the taste of it.
|
|
// The encore check needs prefgametype so can't use G_RaceGametype...
|
|
boolean encorepossible = ((M_SecretUnlocked(SECRET_ENCORE) || encorescramble == 1)
|
|
&& ((gametyperules|gametypedefaultrules[prefgametype]) & GTR_CIRCUIT));
|
|
UINT8 encoremodifier = 0;
|
|
|
|
// -- the below is only necessary if you want to use randmaps.mapbuffer here
|
|
//if (randmaps.lastnummapheaders != nummapheaders)
|
|
//G_ResetRandMapBuffer();
|
|
|
|
if (encorepossible)
|
|
{
|
|
if (encorescramble != -1)
|
|
{
|
|
encorepossible = (boolean)encorescramble; // FORCE to what was scrambled on intermission
|
|
}
|
|
else
|
|
{
|
|
switch (cv_kartvoterulechanges.value)
|
|
{
|
|
case 3: // always
|
|
encorepossible = true;
|
|
break;
|
|
case 2: // frequent
|
|
encorepossible = M_RandomChance(FRACUNIT>>1);
|
|
break;
|
|
case 1: // sometimes
|
|
encorepossible = M_RandomChance(FRACUNIT>>2);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
if (encorepossible != (cv_kartencore.value == 1))
|
|
encoremodifier = VOTEMODIFIER_ENCORE;
|
|
}
|
|
|
|
if (!cv_kartvoterulechanges.value) // never
|
|
return (gametype|encoremodifier);
|
|
|
|
if (randmaps.counttogametype > 0 && (cv_kartvoterulechanges.value != 3))
|
|
{
|
|
randmaps.counttogametype--;
|
|
return (gametype|encoremodifier);
|
|
}
|
|
|
|
switch (cv_kartvoterulechanges.value) // okay, we're having a gametype change! when's the next one, luv?
|
|
{
|
|
case 1: // sometimes
|
|
randmaps.counttogametype = 5; // per "cup"
|
|
break;
|
|
default:
|
|
// fallthrough - happens when clearing buffer, but needs a reasonable countdown if cvar is modified
|
|
case 2: // frequent
|
|
randmaps.counttogametype = 2; // ...every 1/2th-ish cup?
|
|
break;
|
|
}
|
|
|
|
// Only this response is prefgametype-based.
|
|
// todo custom gametypes
|
|
if (prefgametype == GT_BATTLE)
|
|
{
|
|
// Intentionally does not use encoremodifier!
|
|
if (cv_kartencore.value == 1)
|
|
return (GT_RACE|VOTEMODIFIER_ENCORE);
|
|
return (GT_RACE);
|
|
}
|
|
// This might appear wrong HERE, but the game will display the Encore possibility on the second voting choice instead.
|
|
return (GT_BATTLE|encoremodifier);
|
|
}
|
|
|
|
//
|
|
// G_GetGametypeColor
|
|
//
|
|
// Pretty and consistent ^u^
|
|
// See also M_GetGametypeColor.
|
|
//
|
|
UINT8 G_GetGametypeColor(INT16 gt)
|
|
{
|
|
if (modeattacking // == ATTACKING_TIME
|
|
|| gamestate == GS_TIMEATTACK)
|
|
return orangemap[0];
|
|
|
|
if (gametypecolor[gt])
|
|
return *V_GetStringColormap(gametypecolor[gt]);
|
|
|
|
return yellowmap[0]; // FALLBACK
|
|
}
|
|
|
|
/** Get the typeoflevel flag needed to indicate support of a gametype.
|
|
* \param gametype The gametype for which support is desired.
|
|
* \return The typeoflevel flag to check for that gametype.
|
|
* \author Graue <graue@oceanbase.org>
|
|
*/
|
|
UINT32 G_TOLFlag(INT32 pgametype)
|
|
{
|
|
return gametypetol[pgametype];
|
|
}
|
|
|
|
INT16 G_GetFirstMapOfGametype(UINT8 pgametype)
|
|
{
|
|
INT16 mapnum = NEXTMAP_INVALID;
|
|
|
|
/* G: not sure what to do with this
|
|
if ((gametypedefaultrules[pgametype] & GTR_CAMPAIGN) && kartcupheaders)
|
|
{
|
|
mapnum = kartcupheaders->cachedlevels[0];
|
|
}
|
|
*/
|
|
|
|
if (mapnum >= nummapheaders)
|
|
{
|
|
UINT32 tolflag = G_TOLFlag(pgametype);
|
|
for (mapnum = 0; mapnum < nummapheaders; mapnum++)
|
|
{
|
|
if (!mapheaderinfo[mapnum])
|
|
continue;
|
|
if (mapheaderinfo[mapnum]->lumpnum == LUMPERROR)
|
|
continue;
|
|
if (!(mapheaderinfo[mapnum]->typeoflevel & tolflag))
|
|
continue;
|
|
if (mapheaderinfo[mapnum]->menuflags & LF2_HIDEINMENU)
|
|
continue;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return mapnum;
|
|
}
|
|
|
|
static INT32 TOLMaps(UINT8 pgametype)
|
|
{
|
|
INT32 num = 0;
|
|
INT32 i;
|
|
|
|
UINT32 tolflag = G_TOLFlag(pgametype);
|
|
|
|
// Find all the maps that are ok
|
|
for (i = 0; i < nummapheaders; i++)
|
|
{
|
|
if (!mapheaderinfo[i])
|
|
continue;
|
|
if (mapheaderinfo[i]->lumpnum == LUMPERROR)
|
|
continue;
|
|
if (!(mapheaderinfo[i]->typeoflevel & tolflag))
|
|
continue;
|
|
if (mapheaderinfo[i]->menuflags & LF2_HIDEINMENU) // Don't include Map Hell
|
|
continue;
|
|
num++;
|
|
}
|
|
|
|
return num;
|
|
}
|
|
|
|
/** Select a random map with the given typeoflevel flags.
|
|
* If no map has those flags, this arbitrarily gives you map 1.
|
|
* \param tolflags The typeoflevel flags to insist on. Other bits may
|
|
* be on too, but all of these must be on.
|
|
* \return A random map with those flags, 1-based, or 1 if no map
|
|
* has those flags.
|
|
* \author Graue <graue@oceanbase.org>
|
|
*/
|
|
static INT16 *okmaps = NULL;
|
|
INT16 G_RandMap(UINT32 tolflags, INT16 pprevmap, UINT8 ignorebuffer, UINT8 maphell, boolean callagainsoon, INT16 *extbuffer)
|
|
{
|
|
UINT32 numokmaps = 0;
|
|
INT16 ix, bufx;
|
|
UINT16 extbufsize = 0;
|
|
boolean usehellmaps; // Only consider Hell maps in this pick
|
|
|
|
if (randmaps.lastnummapheaders != nummapheaders)
|
|
G_ResetRandMapBuffer();
|
|
|
|
if (!okmaps)
|
|
{
|
|
//CONS_Printf("(making okmaps)\n");
|
|
okmaps = Z_Malloc(nummapheaders * sizeof(INT16), PU_STATIC, NULL);
|
|
}
|
|
|
|
if (extbuffer != NULL)
|
|
{
|
|
bufx = 0;
|
|
while (extbuffer[bufx])
|
|
{
|
|
extbufsize++; bufx++;
|
|
}
|
|
}
|
|
|
|
tryagain:
|
|
|
|
usehellmaps = (maphell == 0 ? false : (maphell == 2 || M_RandomChance(FRACUNIT/100))); // 1% chance of Hell
|
|
|
|
// Find all the maps that are ok and and put them in an array.
|
|
for (ix = 0; ix < nummapheaders; ix++)
|
|
{
|
|
boolean isokmap = true;
|
|
|
|
if (!mapheaderinfo[ix] || mapheaderinfo[ix]->lumpnum == LUMPERROR)
|
|
continue;
|
|
|
|
if ((mapheaderinfo[ix]->typeoflevel & tolflags) != tolflags
|
|
|| ix == pprevmap
|
|
|| (!dedicated && M_MapLocked(ix+1))
|
|
|| (usehellmaps != (mapheaderinfo[ix]->menuflags & LF2_HIDEINMENU))) // this is bad
|
|
continue; //isokmap = false;
|
|
|
|
if (pprevmap == -2) // title demo hack
|
|
{
|
|
// vres GHOST_%u
|
|
virtres_t *vRes;
|
|
virtlump_t *vLump;
|
|
lumpnum_t l;
|
|
|
|
vRes = vres_GetMap(mapheaderinfo[ix+1]->lumpnum);
|
|
|
|
for (int i = 0; i < 10; i++)
|
|
{
|
|
vLump = vres_Find(vRes, va("%s/GHOST_%u",mapheaderinfo[ix+1]->lumpname,i));
|
|
|
|
if (vLump != NULL)
|
|
break;
|
|
}
|
|
|
|
if (vLump == NULL && ((l = W_CheckNumForLongName(va("%sS01",mapheaderinfo[ix+1]->lumpname))) == LUMPERROR))
|
|
{
|
|
vres_Free(vRes);
|
|
continue;
|
|
}
|
|
|
|
vres_Free(vRes);
|
|
}
|
|
|
|
if (!ignorebuffer)
|
|
{
|
|
if (extbufsize > 0)
|
|
{
|
|
for (bufx = 0; bufx < extbufsize; bufx++)
|
|
{
|
|
if (extbuffer[bufx] == -1) // Rest of buffer SHOULD be empty
|
|
break;
|
|
if (ix == extbuffer[bufx])
|
|
{
|
|
isokmap = false;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!isokmap)
|
|
continue;
|
|
}
|
|
|
|
for (bufx = 0; bufx < (maphell ? 3 : randmaps.lastnummapheaders); bufx++)
|
|
{
|
|
if (randmaps.mapbuffer[bufx] == -1) // Rest of buffer SHOULD be empty
|
|
break;
|
|
if (ix == randmaps.mapbuffer[bufx])
|
|
{
|
|
isokmap = false;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!isokmap)
|
|
continue;
|
|
}
|
|
|
|
okmaps[numokmaps++] = ix;
|
|
}
|
|
|
|
if (numokmaps == 0) // If there's no matches... (Goodbye, incredibly silly function chains :V)
|
|
{
|
|
if (!ignorebuffer)
|
|
{
|
|
if (randmaps.mapbuffer[3] == -1) // Is the buffer basically empty?
|
|
{
|
|
ignorebuffer = 1; // This will probably only help in situations where there's very few maps, but it's folly not to at least try it
|
|
//CONS_Printf("RANDMAP - ignoring buffer\n");
|
|
goto tryagain;
|
|
}
|
|
|
|
for (bufx = 3; bufx < randmaps.lastnummapheaders; bufx++) // Let's clear all but the three most recent maps...
|
|
randmaps.mapbuffer[bufx] = -1;
|
|
//CONS_Printf("RANDMAP - emptying randmapbuffer\n");
|
|
goto tryagain;
|
|
}
|
|
|
|
if (maphell) // Any wiggle room to loosen our restrictions here?
|
|
{
|
|
//CONS_Printf("RANDMAP -maphell decrement\n");
|
|
maphell--;
|
|
goto tryagain;
|
|
}
|
|
|
|
//CONS_Printf("RANDMAP - defaulting to map01\n");
|
|
ix = 0; // Sorry, none match. You get MAP01.
|
|
if (ignorebuffer == 1)
|
|
{
|
|
//CONS_Printf("(emptying randmapbuffer entirely)\n");
|
|
for (bufx = 0; bufx < randmaps.lastnummapheaders; bufx++)
|
|
randmaps.mapbuffer[bufx] = -1; // if we're having trouble finding a map we should probably clear it
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//CONS_Printf("RANDMAP - %d maps available to grab\n", numokmaps);
|
|
ix = okmaps[M_RandomKey(numokmaps)];
|
|
}
|
|
|
|
if (!callagainsoon)
|
|
{
|
|
//CONS_Printf("(freeing okmaps)\n");
|
|
Z_Free(okmaps);
|
|
okmaps = NULL;
|
|
}
|
|
|
|
return ix;
|
|
}
|
|
|
|
void G_AddMapToBuffer(INT16 map)
|
|
{
|
|
INT16 bufx;
|
|
INT16 refreshnum = (TOLMaps(gametype))-3;
|
|
|
|
if (refreshnum < 0)
|
|
refreshnum = 3;
|
|
|
|
if (nummapheaders != randmaps.lastnummapheaders)
|
|
{
|
|
G_ResetRandMapBuffer();
|
|
}
|
|
else
|
|
{
|
|
for (bufx = randmaps.lastnummapheaders-1; bufx > 0; bufx--)
|
|
randmaps.mapbuffer[bufx] = randmaps.mapbuffer[bufx-1];
|
|
}
|
|
|
|
randmaps.mapbuffer[0] = map;
|
|
|
|
// We're getting pretty full, so lets flush this for future usage.
|
|
if (randmaps.mapbuffer[refreshnum] != -1)
|
|
{
|
|
// Clear all but the five most recent maps.
|
|
for (bufx = 5; bufx < randmaps.lastnummapheaders; bufx++)
|
|
randmaps.mapbuffer[bufx] = -1;
|
|
//CONS_Printf("Random map buffer has been flushed.\n");
|
|
}
|
|
}
|
|
|
|
//
|
|
// G_UpdateVisited
|
|
//
|
|
static void G_UpdateVisited(void)
|
|
{
|
|
UINT8 i;
|
|
//UINT8 earnedEmblems;
|
|
|
|
// No demos.
|
|
if (demo.playback)
|
|
return;
|
|
|
|
// Check if every local player wiped out.
|
|
for (i = 0; i < MAXPLAYERS; i++)
|
|
{
|
|
if (!playeringame[i]) // Not here.
|
|
continue;
|
|
|
|
if (!P_IsLocalPlayer(&players[i])) // Not local.
|
|
continue;
|
|
|
|
if (players[i].spectator) // Not playing.
|
|
continue;
|
|
|
|
if (players[i].pflags & PF_NOCONTEST) // Sonic after not surviving.
|
|
continue;
|
|
break;
|
|
}
|
|
|
|
if (i == MAXPLAYERS) // Not a single living local soul?
|
|
return;
|
|
|
|
// Update visitation flags
|
|
mapheaderinfo[gamemap-1]->mapvisited |= MV_BEATEN;
|
|
|
|
if (encoremode == true)
|
|
{
|
|
mapheaderinfo[gamemap-1]->mapvisited |= MV_ENCORE;
|
|
}
|
|
|
|
if (modeattacking)
|
|
G_UpdateRecordReplays();
|
|
|
|
// Unseal when we add more emblems
|
|
//if ((earnedEmblems = M_CompletionEmblems()))
|
|
//CONS_Printf(M_GetText("\x82" "Earned %hu emblem%s for level completion.\n"), (UINT16)earnedEmblems, earnedEmblems > 1 ? "s" : "");
|
|
}
|
|
|
|
static boolean CanSaveLevel(INT32 mapnum)
|
|
{
|
|
// SRB2Kart: No save files yet
|
|
(void)mapnum;
|
|
return false;
|
|
}
|
|
|
|
static void G_HandleSaveLevel(void)
|
|
{
|
|
// do this before running the intermission or custom cutscene, mostly for the sake of marathon mode but it also massively reduces redundant file save events in f_finale.c
|
|
if (nextmap >= NEXTMAP_SPECIAL)
|
|
{
|
|
if (!gamecomplete)
|
|
gamecomplete = 2; // special temporary mode to prevent using SP level select in pause menu until the intermission is over without restricting it in every intermission
|
|
if (cursaveslot > 0)
|
|
{
|
|
if (marathonmode)
|
|
{
|
|
// don't keep a backup around when the run is done!
|
|
if (FIL_FileExists(liveeventbackup))
|
|
remove(liveeventbackup);
|
|
cursaveslot = 0;
|
|
}
|
|
else if ((!modifiedgame || savemoddata) && !(netgame || multiplayer || ultimatemode || demo.recording || metalrecording || modeattacking))
|
|
G_SaveGame((UINT32)cursaveslot, 0); // TODO when we readd a campaign one day
|
|
}
|
|
}
|
|
// and doing THIS here means you don't lose your progress if you close the game mid-intermission
|
|
else if (!(ultimatemode || netgame || multiplayer || demo.playback || demo.recording || metalrecording || modeattacking)
|
|
&& (!modifiedgame || savemoddata) && cursaveslot > 0 && CanSaveLevel(lastmap+1))
|
|
G_SaveGame((UINT32)cursaveslot, lastmap+1); // not nextmap+1 to route around special stages
|
|
}
|
|
|
|
static INT16 G_GetNextMap(boolean advancemap)
|
|
{
|
|
INT32 i;
|
|
INT16 newmap, curmap = gamestate == GS_LEVEL ? gamemap-1 : prevmap;
|
|
|
|
// go to next level
|
|
// nextmap is 0-based, unlike gamemap
|
|
if (nextmapoverride != 0)
|
|
{
|
|
newmap = (INT16)(nextmapoverride-1);
|
|
}
|
|
else if (grandprixinfo.gp == true)
|
|
{
|
|
if (grandprixinfo.roundnum == 0 || grandprixinfo.cup == NULL) // Single session
|
|
{
|
|
newmap = curmap; // Same map
|
|
}
|
|
else
|
|
{
|
|
if (grandprixinfo.roundnum >= grandprixinfo.cup->numlevels) // On final map
|
|
{
|
|
newmap = NEXTMAP_CEREMONY; // ceremonymap
|
|
}
|
|
else
|
|
{
|
|
// Proceed to next map
|
|
const INT32 cupLevelNum =grandprixinfo.cup->cachedlevels[grandprixinfo.roundnum];
|
|
|
|
if (cupLevelNum < nummapheaders && mapheaderinfo[cupLevelNum])
|
|
{
|
|
newmap = cupLevelNum;
|
|
}
|
|
else
|
|
{
|
|
newmap = curmap; // Prevent uninitialised use
|
|
}
|
|
|
|
grandprixinfo.roundnum++;
|
|
}
|
|
}
|
|
}
|
|
else if (bossinfo.boss == true)
|
|
{
|
|
newmap = NEXTMAP_TITLE; // temporary
|
|
}
|
|
else
|
|
{
|
|
UINT32 tolflag = G_TOLFlag(gametype);
|
|
register INT16 cm;
|
|
|
|
if (grandprixinfo.gp == true)
|
|
{
|
|
cupheader_t *cup = mapheaderinfo[gamemap-1]->cup;
|
|
UINT8 gettingresult = 0;
|
|
|
|
while (cup)
|
|
{
|
|
// Not unlocked? Grab the next result afterwards
|
|
if (!marathonmode && cup->unlockrequired != -1 && !unlockables[cup->unlockrequired].unlocked)
|
|
{
|
|
cup = cup->next;
|
|
gettingresult = 1;
|
|
continue;
|
|
}
|
|
|
|
for (i = 0; i < cup->numlevels; i++)
|
|
{
|
|
cm = cup->cachedlevels[i];
|
|
|
|
// Not valid?
|
|
if (cm >= nummapheaders
|
|
|| !mapheaderinfo[cm]
|
|
|| mapheaderinfo[cm]->lumpnum == LUMPERROR
|
|
|| !(mapheaderinfo[cm]->typeoflevel & tolflag)
|
|
|| (!marathonmode && M_MapLocked(cm+1)))
|
|
continue;
|
|
|
|
// Grab the first valid after the map you're on
|
|
if (gettingresult)
|
|
{
|
|
newmap = cm;
|
|
gettingresult = 2;
|
|
break;
|
|
}
|
|
|
|
// Not the map you're on?
|
|
if (cm != curmap)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
// Ok, this is the current map, time to get the next
|
|
gettingresult = 1;
|
|
}
|
|
|
|
// We have a good nextmap?
|
|
if (gettingresult == 2)
|
|
{
|
|
break;
|
|
}
|
|
|
|
// Ok, iterate to the next
|
|
cup = cup->next;
|
|
}
|
|
|
|
// Didn't get a nextmap before reaching the end?
|
|
if (gettingresult != 2)
|
|
{
|
|
if (marathonmode)
|
|
{
|
|
newmap = NEXTMAP_CEREMONY; // ceremonymap
|
|
}
|
|
else
|
|
{
|
|
newmap = NEXTMAP_TITLE;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
cm = curmap;
|
|
if (++cm >= nummapheaders)
|
|
cm = 0;
|
|
|
|
while (cm != curmap)
|
|
{
|
|
if (!mapheaderinfo[cm]
|
|
|| mapheaderinfo[cm]->lumpnum == LUMPERROR
|
|
|| !(mapheaderinfo[cm]->typeoflevel & tolflag)
|
|
|| (mapheaderinfo[cm]->menuflags & LF2_HIDEINMENU)
|
|
|| M_MapLocked(cm+1))
|
|
{
|
|
if (++cm >= nummapheaders)
|
|
cm = 0;
|
|
continue;
|
|
}
|
|
|
|
break;
|
|
}
|
|
|
|
newmap = cm;
|
|
}
|
|
|
|
if (advancemap && !marathonmode)
|
|
{
|
|
if (cv_advancemap.value == 0) // Stay on same map.
|
|
{
|
|
newmap = curmap;
|
|
}
|
|
else if (cv_advancemap.value == 2) // Go to random map.
|
|
{
|
|
newmap = G_RandMap(G_TOLFlag(gametype), curmap, 0, 0, false, NULL);
|
|
}
|
|
else if (nextmap >= NEXTMAP_SPECIAL) // Loop back around
|
|
{
|
|
newmap = G_GetFirstMapOfGametype(gametype);
|
|
}
|
|
}
|
|
}
|
|
|
|
// We are committed to this map now.
|
|
if (newmap == NEXTMAP_INVALID || (newmap < NEXTMAP_SPECIAL && (newmap >= nummapheaders || !mapheaderinfo[newmap] || mapheaderinfo[newmap]->lumpnum == LUMPERROR)))
|
|
I_Error("G_GetNextMap: Internal map ID %d not found (nummapheaders = %d)\n", newmap, nummapheaders);
|
|
|
|
return newmap;
|
|
}
|
|
|
|
//
|
|
// G_DoCompleted
|
|
//
|
|
static void G_DoCompleted(void)
|
|
{
|
|
INT32 i, j = 0;
|
|
boolean spec = G_IsSpecialStage(gamemap);
|
|
SINT8 powertype = K_UsingPowerLevels();
|
|
|
|
if (modeattacking && pausedelay)
|
|
pausedelay = 0;
|
|
|
|
gameaction = ga_nothing;
|
|
|
|
if (metalplayback)
|
|
G_StopMetalDemo();
|
|
if (metalrecording)
|
|
G_StopMetalRecording(false);
|
|
|
|
K_StatRound();
|
|
|
|
G_SetGamestate(GS_NULL);
|
|
wipegamestate = GS_NULL;
|
|
|
|
K_StatRound();
|
|
|
|
for (i = 0; i < MAXPLAYERS; i++)
|
|
{
|
|
if (playeringame[i])
|
|
{
|
|
// SRB2Kart: exitlevel shouldn't get you the points
|
|
if (!players[i].exiting && !(players[i].pflags & PF_NOCONTEST))
|
|
{
|
|
clientPowerAdd[i] = 0;
|
|
|
|
if (players[i].bot)
|
|
{
|
|
K_FakeBotResults(&players[i]);
|
|
}
|
|
else
|
|
{
|
|
players[i].pflags |= PF_NOCONTEST;
|
|
|
|
if (P_IsLocalPlayer(&players[i]))
|
|
{
|
|
j++;
|
|
}
|
|
}
|
|
}
|
|
|
|
G_PlayerFinishLevel(i); // take away cards and stuff
|
|
}
|
|
}
|
|
|
|
// play some generic music if there's no win/cool/lose music going on (for exitlevel commands)
|
|
if ((gametyperules & GTR_CIRCUIT) && ((multiplayer && demo.playback) || j == r_splitscreen+1) && (cv_inttime.value > 0))
|
|
S_ChangeMusicInternal("racent", true);
|
|
|
|
if (automapactive)
|
|
AM_Stop();
|
|
|
|
S_StopSounds();
|
|
|
|
prevmap = (INT16)(gamemap-1);
|
|
|
|
if (!demo.playback)
|
|
{
|
|
nextmap = G_GetNextMap(true);
|
|
|
|
// Remember last map for when you come out of the special stage.
|
|
if (!spec)
|
|
lastmap = nextmap;
|
|
|
|
// Set up power level gametype scrambles
|
|
K_SetPowerLevelScrambles(powertype);
|
|
}
|
|
|
|
// If the current gametype has no intermission screen set, then don't start it.
|
|
Y_DetermineIntermissionType();
|
|
|
|
if ((skipstats && !modeattacking)
|
|
|| (modeattacking && (players[consoleplayer].pflags & PF_NOCONTEST))
|
|
|| (intertype == int_none))
|
|
{
|
|
G_UpdateVisited();
|
|
G_HandleSaveLevel();
|
|
G_AfterIntermission();
|
|
}
|
|
else
|
|
{
|
|
G_SetGamestate(GS_INTERMISSION);
|
|
Y_StartIntermission();
|
|
G_UpdateVisited();
|
|
G_HandleSaveLevel();
|
|
}
|
|
}
|
|
|
|
// See also F_EndCutscene, the only other place which handles intra-map/ending transitions
|
|
void G_AfterIntermission(void)
|
|
{
|
|
Y_CleanupScreenBuffer();
|
|
|
|
if (gamecomplete == 2) // special temporary mode to prevent using SP level select in pause menu until the intermission is over without restricting it in every intermission
|
|
gamecomplete = 1;
|
|
|
|
HU_ClearCEcho();
|
|
|
|
if (demo.playback)
|
|
{
|
|
G_StopDemo();
|
|
|
|
if (demo.inreplayhut)
|
|
M_ReplayHut(0);
|
|
else
|
|
D_StartTitle();
|
|
|
|
return;
|
|
}
|
|
else if (demo.recording && (modeattacking || demo.savemode != DSM_NOTSAVING))
|
|
G_SaveDemo();
|
|
|
|
if (modeattacking) // End the run.
|
|
{
|
|
M_ModeAttackEndGame(0);
|
|
return;
|
|
}
|
|
|
|
if (grandprixinfo.gp == true && mapheaderinfo[prevmap]->cutscenenum && !modeattacking && skipstats <= 1 && (gamecomplete || !(marathonmode & MA_NOCUTSCENES))) // Start a custom cutscene.
|
|
F_StartCustomCutscene(mapheaderinfo[prevmap]->cutscenenum-1, false, false);
|
|
else
|
|
{
|
|
if (nextmap < NEXTMAP_SPECIAL)
|
|
G_NextLevel();
|
|
else
|
|
G_EndGame();
|
|
}
|
|
}
|
|
|
|
//
|
|
// G_NextLevel (WorldDone)
|
|
//
|
|
// init next level or go to the final scene
|
|
// called by end of intermission screen (y_inter)
|
|
//
|
|
void G_NextLevel(void)
|
|
{
|
|
if (gamestate != GS_VOTING)
|
|
{
|
|
if ((cv_advancemap.value == 3) && grandprixinfo.gp == false && bossinfo.boss == false && !modeattacking && !skipstats && (multiplayer || netgame))
|
|
{
|
|
UINT8 i;
|
|
for (i = 0; i < MAXPLAYERS; i++)
|
|
{
|
|
if (playeringame[i] && !players[i].spectator)
|
|
{
|
|
gameaction = ga_startvote;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
forceresetplayers = false;
|
|
deferencoremode = (cv_kartencore.value == 1);
|
|
}
|
|
|
|
gameaction = ga_worlddone;
|
|
}
|
|
|
|
static void G_DoWorldDone(void)
|
|
{
|
|
if (server)
|
|
{
|
|
// SRB2Kart
|
|
D_MapChange(nextmap+1,
|
|
gametype,
|
|
deferencoremode,
|
|
forceresetplayers,
|
|
0,
|
|
false,
|
|
false);
|
|
}
|
|
|
|
gameaction = ga_nothing;
|
|
}
|
|
|
|
//
|
|
// G_DoStartVote
|
|
//
|
|
static void G_DoStartVote(void)
|
|
{
|
|
if (server)
|
|
D_SetupVote();
|
|
gameaction = ga_nothing;
|
|
}
|
|
|
|
//
|
|
// G_UseContinue
|
|
//
|
|
void G_UseContinue(void)
|
|
{
|
|
if (gamestate == GS_LEVEL && !netgame && !multiplayer)
|
|
{
|
|
gameaction = ga_startcont;
|
|
lastdraw = true;
|
|
}
|
|
}
|
|
|
|
static void G_DoStartContinue(void)
|
|
{
|
|
I_Assert(!netgame && !multiplayer);
|
|
|
|
legitimateexit = false;
|
|
G_PlayerFinishLevel(consoleplayer); // take away cards and stuff
|
|
|
|
//F_StartContinue();
|
|
gameaction = ga_nothing;
|
|
}
|
|
|
|
//
|
|
// G_Continue
|
|
//
|
|
// re-init level, used by continue and possibly countdowntimeup
|
|
//
|
|
void G_Continue(void)
|
|
{
|
|
if (!netgame && !multiplayer)
|
|
gameaction = ga_continued;
|
|
}
|
|
|
|
static void G_DoContinued(void)
|
|
{
|
|
player_t *pl = &players[consoleplayer];
|
|
I_Assert(!netgame && !multiplayer);
|
|
//I_Assert(pl->continues > 0);
|
|
|
|
/*if (pl->continues)
|
|
pl->continues--;*/
|
|
|
|
// Reset score
|
|
pl->score = 0;
|
|
|
|
// Allow tokens to come back
|
|
tokenlist = 0;
|
|
token = 0;
|
|
|
|
if (!(netgame || multiplayer || demo.playback || demo.recording || metalrecording || modeattacking) && (!modifiedgame || savemoddata) && cursaveslot > 0)
|
|
G_SaveGameOver((UINT32)cursaveslot, true);
|
|
|
|
// Reset # of lives
|
|
pl->lives = 3;
|
|
|
|
D_MapChange(gamemap, gametype, false, false, 0, false, false);
|
|
|
|
gameaction = ga_nothing;
|
|
}
|
|
|
|
//
|
|
// G_EndGame (formerly Y_EndGame)
|
|
// Frankly this function fits better in g_game.c than it does in y_inter.c
|
|
//
|
|
// ...Gee, (why) end the game?
|
|
// Because G_AfterIntermission and F_EndCutscene would
|
|
// both do this exact same thing *in different ways* otherwise,
|
|
// which made it so that you could only unlock Ultimate mode
|
|
// if you had a cutscene after the final level and crap like that.
|
|
// This function simplifies it so only one place has to be updated
|
|
// when something new is added.
|
|
void G_EndGame(void)
|
|
{
|
|
if (demo.recording && (modeattacking || demo.savemode != DSM_NOTSAVING))
|
|
G_SaveDemo();
|
|
|
|
// Only do evaluation and credits in singleplayer contexts
|
|
if (!netgame && grandprixinfo.gp == true)
|
|
{
|
|
if (nextmap == NEXTMAP_CEREMONY) // end game with ceremony
|
|
{
|
|
D_StartTitle(); //F_StartEnding(); -- temporary
|
|
return;
|
|
}
|
|
if (nextmap == NEXTMAP_CREDITS) // end game with credits
|
|
{
|
|
F_StartCredits();
|
|
return;
|
|
}
|
|
if (nextmap == NEXTMAP_EVALUATION) // end game with evaluation
|
|
{
|
|
F_StartGameEvaluation();
|
|
return;
|
|
}
|
|
}
|
|
|
|
// direct or competitive multiplayer, so go back to title screen.
|
|
D_StartTitle();
|
|
}
|
|
|
|
//
|
|
// G_LoadGameSettings
|
|
//
|
|
// Sets a tad of default info we need.
|
|
void G_LoadGameSettings(void)
|
|
{
|
|
// initialize free sfx slots for skin sounds
|
|
S_InitRuntimeSounds();
|
|
}
|
|
|
|
#define GD_VERSIONCHECK 0xBA5ED444
|
|
|
|
// G_LoadGameData
|
|
// Loads the main data file, which stores information such as emblems found, etc.
|
|
void G_LoadGameData(void)
|
|
{
|
|
UINT32 i, j;
|
|
UINT8 modded = false;
|
|
UINT8 rtemp;
|
|
savebuffer_t save = {0};
|
|
|
|
//For records
|
|
UINT32 numgamedatamapheaders;
|
|
|
|
// Clear things so previously read gamedata doesn't transfer
|
|
// to new gamedata
|
|
G_ClearRecords(); // main and nights records
|
|
M_ClearSecrets(); // emblems, unlocks, maps visited, etc
|
|
K_EraseStats(); // stats
|
|
|
|
for (i = 0; i < PWRLV_NUMTYPES; i++) // SRB2Kart: online rank system
|
|
vspowerlevel[i] = PWRLVRECORD_START;
|
|
|
|
if (M_CheckParm("-nodata"))
|
|
return; // Don't load.
|
|
|
|
// Allow saving of gamedata beyond this point
|
|
gamedataloaded = true;
|
|
|
|
if (M_CheckParm("-gamedata") && M_IsNextParm())
|
|
{
|
|
strlcpy(gamedatafilename, M_GetNextParm(), sizeof gamedatafilename);
|
|
}
|
|
|
|
if (M_CheckParm("-resetdata"))
|
|
return; // Don't load (essentially, reset).
|
|
|
|
if (P_SaveBufferFromFile(&save, va(pandf, srb2home, gamedatafilename)) == false)
|
|
return;
|
|
|
|
// Version check
|
|
if (READUINT32(save.p) != GD_VERSIONCHECK)
|
|
{
|
|
const char *gdfolder = "the SRB2Kart folder";
|
|
if (strcmp(srb2home,"."))
|
|
gdfolder = srb2home;
|
|
|
|
P_SaveBufferFree(&save);
|
|
I_Error("Game data is not for SRB2Kart v2.\nDelete %s(maybe in %s) and try again.", gamedatafilename, gdfolder);
|
|
}
|
|
|
|
// well no clue but dont think it would like reading garbage from vanilla files
|
|
K_ReadStats(&save, !savemoddata);
|
|
|
|
for (i = 0; i < PWRLV_NUMTYPES; i++)
|
|
{
|
|
vspowerlevel[i] = READUINT16(save.p);
|
|
if (vspowerlevel[i] < PWRLVRECORD_MIN || vspowerlevel[i] > PWRLVRECORD_MAX)
|
|
goto datacorrupt;
|
|
}
|
|
|
|
modded = READUINT8(save.p);
|
|
|
|
// Aha! Someone's been screwing with the save file!
|
|
if ((modded && !savemoddata))
|
|
goto datacorrupt;
|
|
else if (modded != true && modded != false)
|
|
goto datacorrupt;
|
|
|
|
// To save space, use one bit per collected/achieved/unlocked flag
|
|
for (i = 0; i < MAXEMBLEMS;)
|
|
{
|
|
rtemp = READUINT8(save.p);
|
|
for (j = 0; j < 8 && j+i < MAXEMBLEMS; ++j)
|
|
emblemlocations[j+i].collected = ((rtemp >> j) & 1);
|
|
i += j;
|
|
}
|
|
for (i = 0; i < MAXEXTRAEMBLEMS;)
|
|
{
|
|
rtemp = READUINT8(save.p);
|
|
for (j = 0; j < 8 && j+i < MAXEXTRAEMBLEMS; ++j)
|
|
extraemblems[j+i].collected = ((rtemp >> j) & 1);
|
|
i += j;
|
|
}
|
|
for (i = 0; i < MAXUNLOCKABLES;)
|
|
{
|
|
rtemp = READUINT8(save.p);
|
|
for (j = 0; j < 8 && j+i < MAXUNLOCKABLES; ++j)
|
|
unlockables[j+i].unlocked = ((rtemp >> j) & 1);
|
|
i += j;
|
|
}
|
|
for (i = 0; i < MAXCONDITIONSETS;)
|
|
{
|
|
rtemp = READUINT8(save.p);
|
|
for (j = 0; j < 8 && j+i < MAXCONDITIONSETS; ++j)
|
|
conditionSets[j+i].achieved = ((rtemp >> j) & 1);
|
|
i += j;
|
|
}
|
|
|
|
timesBeaten = READUINT32(save.p);
|
|
|
|
// Main records
|
|
numgamedatamapheaders = READUINT32(save.p);
|
|
if (numgamedatamapheaders >= NEXTMAP_SPECIAL)
|
|
goto datacorrupt;
|
|
|
|
for (i = 0; i < numgamedatamapheaders; i++)
|
|
{
|
|
char mapname[MAXMAPLUMPNAME];
|
|
INT16 mapnum;
|
|
tic_t rectime;
|
|
tic_t reclap;
|
|
|
|
READSTRINGN(save.p, mapname, sizeof(mapname));
|
|
mapnum = G_MapNumber(mapname);
|
|
|
|
rtemp = READUINT8(save.p);
|
|
|
|
for (SINT8 k = 0; k < MAXMAPRECORDS; k++)
|
|
{
|
|
rectime = (tic_t)READUINT32(save.p);
|
|
reclap = (tic_t)READUINT32(save.p);
|
|
|
|
if (mapnum < nummapheaders && mapheaderinfo[mapnum])
|
|
{
|
|
// Valid mapheader, time to populate with record data.
|
|
|
|
if ((mapheaderinfo[mapnum]->mapvisited = rtemp) & ~MV_MAX)
|
|
goto datacorrupt;
|
|
|
|
if (rectime || reclap)
|
|
{
|
|
G_AllocMainRecordData((INT16)i, k);
|
|
mapheaderinfo[i]->mainrecord[k]->time = rectime;
|
|
mapheaderinfo[i]->mainrecord[k]->lap = reclap;
|
|
CONS_Printf("Map Record %d, ID %d, Time = %d, Lap = %d\n", k, i, rectime/35, reclap/35);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// Since it's not worth declaring the entire gamedata
|
|
// corrupt over extra maps, we report and move on.
|
|
//CONS_Alert(CONS_WARNING, "Map with lumpname %s does not exist, time record data will be discarded\n", mapname);
|
|
}
|
|
}
|
|
}
|
|
|
|
// done
|
|
P_SaveBufferFree(&save);
|
|
|
|
// Silent update unlockables in case they're out of sync with conditions
|
|
M_SilentUpdateUnlockablesAndEmblems();
|
|
|
|
return;
|
|
|
|
// Landing point for corrupt gamedata
|
|
datacorrupt:
|
|
{
|
|
const char *gdfolder = "the SRB2Kart folder";
|
|
if (strcmp(srb2home,"."))
|
|
gdfolder = srb2home;
|
|
|
|
P_SaveBufferFree(&save);
|
|
|
|
I_Error("Corrupt game data file.\nDelete %s(maybe in %s) and try again.", gamedatafilename, gdfolder);
|
|
}
|
|
}
|
|
|
|
// G_SaveGameData
|
|
// Saves the main data file, which stores information such as emblems found, etc.
|
|
void G_SaveGameData(void)
|
|
{
|
|
size_t length;
|
|
INT32 i, j;
|
|
UINT8 btemp;
|
|
savebuffer_t save = {0};
|
|
char backupfile[MAX_WADPATH+4];
|
|
|
|
if (!gamedataloaded)
|
|
return; // If never loaded (-nodata), don't save
|
|
|
|
length = 4+4+4+(PWRLV_NUMTYPES*2)+1
|
|
+ BIT_ARRAY_SIZE(MAXEMBLEMS)
|
|
+ BIT_ARRAY_SIZE(MAXEXTRAEMBLEMS)
|
|
+ BIT_ARRAY_SIZE(MAXUNLOCKABLES)
|
|
+ BIT_ARRAY_SIZE(MAXCONDITIONSETS)
|
|
+ 4+4+(nummapheaders*(MAXMAPLUMPNAME+1+4+4));
|
|
|
|
if (P_SaveBufferAlloc(&save, length) == false)
|
|
{
|
|
CONS_Alert(CONS_ERROR, M_GetText("No more free memory for saving game data\n"));
|
|
return;
|
|
}
|
|
|
|
// Create backup of the save data
|
|
snprintf(backupfile, sizeof(backupfile), "%s.bak", gamedatafilename);
|
|
backupfile[sizeof(backupfile) - 1] = '\0';
|
|
|
|
FILE *gamedata = fopen(gamedatafilename, "r");
|
|
|
|
if (gamedata != NULL)
|
|
{
|
|
fclose(gamedata);
|
|
|
|
if (!FIL_CopyFile(gamedatafilename, backupfile))
|
|
{
|
|
CONS_Alert(CONS_WARNING,"Failed to create a backup of save data. Will not attempt to write to save data\n");
|
|
return;
|
|
}
|
|
}
|
|
|
|
// Version test
|
|
WRITEUINT32(save.p, GD_VERSIONCHECK); // 4
|
|
|
|
K_WriteStats(&save, !savemoddata);
|
|
|
|
for (i = 0; i < PWRLV_NUMTYPES; i++)
|
|
WRITEUINT16(save.p, vspowerlevel[i]);
|
|
|
|
WRITEUINT8(save.p, (UINT8)savemoddata); // 1
|
|
|
|
// To save space, use one bit per collected/achieved/unlocked flag
|
|
for (i = 0; i < MAXEMBLEMS;) // BIT_ARRAY_SIZE(MAXEMBLEMS)
|
|
{
|
|
btemp = 0;
|
|
for (j = 0; j < 8 && j+i < MAXEMBLEMS; ++j)
|
|
btemp |= (emblemlocations[j+i].collected << j);
|
|
WRITEUINT8(save.p, btemp);
|
|
i += j;
|
|
}
|
|
for (i = 0; i < MAXEXTRAEMBLEMS;) // BIT_ARRAY_SIZE(MAXEXTRAEMBLEMS)
|
|
{
|
|
btemp = 0;
|
|
for (j = 0; j < 8 && j+i < MAXEXTRAEMBLEMS; ++j)
|
|
btemp |= (extraemblems[j+i].collected << j);
|
|
WRITEUINT8(save.p, btemp);
|
|
i += j;
|
|
}
|
|
for (i = 0; i < MAXUNLOCKABLES;) // BIT_ARRAY_SIZE(MAXUNLOCKABLES)
|
|
{
|
|
btemp = 0;
|
|
for (j = 0; j < 8 && j+i < MAXUNLOCKABLES; ++j)
|
|
btemp |= (unlockables[j+i].unlocked << j);
|
|
WRITEUINT8(save.p, btemp);
|
|
i += j;
|
|
}
|
|
for (i = 0; i < MAXCONDITIONSETS;) // BIT_ARRAY_SIZE(MAXCONDITIONSETS)
|
|
{
|
|
btemp = 0;
|
|
for (j = 0; j < 8 && j+i < MAXCONDITIONSETS; ++j)
|
|
btemp |= (conditionSets[j+i].achieved << j);
|
|
WRITEUINT8(save.p, btemp);
|
|
i += j;
|
|
}
|
|
|
|
WRITEUINT32(save.p, timesBeaten); // 4
|
|
|
|
// Main records
|
|
WRITEUINT32(save.p, nummapheaders); // 4
|
|
|
|
for (i = 0; i < nummapheaders; i++) // nummapheaders * (MAXMAPLUMPNAME+1+4+4)
|
|
{
|
|
// For figuring out which header to assing it to on load
|
|
WRITESTRINGN(save.p, mapheaderinfo[i]->lumpname, MAXMAPLUMPNAME);
|
|
|
|
WRITEUINT8(save.p, (mapheaderinfo[i]->mapvisited & MV_MAX));
|
|
|
|
for (SINT8 k = 0; k < MAXMAPRECORDS; k++)
|
|
{
|
|
if (mapheaderinfo[i]->mainrecord[k])
|
|
{
|
|
WRITEUINT32(save.p, mapheaderinfo[i]->mainrecord[k]->time);
|
|
WRITEUINT32(save.p, mapheaderinfo[i]->mainrecord[k]->lap);
|
|
}
|
|
else
|
|
{
|
|
WRITEUINT32(save.p, 0);
|
|
WRITEUINT32(save.p, 0);
|
|
}
|
|
}
|
|
}
|
|
|
|
length = save.p - save.buffer;
|
|
|
|
FIL_WriteFile(va(pandf, srb2home, gamedatafilename), save.buffer, length);
|
|
P_SaveBufferFree(&save);
|
|
}
|
|
|
|
#define VERSIONSIZE 16
|
|
|
|
//
|
|
// G_InitFromSavegame
|
|
// Can be called by the startup code or the menu task.
|
|
//
|
|
void G_LoadGame(UINT32 slot, INT16 mapoverride)
|
|
{
|
|
char vcheck[VERSIONSIZE];
|
|
char savename[255];
|
|
savebuffer_t save = {0};
|
|
|
|
// memset savedata to all 0, fixes calling perfectly valid saves corrupt because of bots
|
|
memset(&savedata, 0, sizeof(savedata));
|
|
|
|
#ifdef SAVEGAME_OTHERVERSIONS
|
|
//Oh christ. The force load response needs access to mapoverride too...
|
|
startonmapnum = mapoverride;
|
|
#endif
|
|
|
|
if (marathonmode)
|
|
strcpy(savename, liveeventbackup);
|
|
else
|
|
sprintf(savename, savegamename, slot);
|
|
|
|
if (P_SaveBufferFromFile(&save, savename) == false)
|
|
{
|
|
CONS_Printf(M_GetText("Couldn't read file %s\n"), savename);
|
|
return;
|
|
}
|
|
|
|
memset(vcheck, 0, sizeof (vcheck));
|
|
sprintf(vcheck, (marathonmode ? "back-up %d" : "version %d"), VERSION);
|
|
if (strcmp((const char *)save.p, (const char *)vcheck))
|
|
{
|
|
#ifdef SAVEGAME_OTHERVERSIONS
|
|
M_StartMessage(M_GetText("Save game from different version.\nYou can load this savegame, but\nsaving afterwards will be disabled.\n\nDo you want to continue anyway?\n\n(Press 'Y' to confirm)\n"),
|
|
M_ForceLoadGameResponse, MM_YESNO);
|
|
//Freeing done by the callback function of the above message
|
|
#else
|
|
M_ClearMenus(true); // so ESC backs out to title
|
|
M_StartMessage(M_GetText("Save game from different version\n\nPress ESC\n"), NULL, MM_NOTHING);
|
|
Command_ExitGame_f();
|
|
P_SaveBufferFree(&save);
|
|
|
|
// no cheating!
|
|
memset(&savedata, 0, sizeof(savedata));
|
|
#endif
|
|
return; // bad version
|
|
}
|
|
save.p += VERSIONSIZE;
|
|
|
|
if (demo.playback) // reset game engine
|
|
G_StopDemo();
|
|
|
|
// paused = false;
|
|
// automapactive = false;
|
|
|
|
// dearchive all the modifications
|
|
if (!P_LoadGame(&save, mapoverride))
|
|
{
|
|
M_ClearMenus(true); // so ESC backs out to title
|
|
M_StartMessage(M_GetText("Savegame file corrupted\n\nPress ESC\n"), NULL, MM_NOTHING);
|
|
Command_ExitGame_f();
|
|
Z_Free(save.buffer);
|
|
save.p = save.buffer = NULL;
|
|
|
|
// no cheating!
|
|
memset(&savedata, 0, sizeof(savedata));
|
|
return;
|
|
}
|
|
if (marathonmode)
|
|
{
|
|
marathontime = READUINT32(save.p);
|
|
marathonmode |= READUINT8(save.p);
|
|
}
|
|
|
|
// done
|
|
P_SaveBufferFree(&save);
|
|
|
|
// gameaction = ga_nothing;
|
|
// G_SetGamestate(GS_LEVEL);
|
|
displayplayers[0] = consoleplayer;
|
|
multiplayer = false;
|
|
splitscreen = 0;
|
|
SplitScreen_OnChange(); // not needed?
|
|
|
|
// G_DeferedInitNew(sk_medium, G_BuildMapName(1), 0, 0, 1);
|
|
if (setsizeneeded)
|
|
R_ExecuteSetViewSize();
|
|
|
|
M_ClearMenus(true);
|
|
CON_ToggleOff();
|
|
}
|
|
|
|
//
|
|
// G_SaveGame
|
|
// Saves your game.
|
|
//
|
|
void G_SaveGame(UINT32 slot, INT16 mapnum)
|
|
{
|
|
boolean saved;
|
|
char savename[256] = "";
|
|
const char *backup;
|
|
savebuffer_t save = {0};
|
|
|
|
if (marathonmode)
|
|
strcpy(savename, liveeventbackup);
|
|
else
|
|
sprintf(savename, savegamename, slot);
|
|
backup = va("%s",savename);
|
|
|
|
gameaction = ga_nothing;
|
|
{
|
|
char name[VERSIONSIZE];
|
|
size_t length;
|
|
|
|
if (P_SaveBufferAlloc(&save, SAVEGAMESIZE) == false)
|
|
{
|
|
CONS_Alert(CONS_ERROR, M_GetText("No more free memory for saving game data\n"));
|
|
return;
|
|
}
|
|
|
|
memset(name, 0, sizeof (name));
|
|
sprintf(name, (marathonmode ? "back-up %d" : "version %d"), VERSION);
|
|
WRITEMEM(save.p, name, VERSIONSIZE);
|
|
|
|
P_SaveGame(&save, mapnum);
|
|
if (marathonmode)
|
|
{
|
|
UINT32 writetime = marathontime;
|
|
if (!(marathonmode & MA_INGAME))
|
|
writetime += TICRATE*5; // live event backup penalty because we don't know how long it takes to get to the next map
|
|
WRITEUINT32(save.p, writetime);
|
|
WRITEUINT8(save.p, (marathonmode & ~MA_INIT));
|
|
}
|
|
|
|
length = save.p - save.buffer;
|
|
saved = FIL_WriteFile(backup, save.buffer, length);
|
|
P_SaveBufferFree(&save);
|
|
}
|
|
|
|
gameaction = ga_nothing;
|
|
|
|
if (cht_debug && saved)
|
|
CONS_Printf(M_GetText("Game saved.\n"));
|
|
else if (!saved)
|
|
CONS_Alert(CONS_ERROR, M_GetText("Error while writing to %s for save slot %u, base: %s\n"), backup, slot, (marathonmode ? liveeventbackup : savegamename));
|
|
}
|
|
|
|
#define BADSAVE goto cleanup;
|
|
#define CHECKPOS if (save.p >= save.end) BADSAVE
|
|
void G_SaveGameOver(UINT32 slot, boolean modifylives)
|
|
{
|
|
boolean saved = false;
|
|
size_t length;
|
|
char vcheck[VERSIONSIZE];
|
|
char savename[255];
|
|
const char *backup;
|
|
savebuffer_t save = {0};
|
|
|
|
if (marathonmode)
|
|
strcpy(savename, liveeventbackup);
|
|
else
|
|
sprintf(savename, savegamename, slot);
|
|
backup = va("%s",savename);
|
|
|
|
if (P_SaveBufferFromFile(&save, savename) == false)
|
|
{
|
|
CONS_Printf(M_GetText("Couldn't read file %s\n"), savename);
|
|
return;
|
|
}
|
|
|
|
length = save.size;
|
|
|
|
{
|
|
char temp[sizeof(timeattackfolder)];
|
|
UINT8 *lives_p;
|
|
SINT8 pllives;
|
|
|
|
// Version check
|
|
memset(vcheck, 0, sizeof (vcheck));
|
|
sprintf(vcheck, (marathonmode ? "back-up %d" : "version %d"), VERSION);
|
|
if (strcmp((const char *)save.p, (const char *)vcheck)) BADSAVE
|
|
save.p += VERSIONSIZE;
|
|
|
|
// P_UnArchiveMisc()
|
|
(void)READINT16(save.p);
|
|
CHECKPOS
|
|
(void)READUINT16(save.p); // emeralds
|
|
CHECKPOS
|
|
READSTRINGN(save.p, temp, sizeof(temp)); // mod it belongs to
|
|
if (strcmp(temp, timeattackfolder)) BADSAVE
|
|
|
|
// P_UnArchivePlayer()
|
|
CHECKPOS
|
|
(void)READUINT16(save.p);
|
|
CHECKPOS
|
|
|
|
WRITEUINT8(save.p, numgameovers);
|
|
CHECKPOS
|
|
|
|
lives_p = save.p;
|
|
pllives = READSINT8(save.p); // lives
|
|
CHECKPOS
|
|
if (modifylives && pllives < startinglivesbalance[numgameovers])
|
|
{
|
|
pllives = startinglivesbalance[numgameovers];
|
|
WRITESINT8(lives_p, pllives);
|
|
}
|
|
|
|
(void)READINT32(save.p); // Score
|
|
CHECKPOS
|
|
(void)READINT32(save.p); // continues
|
|
|
|
// File end marker check
|
|
CHECKPOS
|
|
switch (READUINT8(save.p))
|
|
{
|
|
case 0xb7:
|
|
{
|
|
UINT8 i, banksinuse;
|
|
CHECKPOS
|
|
banksinuse = READUINT8(save.p);
|
|
CHECKPOS
|
|
if (banksinuse > NUM_LUABANKS)
|
|
BADSAVE
|
|
for (i = 0; i < banksinuse; i++)
|
|
{
|
|
(void)READINT32(save.p);
|
|
CHECKPOS
|
|
}
|
|
if (READUINT8(save.p) != 0x1d)
|
|
BADSAVE
|
|
}
|
|
case 0x1d:
|
|
break;
|
|
default:
|
|
BADSAVE
|
|
}
|
|
|
|
// done
|
|
saved = FIL_WriteFile(backup, save.buffer, length);
|
|
}
|
|
|
|
cleanup:
|
|
if (cht_debug && saved)
|
|
CONS_Printf(M_GetText("Game saved.\n"));
|
|
else if (!saved)
|
|
CONS_Alert(CONS_ERROR, M_GetText("Error while writing to %s for save slot %u, base: %s\n"), backup, slot, (marathonmode ? liveeventbackup : savegamename));
|
|
|
|
P_SaveBufferFree(&save);
|
|
}
|
|
#undef CHECKPOS
|
|
#undef BADSAVE
|
|
|
|
//
|
|
// G_DeferedInitNew
|
|
// Can be called by the startup code or the menu task,
|
|
// consoleplayer, displayplayers[], playeringame[] should be set.
|
|
//
|
|
void G_DeferedInitNew(boolean pencoremode, INT32 map, INT32 pickedchar, UINT8 ssplayers, boolean FLS)
|
|
{
|
|
UINT16 color = SKINCOLOR_NONE;
|
|
|
|
paused = false;
|
|
|
|
if (demo.playback)
|
|
COM_BufAddText("stopdemo\n");
|
|
|
|
G_FreeGhosts(); // TODO: do we actually need to do this?
|
|
|
|
G_ResetRandMapBuffer();
|
|
|
|
// this leave the actual game if needed
|
|
SV_StartSinglePlayerServer();
|
|
|
|
if (splitscreen != ssplayers)
|
|
{
|
|
splitscreen = ssplayers;
|
|
SplitScreen_OnChange();
|
|
}
|
|
|
|
SetPlayerSkinByNum(consoleplayer, pickedchar);
|
|
CV_StealthSet(&cv_skin[0], skins[pickedchar].name);
|
|
|
|
if (color != SKINCOLOR_NONE)
|
|
{
|
|
CV_StealthSetValue(&cv_playercolor[0], color);
|
|
}
|
|
|
|
D_MapChange(map, gametype, pencoremode, true, 1, false, FLS);
|
|
}
|
|
|
|
//
|
|
// This is the map command interpretation something like Command_Map_f
|
|
//
|
|
// called at: map cmd execution, doloadgame, doplaydemo
|
|
void G_InitNew(UINT8 pencoremode, INT32 map, boolean resetplayer, boolean skipprecutscene, boolean FLS)
|
|
{
|
|
const char * mapname = G_BuildMapName(map);
|
|
|
|
INT32 i;
|
|
|
|
(void)FLS;
|
|
|
|
Y_CleanupScreenBuffer();
|
|
|
|
if (paused)
|
|
{
|
|
paused = false;
|
|
S_ResumeAudio();
|
|
}
|
|
|
|
prevencoremode = ((!Playing()) ? false : encoremode);
|
|
encoremode = pencoremode;
|
|
|
|
legitimateexit = false; // SRB2Kart
|
|
comebackshowninfo = false;
|
|
|
|
if (!demo.playback && !netgame) // Netgame sets random seed elsewhere, demo playback sets seed just before us!
|
|
P_SetRandSeed(M_RandomizedSeed()); // Use a more "Random" random seed
|
|
|
|
// Clear a bunch of variables
|
|
redscore = bluescore = lastmap = 0;
|
|
racecountdown = exitcountdown = mapreset = exitfadestarted = 0;
|
|
|
|
for (i = 0; i < MAXPLAYERS; i++)
|
|
{
|
|
players[i].playerstate = PST_REBORN;
|
|
|
|
players[i].roundscore = 0;
|
|
|
|
if (resetplayer && !(multiplayer && demo.playback)) // SRB2Kart
|
|
{
|
|
players[i].lives = 3;
|
|
players[i].xtralife = 0;
|
|
players[i].totalring = 0;
|
|
players[i].score = 0;
|
|
}
|
|
}
|
|
|
|
// Reset unlockable triggers
|
|
unlocktriggers = 0;
|
|
|
|
// clear itemfinder, just in case
|
|
if (!dedicated) // except in dedicated servers, where it is not registered and can actually I_Error debug builds
|
|
CV_StealthSetValue(&cv_itemfinder, 0);
|
|
|
|
// internal game map
|
|
// well this check is useless because it is done before (d_netcmd.c::command_map_f)
|
|
// but in case of for demos....
|
|
if (!mapname)
|
|
{
|
|
I_Error("Internal game map with ID %d not found\n", map);
|
|
Command_ExitGame_f();
|
|
return;
|
|
}
|
|
if (mapheaderinfo[map-1]->lumpnum == LUMPERROR)
|
|
{
|
|
I_Error("Internal game map '%s' not found\n", mapname);
|
|
Command_ExitGame_f();
|
|
return;
|
|
}
|
|
|
|
gamemap = map;
|
|
|
|
maptol = mapheaderinfo[gamemap-1]->typeoflevel;
|
|
globalweather = mapheaderinfo[gamemap-1]->weather;
|
|
|
|
// Don't carry over custom music change to another map.
|
|
mapmusflags |= MUSIC_RELOADRESET;
|
|
|
|
automapactive = false;
|
|
imcontinuing = false;
|
|
|
|
if (!skipprecutscene && mapheaderinfo[gamemap-1]->precutscenenum && !modeattacking && !(marathonmode & MA_NOCUTSCENES)) // Start a custom cutscene.
|
|
F_StartCustomCutscene(mapheaderinfo[gamemap-1]->precutscenenum-1, true, resetplayer);
|
|
else
|
|
{
|
|
LUA_HookGamemap(HOOK(MapChange));
|
|
G_DoLoadLevel(resetplayer);
|
|
}
|
|
|
|
if (netgame)
|
|
{
|
|
char *title = G_BuildMapTitle(gamemap);
|
|
|
|
CON_LogMessage(va(M_GetText("Map is now \"%s"), mapname));
|
|
if (title)
|
|
{
|
|
CON_LogMessage(va(": %s", title));
|
|
Z_Free(title);
|
|
}
|
|
CON_LogMessage("\"\n");
|
|
}
|
|
}
|
|
|
|
|
|
char *G_BuildMapTitle(INT32 mapnum)
|
|
{
|
|
char *title = NULL;
|
|
|
|
if (!mapnum || mapnum > nummapheaders || !mapheaderinfo[mapnum-1])
|
|
I_Error("G_BuildMapTitle: Internal map ID %d not found (nummapheaders = %d)", mapnum-1, nummapheaders);
|
|
|
|
if (strcmp(mapheaderinfo[mapnum-1]->lvlttl, ""))
|
|
{
|
|
size_t len = 1;
|
|
const char *zonetext = NULL;
|
|
const char *actnum = NULL;
|
|
|
|
len += strlen(mapheaderinfo[mapnum-1]->lvlttl);
|
|
if (strlen(mapheaderinfo[mapnum-1]->zonttl) > 0)
|
|
{
|
|
zonetext = M_GetText(mapheaderinfo[mapnum-1]->zonttl);
|
|
len += strlen(zonetext) + 1; // ' ' + zonetext
|
|
}
|
|
else if (!(mapheaderinfo[mapnum-1]->levelflags & LF_NOZONE))
|
|
{
|
|
zonetext = M_GetText("Zone");
|
|
len += strlen(zonetext) + 1; // ' ' + zonetext
|
|
}
|
|
|
|
if (actnum)
|
|
len += 1 + 11; // ' ' + INT32
|
|
|
|
title = Z_Malloc(len, PU_STATIC, NULL);
|
|
|
|
sprintf(title, "%s", mapheaderinfo[mapnum-1]->lvlttl);
|
|
if (zonetext) sprintf(title + strlen(title), " %s", zonetext);
|
|
if (actnum) sprintf(title + strlen(title), " %s", actnum);
|
|
}
|
|
|
|
return title;
|
|
}
|
|
|
|
static void measurekeywords(mapsearchfreq_t *fr,
|
|
struct searchdim **dimp, UINT8 *cuntp,
|
|
const char *s, const char *q, boolean wanttable)
|
|
{
|
|
char *qp;
|
|
char *sp;
|
|
if (wanttable)
|
|
(*dimp) = Z_Realloc((*dimp), 255 * sizeof (struct searchdim),
|
|
PU_STATIC, NULL);
|
|
for (qp = strtok(va("%s", q), " ");
|
|
qp && fr->total < 255;
|
|
qp = strtok(0, " "))
|
|
{
|
|
if (( sp = strcasestr(s, qp) ))
|
|
{
|
|
if (wanttable)
|
|
{
|
|
(*dimp)[(*cuntp)].pos = sp - s;
|
|
(*dimp)[(*cuntp)].siz = strlen(qp);
|
|
}
|
|
(*cuntp)++;
|
|
fr->total++;
|
|
}
|
|
}
|
|
if (wanttable)
|
|
(*dimp) = Z_Realloc((*dimp), (*cuntp) * sizeof (struct searchdim),
|
|
PU_STATIC, NULL);
|
|
}
|
|
|
|
static void writesimplefreq(mapsearchfreq_t *fr, INT32 *frc,
|
|
INT32 mapnum, UINT8 pos, UINT8 siz)
|
|
{
|
|
fr[(*frc)].mapnum = mapnum;
|
|
fr[(*frc)].matchd = ZZ_Alloc(sizeof (struct searchdim));
|
|
fr[(*frc)].matchd[0].pos = pos;
|
|
fr[(*frc)].matchd[0].siz = siz;
|
|
fr[(*frc)].matchc = 1;
|
|
fr[(*frc)].total = 1;
|
|
(*frc)++;
|
|
}
|
|
|
|
INT32 G_FindMap(const char *mapname, char **foundmapnamep,
|
|
mapsearchfreq_t **freqp, INT32 *freqcp)
|
|
{
|
|
INT32 newmapnum = 0;
|
|
INT32 mapnum;
|
|
INT32 apromapnum = 0;
|
|
|
|
size_t mapnamelen;
|
|
char *realmapname = NULL;
|
|
char *newmapname = NULL;
|
|
char *apromapname = NULL;
|
|
char *aprop = NULL;
|
|
|
|
mapsearchfreq_t *freq;
|
|
boolean wanttable;
|
|
INT32 freqc;
|
|
UINT8 frequ;
|
|
|
|
INT32 i;
|
|
|
|
mapnamelen = strlen(mapname);
|
|
|
|
freq = ZZ_Calloc(nummapheaders * sizeof (mapsearchfreq_t));
|
|
|
|
wanttable = !!( freqp );
|
|
|
|
freqc = 0;
|
|
|
|
for (i = 0, mapnum = 1; i < nummapheaders; ++i, ++mapnum)
|
|
{
|
|
if (!mapheaderinfo[i] || mapheaderinfo[i]->lumpnum == LUMPERROR)
|
|
continue;
|
|
|
|
if (!( realmapname = G_BuildMapTitle(mapnum) ))
|
|
continue;
|
|
|
|
aprop = realmapname;
|
|
|
|
/* Now that we found a perfect match no need to fucking guess. */
|
|
if (strnicmp(realmapname, mapname, mapnamelen) == 0)
|
|
{
|
|
if (wanttable)
|
|
{
|
|
writesimplefreq(freq, &freqc, mapnum, 0, mapnamelen);
|
|
}
|
|
if (newmapnum == 0)
|
|
{
|
|
newmapnum = mapnum;
|
|
newmapname = realmapname;
|
|
realmapname = 0;
|
|
Z_Free(apromapname);
|
|
if (!wanttable)
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
if (apromapnum == 0 || wanttable)
|
|
{
|
|
/* LEVEL 1--match keywords verbatim */
|
|
if (( aprop = strcasestr(realmapname, mapname) ))
|
|
{
|
|
if (wanttable)
|
|
{
|
|
writesimplefreq(freq, &freqc,
|
|
mapnum, aprop - realmapname, mapnamelen);
|
|
}
|
|
if (apromapnum == 0)
|
|
{
|
|
apromapnum = mapnum;
|
|
apromapname = realmapname;
|
|
realmapname = 0;
|
|
}
|
|
}
|
|
else/* ...match individual keywords */
|
|
{
|
|
freq[freqc].mapnum = mapnum;
|
|
measurekeywords(&freq[freqc],
|
|
&freq[freqc].matchd, &freq[freqc].matchc,
|
|
realmapname, mapname, wanttable);
|
|
measurekeywords(&freq[freqc],
|
|
&freq[freqc].keywhd, &freq[freqc].keywhc,
|
|
mapheaderinfo[i]->keywords, mapname, wanttable);
|
|
if (freq[freqc].total)
|
|
freqc++;
|
|
}
|
|
}
|
|
|
|
Z_Free(realmapname);/* leftover old name */
|
|
}
|
|
|
|
if (newmapnum == 0)/* no perfect match--try a substring */
|
|
{
|
|
newmapnum = apromapnum;
|
|
newmapname = apromapname;
|
|
}
|
|
|
|
if (newmapnum == 0)/* calculate most queries met! */
|
|
{
|
|
frequ = 0;
|
|
for (i = 0; i < freqc; ++i)
|
|
{
|
|
if (freq[i].total > frequ)
|
|
{
|
|
frequ = freq[i].total;
|
|
newmapnum = freq[i].mapnum;
|
|
}
|
|
}
|
|
if (newmapnum)
|
|
{
|
|
newmapname = G_BuildMapTitle(newmapnum);
|
|
}
|
|
}
|
|
|
|
if (freqp)
|
|
(*freqp) = freq;
|
|
else
|
|
Z_Free(freq);
|
|
|
|
if (freqcp)
|
|
(*freqcp) = freqc;
|
|
|
|
if (foundmapnamep)
|
|
(*foundmapnamep) = newmapname;
|
|
else
|
|
Z_Free(newmapname);
|
|
|
|
return newmapnum;
|
|
}
|
|
|
|
void G_FreeMapSearch(mapsearchfreq_t *freq, INT32 freqc)
|
|
{
|
|
INT32 i;
|
|
for (i = 0; i < freqc; ++i)
|
|
{
|
|
Z_Free(freq[i].matchd);
|
|
}
|
|
Z_Free(freq);
|
|
}
|
|
|
|
INT32 G_FindMapByNameOrCode(const char *mapname, char **realmapnamep)
|
|
{
|
|
INT32 newmapnum;
|
|
|
|
size_t mapnamelen;
|
|
|
|
char *p;
|
|
|
|
mapnamelen = strlen(mapname);
|
|
|
|
if (mapnamelen == 1)
|
|
{
|
|
if (mapname[0] == '*') // current map
|
|
return gamemap;
|
|
else if (mapname[0] == '+') // next map
|
|
return G_GetNextMap(false)+1;
|
|
}
|
|
|
|
/* Now detect map number in base 10, which no one asked for. */
|
|
newmapnum = strtol(mapname, &p, 10);
|
|
|
|
if (*p == '\0')/* we got it */
|
|
{
|
|
if (newmapnum < 1 || newmapnum > nummapheaders)
|
|
return 0;
|
|
|
|
if (!mapheaderinfo[newmapnum-1] || mapheaderinfo[newmapnum-1]->lumpnum == LUMPERROR)
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
newmapnum = G_MapNumber(mapname)+1;
|
|
|
|
if (newmapnum > nummapheaders)
|
|
return G_FindMap(mapname, realmapnamep, NULL, NULL);
|
|
}
|
|
|
|
if (realmapnamep)
|
|
(*realmapnamep) = G_BuildMapTitle(newmapnum);
|
|
|
|
return newmapnum;
|
|
}
|
|
|
|
//
|
|
// G_SetGamestate
|
|
//
|
|
// Use this to set the gamestate, please.
|
|
//
|
|
void G_SetGamestate(gamestate_t newstate)
|
|
{
|
|
gamestate = newstate;
|
|
#ifdef HAVE_DISCORDRPC
|
|
DRPC_UpdatePresence();
|
|
#endif
|
|
}
|
|
|
|
boolean G_GamestateUsesLevel(void)
|
|
{
|
|
switch (gamestate)
|
|
{
|
|
case GS_TITLESCREEN:
|
|
return titlemapinaction;
|
|
|
|
case GS_LEVEL:
|
|
return true;
|
|
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/* These functions handle the exitgame flag. Before, when the user
|
|
chose to end a game, it happened immediately, which could cause
|
|
crashes if the game was in the middle of something. Now, a flag
|
|
is set, and the game can then be stopped when it's safe to do
|
|
so.
|
|
*/
|
|
|
|
// Used as a callback function.
|
|
void G_SetExitGameFlag(void)
|
|
{
|
|
exitgame = true;
|
|
}
|
|
|
|
void G_ClearExitGameFlag(void)
|
|
{
|
|
exitgame = false;
|
|
}
|
|
|
|
boolean G_GetExitGameFlag(void)
|
|
{
|
|
return exitgame;
|
|
}
|
|
|
|
// Same deal with retrying.
|
|
void G_SetRetryFlag(void)
|
|
{
|
|
retrying = true;
|
|
}
|
|
|
|
void G_ClearRetryFlag(void)
|
|
{
|
|
retrying = false;
|
|
}
|
|
|
|
boolean G_GetRetryFlag(void)
|
|
{
|
|
return retrying;
|
|
}
|
|
|
|
void G_SetModeAttackRetryFlag(void)
|
|
{
|
|
retryingmodeattack = true;
|
|
G_SetRetryFlag();
|
|
}
|
|
|
|
void G_ClearModeAttackRetryFlag(void)
|
|
{
|
|
retryingmodeattack = false;
|
|
}
|
|
|
|
boolean G_GetModeAttackRetryFlag(void)
|
|
{
|
|
return retryingmodeattack;
|
|
}
|
|
|
|
// Time utility functions
|
|
INT32 G_TicsToHours(tic_t tics)
|
|
{
|
|
return tics/(3600*TICRATE);
|
|
}
|
|
|
|
INT32 G_TicsToMinutes(tic_t tics, boolean full)
|
|
{
|
|
if (full)
|
|
return tics/(60*TICRATE);
|
|
else
|
|
return tics/(60*TICRATE)%60;
|
|
}
|
|
|
|
INT32 G_TicsToSeconds(tic_t tics)
|
|
{
|
|
return (tics/TICRATE)%60;
|
|
}
|
|
|
|
INT32 G_TicsToCentiseconds(tic_t tics)
|
|
{
|
|
return (INT32)((tics%TICRATE) * (100.00f/TICRATE));
|
|
}
|
|
|
|
INT32 G_TicsToMilliseconds(tic_t tics)
|
|
{
|
|
return (INT32)((tics%TICRATE) * (1000.00f/TICRATE));
|
|
}
|
|
|