From 54f533700cf4bf181724d9ee6e12da74e5aff1fb Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Sat, 27 Jul 2002 04:39:23 +0000 Subject: [PATCH] portabilization --- cfile/cfile.c | 8 + include/cfile.h | 2 + main/cntrlcen.c | 18 +- main/cntrlcen.h | 13 +- main/gamesave.c | 539 ++++++++++++++---------------------------------- main/switch.c | 59 +++++- main/switch.h | 55 ++++- main/wall.c | 84 +++++++- main/wall.h | 133 ++++++++---- 9 files changed, 476 insertions(+), 435 deletions(-) diff --git a/cfile/cfile.c b/cfile/cfile.c index ad310441..2baca72d 100644 --- a/cfile/cfile.c +++ b/cfile/cfile.c @@ -497,3 +497,11 @@ void cfile_read_angvec(vms_angvec *v, CFILE *file) v->b = cfile_read_fixang(file); v->h = cfile_read_fixang(file); } + +void cfile_read_matrix(vms_matrix *m,CFILE *file) +{ + cfile_read_vector(&m->rvec,file); + cfile_read_vector(&m->uvec,file); + cfile_read_vector(&m->fvec,file); +} + diff --git a/include/cfile.h b/include/cfile.h index 25e45321..a2f747f6 100644 --- a/include/cfile.h +++ b/include/cfile.h @@ -58,8 +58,10 @@ int cfile_read_int(CFILE *file); short cfile_read_short(CFILE *file); byte cfile_read_byte(CFILE *file); fix cfile_read_fix(CFILE *file); +fixang cfile_read_fixang(CFILE *file); void cfile_read_vector(vms_vector *v, CFILE *file); void cfile_read_angvec(vms_angvec *v, CFILE *file); +void cfile_read_matrix(vms_matrix *v, CFILE *file); extern char AltHogDir[]; extern char AltHogdir_initialized; diff --git a/main/cntrlcen.c b/main/cntrlcen.c index 3001e207..1f7c738c 100644 --- a/main/cntrlcen.c +++ b/main/cntrlcen.c @@ -16,7 +16,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #endif #ifdef RCS -static char rcsid[] = "$Id: cntrlcen.c,v 1.4 2002-07-26 09:22:05 btb Exp $"; +static char rcsid[] = "$Id: cntrlcen.c,v 1.5 2002-07-27 04:39:23 btb Exp $"; #endif #ifdef WINDOWS @@ -513,7 +513,7 @@ void special_reactor_stuff(void) extern void reactor_read(reactor *r, CFILE *fp) { int i; - + r->model_num = cfile_read_int(fp); r->n_guns = cfile_read_int(fp); for (i = 0; i < MAX_CONTROLCEN_GUNS; i++) @@ -521,3 +521,17 @@ extern void reactor_read(reactor *r, CFILE *fp) for (i = 0; i < MAX_CONTROLCEN_GUNS; i++) cfile_read_vector(&(r->gun_dirs[i]), fp); } + +/* + * reads a control_center_triggers structure from a CFILE + */ +extern void control_center_triggers_read(control_center_triggers *cct, CFILE *fp) +{ + int i; + + cct->num_links = cfile_read_short(fp); + for (i=0; iseg[i] = cfile_read_short( fp ); + for (i=0; iside[i] = cfile_read_short( fp ); +} diff --git a/main/cntrlcen.h b/main/cntrlcen.h index 7143f9c9..07e04b81 100644 --- a/main/cntrlcen.h +++ b/main/cntrlcen.h @@ -26,10 +26,10 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #define MAX_CONTROLCEN_LINKS 10 typedef struct control_center_triggers { - short num_links; - short seg[MAX_CONTROLCEN_LINKS]; - short side[MAX_CONTROLCEN_LINKS]; -} __pack__ control_center_triggers; + short num_links; + short seg[MAX_CONTROLCEN_LINKS]; + short side[MAX_CONTROLCEN_LINKS]; +} control_center_triggers; extern control_center_triggers ControlCenterTriggers; @@ -79,4 +79,9 @@ extern int Reactor_strength; */ extern void reactor_read(reactor *r, CFILE *fp); +/* + * reads a control_center_triggers structure from a CFILE + */ +extern void control_center_triggers_read(control_center_triggers *cct, CFILE *fp); + #endif diff --git a/main/gamesave.c b/main/gamesave.c index d45eba3a..61641616 100644 --- a/main/gamesave.c +++ b/main/gamesave.c @@ -1,3 +1,4 @@ +/* $Id $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -12,26 +13,18 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. */ /* - * $Source: /cvs/cvsroot/d2x/main/gamesave.c,v $ - * $Revision: 1.6 $ - * $Author: bradleyb $ - * $Date: 2001-11-14 09:34:32 $ * * Save game information * - * $Log: not supported by cvs2svn $ * */ #ifdef HAVE_CONFIG_H #include #endif -#ifdef HAVE_CONFIG_H -#include -#endif #ifdef RCS -char gamesave_rcsid[] = "$Id: gamesave.c,v 1.6 2001-11-14 09:34:32 bradleyb Exp $"; +char gamesave_rcsid[] = "$Id: gamesave.c,v 1.7 2002-07-27 04:39:23 btb Exp $"; #endif #include @@ -94,77 +87,6 @@ char Gamesave_current_filename[128]; #define MENU_CURSOR_X_MIN MENU_X #define MENU_CURSOR_X_MAX MENU_X+6 -//Start old wall structures - -typedef struct v16_wall { - byte type; // What kind of special wall. - byte flags; // Flags for the wall. - fix hps; // "Hit points" of the wall. - byte trigger; // Which trigger is associated with the wall. - byte clip_num; // Which animation associated with the wall. - byte keys; - } v16_wall; - -typedef struct v19_wall { - int segnum,sidenum; // Seg & side for this wall - byte type; // What kind of special wall. - byte flags; // Flags for the wall. - fix hps; // "Hit points" of the wall. - byte trigger; // Which trigger is associated with the wall. - byte clip_num; // Which animation associated with the wall. - byte keys; - int linked_wall; // number of linked wall - } v19_wall; - -typedef struct v19_door { - int n_parts; // for linked walls - short seg[2]; // Segment pointer of door. - short side[2]; // Side number of door. - short type[2]; // What kind of door animation. - fix open; // How long it has been open. -} v19_door; - -//End old wall structures - -//old trigger structs - -typedef struct v29_trigger { - byte type; - short flags; - fix value; - fix time; - byte link_num; - short num_links; - short seg[MAX_WALLS_PER_LINK]; - short side[MAX_WALLS_PER_LINK]; - } v29_trigger; - -typedef struct v30_trigger { - short flags; - byte num_links; - byte pad; //keep alignment - fix value; - fix time; - short seg[MAX_WALLS_PER_LINK]; - short side[MAX_WALLS_PER_LINK]; - } v30_trigger; - -//flags for V30 & below triggers -#define TRIGGER_CONTROL_DOORS 1 // Control Trigger -#define TRIGGER_SHIELD_DAMAGE 2 // Shield Damage Trigger -#define TRIGGER_ENERGY_DRAIN 4 // Energy Drain Trigger -#define TRIGGER_EXIT 8 // End of level Trigger -#define TRIGGER_ON 16 // Whether Trigger is active -#define TRIGGER_ONE_SHOT 32 // If Trigger can only be triggered once -#define TRIGGER_MATCEN 64 // Trigger for materialization centers -#define TRIGGER_ILLUSION_OFF 128 // Switch Illusion OFF trigger -#define TRIGGER_SECRET_EXIT 256 // Exit to secret level -#define TRIGGER_ILLUSION_ON 512 // Switch Illusion ON trigger -#define TRIGGER_UNLOCK_DOORS 1024 // Unlocks a door -#define TRIGGER_OPEN_WALL 2048 // Makes a wall open -#define TRIGGER_CLOSE_WALL 4096 // Makes a wall closed -#define TRIGGER_ILLUSORY_WALL 8192 // Makes a wall illusory - struct { ushort fileinfo_signature; ushort fileinfo_version; @@ -443,81 +365,6 @@ void verify_object( object * obj ) { } -static int read_int(CFILE *file) -{ - int i; - - if (cfread( &i, sizeof(i), 1, file) != 1) - Error( "Error reading int in gamesave.c" ); - - i = INTEL_INT(i); - return i; -} - -static fix read_fix(CFILE *file) -{ - fix f; - - if (cfread( &f, sizeof(f), 1, file) != 1) - Error( "Error reading fix in gamesave.c" ); - - f = (fix)INTEL_INT((int)f); - return f; -} - -static short read_short(CFILE *file) -{ - short s; - - if (cfread( &s, sizeof(s), 1, file) != 1) - Error( "Error reading short in gamesave.c" ); - - s = INTEL_SHORT(s); - return s; -} - -static short read_fixang(CFILE *file) -{ - fixang f; - - if (cfread( &f, sizeof(f), 1, file) != 1) - Error( "Error reading fixang in gamesave.c" ); - - f = (fixang)INTEL_SHORT((short)f); - return f; -} - -static byte read_byte(CFILE *file) -{ - byte b; - - if (cfread( &b, sizeof(b), 1, file) != 1) - Error( "Error reading byte in gamesave.c" ); - - return b; -} - -static void read_vector(vms_vector *v,CFILE *file) -{ - v->x = read_fix(file); - v->y = read_fix(file); - v->z = read_fix(file); -} - -static void read_matrix(vms_matrix *m,CFILE *file) -{ - read_vector(&m->rvec,file); - read_vector(&m->uvec,file); - read_vector(&m->fvec,file); -} - -static void read_angvec(vms_angvec *v,CFILE *file) -{ - v->p = read_fixang(file); - v->b = read_fixang(file); - v->h = read_fixang(file); -} - //static gs_skip(int len,CFILE *file) //{ // @@ -589,54 +436,54 @@ extern int multi_powerup_is_4pack(int); void read_object(object *obj,CFILE *f,int version) { - obj->type = read_byte(f); - obj->id = read_byte(f); + obj->type = cfile_read_byte(f); + obj->id = cfile_read_byte(f); if (obj->type == OBJ_CNTRLCEN && version<28) obj->id = 0; //used to be only one kind of reactor - obj->control_type = read_byte(f); - obj->movement_type = read_byte(f); - obj->render_type = read_byte(f); - obj->flags = read_byte(f); + obj->control_type = cfile_read_byte(f); + obj->movement_type = cfile_read_byte(f); + obj->render_type = cfile_read_byte(f); + obj->flags = cfile_read_byte(f); - obj->segnum = read_short(f); + obj->segnum = cfile_read_short(f); obj->attached_obj = -1; - read_vector(&obj->pos,f); - read_matrix(&obj->orient,f); + cfile_read_vector(&obj->pos,f); + cfile_read_matrix(&obj->orient,f); - obj->size = read_fix(f); - obj->shields = read_fix(f); + obj->size = cfile_read_fix(f); + obj->shields = cfile_read_fix(f); - read_vector(&obj->last_pos,f); + cfile_read_vector(&obj->last_pos,f); - obj->contains_type = read_byte(f); - obj->contains_id = read_byte(f); - obj->contains_count = read_byte(f); + obj->contains_type = cfile_read_byte(f); + obj->contains_id = cfile_read_byte(f); + obj->contains_count = cfile_read_byte(f); switch (obj->movement_type) { case MT_PHYSICS: - read_vector(&obj->mtype.phys_info.velocity,f); - read_vector(&obj->mtype.phys_info.thrust,f); + cfile_read_vector(&obj->mtype.phys_info.velocity,f); + cfile_read_vector(&obj->mtype.phys_info.thrust,f); - obj->mtype.phys_info.mass = read_fix(f); - obj->mtype.phys_info.drag = read_fix(f); - obj->mtype.phys_info.brakes = read_fix(f); + obj->mtype.phys_info.mass = cfile_read_fix(f); + obj->mtype.phys_info.drag = cfile_read_fix(f); + obj->mtype.phys_info.brakes = cfile_read_fix(f); - read_vector(&obj->mtype.phys_info.rotvel,f); - read_vector(&obj->mtype.phys_info.rotthrust,f); + cfile_read_vector(&obj->mtype.phys_info.rotvel,f); + cfile_read_vector(&obj->mtype.phys_info.rotthrust,f); - obj->mtype.phys_info.turnroll = read_fixang(f); - obj->mtype.phys_info.flags = read_short(f); + obj->mtype.phys_info.turnroll = cfile_read_fixang(f); + obj->mtype.phys_info.flags = cfile_read_short(f); break; case MT_SPINNING: - read_vector(&obj->mtype.spin_rate,f); + cfile_read_vector(&obj->mtype.spin_rate,f); break; case MT_NONE: @@ -651,19 +498,19 @@ void read_object(object *obj,CFILE *f,int version) case CT_AI: { int i; - obj->ctype.ai_info.behavior = read_byte(f); + obj->ctype.ai_info.behavior = cfile_read_byte(f); for (i=0;ictype.ai_info.flags[i] = read_byte(f); + obj->ctype.ai_info.flags[i] = cfile_read_byte(f); - obj->ctype.ai_info.hide_segment = read_short(f); - obj->ctype.ai_info.hide_index = read_short(f); - obj->ctype.ai_info.path_length = read_short(f); - obj->ctype.ai_info.cur_path_index = read_short(f); + obj->ctype.ai_info.hide_segment = cfile_read_short(f); + obj->ctype.ai_info.hide_index = cfile_read_short(f); + obj->ctype.ai_info.path_length = cfile_read_short(f); + obj->ctype.ai_info.cur_path_index = cfile_read_short(f); if (version <= 25) { - read_short(f); // obj->ctype.ai_info.follow_path_start_seg = - read_short(f); // obj->ctype.ai_info.follow_path_end_seg = + cfile_read_short(f); // obj->ctype.ai_info.follow_path_start_seg = + cfile_read_short(f); // obj->ctype.ai_info.follow_path_end_seg = } break; @@ -671,9 +518,9 @@ void read_object(object *obj,CFILE *f,int version) case CT_EXPLOSION: - obj->ctype.expl_info.spawn_time = read_fix(f); - obj->ctype.expl_info.delete_time = read_fix(f); - obj->ctype.expl_info.delete_objnum = read_short(f); + obj->ctype.expl_info.spawn_time = cfile_read_fix(f); + obj->ctype.expl_info.delete_time = cfile_read_fix(f); + obj->ctype.expl_info.delete_objnum = cfile_read_short(f); obj->ctype.expl_info.next_attach = obj->ctype.expl_info.prev_attach = obj->ctype.expl_info.attach_parent = -1; break; @@ -682,21 +529,21 @@ void read_object(object *obj,CFILE *f,int version) //do I really need to read these? Are they even saved to disk? - obj->ctype.laser_info.parent_type = read_short(f); - obj->ctype.laser_info.parent_num = read_short(f); - obj->ctype.laser_info.parent_signature = read_int(f); + obj->ctype.laser_info.parent_type = cfile_read_short(f); + obj->ctype.laser_info.parent_num = cfile_read_short(f); + obj->ctype.laser_info.parent_signature = cfile_read_int(f); break; case CT_LIGHT: - obj->ctype.light_info.intensity = read_fix(f); + obj->ctype.light_info.intensity = cfile_read_fix(f); break; case CT_POWERUP: if (version >= 25) - obj->ctype.powerup_info.count = read_int(f); + obj->ctype.powerup_info.count = cfile_read_int(f); else obj->ctype.powerup_info.count = 1; @@ -740,14 +587,14 @@ void read_object(object *obj,CFILE *f,int version) case RT_POLYOBJ: { int i,tmo; - obj->rtype.pobj_info.model_num = read_int(f); + obj->rtype.pobj_info.model_num = cfile_read_int(f); for (i=0;irtype.pobj_info.anim_angles[i],f); + cfile_read_angvec(&obj->rtype.pobj_info.anim_angles[i],f); - obj->rtype.pobj_info.subobj_flags = read_int(f); + obj->rtype.pobj_info.subobj_flags = cfile_read_int(f); - tmo = read_int(f); + tmo = cfile_read_int(f); #ifndef EDITOR obj->rtype.pobj_info.tmap_override = tmo; @@ -775,9 +622,9 @@ void read_object(object *obj,CFILE *f,int version) case RT_POWERUP: case RT_FIREBALL: - obj->rtype.vclip_info.vclip_num = read_int(f); - obj->rtype.vclip_info.frametime = read_fix(f); - obj->rtype.vclip_info.framenum = read_byte(f); + obj->rtype.vclip_info.vclip_num = cfile_read_int(f); + obj->rtype.vclip_info.frametime = cfile_read_fix(f); + obj->rtype.vclip_info.framenum = cfile_read_byte(f); break; @@ -1024,9 +871,9 @@ int load_game_data(CFILE *LoadFile) // if (cfread( &game_top_fileinfo, sizeof(game_top_fileinfo), 1, LoadFile) != 1) // Error( "Error reading game_top_fileinfo in gamesave.c" ); - game_top_fileinfo.fileinfo_signature = read_short(LoadFile); - game_top_fileinfo.fileinfo_version = read_short(LoadFile); - game_top_fileinfo.fileinfo_sizeof = read_int(LoadFile); + game_top_fileinfo.fileinfo_signature = cfile_read_short(LoadFile); + game_top_fileinfo.fileinfo_version = cfile_read_short(LoadFile); + game_top_fileinfo.fileinfo_sizeof = cfile_read_int(LoadFile); // Check signature if (game_top_fileinfo.fileinfo_signature != 0x6705) @@ -1043,44 +890,44 @@ int load_game_data(CFILE *LoadFile) // if (cfread( &game_fileinfo, game_top_fileinfo.fileinfo_sizeof, 1, LoadFile )!=1) // Error( "Error reading game_fileinfo in gamesave.c" ); - game_fileinfo.fileinfo_signature = read_short(LoadFile); - game_fileinfo.fileinfo_version = read_short(LoadFile); - game_fileinfo.fileinfo_sizeof = read_int(LoadFile); + game_fileinfo.fileinfo_signature = cfile_read_short(LoadFile); + game_fileinfo.fileinfo_version = cfile_read_short(LoadFile); + game_fileinfo.fileinfo_sizeof = cfile_read_int(LoadFile); for(i=0; i<15; i++) - game_fileinfo.mine_filename[i] = read_byte(LoadFile); - game_fileinfo.level = read_int(LoadFile); - game_fileinfo.player_offset = read_int(LoadFile); // Player info - game_fileinfo.player_sizeof = read_int(LoadFile); - game_fileinfo.object_offset = read_int(LoadFile); // Object info - game_fileinfo.object_howmany = read_int(LoadFile); - game_fileinfo.object_sizeof = read_int(LoadFile); - game_fileinfo.walls_offset = read_int(LoadFile); - game_fileinfo.walls_howmany = read_int(LoadFile); - game_fileinfo.walls_sizeof = read_int(LoadFile); - game_fileinfo.doors_offset = read_int(LoadFile); - game_fileinfo.doors_howmany = read_int(LoadFile); - game_fileinfo.doors_sizeof = read_int(LoadFile); - game_fileinfo.triggers_offset = read_int(LoadFile); - game_fileinfo.triggers_howmany = read_int(LoadFile); - game_fileinfo.triggers_sizeof = read_int(LoadFile); - game_fileinfo.links_offset = read_int(LoadFile); - game_fileinfo.links_howmany = read_int(LoadFile); - game_fileinfo.links_sizeof = read_int(LoadFile); - game_fileinfo.control_offset = read_int(LoadFile); - game_fileinfo.control_howmany = read_int(LoadFile); - game_fileinfo.control_sizeof = read_int(LoadFile); - game_fileinfo.matcen_offset = read_int(LoadFile); - game_fileinfo.matcen_howmany = read_int(LoadFile); - game_fileinfo.matcen_sizeof = read_int(LoadFile); + game_fileinfo.mine_filename[i] = cfile_read_byte(LoadFile); + game_fileinfo.level = cfile_read_int(LoadFile); + game_fileinfo.player_offset = cfile_read_int(LoadFile); // Player info + game_fileinfo.player_sizeof = cfile_read_int(LoadFile); + game_fileinfo.object_offset = cfile_read_int(LoadFile); // Object info + game_fileinfo.object_howmany = cfile_read_int(LoadFile); + game_fileinfo.object_sizeof = cfile_read_int(LoadFile); + game_fileinfo.walls_offset = cfile_read_int(LoadFile); + game_fileinfo.walls_howmany = cfile_read_int(LoadFile); + game_fileinfo.walls_sizeof = cfile_read_int(LoadFile); + game_fileinfo.doors_offset = cfile_read_int(LoadFile); + game_fileinfo.doors_howmany = cfile_read_int(LoadFile); + game_fileinfo.doors_sizeof = cfile_read_int(LoadFile); + game_fileinfo.triggers_offset = cfile_read_int(LoadFile); + game_fileinfo.triggers_howmany = cfile_read_int(LoadFile); + game_fileinfo.triggers_sizeof = cfile_read_int(LoadFile); + game_fileinfo.links_offset = cfile_read_int(LoadFile); + game_fileinfo.links_howmany = cfile_read_int(LoadFile); + game_fileinfo.links_sizeof = cfile_read_int(LoadFile); + game_fileinfo.control_offset = cfile_read_int(LoadFile); + game_fileinfo.control_howmany = cfile_read_int(LoadFile); + game_fileinfo.control_sizeof = cfile_read_int(LoadFile); + game_fileinfo.matcen_offset = cfile_read_int(LoadFile); + game_fileinfo.matcen_howmany = cfile_read_int(LoadFile); + game_fileinfo.matcen_sizeof = cfile_read_int(LoadFile); if (game_top_fileinfo.fileinfo_version >= 29) { - game_fileinfo.dl_indices_offset = read_int(LoadFile); - game_fileinfo.dl_indices_howmany = read_int(LoadFile); - game_fileinfo.dl_indices_sizeof = read_int(LoadFile); + game_fileinfo.dl_indices_offset = cfile_read_int(LoadFile); + game_fileinfo.dl_indices_howmany = cfile_read_int(LoadFile); + game_fileinfo.dl_indices_sizeof = cfile_read_int(LoadFile); - game_fileinfo.delta_light_offset = read_int(LoadFile); - game_fileinfo.delta_light_howmany = read_int(LoadFile); - game_fileinfo.delta_light_sizeof = read_int(LoadFile); + game_fileinfo.delta_light_offset = cfile_read_int(LoadFile); + game_fileinfo.delta_light_howmany = cfile_read_int(LoadFile); + game_fileinfo.delta_light_sizeof = cfile_read_int(LoadFile); } if (game_top_fileinfo.fileinfo_version >= 14) { //load mine filename @@ -1098,7 +945,7 @@ int load_game_data(CFILE *LoadFile) if (game_top_fileinfo.fileinfo_version >= 19) { //load pof names // cfread(&N_save_pof_names,2,1,LoadFile); - N_save_pof_names = read_short(LoadFile); + N_save_pof_names = cfile_read_short(LoadFile); cfread(Save_pof_names,N_save_pof_names,FILENAME_LEN,LoadFile); } @@ -1132,39 +979,14 @@ int load_game_data(CFILE *LoadFile) if (!cfseek( LoadFile, game_fileinfo.walls_offset,SEEK_SET )) { for (i=0;i= 20) { - - Assert(sizeof(Walls[i]) == game_fileinfo.walls_sizeof); - -// code to correctly read wall structure on mac. I'm assuming only v20 walls -// and up. -#ifndef MACINTOSH - if (cfread(&Walls[i], game_fileinfo.walls_sizeof, 1,LoadFile)!=1) - Error( "Error reading Walls[%d] in gamesave.c", i); -#else - Walls[i].segnum = read_int(LoadFile); - Walls[i].sidenum = read_int(LoadFile); - Walls[i].hps = read_fix(LoadFile); - Walls[i].linked_wall = read_int(LoadFile); - Walls[i].type = read_byte(LoadFile); - Walls[i].flags = read_byte(LoadFile); - Walls[i].state = read_byte(LoadFile); - Walls[i].trigger = read_byte(LoadFile); - Walls[i].clip_num = read_byte(LoadFile); - Walls[i].keys = read_byte(LoadFile); - Walls[i].controlling_trigger = read_byte(LoadFile); - Walls[i].cloak_value = read_byte(LoadFile); -#endif - } + if (game_top_fileinfo.fileinfo_version >= 20) + wall_read(&Walls[i], LoadFile); // v20 walls and up. else if (game_top_fileinfo.fileinfo_version >= 17) { v19_wall w; - Assert(sizeof(w) == game_fileinfo.walls_sizeof); + v19_wall_read(&w, LoadFile); - if (cfread(&w, game_fileinfo.walls_sizeof, 1,LoadFile)!=1) - Error( "Error reading Walls[%d] in gamesave.c", i); - - Walls[i].segnum = w.segnum; + Walls[i].segnum = w.segnum; Walls[i].sidenum = w.sidenum; Walls[i].linked_wall = w.linked_wall; @@ -1176,14 +998,10 @@ int load_game_data(CFILE *LoadFile) Walls[i].keys = w.keys; Walls[i].state = WALL_DOOR_CLOSED; - } - else { + } else { v16_wall w; - Assert(sizeof(w) == game_fileinfo.walls_sizeof); - - if (cfread(&w, game_fileinfo.walls_sizeof, 1,LoadFile)!=1) - Error( "Error reading Walls[%d] in gamesave.c", i); + v16_wall_read(&w, LoadFile); Walls[i].segnum = Walls[i].sidenum = Walls[i].linked_wall = -1; @@ -1207,31 +1025,13 @@ int load_game_data(CFILE *LoadFile) for (i=0;i= 20) { - - Assert(sizeof(ActiveDoors[i]) == game_fileinfo.doors_sizeof); - -// code to read doors for mac -- assume version 20 and greater for doors -#ifndef MACINTOSH - if (cfread(&ActiveDoors[i], game_fileinfo.doors_sizeof,1,LoadFile)!=1) - Error( "Error reading ActiveDoors[%d] in gamesave.c", i); -#else - ActiveDoors[i].n_parts = read_int(LoadFile); - ActiveDoors[i].front_wallnum[0] = read_short(LoadFile); - ActiveDoors[i].front_wallnum[1] = read_short(LoadFile); - ActiveDoors[i].back_wallnum[0] = read_short(LoadFile); - ActiveDoors[i].back_wallnum[1] = read_short(LoadFile); - ActiveDoors[i].time = read_fix(LoadFile); -#endif - } + if (game_top_fileinfo.fileinfo_version >= 20) + active_door_read(&ActiveDoors[i], LoadFile); // version 20 and up else { v19_door d; int p; - Assert(sizeof(d) == game_fileinfo.doors_sizeof); - - if (cfread(&d, game_fileinfo.doors_sizeof, 1,LoadFile)!=1) - Error( "Error reading Doors[%d] in gamesave.c", i); + v19_door_read(&d, LoadFile); ActiveDoors[i].n_parts = d.n_parts; @@ -1268,24 +1068,22 @@ int load_game_data(CFILE *LoadFile) if (game_top_fileinfo.fileinfo_version < 30) { v29_trigger trig29; int t; - - if (cfread(&trig29, game_fileinfo.triggers_sizeof,1,LoadFile)!=1) - Error( "Error reading Triggers[%d] in gamesave.c", i); - + + v29_trigger_read(&trig29, LoadFile); + trig.flags = trig29.flags; trig.num_links = trig29.num_links; trig.num_links = trig29.num_links; trig.value = trig29.value; trig.time = trig29.time; - + for (t=0;t -1) - { - if (!cfseek( LoadFile, game_fileinfo.control_offset,SEEK_SET )) { + if (!cfseek( LoadFile, game_fileinfo.control_offset,SEEK_SET )) for (i=0;i 1) { cfgets(Current_level_palette,sizeof(Current_level_palette),LoadFile); @@ -1760,26 +1531,26 @@ int load_level(char * filename_passed) } if (version >= 3) - Base_control_center_explosion_time = read_int(LoadFile); + Base_control_center_explosion_time = cfile_read_int(LoadFile); else Base_control_center_explosion_time = DEFAULT_CONTROL_CENTER_EXPLOSION_TIME; if (version >= 4) - Reactor_strength = read_int(LoadFile); + Reactor_strength = cfile_read_int(LoadFile); else Reactor_strength = -1; //use old defaults if (version >= 7) { - Num_flickering_lights = read_int(LoadFile); + Num_flickering_lights = cfile_read_int(LoadFile); #ifdef MACINTOSH Assert((Num_flickering_lights >= 0) && (Num_flickering_lights < MAX_FLICKERING_LIGHTS)); for (i = 0; i < Num_flickering_lights; i++) { - Flickering_lights[i].segnum = read_short(LoadFile); - Flickering_lights[i].sidenum = read_short(LoadFile); - Flickering_lights[i].mask = read_int(LoadFile); - Flickering_lights[i].timer = read_fix(LoadFile); - Flickering_lights[i].delay = read_fix(LoadFile); + Flickering_lights[i].segnum = cfile_read_short(LoadFile); + Flickering_lights[i].sidenum = cfile_read_short(LoadFile); + Flickering_lights[i].mask = cfile_read_int(LoadFile); + Flickering_lights[i].timer = cfile_read_fix(LoadFile); + Flickering_lights[i].delay = cfile_read_fix(LoadFile); } #else cfread(Flickering_lights,sizeof(*Flickering_lights),Num_flickering_lights,LoadFile); @@ -1797,16 +1568,16 @@ int load_level(char * filename_passed) Secret_return_orient.fvec.x = 0; Secret_return_orient.fvec.y = F1_0; Secret_return_orient.fvec.z = 0; Secret_return_orient.uvec.x = 0; Secret_return_orient.uvec.y = 0; Secret_return_orient.uvec.z = F1_0; } else { - Secret_return_segment = read_int(LoadFile); - Secret_return_orient.rvec.x = read_int(LoadFile); - Secret_return_orient.rvec.y = read_int(LoadFile); - Secret_return_orient.rvec.z = read_int(LoadFile); - Secret_return_orient.fvec.x = read_int(LoadFile); - Secret_return_orient.fvec.y = read_int(LoadFile); - Secret_return_orient.fvec.z = read_int(LoadFile); - Secret_return_orient.uvec.x = read_int(LoadFile); - Secret_return_orient.uvec.y = read_int(LoadFile); - Secret_return_orient.uvec.z = read_int(LoadFile); + Secret_return_segment = cfile_read_int(LoadFile); + Secret_return_orient.rvec.x = cfile_read_int(LoadFile); + Secret_return_orient.rvec.y = cfile_read_int(LoadFile); + Secret_return_orient.rvec.z = cfile_read_int(LoadFile); + Secret_return_orient.fvec.x = cfile_read_int(LoadFile); + Secret_return_orient.fvec.y = cfile_read_int(LoadFile); + Secret_return_orient.fvec.z = cfile_read_int(LoadFile); + Secret_return_orient.uvec.x = cfile_read_int(LoadFile); + Secret_return_orient.uvec.y = cfile_read_int(LoadFile); + Secret_return_orient.uvec.z = cfile_read_int(LoadFile); } cfseek(LoadFile,minedata_offset,SEEK_SET); diff --git a/main/switch.c b/main/switch.c index bfd9e88e..f9caa110 100644 --- a/main/switch.c +++ b/main/switch.c @@ -16,7 +16,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #endif #ifdef RCS -static char rcsid[] = "$Id: switch.c,v 1.5 2001-11-08 10:30:28 bradleyb Exp $"; +static char rcsid[] = "$Id: switch.c,v 1.6 2002-07-27 04:39:23 btb Exp $"; #endif #include @@ -635,7 +635,7 @@ void check_trigger(segment *seg, short side, short objnum,int shot) #endif } } - + void triggers_frame_process() { int i; @@ -645,3 +645,58 @@ void triggers_frame_process() Triggers[i].time -= FrameTime; } +/* + * reads a v29_trigger structure from a CFILE + */ +extern void v29_trigger_read(v29_trigger *t, CFILE *fp) +{ + int i; + + t->type = cfile_read_byte(fp); + t->flags = cfile_read_short(fp); + t->value = cfile_read_fix(fp); + t->time = cfile_read_fix(fp); + t->link_num = cfile_read_byte(fp); + t->num_links = cfile_read_short(fp); + for (i=0; iseg[i] = cfile_read_short(fp); + for (i=0; iside[i] = cfile_read_short(fp); +} + +/* + * reads a v30_trigger structure from a CFILE + */ +extern void v30_trigger_read(v30_trigger *t, CFILE *fp) +{ + int i; + + t->flags = cfile_read_short(fp); + t->num_links = cfile_read_byte(fp); + t->pad = cfile_read_byte(fp); + t->value = cfile_read_fix(fp); + t->time = cfile_read_fix(fp); + for (i=0; iseg[i] = cfile_read_short(fp); + for (i=0; iside[i] = cfile_read_short(fp); +} + +/* + * reads a trigger structure from a CFILE + */ +extern void trigger_read(trigger *t, CFILE *fp) +{ + int i; + + t->type = cfile_read_byte(fp); + t->flags = cfile_read_byte(fp); + t->num_links = cfile_read_byte(fp); + t->pad = cfile_read_byte(fp); + t->value = cfile_read_fix(fp); + t->time = cfile_read_fix(fp); + for (i=0; iseg[i] = cfile_read_short(fp); + for (i=0; iside[i] = cfile_read_short(fp); +} diff --git a/main/switch.h b/main/switch.h index 97d30880..49318ca0 100644 --- a/main/switch.h +++ b/main/switch.h @@ -46,6 +46,44 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #define TF_ONE_SHOT 2 // Only trigger once #define TF_DISABLED 4 // Set after one-shot fires +//old trigger structs + +typedef struct v29_trigger { + byte type; + short flags; + fix value; + fix time; + byte link_num; + short num_links; + short seg[MAX_WALLS_PER_LINK]; + short side[MAX_WALLS_PER_LINK]; +} v29_trigger; + +typedef struct v30_trigger { + short flags; + byte num_links; + byte pad; //keep alignment + fix value; + fix time; + short seg[MAX_WALLS_PER_LINK]; + short side[MAX_WALLS_PER_LINK]; +} v30_trigger; + +//flags for V30 & below triggers +#define TRIGGER_CONTROL_DOORS 1 // Control Trigger +#define TRIGGER_SHIELD_DAMAGE 2 // Shield Damage Trigger +#define TRIGGER_ENERGY_DRAIN 4 // Energy Drain Trigger +#define TRIGGER_EXIT 8 // End of level Trigger +#define TRIGGER_ON 16 // Whether Trigger is active +#define TRIGGER_ONE_SHOT 32 // If Trigger can only be triggered once +#define TRIGGER_MATCEN 64 // Trigger for materialization centers +#define TRIGGER_ILLUSION_OFF 128 // Switch Illusion OFF trigger +#define TRIGGER_SECRET_EXIT 256 // Exit to secret level +#define TRIGGER_ILLUSION_ON 512 // Switch Illusion ON trigger +#define TRIGGER_UNLOCK_DOORS 1024 // Unlocks a door +#define TRIGGER_OPEN_WALL 2048 // Makes a wall open +#define TRIGGER_CLOSE_WALL 4096 // Makes a wall closed +#define TRIGGER_ILLUSORY_WALL 8192 // Makes a wall illusory //the trigger really should have both a type & a flags, since most of the //flags bits are exclusive of the others. @@ -58,7 +96,7 @@ typedef struct trigger { fix time; short seg[MAX_WALLS_PER_LINK]; short side[MAX_WALLS_PER_LINK]; - } __pack__ trigger; +} trigger; extern trigger Triggers[MAX_TRIGGERS]; @@ -69,4 +107,19 @@ extern void check_trigger(segment *seg, short side, short objnum,int shot); extern int check_trigger_sub(int trigger_num, int player_num,int shot); extern void triggers_frame_process(); +/* + * reads a v29_trigger structure from a CFILE + */ +extern void v29_trigger_read(v29_trigger *t, CFILE *fp); + +/* + * reads a v30_trigger structure from a CFILE + */ +extern void v30_trigger_read(v30_trigger *t, CFILE *fp); + +/* + * reads a trigger structure from a CFILE + */ +extern void trigger_read(trigger *t, CFILE *fp); + #endif diff --git a/main/wall.c b/main/wall.c index fb6aedb0..2e386b8e 100644 --- a/main/wall.c +++ b/main/wall.c @@ -16,7 +16,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #endif #ifdef RCS -static char rcsid[] = "$Id: wall.c,v 1.5 2002-07-26 09:22:05 btb Exp $"; +static char rcsid[] = "$Id: wall.c,v 1.6 2002-07-27 04:39:23 btb Exp $"; #endif #include @@ -1550,9 +1550,9 @@ void blast_nearby_glass(object *objp, fix damage) void wclip_read(wclip *wc, CFILE *fp) { int i; - - wc->play_time = cfile_read_fix(fp);; - wc->num_frames = cfile_read_short(fp);; + + wc->play_time = cfile_read_fix(fp); + wc->num_frames = cfile_read_short(fp); for (i = 0; i < MAX_CLIP_FRAMES; i++) wc->frames[i] = cfile_read_short(fp); wc->open_sound = cfile_read_short(fp); @@ -1561,3 +1561,79 @@ void wclip_read(wclip *wc, CFILE *fp) cfread(wc->filename, 13, 1, fp); wc->pad = cfile_read_byte(fp); } + +/* + * reads a v16_wall structure from a CFILE + */ +extern void v16_wall_read(v16_wall *w, CFILE *fp) +{ + w->type = cfile_read_byte(fp); + w->flags = cfile_read_byte(fp); + w->hps = cfile_read_fix(fp); + w->trigger = cfile_read_byte(fp); + w->clip_num = cfile_read_byte(fp); + w->keys = cfile_read_byte(fp); +} + +/* + * reads a v19_wall structure from a CFILE + */ +extern void v19_wall_read(v19_wall *w, CFILE *fp) +{ + w->segnum = cfile_read_int(fp); + w->sidenum = cfile_read_int(fp); + w->type = cfile_read_byte(fp); + w->flags = cfile_read_byte(fp); + w->hps = cfile_read_fix(fp); + w->trigger = cfile_read_byte(fp); + w->clip_num = cfile_read_byte(fp); + w->keys = cfile_read_byte(fp); + w->linked_wall = cfile_read_int(fp); +} + +/* + * reads a wall structure from a CFILE + */ +extern void wall_read(wall *w, CFILE *fp) +{ + w->segnum = cfile_read_int(fp); + w->sidenum = cfile_read_int(fp); + w->hps = cfile_read_fix(fp); + w->linked_wall = cfile_read_int(fp); + w->type = cfile_read_byte(fp); + w->flags = cfile_read_byte(fp); + w->state = cfile_read_byte(fp); + w->trigger = cfile_read_byte(fp); + w->clip_num = cfile_read_byte(fp); + w->keys = cfile_read_byte(fp); + w->controlling_trigger = cfile_read_byte(fp); + w->cloak_value = cfile_read_byte(fp); +} + +/* + * reads a v19_door structure from a CFILE + */ +extern void v19_door_read(v19_door *d, CFILE *fp) +{ + d->n_parts = cfile_read_int(fp); + d->seg[0] = cfile_read_short(fp); + d->seg[1] = cfile_read_short(fp); + d->side[0] = cfile_read_short(fp); + d->side[1] = cfile_read_short(fp); + d->type[0] = cfile_read_short(fp); + d->type[1] = cfile_read_short(fp); + d->open = cfile_read_fix(fp); +} + +/* + * reads an active_door structure from a CFILE + */ +extern void active_door_read(active_door *ad, CFILE *fp) +{ + ad->n_parts = cfile_read_int(fp); + ad->front_wallnum[0] = cfile_read_short(fp); + ad->front_wallnum[1] = cfile_read_short(fp); + ad->back_wallnum[0] = cfile_read_short(fp); + ad->back_wallnum[1] = cfile_read_short(fp); + ad->time = cfile_read_fix(fp); +} diff --git a/main/wall.h b/main/wall.h index b298b258..0ffbef0f 100644 --- a/main/wall.h +++ b/main/wall.h @@ -78,7 +78,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #define WID_CLOAKED_FLAG 16 //@@// WALL_IS_DOORWAY return values F/R/RP -//@@#define WID_WALL 2 // 0/1/0 wall +//@@#define WID_WALL 2 // 0/1/0 wall //@@#define WID_TRANSPARENT_WALL 6 // 0/1/1 transparent wall //@@#define WID_ILLUSORY_WALL 3 // 1/1/0 illusory wall //@@#define WID_TRANSILLUSORY_WALL 7 // 1/1/1 transparent illusory wall @@ -88,55 +88,87 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #define MAX_STUCK_OBJECTS 32 typedef struct stuckobj { - short objnum, wallnum; - int signature; + short objnum, wallnum; + int signature; } stuckobj; +//Start old wall structures + +typedef struct v16_wall { + byte type; // What kind of special wall. + byte flags; // Flags for the wall. + fix hps; // "Hit points" of the wall. + byte trigger; // Which trigger is associated with the wall. + byte clip_num; // Which animation associated with the wall. + byte keys; +} v16_wall; + +typedef struct v19_wall { + int segnum,sidenum; // Seg & side for this wall + byte type; // What kind of special wall. + byte flags; // Flags for the wall. + fix hps; // "Hit points" of the wall. + byte trigger; // Which trigger is associated with the wall. + byte clip_num; // Which animation associated with the wall. + byte keys; + int linked_wall; // number of linked wall +} v19_wall; + +typedef struct v19_door { + int n_parts; // for linked walls + short seg[2]; // Segment pointer of door. + short side[2]; // Side number of door. + short type[2]; // What kind of door animation. + fix open; // How long it has been open. +} v19_door; + +//End old wall structures + typedef struct wall { - int segnum,sidenum; // Seg & side for this wall - fix hps; // "Hit points" of the wall. - int linked_wall; // number of linked wall - ubyte type; // What kind of special wall. - ubyte flags; // Flags for the wall. - ubyte state; // Opening, closing, etc. - byte trigger; // Which trigger is associated with the wall. - byte clip_num; // Which animation associated with the wall. - ubyte keys; // which keys are required - byte controlling_trigger; // which trigger causes something to happen here. Not like "trigger" above, which is the trigger on this wall. - // Note: This gets stuffed at load time in gamemine.c. Don't try to use it in the editor. You will be sorry! - byte cloak_value; // if this wall is cloaked, the fade value - } __pack__ wall; + int segnum,sidenum; // Seg & side for this wall + fix hps; // "Hit points" of the wall. + int linked_wall; // number of linked wall + ubyte type; // What kind of special wall. + ubyte flags; // Flags for the wall. + ubyte state; // Opening, closing, etc. + byte trigger; // Which trigger is associated with the wall. + byte clip_num; // Which animation associated with the wall. + ubyte keys; // which keys are required + byte controlling_trigger;// which trigger causes something to happen here. Not like "trigger" above, which is the trigger on this wall. + // Note: This gets stuffed at load time in gamemine.c. Don't try to use it in the editor. You will be sorry! + byte cloak_value; // if this wall is cloaked, the fade value +} wall; typedef struct active_door { - int n_parts; // for linked walls - short front_wallnum[2]; // front wall numbers for this door - short back_wallnum[2]; // back wall numbers for this door - fix time; // how long been opening, closing, waiting -} __pack__ active_door; + int n_parts; // for linked walls + short front_wallnum[2]; // front wall numbers for this door + short back_wallnum[2]; // back wall numbers for this door + fix time; // how long been opening, closing, waiting +} active_door; typedef struct cloaking_wall { - short front_wallnum; // front wall numbers for this door - short back_wallnum; // back wall numbers for this door - fix front_ls[4]; // front wall saved light values - fix back_ls[4]; // back wall saved light values - fix time; // how long been cloaking or decloaking + short front_wallnum; // front wall numbers for this door + short back_wallnum; // back wall numbers for this door + fix front_ls[4]; // front wall saved light values + fix back_ls[4]; // back wall saved light values + fix time; // how long been cloaking or decloaking } __pack__ cloaking_wall; //wall clip flags -#define WCF_EXPLODES 1 //door explodes when opening -#define WCF_BLASTABLE 2 //this is a blastable wall -#define WCF_TMAP1 4 //this uses primary tmap, not tmap2 -#define WCF_HIDDEN 8 //this uses primary tmap, not tmap2 +#define WCF_EXPLODES 1 //door explodes when opening +#define WCF_BLASTABLE 2 //this is a blastable wall +#define WCF_TMAP1 4 //this uses primary tmap, not tmap2 +#define WCF_HIDDEN 8 //this uses primary tmap, not tmap2 typedef struct { - fix play_time; - short num_frames; - short frames[MAX_CLIP_FRAMES]; - short open_sound; - short close_sound; - short flags; - char filename[13]; - char pad; + fix play_time; + short num_frames; + short frames[MAX_CLIP_FRAMES]; + short open_sound; + short close_sound; + short flags; + char filename[13]; + char pad; } wclip; extern char Wall_names[7][10]; @@ -228,4 +260,29 @@ void start_wall_decloak(segment *seg, int side); */ extern void wclip_read(wclip *wc, CFILE *fp); +/* + * reads a v16_wall structure from a CFILE + */ +extern void v16_wall_read(v16_wall *w, CFILE *fp); + +/* + * reads a v19_wall structure from a CFILE + */ +extern void v19_wall_read(v19_wall *w, CFILE *fp); + +/* + * reads a wall structure from a CFILE + */ +extern void wall_read(wall *w, CFILE *fp); + +/* + * reads a v19_door structure from a CFILE + */ +extern void v19_door_read(v19_door *d, CFILE *fp); + +/* + * reads an active_door structure from a CFILE + */ +extern void active_door_read(active_door *ad, CFILE *fp); + #endif -- 2.39.2