From: <av...@us...> - 2011-08-24 16:22:46
|
Revision: 3667 http://sc2.svn.sourceforge.net/sc2/?rev=3667&view=rev Author: avolkov Date: 2011-08-24 16:22:39 +0000 (Wed, 24 Aug 2011) Log Message: ----------- Various warning cleanups from Scott A. Colcord, bug #50; reworked Umgah ship code so as not to compare FRAMEs Modified Paths: -------------- trunk/sc2/ChangeLog trunk/sc2/build/msvc6/UrQuanMasters.dsp trunk/sc2/src/uqm/cleanup.c trunk/sc2/src/uqm/planets/Makeinfo trunk/sc2/src/uqm/planets/oval.c trunk/sc2/src/uqm/planets/solarsys.c trunk/sc2/src/uqm/races.h trunk/sc2/src/uqm/setupmenu.c trunk/sc2/src/uqm/ships/androsyn/androsyn.c trunk/sc2/src/uqm/ships/mmrnmhrm/mmrnmhrm.c trunk/sc2/src/uqm/ships/pkunk/pkunk.c trunk/sc2/src/uqm/ships/sis_ship/sis_ship.c trunk/sc2/src/uqm/ships/umgah/umgah.c Added Paths: ----------- trunk/sc2/src/uqm/planets/solarsys.h Modified: trunk/sc2/ChangeLog =================================================================== --- trunk/sc2/ChangeLog 2011-08-08 15:56:23 UTC (rev 3666) +++ trunk/sc2/ChangeLog 2011-08-24 16:22:39 UTC (rev 3667) @@ -1,4 +1,5 @@ Changes towards version 0.8: +- Various warnings cleanup (bug #50), from Scott A. Colcord - Fixed various Pkunk reincarnation and Shofixti Glory device interactions; Pkunk ditty plays in a simultaneous destruction (bug #666) - Alex - Preparing for linking with C++ code, from Scott A. Colcord Modified: trunk/sc2/build/msvc6/UrQuanMasters.dsp =================================================================== --- trunk/sc2/build/msvc6/UrQuanMasters.dsp 2011-08-08 15:56:23 UTC (rev 3666) +++ trunk/sc2/build/msvc6/UrQuanMasters.dsp 2011-08-24 16:22:39 UTC (rev 3667) @@ -2217,6 +2217,10 @@ # End Source File # Begin Source File +SOURCE=..\..\src\uqm\planets\solarsys.h +# End Source File +# Begin Source File + SOURCE=..\..\src\uqm\planets\sundata.h # End Source File # Begin Source File Modified: trunk/sc2/src/uqm/cleanup.c =================================================================== --- trunk/sc2/src/uqm/cleanup.c 2011-08-08 15:56:23 UTC (rev 3666) +++ trunk/sc2/src/uqm/cleanup.c 2011-08-24 16:22:39 UTC (rev 3667) @@ -25,15 +25,12 @@ #include "planets/lander.h" #include "starcon.h" #include "setup.h" +#include "planets/solarsys.h" #include "sounds.h" #include "libs/sndlib.h" #include "libs/vidlib.h" -// XXX: we do not current have a header for this prototype to live in -// should be something like solarsys.h -extern void FreeIPData (void); - void FreeKernel (void) { Modified: trunk/sc2/src/uqm/planets/Makeinfo =================================================================== --- trunk/sc2/src/uqm/planets/Makeinfo 2011-08-08 15:56:23 UTC (rev 3666) +++ trunk/sc2/src/uqm/planets/Makeinfo 2011-08-24 16:22:39 UTC (rev 3667) @@ -3,5 +3,5 @@ oval.c pl_stuff.c planets.c plangen.c pstarmap.c report.c roster.c scan.c solarsys.c surface.c" uqm_HFILES="elemdata.h generate.h lander.h lifeform.h plandata.h planets.h - scan.h sundata.h" + scan.h solarsys.h sundata.h" Modified: trunk/sc2/src/uqm/planets/oval.c =================================================================== --- trunk/sc2/src/uqm/planets/oval.c 2011-08-08 15:56:23 UTC (rev 3666) +++ trunk/sc2/src/uqm/planets/oval.c 2011-08-24 16:22:39 UTC (rev 3667) @@ -21,6 +21,7 @@ #include "libs/graphics/context.h" #include "libs/graphics/drawable.h" +#include "planets.h" #define NUM_QUADS 4 Modified: trunk/sc2/src/uqm/planets/solarsys.c =================================================================== --- trunk/sc2/src/uqm/planets/solarsys.c 2011-08-08 15:56:23 UTC (rev 3666) +++ trunk/sc2/src/uqm/planets/solarsys.c 2011-08-24 16:22:39 UTC (rev 3667) @@ -16,6 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "solarsys.h" #include "lander.h" #include "../colors.h" #include "../controls.h" Added: trunk/sc2/src/uqm/planets/solarsys.h =================================================================== --- trunk/sc2/src/uqm/planets/solarsys.h (rev 0) +++ trunk/sc2/src/uqm/planets/solarsys.h 2011-08-24 16:22:39 UTC (rev 3667) @@ -0,0 +1,34 @@ +//Copyright (C) 2011, Scott A. Colcord + +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef SOLARSYS_H +#define SOLARSYS_H + +#if defined(__cplusplus) +extern "C" { +#endif + +extern void LoadIPData (void); +extern void FreeIPData (void); + +#if defined(__cplusplus) +} +#endif + +#endif /* SOLARSYS_H */ + Property changes on: trunk/sc2/src/uqm/planets/solarsys.h ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/sc2/src/uqm/races.h =================================================================== --- trunk/sc2/src/uqm/races.h 2011-08-08 15:56:23 UTC (rev 3666) +++ trunk/sc2/src/uqm/races.h 2011-08-24 16:22:39 UTC (rev 3667) @@ -221,7 +221,7 @@ POSTPROCESS_FUNC *postprocess_func; INIT_WEAPON_FUNC *init_weapon_func; - intptr_t data; // private ship data, ship code owns this + void* data; // private ship data, ship code owns this void *CodeRef; }; Modified: trunk/sc2/src/uqm/setupmenu.c =================================================================== --- trunk/sc2/src/uqm/setupmenu.c 2011-08-08 15:56:23 UTC (rev 3666) +++ trunk/sc2/src/uqm/setupmenu.c 2011-08-24 16:22:39 UTC (rev 3667) @@ -766,7 +766,7 @@ } static int -count_widgets (const WIDGET **widgets) +count_widgets (WIDGET **widgets) { int count; Modified: trunk/sc2/src/uqm/ships/androsyn/androsyn.c =================================================================== --- trunk/sc2/src/uqm/ships/androsyn/androsyn.c 2011-08-08 15:56:23 UTC (rev 3666) +++ trunk/sc2/src/uqm/ships/androsyn/androsyn.c 2011-08-24 16:22:39 UTC (rev 3667) @@ -110,6 +110,46 @@ 0, /* CodeRef */ }; + +// Private per-instance ship data +typedef struct +{ + ElementCollisionFunc* collision_func; +} ANDROSYNTH_DATA; + +// Local typedef +typedef ANDROSYNTH_DATA CustomShipData_t; + +// Retrieve race-specific ship data from a race desc +static CustomShipData_t * +GetCustomShipData (RACE_DESC *pRaceDesc) +{ + return pRaceDesc->data; +} + +// Set the race-specific data in a race desc +// (Re)Allocates its own storage for the data. +static void +SetCustomShipData (RACE_DESC *pRaceDesc, const CustomShipData_t *data) +{ + if (pRaceDesc->data == data) + return; // no-op + + if (pRaceDesc->data) // Out with the old + { + HFree (pRaceDesc->data); + pRaceDesc->data = NULL; + } + + if (data) // In with the new + { + CustomShipData_t* newData = HMalloc (sizeof (*data)); + *newData = *data; + pRaceDesc->data = newData; + } +} + + #define BLAZER_DAMAGE 3 #define BLAZER_MASS 1 @@ -355,11 +395,14 @@ ElementPtr->mass_points = BLAZER_MASS; StarShipPtr->RaceDescPtr->characteristics.turn_wait = BLAZER_TURN_WAIT; + /* Save the current collision func because we were not the * ones who set it */ - StarShipPtr->RaceDescPtr->data = (intptr_t) - ElementPtr->collision_func; - ElementPtr->collision_func = blazer_collision; + { + const ANDROSYNTH_DATA shipData = { ElementPtr->collision_func }; + SetCustomShipData (StarShipPtr->RaceDescPtr, &shipData); + ElementPtr->collision_func = blazer_collision; + } } } @@ -426,8 +469,8 @@ StarShipPtr->RaceDescPtr->characteristics.special_wait; StarShipPtr->RaceDescPtr->characteristics.energy_regeneration = ENERGY_REGENERATION; ElementPtr->mass_points = SHIP_MASS; - ElementPtr->collision_func = (ElementCollisionFunc *) - StarShipPtr->RaceDescPtr->data; + ElementPtr->collision_func = + GetCustomShipData (StarShipPtr->RaceDescPtr)->collision_func; ElementPtr->next.image.farray = StarShipPtr->RaceDescPtr->ship_data.ship; ElementPtr->next.image.frame = @@ -463,11 +506,19 @@ StarShipPtr->cur_status_flags = cur_status_flags; } +static void +uninit_androsynth (RACE_DESC *pRaceDesc) +{ + SetCustomShipData (pRaceDesc, NULL); +} + + RACE_DESC* init_androsynth (void) { RACE_DESC *RaceDescPtr; + androsynth_desc.uninit_func = uninit_androsynth; androsynth_desc.preprocess_func = androsynth_preprocess; androsynth_desc.postprocess_func = androsynth_postprocess; androsynth_desc.init_weapon_func = initialize_bubble; Modified: trunk/sc2/src/uqm/ships/mmrnmhrm/mmrnmhrm.c =================================================================== --- trunk/sc2/src/uqm/ships/mmrnmhrm/mmrnmhrm.c 2011-08-08 15:56:23 UTC (rev 3666) +++ trunk/sc2/src/uqm/ships/mmrnmhrm/mmrnmhrm.c 2011-08-24 16:22:39 UTC (rev 3667) @@ -124,7 +124,42 @@ #define MISSILE_SPEED DISPLAY_TO_WORLD (20) #define TRACK_WAIT 5 +// Private per-instance ship data +typedef CHARACTERISTIC_STUFF MMRNMHRM_DATA; + +// Local typedef +typedef MMRNMHRM_DATA CustomShipData_t; + +// Retrieve race-specific ship data from a race desc +static CustomShipData_t * +GetCustomShipData (RACE_DESC *pRaceDesc) +{ + return pRaceDesc->data; +} + +// Set the race-specific data in a race desc +// (Re)Allocates its own storage for the data. static void +SetCustomShipData (RACE_DESC *pRaceDesc, const CustomShipData_t *data) +{ + if (pRaceDesc->data == data) + return; // no-op + + if (pRaceDesc->data) // Out with the old + { + HFree (pRaceDesc->data); + pRaceDesc->data = NULL; + } + + if (data) // In with the new + { + CustomShipData_t* newData = HMalloc (sizeof (*data)); + *newData = *data; + pRaceDesc->data = newData; + } +} + +static void missile_preprocess (ELEMENT *ElementPtr) { if (ElementPtr->turn_wait > 0) @@ -363,8 +398,8 @@ /* take care of transform effect */ if (ElementPtr->next.image.farray != ElementPtr->current.image.farray) { - CHARACTERISTIC_STUFF t; - CHARACTERISTIC_STUFF *otherwing_desc; + MMRNMHRM_DATA tempShipData; + MMRNMHRM_DATA *otherwing_desc; ProcessSound (SetAbsSoundIndex ( /* TRANSFORM */ @@ -373,11 +408,13 @@ StarShipPtr->weapon_counter = 0; /* Swap characteristics descriptors around */ - otherwing_desc = (CHARACTERISTIC_STUFF *) - StarShipPtr->RaceDescPtr->data; - t = *otherwing_desc; - *otherwing_desc = StarShipPtr->RaceDescPtr->characteristics; - StarShipPtr->RaceDescPtr->characteristics = t; + otherwing_desc = GetCustomShipData (StarShipPtr->RaceDescPtr); + if (!otherwing_desc) + return; // No ship data (?!) + + tempShipData = *otherwing_desc; + SetCustomShipData (StarShipPtr->RaceDescPtr, &StarShipPtr->RaceDescPtr->characteristics); + StarShipPtr->RaceDescPtr->characteristics = tempShipData; StarShipPtr->RaceDescPtr->cyborg_control.ManeuverabilityIndex = 0; if (ElementPtr->next.image.farray == StarShipPtr->RaceDescPtr->ship_data.special) @@ -444,8 +481,7 @@ static void uninit_mmrnmhrm (RACE_DESC *pRaceDesc) { - HFree ((void *)pRaceDesc->data); - pRaceDesc->data = 0; + SetCustomShipData (pRaceDesc, NULL); } RACE_DESC* @@ -454,7 +490,7 @@ RACE_DESC *RaceDescPtr; // The caller of this func will copy the struct static RACE_DESC new_mmrnmhrm_desc; - CHARACTERISTIC_STUFF *otherwing_desc; + MMRNMHRM_DATA otherwing_desc; mmrnmhrm_desc.uninit_func = uninit_mmrnmhrm; mmrnmhrm_desc.preprocess_func = mmrnmhrm_preprocess; @@ -464,20 +500,19 @@ new_mmrnmhrm_desc = mmrnmhrm_desc; - otherwing_desc = HMalloc (sizeof (*otherwing_desc)); - otherwing_desc->max_thrust = YWING_MAX_THRUST; - otherwing_desc->thrust_increment = YWING_THRUST_INCREMENT; - otherwing_desc->energy_regeneration = YWING_ENERGY_REGENERATION; - otherwing_desc->weapon_energy_cost = YWING_WEAPON_ENERGY_COST; - otherwing_desc->special_energy_cost = YWING_SPECIAL_ENERGY_COST; - otherwing_desc->energy_wait = YWING_ENERGY_WAIT; - otherwing_desc->turn_wait = YWING_TURN_WAIT; - otherwing_desc->thrust_wait = YWING_THRUST_WAIT; - otherwing_desc->weapon_wait = YWING_WEAPON_WAIT; - otherwing_desc->special_wait = YWING_SPECIAL_WAIT; - otherwing_desc->ship_mass = SHIP_MASS; + otherwing_desc.max_thrust = YWING_MAX_THRUST; + otherwing_desc.thrust_increment = YWING_THRUST_INCREMENT; + otherwing_desc.energy_regeneration = YWING_ENERGY_REGENERATION; + otherwing_desc.weapon_energy_cost = YWING_WEAPON_ENERGY_COST; + otherwing_desc.special_energy_cost = YWING_SPECIAL_ENERGY_COST; + otherwing_desc.energy_wait = YWING_ENERGY_WAIT; + otherwing_desc.turn_wait = YWING_TURN_WAIT; + otherwing_desc.thrust_wait = YWING_THRUST_WAIT; + otherwing_desc.weapon_wait = YWING_WEAPON_WAIT; + otherwing_desc.special_wait = YWING_SPECIAL_WAIT; + otherwing_desc.ship_mass = SHIP_MASS; - new_mmrnmhrm_desc.data = (intptr_t) otherwing_desc; + SetCustomShipData (&new_mmrnmhrm_desc, &otherwing_desc); RaceDescPtr = &new_mmrnmhrm_desc; Modified: trunk/sc2/src/uqm/ships/pkunk/pkunk.c =================================================================== --- trunk/sc2/src/uqm/ships/pkunk/pkunk.c 2011-08-08 15:56:23 UTC (rev 3666) +++ trunk/sc2/src/uqm/ships/pkunk/pkunk.c 2011-08-24 16:22:39 UTC (rev 3667) @@ -123,7 +123,39 @@ } PKUNK_DATA; +// Local typedef +typedef PKUNK_DATA CustomShipData_t; + +// Retrieve race-specific ship data from a race desc +static CustomShipData_t * +GetCustomShipData (RACE_DESC *pRaceDesc) +{ + return pRaceDesc->data; +} + +// Set the race-specific data in a race desc +// (Re)Allocates its own storage for the data. static void +SetCustomShipData (RACE_DESC *pRaceDesc, const CustomShipData_t *data) +{ + if (pRaceDesc->data == data) + return; // no-op + + if (pRaceDesc->data) // Out with the old + { + HFree (pRaceDesc->data); + pRaceDesc->data = NULL; + } + + if (data) // In with the new + { + CustomShipData_t* newData = HMalloc (sizeof (*data)); + *newData = *data; + pRaceDesc->data = newData; + } +} + +static void animate (ELEMENT *ElementPtr) { if (ElementPtr->turn_wait > 0) @@ -200,7 +232,7 @@ PKUNK_DATA *PkunkData; GetElementStarShip (ShipPtr, &StarShipPtr); - PkunkData = (PKUNK_DATA *) StarShipPtr->RaceDescPtr->data; + PkunkData = GetCustomShipData (StarShipPtr->RaceDescPtr); if (PkunkData->hPhoenix && (StarShipPtr->control & STANDARD_RATING)) { RemoveElement (PkunkData->hPhoenix); @@ -227,7 +259,7 @@ PKUNK_DATA *PkunkData; GetElementStarShip (ElementPtr, &StarShipPtr); - PkunkData = (PKUNK_DATA *) StarShipPtr->RaceDescPtr->data; + PkunkData = GetCustomShipData (StarShipPtr->RaceDescPtr); ElementPtr->state_flags = APPEARING | PLAYER_SHIP | IGNORE_SIMILAR; ElementPtr->mass_points = SHIP_MASS; @@ -301,7 +333,7 @@ ELEMENT *ShipPtr; GetElementStarShip (ElementPtr, &StarShipPtr); - PkunkData = (PKUNK_DATA *) StarShipPtr->RaceDescPtr->data; + PkunkData = GetCustomShipData (StarShipPtr->RaceDescPtr); if (StarShipPtr->RaceDescPtr->ship_info.crew_level != 0) { // Ship not dead yet. @@ -447,7 +479,7 @@ PKUNK_DATA *PkunkData; GetElementStarShip (ElementPtr, &StarShipPtr); - PkunkData = (PKUNK_DATA *) StarShipPtr->RaceDescPtr->data; + PkunkData = GetCustomShipData (StarShipPtr->RaceDescPtr); if (ElementPtr->state_flags & APPEARING) { HELEMENT hPhoenix = 0; @@ -572,8 +604,7 @@ static void uninit_pkunk (RACE_DESC *pRaceDesc) { - HFree ((void *)pRaceDesc->data); - pRaceDesc->data = 0; + SetCustomShipData (pRaceDesc, NULL); } RACE_DESC* @@ -582,6 +613,8 @@ RACE_DESC *RaceDescPtr; // The caller of this func will copy the struct static RACE_DESC new_pkunk_desc; + PKUNK_DATA empty_data; + memset (&empty_data, 0, sizeof (empty_data)); pkunk_desc.uninit_func = uninit_pkunk; pkunk_desc.preprocess_func = pkunk_preprocess; @@ -591,7 +624,7 @@ /* copy initial ship settings to the new descriptor */ new_pkunk_desc = pkunk_desc; - new_pkunk_desc.data = (intptr_t) HCalloc (sizeof (PKUNK_DATA)); + SetCustomShipData (&new_pkunk_desc, &empty_data); RaceDescPtr = &new_pkunk_desc; Modified: trunk/sc2/src/uqm/ships/sis_ship/sis_ship.c =================================================================== --- trunk/sc2/src/uqm/ships/sis_ship/sis_ship.c 2011-08-08 15:56:23 UTC (rev 3666) +++ trunk/sc2/src/uqm/ships/sis_ship/sis_ship.c 2011-08-24 16:22:39 UTC (rev 3667) @@ -136,10 +136,42 @@ const BYTE *DriveSlots); static void InitJetSlots (RACE_DESC *RaceDescPtr, const BYTE *JetSlots); -void uninit_sis (RACE_DESC *pRaceDesc); +static void uninit_sis (RACE_DESC *pRaceDesc); +// Local typedef +typedef SIS_DATA CustomShipData_t; + +// Retrieve race-specific ship data from a race desc +static CustomShipData_t * +GetCustomShipData (RACE_DESC *pRaceDesc) +{ + return pRaceDesc->data; +} + +// Set the race-specific data in a race desc +// (Re)Allocates its own storage for the data. static void +SetCustomShipData (RACE_DESC *pRaceDesc, const CustomShipData_t *data) +{ + if (pRaceDesc->data == data) + return; // no-op + + if (pRaceDesc->data) // Out with the old + { + HFree (pRaceDesc->data); + pRaceDesc->data = NULL; + } + + if (data) // In with the new + { + CustomShipData_t* newData = HMalloc (sizeof (*data)); + *newData = *data; + pRaceDesc->data = newData; + } +} + +static void sis_hyper_preprocess (ELEMENT *ElementPtr) { SIZE udx = 0, udy = 0; @@ -566,7 +598,7 @@ SIS_DATA *SisData; GetElementStarShip (ShipPtr, &StarShipPtr); - SisData = (SIS_DATA *) StarShipPtr->RaceDescPtr->data; + SisData = GetCustomShipData (StarShipPtr->RaceDescPtr); nt = (BYTE)((4 - SisData->num_trackers) & 3); @@ -606,7 +638,7 @@ SIS_DATA *SisData; GetElementStarShip (ShipPtr, &StarShipPtr); - SisData = (SIS_DATA *) StarShipPtr->RaceDescPtr->data; + SisData = GetCustomShipData (StarShipPtr->RaceDescPtr); lpEvalDesc = &ObjectsOfConcern[ENEMY_WEAPON_INDEX]; if (lpEvalDesc->ObjectPtr) @@ -680,7 +712,7 @@ #define BLASTER_HITS 2 #define BLASTER_OFFSET 8 COUNT i; - SIS_DATA *SisData = (SIS_DATA *) RaceDescPtr->data; + SIS_DATA *SisData = GetCustomShipData (RaceDescPtr); MISSILE_BLOCK *lpMB = SisData->MissileBlock; SisData->num_blasters = 0; @@ -760,7 +792,7 @@ { COUNT i; COUNT num_trackers; - SIS_DATA *SisData = (SIS_DATA *) RaceDescPtr->data; + SIS_DATA *SisData = GetCustomShipData (RaceDescPtr); RaceDescPtr->ship_info.max_crew = 0; num_trackers = 0; @@ -851,6 +883,8 @@ COUNT i; // The caller of this func will copy the struct static RACE_DESC new_sis_desc; + SIS_DATA empty_data; + memset (&empty_data, 0, sizeof (empty_data)); /* copy initial ship settings to new_sis_desc */ new_sis_desc = sis_desc; @@ -888,7 +922,7 @@ SET_GAME_STATE (BOMB_CARRIER, 1); } - new_sis_desc.data = (intptr_t) HCalloc (sizeof (SIS_DATA)); + SetCustomShipData (&new_sis_desc, &empty_data); InitModuleSlots (&new_sis_desc, GLOBAL_SIS (ModuleSlots)); InitWeaponSlots (&new_sis_desc, GLOBAL_SIS (ModuleSlots)); InitDriveSlots (&new_sis_desc, GLOBAL_SIS (DriveSlots)); @@ -913,7 +947,7 @@ return (RaceDescPtr); } -void +static void uninit_sis (RACE_DESC *pRaceDesc) { if (LOBYTE (GLOBAL (CurrentActivity)) != IN_HYPERSPACE) @@ -923,8 +957,7 @@ GLOBAL_SIS (CrewEnlisted)--; } - HFree ((void *)pRaceDesc->data); - pRaceDesc->data = 0; + SetCustomShipData (pRaceDesc, NULL); } Modified: trunk/sc2/src/uqm/ships/umgah/umgah.c =================================================================== --- trunk/sc2/src/uqm/ships/umgah/umgah.c 2011-08-08 15:56:23 UTC (rev 3666) +++ trunk/sc2/src/uqm/ships/umgah/umgah.c 2011-08-24 16:22:39 UTC (rev 3667) @@ -110,7 +110,47 @@ 0, /* CodeRef */ }; + +// Private per-instance ship data +typedef struct +{ + UWORD prevFacing; +} UMGAH_DATA; + +// Local typedef +typedef UMGAH_DATA CustomShipData_t; + +// Retrieve race-specific ship data from a race desc +static CustomShipData_t * +GetCustomShipData (RACE_DESC *pRaceDesc) +{ + return pRaceDesc->data; +} + +// Set the race-specific data in a race desc +// (Re)Allocates its own storage for the data. static void +SetCustomShipData (RACE_DESC *pRaceDesc, const CustomShipData_t *data) +{ + if (pRaceDesc->data == data) + return; // no-op + + if (pRaceDesc->data) // Out with the old + { + HFree (pRaceDesc->data); + pRaceDesc->data = NULL; + } + + if (data) // In with the new + { + CustomShipData_t* newData = HMalloc (sizeof (*data)); + *newData = *data; + pRaceDesc->data = newData; + } +} + + +static void cone_preprocess (ELEMENT *ElementPtr) { STARSHIP *StarShipPtr; @@ -266,6 +306,7 @@ #define MISSILE_LIFE 1 #define MISSILE_OFFSET 0 STARSHIP *StarShipPtr; + UMGAH_DATA* UmgahData; MISSILE_BLOCK MissileBlock; GetElementStarShip (ShipPtr, &StarShipPtr); @@ -285,15 +326,17 @@ // This func is called every frame while the player is holding down WEAPON // Don't reset the cone FRAME to the first image every time - if (ShipPtr->next.image.frame != (FRAME) StarShipPtr->RaceDescPtr->data) + UmgahData = GetCustomShipData (StarShipPtr->RaceDescPtr); + if (!UmgahData || StarShipPtr->ShipFacing != UmgahData->prevFacing) { - StarShipPtr->RaceDescPtr->data = (intptr_t) ShipPtr->next.image.frame; + const UMGAH_DATA shipData = {StarShipPtr->ShipFacing}; + SetCustomShipData (StarShipPtr->RaceDescPtr, &shipData); + StarShipPtr->RaceDescPtr->ship_data.special[0] = SetAbsFrameIndex ( StarShipPtr->RaceDescPtr->ship_data.special[0], - StarShipPtr->ShipFacing - ); + StarShipPtr->ShipFacing); } MissileBlock.index = GetFrameIndex (StarShipPtr->RaceDescPtr->ship_data.special[0]); @@ -341,7 +384,7 @@ if (ElementPtr->state_flags & APPEARING) { // Reset the value just in case - StarShipPtr->RaceDescPtr->data = 0; + SetCustomShipData (StarShipPtr->RaceDescPtr, NULL); } else { @@ -366,11 +409,18 @@ } } +static void +uninit_umgah (RACE_DESC *pRaceDesc) +{ + SetCustomShipData (pRaceDesc, NULL); +} + RACE_DESC* init_umgah (void) { RACE_DESC *RaceDescPtr; + umgah_desc.uninit_func = uninit_umgah; umgah_desc.preprocess_func = umgah_preprocess; umgah_desc.postprocess_func = umgah_postprocess; umgah_desc.init_weapon_func = initialize_cone; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |