Planet/system generation code cleanup: isolate generation code with an own RandomContext; generation funcs do not return the random seed anymore; move and cleanup some calculation funcs; clarify deliberate Random() truncation; other random cleanups

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3694 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2011-09-09 01:59:12 +00:00
parent 128bfaa8d4
commit d2358e1e51
51 changed files with 450 additions and 416 deletions
+4
View File
@@ -3482,6 +3482,10 @@ SOURCE=..\..\src\uqm\starmap.c
# End Source File
# Begin Source File
SOURCE=..\..\src\uqm\starmap.h
# End Source File
# Begin Source File
SOURCE=..\..\src\uqm\state.c
# End Source File
# Begin Source File
+1 -7
View File
@@ -29,13 +29,6 @@
#ifndef _RANDOM_H
#define _RANDOM_H
/* ----------------------------DEFINES------------------------------------ */
#define RAND(n) ( (int) ( (unsigned int)TFB_Random() % (n) ) )
#define SRAND(n) ( (int)TFB_Random() % (n) )
#define AND_RAND(n) ( (int)TFB_Random() & (n) )
/* ----------------------------GLOBALS/EXTERNS---------------------------- */
DWORD TFB_SeedRandom (DWORD seed);
@@ -55,6 +48,7 @@ void RandomContext_Delete (RandomContext *context);
RandomContext *RandomContext_Copy (const RandomContext *source);
DWORD RandomContext_Random (RandomContext *context);
DWORD RandomContext_SeedRandom (RandomContext *context, DWORD new_seed);
DWORD RandomContext_GetSeed (RandomContext *context);
#endif /* _RANDOM_H */
+5 -1
View File
@@ -82,4 +82,8 @@ RandomContext_SeedRandom (RandomContext *context, DWORD new_seed)
return old_seed;
}
DWORD
RandomContext_GetSeed (RandomContext *context)
{
return context->seed;
}
+1
View File
@@ -18,5 +18,6 @@ uqm_HFILES="battlecontrols.h battle.h build.h clock.h cnctdlg.h coderes.h
nameref.h oscill.h pickship.h process.h races.h resinst.h respkg.h
restart.h save.h settings.h setup.h setupmenu.h shipcont.h ship.h
sis.h sounds.h starbase.h starcon.h state.h status.h tactrans.h
starmap.h
units.h uqmdebug.h util.h velocity.h weapon.h"
+1
View File
@@ -27,6 +27,7 @@
#include "sis.h"
#include "units.h"
#include "encount.h"
#include "starmap.h"
#include "endian_uqm.h"
#include "gamestr.h"
#include "options.h"
+1
View File
@@ -22,6 +22,7 @@
#include "battlecontrols.h"
#include "build.h"
#include "colors.h"
#include "starmap.h"
#include "cons_res.h"
#include "controls.h"
#include "menustat.h"
-95
View File
@@ -93,78 +93,12 @@ struct encounter
#define GetPredEncounter(l) _GetPredLink (l)
#define GetSuccEncounter(l) _GetSuccLink (l)
enum
{
SOL_DEFINED = 1,
SHOFIXTI_DEFINED,
MAIDENS_DEFINED,
START_COLONY_DEFINED,
SPATHI_DEFINED,
ZOQFOT_DEFINED,
MELNORME0_DEFINED,
MELNORME1_DEFINED,
MELNORME2_DEFINED,
MELNORME3_DEFINED,
MELNORME4_DEFINED,
MELNORME5_DEFINED,
MELNORME6_DEFINED,
MELNORME7_DEFINED,
MELNORME8_DEFINED,
TALKING_PET_DEFINED,
CHMMR_DEFINED,
SYREEN_DEFINED,
BURVIXESE_DEFINED,
SLYLANDRO_DEFINED,
DRUUGE_DEFINED,
BOMB_DEFINED,
AQUA_HELIX_DEFINED,
SUN_DEVICE_DEFINED,
TAALO_PROTECTOR_DEFINED,
SHIP_VAULT_DEFINED,
URQUAN_WRECK_DEFINED,
VUX_BEAST_DEFINED,
SAMATRA_DEFINED,
ZOQ_SCOUT_DEFINED,
MYCON_DEFINED,
EGG_CASE0_DEFINED,
EGG_CASE1_DEFINED,
EGG_CASE2_DEFINED,
PKUNK_DEFINED,
UTWIG_DEFINED,
SUPOX_DEFINED,
YEHAT_DEFINED,
VUX_DEFINED,
ORZ_DEFINED,
THRADD_DEFINED,
RAINBOW_DEFINED,
ILWRATH_DEFINED,
ANDROSYNTH_DEFINED,
MYCON_TRAP_DEFINED
};
#define UMGAH_DEFINED TALKING_PET_DEFINED
// XXX: The stuff till EOC does not belong here
extern STAR_DESC *CurStarDescPtr;
extern STAR_DESC *star_array;
#define NUM_SOLAR_SYSTEMS 502
extern STAR_DESC* FindStar (STAR_DESC *pLastStar, POINT *puniverse,
SIZE xbounds, SIZE ybounds);
extern void GetClusterName (const STAR_DESC *pSD, UNICODE buf[]);
// <<< EOC
enum
{
HAIL = 0,
ATTACK
};
extern void EncounterBattle (void);
extern void BuildBattle (COUNT which_player);
extern COUNT InitEncounter (void);
@@ -172,35 +106,6 @@ extern COUNT UninitEncounter (void);
extern BOOLEAN FleetIsInfinite (COUNT playerNr);
extern void UpdateShipFragCrew (STARSHIP *);
// XXX: in comm.h, temporary, until solsys generation code is redone
extern COUNT InitCommunication (CONVERSATION which_comm);
extern void GenerateSOL (BYTE control);
extern void GenerateShofixti (BYTE control);
extern void GenerateColony (BYTE control);
extern void GenerateSpathi (BYTE control);
extern void GenerateZoqFotPik (BYTE control);
extern void GenerateMelnorme (BYTE control);
extern void GenerateTalkingPet (BYTE control);
extern void GenerateChmmr (BYTE control);
extern void GenerateSyreen (BYTE control);
extern void GenerateBurvixes (BYTE control);
extern void GenerateSlylandro (BYTE control);
extern void GenerateDruuge (BYTE control);
extern void GenerateUtwig (BYTE control);
extern void GenerateThradd (BYTE control);
extern void GenerateMycon (BYTE control);
extern void GenerateOrz (BYTE control);
extern void GenerateShipVault (BYTE control);
extern void GenerateUrquanWreck (BYTE control);
extern void GenerateVUX (BYTE control);
extern void GenerateSamatra (BYTE control);
extern void GenerateYehat (BYTE control);
extern void GeneratePkunk (BYTE control);
extern void GenerateSupox (BYTE control);
extern void GenerateRainbow (BYTE control);
extern void GenerateIlwrath (BYTE control);
// Last race the player battled with, or -1 if no battle took place.
// Set to -1 by some funcs to inhibit IP groups from intercepting
// the flagship.
+2 -2
View File
@@ -19,8 +19,8 @@
#include "build.h"
#include "clock.h"
// XXX: for CurStarDescPtr and XXX_DEFINED constants
#include "encount.h"
#include "starmap.h"
#include "gendef.h"
#include "globdata.h"
#include "hyper.h"
#include "libs/compiler.h"
+1 -2
View File
@@ -21,8 +21,7 @@
#include "build.h"
#include "colors.h"
#include "controls.h"
// XXX: for FindStart(), GetClusterName()
#include "encount.h"
#include "starmap.h"
#include "menustat.h"
#include "sis.h"
#include "units.h"
-1
View File
@@ -17,7 +17,6 @@
*/
#include "gendef.h"
#include "encount.h"
#include "planets/generate.h"
+53
View File
@@ -10,6 +10,59 @@ extern "C" {
const GenerateFunctions *getGenerateFunctions (BYTE Index);
enum
{
SOL_DEFINED = 1,
SHOFIXTI_DEFINED,
MAIDENS_DEFINED,
START_COLONY_DEFINED,
SPATHI_DEFINED,
ZOQFOT_DEFINED,
MELNORME0_DEFINED,
MELNORME1_DEFINED,
MELNORME2_DEFINED,
MELNORME3_DEFINED,
MELNORME4_DEFINED,
MELNORME5_DEFINED,
MELNORME6_DEFINED,
MELNORME7_DEFINED,
MELNORME8_DEFINED,
TALKING_PET_DEFINED,
CHMMR_DEFINED,
SYREEN_DEFINED,
BURVIXESE_DEFINED,
SLYLANDRO_DEFINED,
DRUUGE_DEFINED,
BOMB_DEFINED,
AQUA_HELIX_DEFINED,
SUN_DEVICE_DEFINED,
TAALO_PROTECTOR_DEFINED,
SHIP_VAULT_DEFINED,
URQUAN_WRECK_DEFINED,
VUX_BEAST_DEFINED,
SAMATRA_DEFINED,
ZOQ_SCOUT_DEFINED,
MYCON_DEFINED,
EGG_CASE0_DEFINED,
EGG_CASE1_DEFINED,
EGG_CASE2_DEFINED,
PKUNK_DEFINED,
UTWIG_DEFINED,
SUPOX_DEFINED,
YEHAT_DEFINED,
VUX_DEFINED,
ORZ_DEFINED,
THRADD_DEFINED,
RAINBOW_DEFINED,
ILWRATH_DEFINED,
ANDROSYNTH_DEFINED,
MYCON_TRAP_DEFINED
};
#define UMGAH_DEFINED TALKING_PET_DEFINED
#if defined(__cplusplus)
}
#endif
+1
View File
@@ -20,6 +20,7 @@
#include "coderes.h"
#include "encount.h"
#include "starmap.h"
#include "master.h"
#include "setup.h"
#include "units.h"
+2 -2
View File
@@ -17,8 +17,8 @@
*/
#include "build.h"
// XXX: for CurStarDescPtr and XXX_DEFINED constants
#include "encount.h"
#include "starmap.h"
#include "gendef.h"
#include "libs/file.h"
#include "globdata.h"
#include "intel.h"
+1
View File
@@ -26,6 +26,7 @@
#include "menustat.h"
// for DrawMenuStateStrings()
#include "encount.h"
#include "starmap.h"
#include "ship.h"
#include "shipcont.h"
#include "process.h"
+1
View File
@@ -23,6 +23,7 @@
#include "build.h"
#include "libs/declib.h"
#include "encount.h"
#include "starmap.h"
#include "libs/file.h"
#include "globdata.h"
#include "load.h"
+1 -2
View File
@@ -16,8 +16,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// XXX: for XXX_DEFINED constants
#include "encount.h"
#include "gendef.h"
#include "resinst.h"
#include "planets/planets.h"
#include "planets/elemdata.h"
+149 -35
View File
@@ -17,7 +17,8 @@
*/
/* ----------------------------- INCLUDES ---------------------------- */
#include "../encount.h"
#include "planets.h"
#include "uqm/starmap.h"
#include "libs/mathlib.h"
#include "libs/log.h"
/* -------------------------------- DATA -------------------------------- */
@@ -26,9 +27,6 @@
//#define DEBUG_PLANET_CALC
#define CalcMass(b) CalcFromBase (b, b)
#define CalcRadius(b) CalcFromBase (b, ((b) >> 1) + 1)
#define LOW_TEMP 0
#define MED_TEMP 500
#define HIGH_TEMP 1500
@@ -36,15 +34,6 @@
#define MED_TEMP_BONUS 25
#define HIGH_TEMP_BONUS 50
#define MAX_TECTONICS 255
#ifdef OLD
#define CalcTectonics(b,t) (CalcFromBase(b, 3 << 5) \
+ (UWORD)((t) < LOW_TEMP ? 0 : \
((t) < MED_TEMP ? LOW_TEMP_BONUS : \
((t) < HIGH_TEMP ? MED_TEMP_BONUS : \
HIGH_TEMP_BONUS))))
#else /* OLD */
#define CalcTectonics(b,t) CalcFromBase(b, 3 << 5)
#endif /* OLD */
enum
{
@@ -56,6 +45,18 @@ enum
WHITE_SUN_INTENSITY
};
static UWORD
CalcFromBase (UWORD base, UWORD variance)
{
return base + LOWORD (RandomContext_Random (SysGenRNG)) % variance;
}
static inline UWORD
CalcHalfBaseVariance (UWORD base)
{
return CalcFromBase (base, (base >> 1) + 1);
}
static void
CalcSysInfo (SYSTEM_INFO *SysInfoPtr)
{
@@ -149,7 +150,7 @@ GeneratePlanetComposition (PLANET_INFO *PlanetInfoPtr, SIZE SurfaceTemp,
PlanetInfoPtr->Weather += 1 << 5;
else if (radius > 10)
PlanetInfoPtr->Weather -= 1 << 5;
atmo = CalcFromBase (atmo, (atmo >> 1) + 1);
atmo = CalcHalfBaseVariance (atmo);
}
}
@@ -194,7 +195,7 @@ CalcTemp (SYSTEM_INFO *SysInfoPtr, SIZE radius)
bonus = COLD_BONUS;
bonus <<= HINIBBLE (SysInfoPtr->PlanetInfo.PlanDataPtr->AtmoAndDensity);
bonus = CalcFromBase (bonus, (bonus >> 1) + 1);
bonus = CalcHalfBaseVariance (bonus);
}
return (centigrade + bonus);
@@ -204,11 +205,11 @@ static COUNT
CalcRotation (PLANET_INFO *PlanetInfoPtr)
{
if (PLANSIZE (PlanetInfoPtr->PlanDataPtr->Type) == GAS_GIANT)
return ((COUNT)CalcFromBase (80, 80));
else if (((BYTE)TFB_Random () % 10) == 0)
return ((COUNT)CalcFromBase ((UWORD)50 * 240, (UWORD)200 * 240));
return CalcFromBase (80, 80);
else if (LOBYTE (RandomContext_Random (SysGenRNG)) % 10 == 0)
return CalcFromBase (50 * 240, 200 * 240);
else
return ((COUNT)CalcFromBase (150, 150));
return CalcFromBase (150, 150);
}
static SIZE
@@ -223,22 +224,137 @@ CalcTilt (void)
i = NUM_TOSSES;
do /* Using added Randomom values to give bell curve */
{
tilt += (UWORD)TFB_Random () % ((TILT_RANGE / NUM_TOSSES) + 1);
tilt += LOWORD (RandomContext_Random (SysGenRNG))
% ((TILT_RANGE / NUM_TOSSES) + 1);
} while (--i);
return (tilt);
}
// NB. Returns the RNG to the state it found it in.
DWORD
UWORD
CalcGravity (const PLANET_INFO *PlanetInfoPtr)
{
return (DWORD)PlanetInfoPtr->PlanetDensity * PlanetInfoPtr->PlanetRadius
/ 100;
}
static UWORD
CalcTectonics (UWORD base, UWORD temp)
{
UWORD tect = CalcFromBase (base, 3 << 5);
#ifdef OLD
if (temp >= HIGH_TEMP)
tect += HIGH_TEMP_BONUS;
else if (temp >= MED_TEMP)
tect += MED_TEMP_BONUS;
else if (temp >= LOW_TEMP)
tect += LOW_TEMP_BONUS;
#else /* !OLD */
(void) temp; /* silence compiler whining */
#endif /* OLD */
return tect;
}
// This code moved from planets/surface.c:CalcLifeForms()
static int
CalcLifeChance (const PLANET_INFO *PlanetInfoPtr)
{
SIZE life_var = 0;
if (PLANSIZE (PlanetInfoPtr->PlanDataPtr->Type) == GAS_GIANT)
return -1;
if (PlanetInfoPtr->SurfaceTemperature < -151)
life_var -= 300;
else if (PlanetInfoPtr->SurfaceTemperature < -51)
life_var -= 100;
else if (PlanetInfoPtr->SurfaceTemperature < 0)
life_var += 100;
else if (PlanetInfoPtr->SurfaceTemperature < 50)
life_var += 300;
else if (PlanetInfoPtr->SurfaceTemperature < 150)
life_var += 50;
else if (PlanetInfoPtr->SurfaceTemperature < 250)
life_var -= 100;
else if (PlanetInfoPtr->SurfaceTemperature < 500)
life_var -= 400;
else
life_var -= 800;
if (PlanetInfoPtr->AtmoDensity == 0)
life_var -= 1000;
else if (PlanetInfoPtr->AtmoDensity < 15)
life_var += 100;
else if (PlanetInfoPtr->AtmoDensity < 30)
life_var += 200;
else if (PlanetInfoPtr->AtmoDensity < 100)
life_var += 300;
else if (PlanetInfoPtr->AtmoDensity < 1000)
life_var += 150;
else if (PlanetInfoPtr->AtmoDensity < 2500)
;
else
life_var -= 100;
#ifndef NOTYET
life_var += 200 + 80 + 80;
#else /* NOTYET */
if (PlanetInfoPtr->SurfaceGravity < 10)
;
else if (PlanetInfoPtr->SurfaceGravity < 35)
life_var += 50;
else if (PlanetInfoPtr->SurfaceGravity < 75)
life_var += 100;
else if (PlanetInfoPtr->SurfaceGravity < 150)
life_var += 200;
else if (PlanetInfoPtr->SurfaceGravity < 400)
life_var += 50;
else if (PlanetInfoPtr->SurfaceGravity < 800)
;
else
life_var -= 100;
if (PlanetInfoPtr->Tectonics < 1)
life_var += 80;
else if (PlanetInfoPtr->Tectonics < 2)
life_var += 70;
else if (PlanetInfoPtr->Tectonics < 3)
life_var += 60;
else if (PlanetInfoPtr->Tectonics < 4)
life_var += 50;
else if (PlanetInfoPtr->Tectonics < 5)
life_var += 25;
else if (PlanetInfoPtr->Tectonics < 6)
;
else
life_var -= 100;
if (PlanetInfoPtr->Weather < 1)
life_var += 80;
else if (PlanetInfoPtr->Weather < 2)
life_var += 70;
else if (PlanetInfoPtr->Weather < 3)
life_var += 60;
else if (PlanetInfoPtr->Weather < 4)
life_var += 50;
else if (PlanetInfoPtr->Weather < 5)
life_var += 25;
else if (PlanetInfoPtr->Weather < 6)
;
else
life_var -= 100;
#endif /* NOTYET */
return life_var;
}
// Sets the SysGenRNG to the required state first.
void
DoPlanetaryAnalysis (SYSTEM_INFO *SysInfoPtr, PLANET_DESC *pPlanetDesc)
{
DWORD old_seed;
assert (pPlanetDesc->data_index != HIERARCHY_STARBASE);
if (pPlanetDesc->data_index == HIERARCHY_STARBASE)
return (0);
old_seed = TFB_SeedRandom (pPlanetDesc->rand_seed);
RandomContext_SeedRandom (SysGenRNG, pPlanetDesc->rand_seed);
CalcSysInfo (SysInfoPtr);
@@ -303,18 +419,18 @@ DoPlanetaryAnalysis (SYSTEM_INFO *SysInfoPtr, PLANET_DESC *pPlanetDesc)
}
SysInfoPtr->PlanetInfo.PlanetDensity +=
(SysInfoPtr->PlanetInfo.PlanetDensity / 20)
- ((COUNT)TFB_Random ()
- (LOWORD (RandomContext_Random (SysGenRNG))
% (SysInfoPtr->PlanetInfo.PlanetDensity / 10));
switch (PLANSIZE (SysInfoPtr->PlanetInfo.PlanDataPtr->Type))
{
case SMALL_ROCKY_WORLD:
#define SMALL_RADIUS 25
SysInfoPtr->PlanetInfo.PlanetRadius = CalcRadius (SMALL_RADIUS);
SysInfoPtr->PlanetInfo.PlanetRadius = CalcHalfBaseVariance (SMALL_RADIUS);
break;
case LARGE_ROCKY_WORLD:
#define LARGE_RADIUS 75
SysInfoPtr->PlanetInfo.PlanetRadius = CalcRadius (LARGE_RADIUS);
SysInfoPtr->PlanetInfo.PlanetRadius = CalcHalfBaseVariance (LARGE_RADIUS);
break;
case GAS_GIANT:
#define MIN_GAS_RADIUS 300
@@ -325,9 +441,7 @@ DoPlanetaryAnalysis (SYSTEM_INFO *SysInfoPtr, PLANET_DESC *pPlanetDesc)
}
SysInfoPtr->PlanetInfo.RotationPeriod = CalcRotation (&SysInfoPtr->PlanetInfo);
SysInfoPtr->PlanetInfo.SurfaceGravity =
CalcGravity (SysInfoPtr->PlanetInfo.PlanetDensity,
SysInfoPtr->PlanetInfo.PlanetRadius);
SysInfoPtr->PlanetInfo.SurfaceGravity = CalcGravity (&SysInfoPtr->PlanetInfo);
SysInfoPtr->PlanetInfo.AxialTilt = CalcTilt ();
if ((SysInfoPtr->PlanetInfo.Tectonics =
CalcTectonics (SysInfoPtr->PlanetInfo.PlanDataPtr->BaseTectonics,
@@ -341,6 +455,8 @@ DoPlanetaryAnalysis (SYSTEM_INFO *SysInfoPtr, PLANET_DESC *pPlanetDesc)
SysInfoPtr->PlanetInfo.Tectonics >>= 5;
SysInfoPtr->PlanetInfo.Weather >>= 5;
SysInfoPtr->PlanetInfo.LifeChance = CalcLifeChance (&SysInfoPtr->PlanetInfo);
#ifdef DEBUG_PLANET_CALC
radius = (SIZE)((DWORD)UNSCALE_RADIUS (radius) * 100 / UNSCALE_RADIUS (EARTH_RADIUS));
log_add (log_Debug, "\tOrbital Distance : %d.%02d AU", radius / 100, radius % 100);
@@ -404,7 +520,5 @@ DoPlanetaryAnalysis (SYSTEM_INFO *SysInfoPtr, PLANET_DESC *pPlanetDesc)
}
#endif /* DEBUG_PLANET_CALC */
}
return (TFB_SeedRandom (old_seed));
}
+2
View File
@@ -18,6 +18,8 @@
#include "../build.h"
#include "../colors.h"
#include "../gendef.h"
#include "../starmap.h"
#include "../encount.h"
#include "../gamestr.h"
#include "../controls.h"
+6 -7
View File
@@ -85,7 +85,7 @@ GenerateBurvixese_generateMoons (SOLARSYS_STATE *solarSys, PLANET_DESC *planet)
solarSys->MoonDesc[0].data_index = SELENIC_WORLD;
solarSys->MoonDesc[0].radius = MIN_MOON_RADIUS
+ (MAX_MOONS - 1) * MOON_DELTA;
rand_val = TFB_Random ();
rand_val = RandomContext_Random (SysGenRNG);
angle = NORMALIZE_ANGLE (LOWORD (rand_val));
solarSys->MoonDesc[0].location.x =
COSINE (angle, solarSys->MoonDesc[0].radius);
@@ -98,18 +98,17 @@ GenerateBurvixese_generateMoons (SOLARSYS_STATE *solarSys, PLANET_DESC *planet)
static bool
GenerateBurvixese_generateOrbital (SOLARSYS_STATE *solarSys, PLANET_DESC *world)
{
COUNT i;
DWORD rand_val;
rand_val = DoPlanetaryAnalysis (&solarSys->SysInfo, world);
DoPlanetaryAnalysis (&solarSys->SysInfo, world);
rand_val = RandomContext_GetSeed (SysGenRNG);
solarSys->SysInfo.PlanetInfo.ScanSeed[BIOLOGICAL_SCAN] = rand_val;
i = (COUNT)~0;
rand_val = GenerateLifeForms (&solarSys->SysInfo, &i);
GenerateLifeForms (&solarSys->SysInfo, GENERATE_ALL);
rand_val = RandomContext_GetSeed (SysGenRNG);
solarSys->SysInfo.PlanetInfo.ScanSeed[MINERAL_SCAN] = rand_val;
i = (COUNT)~0;
GenerateMineralDeposits (&solarSys->SysInfo, &i);
GenerateMineralDeposits (&solarSys->SysInfo, GENERATE_ALL);
solarSys->SysInfo.PlanetInfo.ScanSeed[ENERGY_SCAN] = rand_val;
+1 -1
View File
@@ -77,7 +77,7 @@ GenerateChmmr_generateMoons (SOLARSYS_STATE *solarSys, PLANET_DESC *planet)
solarSys->MoonDesc[0].data_index = HIERARCHY_STARBASE;
solarSys->MoonDesc[0].radius = MIN_MOON_RADIUS;
rand_val = TFB_Random ();
rand_val = RandomContext_Random (SysGenRNG);
angle = NORMALIZE_ANGLE (LOWORD (rand_val));
solarSys->MoonDesc[0].location.x =
COSINE (angle, solarSys->MoonDesc[0].radius);
+11 -16
View File
@@ -126,7 +126,6 @@ GenerateDefault_generateName (SOLARSYS_STATE *solarSys, PLANET_DESC *world)
bool
GenerateDefault_generateOrbital (SOLARSYS_STATE *solarSys, PLANET_DESC *world)
{
COUNT i;
DWORD rand_val;
SYSTEM_INFO *sysInfo;
@@ -146,15 +145,15 @@ GenerateDefault_generateOrbital (SOLARSYS_STATE *solarSys, PLANET_DESC *world)
sysInfo = &solarSys->SysInfo;
rand_val = DoPlanetaryAnalysis (sysInfo, world);
DoPlanetaryAnalysis (sysInfo, world);
rand_val = RandomContext_GetSeed (SysGenRNG);
sysInfo->PlanetInfo.ScanSeed[BIOLOGICAL_SCAN] = rand_val;
i = (COUNT)~0;
rand_val = GenerateLifeForms (sysInfo, &i);
GenerateLifeForms (sysInfo, GENERATE_ALL);
rand_val = RandomContext_GetSeed (SysGenRNG);
sysInfo->PlanetInfo.ScanSeed[MINERAL_SCAN] = rand_val;
i = (COUNT)~0;
GenerateMineralDeposits (sysInfo, &i);
GenerateMineralDeposits (sysInfo, GENERATE_ALL);
sysInfo->PlanetInfo.ScanSeed[ENERGY_SCAN] = rand_val;
LoadPlanet (NULL);
@@ -166,9 +165,8 @@ COUNT
GenerateDefault_generateMinerals (SOLARSYS_STATE *solarSys,
PLANET_DESC *world, COUNT whichNode)
{
GenerateMineralDeposits (&solarSys->SysInfo, &whichNode);
return GenerateMineralDeposits (&solarSys->SysInfo, whichNode);
(void) world;
return whichNode;
}
bool
@@ -209,9 +207,8 @@ COUNT
GenerateDefault_generateLife (SOLARSYS_STATE *solarSys, PLANET_DESC *world,
COUNT whichNode)
{
GenerateLifeForms (&solarSys->SysInfo, &whichNode);
return GenerateLifeForms (&solarSys->SysInfo, whichNode);
(void) world;
return whichNode;
}
bool
@@ -229,17 +226,15 @@ COUNT
GenerateDefault_generateArtifact (SOLARSYS_STATE *solarSys, COUNT whichNode)
{
// Generate an energy node at a random location
GenerateRandomNodes (&solarSys->SysInfo, ENERGY_SCAN, 1, 0, &whichNode);
return whichNode;
return GenerateRandomNodes (&solarSys->SysInfo, ENERGY_SCAN, 1, 0, whichNode);
}
COUNT
GenerateDefault_generateRuins (SOLARSYS_STATE *solarSys, COUNT whichNode)
{
// Generate a standard spread of city ruins of a destroyed civilization
GenerateRandomNodes (&solarSys->SysInfo, ENERGY_SCAN, NUM_RACE_RUINS,
0, &whichNode);
return whichNode;
return GenerateRandomNodes (&solarSys->SysInfo, ENERGY_SCAN, NUM_RACE_RUINS,
0, whichNode);
}
static inline void
@@ -309,7 +304,7 @@ GeneratePlanets (SOLARSYS_STATE *solarSys)
BYTE num_moons;
BYTE type;
rand_val = TFB_Random ();
rand_val = RandomContext_Random (SysGenRNG);
byte_val = LOBYTE (rand_val);
num_moons = 0;
+2 -1
View File
@@ -18,7 +18,8 @@
#include "genall.h"
#include "../../build.h"
#include "../../encount.h"
#include "../../gendef.h"
#include "../../starmap.h"
#include "../../globdata.h"
#include "../../state.h"
#include "libs/log.h"
+2 -1
View File
@@ -22,7 +22,8 @@
#include "../scan.h"
#include "../../build.h"
#include "../../comm.h"
#include "../../encount.h"
#include "../../gendef.h"
#include "../../starmap.h"
#include "../../globdata.h"
#include "../../ipdisp.h"
#include "../../nameref.h"
+2 -1
View File
@@ -21,7 +21,8 @@
#include "../planets.h"
#include "../../build.h"
#include "../../comm.h"
#include "../../encount.h"
#include "../../gendef.h"
#include "../../starmap.h"
#include "../../globdata.h"
#include "../../ipdisp.h"
#include "../../nameref.h"
+1
View File
@@ -21,6 +21,7 @@
#include "../../build.h"
#include "../../comm.h"
#include "../../encount.h"
#include "../../starmap.h"
#include "../../globdata.h"
#include "../../ipdisp.h"
#include "../../nameref.h"
+2 -1
View File
@@ -18,7 +18,8 @@
#include "genall.h"
#include "../planets.h"
#include "../../encount.h"
#include "../../gendef.h"
#include "../../starmap.h"
#include "../../globdata.h"
#include "libs/mathlib.h"
+1 -1
View File
@@ -150,7 +150,7 @@ GenerateSaMatra_generateMoons (SOLARSYS_STATE *solarSys, PLANET_DESC *planet)
solarSys->MoonDesc[0].data_index = SA_MATRA;
solarSys->MoonDesc[0].radius = MIN_MOON_RADIUS + (2 * MOON_DELTA);
rand_val = TFB_Random ();
rand_val = RandomContext_Random (SysGenRNG);
angle = NORMALIZE_ANGLE (LOWORD (rand_val));
solarSys->MoonDesc[0].location.x =
COSINE (angle, solarSys->MoonDesc[0].radius);
+17 -18
View File
@@ -108,7 +108,7 @@ GenerateSol_generatePlanets (SOLARSYS_STATE *solarSys)
COUNT planetI;
#define SOL_SEED 334241042L
TFB_SeedRandom (SOL_SEED);
RandomContext_SeedRandom (SysGenRNG, SOL_SEED);
solarSys->SunDesc[0].NumPlanets = 9;
for (planetI = 0; planetI < 9; ++planetI)
@@ -118,7 +118,8 @@ GenerateSol_generatePlanets (SOLARSYS_STATE *solarSys)
UWORD word_val;
PLANET_DESC *pCurDesc = &solarSys->PlanetDesc[planetI];
pCurDesc->rand_seed = rand_val = TFB_Random ();
pCurDesc->rand_seed = RandomContext_Random (SysGenRNG);
rand_val = pCurDesc->rand_seed;
word_val = LOWORD (rand_val);
angle = NORMALIZE_ANGLE ((COUNT)HIBYTE (word_val));
@@ -208,7 +209,7 @@ GenerateSol_generateMoons (SOLARSYS_STATE *solarSys, PLANET_DESC *planet)
solarSys->MoonDesc[1].data_index = SELENIC_WORLD;
solarSys->MoonDesc[1].radius = MIN_MOON_RADIUS
+ (MAX_MOONS - 1) * MOON_DELTA;
rand_val = TFB_Random ();
rand_val = RandomContext_Random (SysGenRNG);
angle = NORMALIZE_ANGLE (LOWORD (rand_val));
solarSys->MoonDesc[1].location.x =
COSINE (angle, solarSys->MoonDesc[1].radius);
@@ -269,15 +270,12 @@ GenerateSol_generateOrbital (SOLARSYS_STATE *solarSys, PLANET_DESC *world)
return true;
}
rand_val = DoPlanetaryAnalysis (&solarSys->SysInfo, world);
if (rand_val)
{
COUNT i;
DoPlanetaryAnalysis (&solarSys->SysInfo, world);
rand_val = RandomContext_GetSeed (SysGenRNG);
solarSys->SysInfo.PlanetInfo.ScanSeed[MINERAL_SCAN] = rand_val;
i = (COUNT)~0;
rand_val = GenerateMineralDeposits (&solarSys->SysInfo, &i);
}
solarSys->SysInfo.PlanetInfo.ScanSeed[MINERAL_SCAN] = rand_val;
GenerateMineralDeposits (&solarSys->SysInfo, GENERATE_ALL);
rand_val = RandomContext_GetSeed (SysGenRNG);
planetNr = planetIndex (solarSys, world);
if (worldIsPlanet (solarSys, world))
@@ -405,8 +403,7 @@ GenerateSol_generateOrbital (SOLARSYS_STATE *solarSys, PLANET_DESC *world)
}
solarSys->SysInfo.PlanetInfo.SurfaceGravity =
CalcGravity (solarSys->SysInfo.PlanetInfo.PlanetDensity,
solarSys->SysInfo.PlanetInfo.PlanetRadius);
CalcGravity (&solarSys->SysInfo.PlanetInfo);
LoadPlanet (planetNr == 2 ?
CaptureDrawable (LoadGraphic (EARTH_MASK_ANIM)) : NULL);
}
@@ -421,6 +418,10 @@ GenerateSol_generateOrbital (SOLARSYS_STATE *solarSys, PLANET_DESC *world)
switch (planetNr)
{
case 2: /* moons of EARTH */
// NOTE: Even though we save the seed here, it is irrelevant.
// The seed will be used to randomly place the tractors, but
// since they are mobile, they will be moved to different
// locations not governed by this seed.
solarSys->SysInfo.PlanetInfo.ScanSeed[BIOLOGICAL_SCAN] =
rand_val;
@@ -505,8 +506,7 @@ GenerateSol_generateOrbital (SOLARSYS_STATE *solarSys, PLANET_DESC *world)
}
solarSys->SysInfo.PlanetInfo.SurfaceGravity =
CalcGravity (solarSys->SysInfo.PlanetInfo.PlanetDensity,
solarSys->SysInfo.PlanetInfo.PlanetRadius);
CalcGravity (&solarSys->SysInfo.PlanetInfo);
LoadPlanet (NULL);
}
@@ -601,9 +601,8 @@ GenerateSol_generateLife (SOLARSYS_STATE *solarSys, PLANET_DESC *world,
if (matchWorld (solarSys, world, 2, 1))
{
/* Earth Moon */
GenerateRandomNodes (&solarSys->SysInfo, BIOLOGICAL_SCAN, 10,
NUM_CREATURE_TYPES + 1, &whichNode);
return whichNode;
return GenerateRandomNodes (&solarSys->SysInfo, BIOLOGICAL_SCAN, 10,
NUM_CREATURE_TYPES + 1, whichNode);
}
return 0;
+14 -15
View File
@@ -102,7 +102,7 @@ GenerateSpathi_generateMoons (SOLARSYS_STATE *solarSys, PLANET_DESC *planet)
solarSys->MoonDesc[0].data_index = PELLUCID_WORLD;
solarSys->MoonDesc[0].radius = MIN_MOON_RADIUS + MOON_DELTA;
angle = NORMALIZE_ANGLE (LOWORD (TFB_Random ()));
angle = NORMALIZE_ANGLE (LOWORD (RandomContext_Random (SysGenRNG)));
solarSys->MoonDesc[0].location.x =
COSINE (angle, solarSys->MoonDesc[0].radius);
solarSys->MoonDesc[0].location.y =
@@ -116,7 +116,6 @@ static bool
GenerateSpathi_generateOrbital (SOLARSYS_STATE *solarSys, PLANET_DESC *world)
{
DWORD rand_val;
COUNT i;
if (matchWorld (solarSys, world, 0, 0))
{
@@ -144,15 +143,16 @@ GenerateSpathi_generateOrbital (SOLARSYS_STATE *solarSys, PLANET_DESC *world)
}
return true;
}
rand_val = DoPlanetaryAnalysis (&solarSys->SysInfo, world);
DoPlanetaryAnalysis (&solarSys->SysInfo, world);
rand_val = RandomContext_GetSeed (SysGenRNG);
solarSys->SysInfo.PlanetInfo.ScanSeed[BIOLOGICAL_SCAN] = rand_val;
i = (COUNT)~0;
rand_val = GenerateLifeForms (&solarSys->SysInfo, &i);
GenerateLifeForms (&solarSys->SysInfo, GENERATE_ALL);
rand_val = RandomContext_GetSeed (SysGenRNG);
solarSys->SysInfo.PlanetInfo.ScanSeed[MINERAL_SCAN] = rand_val;
i = (COUNT)~0;
GenerateMineralDeposits (&solarSys->SysInfo, &i);
GenerateMineralDeposits (&solarSys->SysInfo, GENERATE_ALL);
solarSys->SysInfo.PlanetInfo.ScanSeed[ENERGY_SCAN] = rand_val;
@@ -181,18 +181,18 @@ GenerateSpathi_generateOrbital (SOLARSYS_STATE *solarSys, PLANET_DESC *world)
else if (matchWorld (solarSys, world, 0, MATCH_PLANET))
{
/* visiting Spathiwa */
rand_val = DoPlanetaryAnalysis (&solarSys->SysInfo, world);
DoPlanetaryAnalysis (&solarSys->SysInfo, world);
rand_val = RandomContext_GetSeed (SysGenRNG);
solarSys->SysInfo.PlanetInfo.ScanSeed[MINERAL_SCAN] = rand_val;
i = (COUNT)~0;
rand_val = GenerateMineralDeposits (&solarSys->SysInfo, &i);
GenerateMineralDeposits (&solarSys->SysInfo, GENERATE_ALL);
rand_val = RandomContext_GetSeed (SysGenRNG);
solarSys->SysInfo.PlanetInfo.ScanSeed[BIOLOGICAL_SCAN] = rand_val;
solarSys->SysInfo.PlanetInfo.PlanetRadius = 120;
solarSys->SysInfo.PlanetInfo.SurfaceGravity =
CalcGravity (solarSys->SysInfo.PlanetInfo.PlanetDensity,
solarSys->SysInfo.PlanetInfo.PlanetRadius);
CalcGravity (&solarSys->SysInfo.PlanetInfo);
solarSys->SysInfo.PlanetInfo.Weather = 0;
solarSys->SysInfo.PlanetInfo.Tectonics = 0;
solarSys->SysInfo.PlanetInfo.SurfaceTemperature = 31;
@@ -253,9 +253,8 @@ GenerateSpathi_generateLife (SOLARSYS_STATE *solarSys, PLANET_DESC *world,
if (matchWorld (solarSys, world, 0, MATCH_PLANET))
{
#define NUM_EVIL_ONES 32
GenerateRandomNodes (&solarSys->SysInfo, BIOLOGICAL_SCAN, NUM_EVIL_ONES,
NUM_CREATURE_TYPES, &whichNode);
return whichNode;
return GenerateRandomNodes (&solarSys->SysInfo, BIOLOGICAL_SCAN, NUM_EVIL_ONES,
NUM_CREATURE_TYPES, whichNode);
}
return 0;
+2 -1
View File
@@ -21,7 +21,8 @@
#include "../planets.h"
#include "../../build.h"
#include "../../comm.h"
#include "../../encount.h"
#include "../../gendef.h"
#include "../../starmap.h"
#include "../../globdata.h"
#include "../../ipdisp.h"
#include "../../nameref.h"
+2 -1
View File
@@ -21,7 +21,8 @@
#include "../planets.h"
#include "../../build.h"
#include "../../comm.h"
#include "../../encount.h"
#include "../../gendef.h"
#include "../../starmap.h"
#include "../../globdata.h"
#include "../../ipdisp.h"
#include "../../nameref.h"
+4 -9
View File
@@ -22,7 +22,8 @@
#include "../planets.h"
#include "../../build.h"
#include "../../comm.h"
#include "../../encount.h"
#include "../../gendef.h"
#include "../../starmap.h"
#include "../../globdata.h"
#include "../../ipdisp.h"
#include "../../nameref.h"
@@ -276,9 +277,8 @@ GenerateVux_generateLife (SOLARSYS_STATE *solarSys, PLANET_DESC *world,
&& matchWorld (solarSys, world, 0, MATCH_PLANET))
{
COUNT i;
DWORD old_rand;
old_rand = TFB_SeedRandom (
RandomContext_SeedRandom (SysGenRNG,
solarSys->SysInfo.PlanetInfo.ScanSeed[BIOLOGICAL_SCAN]);
for (i = 0; i <= whichNode && i < 12; ++i)
@@ -292,8 +292,6 @@ GenerateVux_generateLife (SOLARSYS_STATE *solarSys, PLANET_DESC *world,
solarSys->SysInfo.PlanetInfo.CurType = 18;
}
TFB_SeedRandom (old_rand);
return 12; // only matters when count is requested
}
@@ -301,9 +299,8 @@ GenerateVux_generateLife (SOLARSYS_STATE *solarSys, PLANET_DESC *world,
&& matchWorld (solarSys, world, 0, MATCH_PLANET))
{
COUNT i;
DWORD old_rand;
old_rand = TFB_SeedRandom (
RandomContext_SeedRandom (SysGenRNG,
solarSys->SysInfo.PlanetInfo.ScanSeed[BIOLOGICAL_SCAN]);
for (i = 0; i <= whichNode && i < 11; ++i)
@@ -319,8 +316,6 @@ GenerateVux_generateLife (SOLARSYS_STATE *solarSys, PLANET_DESC *world,
solarSys->SysInfo.PlanetInfo.CurType = 8;
}
TFB_SeedRandom (old_rand);
return 11; // only matters when count is requested
}
+3 -2
View File
@@ -43,9 +43,10 @@ DeltaTopography (COUNT num_iterations, SBYTE *DepthArray, RECT *pRect,
DWORD rand_val;
SBYTE *lpDst;
depth_delta = ((((SIZE)TFB_Random () & 1) << 1) - 1) * depth_delta;
if ((RandomContext_Random (SysGenRNG) & 1) == 0)
depth_delta = -depth_delta;
rand_val = TFB_Random ();
rand_val = RandomContext_Random (SysGenRNG);
w1 = LOWORD (rand_val);
w2 = HIWORD (rand_val);
-2
View File
@@ -23,8 +23,6 @@
#include "../cons_res.h"
#include "../controls.h"
#include "../colors.h"
// XXX: for CurStarDescPtr and XXX_DEFINED
#include "../encount.h"
#include "../process.h"
#include "../units.h"
#include "../gamestr.h"
+13 -9
View File
@@ -17,8 +17,7 @@
*/
#include "planets.h"
// XXX: for CurStarDescPtr
#include "../encount.h"
#include "../starmap.h"
#include "libs/compiler.h"
#include "libs/mathlib.h"
#include "libs/log.h"
@@ -499,10 +498,15 @@ char scolor[] = {'B', 'G', 'O', 'R', 'W', 'Y'};
if (NumPlanets == (BYTE)~0)
{
#define MAX_GENERATED_PLANETS 10
while ((NumPlanets = (BYTE)(LOWORD (TFB_Random())
% MAX_GENERATED_PLANETS)) == 0)
;
#define MAX_GENERATED_PLANETS 9
// XXX: This is pretty funny. Instead of calling RNG once, like so:
// 1 + Random % MAX_GENERATED_PLANETS
// we spin in a loop until the result > 0.
// Note that this behavior must be kept to preserve the universe.
do
NumPlanets = LOWORD (RandomContext_Random (SysGenRNG))
% (MAX_GENERATED_PLANETS + 1);
while (NumPlanets == 0);
system->SunDesc[0].NumPlanets = NumPlanets;
}
@@ -528,7 +532,7 @@ char scolor[] = {'B', 'G', 'O', 'R', 'W', 'Y'};
do
{
rand_val = TFB_Random ();
rand_val = RandomContext_Random (SysGenRNG);
if (TypesDefined)
rand_val = 0;
else
@@ -564,7 +568,7 @@ char scolor[] = {'B', 'G', 'O', 'R', 'W', 'Y'};
else
min_radius = Suns[StarSize].MinGasGDist;
RelocatePlanet:
rand_val = TFB_Random ();
rand_val = RandomContext_Random (SysGenRNG);
if (GeneratingMoons)
{
pPD->radius = MIN_MOON_RADIUS
@@ -592,7 +596,7 @@ RelocatePlanet:
}
}
rand_val = TFB_Random ();
rand_val = RandomContext_Random (SysGenRNG);
angle = NORMALIZE_ANGLE (LOWORD (rand_val));
pPD->location.x = COSINE (angle, pPD->radius);
pPD->location.y = SINE (angle, pPD->radius);
+1 -2
View File
@@ -313,8 +313,7 @@ enum
SUPER_DENSITY
};
#define CalcGravity(d,r) (UWORD)((DWORD)(d) * (r) / 100)
#define CalcFromBase(b,v) ((UWORD)(b) + ((UWORD)TFB_Random () % (v)))
extern UWORD CalcGravity (const PLANET_INFO*);
#define EARTH_ATMOSPHERE 50
+7
View File
@@ -19,6 +19,8 @@
#ifndef _PLANETS_H
#define _PLANETS_H
#include "libs/mathlib.h"
#define END_INTERPLANETARY START_INTERPLANETARY
enum PlanetScanTypes
@@ -233,6 +235,9 @@ extern SOLARSYS_STATE *pSolarSysState;
extern MUSIC_REF SpaceMusic;
extern CONTEXT PlanetContext;
// Random context used for all solar system, planets and surfaces generation
extern RandomContext *SysGenRNG;
bool playerInSolarSystem (void);
bool playerInPlanetOrbit (void);
bool playerInInnerSystem (void);
@@ -244,6 +249,8 @@ COUNT moonIndex (const SOLARSYS_STATE *solarSys, const PLANET_DESC *moon);
bool matchWorld (const SOLARSYS_STATE *solarSys, const PLANET_DESC *world,
BYTE planetI, BYTE moonI);
DWORD GetRandomSeedForStar (const STAR_DESC *star);
POINT locationToDisplay (POINT pt, SIZE scaleRadius);
POINT displayToLocation (POINT pt, SIZE scaleRadius);
POINT planetOuterLocation (COUNT planetI);
+10 -12
View File
@@ -842,7 +842,7 @@ DitherMap (SBYTE *DepthArray)
{
// Use up the random value byte by byte
if ((i & 3) == 0)
rand_val = TFB_Random ();
rand_val = RandomContext_Random (SysGenRNG);
else
rand_val >>= 8;
@@ -1066,7 +1066,7 @@ MakeStorms (COUNT storm_count, SBYTE *DepthArray)
intersect = FALSE;
rand_val = TFB_Random ();
rand_val = RandomContext_Random (SysGenRNG);
loword = LOWORD (rand_val);
hiword = HIWORD (rand_val);
switch (HIBYTE (hiword) & 31)
@@ -1094,7 +1094,7 @@ MakeStorms (COUNT storm_count, SBYTE *DepthArray)
if (pstorm_r->extent.height <= 4)
pstorm_r->extent.height += 4;
rand_val = TFB_Random ();
rand_val = RandomContext_Random (SysGenRNG);
loword = LOWORD (rand_val);
hiword = HIWORD (rand_val);
@@ -1183,7 +1183,7 @@ MakeGasGiant (COUNT num_bands, SBYTE *DepthArray, RECT *pRect, SIZE
band_error = num_bands >> 1;
lpDst = DepthArray;
band_delta = ((LOWORD (TFB_Random ())
band_delta = ((LOWORD (RandomContext_Random (SysGenRNG))
& (NUM_BAND_COLORS - 1)) << RANGE_SHIFT)
+ (1 << (RANGE_SHIFT - 1));
last_y = next_y = 0;
@@ -1191,7 +1191,7 @@ MakeGasGiant (COUNT num_bands, SBYTE *DepthArray, RECT *pRect, SIZE
{
COORD cur_y;
rand_val = TFB_Random ();
rand_val = RandomContext_Random (SysGenRNG);
loword = LOWORD (rand_val);
hiword = HIWORD (rand_val);
@@ -1232,7 +1232,7 @@ MakeGasGiant (COUNT num_bands, SBYTE *DepthArray, RECT *pRect, SIZE
& (((1 << RANGE_SHIFT) * NUM_BAND_COLORS) - 1);
}
MakeStorms (4 + (TFB_Random () & 3) + 1, DepthArray);
MakeStorms (4 + (RandomContext_Random (SysGenRNG) & 3) + 1, DepthArray);
DitherMap (DepthArray);
}
@@ -1718,11 +1718,11 @@ GenerateLightMap (SBYTE *pTopo, int w, int h)
}
}
// Sets the SysGenRNG to the required state first.
void
GeneratePlanetSurface (PLANET_DESC *pPlanetDesc, FRAME SurfDefFrame)
{
RECT r;
DWORD old_seed;
const PlanetFrame *PlanDataPtr;
PLANET_INFO *PlanetInfo = &pSolarSysState->SysInfo.PlanetInfo;
COUNT i, y;
@@ -1732,7 +1732,7 @@ GeneratePlanetSurface (PLANET_DESC *pPlanetDesc, FRAME SurfDefFrame)
PLANET_ORBIT *Orbit = &pSolarSysState->Orbit;
BOOLEAN shielded = (pPlanetDesc->data_index & PLANET_SHIELDED) != 0;
old_seed = TFB_SeedRandom (pPlanetDesc->rand_seed);
RandomContext_SeedRandom (SysGenRNG, pPlanetDesc->rand_seed);
TopoContext = CreateContext ("Plangen.TopoContext");
LockMutex (GraphicsLock);
@@ -1818,7 +1818,7 @@ GeneratePlanetSurface (PLANET_DESC *pPlanetDesc, FRAME SurfDefFrame)
RECT crater_r;
UWORD loword;
loword = LOWORD (TFB_Random ());
loword = LOWORD (RandomContext_Random (SysGenRNG));
switch (HIBYTE (loword) & 31)
{
case 0:
@@ -1841,7 +1841,7 @@ GeneratePlanetSurface (PLANET_DESC *pPlanetDesc, FRAME SurfDefFrame)
break;
}
loword = LOWORD (TFB_Random ());
loword = LOWORD (RandomContext_Random (SysGenRNG));
crater_r.extent.height = crater_r.extent.width;
crater_r.corner.x = HIBYTE (loword)
% (MAP_WIDTH - crater_r.extent.width);
@@ -1952,7 +1952,5 @@ GeneratePlanetSurface (PLANET_DESC *pPlanetDesc, FRAME SurfDefFrame)
SetContext (OldContext);
UnlockMutex (GraphicsLock);
DestroyContext (TopoContext);
TFB_SeedRandom (old_seed);
}
+1 -2
View File
@@ -20,8 +20,7 @@
#include "../colors.h"
#include "../controls.h"
#include "../menustat.h"
// XXX: for stuff that does not belong there
#include "../encount.h"
#include "../starmap.h"
#include "../races.h"
#include "../gameopt.h"
#include "../gamestr.h"
+2
View File
@@ -1300,6 +1300,8 @@ generateBioNode (SOLARSYS_STATE *system, ELEMENT *NodeElementPtr,
creatureType = system->SysInfo.PlanetInfo.CurType;
// NOTE: TFB_Random() calls here are NOT part of the deterministic planet
// generation PRNG flow.
if (CreatureData[creatureType].Attributes & SPEED_MASK)
{
// Place moving creatures at a random location.
+20 -21
View File
@@ -22,7 +22,7 @@
#include "../controls.h"
#include "../menustat.h"
// for DrawMenuStateStrings()
#include "../encount.h"
#include "../starmap.h"
#include "../races.h"
#include "../gamestr.h"
#include "../gendef.h"
@@ -95,6 +95,7 @@ static FRAME SolarSysFrame;
static RECT scaleRect;
// system zooms in when the flagship enters this rect
RandomContext *SysGenRNG;
#define DISPLAY_TO_LOC (DISPLAY_FACTOR >> 1)
@@ -211,15 +212,15 @@ playerInInnerSystem (void)
return pSolarSysState->pBaseDesc != pSolarSysState->PlanetDesc;
}
// Sets the SysGenRNG to the required state first.
static void
GenerateMoons (SOLARSYS_STATE *system, PLANET_DESC *planet)
{
COUNT i;
COUNT facing;
PLANET_DESC *pMoonDesc;
DWORD old_seed;
old_seed = TFB_SeedRandom (planet->rand_seed);
RandomContext_SeedRandom (SysGenRNG, planet->rand_seed);
(*system->genFuncs->generateName) (system, planet);
(*system->genFuncs->generateMoons) (system, planet);
@@ -235,8 +236,6 @@ GenerateMoons (SOLARSYS_STATE *system, PLANET_DESC *planet)
pMoonDesc->temp_color = planet->temp_color;
}
TFB_SeedRandom (old_seed);
}
void
@@ -256,6 +255,9 @@ FreeIPData (void)
SpaceJunkFrame = 0;
DestroyMusic (SpaceMusic);
SpaceMusic = 0;
RandomContext_Delete (SysGenRNG);
SysGenRNG = NULL;
}
void
@@ -275,6 +277,11 @@ LoadIPData (void)
SpaceMusic = LoadMusic (IP_MUSIC);
}
if (!SysGenRNG)
{
SysGenRNG = RandomContext_New ();
}
}
@@ -350,11 +357,10 @@ initSolarSysSISCharacteristics (void)
}
}
static DWORD
seedRandomForSolarSys (void)
DWORD
GetRandomSeedForStar (const STAR_DESC *star)
{
return TFB_SeedRandom (MAKE_DWORD (CurStarDescPtr->star_pt.x,
CurStarDescPtr->star_pt.y));
return MAKE_DWORD (star->star_pt.x, star->star_pt.y);
}
// Returns an orbital PLANET_DESC when player is in orbit
@@ -364,7 +370,6 @@ LoadSolarSys (void)
COUNT i;
PLANET_DESC *orbital = NULL;
PLANET_DESC *pCurDesc;
DWORD old_seed;
#define NUM_TEMP_RANGES 5
static const Color temp_color_array[NUM_TEMP_RANGES] =
{
@@ -375,13 +380,13 @@ LoadSolarSys (void)
BUILD_COLOR (MAKE_RGB15_INIT (0x0F, 0x08, 0x00), 0x75),
};
old_seed = seedRandomForSolarSys ();
RandomContext_SeedRandom (SysGenRNG, GetRandomSeedForStar (CurStarDescPtr));
SunFrame = SetAbsFrameIndex (SunFrame, STAR_TYPE (CurStarDescPtr->Type));
pCurDesc = &pSolarSysState->SunDesc[0];
pCurDesc->pPrevDesc = 0;
pCurDesc->rand_seed = TFB_Random ();
pCurDesc->rand_seed = RandomContext_Random (SysGenRNG);
pCurDesc->data_index = STAR_TYPE (CurStarDescPtr->Type);
pCurDesc->location.x = 0;
@@ -467,9 +472,6 @@ LoadSolarSys (void)
GLOBAL (ShipStamp.frame) = SetAbsFrameIndex (SISIPFrame, i - 1);
}
// Restore RNG state:
TFB_SeedRandom (old_seed);
return orbital;
}
@@ -1656,7 +1658,6 @@ CreateStarBackGround (void)
COUNT i, j;
DWORD rand_val;
STAMP s;
DWORD old_seed;
CONTEXT oldContext;
RECT clipRect;
FRAME frame;
@@ -1675,7 +1676,7 @@ CreateStarBackGround (void)
ClearDrawable ();
old_seed = seedRandomForSolarSys ();
RandomContext_SeedRandom (SysGenRNG, GetRandomSeedForStar (CurStarDescPtr));
#define NUM_DIM_PIECES 8
s.frame = SpaceJunkFrame;
@@ -1684,7 +1685,7 @@ CreateStarBackGround (void)
#define NUM_DIM_DRAWN 5
for (j = 0; j < NUM_DIM_DRAWN; ++j)
{
rand_val = TFB_Random ();
rand_val = RandomContext_Random (SysGenRNG);
s.origin.x = LOWORD (rand_val) % SIS_SCREEN_WIDTH;
s.origin.y = HIWORD (rand_val) % SIS_SCREEN_HEIGHT;
@@ -1698,7 +1699,7 @@ CreateStarBackGround (void)
#define NUM_BRT_DRAWN 30
for (j = 0; j < NUM_BRT_DRAWN; ++j)
{
rand_val = TFB_Random ();
rand_val = RandomContext_Random (SysGenRNG);
s.origin.x = LOWORD (rand_val) % SIS_SCREEN_WIDTH;
s.origin.y = HIWORD (rand_val) % SIS_SCREEN_HEIGHT;
@@ -1707,8 +1708,6 @@ CreateStarBackGround (void)
s.frame = IncFrameIndex (s.frame);
}
TFB_SeedRandom (old_seed);
SetContext (oldContext);
return frame;
+8 -8
View File
@@ -43,12 +43,14 @@ typedef struct
PLANET_INFO PlanetInfo;
} SYSTEM_INFO;
extern DWORD GenerateMineralDeposits (SYSTEM_INFO *SysInfoPtr,
COUNT *pwhich_deposit);
extern DWORD GenerateLifeForms (SYSTEM_INFO *SysInfoPtr, COUNT *pwhich_life);
#define GENERATE_ALL ((COUNT)~0)
extern COUNT GenerateMineralDeposits (SYSTEM_INFO *SysInfoPtr,
COUNT whichDeposit);
extern COUNT GenerateLifeForms (SYSTEM_INFO *SysInfoPtr, COUNT whichLife);
extern void GenerateRandomLocation (SYSTEM_INFO *);
extern DWORD GenerateRandomNodes (SYSTEM_INFO *, COUNT scan, COUNT numNodes,
COUNT type, COUNT *whichNode);
extern COUNT GenerateRandomNodes (SYSTEM_INFO *, COUNT scan, COUNT numNodes,
COUNT type, COUNT whichNode);
#define DWARF_ELEMENT_DENSITY 1
#define GIANT_ELEMENT_DENSITY 3
@@ -56,11 +58,9 @@ extern DWORD GenerateRandomNodes (SYSTEM_INFO *, COUNT scan, COUNT numNodes,
#define MAX_ELEMENT_DENSITY ((MAX_ELEMENT_UNITS * SUPERGIANT_ELEMENT_DENSITY) << 1)
extern DWORD DoPlanetaryAnalysis (SYSTEM_INFO *SysInfoPtr,
extern void DoPlanetaryAnalysis (SYSTEM_INFO *SysInfoPtr,
PLANET_DESC *pPlanetDesc);
extern SYSTEM_INFO CurSysInfo;
#if defined(__cplusplus)
}
#endif
+38 -120
View File
@@ -41,16 +41,16 @@ CalcMineralDeposits (SYSTEM_INFO *SysInfoPtr, COUNT which_deposit)
{
BYTE num_possible;
num_possible = (BYTE)((BYTE)TFB_Random ()
% (DEPOSIT_QUANTITY (eptr->Density) + 1));
num_possible = LOBYTE (RandomContext_Random (SysGenRNG))
% (DEPOSIT_QUANTITY (eptr->Density) + 1);
while (num_possible--)
{
#define MEDIUM_DEPOSIT_THRESHOLD 150
#define LARGE_DEPOSIT_THRESHOLD 225
COUNT deposit_quality_fine,
deposit_quality_gross;
COUNT deposit_quality_fine;
COUNT deposit_quality_gross;
deposit_quality_fine = ((COUNT)TFB_Random () % 100)
deposit_quality_fine = (LOWORD (RandomContext_Random (SysGenRNG)) % 100)
+ (
DEPOSIT_QUALITY (eptr->Density)
+ SysInfoPtr->StarSize
@@ -85,14 +85,16 @@ ExitCalcMinerals:
return (num_deposits);
}
DWORD
GenerateMineralDeposits (SYSTEM_INFO *SysInfoPtr, COUNT *pwhich_deposit)
// Returns:
// for whichLife==~0 : the number of nodes generated
// for whichLife<32 : the index of the last node (no known usage exists)
// Sets the SysGenRNG to the required state first.
COUNT
GenerateMineralDeposits (SYSTEM_INFO *SysInfoPtr, COUNT whichDeposit)
{
DWORD old_rand;
old_rand = TFB_SeedRandom (SysInfoPtr->PlanetInfo.ScanSeed[MINERAL_SCAN]);
*pwhich_deposit = CalcMineralDeposits (SysInfoPtr, *pwhich_deposit);
return (TFB_SeedRandom (old_rand));
RandomContext_SeedRandom (SysGenRNG,
SysInfoPtr->PlanetInfo.ScanSeed[MINERAL_SCAN]);
return CalcMineralDeposits (SysInfoPtr, whichDeposit);
}
static COUNT
@@ -101,114 +103,28 @@ CalcLifeForms (SYSTEM_INFO *SysInfoPtr, COUNT which_life)
COUNT num_life_forms;
num_life_forms = 0;
if (PLANSIZE (SysInfoPtr->PlanetInfo.PlanDataPtr->Type) == GAS_GIANT)
SysInfoPtr->PlanetInfo.LifeChance = -1;
else
if (PLANSIZE (SysInfoPtr->PlanetInfo.PlanDataPtr->Type) != GAS_GIANT)
{
#define MIN_LIFE_CHANCE 10
SIZE life_var;
life_var = 0;
if (SysInfoPtr->PlanetInfo.SurfaceTemperature < -151)
life_var -= 300;
else if (SysInfoPtr->PlanetInfo.SurfaceTemperature < -51)
life_var -= 100;
else if (SysInfoPtr->PlanetInfo.SurfaceTemperature < 0)
life_var += 100;
else if (SysInfoPtr->PlanetInfo.SurfaceTemperature < 50)
life_var += 300;
else if (SysInfoPtr->PlanetInfo.SurfaceTemperature < 150)
life_var += 50;
else if (SysInfoPtr->PlanetInfo.SurfaceTemperature < 250)
life_var -= 100;
else if (SysInfoPtr->PlanetInfo.SurfaceTemperature < 500)
life_var -= 400;
else
life_var -= 800;
if (SysInfoPtr->PlanetInfo.AtmoDensity == 0)
life_var -= 1000;
else if (SysInfoPtr->PlanetInfo.AtmoDensity < 15)
life_var += 100;
else if (SysInfoPtr->PlanetInfo.AtmoDensity < 30)
life_var += 200;
else if (SysInfoPtr->PlanetInfo.AtmoDensity < 100)
life_var += 300;
else if (SysInfoPtr->PlanetInfo.AtmoDensity < 1000)
life_var += 150;
else if (SysInfoPtr->PlanetInfo.AtmoDensity < 2500)
;
else
life_var -= 100;
#ifndef NOTYET
life_var += 200 + 80 + 80;
#else /* NOTYET */
if (SysInfoPtr->PlanetInfo.SurfaceGravity < 10)
;
else if (SysInfoPtr->PlanetInfo.SurfaceGravity < 35)
life_var += 50;
else if (SysInfoPtr->PlanetInfo.SurfaceGravity < 75)
life_var += 100;
else if (SysInfoPtr->PlanetInfo.SurfaceGravity < 150)
life_var += 200;
else if (SysInfoPtr->PlanetInfo.SurfaceGravity < 400)
life_var += 50;
else if (SysInfoPtr->PlanetInfo.SurfaceGravity < 800)
;
else
life_var -= 100;
if (SysInfoPtr->PlanetInfo.Tectonics < 1)
life_var += 80;
else if (SysInfoPtr->PlanetInfo.Tectonics < 2)
life_var += 70;
else if (SysInfoPtr->PlanetInfo.Tectonics < 3)
life_var += 60;
else if (SysInfoPtr->PlanetInfo.Tectonics < 4)
life_var += 50;
else if (SysInfoPtr->PlanetInfo.Tectonics < 5)
life_var += 25;
else if (SysInfoPtr->PlanetInfo.Tectonics < 6)
;
else
life_var -= 100;
if (SysInfoPtr->PlanetInfo.Weather < 1)
life_var += 80;
else if (SysInfoPtr->PlanetInfo.Weather < 2)
life_var += 70;
else if (SysInfoPtr->PlanetInfo.Weather < 3)
life_var += 60;
else if (SysInfoPtr->PlanetInfo.Weather < 4)
life_var += 50;
else if (SysInfoPtr->PlanetInfo.Weather < 5)
life_var += 25;
else if (SysInfoPtr->PlanetInfo.Weather < 6)
;
else
life_var -= 100;
#endif /* NOTYET */
SysInfoPtr->PlanetInfo.LifeChance = life_var;
life_var = (COUNT)TFB_Random () & 1023;
life_var = RandomContext_Random (SysGenRNG) & 1023;
if (life_var < SysInfoPtr->PlanetInfo.LifeChance
|| (SysInfoPtr->PlanetInfo.LifeChance < MIN_LIFE_CHANCE
&& life_var < MIN_LIFE_CHANCE))
{
BYTE num_types;
num_types = (BYTE)(((BYTE)TFB_Random () % MAX_LIFE_VARIATION) + 1);
num_types = 1 + LOBYTE (RandomContext_Random (SysGenRNG))
% MAX_LIFE_VARIATION;
do
{
BYTE index, num_creatures;
UWORD rand_val;
rand_val = (UWORD)TFB_Random ();
rand_val = RandomContext_Random (SysGenRNG);
index = LOBYTE (rand_val) % NUM_CREATURE_TYPES;
num_creatures = (BYTE)((HIBYTE (rand_val) % 10) + 1);
num_creatures = 1 + HIBYTE (rand_val) % 10;
do
{
GenerateRandomLocation (SysInfoPtr);
@@ -233,15 +149,16 @@ CalcLifeForms (SYSTEM_INFO *SysInfoPtr, COUNT which_life)
return (num_life_forms);
}
DWORD
GenerateLifeForms (SYSTEM_INFO *SysInfoPtr, COUNT *pwhich_life)
// Returns:
// for whichLife==~0 : the number of lifeforms generated
// for whichLife<32 : the index of the last lifeform (no known usage exists)
// Sets the SysGenRNG to the required state first.
COUNT
GenerateLifeForms (SYSTEM_INFO *SysInfoPtr, COUNT whichLife)
{
DWORD old_rand;
old_rand = TFB_SeedRandom (
RandomContext_SeedRandom (SysGenRNG,
SysInfoPtr->PlanetInfo.ScanSeed[BIOLOGICAL_SCAN]);
*pwhich_life = CalcLifeForms (SysInfoPtr, *pwhich_life);
return (TFB_SeedRandom (old_rand));
return CalcLifeForms (SysInfoPtr, whichLife);
}
void
@@ -249,21 +166,24 @@ GenerateRandomLocation (SYSTEM_INFO *SysInfoPtr)
{
UWORD rand_val;
rand_val = (UWORD)TFB_Random ();
rand_val = RandomContext_Random (SysGenRNG);
SysInfoPtr->PlanetInfo.CurPt.x =
(LOBYTE (rand_val) % (MAP_WIDTH - (8 << 1))) + 8;
SysInfoPtr->PlanetInfo.CurPt.y =
(HIBYTE (rand_val) % (MAP_HEIGHT - (8 << 1))) + 8;
}
DWORD
// Returns:
// for whichNode==~0 : the number of nodes generated
// for whichNode<32 : the index of the last node (no known usage exists)
// Sets the SysGenRNG to the required state first.
COUNT
GenerateRandomNodes (SYSTEM_INFO *SysInfoPtr, COUNT scan, COUNT numNodes,
COUNT type, COUNT *whichNode)
COUNT type, COUNT whichNode)
{
DWORD old_rand;
COUNT i;
old_rand = TFB_SeedRandom (SysInfoPtr->PlanetInfo.ScanSeed[scan]);
RandomContext_SeedRandom (SysGenRNG, SysInfoPtr->PlanetInfo.ScanSeed[scan]);
for (i = 0; i < numNodes; ++i)
{
@@ -273,11 +193,9 @@ GenerateRandomNodes (SYSTEM_INFO *SysInfoPtr, COUNT scan, COUNT numNodes,
// CurDensity is irrelevant for energy and bio nodes
SysInfoPtr->PlanetInfo.CurDensity = 0;
if (i >= *whichNode)
if (i >= whichNode)
break;
}
*whichNode = i; // only matters when count is requested
return (TFB_SeedRandom (old_rand));
return i;
}
+1 -2
View File
@@ -21,8 +21,7 @@
#include "colors.h"
#include "controls.h"
#include "credits.h"
// XXX: for star_array[]
#include "encount.h"
#include "starmap.h"
#include "fmv.h"
#include "menustat.h"
#include "gamestr.h"
+1
View File
@@ -22,6 +22,7 @@
#include "build.h"
#include "controls.h"
#include "starmap.h"
#include "encount.h"
#include "libs/file.h"
#include "gamestr.h"
+1 -2
View File
@@ -20,8 +20,7 @@
#include "colors.h"
#include "races.h"
// XXX: including encount.h for stuff that does not belong there
#include "encount.h"
#include "starmap.h"
#include "units.h"
#include "menustat.h"
// for DrawMenuStateStrings()
+1 -2
View File
@@ -19,8 +19,7 @@
#include "build.h"
#include "colors.h"
#include "controls.h"
// XXX: for CurStarDescPtr
#include "encount.h"
#include "starmap.h"
#include "comm.h"
#include "gamestr.h"
#include "load.h"
+1 -2
View File
@@ -16,10 +16,9 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "encount.h"
#include "starmap.h"
#include "gamestr.h"
#include "globdata.h"
#include "libs/compiler.h"
#include "libs/gfxlib.h"
+42
View File
@@ -0,0 +1,42 @@
/*
* 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 STARMAP_H_INCL_
#define STARMAP_H_INCL_
#include "libs/compiler.h"
#include "planets/planets.h"
#if defined(__cplusplus)
extern "C" {
#endif
extern STAR_DESC *CurStarDescPtr;
extern STAR_DESC *star_array;
#define NUM_SOLAR_SYSTEMS 502
extern STAR_DESC* FindStar (STAR_DESC *pLastStar, POINT *puniverse,
SIZE xbounds, SIZE ybounds);
extern void GetClusterName (const STAR_DESC *pSD, UNICODE buf[]);
#if defined(__cplusplus)
}
#endif
#endif /* STARMAP_H_INCL_ */
+2 -1
View File
@@ -18,12 +18,13 @@
#include "state.h"
#include "encount.h"
#include "starmap.h"
#include "libs/memlib.h"
#include "libs/log.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <memory.h>
// in-memory file i/o
struct GAME_STATE_FILE
+5 -9
View File
@@ -22,7 +22,7 @@
#include "colors.h"
#include "controls.h"
#include "clock.h"
#include "encount.h"
#include "starmap.h"
#include "element.h"
#include "sis.h"
#include "status.h"
@@ -627,15 +627,14 @@ starRecurse (STAR_DESC *star, void *arg)
SOLARSYS_STATE SolarSysState;
SOLARSYS_STATE *oldPSolarSysState = pSolarSysState;
DWORD oldSeed =
TFB_SeedRandom (MAKE_DWORD (star->star_pt.x, star->star_pt.y));
STAR_DESC *oldStarDescPtr = CurStarDescPtr;
CurStarDescPtr = star;
RandomContext_SeedRandom (SysGenRNG, GetRandomSeedForStar (star));
memset (&SolarSysState, 0, sizeof (SolarSysState));
SolarSysState.SunDesc[0].pPrevDesc = 0;
SolarSysState.SunDesc[0].rand_seed = TFB_Random ();
SolarSysState.SunDesc[0].rand_seed = RandomContext_Random (SysGenRNG);
SolarSysState.SunDesc[0].data_index = STAR_TYPE (star->Type);
SolarSysState.SunDesc[0].location.x = 0;
SolarSysState.SunDesc[0].location.y = 0;
@@ -667,7 +666,6 @@ starRecurse (STAR_DESC *star, void *arg)
pSolarSysState = oldPSolarSysState;
CurStarDescPtr = oldStarDescPtr;
TFB_SeedRandom (oldSeed);
}
static void
@@ -695,14 +693,12 @@ planetRecurse (STAR_DESC *star, SOLARSYS_STATE *system, PLANET_DESC *planet,
if (universeRecurseArg->moonFunc != NULL)
{
DWORD oldSeed = TFB_SeedRandom (planet->rand_seed);
RandomContext_SeedRandom (SysGenRNG, planet->rand_seed);
(*system->genFuncs->generateMoons) (system, planet);
forAllMoons (star, system, planet, moonRecurse,
(void *) universeRecurseArg);
TFB_SeedRandom (oldSeed);
}
if (universeRecurseArg->planetFuncPost != NULL)