Some cleanups, comments.

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2723 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
Meep-Eep
2007-04-07 00:56:51 +00:00
parent 6c991d8b36
commit 6c1d9b9d62
9 changed files with 68 additions and 41 deletions
+11 -10
View File
@@ -38,7 +38,9 @@
QUEUE disp_q; QUEUE disp_q;
SIZE battle_counter; BYTE battle_counter[NUM_SIDES];
// The number of ships still available for battle to each side.
// A ship that has warped out is no longer available.
BOOLEAN instantVictory; BOOLEAN instantVictory;
size_t battleInputOrder[NUM_SIDES]; size_t battleInputOrder[NUM_SIDES];
// Indices of the sides in the order their input is processed. // Indices of the sides in the order their input is processed.
@@ -79,7 +81,7 @@ DoRunAway (STARSHIP *StarShipPtr)
{ {
extern void flee_preprocess (ELEMENT *); extern void flee_preprocess (ELEMENT *);
battle_counter -= MAKE_WORD (1, 0); battle_counter[0]--;
ElementPtr->turn_wait = 3; ElementPtr->turn_wait = 3;
ElementPtr->thrust_wait = MAKE_BYTE (4, 0); ElementPtr->thrust_wait = MAKE_BYTE (4, 0);
@@ -353,7 +355,7 @@ selectAllShips (SIZE num_ships)
// On network play, what is the top player to one party may be // On network play, what is the top player to one party may be
// the bottom player the other. To keep both sides synchronised // the bottom player the other. To keep both sides synchronised
// the order is always the same. // the order is always the same.
SIZE order[2]; SIZE order[NUM_PLAYERS];
if (num_ships == 1) { if (num_ships == 1) {
// HyperSpace in full game. // HyperSpace in full game.
@@ -393,7 +395,7 @@ selectAllShips (SIZE num_ships)
{ {
size_t i; size_t i;
for (i = 0; i < 2; i++) for (i = 0; i < NUM_PLAYERS; i++)
{ {
if (!GetNextStarShip (NULL, order[i])) if (!GetNextStarShip (NULL, order[i]))
return FALSE; return FALSE;
@@ -430,8 +432,9 @@ Battle (void)
if (instantVictory) if (instantVictory)
{ {
num_ships = 0; // no ships were harmed in the making of this battle num_ships = 0;
battle_counter = 1; // a winner is you! battle_counter[0] = 1;
battle_counter[1] = 0;
instantVictory = FALSE; instantVictory = FALSE;
} }
@@ -440,10 +443,8 @@ Battle (void)
BATTLE_STATE bs; BATTLE_STATE bs;
GLOBAL (CurrentActivity) |= IN_BATTLE; GLOBAL (CurrentActivity) |= IN_BATTLE;
battle_counter = MAKE_WORD ( battle_counter[0] = CountLinks (&race_q[0]);
CountLinks (&race_q[0]), battle_counter[1] = CountLinks (&race_q[1]);
CountLinks (&race_q[1])
);
setupBattleInputOrder (); setupBattleInputOrder ();
#ifdef NETPLAY #ifdef NETPLAY
+3 -1
View File
@@ -18,6 +18,8 @@
#include "libs/compiler.h" #include "libs/compiler.h"
#include "displist.h" #include "displist.h"
#include "init.h"
// For NUM_SIDES
typedef struct battlestate_struct { typedef struct battlestate_struct {
BOOLEAN (*InputFunc) (struct battlestate_struct *pInputState); BOOLEAN (*InputFunc) (struct battlestate_struct *pInputState);
@@ -27,7 +29,7 @@ typedef struct battlestate_struct {
} BATTLE_STATE; } BATTLE_STATE;
extern QUEUE disp_q; extern QUEUE disp_q;
extern SIZE battle_counter; extern BYTE battle_counter[NUM_SIDES];
extern BOOLEAN instantVictory; extern BOOLEAN instantVictory;
#ifdef NETPLAY #ifdef NETPLAY
typedef DWORD BattleFrameCounter; typedef DWORD BattleFrameCounter;
+11 -1
View File
@@ -47,6 +47,9 @@ typedef QUEUE_HANDLE HELEMENT;
#define GOOD_GUY (1 << 0) #define GOOD_GUY (1 << 0)
#define BAD_GUY (1 << 1) #define BAD_GUY (1 << 1)
#define PLAYER_SHIP (1 << 2) #define PLAYER_SHIP (1 << 2)
// The ELEMENT is a player controlable ship, and not some bullet,
// crew, asteroid, fighter, etc. This does not mean that the ship
// is actually controlled by a human; it may be a computer.
#define APPEARING (1 << 3) #define APPEARING (1 << 3)
#define DISAPPEARING (1 << 4) #define DISAPPEARING (1 << 4)
@@ -60,6 +63,7 @@ typedef QUEUE_HANDLE HELEMENT;
#define FINITE_LIFE (1 << 10) #define FINITE_LIFE (1 << 10)
#define PRE_PROCESS (1 << 11) #define PRE_PROCESS (1 << 11)
// PreProcess() is to be called for the ELEMENT.
#define POST_PROCESS (1 << 12) #define POST_PROCESS (1 << 12)
#define IGNORE_VELOCITY (1 << 13) #define IGNORE_VELOCITY (1 << 13)
@@ -146,7 +150,13 @@ extern PRIMITIVE DisplayArray[MAX_DISPLAY_PRIMS];
#define GRAVITY_MASS(m) ((m) > MAX_SHIP_MASS * 10) #define GRAVITY_MASS(m) ((m) > MAX_SHIP_MASS * 10)
#define GRAVITY_THRESHOLD (COUNT)255 #define GRAVITY_THRESHOLD (COUNT)255
#define WHICH_SIDE(f) (((f) & BAD_GUY) >> 1) static inline BYTE
ElementFlagsSide (ELEMENT_FLAGS flags)
{
return (BYTE) ((flags & BAD_GUY) >> 1);
}
#define WHICH_SIDE(flags) ElementFlagsSide (flags)
#define OBJECT_CLOAKED(eptr) \ #define OBJECT_CLOAKED(eptr) \
(GetPrimType (&GLOBAL (DisplayArray[(eptr)->PrimIndex])) >= NUM_PRIMS \ (GetPrimType (&GLOBAL (DisplayArray[(eptr)->PrimIndex])) >= NUM_PRIMS \
|| (GetPrimType (&GLOBAL (DisplayArray[(eptr)->PrimIndex])) == STAMPFILL_PRIM \ || (GetPrimType (&GLOBAL (DisplayArray[(eptr)->PrimIndex])) == STAMPFILL_PRIM \
+1 -1
View File
@@ -462,7 +462,7 @@ UninitEncounter (void)
SET_GAME_STATE (BOMB_CARRIER, 0); SET_GAME_STATE (BOMB_CARRIER, 0);
VictoryState = ( VictoryState = (
HIBYTE (battle_counter) || !LOBYTE (battle_counter) battle_counter[1] || !battle_counter[0]
|| GET_GAME_STATE (URQUAN_PROTECTING_SAMATRA) || GET_GAME_STATE (URQUAN_PROTECTING_SAMATRA)
) ? 0 : 1; ) ? 0 : 1;
+2 -5
View File
@@ -389,7 +389,7 @@ GetMeleeStarShip (STARSHIP *LastStarShipPtr, COUNT which_player)
DrawStamp (&s); DrawStamp (&s);
if (LOBYTE (battle_counter) == 0 || HIBYTE (battle_counter) == 0) if (battle_counter[0] == 0 || battle_counter[1] == 0)
{ {
// One side is out of ships. Game over. // One side is out of ships. Game over.
DWORD TimeOut; DWORD TimeOut;
@@ -457,10 +457,7 @@ GetMeleeStarShip (STARSHIP *LastStarShipPtr, COUNT which_player)
FlushColorXForms (); FlushColorXForms ();
} }
if (which_player == 0) ships_left = battle_counter[which_player];
ships_left = LOBYTE (battle_counter);
else
ships_left = HIBYTE (battle_counter);
gmstate.flash_rect.extent.width = (ICON_WIDTH + 2); gmstate.flash_rect.extent.width = (ICON_WIDTH + 2);
gmstate.flash_rect.extent.height = (ICON_HEIGHT + 2); gmstate.flash_rect.extent.height = (ICON_HEIGHT + 2);
+28 -13
View File
@@ -114,8 +114,10 @@ DoPickBattleShip (MENU_STATE *pMS)
ChangeSelection: ChangeSelection:
if (pMS->first_item.x == (NUM_PICK_SHIP_COLUMNS >> 1)) if (pMS->first_item.x == (NUM_PICK_SHIP_COLUMNS >> 1))
{ {
pMS->flash_rect0.corner.x = pMS->flash_rect1.corner.x - 2 + FLAGSHIP_X_OFFS; pMS->flash_rect0.corner.x =
pMS->flash_rect0.corner.y = pMS->flash_rect1.corner.y - 2 + FLAGSHIP_Y_OFFS; pMS->flash_rect1.corner.x - 2 + FLAGSHIP_X_OFFS;
pMS->flash_rect0.corner.y =
pMS->flash_rect1.corner.y - 2 + FLAGSHIP_Y_OFFS;
pMS->flash_rect0.extent.width = FLAGSHIP_WIDTH + 4; pMS->flash_rect0.extent.width = FLAGSHIP_WIDTH + 4;
pMS->flash_rect0.extent.height = FLAGSHIP_HEIGHT + 4; pMS->flash_rect0.extent.height = FLAGSHIP_HEIGHT + 4;
@@ -248,9 +250,10 @@ GetArmadaStarShip (void)
CONTEXT OldContext; CONTEXT OldContext;
HSTARSHIP hBattleShip; HSTARSHIP hBattleShip;
if (HIBYTE (battle_counter) == 0) if (battle_counter[1] == 0)
{ {
return (0); // No opponents left.
return 0;
} }
// MenuSounds = CaptureSound (LoadSound (MENU_SOUNDS)); // MenuSounds = CaptureSound (LoadSound (MENU_SOUNDS));
@@ -285,7 +288,7 @@ OldContext = SetContext (SpaceContext);
if (hBattleShip) if (hBattleShip)
{ {
if (hBattleShip == GetTailLink (&race_q[0])) if (hBattleShip == GetTailLink (&race_q[0]))
battle_counter = MAKE_WORD (1, HIBYTE (battle_counter)); battle_counter[0] = 1;
WaitForSoundEnd (0); WaitForSoundEnd (0);
} }
@@ -312,14 +315,19 @@ GetEncounterStarShip (STARSHIP *LastStarShipPtr, COUNT which_player)
} }
else else
{ {
// Full game.
HSTARSHIP hStarShip; HSTARSHIP hStarShip;
STARSHIP *SPtr; STARSHIP *SPtr;
SHIP_FRAGMENT *FragPtr; SHIP_FRAGMENT *FragPtr;
if (LastStarShipPtr == 0) if (LastStarShipPtr == 0)
{ {
if (which_player == 0 && LOBYTE (battle_counter) > 1) // First time picking a ship.
if (which_player == 0 && battle_counter[0] > 1)
{
// The player in a full game, still having a ship left.
hBattleShip = GetArmadaStarShip (); hBattleShip = GetArmadaStarShip ();
}
else else
{ {
hBattleShip = GetHeadLink (&race_q[which_player]); hBattleShip = GetHeadLink (&race_q[which_player]);
@@ -331,7 +339,7 @@ GetEncounterStarShip (STARSHIP *LastStarShipPtr, COUNT which_player)
if (FragPtr->ShipInfo.crew_level == INFINITE_FLEET) if (FragPtr->ShipInfo.crew_level == INFINITE_FLEET)
{ {
// Infinite number of ships. // Infinite number of ships.
battle_counter += MAKE_WORD (0, 1); battle_counter[1]++;
} }
UnlockStarShip (&GLOBAL (npc_built_ship_q), hStarShip); UnlockStarShip (&GLOBAL (npc_built_ship_q), hStarShip);
} }
@@ -373,7 +381,7 @@ GetEncounterStarShip (STARSHIP *LastStarShipPtr, COUNT which_player)
SPtr->cur_status_flags = 1 << which_player; SPtr->cur_status_flags = 1 << which_player;
SPtr->captains_name_index = PickCaptainName (); SPtr->captains_name_index = PickCaptainName ();
battle_counter += MAKE_WORD (0, 1); battle_counter[1]++;
} }
UnlockStarShip (pQueue, hStarShip); UnlockStarShip (pQueue, hStarShip);
break; break;
@@ -384,19 +392,26 @@ GetEncounterStarShip (STARSHIP *LastStarShipPtr, COUNT which_player)
if (which_player == 0) if (which_player == 0)
{ {
if (LOBYTE (battle_counter)) // Player in a full game.
if (battle_counter[0])
hBattleShip = GetArmadaStarShip (); hBattleShip = GetArmadaStarShip ();
else /* last ship was flagship */ else /* last ship was flagship */
{ {
#define RUN_AWAY_FUEL_COST (5 * FUEL_TANK_SCALE) #define RUN_AWAY_FUEL_COST (5 * FUEL_TANK_SCALE)
hBattleShip = 0; hBattleShip = 0;
if (LastStarShipPtr->special_counter == 0) if (LastStarShipPtr->special_counter == 0)
/* died in the line of duty */ {
/* Died in the line of duty */
GLOBAL_SIS (CrewEnlisted) = (COUNT)~0; GLOBAL_SIS (CrewEnlisted) = (COUNT)~0;
else if (GLOBAL_SIS (FuelOnBoard) > RUN_AWAY_FUEL_COST) }
GLOBAL_SIS (FuelOnBoard) -= RUN_AWAY_FUEL_COST;
else else
GLOBAL_SIS (FuelOnBoard) = 0; {
// Player ran away.
if (GLOBAL_SIS (FuelOnBoard) > RUN_AWAY_FUEL_COST)
GLOBAL_SIS (FuelOnBoard) -= RUN_AWAY_FUEL_COST;
else
GLOBAL_SIS (FuelOnBoard) = 0;
}
} }
} }
} }
+6 -4
View File
@@ -619,7 +619,7 @@ static VIEW_STATE
PreProcessQueue (SIZE *pscroll_x, SIZE *pscroll_y) PreProcessQueue (SIZE *pscroll_x, SIZE *pscroll_y)
{ {
SIZE min_reduction, max_reduction; SIZE min_reduction, max_reduction;
COUNT num_ships; COUNT sides_active;
POINT Origin; POINT Origin;
HELEMENT hElement; HELEMENT hElement;
COUNT ships_alive; COUNT ships_alive;
@@ -627,8 +627,8 @@ PreProcessQueue (SIZE *pscroll_x, SIZE *pscroll_y)
#ifdef KDEBUG #ifdef KDEBUG
log_add (log_Debug, "PreProcess:"); log_add (log_Debug, "PreProcess:");
#endif #endif
num_ships = (LOBYTE (battle_counter) ? 1 : 0) sides_active = (battle_counter[0] ? 1 : 0)
+ (HIBYTE (battle_counter) ? 1 : 0); + (battle_counter[1] ? 1 : 0);
if (optMeleeScale == TFB_SCALE_STEP) if (optMeleeScale == TFB_SCALE_STEP)
min_reduction = max_reduction = MAX_VIS_REDUCTION + 1; min_reduction = max_reduction = MAX_VIS_REDUCTION + 1;
@@ -673,7 +673,7 @@ PreProcessQueue (SIZE *pscroll_x, SIZE *pscroll_y)
dy = DISPLAY_ALIGN (ElementPtr->next.location.y) - Origin.y; dy = DISPLAY_ALIGN (ElementPtr->next.location.y) - Origin.y;
dy = WRAP_DELTA_Y (dy); dy = WRAP_DELTA_Y (dy);
if (num_ships <= 2 || !(ElementPtr->state_flags & BAD_GUY)) if (sides_active <= 2 || !(ElementPtr->state_flags & BAD_GUY))
{ {
Origin.x = DISPLAY_ALIGN (Origin.x + (dx >> 1)); Origin.x = DISPLAY_ALIGN (Origin.x + (dx >> 1));
Origin.y = DISPLAY_ALIGN (Origin.y + (dy >> 1)); Origin.y = DISPLAY_ALIGN (Origin.y + (dy >> 1));
@@ -1061,6 +1061,8 @@ RedrawQueue (BOOLEAN clear)
DisplayLinks = MakeLinks (END_OF_LIST, END_OF_LIST); DisplayLinks = MakeLinks (END_OF_LIST, END_OF_LIST);
} }
// Set the hTarget field to 0 for all elements in the display list that
// have hTarget set to ElementPtr.
void void
Untarget (ELEMENT *ElementPtr) Untarget (ELEMENT *ElementPtr)
{ {
+3
View File
@@ -202,6 +202,7 @@ arilou_preprocess (ELEMENT *ElementPtr)
&& StarShipPtr->special_counter == 0 && StarShipPtr->special_counter == 0
&& DeltaEnergy (ElementPtr, -SPECIAL_ENERGY_COST)) && DeltaEnergy (ElementPtr, -SPECIAL_ENERGY_COST))
{ {
/* Special key is pressed; start teleport */
#define HYPER_LIFE 5 #define HYPER_LIFE 5
ZeroVelocityComponents (&ElementPtr->velocity); ZeroVelocityComponents (&ElementPtr->velocity);
StarShipPtr->cur_status_flags &= StarShipPtr->cur_status_flags &=
@@ -239,6 +240,7 @@ arilou_preprocess (ELEMENT *ElementPtr)
if ((life_span = ElementPtr->life_span) == NORMAL_LIFE) if ((life_span = ElementPtr->life_span) == NORMAL_LIFE)
{ {
/* Ending teleport */
ElementPtr->state_flags &= ~(NONSOLID | FINITE_LIFE); ElementPtr->state_flags &= ~(NONSOLID | FINITE_LIFE);
ElementPtr->state_flags |= APPEARING; ElementPtr->state_flags |= APPEARING;
ElementPtr->current.image.farray = ElementPtr->current.image.farray =
@@ -252,6 +254,7 @@ arilou_preprocess (ELEMENT *ElementPtr)
} }
else else
{ {
/* Teleporting in progress */
--life_span; --life_span;
if (life_span != 2) if (life_span != 2)
{ {
+3 -6
View File
@@ -374,8 +374,7 @@ UnbatchGraphics ();
if (RestartMusic) if (RestartMusic)
BattleSong (TRUE); BattleSong (TRUE);
} }
else if (LOBYTE (battle_counter) == 0 else if (battle_counter[0] == 0 || battle_counter[1] == 0)
|| HIBYTE (battle_counter) == 0)
{ {
// One player is out of ships. The battle is over. // One player is out of ships. The battle is over.
GLOBAL (CurrentActivity) &= ~IN_BATTLE; GLOBAL (CurrentActivity) &= ~IN_BATTLE;
@@ -489,10 +488,8 @@ ship_death (ELEMENT *ShipPtr)
if (ShipPtr->mass_points <= MAX_SHIP_MASS) if (ShipPtr->mass_points <= MAX_SHIP_MASS)
{ {
if (WHICH_SIDE (ShipPtr->state_flags)) COUNT side = ElementFlagsSide (ShipPtr->state_flags);
battle_counter -= MAKE_WORD (0, 1); battle_counter[side]--;
else
battle_counter -= MAKE_WORD (1, 0);
} }
VictoriousStarShipPtr = 0; VictoriousStarShipPtr = 0;