dxx-rebirth/main/game.c

1420 lines
38 KiB
C
Raw Normal View History

2006-03-20 16:43:15 +00:00
/*
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
*/
/*
*
* Game loop for Inferno
*
*/
2006-03-20 16:43:15 +00:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <SDL/SDL.h>
2006-03-20 16:43:15 +00:00
#ifdef OGL
#include "ogl_init.h"
#endif
#include "pstypes.h"
#include "console.h"
#include "gr.h"
2006-03-20 16:43:15 +00:00
#include "inferno.h"
#include "game.h"
#include "key.h"
#include "object.h"
#include "physics.h"
#include "error.h"
#include "joy.h"
#include "iff.h"
#include "pcx.h"
#include "timer.h"
#include "render.h"
#include "laser.h"
#include "screens.h"
#include "textures.h"
#include "slew.h"
#include "gauges.h"
#include "texmap.h"
#include "3d.h"
#include "effects.h"
#include "menu.h"
#include "gameseg.h"
#include "wall.h"
#include "ai.h"
#include "hostage.h"
#include "fuelcen.h"
#include "digi.h"
#include "u_mem.h"
#include "palette.h"
#include "morph.h"
#include "lighting.h"
#include "newdemo.h"
#include "collide.h"
#include "weapon.h"
#include "sounds.h"
#include "args.h"
#include "gameseq.h"
#include "automap.h"
#include "text.h"
#include "powerup.h"
#include "fireball.h"
#include "newmenu.h"
#include "gamefont.h"
#include "endlevel.h"
#include "kconfig.h"
#include "config.h"
2006-03-20 16:43:15 +00:00
#include "mouse.h"
#include "switch.h"
#include "controls.h"
#include "songs.h"
#include "rbaudio.h"
2006-03-20 16:43:15 +00:00
#include "multi.h"
#include "desc_id.h"
#include "cntrlcen.h"
#include "pcx.h"
#include "state.h"
#include "piggy.h"
#include "multibot.h"
#include "fvi.h"
#include "playsave.h"
#include "hudmsg.h"
#include "vers_id.h"
#include "event.h"
#include "window.h"
2006-03-20 16:43:15 +00:00
#ifdef EDITOR
#include "editor/editor.h"
#endif
2006-03-20 16:43:15 +00:00
#ifndef NDEBUG
int Mark_count = 0; // number of debugging marks set
#endif
2006-03-20 16:43:15 +00:00
static fix last_timer_value=0;
2006-03-20 16:43:15 +00:00
fix VR_eye_width = F1_0;
int VR_render_mode = VR_NONE;
int VR_low_res = 3; // Default to low res
2006-03-20 16:43:15 +00:00
int VR_show_hud = 1;
int VR_sensitivity = 1; // 0 - 2
//NEWVR
int VR_eye_offset = 0;
int VR_eye_switch = 0;
int VR_eye_offset_changed = 0;
int VR_use_reg_code = 0;
grs_canvas Screen_3d_window; // The rectangle for rendering the mine to
grs_canvas *VR_offscreen_buffer = NULL; // The offscreen data buffer
grs_canvas VR_render_buffer[2]; // Two offscreen buffers for left/right eyes.
grs_canvas VR_render_sub_buffer[2]; // Two sub buffers for left/right eyes.
grs_canvas VR_editor_canvas; // The canvas that the editor writes to.
2006-03-20 16:43:15 +00:00
int force_cockpit_redraw=0;
int PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd;
// Toggle_var points at a variable which gets !ed on del-T press.
2006-03-20 16:43:15 +00:00
int Dummy_var;
int *Toggle_var = &Dummy_var;
2006-03-20 16:43:15 +00:00
#ifdef EDITOR
//flag for whether initial fade-in has been done
char faded_in;
2006-03-20 16:43:15 +00:00
#endif
int Game_suspended=0; //if non-zero, nothing moves but player
2006-03-20 16:43:15 +00:00
fix Auto_fire_fusion_cannon_time = 0;
fix Fusion_charge = 0;
fix Fusion_next_sound_time = 0;
fix Fusion_last_sound_time = 0;
int Game_turbo_mode = 0;
int Game_mode = GM_GAME_OVER;
2006-03-20 16:43:15 +00:00
int Global_laser_firing_count = 0;
int Global_missile_firing_count = 0;
int Game_aborted;
2006-03-20 16:43:15 +00:00
// Function prototypes for GAME.C exclusively.
void GameProcessFrame(void);
void FireLaser(void);
void powerup_grab_cheat_all(void);
void game_init_render_sub_buffers(int x, int y, int w, int h);
2006-03-20 16:43:15 +00:00
extern void ReadControls(void); // located in gamecntl.c
2006-03-20 16:43:15 +00:00
// ==============================================================================================
//this is called once per game
void init_game()
{
init_objects();
hostage_init();
init_special_effects();
init_exploding_walls();
Clear_window = 2; // do portal only window clear.
2006-03-20 16:43:15 +00:00
}
void reset_palette_add()
{
PaletteRedAdd = 0;
PaletteGreenAdd = 0;
PaletteBlueAdd = 0;
}
void game_show_warning(char *s)
{
if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME)))
stop_time();
nm_messagebox( TXT_WARNING, 1, TXT_OK, s );
if (!((Game_mode & GM_MULTI) && (Function_mode == FMODE_GAME)))
start_time();
}
u_int32_t Game_screen_mode = SM(640,480);
2006-03-20 16:43:15 +00:00
//initialize the various canvases on the game screen
//called every time the screen mode or cockpit changes
void init_cockpit()
{
//Initialize the on-screen canvases
if (Screen_mode != SCREEN_GAME)
return;
if (( Screen_mode == SCREEN_EDITOR ) || ( VR_render_mode != VR_NONE ))
PlayerCfg.CockpitMode[1] = CM_FULL_SCREEN;
2006-03-20 16:43:15 +00:00
#ifndef OGL
if ( Game_screen_mode != (HiresGFXAvailable? SM(640,480) : SM(320,200)) && PlayerCfg.CockpitMode[1] != CM_LETTERBOX) {
PlayerCfg.CockpitMode[1] = CM_FULL_SCREEN;
2006-03-20 16:43:15 +00:00
}
#endif
gr_set_current_canvas(NULL);
2006-03-20 16:43:15 +00:00
switch( PlayerCfg.CockpitMode[1] ) {
case CM_FULL_COCKPIT:
game_init_render_sub_buffers(0, 0, SWIDTH, (SHEIGHT*2)/3);
break;
case CM_REAR_VIEW:
case CM_FULL_SCREEN:
game_init_render_sub_buffers(0, 0, SWIDTH, SHEIGHT);
break;
2006-03-20 16:43:15 +00:00
case CM_STATUS_BAR:
game_init_render_sub_buffers( 0, 0, SWIDTH, (HIRESMODE?(SHEIGHT*2)/2.6:(SHEIGHT*2)/2.72) );
break;
case CM_LETTERBOX: {
int x,y,w,h;
2006-03-20 16:43:15 +00:00
x = 0; w = SM_W(Game_screen_mode);
h = (SM_H(Game_screen_mode) * 3) / 4; // true letterbox size (16:9)
y = (SM_H(Game_screen_mode)-h)/2;
2006-03-20 16:43:15 +00:00
gr_rect(x,0,w,SM_H(Game_screen_mode)-h);
gr_rect(x,SM_H(Game_screen_mode)-h,w,SM_H(Game_screen_mode));
game_init_render_sub_buffers( x, y, w, h );
break;
2006-03-20 16:43:15 +00:00
}
}
2006-03-20 16:43:15 +00:00
gr_set_current_canvas(NULL);
}
//selects a given cockpit (or lack of one). See types in game.h
void select_cockpit(int mode)
{
if (mode != PlayerCfg.CockpitMode[1]) { //new mode
PlayerCfg.CockpitMode[1]=mode;
2006-03-20 16:43:15 +00:00
init_cockpit();
}
}
//force cockpit redraw next time. call this if you've trashed the screen
void reset_cockpit()
{
force_cockpit_redraw=1;
last_drawn_cockpit = -1;
2006-03-20 16:43:15 +00:00
}
void game_init_render_sub_buffers( int x, int y, int w, int h )
{
gr_clear_canvas(0);
gr_init_sub_canvas( &Screen_3d_window, &grd_curscreen->sc_canvas, x, y, w, h );
2006-03-20 16:43:15 +00:00
gr_init_sub_canvas( &VR_render_sub_buffer[0], &VR_render_buffer[0], x, y, w, h );
gr_init_sub_canvas( &VR_render_sub_buffer[1], &VR_render_buffer[1], x, y, w, h );
}
// Sets up the canvases we will be rendering to
void game_init_render_buffers(int render_w, int render_h, int render_method )
2006-03-20 16:43:15 +00:00
{
VR_render_mode = render_method;
if (VR_offscreen_buffer) {
gr_free_canvas(VR_offscreen_buffer);
}
if ( (VR_render_mode==VR_AREA_DET) || (VR_render_mode==VR_INTERLACED ) ) {
if ( render_h*2 < 200 )
VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
else
VR_offscreen_buffer = gr_create_canvas( render_w, render_h*2 );
2006-03-20 16:43:15 +00:00
gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, render_h, render_w, render_h );
} else {
if ( render_h < 200 )
VR_offscreen_buffer = gr_create_canvas( render_w, 200 );
else
VR_offscreen_buffer = gr_create_canvas( render_w, render_h );
2006-03-20 16:43:15 +00:00
#ifdef OGL
VR_offscreen_buffer->cv_bitmap.bm_type = BM_OGL;
2006-03-20 16:43:15 +00:00
#endif
gr_init_sub_canvas( &VR_render_buffer[0], VR_offscreen_buffer, 0, 0, render_w, render_h );
gr_init_sub_canvas( &VR_render_buffer[1], VR_offscreen_buffer, 0, 0, render_w, render_h );
2006-03-20 16:43:15 +00:00
}
game_init_render_sub_buffers( 0, 0, render_w, render_h );
2006-03-20 16:43:15 +00:00
}
//called to change the screen mode. Parameter sm is the new mode, one of
//SMODE_GAME or SMODE_EDITOR. returns mode acutally set (could be other
//mode if cannot init requested mode)
int set_screen_mode(int sm)
{
if ( (Screen_mode == sm) && !((sm==SCREEN_GAME) && (grd_curscreen->sc_mode != Game_screen_mode)) && !(sm==SCREEN_MENU) )
{
gr_set_current_canvas(NULL);
#ifndef OGL
gr_set_draw_buffer(0); // Set to the front buffer
#endif
return 1;
}
2006-03-20 16:43:15 +00:00
#ifdef EDITOR
Canv_editor = NULL;
#endif
Screen_mode = sm;
switch( Screen_mode )
{
case SCREEN_MENU:
/* give control back to the WM */
if (GameArg.CtlGrabMouse)
SDL_WM_GrabInput(SDL_GRAB_OFF);
if (grd_curscreen->sc_mode != Game_screen_mode)
if (gr_set_mode(Game_screen_mode))
Error("Cannot set screen mode.");
break;
case SCREEN_GAME:
/* keep the mouse from wandering in SDL */
if (GameArg.CtlGrabMouse && (Newdemo_state != ND_STATE_PLAYBACK))
SDL_WM_GrabInput(SDL_GRAB_ON);
if (grd_curscreen->sc_mode != Game_screen_mode)
if (gr_set_mode(Game_screen_mode))
Error("Cannot set screen mode.");
reset_cockpit();
init_cockpit();
break;
#ifdef EDITOR
case SCREEN_EDITOR:
/* give control back to the WM */
if (GameArg.CtlGrabMouse)
SDL_WM_GrabInput(SDL_GRAB_OFF);
if (grd_curscreen->sc_mode != SM(800,600)) {
int gr_error;
if ((gr_error=gr_set_mode(SM(800,600)))!=0) { //force into game scrren
Warning("Cannot init editor screen (error=%d)",gr_error);
return 0;
}
2006-03-20 16:43:15 +00:00
}
gr_palette_load( gr_palette );
gr_init_sub_canvas( &VR_editor_canvas, &grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT );
Canv_editor = &VR_editor_canvas;
gr_set_current_canvas( Canv_editor );
init_editor_screen(); //setup other editor stuff
break;
#endif
default:
Error("Invalid screen mode %d",sm);
2006-03-20 16:43:15 +00:00
}
gr_set_current_canvas(NULL);
2006-03-20 16:43:15 +00:00
#ifndef OGL
2007-07-22 01:34:00 +00:00
gr_set_draw_buffer(((Screen_mode == SCREEN_GAME) && GameArg.DbgUseDoubleBuffer) ? 1 : 0); // Double buffering or 'front' buffer only
2006-03-20 16:43:15 +00:00
#endif
2006-03-20 16:43:15 +00:00
return 1;
}
static int time_paused=0;
2006-03-20 16:43:15 +00:00
void stop_time()
{
if (time_paused==0) {
2006-03-20 16:43:15 +00:00
fix time;
time = timer_get_fixed_seconds();
last_timer_value = time - last_timer_value;
if (last_timer_value < 0) {
last_timer_value = 0;
}
}
time_paused++;
2006-03-20 16:43:15 +00:00
}
void start_time()
{
time_paused--;
Assert(time_paused >= 0);
if (time_paused==0) {
2006-03-20 16:43:15 +00:00
fix time;
time = timer_get_fixed_seconds();
last_timer_value = time - last_timer_value;
}
}
void game_flush_inputs()
{
int dx,dy,dz;
2006-03-20 16:43:15 +00:00
key_flush();
joy_flush();
mouse_flush();
mouse_get_delta( &dx, &dy, &dz ); // Read mouse
2006-03-20 16:43:15 +00:00
memset(&Controls,0,sizeof(control_info));
}
/*
Calculates several - common used - timesteps and stores into FixedStep
*/
void FixedStepCalc()
{
int StepRes = 0;
static fix Timer4 = 0, Timer20 = 0, Timer30 = 0;
Timer4 += FrameTime;
if (Timer4 >= F1_0/4)
{
StepRes |= EPS4;
Timer4 = 0 - (Timer4-F1_0/4);
}
Timer20 += FrameTime;
if (Timer20 >= F1_0/20)
{
StepRes |= EPS20;
Timer20 = 0 - (Timer20-F1_0/20);
}
Timer30 += FrameTime;
if (Timer30 >= F1_0/30)
{
StepRes |= EPS30;
Timer30 = 0 - (Timer30-F1_0/30);
}
FixedStep = StepRes;
}
2006-03-20 16:43:15 +00:00
void reset_time()
{
last_timer_value = timer_get_fixed_seconds();
}
void calc_frame_time()
{
fix timer_value,last_frametime = FrameTime;
timer_value = timer_get_fixed_seconds();
FrameTime = timer_value - last_timer_value;
while (FrameTime < f1_0 / (GameCfg.VSync?MAXIMUM_FPS:GameArg.SysMaxFPS))
{
if (GameArg.SysUseNiceFPS && !GameCfg.VSync)
timer_delay(f1_0 / GameArg.SysMaxFPS - FrameTime);
timer_value = timer_get_fixed_seconds();
FrameTime = timer_value - last_timer_value;
}
2006-03-20 16:43:15 +00:00
if ( Game_turbo_mode )
FrameTime *= 2;
last_timer_value = timer_value;
if (FrameTime < 0) //if bogus frametime...
FrameTime = (last_frametime==0?1:last_frametime); //...then use time from last frame
GameTime += FrameTime;
if (GameTime < 0 || GameTime > i2f(0x7fff - 600))
GameTime = FrameTime; //wrap when goes negative, or ~9hrs
FixedStepCalc();
2006-03-20 16:43:15 +00:00
}
void move_player_2_segment(segment *seg,int side)
{
vms_vector vp;
compute_segment_center(&ConsoleObject->pos,seg);
compute_center_point_on_side(&vp,seg,side);
vm_vec_sub2(&vp,&ConsoleObject->pos);
vm_vector_2_matrix(&ConsoleObject->orient,&vp,NULL,NULL);
obj_relink( ConsoleObject-Objects, SEG_PTR_2_NUM(seg) );
}
void do_photos();
void level_with_floor();
#ifndef OGL
void save_screen_shot(int automap_flag)
{
char message[100];
grs_canvas *screen_canv=&grd_curscreen->sc_canvas;
static int savenum=0;
grs_canvas *temp_canv,*save_canv;
char savename[FILENAME_LEN+sizeof(SCRNS_DIR)];
2006-03-20 16:43:15 +00:00
ubyte pal[768];
stop_time();
if (!cfexist(SCRNS_DIR))
PHYSFS_mkdir(SCRNS_DIR); //try making directory
2006-03-20 16:43:15 +00:00
save_canv = grd_curcanv;
temp_canv = gr_create_canvas(screen_canv->cv_bitmap.bm_w,screen_canv->cv_bitmap.bm_h);
gr_set_current_canvas(temp_canv);
gr_ubitmap(0,0,&screen_canv->cv_bitmap);
gr_set_current_canvas(save_canv);
do
{
sprintf(savename, "%sscrn%04d.pcx",SCRNS_DIR, savenum++);
} while (PHYSFS_exists(savename));
sprintf( message, "%s 'scrn%04d.pcx'", TXT_DUMPING_SCREEN, savenum-1 );
2006-03-20 16:43:15 +00:00
gr_set_current_canvas(NULL);
if (!automap_flag)
hud_message(MSGC_GAME_FEEDBACK,message);
2006-03-20 16:43:15 +00:00
gr_palette_read(pal); //get actual palette from the hardware
2006-03-20 16:43:15 +00:00
pcx_write_bitmap(savename,&temp_canv->cv_bitmap,pal);
gr_set_current_canvas(screen_canv);
gr_ubitmap(0,0,&temp_canv->cv_bitmap);
2006-03-20 16:43:15 +00:00
gr_free_canvas(temp_canv);
gr_set_current_canvas(save_canv);
2006-03-20 16:43:15 +00:00
key_flush();
start_time();
}
#endif
2006-03-20 16:43:15 +00:00
//initialize flying
void fly_init(object *obj)
{
obj->control_type = CT_FLYING;
obj->movement_type = MT_PHYSICS;
vm_vec_zero(&obj->mtype.phys_info.velocity);
vm_vec_zero(&obj->mtype.phys_info.thrust);
vm_vec_zero(&obj->mtype.phys_info.rotvel);
vm_vec_zero(&obj->mtype.phys_info.rotthrust);
}
void test_anim_states();
extern int been_in_editor;
// ------------------------------------------------------------------------------------
void do_cloak_stuff(void)
{
int i;
2006-03-20 16:43:15 +00:00
for (i = 0; i < N_players; i++)
if (Players[i].flags & PLAYER_FLAGS_CLOAKED) {
if (Players[Player_num].cloak_time+CLOAK_TIME_MAX-GameTime < 0 &&
Players[Player_num].cloak_time+CLOAK_TIME_MAX-GameTime > -F1_0*2)
{
2006-03-20 16:43:15 +00:00
Players[i].flags &= ~PLAYER_FLAGS_CLOAKED;
if (i == Player_num) {
digi_play_sample( SOUND_CLOAK_OFF, F1_0);
#ifdef NETWORK
2006-03-20 16:43:15 +00:00
if (Game_mode & GM_MULTI)
multi_send_play_sound(SOUND_CLOAK_OFF, F1_0);
maybe_drop_net_powerup(POW_CLOAK);
if ( Newdemo_state != ND_STATE_PLAYBACK )
2007-02-28 20:43:10 +00:00
multi_send_decloak(); // For demo recording
#endif
2006-03-20 16:43:15 +00:00
}
}
}
}
// ------------------------------------------------------------------------------------
void do_invulnerable_stuff(void)
{
if (Players[Player_num].flags & PLAYER_FLAGS_INVULNERABLE) {
if (Players[Player_num].invulnerable_time+INVULNERABLE_TIME_MAX-GameTime < 0 &&
Players[Player_num].invulnerable_time+INVULNERABLE_TIME_MAX-GameTime > -F1_0*2)
{
2006-03-20 16:43:15 +00:00
Players[Player_num].flags ^= PLAYER_FLAGS_INVULNERABLE;
#ifdef NETWORK
2006-03-20 16:43:15 +00:00
maybe_drop_net_powerup(POW_INVULNERABILITY);
#endif
2006-03-20 16:43:15 +00:00
digi_play_sample( SOUND_INVULNERABILITY_OFF, F1_0);
#ifdef NETWORK
2006-03-20 16:43:15 +00:00
if (Game_mode & GM_MULTI)
multi_send_play_sound(SOUND_INVULNERABILITY_OFF, F1_0);
#endif
2006-03-20 16:43:15 +00:00
}
}
}
// Amount to diminish guns towards normal, per second.
#define DIMINISH_RATE 16 // gots to be a power of 2, else change the code in diminish_palette_towards_normal
2006-03-20 16:43:15 +00:00
//adds to rgb values for palette flash
void PALETTE_FLASH_ADD(int _dr, int _dg, int _db)
{
int maxval;
PaletteRedAdd += _dr;
PaletteGreenAdd += _dg;
PaletteBlueAdd += _db;
maxval = MAX_PALETTE_ADD;
if (PaletteRedAdd > maxval)
PaletteRedAdd = maxval;
if (PaletteGreenAdd > maxval)
PaletteGreenAdd = maxval;
if (PaletteBlueAdd > maxval)
PaletteBlueAdd = maxval;
if (PaletteRedAdd < -maxval)
PaletteRedAdd = -maxval;
if (PaletteGreenAdd < -maxval)
PaletteGreenAdd = -maxval;
if (PaletteBlueAdd < -maxval)
PaletteBlueAdd = -maxval;
}
2006-03-20 16:43:15 +00:00
// ------------------------------------------------------------------------------------
// Diminish palette effects towards normal.
void diminish_palette_towards_normal(void)
{
int dec_amount = 0;
// Diminish at DIMINISH_RATE units/second.
// For frame rates > DIMINISH_RATE Hz, use randomness to achieve this.
2006-03-20 16:43:15 +00:00
if (FrameTime < F1_0/DIMINISH_RATE) {
if (d_rand() < FrameTime*DIMINISH_RATE/2) // Note: d_rand() is in 0..32767, and 8 Hz means decrement every frame
2006-03-20 16:43:15 +00:00
dec_amount = 1;
} else {
dec_amount = f2i(FrameTime*DIMINISH_RATE); // one second = DIMINISH_RATE counts
2006-03-20 16:43:15 +00:00
if (dec_amount == 0)
dec_amount++; // make sure we decrement by something
2006-03-20 16:43:15 +00:00
}
if (PaletteRedAdd > 0 ) { PaletteRedAdd -= dec_amount; if (PaletteRedAdd < 0 ) PaletteRedAdd = 0; }
if (PaletteRedAdd < 0 ) { PaletteRedAdd += dec_amount; if (PaletteRedAdd > 0 ) PaletteRedAdd = 0; }
if (PaletteGreenAdd > 0 ) { PaletteGreenAdd -= dec_amount; if (PaletteGreenAdd < 0 ) PaletteGreenAdd = 0; }
if (PaletteGreenAdd < 0 ) { PaletteGreenAdd += dec_amount; if (PaletteGreenAdd > 0 ) PaletteGreenAdd = 0; }
if (PaletteBlueAdd > 0 ) { PaletteBlueAdd -= dec_amount; if (PaletteBlueAdd < 0 ) PaletteBlueAdd = 0; }
if (PaletteBlueAdd < 0 ) { PaletteBlueAdd += dec_amount; if (PaletteBlueAdd > 0 ) PaletteBlueAdd = 0; }
if ( (Newdemo_state==ND_STATE_RECORDING) && (PaletteRedAdd || PaletteGreenAdd || PaletteBlueAdd) )
newdemo_record_palette_effect(PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd);
gr_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
}
int Redsave, Bluesave, Greensave;
void palette_save(void)
{
Redsave = PaletteRedAdd; Bluesave = PaletteBlueAdd; Greensave = PaletteGreenAdd;
}
void palette_restore(void)
{
PaletteRedAdd = Redsave; PaletteBlueAdd = Bluesave; PaletteGreenAdd = Greensave;
gr_palette_step_up( PaletteRedAdd, PaletteGreenAdd, PaletteBlueAdd );
}
extern void dead_player_frame(void);
// --------------------------------------------------------------------------------------------------
int allowed_to_fire_laser(void)
{
if (Player_is_dead) {
Global_missile_firing_count = 0;
return 0;
}
// Make sure enough time has elapsed to fire laser, but if it looks like it will
// be a long while before laser can be fired, then there must be some mistake!
if (Next_laser_fire_time > GameTime)
if (Next_laser_fire_time < GameTime + 2*F1_0)
return 0;
return 1;
}
fix Next_flare_fire_time = 0;
int allowed_to_fire_flare(void)
{
if (Next_flare_fire_time > GameTime)
if (Next_flare_fire_time < GameTime + F1_0) // In case time is bogus, never wait > 1 second.
return 0;
Next_flare_fire_time = GameTime + F1_0/4;
return 1;
}
int allowed_to_fire_missile(void)
{
// Make sure enough time has elapsed to fire missile, but if it looks like it will
// be a long while before missile can be fired, then there must be some mistake!
if (Next_missile_fire_time > GameTime)
if (Next_missile_fire_time < GameTime + 5*F1_0)
return 0;
return 1;
}
extern int Death_sequence_aborted;
#ifdef USE_SDLMIXER
#define EXT_MUSIC_TEXT "Jukebox/Audio CD"
#else
#define EXT_MUSIC_TEXT "Audio CD"
#endif
2006-03-20 16:43:15 +00:00
void show_help()
{
int nitems = 0;
newmenu_item m[25];
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_ESC;
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "SHIFT-ESC\t SHOW GAME LOG";
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "F1\t THIS SCREEN";
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_F2;
#if !(defined(__APPLE__) || defined(macintosh))
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Alt-F2/F3\t SAVE/LOAD GAME";
#else
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Alt-F2/F3 (\x85-s/o)\t SAVE/LOAD GAME";
#endif
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "F3\t SWITCH COCKPIT MODES";
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_F5;
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "ALT-F7\t SWITCH HUD MODES";
#if !(defined(__APPLE__) || defined(macintosh))
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_PAUSE;
#else
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Pause (\x85-P)\t Pause";
#endif
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_PRTSCN;
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_1TO5;
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_6TO10;
#if !(defined(__APPLE__) || defined(macintosh))
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Alt-Shift-F9\t Eject Audio CD";
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Alt-Shift-F10\t Play/Pause " EXT_MUSIC_TEXT;
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "Alt-Shift-F11/F12\t Previous/Next Song";
#else
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "\x85-E\t Eject Audio CD";
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "\x85-Up/Down\t Play/Pause " EXT_MUSIC_TEXT;
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "\x85-Left/Right\t Previous/Next Song";
#endif
#if (defined(__APPLE__) || defined(macintosh))
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "";
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "(Use \x85-# for F#. e.g. \x85-1 for F1)";
#endif
newmenu_dotiny( NULL, TXT_KEYS, nitems, m, NULL, NULL );
}
void show_netgame_help()
{
int nitems = 0;
newmenu_item m[12];
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "F1\t THIS SCREEN";
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "ALT-F4\t SHOW RETICLE NAMES";
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "F7\t TOGGLE KILL LIST";
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "F8\t SEND MESSAGE";
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "(SHIFT-)F8 to F12\t (DEFINE)SEND MACRO";
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "PAUSE\t SHOW NETGAME INFORMATION";
#if (defined(__APPLE__) || defined(macintosh))
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "";
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "(Use \x85-# for F#. e.g. \x85-1 for F1)";
#endif
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "";
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "MULTIPLAYER MESSAGE COMMANDS:";
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "kick: (*)\t KICK PLAYER (*) FROM GAME (Host-only)";
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "KillReactor\t BLOW UP THE MINE (Host-only)";
newmenu_dotiny( NULL, TXT_KEYS, nitems, m, NULL, NULL );
2006-03-20 16:43:15 +00:00
}
void show_newdemo_help()
{
newmenu_item m[15];
int nitems = 0;
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "ESC\t QUIT DEMO PLAYBACK";
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "F1\t THIS SCREEN";
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = TXT_HELP_F2;
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "F3\t SWITCH COCKPIT MODES";
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "F4\t TOGGLE PERCENTAGE DISPLAY";
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "UP\t PLAY";
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "DOWN\t PAUSE";
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "RIGHT\t ONE FRAME FORWARD";
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "LEFT\t ONE FRAME BACKWARD";
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "SHIFT-RIGHT\t FAST FORWARD";
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "SHIFT-LEFT\t FAST BACKWARD";
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "CTRL-RIGHT\t JUMP TO END";
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "CTRL-LEFT\t JUMP TO START";
#if (defined(__APPLE__) || defined(macintosh))
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "";
m[nitems].type = NM_TYPE_TEXT; m[nitems++].text = "(Use \x85-# for F#. e.g. \x85-1 for F1)";
#endif
newmenu_dotiny( NULL, "DEMO PLAYBACK CONTROLS", nitems, m, NULL, NULL );
}
2006-03-20 16:43:15 +00:00
//temp function until Matt cleans up game sequencing
extern void temp_reset_stuff_on_level();
Giving credits function ability to use custom creditfile (again); Made laser-offset for laser exclusive so Prox mines won't go tru doors; Preventing cycling tru cockpit modes while dead, but allowing to load a state; Implemented D2X' lighting code to D1X (faster, better, sexier - weeee); Try to hop over some errors regarding walls/doors in levels instead of using -1 indexes for arrays; Made the briefing text ptr a bit more failsafe in case the file is corrupt/non-standard; Made scores use the menu screen even in GAME OVER; Fixed bug in neighbour fields of Weapon Keys table; Added the Weapon Keys stuff to TABLE_CREATION; Fixed bug where D2X did not recall applied resolution in the resolutions menu; Simpler check to create DEMO_DIR; Seperated X/Y sensitivity for mouse and joystick; Flush controls when Automap toggles so keypress won't deactivate it again; Made FrameCount in Demos aligned to the Dropframe condition; Added KEy to ttoggle playback text off; Gracefully exit demo code if demo is corrupt; Removed that new percent counter because many old demos seem to have corrupted last frames; Closing endlevel data file if IFF error so the mission still can be freed; Fixed Cruising for keyboard which was not aligned to FPS correctly; Used mouse delta scaling in kconfig.c instead of mouse.c to not screw up when delta is requested in non-ingame situations - it actually belongs to the controls IMHO; Now support up to 8 joysticks; Changed some leftover malloc's to d_malloc and free to d_free
2008-10-16 17:27:02 +00:00
#define LEAVE_TIME 0x4000 //how long until we decide key is down (Used to be 0x4000)
2006-03-20 16:43:15 +00:00
//deal with rear view - switch it on, or off, or whatever
void check_rear_view()
{
static int leave_mode;
static fix entry_time;
if (Newdemo_state == ND_STATE_PLAYBACK)
return;
if ( Controls.rear_view_down_count ) { //key/button has gone down
2006-03-20 16:43:15 +00:00
if (Rear_view) {
Rear_view = 0;
if (PlayerCfg.CockpitMode[1]==CM_REAR_VIEW) {
select_cockpit(PlayerCfg.CockpitMode[0]);
2006-03-20 16:43:15 +00:00
}
if (Newdemo_state == ND_STATE_RECORDING)
newdemo_record_restore_rearview();
}
else {
Rear_view = 1;
leave_mode = 0; //means wait for another key
entry_time = timer_get_fixed_seconds();
if (PlayerCfg.CockpitMode[1] == CM_FULL_COCKPIT) {
2006-03-20 16:43:15 +00:00
select_cockpit(CM_REAR_VIEW);
}
if (Newdemo_state == ND_STATE_RECORDING)
newdemo_record_rearview();
}
}
else
if (Controls.rear_view_down_state) {
if (leave_mode == 0 && (timer_get_fixed_seconds() - entry_time) > LEAVE_TIME)
2006-03-20 16:43:15 +00:00
leave_mode = 1;
}
else
{
2006-03-20 16:43:15 +00:00
if (leave_mode==1 && Rear_view) {
Rear_view = 0;
if (PlayerCfg.CockpitMode[1]==CM_REAR_VIEW) {
select_cockpit(PlayerCfg.CockpitMode[0]);
2006-03-20 16:43:15 +00:00
}
if (Newdemo_state == ND_STATE_RECORDING)
newdemo_record_restore_rearview();
}
}
}
void reset_rear_view(void)
{
if (Rear_view) {
if (Newdemo_state == ND_STATE_RECORDING)
newdemo_record_restore_rearview();
}
Rear_view = 0;
select_cockpit(PlayerCfg.CockpitMode[0]);
2006-03-20 16:43:15 +00:00
}
int Config_menu_flag;
extern int Laser_rapid_fire, Ugly_robot_cheat;
extern void do_lunacy_on(), do_lunacy_off();
extern int Physics_cheat_flag;
2006-03-20 16:43:15 +00:00
extern int cheat_enable_index;
extern int cheat_wowie_index;
extern int cheat_allkeys_index;
extern int cheat_invuln_index;
extern int cheat_cloak_index;
extern int cheat_shield_index;
extern int cheat_warp_index;
extern int cheat_astral_index;
extern int cheat_turbomode_index;
extern int cheat_wowie2_index;
extern int cheat_newlife_index;
extern int cheat_exitpath_index;
extern int cheat_robotpause_index;
2006-03-20 16:43:15 +00:00
void game_disable_cheats()
{
Game_turbo_mode = 0;
Cheats_enabled=0;
do_lunacy_off();
Laser_rapid_fire = 0;
Ugly_robot_cheat = 0;
Physics_cheat_flag = 0;
}
// game_setup()
// ----------------------------------------------------------------------------
int game_handler(window *wind, d_event *event, void *data);
window *game_setup(void)
{
window *game_wind;
do_lunacy_on(); // Copy values for insane into copy buffer in ai.c
do_lunacy_off(); // Restore true insane mode.
2006-03-20 16:43:15 +00:00
Game_aborted = 0;
PlayerCfg.CockpitMode[1] = PlayerCfg.CockpitMode[0];
last_drawn_cockpit = -1; // Force cockpit to redraw next time a frame renders.
2006-03-20 16:43:15 +00:00
Endlevel_sequence = 0;
cheat_enable_index = 0;
cheat_wowie_index = cheat_allkeys_index = cheat_invuln_index = cheat_cloak_index = cheat_shield_index = cheat_warp_index = cheat_astral_index = 0;
cheat_turbomode_index = cheat_wowie2_index = 0;
set_screen_mode(SCREEN_GAME);
game_wind = window_create(&grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, game_handler, NULL);
if (!game_wind)
return NULL;
2006-03-20 16:43:15 +00:00
reset_palette_add();
set_warn_func(game_show_warning);
init_cockpit();
init_gauges();
#ifdef EDITOR
if (Segments[ConsoleObject->segnum].segnum == -1) //segment no longer exists
obj_relink( ConsoleObject-Objects, SEG_PTR_2_NUM(Cursegp) );
2006-03-20 16:43:15 +00:00
if (!check_obj_seg(ConsoleObject))
move_player_2_segment(Cursegp,Curside);
#endif
2006-03-20 16:43:15 +00:00
Viewer = ConsoleObject;
fly_init(ConsoleObject);
Game_suspended = 0;
reset_time();
FrameTime = 0; //make first frame zero
#ifdef EDITOR
if (Current_level_num == 0) { //not a real level
2006-03-20 16:43:15 +00:00
init_player_stats_game();
init_ai_objects();
}
#endif
2006-03-20 16:43:15 +00:00
fix_object_segs();
game_flush_inputs();
return game_wind;
}
void game_render_frame();
window *Game_wind = NULL;
// Event handler for the game
int game_handler(window *wind, d_event *event, void *data)
{
data = data;
2006-03-20 16:43:15 +00:00
switch (event->type)
{
case EVENT_IDLE:
// GAME LOOP!
Config_menu_flag = 0;
ReadControls(); // will have its own event(s) eventually
if (window_get_front() != wind)
break;
//see if redbook song needs to be restarted
RBACheckFinishedHook(); // Handle RedBook Audio Repeating.
if (Config_menu_flag) {
if (!(Game_mode&GM_MULTI)) palette_save();
do_options_menu();
if (!(Game_mode&GM_MULTI)) palette_restore();
}
if (!Game_wind)
break;
if ( (Function_mode != FMODE_GAME ) && (Newdemo_state != ND_STATE_PLAYBACK ) && (Function_mode!=FMODE_EDITOR))
{
int choice, fmode;
fmode = Function_mode;
Function_mode = FMODE_GAME;
choice=nm_messagebox( NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_GAME );
Function_mode = fmode;
if (choice != 0)
Function_mode = FMODE_GAME;
}
if (Function_mode != FMODE_GAME)
window_close(wind);
return 0;
break;
case EVENT_WINDOW_DRAW:
if (!time_paused)
{
calc_frame_time();
GameProcessFrame();
}
if (!Automap_active) // efficiency hack
{
if (force_cockpit_redraw) { //screen need redrawing?
init_cockpit();
force_cockpit_redraw=0;
}
game_render_frame();
}
break;
case EVENT_WINDOW_CLOSE:
if (Function_mode == FMODE_GAME)
Function_mode = FMODE_MENU;
digi_stop_all();
if ( (Newdemo_state == ND_STATE_RECORDING) || (Newdemo_state == ND_STATE_PAUSED) )
newdemo_stop_recording();
#ifdef NETWORK
multi_leave_game();
#endif
if ( Newdemo_state == ND_STATE_PLAYBACK )
newdemo_stop_playback();
clear_warn_func(game_show_warning); //don't use this func anymore
game_disable_cheats();
Game_wind = NULL;
return 0; // continue closing
break;
default:
return 0;
break;
}
2006-03-20 16:43:15 +00:00
return 1;
}
2006-03-20 16:43:15 +00:00
// ------------------------------------------------------------------------------------
//this function is the game. called when game mode selected. runs until
//editor mode or exit selected
void game()
{
Game_wind = game_setup();
2006-03-20 16:43:15 +00:00
while (Game_wind)
event_process();
2006-03-20 16:43:15 +00:00
}
//called at the end of the program
void close_game()
{
if (VR_offscreen_buffer) {
gr_free_canvas(VR_offscreen_buffer);
VR_offscreen_buffer = NULL;
}
close_gauges();
2006-03-20 16:43:15 +00:00
restore_effect_bitmap_icons();
clear_warn_func(game_show_warning); //don't use this func anymore
}
#ifdef EDITOR
extern void player_follow_path(object *objp);
extern void check_create_player_path(void);
2006-03-20 16:43:15 +00:00
#endif
extern int Do_appearance_effect;
2006-03-20 16:43:15 +00:00
void GameProcessFrame(void)
2006-03-20 16:43:15 +00:00
{
update_player_stats();
diminish_palette_towards_normal(); // Should leave palette effect up for as long as possible by putting right before render.
do_cloak_stuff();
do_invulnerable_stuff();
remove_obsolete_stuck_objects();
2006-03-20 16:43:15 +00:00
#ifdef EDITOR
check_create_player_path();
player_follow_path(ConsoleObject);
2006-03-20 16:43:15 +00:00
#endif
#ifdef NETWORK
if (Game_mode & GM_MULTI)
multi_do_frame();
#endif
2006-03-20 16:43:15 +00:00
dead_player_frame();
if (Newdemo_state != ND_STATE_PLAYBACK)
do_controlcen_dead_frame();
2006-03-20 16:43:15 +00:00
digi_sync_sounds();
2006-03-20 16:43:15 +00:00
if (Endlevel_sequence) {
do_endlevel_frame();
powerup_grab_cheat_all();
do_special_effects();
return; //skip everything else
}
2006-03-20 16:43:15 +00:00
if (Newdemo_state != ND_STATE_PLAYBACK)
do_exploding_wall_frame();
if ((Newdemo_state != ND_STATE_PLAYBACK) || (Newdemo_vcr_state != ND_STATE_PAUSED)) {
do_special_effects();
wall_frame_process();
triggers_frame_process();
}
2006-03-20 16:43:15 +00:00
if (Control_center_destroyed) {
if (Newdemo_state==ND_STATE_RECORDING )
newdemo_record_control_center_destroyed();
}
2006-03-20 16:43:15 +00:00
flash_frame();
if ( Newdemo_state == ND_STATE_PLAYBACK ) {
newdemo_playback_one_frame();
if ( Newdemo_state != ND_STATE_PLAYBACK ) {
if (Game_wind)
window_close(Game_wind); // Go back to menu
return;
}
}
else
{ // Note the link to above!
Players[Player_num].homing_object_dist = -1; // Assume not being tracked. Laser_do_weapon_sequence modifies this.
object_move_all();
powerup_grab_cheat_all();
2006-03-20 16:43:15 +00:00
if (Endlevel_sequence) //might have been started during move
return;
2006-03-20 16:43:15 +00:00
fuelcen_update_all();
do_ai_frame_all();
2006-03-20 16:43:15 +00:00
if (allowed_to_fire_laser())
FireLaser(); // Fire Laser!
2006-03-20 16:43:15 +00:00
if (Auto_fire_fusion_cannon_time) {
if (Primary_weapon != FUSION_INDEX)
Auto_fire_fusion_cannon_time = 0;
else if (GameTime + FrameTime/2 >= Auto_fire_fusion_cannon_time) {
Auto_fire_fusion_cannon_time = 0;
Global_laser_firing_count = 1;
} else if (FixedStep & EPS20) {
vms_vector rand_vec;
fix bump_amount;
2006-03-20 16:43:15 +00:00
Global_laser_firing_count = 0;
2006-03-20 16:43:15 +00:00
ConsoleObject->mtype.phys_info.rotvel.x += (d_rand() - 16384)/8;
ConsoleObject->mtype.phys_info.rotvel.z += (d_rand() - 16384)/8;
2006-03-20 16:43:15 +00:00
make_random_vector(&rand_vec);
2006-03-20 16:43:15 +00:00
bump_amount = F1_0*4;
2006-03-20 16:43:15 +00:00
if (Fusion_charge > F1_0*2)
bump_amount = Fusion_charge*4;
2006-03-20 16:43:15 +00:00
bump_one_object(ConsoleObject, &rand_vec, bump_amount);
2006-03-20 16:43:15 +00:00
}
else
{
2006-03-20 16:43:15 +00:00
Global_laser_firing_count = 0;
}
2006-03-20 16:43:15 +00:00
}
if (Global_laser_firing_count)
Global_laser_firing_count -= do_laser_firing_player();
if (Global_laser_firing_count < 0)
Global_laser_firing_count = 0;
}
2006-03-20 16:43:15 +00:00
if (Do_appearance_effect) {
create_player_appearance_effect(ConsoleObject);
Do_appearance_effect = 0;
}
}
// -----------------------------------------------------------------------------
// Fire Laser: Registers a laser fire, and performs special stuff for the fusion
// cannon.
void FireLaser()
{
Global_laser_firing_count = Weapon_info[Primary_weapon_to_weapon_info[Primary_weapon]].fire_count * (Controls.fire_primary_state || Controls.fire_primary_down_count);
if ((Primary_weapon == FUSION_INDEX) && (Global_laser_firing_count)) {
if ((Players[Player_num].energy < F1_0*2) && (Auto_fire_fusion_cannon_time == 0)) {
Global_laser_firing_count = 0;
} else {
if (Fusion_charge == 0)
Players[Player_num].energy -= F1_0*2;
Fusion_charge += FrameTime;
Players[Player_num].energy -= FrameTime;
if (Players[Player_num].energy <= 0) {
Players[Player_num].energy = 0;
Auto_fire_fusion_cannon_time = GameTime -1; // Fire now!
} else
Auto_fire_fusion_cannon_time = GameTime + FrameTime/2 + 1; // Fire the fusion cannon at this time in the future.
if (Fusion_charge < F1_0*2)
PALETTE_FLASH_ADD(Fusion_charge >> 11, 0, Fusion_charge >> 11);
else
PALETTE_FLASH_ADD(Fusion_charge >> 11, Fusion_charge >> 11, 0);
if (GameTime < Fusion_last_sound_time) //gametime has wrapped
Fusion_next_sound_time = Fusion_last_sound_time = GameTime;
if (Fusion_next_sound_time < GameTime) {
if (Fusion_charge > F1_0*2) {
digi_play_sample( 11, F1_0 );
#ifdef NETWORK
if(Game_mode & GM_MULTI)
multi_send_play_sound(11, F1_0);
#endif
apply_damage_to_player(ConsoleObject, ConsoleObject, d_rand() * 4);
} else {
create_awareness_event(ConsoleObject, PA_WEAPON_ROBOT_COLLISION);
digi_play_sample( SOUND_FUSION_WARMUP, F1_0 );
#ifdef NETWORK
if (Game_mode & GM_MULTI)
multi_send_play_sound(SOUND_FUSION_WARMUP, F1_0);
#endif
}
Fusion_last_sound_time = GameTime;
Fusion_next_sound_time = GameTime + F1_0/8 + d_rand()/4;
}
}
}
}
2006-03-20 16:43:15 +00:00
// -------------------------------------------------------------------------------------------------------
// If player is close enough to objnum, which ought to be a powerup, pick it up!
// This could easily be made difficulty level dependent.
void powerup_grab_cheat(object *player, int objnum)
{
fix powerup_size;
fix player_size;
fix dist;
Assert(Objects[objnum].type == OBJ_POWERUP);
powerup_size = Objects[objnum].size;
player_size = player->size;
dist = vm_vec_dist_quick(&Objects[objnum].pos, &player->pos);
if ((dist < 2*(powerup_size + player_size)) && !(Objects[objnum].flags & OF_SHOULD_BE_DEAD)) {
vms_vector collision_point;
vm_vec_avg(&collision_point, &Objects[objnum].pos, &player->pos);
collide_player_and_powerup(player, &Objects[objnum], &collision_point);
}
}
// -------------------------------------------------------------------------------------------------------
// Make it easier to pick up powerups.
// For all powerups in this segment, pick them up at up to twice pickuppable distance based on dot product
// from player to powerup and player's forward vector.
// This has the effect of picking them up more easily left/right and up/down, but not making them disappear
// way before the player gets there.
void powerup_grab_cheat_all(void)
{
segment *segp;
int objnum;
2006-03-20 16:43:15 +00:00
segp = &Segments[ConsoleObject->segnum];
objnum = segp->objects;
while (objnum != -1) {
if (Objects[objnum].type == OBJ_POWERUP)
powerup_grab_cheat(ConsoleObject, objnum);
objnum = Objects[objnum].next;
}
}
int Last_level_path_created = -1;
#ifdef SHOW_EXIT_PATH
// ------------------------------------------------------------------------------------------------------------------
// Create path for player from current segment to goal segment.
// Return true if path created, else return false.
int mark_player_path_to_segment(int segnum)
{
int i;
object *objp = ConsoleObject;
2006-03-20 16:43:15 +00:00
short player_path_length=0;
int player_hide_index=-1;
if (Last_level_path_created == Current_level_num) {
return 0;
}
Last_level_path_created = Current_level_num;
if (create_path_points(objp, objp->segnum, segnum, Point_segs_free_ptr, &player_path_length, 100, 0, 0, -1) == -1) {
return 0;
}
player_hide_index = Point_segs_free_ptr - Point_segs;
Point_segs_free_ptr += player_path_length;
if (Point_segs_free_ptr - Point_segs + MAX_PATH_LENGTH*2 > MAX_POINT_SEGS) {
ai_reset_all_paths();
return 0;
}
for (i=1; i<player_path_length; i++) {
int segnum, objnum;
vms_vector seg_center;
object *obj;
segnum = Point_segs[player_hide_index+i].segnum;
seg_center = Point_segs[player_hide_index+i].point;
objnum = obj_create( OBJ_POWERUP, POW_ENERGY, segnum, &seg_center, &vmd_identity_matrix, Powerup_info[POW_ENERGY].size, CT_POWERUP, MT_NONE, RT_POWERUP);
if (objnum == -1) {
Int3(); // Unable to drop energy powerup for path
2006-03-20 16:43:15 +00:00
return 1;
}
obj = &Objects[objnum];
obj->rtype.vclip_info.vclip_num = Powerup_info[obj->id].vclip_num;
obj->rtype.vclip_info.frametime = Vclip[obj->rtype.vclip_info.vclip_num].frame_time;
obj->rtype.vclip_info.framenum = 0;
obj->lifeleft = F1_0*100 + d_rand() * 4;
}
2006-03-20 16:43:15 +00:00
return 1;
}
// Return true if it happened, else return false.
int create_special_path(void)
{
int i,j;
// ---------- Find exit doors ----------
for (i=0; i<=Highest_segment_index; i++)
for (j=0; j<MAX_SIDES_PER_SEGMENT; j++)
if (Segments[i].children[j] == -2) {
return mark_player_path_to_segment(i);
}
return 0;
}
2006-03-20 16:43:15 +00:00
#endif
#ifndef RELEASE
int Max_obj_count_mike = 0;
// Shows current number of used objects.
void show_free_objects(void)
{
if (!(FrameCount & 8)) {
int i;
int count=0;
for (i=0; i<=Highest_object_index; i++)
if (Objects[i].type != OBJ_NONE)
count++;
if (count > Max_obj_count_mike) {
Max_obj_count_mike = count;
}
}
}
#endif