From: <av...@us...> - 2009-10-31 00:57:19
|
Revision: 3266 http://sc2.svn.sourceforge.net/sc2/?rev=3266&view=rev Author: avolkov Date: 2009-10-31 00:57:09 +0000 (Sat, 31 Oct 2009) Log Message: ----------- Battle & ship code cleanup: Switch to playerNr instead of GOOD_GUY/BAD_GUY in ship status code Modified Paths: -------------- trunk/sc2/src/uqm/melee.c trunk/sc2/src/uqm/setup.c trunk/sc2/src/uqm/ship.c trunk/sc2/src/uqm/shipstat.c trunk/sc2/src/uqm/status.c trunk/sc2/src/uqm/status.h trunk/sc2/src/uqm/weapon.c Modified: trunk/sc2/src/uqm/melee.c =================================================================== --- trunk/sc2/src/uqm/melee.c 2009-10-30 22:33:09 UTC (rev 3265) +++ trunk/sc2/src/uqm/melee.c 2009-10-31 00:57:09 UTC (rev 3266) @@ -894,7 +894,7 @@ RECT r; TEXT t; - ClearShipStatus (BAD_GUY_YOFFS); + ClearShipStatus (0); SetContextFont (StarConFont); r.corner.x = 3; r.corner.y = 4; @@ -931,7 +931,7 @@ hMasterShip = GetStarShipFromIndex (&master_q, NewStarShip); MasterPtr = LockMasterShip (&master_q, hMasterShip); - InitShipStatus (&MasterPtr->ShipInfo, ~0, NULL); + InitShipStatus (&MasterPtr->ShipInfo, NULL, NULL); UnlockMasterShip (&master_q, hMasterShip); } Modified: trunk/sc2/src/uqm/setup.c =================================================================== --- trunk/sc2/src/uqm/setup.c 2009-10-30 22:33:09 UTC (rev 3265) +++ trunk/sc2/src/uqm/setup.c 2009-10-31 00:57:09 UTC (rev 3266) @@ -27,6 +27,7 @@ #endif #include "init.h" #include "intel.h" +#include "status.h" #include "resinst.h" #include "sounds.h" #include "libs/compiler.h" @@ -219,6 +220,7 @@ if (MenuSounds == 0) return FALSE; + InitStatusOffsets (); InitSpace (); return TRUE; Modified: trunk/sc2/src/uqm/ship.c =================================================================== --- trunk/sc2/src/uqm/ship.c 2009-10-30 22:33:09 UTC (rev 3265) +++ trunk/sc2/src/uqm/ship.c 2009-10-31 00:57:09 UTC (rev 3266) @@ -160,10 +160,12 @@ StarShipPtr->cur_status_flags & ~(LEFT | RIGHT | THRUST | WEAPON | SPECIAL); if (!(ElementPtr->state_flags & APPEARING)) + { cur_status_flags |= StarShipPtr->ship_input_state & (LEFT | RIGHT | THRUST | WEAPON | SPECIAL); + } else - { + { // Preprocessing for the first time ElementPtr->crew_level = RDPtr->ship_info.crew_level; if ((ElementPtr->state_flags & BAD_GUY) @@ -184,8 +186,7 @@ { CONTEXT OldContext; - InitShipStatus (&RDPtr->ship_info, - StarShipPtr->captains_name_index, NULL); + InitShipStatus (&RDPtr->ship_info, StarShipPtr, NULL); OldContext = SetContext (StatusContext); DrawCaptainsWindow (StarShipPtr); SetContext (OldContext); Modified: trunk/sc2/src/uqm/shipstat.c =================================================================== --- trunk/sc2/src/uqm/shipstat.c 2009-10-30 22:33:09 UTC (rev 3265) +++ trunk/sc2/src/uqm/shipstat.c 2009-10-31 00:57:09 UTC (rev 3266) @@ -133,18 +133,17 @@ } void -InitShipStatus (SHIP_INFO *SIPtr, BYTE captains_name_index, RECT *pClipRect) +InitShipStatus (SHIP_INFO *SIPtr, STARSHIP *StarShipPtr, RECT *pClipRect) { RECT r; - COORD y, y_stat; + COORD y = 0; // default, for Melee menu STAMP Stamp; CONTEXT OldContext; - y_stat = (SIPtr->ship_flags & GOOD_GUY) ? - GOOD_GUY_YOFFS : BAD_GUY_YOFFS; + if (StarShipPtr) // set during battle + y = status_y_offsets[StarShipPtr->playerNr]; OldContext = SetContext (StatusContext); - y = y_stat; if (pClipRect) { GetContextClipRect (&r); @@ -225,8 +224,9 @@ DrawFilledRectangle (&r); } - if (captains_name_index) - { + if (!StarShipPtr || StarShipPtr->captains_name_index) + { // Any regular ship. SIS and Sa-Matra are separate. + // This includes Melee menu. STRING locString; DrawCrewFuelString (y, 0); @@ -234,7 +234,7 @@ locString = SetAbsStringTableIndex (SIPtr->race_strings, 1); DrawShipNameString ( (UNICODE *)GetStringAddress (locString), - GetStringLength (locString),y); + GetStringLength (locString), y); { UNICODE buf[30]; @@ -243,8 +243,8 @@ OldFont = SetContextFont (TinyFont); - if (!(GLOBAL (CurrentActivity) & IN_BATTLE)) - { + if (!StarShipPtr) + { // In Melee menu sprintf (buf, "%d", SIPtr->ship_cost); Text.pStr = buf; Text.CharCount = (COUNT)~0; @@ -252,7 +252,7 @@ else { locString = SetAbsStringTableIndex (SIPtr->race_strings, - captains_name_index); + StarShipPtr->captains_name_index); Text.pStr = (UNICODE *)GetStringAddress (locString); Text.CharCount = GetStringLength (locString); } @@ -267,13 +267,10 @@ SetContextFont (OldFont); } } - else /* if (captains_name_index == 0) */ - { /* Only SIS or Sa-Matra */ - if (SIPtr->ship_flags & GOOD_GUY) - { - DrawCrewFuelString (y, 0); - DrawShipNameString (GLOBAL_SIS (ShipName), (COUNT)~0, y); - } + else if (StarShipPtr->playerNr == 0) + { // This is SIS + DrawCrewFuelString (y, 0); + DrawShipNameString (GLOBAL_SIS (ShipName), (COUNT)~0, y); } { @@ -281,8 +278,10 @@ crew_delta = SIPtr->crew_level; energy_delta = SIPtr->energy_level; - SIPtr->crew_level = SIPtr->energy_level = 0; - DeltaStatistics (SIPtr, crew_delta, energy_delta); + // DeltaStatistics() below will add specified values to these + SIPtr->crew_level = 0; + SIPtr->energy_level = 0; + DeltaStatistics (SIPtr, y, crew_delta, energy_delta); } UnbatchGraphics (); @@ -303,7 +302,8 @@ // Pre: -crew_delta <= ShipInfoPtr->crew_level // crew_delta <= ShipInfoPtr->max_crew - ShipInfoPtr->crew_level void -DeltaStatistics (SHIP_INFO *ShipInfoPtr, SIZE crew_delta, SIZE energy_delta) +DeltaStatistics (SHIP_INFO *ShipInfoPtr, COORD y_offs, + SIZE crew_delta, SIZE energy_delta) { COORD x, y; RECT r; @@ -312,8 +312,7 @@ return; x = 0; - y = GAUGE_YOFFS + ((ShipInfoPtr->ship_flags & GOOD_GUY) ? - GOOD_GUY_YOFFS : BAD_GUY_YOFFS); + y = GAUGE_YOFFS + y_offs; r.extent.width = UNIT_WIDTH; r.extent.height = UNIT_HEIGHT; @@ -388,7 +387,7 @@ { // All crew doesn't fit in the graphics; print a number. // Always print a number for the SIS in the full game. - DrawBattleCrewAmount (ShipInfoPtr); + DrawBattleCrewAmount (ShipInfoPtr, y_offs); } } Modified: trunk/sc2/src/uqm/status.c =================================================================== --- trunk/sc2/src/uqm/status.c 2009-10-30 22:33:09 UTC (rev 3265) +++ trunk/sc2/src/uqm/status.c 2009-10-31 00:57:09 UTC (rev 3266) @@ -23,10 +23,25 @@ #include "ship.h" #include "setup.h" #include "options.h" +#include "init.h" + // for NUM_PLAYERS #include <stdio.h> #include <string.h> + +COORD status_y_offsets[NUM_PLAYERS]; + + +void +InitStatusOffsets (void) +{ + // XXX: We have to jump through these hoops because GOOD_GUY_YOFFS is + // not a constant, contrary to what its' name suggests. + status_y_offsets[0] = GOOD_GUY_YOFFS; // bottom player + status_y_offsets[1] = BAD_GUY_YOFFS; // top player +} + static void CaptainsWindow (CAPTAIN_STUFF *CSPtr, COORD y, STATUS_FLAGS delta_status_flags, STATUS_FLAGS cur_status_flags, @@ -115,7 +130,7 @@ } void -DrawBattleCrewAmount (SHIP_INFO *ShipInfoPtr) +DrawBattleCrewAmount (SHIP_INFO *ShipInfoPtr, COORD y_offs) { #define MAX_CREW_DIGITS 3 RECT r; @@ -125,9 +140,7 @@ t.baseline.x = BATTLE_CREW_X + 2; if (optWhichMenu == OPT_PC) t.baseline.x -= 8; - t.baseline.y = BATTLE_CREW_Y + - ((ShipInfoPtr->ship_flags & GOOD_GUY) ? - GOOD_GUY_YOFFS : BAD_GUY_YOFFS); + t.baseline.y = BATTLE_CREW_Y + y_offs; t.align = ALIGN_LEFT; t.pStr = buf; t.CharCount = (COUNT)~0; @@ -150,7 +163,8 @@ void DrawCaptainsWindow (STARSHIP *StarShipPtr) { - COORD y, y_offs; + COORD y; + COORD y_offs; RECT r; STAMP s; FRAME Frame; @@ -174,23 +188,20 @@ BatchGraphics (); - y_offs = CAPTAIN_YOFFS - + ((RDPtr->ship_info.ship_flags & GOOD_GUY) ? - GOOD_GUY_YOFFS : BAD_GUY_YOFFS); + y_offs = status_y_offsets[StarShipPtr->playerNr]; + r.corner.x = CAPTAIN_XOFFS - 2; - r.corner.y = y_offs - 4; + r.corner.y = y_offs + SHIP_INFO_HEIGHT; r.extent.width = STATUS_WIDTH - CAPTAIN_XOFFS; r.extent.height = SHIP_STATUS_HEIGHT - CAPTAIN_YOFFS + 2; SetContextForeGroundColor ( BUILD_COLOR (MAKE_RGB15 (0x0A, 0x0A, 0x0A), 0x08)); DrawFilledRectangle (&r); - y = y_offs - CAPTAIN_YOFFS; - SetContextForeGroundColor ( BUILD_COLOR (MAKE_RGB15 (0x08, 0x08, 0x08), 0x1F)); r.corner.x = 1; - r.corner.y = SHIP_INFO_HEIGHT + y; + r.corner.y = y_offs + SHIP_INFO_HEIGHT; r.extent.width = 1; r.extent.height = (SHIP_STATUS_HEIGHT - SHIP_INFO_HEIGHT - 2); DrawFilledRectangle (&r); @@ -201,7 +212,7 @@ SetContextForeGroundColor ( BUILD_COLOR (MAKE_RGB15 (0x10, 0x10, 0x10), 0x19)); r.corner.x = STATUS_WIDTH - 1; - r.corner.y = SHIP_INFO_HEIGHT + y; + r.corner.y = y_offs + SHIP_INFO_HEIGHT; r.extent.width = 1; r.extent.height = SHIP_STATUS_HEIGHT - SHIP_INFO_HEIGHT; DrawFilledRectangle (&r); @@ -209,7 +220,7 @@ DrawFilledRectangle (&r); r.corner.x = 1; r.extent.width = STATUS_WIDTH - 2; - r.corner.y = (SHIP_STATUS_HEIGHT - 2) + y; + r.corner.y = y_offs + (SHIP_STATUS_HEIGHT - 2); r.extent.height = 1; DrawFilledRectangle (&r); r.corner.x = 0; @@ -217,63 +228,59 @@ ++r.corner.y; DrawFilledRectangle (&r); - { - SetContextForeGroundColor ( - BUILD_COLOR (MAKE_RGB15 (0x08, 0x08, 0x08), 0x1F)); - r.corner.x = 59; - r.corner.y = y_offs; - r.extent.width = 1; - r.extent.height = 30; - DrawFilledRectangle (&r); - r.corner.x = 3; - r.corner.y += 30; - r.extent.width = 57; - r.extent.height = 1; - DrawFilledRectangle (&r); + y = y_offs + CAPTAIN_YOFFS; - SetContextForeGroundColor ( - BUILD_COLOR (MAKE_RGB15 (0x10, 0x10, 0x10), 0x19)); - r.corner.x = 3; - r.extent.width = 57; - r.corner.y = y_offs - 1; - r.extent.height = 1; - DrawFilledRectangle (&r); - r.corner.x = 3; - r.extent.width = 1; - r.corner.y = y_offs; - r.extent.height = 30; - DrawFilledRectangle (&r); + SetContextForeGroundColor ( + BUILD_COLOR (MAKE_RGB15 (0x08, 0x08, 0x08), 0x1F)); + r.corner.x = 59; + r.corner.y = y; + r.extent.width = 1; + r.extent.height = 30; + DrawFilledRectangle (&r); + r.corner.x = 3; + r.corner.y += 30; + r.extent.width = 57; + r.extent.height = 1; + DrawFilledRectangle (&r); - s.frame = RDPtr->ship_data.captain_control.background; - s.origin.x = CAPTAIN_XOFFS; - s.origin.y = y_offs; - DrawStamp (&s); - } + SetContextForeGroundColor ( + BUILD_COLOR (MAKE_RGB15 (0x10, 0x10, 0x10), 0x19)); + r.corner.x = 3; + r.extent.width = 57; + r.corner.y = y - 1; + r.extent.height = 1; + DrawFilledRectangle (&r); + r.corner.x = 3; + r.extent.width = 1; + r.corner.y = y; + r.extent.height = 30; + DrawFilledRectangle (&r); - if (StarShipPtr->captains_name_index == 0) - { - if (RDPtr->ship_info.ship_flags & GOOD_GUY) - { - // SIS - TEXT t; + s.frame = RDPtr->ship_data.captain_control.background; + s.origin.x = CAPTAIN_XOFFS; + s.origin.y = y; + DrawStamp (&s); - t.baseline.x = STATUS_WIDTH >> 1; - t.baseline.y = y_offs + 6; - t.align = ALIGN_CENTER; - t.pStr = GLOBAL_SIS (CommanderName); - t.CharCount = (COUNT)~0; - SetContextForeGroundColor ( - BUILD_COLOR (MAKE_RGB15 (0x00, 0x14, 0x00), 0x02)); - SetContextFont (TinyFont); - font_DrawText (&t); - } + if (StarShipPtr->captains_name_index == 0 && StarShipPtr->playerNr == 0) + { // This is SIS + TEXT t; + + t.baseline.x = STATUS_WIDTH >> 1; + t.baseline.y = y + 6; + t.align = ALIGN_CENTER; + t.pStr = GLOBAL_SIS (CommanderName); + t.CharCount = (COUNT)~0; + SetContextForeGroundColor ( + BUILD_COLOR (MAKE_RGB15 (0x00, 0x14, 0x00), 0x02)); + SetContextFont (TinyFont); + font_DrawText (&t); } if (RDPtr->ship_info.max_crew > MAX_CREW_SIZE || RDPtr->ship_info.ship_flags & PLAYER_CAPTAIN) { // All crew doesn't fit in the graphics; print a number. // Always print a number for the SIS in the full game. - DrawBattleCrewAmount (&RDPtr->ship_info); + DrawBattleCrewAmount (&RDPtr->ship_info, y_offs); } UnbatchGraphics (); @@ -313,7 +320,8 @@ StarShipPtr->energy_counter = StarShipPtr->RaceDescPtr->characteristics.energy_wait; - DeltaStatistics (ShipInfoPtr, 0, energy_delta); + DeltaStatistics (ShipInfoPtr, status_y_offsets[StarShipPtr->playerNr], + 0, energy_delta); } return (retval); @@ -354,7 +362,8 @@ } } - DeltaStatistics (ShipInfoPtr, crew_delta, 0); + DeltaStatistics (ShipInfoPtr, status_y_offsets[StarShipPtr->playerNr], + crew_delta, 0); return (retval); } @@ -365,9 +374,8 @@ STARSHIP *StarShipPtr; GetElementStarShip (ShipPtr, &StarShipPtr); - if (StarShipPtr->captains_name_index - || (StarShipPtr->RaceDescPtr->ship_info.ship_flags & GOOD_GUY)) - { + if (StarShipPtr->captains_name_index || StarShipPtr->playerNr == 0) + { // All except Sa-Matra, no captain's window there STATUS_FLAGS old_status_flags, cur_status_flags; CAPTAIN_STUFF *CSPtr; @@ -379,9 +387,7 @@ old_status_flags &= (LEFT | RIGHT | THRUST | WEAPON | SPECIAL); if (old_status_flags) { - CaptainsWindow (CSPtr, - (StarShipPtr->RaceDescPtr->ship_info.ship_flags & GOOD_GUY) ? - GOOD_GUY_YOFFS : BAD_GUY_YOFFS, + CaptainsWindow (CSPtr, status_y_offsets[StarShipPtr->playerNr], old_status_flags, cur_status_flags, 1); } } @@ -393,16 +399,14 @@ STARSHIP *StarShipPtr; GetElementStarShip (ShipPtr, &StarShipPtr); - if (StarShipPtr->captains_name_index - || (StarShipPtr->RaceDescPtr->ship_info.ship_flags & GOOD_GUY)) - { + if (StarShipPtr->captains_name_index || StarShipPtr->playerNr == 0) + { // All except Sa-Matra, no captain's window there COORD y; STATUS_FLAGS cur_status_flags, old_status_flags; cur_status_flags = StarShipPtr->cur_status_flags; - y = (StarShipPtr->RaceDescPtr->ship_info.ship_flags & GOOD_GUY) ? - GOOD_GUY_YOFFS : BAD_GUY_YOFFS; + y = status_y_offsets[StarShipPtr->playerNr]; if (ShipPtr->crew_level == 0) { Modified: trunk/sc2/src/uqm/status.h =================================================================== --- trunk/sc2/src/uqm/status.h 2009-10-30 22:33:09 UTC (rev 3265) +++ trunk/sc2/src/uqm/status.h 2009-10-31 00:57:09 UTC (rev 3266) @@ -43,14 +43,19 @@ #define BATTLE_CREW_X 10 #define BATTLE_CREW_Y (64 - SAFE_Y) +extern COORD status_y_offsets[]; + +extern void InitStatusOffsets (void); + extern void DrawCrewFuelString (COORD y, SIZE state); extern void ClearShipStatus (COORD y); extern void OutlineShipStatus (COORD y); -extern void InitShipStatus (SHIP_INFO *ShipInfoPtr, BYTE captains_name_index, +extern void InitShipStatus (SHIP_INFO *ShipInfoPtr, STARSHIP *StarShipPtr, RECT *pClipRect); -extern void DeltaStatistics (SHIP_INFO *ShipInfoPtr, SIZE crew_delta, - SIZE energy_delta); -extern void DrawBattleCrewAmount (SHIP_INFO *ShipInfoPtr); + // StarShipPtr or pClipRect can be NULL +extern void DeltaStatistics (SHIP_INFO *ShipInfoPtr, COORD y_offs, + SIZE crew_delta, SIZE energy_delta); +extern void DrawBattleCrewAmount (SHIP_INFO *ShipInfoPtr, COORD y_offs); extern void DrawCaptainsWindow (STARSHIP *StarShipPtr); extern BOOLEAN DeltaEnergy (ELEMENT *ElementPtr, SIZE energy_delta); Modified: trunk/sc2/src/uqm/weapon.c =================================================================== --- trunk/sc2/src/uqm/weapon.c 2009-10-30 22:33:09 UTC (rev 3265) +++ trunk/sc2/src/uqm/weapon.c 2009-10-31 00:57:09 UTC (rev 3266) @@ -287,7 +287,7 @@ or.corner.x += ObjectIntersect.IntersectStamp.origin.x; or.corner.y += ObjectIntersect.IntersectStamp.origin.y; InitShipStatus (&StarShipPtr->RaceDescPtr->ship_info, - StarShipPtr->captains_name_index, &or); + StarShipPtr, &or); } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |