DOOM64-RE

DOOM 64 Reverse Engineering
Log | Files | Refs | README | LICENSE

g_game.c (8790B)


      1 /* G_game.c  */
      2 
      3 #include "doomdef.h"
      4 #include "p_local.h"
      5 
      6 void G_PlayerReborn (int player);
      7 
      8 void G_DoReborn (int playernum);
      9 
     10 void G_DoLoadLevel (void);
     11 
     12 
     13 gameaction_t    gameaction;                 // 80063230
     14 skill_t         gameskill;                  // 80063234
     15 int             gamemap;                    // 80063238
     16 int				nextmap;				    // 8006323C /* the map to go to after the stats */
     17 
     18 //boolean         playeringame[MAXPLAYERS]; //
     19 player_t        players[MAXPLAYERS];        // 80063240
     20 
     21 int             consoleplayer;          /* player taking events and displaying  */
     22 int             displayplayer;          /* view being displayed  */
     23 int             gametic;
     24 int             totalkills, totalitems, totalsecret;    /* for intermission  */
     25 
     26 //char            demoname[32];
     27 boolean         demorecording;          // 800633A4
     28 boolean         demoplayback;           // 800633A8
     29 int		        *demo_p = NULL, *demobuffer = NULL;   // 8005A180, 8005a184
     30 
     31 //mapthing_t	deathmatchstarts[10], *deathmatch_p;    // 80097e4c, 80077E8C
     32 mapthing_t	playerstarts[MAXPLAYERS];   // 800a8c60
     33 
     34 /*
     35 ==============
     36 =
     37 = G_DoLoadLevel
     38 =
     39 ==============
     40 */
     41 
     42 void G_DoLoadLevel (void) // 80004530
     43 {
     44     if (((gameaction == 7) || (gameaction == 4)) || (players[0].playerstate == PST_DEAD))
     45         players[0].playerstate = PST_REBORN;
     46 
     47 	P_SetupLevel(gamemap, gameskill);
     48 	gameaction = ga_nothing;
     49 }
     50 
     51 
     52 /*
     53 ==============================================================================
     54 
     55 						PLAYER STRUCTURE FUNCTIONS
     56 
     57 also see P_SpawnPlayer in P_Mobj
     58 ==============================================================================
     59 */
     60 
     61 /*
     62 ====================
     63 =
     64 = G_PlayerFinishLevel
     65 =
     66 = Can when a player completes a level
     67 ====================
     68 */
     69 
     70 void G_PlayerFinishLevel (int player) // 80004598
     71 {
     72 	player_t *p;
     73 
     74 	p = &players[player];
     75 
     76 	D_memset (p->powers, 0, sizeof (p->powers));
     77 	D_memset (p->cards, 0, sizeof (p->cards));
     78 	p->mo->flags &= ~MF_SHADOW; /* cancel invisibility  */
     79 	p->extralight = 0;                      /* cancel gun flashes  */
     80 	p->damagecount = 0;                     /* no palette changes  */
     81 	p->bonuscount = 0;
     82     p->bfgcount = 0;
     83     p->automapflags = 0;
     84     p->messagetic = 0;
     85 }
     86 
     87 /*
     88 ====================
     89 =
     90 = G_PlayerReborn
     91 =
     92 = Called after a player dies
     93 = almost everything is cleared and initialized
     94 ====================
     95 */
     96 
     97 int gobalcheats = 0; // [GEC]
     98 
     99 void G_PlayerReborn (int player) // 80004630
    100 {
    101 	player_t *p;
    102 
    103 	p = &players[player];
    104 	D_memset(p, 0, sizeof(*p));
    105 
    106 	p->usedown = p->attackdown = true; // don't do anything immediately
    107 	p->playerstate = PST_LIVE;
    108 	p->health = MAXHEALTH;
    109 	p->readyweapon = p->pendingweapon = wp_pistol;
    110 	p->weaponowned[wp_fist] = true;
    111 	p->weaponowned[wp_pistol] = true;
    112 	p->ammo[am_clip] = 50;
    113     p->maxammo[am_clip] = maxammo[am_clip];
    114     p->maxammo[am_shell] = maxammo[am_shell];
    115     p->maxammo[am_cell] = maxammo[am_cell];
    116     p->maxammo[am_misl] = maxammo[am_misl];
    117 
    118     p->cheats |= gobalcheats; // [GEC] Apply global cheat codes
    119 }
    120 
    121 /*============================================================================  */
    122 
    123 /*
    124 ====================
    125 =
    126 = G_CompleteLevel
    127 =
    128 ====================
    129 */
    130 
    131 void G_CompleteLevel (void) // 800046E4
    132 {
    133 	gameaction = ga_completed;
    134 }
    135 
    136 /*
    137 ====================
    138 =
    139 = G_InitNew
    140 =
    141 ====================
    142 */
    143 
    144 extern int ActualConfiguration[13];
    145 mobj_t emptymobj; // 80063158
    146 
    147 void G_InitNew (skill_t skill, int map, gametype_t gametype) // 800046F4
    148 {
    149 	//printf ("G_InitNew, skill %d, map %d\n", skill, map);
    150 
    151 	/* free all tags except the PU_STATIC tag */
    152 	Z_FreeTags(mainzone, ~PU_STATIC); // (PU_LEVEL | PU_LEVSPEC | PU_CACHE)
    153 
    154 	M_ClearRandom ();
    155 
    156 /* force players to be initialized upon first level load          */
    157     players[0].playerstate = PST_REBORN;
    158 
    159 /* these may be reset by I_NetSetup */
    160 	gameskill = skill;
    161 	gamemap = map;
    162 
    163 	D_memset(&emptymobj, 0, sizeof(emptymobj));
    164 	players[0].mo = &emptymobj;	/* for net consistancy checks */
    165 
    166 	demorecording = false;
    167 	demoplayback = false;
    168 
    169 	BT_DATA[0] = (buttons_t *)ActualConfiguration;
    170 
    171 	#if ENABLE_NIGHTMARE == 1
    172 	if (skill == sk_nightmare)
    173 	{
    174 		states[S_054].tics = 4; // S_SARG_ATK1
    175 		states[S_055].tics = 4; // S_SARG_ATK2
    176 		states[S_056].tics = 4; // S_SARG_ATK3
    177 		mobjinfo[MT_DEMON1].speed = 17; // MT_SERGEANT
    178 		mobjinfo[MT_DEMON2].speed = 17; // MT_SERGEANT2
    179 
    180 		mobjinfo[MT_PROJ_BRUISER1].speed = 20; // MT_BRUISERSHOT
    181 		mobjinfo[MT_PROJ_BRUISER2].speed = 20; // MT_BRUISERSHOT2
    182 		mobjinfo[MT_PROJ_HEAD].speed = 30; // MT_HEADSHOT value like Doom 64 Ex
    183 		mobjinfo[MT_PROJ_IMP1].speed = 20; // MT_TROOPSHOT
    184 		mobjinfo[MT_PROJ_IMP2].speed = 35; // MT_TROOPSHOT2 value like Doom 64 Ex
    185 	}
    186 	else
    187 	{
    188 		states[S_054].tics = 8; // S_SARG_ATK1
    189 		states[S_055].tics = 8; // S_SARG_ATK2
    190 		states[S_056].tics = 8; // S_SARG_ATK3
    191 		mobjinfo[MT_DEMON1].speed = 12; // MT_SERGEANT
    192 		mobjinfo[MT_DEMON2].speed = 12; // MT_SERGEANT2
    193 
    194 		mobjinfo[MT_PROJ_BRUISER1].speed = 15; // MT_BRUISERSHOT
    195 		mobjinfo[MT_PROJ_BRUISER2].speed = 15; // MT_BRUISERSHOT2
    196 		mobjinfo[MT_PROJ_HEAD].speed = 20; // MT_HEADSHOT
    197 		mobjinfo[MT_PROJ_IMP1].speed = 10; // MT_TROOPSHOT
    198 		mobjinfo[MT_PROJ_IMP2].speed = 20; // MT_TROOPSHOT2
    199 	}
    200 	#endif // ENABLE_NIGHTMARE
    201 }
    202 
    203 /*============================================================================  */
    204 
    205 /*
    206 =================
    207 =
    208 = G_RunGame
    209 =
    210 = The game should allready have been initialized or laoded
    211 =================
    212 */
    213 
    214 void G_RunGame (void) // 80004794
    215 {
    216 
    217 	while (1)
    218 	{
    219         /* load a level */
    220         G_DoLoadLevel ();
    221 
    222         //printf("RUN P_Start\n");
    223         //PRINTF_D2(WHITE, 0, 28, "RUN P_Start\n");
    224 		/* run a level until death or completion */
    225 		MiniLoop (P_Start, P_Stop, P_Ticker, P_Drawer);
    226 
    227         //if (gameaction == ga_recorddemo)
    228             //G_RecordDemo();
    229 
    230         if(gameaction == ga_warped)
    231 			continue; /* skip intermission */
    232 
    233         if ((gameaction == ga_died) || (gameaction == ga_restart))
    234 			continue;			/* died, so restart the level */
    235 
    236         if (gameaction == ga_exitdemo)
    237             return;
    238 
    239         /* run a stats intermission */
    240         if (nextmap != 32) {
    241             MiniLoop(IN_Start, IN_Stop, IN_Ticker, IN_Drawer);
    242         }
    243 
    244         if(((gamemap ==  8) && (nextmap ==  9)) ||
    245            ((gamemap ==  4) && (nextmap == 29)) ||
    246            ((gamemap == 12) && (nextmap == 30)) ||
    247            ((gamemap == 18) && (nextmap == 31)) ||
    248            ((gamemap ==  1) && (nextmap == 32)))
    249         {
    250             /* run the intermission if needed */
    251             MiniLoop(F_StartIntermission, F_StopIntermission, F_TickerIntermission, F_DrawerIntermission);
    252 
    253             if(gameaction == ga_warped)
    254                 continue; /* skip intermission */
    255 
    256             if(gameaction == ga_restart)
    257                 continue;
    258 
    259             if (gameaction == ga_exitdemo)
    260                 return;
    261         }
    262         else
    263         {
    264             if (nextmap >= LASTLEVEL)
    265             {
    266                 /* run the finale if needed */
    267                 MiniLoop(F_Start, F_Stop, F_Ticker, F_Drawer);
    268 
    269                 if(gameaction == ga_warped)
    270                     continue; /* skip intermission */
    271 
    272                 if(gameaction == ga_restart)
    273                     continue;
    274                 else
    275                     return;
    276             }
    277         }
    278 
    279         /* Set Next Level */
    280         gamemap = nextmap;
    281 	}
    282 }
    283 
    284 int G_PlayDemoPtr (int skill, int map) // 800049D0
    285 {
    286 	int		exit;
    287 	int		config[13];
    288 	int     sensitivity;
    289 
    290 	demobuffer = demo_p;
    291 
    292 	/* copy key configuration */
    293 	D_memcpy(config, ActualConfiguration, sizeof(config));
    294 
    295 	/* set new key configuration */
    296 	D_memcpy(ActualConfiguration, demobuffer, sizeof(config));
    297 
    298 	/* copy analog m_sensitivity */
    299 	sensitivity = M_SENSITIVITY;
    300 
    301 	/* set new analog m_sensitivity */
    302 	M_SENSITIVITY = demobuffer[13];
    303 
    304 	/* skip analog and key configuration */
    305 	demobuffer += 14;
    306 
    307 	/* play demo game */
    308 	G_InitNew (skill, map, gt_single);
    309 	G_DoLoadLevel ();
    310 	demoplayback = true;
    311 	exit = MiniLoop (P_Start, P_Stop, P_Ticker, P_Drawer);
    312 	demoplayback = false;
    313 
    314 	/* restore key configuration */
    315 	D_memcpy(ActualConfiguration, config, sizeof(config));
    316 
    317 	/* restore analog m_sensitivity */
    318 	M_SENSITIVITY = sensitivity;
    319 
    320 	/* free all tags except the PU_STATIC tag */
    321 	Z_FreeTags(mainzone, ~PU_STATIC); // (PU_LEVEL | PU_LEVSPEC | PU_CACHE)
    322 
    323 	return exit;
    324 }
    325 
    326 /*
    327 =================
    328 =
    329 = G_RecordDemo
    330 =
    331 =================
    332 */
    333 
    334 void G_RecordDemo (void)//80013D0C
    335 {
    336     #if 0
    337 	demo_p = demobuffer = Z_Malloc (0x8000, PU_STATIC, NULL);
    338 
    339 	*demo_p++ = startskill;
    340 	*demo_p++ = startmap;
    341 
    342 	G_InitNew (startskill, startmap, gt_single);
    343 	G_DoLoadLevel ();
    344 	demorecording = true;
    345 	MiniLoop (P_Start, P_Stop, P_Ticker, P_Drawer);
    346 	demorecording = false;
    347 
    348 	D_printf ("w %x,%x",demobuffer,demo_p);
    349 
    350 	while (1)
    351 	{
    352 		G_PlayDemoPtr (demobuffer);
    353 	D_printf ("w %x,%x",demobuffer,demo_p);
    354 	}
    355     #endif
    356 }