Dynamically compute the number of stars in the array.
This commit is contained in:
+1
-1
@@ -483,7 +483,7 @@ InterplanetaryTransition (ELEMENT *ElementPtr)
|
|||||||
COUNT index;
|
COUNT index;
|
||||||
const POINT portal_pt[] = QUASISPACE_PORTALS_HYPERSPACE_ENDPOINTS;
|
const POINT portal_pt[] = QUASISPACE_PORTALS_HYPERSPACE_ENDPOINTS;
|
||||||
|
|
||||||
index = CurStarDescPtr - &star_array[NUM_SOLAR_SYSTEMS + 1];
|
index = CurStarDescPtr - &star_array[GetStarCount() + 1];
|
||||||
GLOBAL_SIS (log_x) = UNIVERSE_TO_LOGX (portal_pt[index].x);
|
GLOBAL_SIS (log_x) = UNIVERSE_TO_LOGX (portal_pt[index].x);
|
||||||
GLOBAL_SIS (log_y) = UNIVERSE_TO_LOGY (portal_pt[index].y);
|
GLOBAL_SIS (log_y) = UNIVERSE_TO_LOGY (portal_pt[index].y);
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,9 @@
|
|||||||
#include "planets/elemdata.h"
|
#include "planets/elemdata.h"
|
||||||
|
|
||||||
|
|
||||||
|
// This array has to be sorted in Y coordinate order then X coordinate order.
|
||||||
|
// Items out of order can cause crashes (better, actually) or "ghost"
|
||||||
|
// stars in the map that cannot be entered.
|
||||||
STAR_DESC starmap_array[] =
|
STAR_DESC starmap_array[] =
|
||||||
{
|
{
|
||||||
// postfix name index (like 'Normae')
|
// postfix name index (like 'Normae')
|
||||||
@@ -572,6 +575,24 @@ STAR_DESC starmap_array[] =
|
|||||||
{{MAX_X_UNIVERSE << 1, MAX_Y_UNIVERSE << 1}, 0, 0, 0, 0},
|
{{MAX_X_UNIVERSE << 1, MAX_Y_UNIVERSE << 1}, 0, 0, 0, 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
COUNT
|
||||||
|
GetStarCount( void )
|
||||||
|
{
|
||||||
|
static bool ready= false;
|
||||||
|
static COUNT rv= 0;
|
||||||
|
|
||||||
|
while( !ready )
|
||||||
|
{
|
||||||
|
if( starmap_array[ rv ].star_pt.x == MAX_X_UNIVERSE << 1
|
||||||
|
&& starmap_array[ rv ].star_pt.y == MAX_Y_UNIVERSE << 1 ) break;
|
||||||
|
++rv;
|
||||||
|
}
|
||||||
|
ready= true;
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
const BYTE element_array[NUMBER_OF_ELEMENTS] =
|
const BYTE element_array[NUMBER_OF_ELEMENTS] =
|
||||||
{
|
{
|
||||||
COMMON, /* HYDROGEN */
|
COMMON, /* HYDROGEN */
|
||||||
|
|||||||
@@ -331,7 +331,7 @@ DrawStarMap (COUNT race_update, RECT *pClipRect)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SDPtr = &star_array[NUM_SOLAR_SYSTEMS + 1];
|
SDPtr = &star_array[GetStarCount() + 1];
|
||||||
SetContextForeGroundColor (
|
SetContextForeGroundColor (
|
||||||
BUILD_COLOR (MAKE_RGB15 (0x00, 0x0B, 0x00), 0x6D));
|
BUILD_COLOR (MAKE_RGB15 (0x00, 0x0B, 0x00), 0x6D));
|
||||||
SetContextBackGroundColor (
|
SetContextBackGroundColor (
|
||||||
@@ -817,7 +817,7 @@ typedef struct starsearch_state
|
|||||||
int PrefixLen;
|
int PrefixLen;
|
||||||
int ClusterLen;
|
int ClusterLen;
|
||||||
int ClusterPos;
|
int ClusterPos;
|
||||||
int SortedStars[NUM_SOLAR_SYSTEMS];
|
int *SortedStars;
|
||||||
} STAR_SEARCH_STATE;
|
} STAR_SEARCH_STATE;
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@@ -849,10 +849,10 @@ SortStarsOnName (STAR_SEARCH_STATE *pSS)
|
|||||||
int i;
|
int i;
|
||||||
int *sorted = pSS->SortedStars;
|
int *sorted = pSS->SortedStars;
|
||||||
|
|
||||||
for (i = 0; i < NUM_SOLAR_SYSTEMS; i++)
|
for (i = 0; i < GetStarCount(); i++)
|
||||||
sorted[i] = i;
|
sorted[i] = i;
|
||||||
|
|
||||||
qsort (sorted, NUM_SOLAR_SYSTEMS, sizeof (int), compStarName);
|
qsort (sorted, GetStarCount(), sizeof (int), compStarName);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -917,7 +917,7 @@ SkipStarCluster (int *sortedStars, int istar)
|
|||||||
{
|
{
|
||||||
int Postfix = star_array[sortedStars[istar]].Postfix;
|
int Postfix = star_array[sortedStars[istar]].Postfix;
|
||||||
|
|
||||||
for (++istar; istar < NUM_SOLAR_SYSTEMS &&
|
for (++istar; istar < GetStarCount() &&
|
||||||
star_array[sortedStars[istar]].Postfix == Postfix;
|
star_array[sortedStars[istar]].Postfix == Postfix;
|
||||||
++istar)
|
++istar)
|
||||||
;
|
;
|
||||||
@@ -932,7 +932,7 @@ FindNextStarIndex (STAR_SEARCH_STATE *pSS, int from, BOOLEAN WithinClust)
|
|||||||
if (!pSS->Cluster)
|
if (!pSS->Cluster)
|
||||||
return -1; // nothing to search for
|
return -1; // nothing to search for
|
||||||
|
|
||||||
for (i = from; i < NUM_SOLAR_SYSTEMS; ++i)
|
for (i = from; i < GetStarCount(); ++i)
|
||||||
{
|
{
|
||||||
STAR_DESC *SDPtr = &star_array[pSS->SortedStars[i]];
|
STAR_DESC *SDPtr = &star_array[pSS->SortedStars[i]];
|
||||||
UNICODE FullName[STAR_SEARCH_BUFSIZE];
|
UNICODE FullName[STAR_SEARCH_BUFSIZE];
|
||||||
@@ -1009,7 +1009,7 @@ FindNextStarIndex (STAR_SEARCH_STATE *pSS, int from, BOOLEAN WithinClust)
|
|||||||
break; // found one
|
break; // found one
|
||||||
}
|
}
|
||||||
|
|
||||||
return (i < NUM_SOLAR_SYSTEMS) ? i : -1;
|
return (i < GetStarCount()) ? i : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -1177,6 +1177,12 @@ DoStarSearch (MENU_STATE *pMS)
|
|||||||
pss = HMalloc (sizeof (*pss));
|
pss = HMalloc (sizeof (*pss));
|
||||||
if (!pss)
|
if (!pss)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
pss->SortedStars= HMalloc( GetStarCount() * sizeof( int * ) );
|
||||||
|
if (!pss->SortedStars)
|
||||||
|
{
|
||||||
|
HFree (pss);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
DrawSISMessageEx ("", 0, 0, DSME_SETFR);
|
DrawSISMessageEx ("", 0, 0, DSME_SETFR);
|
||||||
|
|
||||||
@@ -1202,6 +1208,7 @@ DoStarSearch (MENU_STATE *pMS)
|
|||||||
|
|
||||||
DrawSISMessageEx (pss->Text, -1, -1, DSME_CLEARFR);
|
DrawSISMessageEx (pss->Text, -1, -1, DSME_CLEARFR);
|
||||||
|
|
||||||
|
HFree (pss->SortedStars);
|
||||||
HFree (pss);
|
HFree (pss);
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
|
|||||||
@@ -36,12 +36,12 @@ FindStar (STAR_DESC *LastSDPtr, POINT *puniverse, SIZE xbounds,
|
|||||||
if (GET_GAME_STATE (ARILOU_SPACE_SIDE) <= 1)
|
if (GET_GAME_STATE (ARILOU_SPACE_SIDE) <= 1)
|
||||||
{
|
{
|
||||||
BaseSDPtr = star_array;
|
BaseSDPtr = star_array;
|
||||||
hi = NUM_SOLAR_SYSTEMS - 1;
|
hi = GetStarCount() - 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#define NUM_HYPER_VORTICES 15
|
#define NUM_HYPER_VORTICES 15
|
||||||
BaseSDPtr = &star_array[NUM_SOLAR_SYSTEMS + 1];
|
BaseSDPtr = &star_array[GetStarCount() + 1];
|
||||||
hi = (NUM_HYPER_VORTICES + 1) - 1;
|
hi = (NUM_HYPER_VORTICES + 1) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,13 +27,16 @@ extern "C" {
|
|||||||
extern STAR_DESC *CurStarDescPtr;
|
extern STAR_DESC *CurStarDescPtr;
|
||||||
extern STAR_DESC *star_array;
|
extern STAR_DESC *star_array;
|
||||||
|
|
||||||
#define NUM_SOLAR_SYSTEMS 502
|
//#define NUM_SOLAR_SYSTEMS 503
|
||||||
|
|
||||||
extern STAR_DESC* FindStar (STAR_DESC *pLastStar, POINT *puniverse,
|
extern STAR_DESC* FindStar (STAR_DESC *pLastStar, POINT *puniverse,
|
||||||
SIZE xbounds, SIZE ybounds);
|
SIZE xbounds, SIZE ybounds);
|
||||||
|
|
||||||
extern void GetClusterName (const STAR_DESC *pSD, UNICODE buf[]);
|
extern void GetClusterName (const STAR_DESC *pSD, UNICODE buf[]);
|
||||||
|
|
||||||
|
// Defined in plandata.c
|
||||||
|
extern COUNT GetStarCount (void);
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+8
-2
@@ -54,8 +54,14 @@ typedef struct GAME_STATE_FILE GAME_STATE_FILE;
|
|||||||
|
|
||||||
#define STARINFO_FILE 0
|
#define STARINFO_FILE 0
|
||||||
//"starinfo.dat"
|
//"starinfo.dat"
|
||||||
#define STAR_BUFSIZE (NUM_SOLAR_SYSTEMS * sizeof (DWORD) \
|
// Hack for up to 4k star systems (for now)...
|
||||||
+ 3800 * (3 * sizeof (DWORD)))
|
// Each system having up to 15 planets with
|
||||||
|
// up to 5 moons each. This is somewhat
|
||||||
|
// overkill.... but I don't want to unspool
|
||||||
|
// all of the C arrays just yet. Memory
|
||||||
|
// is cheap, so let it get big...
|
||||||
|
#define STAR_BUFSIZE (4096 * sizeof (DWORD) \
|
||||||
|
+ 16 * 5 * 4096 * (3 * sizeof (DWORD)))
|
||||||
#define RANDGRPINFO_FILE 1
|
#define RANDGRPINFO_FILE 1
|
||||||
//"randgrp.dat"
|
//"randgrp.dat"
|
||||||
#define RAND_BUFSIZE (4 * 1024)
|
#define RAND_BUFSIZE (4 * 1024)
|
||||||
|
|||||||
@@ -568,7 +568,7 @@ forAllStars (void (*callback) (STAR_DESC *, void *), void *arg)
|
|||||||
int i;
|
int i;
|
||||||
extern STAR_DESC starmap_array[];
|
extern STAR_DESC starmap_array[];
|
||||||
|
|
||||||
for (i = 0; i < NUM_SOLAR_SYSTEMS; i++)
|
for (i = 0; i < GetStarCount(); i++)
|
||||||
callback (&starmap_array[i], arg);
|
callback (&starmap_array[i], arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user