Moved static ship variables to per-instance RACE_DESC

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3278 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2009-11-05 06:12:33 +00:00
parent 9e1b5ac5c4
commit d5230903d8
5 changed files with 51 additions and 44 deletions
+2 -2
View File
@@ -217,6 +217,8 @@ struct race_desc
POSTPROCESS_FUNC *postprocess_func; POSTPROCESS_FUNC *postprocess_func;
INIT_WEAPON_FUNC *init_weapon_func; INIT_WEAPON_FUNC *init_weapon_func;
intptr_t data; // private ship data, ship code owns this
void *CodeRef; void *CodeRef;
}; };
@@ -276,8 +278,6 @@ struct STARSHIP
// -1: neutral; this should currently never happen (asserts) // -1: neutral; this should currently never happen (asserts)
BYTE control; BYTE control;
// HUMAN, COMPUTER or NETWORK control flags, see intel.h // HUMAN, COMPUTER or NETWORK control flags, see intel.h
intptr_t data; // private ship data, ship code owns this
}; };
#define RPG_PLAYER_NUM 0 #define RPG_PLAYER_NUM 0
+6 -7
View File
@@ -20,8 +20,6 @@
#include "resinst.h" #include "resinst.h"
#include "libs/mathlib.h" #include "libs/mathlib.h"
#include "uqm/init.h"
// for NUM_PLAYERS
#define MAX_CREW 20 #define MAX_CREW 20
@@ -324,8 +322,6 @@ androsynth_intelligence (ELEMENT *ShipPtr, EVALUATE_DESC *ObjectsOfConcern,
} }
} }
static CollisionFunc *ship_collision_func[NUM_PLAYERS];
#define BLAZER_TURN_WAIT 1 #define BLAZER_TURN_WAIT 1
static void static void
@@ -357,8 +353,10 @@ androsynth_postprocess (ELEMENT *ElementPtr)
ElementPtr->mass_points = BLAZER_MASS; ElementPtr->mass_points = BLAZER_MASS;
StarShipPtr->RaceDescPtr->characteristics.turn_wait StarShipPtr->RaceDescPtr->characteristics.turn_wait
= BLAZER_TURN_WAIT; = BLAZER_TURN_WAIT;
ship_collision_func[StarShipPtr->playerNr] /* Save the current collision func because we were not the
= ElementPtr->collision_func; * ones who set it */
StarShipPtr->RaceDescPtr->data = (intptr_t)
ElementPtr->collision_func;
ElementPtr->collision_func = blazer_collision; ElementPtr->collision_func = blazer_collision;
} }
} }
@@ -426,7 +424,8 @@ androsynth_preprocess (ELEMENT *ElementPtr)
StarShipPtr->RaceDescPtr->characteristics.special_wait; StarShipPtr->RaceDescPtr->characteristics.special_wait;
StarShipPtr->RaceDescPtr->characteristics.energy_regeneration = ENERGY_REGENERATION; StarShipPtr->RaceDescPtr->characteristics.energy_regeneration = ENERGY_REGENERATION;
ElementPtr->mass_points = SHIP_MASS; ElementPtr->mass_points = SHIP_MASS;
ElementPtr->collision_func = ship_collision_func[StarShipPtr->playerNr]; ElementPtr->collision_func = (CollisionFunc *)
StarShipPtr->RaceDescPtr->data;
ElementPtr->next.image.farray = ElementPtr->next.image.farray =
StarShipPtr->RaceDescPtr->ship_data.ship; StarShipPtr->RaceDescPtr->ship_data.ship;
ElementPtr->next.image.frame = ElementPtr->next.image.frame =
+36 -24
View File
@@ -19,9 +19,6 @@
#include "../ship.h" #include "../ship.h"
#include "resinst.h" #include "resinst.h"
#include "uqm/init.h"
// for NUM_PLAYERS
#define MAX_CREW 20 #define MAX_CREW 20
#define MAX_ENERGY 10 #define MAX_ENERGY 10
@@ -51,7 +48,6 @@
#define MMRNMHRM_OFFSET 16 #define MMRNMHRM_OFFSET 16
#define LASER_RANGE DISPLAY_TO_WORLD (125 + MMRNMHRM_OFFSET) #define LASER_RANGE DISPLAY_TO_WORLD (125 + MMRNMHRM_OFFSET)
static CHARACTERISTIC_STUFF otherwing_desc[NUM_PLAYERS];
static RACE_DESC mmrnmhrm_desc = static RACE_DESC mmrnmhrm_desc =
{ {
@@ -366,6 +362,7 @@ mmrnmhrm_postprocess (ELEMENT *ElementPtr)
if (ElementPtr->next.image.farray != ElementPtr->current.image.farray) if (ElementPtr->next.image.farray != ElementPtr->current.image.farray)
{ {
CHARACTERISTIC_STUFF t; CHARACTERISTIC_STUFF t;
CHARACTERISTIC_STUFF *otherwing_desc;
ProcessSound (SetAbsSoundIndex ( ProcessSound (SetAbsSoundIndex (
/* TRANSFORM */ /* TRANSFORM */
@@ -373,8 +370,11 @@ mmrnmhrm_postprocess (ELEMENT *ElementPtr)
StarShipPtr->weapon_counter = 0; StarShipPtr->weapon_counter = 0;
t = otherwing_desc[StarShipPtr->playerNr]; /* Swap characteristics descriptors around */
otherwing_desc[StarShipPtr->playerNr] = StarShipPtr->RaceDescPtr->characteristics; otherwing_desc = (CHARACTERISTIC_STUFF *)
StarShipPtr->RaceDescPtr->data;
t = *otherwing_desc;
*otherwing_desc = StarShipPtr->RaceDescPtr->characteristics;
StarShipPtr->RaceDescPtr->characteristics = t; StarShipPtr->RaceDescPtr->characteristics = t;
StarShipPtr->RaceDescPtr->cyborg_control.ManeuverabilityIndex = 0; StarShipPtr->RaceDescPtr->cyborg_control.ManeuverabilityIndex = 0;
@@ -412,23 +412,7 @@ mmrnmhrm_preprocess (ELEMENT *ElementPtr)
GetElementStarShip (ElementPtr, &StarShipPtr); GetElementStarShip (ElementPtr, &StarShipPtr);
if (ElementPtr->state_flags & APPEARING) if (!(ElementPtr->state_flags & APPEARING))
{
// Set here because playerNr is unknown during init()
COUNT i = StarShipPtr->playerNr;
otherwing_desc[i].max_thrust = YWING_MAX_THRUST;
otherwing_desc[i].thrust_increment = YWING_THRUST_INCREMENT;
otherwing_desc[i].energy_regeneration = YWING_ENERGY_REGENERATION;
otherwing_desc[i].weapon_energy_cost = YWING_WEAPON_ENERGY_COST;
otherwing_desc[i].special_energy_cost = YWING_SPECIAL_ENERGY_COST;
otherwing_desc[i].energy_wait = YWING_ENERGY_WAIT;
otherwing_desc[i].turn_wait = YWING_TURN_WAIT;
otherwing_desc[i].thrust_wait = YWING_THRUST_WAIT;
otherwing_desc[i].weapon_wait = YWING_WEAPON_WAIT;
otherwing_desc[i].special_wait = YWING_SPECIAL_WAIT;
otherwing_desc[i].ship_mass = SHIP_MASS;
}
else
{ {
if ((StarShipPtr->cur_status_flags & SPECIAL) if ((StarShipPtr->cur_status_flags & SPECIAL)
&& StarShipPtr->special_counter == 0) && StarShipPtr->special_counter == 0)
@@ -455,17 +439,45 @@ mmrnmhrm_preprocess (ELEMENT *ElementPtr)
} }
} }
static void
uninit_mmrnmhrm (RACE_DESC *pRaceDesc)
{
HFree ((void *)pRaceDesc->data);
pRaceDesc->data = 0;
}
RACE_DESC* RACE_DESC*
init_mmrnmhrm (void) init_mmrnmhrm (void)
{ {
RACE_DESC *RaceDescPtr; RACE_DESC *RaceDescPtr;
static RACE_DESC new_mmrnmhrm_desc;
CHARACTERISTIC_STUFF *otherwing_desc;
mmrnmhrm_desc.uninit_func = uninit_mmrnmhrm;
mmrnmhrm_desc.preprocess_func = mmrnmhrm_preprocess; mmrnmhrm_desc.preprocess_func = mmrnmhrm_preprocess;
mmrnmhrm_desc.postprocess_func = mmrnmhrm_postprocess; mmrnmhrm_desc.postprocess_func = mmrnmhrm_postprocess;
mmrnmhrm_desc.init_weapon_func = initialize_dual_weapons; mmrnmhrm_desc.init_weapon_func = initialize_dual_weapons;
mmrnmhrm_desc.cyborg_control.intelligence_func = mmrnmhrm_intelligence; mmrnmhrm_desc.cyborg_control.intelligence_func = mmrnmhrm_intelligence;
RaceDescPtr = &mmrnmhrm_desc; 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;
new_mmrnmhrm_desc.data = (intptr_t) otherwing_desc;
RaceDescPtr = &new_mmrnmhrm_desc;
return (RaceDescPtr); return (RaceDescPtr);
} }
+3 -3
View File
@@ -187,12 +187,12 @@ pkunk_intelligence (ELEMENT *ShipPtr, EVALUATE_DESC *ObjectsOfConcern,
HELEMENT hPhoenix; HELEMENT hPhoenix;
GetElementStarShip (ShipPtr, &StarShipPtr); GetElementStarShip (ShipPtr, &StarShipPtr);
hPhoenix = (HELEMENT) StarShipPtr->data; hPhoenix = (HELEMENT) StarShipPtr->RaceDescPtr->data;
if (hPhoenix && (StarShipPtr->control & STANDARD_RATING)) if (hPhoenix && (StarShipPtr->control & STANDARD_RATING))
{ {
RemoveElement (hPhoenix); RemoveElement (hPhoenix);
FreeElement (hPhoenix); FreeElement (hPhoenix);
StarShipPtr->data = 0; StarShipPtr->RaceDescPtr->data = 0;
} }
if (StarShipPtr->RaceDescPtr->ship_info.energy_level < if (StarShipPtr->RaceDescPtr->ship_info.energy_level <
@@ -463,7 +463,7 @@ pkunk_preprocess (ELEMENT *ElementPtr)
UnlockElement (hPhoenix); UnlockElement (hPhoenix);
InsertElement (hPhoenix, GetHeadElement ()); InsertElement (hPhoenix, GetHeadElement ());
} }
StarShipPtr->data = (intptr_t) hPhoenix; StarShipPtr->RaceDescPtr->data = (intptr_t) hPhoenix;
if (ElementPtr->hTarget == 0) if (ElementPtr->hTarget == 0)
StarShipPtr->RaceDescPtr->preprocess_func = 0; StarShipPtr->RaceDescPtr->preprocess_func = 0;
+4 -8
View File
@@ -20,8 +20,6 @@
#include "resinst.h" #include "resinst.h"
#include "libs/mathlib.h" #include "libs/mathlib.h"
#include "uqm/init.h"
// for NUM_PLAYERS
#define MAX_CREW 10 #define MAX_CREW 10
@@ -39,7 +37,6 @@
#define SHIP_MASS 1 #define SHIP_MASS 1
static FRAME LastShipFrame[NUM_PLAYERS];
static RACE_DESC umgah_desc = static RACE_DESC umgah_desc =
{ {
@@ -286,9 +283,9 @@ initialize_cone (ELEMENT *ShipPtr, HELEMENT ConeArray[])
// This func is called every frame while the player is holding down WEAPON // 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 // Don't reset the cone FRAME to the first image every time
if (ShipPtr->next.image.frame != LastShipFrame[StarShipPtr->playerNr]) if (ShipPtr->next.image.frame != (FRAME) StarShipPtr->RaceDescPtr->data)
{ {
LastShipFrame[StarShipPtr->playerNr] = ShipPtr->next.image.frame; StarShipPtr->RaceDescPtr->data = (intptr_t) ShipPtr->next.image.frame;
StarShipPtr->RaceDescPtr->ship_data.special[0] = StarShipPtr->RaceDescPtr->ship_data.special[0] =
SetAbsFrameIndex ( SetAbsFrameIndex (
@@ -341,9 +338,8 @@ umgah_preprocess (ELEMENT *ElementPtr)
if (ElementPtr->state_flags & APPEARING) if (ElementPtr->state_flags & APPEARING)
{ {
// Reset prevously set value, if any. It could only have been // Reset the value just in case
// set by another ship of the same player, though. StarShipPtr->RaceDescPtr->data = 0;
LastShipFrame[StarShipPtr->playerNr] = 0;
} }
else else
{ {