diff --git a/sc2/src/uqm/planets/generate/genand.c b/sc2/src/uqm/planets/generate/genand.c index 07264a616..de3a24da8 100644 --- a/sc2/src/uqm/planets/generate/genand.c +++ b/sc2/src/uqm/planets/generate/genand.c @@ -124,26 +124,14 @@ static bool GenerateAndrosynth_generateEnergy (SOLARSYS_STATE *solarSys, PLANET_DESC *world, COUNT *whichNode) { - DWORD rand_val; - DWORD old_rand; - if (matchWorld (solarSys, world, 1, MATCH_PLANET)) { COUNT i; - old_rand = TFB_SeedRandom ( - solarSys->SysInfo.PlanetInfo.ScanSeed[ENERGY_SCAN]); + GenerateRandomRuins (&solarSys->SysInfo, 0, whichNode); for (i = 0; i < 16; ++i) { - rand_val = TFB_Random (); - solarSys->SysInfo.PlanetInfo.CurPt.x = - (LOBYTE (LOWORD (rand_val)) % (MAP_WIDTH - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurPt.y = - (HIBYTE (LOWORD (rand_val)) % (MAP_HEIGHT - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurType = 0; - solarSys->SysInfo.PlanetInfo.CurDensity = 0; - if (isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, i)) { // Retrieval status is cleared to keep the node on the map @@ -169,13 +157,8 @@ GenerateAndrosynth_generateEnergy (SOLARSYS_STATE *solarSys, PLANET_DESC *world, } } } - - if (i >= *whichNode) - break; } - *whichNode = i; - - TFB_SeedRandom (old_rand); + return true; } diff --git a/sc2/src/uqm/planets/generate/genburv.c b/sc2/src/uqm/planets/generate/genburv.c index 673844f30..31ac186aa 100644 --- a/sc2/src/uqm/planets/generate/genburv.c +++ b/sc2/src/uqm/planets/generate/genburv.c @@ -139,60 +139,35 @@ static bool GenerateBurvixese_generateEnergy (SOLARSYS_STATE *solarSys, PLANET_DESC *world, COUNT *whichNode) { - DWORD rand_val; DWORD old_rand; if (matchWorld (solarSys, world, 0, MATCH_PLANET)) { - COUNT i; - - old_rand = TFB_SeedRandom ( - solarSys->SysInfo.PlanetInfo.ScanSeed[ENERGY_SCAN]); - - for (i = 0; i < 16; ++i) - { - rand_val = TFB_Random (); - solarSys->SysInfo.PlanetInfo.CurPt.x = - (LOBYTE (LOWORD (rand_val)) % (MAP_WIDTH - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurPt.y = - (HIBYTE (LOWORD (rand_val)) % (MAP_HEIGHT - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurType = 1; - solarSys->SysInfo.PlanetInfo.CurDensity = 0; - if (i >= *whichNode) - break; - } - *whichNode = i; - - TFB_SeedRandom (old_rand); + GenerateRandomRuins (&solarSys->SysInfo, 1, whichNode); return true; } - if (matchWorld (solarSys, world, 0, 0) - && !GET_GAME_STATE (BURVIXESE_BROADCASTERS)) + if (matchWorld (solarSys, world, 0, 0)) { + if (GET_GAME_STATE (BURVIXESE_BROADCASTERS)) + { // already picked up + *whichNode = 0; + return true; + } + old_rand = TFB_SeedRandom ( solarSys->SysInfo.PlanetInfo.ScanSeed[ENERGY_SCAN]); - rand_val = TFB_Random (); - solarSys->SysInfo.PlanetInfo.CurPt.x = - (LOBYTE (LOWORD (rand_val)) % (MAP_WIDTH - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurPt.y = - (HIBYTE (LOWORD (rand_val)) % (MAP_HEIGHT - (8 << 1))) + 8; + GenerateRandomLocation (&solarSys->SysInfo); solarSys->SysInfo.PlanetInfo.CurDensity = 0; solarSys->SysInfo.PlanetInfo.CurType = 0; - if (!isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0) - && *whichNode == (COUNT)~0) + + *whichNode = 1; // only matters when count is requested + + if (isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0)) { - *whichNode = 1; - } - else - { - *whichNode = 0; - if (isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0)) - { - SET_GAME_STATE (BURVIXESE_BROADCASTERS, 1); - SET_GAME_STATE (BURV_BROADCASTERS_ON_SHIP, 1); - } + SET_GAME_STATE (BURVIXESE_BROADCASTERS, 1); + SET_GAME_STATE (BURV_BROADCASTERS_ON_SHIP, 1); } TFB_SeedRandom (old_rand); diff --git a/sc2/src/uqm/planets/generate/gendru.c b/sc2/src/uqm/planets/generate/gendru.c index 844edb5f2..24964f43f 100644 --- a/sc2/src/uqm/planets/generate/gendru.c +++ b/sc2/src/uqm/planets/generate/gendru.c @@ -132,25 +132,13 @@ GenerateDruuge_generateEnergy (SOLARSYS_STATE *solarSys, PLANET_DESC *world, if (matchWorld (solarSys, world, 0, MATCH_PLANET)) { COUNT i; - DWORD rand_val; - DWORD old_rand; + COUNT type; - old_rand = TFB_SeedRandom ( - solarSys->SysInfo.PlanetInfo.ScanSeed[ENERGY_SCAN]); + type = GET_GAME_STATE (ROSY_SPHERE) ? 1 : 0; + GenerateRandomRuins (&solarSys->SysInfo, type, whichNode); for (i = 0; i < 16; ++i) { - rand_val = TFB_Random (); - solarSys->SysInfo.PlanetInfo.CurPt.x = - (LOBYTE (LOWORD (rand_val)) % (MAP_WIDTH - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurPt.y = - (HIBYTE (LOWORD (rand_val)) % (MAP_HEIGHT - (8 << 1))) + 8; - if (!GET_GAME_STATE (ROSY_SPHERE)) - solarSys->SysInfo.PlanetInfo.CurType = 0; - else - solarSys->SysInfo.PlanetInfo.CurType = 1; - solarSys->SysInfo.PlanetInfo.CurDensity = 0; - if (isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, i)) { // Retrieval status is cleared to keep the node on the map @@ -164,19 +152,12 @@ GenerateDruuge_generateEnergy (SOLARSYS_STATE *solarSys, PLANET_DESC *world, SET_GAME_STATE (ROSY_SPHERE_ON_SHIP, 1); } } - - if (i >= *whichNode) - break; } - *whichNode = i; - - TFB_SeedRandom (old_rand); return true; } *whichNode = 0; - return true; } diff --git a/sc2/src/uqm/planets/generate/genilw.c b/sc2/src/uqm/planets/generate/genilw.c index 21b219d7b..19ebaffec 100644 --- a/sc2/src/uqm/planets/generate/genilw.c +++ b/sc2/src/uqm/planets/generate/genilw.c @@ -123,28 +123,7 @@ GenerateIlwrath_generateEnergy (SOLARSYS_STATE *solarSys, PLANET_DESC *world, { if (matchWorld (solarSys, world, 0, MATCH_PLANET)) { - COUNT i; - DWORD rand_val; - DWORD old_rand; - - old_rand = TFB_SeedRandom ( - solarSys->SysInfo.PlanetInfo.ScanSeed[ENERGY_SCAN]); - - for (i = 0; i < 16; ++i) - { - rand_val = TFB_Random (); - solarSys->SysInfo.PlanetInfo.CurPt.x = - (LOBYTE (LOWORD (rand_val)) % (MAP_WIDTH - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurPt.y = - (HIBYTE (LOWORD (rand_val)) % (MAP_HEIGHT - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurType = 1; - solarSys->SysInfo.PlanetInfo.CurDensity = 0; - if (i >= *whichNode) - break; - } - *whichNode = i; - - TFB_SeedRandom (old_rand); + GenerateRandomRuins (&solarSys->SysInfo, 1, whichNode); return true; } diff --git a/sc2/src/uqm/planets/generate/genmyc.c b/sc2/src/uqm/planets/generate/genmyc.c index 7b21480a0..d9ee6d280 100644 --- a/sc2/src/uqm/planets/generate/genmyc.c +++ b/sc2/src/uqm/planets/generate/genmyc.c @@ -185,68 +185,73 @@ static bool GenerateMycon_generateEnergy (SOLARSYS_STATE *solarSys, PLANET_DESC *world, COUNT *whichNode) { - if (CurStarDescPtr->Index != MYCON_DEFINED - && matchWorld (solarSys, world, 0, MATCH_PLANET)) + DWORD old_rand; + + if (CurStarDescPtr->Index == SUN_DEVICE_DEFINED + && matchWorld (solarSys, world, 0, MATCH_PLANET)) { - DWORD rand_val; - DWORD old_rand; + if (GET_GAME_STATE (SUN_DEVICE)) + { // already picked up + *whichNode = 0; + return true; + } old_rand = TFB_SeedRandom ( solarSys->SysInfo.PlanetInfo.ScanSeed[ENERGY_SCAN]); - rand_val = TFB_Random (); - solarSys->SysInfo.PlanetInfo.CurPt.x = - (LOBYTE (LOWORD (rand_val)) % (MAP_WIDTH - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurPt.y = - (HIBYTE (LOWORD (rand_val)) % (MAP_HEIGHT - (8 << 1))) + 8; + GenerateRandomLocation (&solarSys->SysInfo); solarSys->SysInfo.PlanetInfo.CurDensity = 0; solarSys->SysInfo.PlanetInfo.CurType = 0; - if (CurStarDescPtr->Index == SUN_DEVICE_DEFINED) + + *whichNode = 1; // only matters when count is requested + + if (isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0)) { - if (!isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0) - && *whichNode == (COUNT)~0) - { - *whichNode = 1; - } - else - { - *whichNode = 0; - if (isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0)) - { - SET_GAME_STATE (SUN_DEVICE, 1); - SET_GAME_STATE (SUN_DEVICE_ON_SHIP, 1); - SET_GAME_STATE (MYCON_VISITS, 0); - } - } + SET_GAME_STATE (SUN_DEVICE, 1); + SET_GAME_STATE (SUN_DEVICE_ON_SHIP, 1); + SET_GAME_STATE (MYCON_VISITS, 0); } - else + + TFB_SeedRandom (old_rand); + return true; + } + + if ((CurStarDescPtr->Index == EGG_CASE0_DEFINED + || CurStarDescPtr->Index == EGG_CASE1_DEFINED + || CurStarDescPtr->Index == EGG_CASE2_DEFINED) + && matchWorld (solarSys, world, 0, MATCH_PLANET)) + { + // XXX: DiscoveryString is set by generateOrbital() only when the + // node has not been picked up yet + if (isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0) + && !solarSys->SysInfo.PlanetInfo.DiscoveryString) + { // already picked up + *whichNode = 0; + return true; + } + + old_rand = TFB_SeedRandom ( + solarSys->SysInfo.PlanetInfo.ScanSeed[ENERGY_SCAN]); + + GenerateRandomLocation (&solarSys->SysInfo); + solarSys->SysInfo.PlanetInfo.CurDensity = 0; + solarSys->SysInfo.PlanetInfo.CurType = 0; + + *whichNode = 1; // only matters when count is requested + + if (isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0)) { - if (!isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0) - && *whichNode == (COUNT)~0) + switch (CurStarDescPtr->Index) { - *whichNode = 1; - } - else - { - *whichNode = 0; - // XXX: Why does this also test the PlanetInfo.DiscoveryString? - // No other similar code ever tests the DiscoveryString. - if (isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0) - && solarSys->SysInfo.PlanetInfo.DiscoveryString) - { - switch (CurStarDescPtr->Index) - { - case EGG_CASE0_DEFINED: - SET_GAME_STATE (EGG_CASE0_ON_SHIP, 1); - break; - case EGG_CASE1_DEFINED: - SET_GAME_STATE (EGG_CASE1_ON_SHIP, 1); - break; - case EGG_CASE2_DEFINED: - SET_GAME_STATE (EGG_CASE2_ON_SHIP, 1); - break; - } - } + case EGG_CASE0_DEFINED: + SET_GAME_STATE (EGG_CASE0_ON_SHIP, 1); + break; + case EGG_CASE1_DEFINED: + SET_GAME_STATE (EGG_CASE1_ON_SHIP, 1); + break; + case EGG_CASE2_DEFINED: + SET_GAME_STATE (EGG_CASE2_ON_SHIP, 1); + break; } } diff --git a/sc2/src/uqm/planets/generate/genorz.c b/sc2/src/uqm/planets/generate/genorz.c index 982a57fe0..95254e64e 100644 --- a/sc2/src/uqm/planets/generate/genorz.c +++ b/sc2/src/uqm/planets/generate/genorz.c @@ -165,66 +165,40 @@ static bool GenerateOrz_generateEnergy (SOLARSYS_STATE *solarSys, PLANET_DESC *world, COUNT *whichNode) { - DWORD rand_val; DWORD old_rand; - if (CurStarDescPtr->Index != ORZ_DEFINED - && matchWorld (solarSys, world, 1, 2) - && !GET_GAME_STATE (TAALO_PROTECTOR)) + if (CurStarDescPtr->Index == TAALO_PROTECTOR_DEFINED + && matchWorld (solarSys, world, 1, 2)) { + if (GET_GAME_STATE (TAALO_PROTECTOR)) + { // already picked up + *whichNode = 0; + return true; + } + old_rand = TFB_SeedRandom ( solarSys->SysInfo.PlanetInfo.ScanSeed[ENERGY_SCAN]); - rand_val = TFB_Random (); - solarSys->SysInfo.PlanetInfo.CurPt.x = - (LOBYTE (LOWORD (rand_val)) % (MAP_WIDTH - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurPt.y = - (HIBYTE (LOWORD (rand_val)) % (MAP_HEIGHT - (8 << 1))) + 8; + GenerateRandomLocation (&solarSys->SysInfo); solarSys->SysInfo.PlanetInfo.CurDensity = 0; solarSys->SysInfo.PlanetInfo.CurType = 0; - if (!isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0) - && *whichNode == (COUNT)~0) + + *whichNode = 1; // only matters when count is requested + + if (isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0)) { - *whichNode = 1; - } - else - { - *whichNode = 0; - if (isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0)) - { - SET_GAME_STATE (TAALO_PROTECTOR, 1); - SET_GAME_STATE (TAALO_PROTECTOR_ON_SHIP, 1); - } + SET_GAME_STATE (TAALO_PROTECTOR, 1); + SET_GAME_STATE (TAALO_PROTECTOR_ON_SHIP, 1); } TFB_SeedRandom (old_rand); - return true; } if (CurStarDescPtr->Index == ORZ_DEFINED && matchWorld (solarSys, world, 0, MATCH_PLANET)) { - COUNT i; - - old_rand = TFB_SeedRandom ( - solarSys->SysInfo.PlanetInfo.ScanSeed[ENERGY_SCAN]); - - for (i = 0; i < 16; ++i) - { - rand_val = TFB_Random (); - solarSys->SysInfo.PlanetInfo.CurPt.x = - (LOBYTE (LOWORD (rand_val)) % (MAP_WIDTH - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurPt.y = - (HIBYTE (LOWORD (rand_val)) % (MAP_HEIGHT - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurType = 1; - solarSys->SysInfo.PlanetInfo.CurDensity = 0; - if (i >= *whichNode) - break; - } - *whichNode = i; - - TFB_SeedRandom (old_rand); + GenerateRandomRuins (&solarSys->SysInfo, 1, whichNode); return true; } diff --git a/sc2/src/uqm/planets/generate/genpet.c b/sc2/src/uqm/planets/generate/genpet.c index 7cef09631..fd4cc5056 100644 --- a/sc2/src/uqm/planets/generate/genpet.c +++ b/sc2/src/uqm/planets/generate/genpet.c @@ -160,28 +160,7 @@ GenerateTalkingPet_generateEnergy (SOLARSYS_STATE *solarSys, PLANET_DESC *world, { if (matchWorld (solarSys, world, 0, MATCH_PLANET)) { - COUNT i; - DWORD rand_val; - COUNT old_rand; - - old_rand = TFB_SeedRandom ( - solarSys->SysInfo.PlanetInfo.ScanSeed[ENERGY_SCAN]); - - for (i = 0; i < 16; ++i) - { - rand_val = TFB_Random (); - solarSys->SysInfo.PlanetInfo.CurPt.x = - (LOBYTE (LOWORD (rand_val)) % (MAP_WIDTH - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurPt.y = - (HIBYTE (LOWORD (rand_val)) % (MAP_HEIGHT - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurType = 1; - solarSys->SysInfo.PlanetInfo.CurDensity = 0; - if (i >= *whichNode) - break; - } - *whichNode = i; - - TFB_SeedRandom (old_rand); + GenerateRandomRuins (&solarSys->SysInfo, 1, whichNode); return true; } diff --git a/sc2/src/uqm/planets/generate/genpku.c b/sc2/src/uqm/planets/generate/genpku.c index 4674c256d..34e9d05f1 100644 --- a/sc2/src/uqm/planets/generate/genpku.c +++ b/sc2/src/uqm/planets/generate/genpku.c @@ -122,25 +122,13 @@ GeneratePkunk_generateEnergy (SOLARSYS_STATE *solarSys, PLANET_DESC *world, if (matchWorld (solarSys, world, 0, MATCH_PLANET)) { COUNT i; - DWORD rand_val; - DWORD old_rand; + COUNT type; - old_rand = TFB_SeedRandom ( - solarSys->SysInfo.PlanetInfo.ScanSeed[ENERGY_SCAN]); + type = GET_GAME_STATE (CLEAR_SPINDLE) ? 1 : 0; + GenerateRandomRuins (&solarSys->SysInfo, type, whichNode); for (i = 0; i < 16; ++i) { - rand_val = TFB_Random (); - solarSys->SysInfo.PlanetInfo.CurPt.x = - (LOBYTE (LOWORD (rand_val)) % (MAP_WIDTH - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurPt.y = - (HIBYTE (LOWORD (rand_val)) % (MAP_HEIGHT - (8 << 1))) + 8; - if (!GET_GAME_STATE (CLEAR_SPINDLE)) - solarSys->SysInfo.PlanetInfo.CurType = 0; - else - solarSys->SysInfo.PlanetInfo.CurType = 1; - solarSys->SysInfo.PlanetInfo.CurDensity = 0; - if (isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, i)) { // Retrieval status is cleared to keep the node on the map @@ -154,13 +142,8 @@ GeneratePkunk_generateEnergy (SOLARSYS_STATE *solarSys, PLANET_DESC *world, SET_GAME_STATE (CLEAR_SPINDLE_ON_SHIP, 1); } } - - if (i >= *whichNode) - break; } - *whichNode = i; - TFB_SeedRandom (old_rand); return true; } diff --git a/sc2/src/uqm/planets/generate/gensol.c b/sc2/src/uqm/planets/generate/gensol.c index 196b217d7..eccfd9d66 100644 --- a/sc2/src/uqm/planets/generate/gensol.c +++ b/sc2/src/uqm/planets/generate/gensol.c @@ -516,51 +516,54 @@ GenerateSol_generateEnergy (SOLARSYS_STATE *solarSys, PLANET_DESC *world, if (matchWorld (solarSys, world, 8, MATCH_PLANET)) { /* Pluto */ - if (!GET_GAME_STATE (FOUND_PLUTO_SPATHI)) - { - solarSys->SysInfo.PlanetInfo.CurPt.x = 20; - solarSys->SysInfo.PlanetInfo.CurPt.y = MAP_HEIGHT - 8; - solarSys->SysInfo.PlanetInfo.CurDensity = 0; - solarSys->SysInfo.PlanetInfo.CurType = 2; - if (isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0)) - { - SET_GAME_STATE (FOUND_PLUTO_SPATHI, 1); - // Retrieval status is cleared to keep the node on the map - // while the lander is taking off. FOUND_PLUTO_SPATHI bit - // will keep the node from showing up on subsequent visits. - setNodeNotRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0); - SetLanderTakeoff (); - // XXX: This does NOT set *whichNode when the node is - // retrieved. Other similar pieces of code return the node - // count. See just below. AFAICT, the returned value is ignored. - } - else if (*whichNode == (COUNT)~0) - *whichNode = 1; + if (GET_GAME_STATE (FOUND_PLUTO_SPATHI)) + { // already picked up + *whichNode = 0; return true; } + + solarSys->SysInfo.PlanetInfo.CurPt.x = 20; + solarSys->SysInfo.PlanetInfo.CurPt.y = MAP_HEIGHT - 8; + solarSys->SysInfo.PlanetInfo.CurDensity = 0; + solarSys->SysInfo.PlanetInfo.CurType = 2; + + *whichNode = 1; // only matters when count is requested + + if (isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0)) + { + SET_GAME_STATE (FOUND_PLUTO_SPATHI, 1); + // Retrieval status is cleared to keep the node on the map + // while the lander is taking off. FOUND_PLUTO_SPATHI bit + // will keep the node from showing up on subsequent visits. + setNodeNotRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0); + SetLanderTakeoff (); + } + + return true; } - else if (matchWorld (solarSys, world, 2, 1) - && !GET_GAME_STATE (MOONBASE_DESTROYED)) + + if (matchWorld (solarSys, world, 2, 1)) { /* Earth Moon */ + if (GET_GAME_STATE (MOONBASE_DESTROYED)) + { // already picked up + *whichNode = 0; + return true; + } + solarSys->SysInfo.PlanetInfo.CurPt.x = MAP_WIDTH * 3 / 4; solarSys->SysInfo.PlanetInfo.CurPt.y = MAP_HEIGHT * 1 / 4; solarSys->SysInfo.PlanetInfo.CurDensity = 0; solarSys->SysInfo.PlanetInfo.CurType = 0; - if (!isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0) - && *whichNode == (COUNT)~0) + + *whichNode = 1; // only matters when count is requested + + if (isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0)) { - *whichNode = 1; - } - else - { - *whichNode = 0; - if (isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0)) - { - SET_GAME_STATE (MOONBASE_DESTROYED, 1); - SET_GAME_STATE (MOONBASE_ON_SHIP, 1); - } + SET_GAME_STATE (MOONBASE_DESTROYED, 1); + SET_GAME_STATE (MOONBASE_ON_SHIP, 1); } + return true; } @@ -572,35 +575,15 @@ static bool GenerateSol_generateLife (SOLARSYS_STATE *solarSys, PLANET_DESC *world, COUNT *whichNode) { - if (!matchWorld (solarSys, world, 2, 1)) + if (matchWorld (solarSys, world, 2, 1)) { - *whichNode = 0; - } - else /* Earth Moon */ - { - COUNT i; - DWORD old_rand; - DWORD rand_val; - - old_rand = TFB_SeedRandom ( - solarSys->SysInfo.PlanetInfo.ScanSeed[BIOLOGICAL_SCAN]); - - for (i = 0; i < 10; ++i) - { - rand_val = TFB_Random (); - solarSys->SysInfo.PlanetInfo.CurPt.x = - (LOBYTE (LOWORD (rand_val)) % (MAP_WIDTH - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurPt.y = - (HIBYTE (LOWORD (rand_val)) % (MAP_HEIGHT - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurType = NUM_CREATURE_TYPES + 1; - if (i >= *whichNode) - break; - } - *whichNode = i; - - TFB_SeedRandom (old_rand); + /* Earth Moon */ + GenerateRandomNodes (&solarSys->SysInfo, BIOLOGICAL_SCAN, 10, + NUM_CREATURE_TYPES + 1, whichNode); + return true; } + *whichNode = 0; return true; } diff --git a/sc2/src/uqm/planets/generate/genspa.c b/sc2/src/uqm/planets/generate/genspa.c index 2dbfa7a41..9f58fa0aa 100644 --- a/sc2/src/uqm/planets/generate/genspa.c +++ b/sc2/src/uqm/planets/generate/genspa.c @@ -194,35 +194,29 @@ static bool GenerateSpathi_generateEnergy (SOLARSYS_STATE *solarSys, PLANET_DESC *world, COUNT *whichNode) { - if (matchWorld (solarSys, world, 0, 0) - && !GET_GAME_STATE (UMGAH_BROADCASTERS)) + if (matchWorld (solarSys, world, 0, 0)) { - DWORD rand_val; DWORD old_rand; + if (GET_GAME_STATE (UMGAH_BROADCASTERS)) + { // already picked up + *whichNode = 0; + return true; + } + old_rand = TFB_SeedRandom ( solarSys->SysInfo.PlanetInfo.ScanSeed[ENERGY_SCAN]); - rand_val = TFB_Random (); - solarSys->SysInfo.PlanetInfo.CurPt.x = - (LOBYTE (LOWORD (rand_val)) % (MAP_WIDTH - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurPt.y = - (HIBYTE (LOWORD (rand_val)) % (MAP_HEIGHT - (8 << 1))) + 8; + GenerateRandomLocation (&solarSys->SysInfo); solarSys->SysInfo.PlanetInfo.CurDensity = 0; solarSys->SysInfo.PlanetInfo.CurType = 0; - if (!isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0) - && *whichNode == (COUNT)~0) + + *whichNode = 1; // only matters when count is requested + + if (isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0)) { - *whichNode = 1; - } - else - { - *whichNode = 0; - if (isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0)) - { - SET_GAME_STATE (UMGAH_BROADCASTERS, 1); - SET_GAME_STATE (UMGAH_BROADCASTERS_ON_SHIP, 1); - } + SET_GAME_STATE (UMGAH_BROADCASTERS, 1); + SET_GAME_STATE (UMGAH_BROADCASTERS_ON_SHIP, 1); } TFB_SeedRandom (old_rand); @@ -237,27 +231,17 @@ static bool GenerateSpathi_generateLife (SOLARSYS_STATE *solarSys, PLANET_DESC *world, COUNT *whichNode) { - if (matchWorld (solarSys, world, 0, MATCH_PLANET) - && !GET_GAME_STATE (SPATHI_SHIELDED_SELVES)) + if (matchWorld (solarSys, world, 0, MATCH_PLANET)) { - COUNT i; - DWORD old_rand; - - old_rand = TFB_SeedRandom ( - solarSys->SysInfo.PlanetInfo.ScanSeed[BIOLOGICAL_SCAN]); - - for (i = 0; i < 32; ++i) - { - DWORD rand_val = TFB_Random (); - solarSys->SysInfo.PlanetInfo.CurPt.x = - (LOBYTE (LOWORD (rand_val)) % (MAP_WIDTH - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurPt.y = - (HIBYTE (LOWORD (rand_val)) % (MAP_HEIGHT - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurType = NUM_CREATURE_TYPES; - if (i >= *whichNode) - break; + if (GET_GAME_STATE (SPATHI_CREATURES_ELIMINATED) + || GET_GAME_STATE (SPATHI_SHIELDED_SELVES)) + { // no creatures left + *whichNode = 0; + return true; } - *whichNode = i; + + GenerateRandomNodes (&solarSys->SysInfo, BIOLOGICAL_SCAN, 32, + NUM_CREATURE_TYPES, whichNode); if (solarSys->SysInfo.PlanetInfo.ScanRetrieveMask[BIOLOGICAL_SCAN]) { @@ -267,7 +251,6 @@ GenerateSpathi_generateLife (SOLARSYS_STATE *solarSys, PLANET_DESC *world, SET_GAME_STATE (SPATHI_CREATURES_ELIMINATED, 1); } - TFB_SeedRandom (old_rand); return true; } diff --git a/sc2/src/uqm/planets/generate/gensup.c b/sc2/src/uqm/planets/generate/gensup.c index 798637dd8..f90f88673 100644 --- a/sc2/src/uqm/planets/generate/gensup.c +++ b/sc2/src/uqm/planets/generate/gensup.c @@ -125,25 +125,13 @@ GenerateSupox_generateEnergy (SOLARSYS_STATE *solarSys, PLANET_DESC *world, if (matchWorld (solarSys, world, 0, MATCH_PLANET)) { COUNT i; - DWORD rand_val; - DWORD old_rand; + COUNT type; - old_rand = TFB_SeedRandom ( - solarSys->SysInfo.PlanetInfo.ScanSeed[ENERGY_SCAN]); + type = GET_GAME_STATE (ULTRON_CONDITION) ? 1 : 0; + GenerateRandomRuins (&solarSys->SysInfo, type, whichNode); for (i = 0; i < 16; ++i) { - rand_val = TFB_Random (); - solarSys->SysInfo.PlanetInfo.CurPt.x = - (LOBYTE (LOWORD (rand_val)) % (MAP_WIDTH - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurPt.y = - (HIBYTE (LOWORD (rand_val)) % (MAP_HEIGHT - (8 << 1))) + 8; - if (!GET_GAME_STATE (ULTRON_CONDITION)) - solarSys->SysInfo.PlanetInfo.CurType = 0; - else - solarSys->SysInfo.PlanetInfo.CurType = 1; - solarSys->SysInfo.PlanetInfo.CurDensity = 0; - if (isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, i)) { // Retrieval status is cleared to keep the node on the map @@ -156,13 +144,8 @@ GenerateSupox_generateEnergy (SOLARSYS_STATE *solarSys, PLANET_DESC *world, SET_GAME_STATE (ULTRON_CONDITION, 1); } } - - if (i >= *whichNode) - break; } - *whichNode = i; - TFB_SeedRandom (old_rand); return true; } diff --git a/sc2/src/uqm/planets/generate/genthrad.c b/sc2/src/uqm/planets/generate/genthrad.c index 0ef58dcd6..1a1c76155 100644 --- a/sc2/src/uqm/planets/generate/genthrad.c +++ b/sc2/src/uqm/planets/generate/genthrad.c @@ -158,68 +158,43 @@ static bool GenerateThraddash_generateEnergy (SOLARSYS_STATE *solarSys, PLANET_DESC *world, COUNT *whichNode) { - if (matchWorld (solarSys, world, 0, MATCH_PLANET)) + DWORD old_rand; + + if (CurStarDescPtr->Index == THRADD_DEFINED + && matchWorld (solarSys, world, 0, MATCH_PLANET)) { - DWORD rand_val; - DWORD old_rand; + GenerateRandomRuins (&solarSys->SysInfo, 1, whichNode); + return true; + } - if (CurStarDescPtr->Index != AQUA_HELIX_DEFINED) - { - COUNT i; - - old_rand = TFB_SeedRandom ( - solarSys->SysInfo.PlanetInfo.ScanSeed[ENERGY_SCAN]); - - for (i = 0; i < 16; ++i) - { - rand_val = TFB_Random (); - solarSys->SysInfo.PlanetInfo.CurPt.x = - (LOBYTE (LOWORD (rand_val)) % (MAP_WIDTH - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurPt.y = - (HIBYTE (LOWORD (rand_val)) % (MAP_HEIGHT - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurType = 1; - solarSys->SysInfo.PlanetInfo.CurDensity = 0; - if (i >= *whichNode) - break; - } - *whichNode = i; - - TFB_SeedRandom (old_rand); + if (CurStarDescPtr->Index == AQUA_HELIX_DEFINED + && matchWorld (solarSys, world, 0, MATCH_PLANET)) + { + if (GET_GAME_STATE (AQUA_HELIX)) + { // already picked up + *whichNode = 0; return true; } - if (!GET_GAME_STATE (AQUA_HELIX)) + old_rand = TFB_SeedRandom ( + solarSys->SysInfo.PlanetInfo.ScanSeed[ENERGY_SCAN]); + + GenerateRandomLocation (&solarSys->SysInfo); + solarSys->SysInfo.PlanetInfo.CurDensity = 0; + solarSys->SysInfo.PlanetInfo.CurType = 0; + + *whichNode = 1; // only matters when count is requested + + if (isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0)) { - old_rand = TFB_SeedRandom ( - solarSys->SysInfo.PlanetInfo.ScanSeed[ENERGY_SCAN]); - - rand_val = TFB_Random (); - solarSys->SysInfo.PlanetInfo.CurPt.x = - (LOBYTE (LOWORD (rand_val)) % (MAP_WIDTH - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurPt.y = - (HIBYTE (LOWORD (rand_val)) % (MAP_HEIGHT - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurDensity = 0; - solarSys->SysInfo.PlanetInfo.CurType = 0; - if (!isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0) - && *whichNode == (COUNT)~0) - { - *whichNode = 1; - } - else - { - *whichNode = 0; - if (isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0)) - { - SET_GAME_STATE (HELIX_VISITS, 0); - SET_GAME_STATE (AQUA_HELIX, 1); - SET_GAME_STATE (AQUA_HELIX_ON_SHIP, 1); - SET_GAME_STATE (HELIX_UNPROTECTED, 1); - } - } - - TFB_SeedRandom (old_rand); - return true; + SET_GAME_STATE (HELIX_VISITS, 0); + SET_GAME_STATE (AQUA_HELIX, 1); + SET_GAME_STATE (AQUA_HELIX_ON_SHIP, 1); + SET_GAME_STATE (HELIX_UNPROTECTED, 1); } + + TFB_SeedRandom (old_rand); + return true; } *whichNode = 0; diff --git a/sc2/src/uqm/planets/generate/genutw.c b/sc2/src/uqm/planets/generate/genutw.c index 14f55252f..2b3367f20 100644 --- a/sc2/src/uqm/planets/generate/genutw.c +++ b/sc2/src/uqm/planets/generate/genutw.c @@ -209,65 +209,40 @@ static bool GenerateUtwig_generateEnergy (SOLARSYS_STATE *solarSys, PLANET_DESC *world, COUNT *whichNode) { - DWORD rand_val; DWORD old_rand; if (CurStarDescPtr->Index == UTWIG_DEFINED && matchWorld (solarSys, world, 0, MATCH_PLANET)) { - COUNT i; - - old_rand = TFB_SeedRandom ( - solarSys->SysInfo.PlanetInfo.ScanSeed[ENERGY_SCAN]); - - for (i = 0; i < 16; ++i) - { - rand_val = TFB_Random (); - solarSys->SysInfo.PlanetInfo.CurPt.x = - (LOBYTE (LOWORD (rand_val)) % (MAP_WIDTH - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurPt.y = - (HIBYTE (LOWORD (rand_val)) % (MAP_HEIGHT - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurType = 1; - solarSys->SysInfo.PlanetInfo.CurDensity = 0; - if (i >= *whichNode) - break; - } - *whichNode = i; - - TFB_SeedRandom (old_rand); + GenerateRandomRuins (&solarSys->SysInfo, 1, whichNode); return true; } if (CurStarDescPtr->Index == BOMB_DEFINED - && matchWorld (solarSys, world, 5, 1) - && !GET_GAME_STATE (UTWIG_BOMB)) + && matchWorld (solarSys, world, 5, 1)) { + if (GET_GAME_STATE (UTWIG_BOMB)) + { // already picked up + *whichNode = 0; + return true; + } + old_rand = TFB_SeedRandom ( solarSys->SysInfo.PlanetInfo.ScanSeed[ENERGY_SCAN]); - rand_val = TFB_Random (); - solarSys->SysInfo.PlanetInfo.CurPt.x = - (LOBYTE (LOWORD (rand_val)) % (MAP_WIDTH - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurPt.y = - (HIBYTE (LOWORD (rand_val)) % (MAP_HEIGHT - (8 << 1))) + 8; + GenerateRandomLocation (&solarSys->SysInfo); solarSys->SysInfo.PlanetInfo.CurDensity = 0; solarSys->SysInfo.PlanetInfo.CurType = 0; - if (!isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0) - && *whichNode == (COUNT)~0) + + *whichNode = 1; // only matters when count is requested + + if (isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0)) { - *whichNode = 1; - } - else - { - *whichNode = 0; - if (isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0)) - { - SET_GAME_STATE (UTWIG_BOMB, 1); - SET_GAME_STATE (UTWIG_BOMB_ON_SHIP, 1); - SET_GAME_STATE (DRUUGE_MANNER, 1); - SET_GAME_STATE (DRUUGE_VISITS, 0); - SET_GAME_STATE (DRUUGE_HOME_VISITS, 0); - } + SET_GAME_STATE (UTWIG_BOMB, 1); + SET_GAME_STATE (UTWIG_BOMB_ON_SHIP, 1); + SET_GAME_STATE (DRUUGE_MANNER, 1); + SET_GAME_STATE (DRUUGE_VISITS, 0); + SET_GAME_STATE (DRUUGE_HOME_VISITS, 0); } TFB_SeedRandom (old_rand); diff --git a/sc2/src/uqm/planets/generate/genvault.c b/sc2/src/uqm/planets/generate/genvault.c index cd2e3cf3f..e0d357fd0 100644 --- a/sc2/src/uqm/planets/generate/genvault.c +++ b/sc2/src/uqm/planets/generate/genvault.c @@ -80,27 +80,20 @@ GenerateVault_generateEnergy (SOLARSYS_STATE *solarSys, PLANET_DESC *world, { if (matchWorld (solarSys, world, 0, 0)) { - DWORD rand_val; DWORD old_rand; old_rand = TFB_SeedRandom ( solarSys->SysInfo.PlanetInfo.ScanSeed[ENERGY_SCAN]); - rand_val = TFB_Random (); - solarSys->SysInfo.PlanetInfo.CurPt.x = - (LOBYTE (LOWORD (rand_val)) % (MAP_WIDTH - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurPt.y = - (HIBYTE (LOWORD (rand_val)) % (MAP_HEIGHT - (8 << 1))) + 8; + GenerateRandomLocation (&solarSys->SysInfo); solarSys->SysInfo.PlanetInfo.CurDensity = 0; if (!GET_GAME_STATE (SHIP_VAULT_UNLOCKED)) solarSys->SysInfo.PlanetInfo.CurType = 0; else solarSys->SysInfo.PlanetInfo.CurType = 1; - // XXX: This node is always present, even after it is "picked up". - // Other similar pieces return the current node index when called - // by GeneratePlanetSide() to get the node info, and in that - // case the returned value is ignored AFAICT. - *whichNode = 1; + + // This node is always present, even after it is "picked up". + *whichNode = 1; // only matters when count is requested if (isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0)) { diff --git a/sc2/src/uqm/planets/generate/genvux.c b/sc2/src/uqm/planets/generate/genvux.c index 3f2833821..979cce510 100644 --- a/sc2/src/uqm/planets/generate/genvux.c +++ b/sc2/src/uqm/planets/generate/genvux.c @@ -207,59 +207,36 @@ static bool GenerateVux_generateEnergy (SOLARSYS_STATE *solarSys, PLANET_DESC *world, COUNT *whichNode) { - if (matchWorld (solarSys, world, 0, MATCH_PLANET) - && CurStarDescPtr->Index != VUX_BEAST_DEFINED) + if (CurStarDescPtr->Index == MAIDENS_DEFINED + && matchWorld (solarSys, world, 0, MATCH_PLANET)) { - if (CurStarDescPtr->Index == MAIDENS_DEFINED - && !GET_GAME_STATE (SHOFIXTI_MAIDENS)) - { - solarSys->SysInfo.PlanetInfo.CurPt.x = MAP_WIDTH / 3; - solarSys->SysInfo.PlanetInfo.CurPt.y = MAP_HEIGHT * 5 / 8; - solarSys->SysInfo.PlanetInfo.CurDensity = 0; - solarSys->SysInfo.PlanetInfo.CurType = 0; - if (!isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0) - && *whichNode == (COUNT)~0) - { - *whichNode = 1; - } - else - { - *whichNode = 0; - if (isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0)) - { - SET_GAME_STATE (SHOFIXTI_MAIDENS, 1); - SET_GAME_STATE (MAIDENS_ON_SHIP, 1); - } - } + if (GET_GAME_STATE (SHOFIXTI_MAIDENS)) + { // already picked up + *whichNode = 0; return true; } - if (CurStarDescPtr->Index == VUX_DEFINED) + solarSys->SysInfo.PlanetInfo.CurPt.x = MAP_WIDTH / 3; + solarSys->SysInfo.PlanetInfo.CurPt.y = MAP_HEIGHT * 5 / 8; + solarSys->SysInfo.PlanetInfo.CurDensity = 0; + solarSys->SysInfo.PlanetInfo.CurType = 0; + + *whichNode = 1; // only matters when count is requested + + if (isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0)) { - COUNT i; - DWORD rand_val; - DWORD old_rand; - - old_rand = TFB_SeedRandom ( - solarSys->SysInfo.PlanetInfo.ScanSeed[ENERGY_SCAN]); - - for (i = 0; i < 16; ++i) - { - rand_val = TFB_Random (); - solarSys->SysInfo.PlanetInfo.CurPt.x = - (LOBYTE (LOWORD (rand_val)) % (MAP_WIDTH - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurPt.y = - (HIBYTE (LOWORD (rand_val)) % (MAP_HEIGHT - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurType = 1; - solarSys->SysInfo.PlanetInfo.CurDensity = 0; - if (i >= *whichNode) - break; - } - *whichNode = i; - - TFB_SeedRandom (old_rand); - return true; + SET_GAME_STATE (SHOFIXTI_MAIDENS, 1); + SET_GAME_STATE (MAIDENS_ON_SHIP, 1); } + + return true; + } + + if (CurStarDescPtr->Index == VUX_DEFINED + && matchWorld (solarSys, world, 0, MATCH_PLANET)) + { + GenerateRandomRuins (&solarSys->SysInfo, 1, whichNode); + return true; } *whichNode = 0; @@ -279,23 +256,18 @@ GenerateVux_generateLife (SOLARSYS_STATE *solarSys, PLANET_DESC *world, old_rand = TFB_SeedRandom ( solarSys->SysInfo.PlanetInfo.ScanSeed[BIOLOGICAL_SCAN]); - for (i = 0; i < 12; ++i) + for (i = 0; i <= *whichNode && i < 12; ++i) { - DWORD rand_val = TFB_Random (); - solarSys->SysInfo.PlanetInfo.CurPt.x = - (LOBYTE (LOWORD (rand_val)) % (MAP_WIDTH - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurPt.y = - (HIBYTE (LOWORD (rand_val)) % (MAP_HEIGHT - (8 << 1))) + 8; + GenerateRandomLocation (&solarSys->SysInfo); if (i < 4) solarSys->SysInfo.PlanetInfo.CurType = 9; else if (i < 8) solarSys->SysInfo.PlanetInfo.CurType = 14; else /* if (i < 12) */ solarSys->SysInfo.PlanetInfo.CurType = 18; - if (i >= *whichNode) - break; } - *whichNode = i; + + *whichNode = 12; // only matters when count is requested TFB_SeedRandom (old_rand); return true; @@ -310,14 +282,10 @@ GenerateVux_generateLife (SOLARSYS_STATE *solarSys, PLANET_DESC *world, old_rand = TFB_SeedRandom ( solarSys->SysInfo.PlanetInfo.ScanSeed[BIOLOGICAL_SCAN]); - for (i = 0; i < 11; ++i) + for (i = 0; i <= *whichNode && i < 11; ++i) { - DWORD rand_val = TFB_Random (); - solarSys->SysInfo.PlanetInfo.CurPt.x = - (LOBYTE (LOWORD (rand_val)) % (MAP_WIDTH - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurPt.y = - (HIBYTE (LOWORD (rand_val)) % (MAP_HEIGHT - (8 << 1))) + 8; - if (i == 0) + GenerateRandomLocation (&solarSys->SysInfo); + if (i == 0) /* VUX Beast */ solarSys->SysInfo.PlanetInfo.CurType = NUM_CREATURE_TYPES + 2; else if (i <= 5) /* {SPEED_MOTIONLESS | DANGER_NORMAL, MAKE_BYTE (5, 3)}, */ @@ -325,27 +293,21 @@ GenerateVux_generateLife (SOLARSYS_STATE *solarSys, PLANET_DESC *world, else /* if (i <= 10) */ /* {BEHAVIOR_UNPREDICTABLE | SPEED_SLOW | DANGER_NORMAL, MAKE_BYTE (3, 8)}, */ solarSys->SysInfo.PlanetInfo.CurType = 8; - - // XXX: This currently does not need to be done in a loop. When a - // node is retrieved, the func is called with *whichNode==~0 - if (i == 0 - && isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, - BIOLOGICAL_SCAN, 0) - && !GET_GAME_STATE (VUX_BEAST)) - { - UnbatchGraphics (); - DoDiscoveryReport (MenuSounds); - BatchGraphics (); - SetLanderTakeoff (); - - SET_GAME_STATE (VUX_BEAST, 1); - SET_GAME_STATE (VUX_BEAST_ON_SHIP, 1); - } - - if (i >= *whichNode) - break; } - *whichNode = i; + + *whichNode = 11; // only matters when count is requested + + if (isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, BIOLOGICAL_SCAN, 0) + && !GET_GAME_STATE (VUX_BEAST)) + { // Picked up Zex' Beauty + UnbatchGraphics (); + DoDiscoveryReport (MenuSounds); + BatchGraphics (); + SetLanderTakeoff (); + + SET_GAME_STATE (VUX_BEAST, 1); + SET_GAME_STATE (VUX_BEAST_ON_SHIP, 1); + } TFB_SeedRandom (old_rand); return true; diff --git a/sc2/src/uqm/planets/generate/genwreck.c b/sc2/src/uqm/planets/generate/genwreck.c index 26b02f65c..ffb204bfa 100644 --- a/sc2/src/uqm/planets/generate/genwreck.c +++ b/sc2/src/uqm/planets/generate/genwreck.c @@ -74,27 +74,20 @@ GenerateWreck_generateEnergy (SOLARSYS_STATE *solarSys, PLANET_DESC *world, { if (matchWorld (solarSys, world, 6, MATCH_PLANET)) { - DWORD rand_val; DWORD old_rand; old_rand = TFB_SeedRandom ( solarSys->SysInfo.PlanetInfo.ScanSeed[ENERGY_SCAN]); - rand_val = TFB_Random (); - solarSys->SysInfo.PlanetInfo.CurPt.x = - (LOBYTE (LOWORD (rand_val)) % (MAP_WIDTH - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurPt.y = - (HIBYTE (LOWORD (rand_val)) % (MAP_HEIGHT - (8 << 1))) + 8; + GenerateRandomLocation (&solarSys->SysInfo); solarSys->SysInfo.PlanetInfo.CurDensity = 0; if (!GET_GAME_STATE (PORTAL_KEY)) solarSys->SysInfo.PlanetInfo.CurType = 0; else solarSys->SysInfo.PlanetInfo.CurType = 1; - // XXX: This node is always present, even after it is "picked up". - // Other similar pieces return the current node index when called - // by GeneratePlanetSide() to get the node info, and in that - // case the returned value is ignored AFAICT. - *whichNode = 1; + + // This node is always present, even after it is "picked up". + *whichNode = 1; // only matters when count is requested if (isNodeRetrieved (&solarSys->SysInfo.PlanetInfo, ENERGY_SCAN, 0)) { diff --git a/sc2/src/uqm/planets/generate/genyeh.c b/sc2/src/uqm/planets/generate/genyeh.c index ee8005a62..955c4c4ec 100644 --- a/sc2/src/uqm/planets/generate/genyeh.c +++ b/sc2/src/uqm/planets/generate/genyeh.c @@ -113,28 +113,7 @@ GenerateYehat_generateEnergy (SOLARSYS_STATE *solarSys, PLANET_DESC *world, { if (matchWorld (solarSys, world, 0, MATCH_PLANET)) { - COUNT i; - DWORD rand_val; - DWORD old_rand; - - old_rand = TFB_SeedRandom ( - solarSys->SysInfo.PlanetInfo.ScanSeed[ENERGY_SCAN]); - - for (i = 0; i < 16; ++i) - { - rand_val = TFB_Random (); - solarSys->SysInfo.PlanetInfo.CurPt.x = - (LOBYTE (LOWORD (rand_val)) % (MAP_WIDTH - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurPt.y = - (HIBYTE (LOWORD (rand_val)) % (MAP_HEIGHT - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurType = 1; - solarSys->SysInfo.PlanetInfo.CurDensity = 0; - if (i >= *whichNode) - break; - } - *whichNode = i; - - TFB_SeedRandom (old_rand); + GenerateRandomRuins (&solarSys->SysInfo, 1, whichNode); return true; } diff --git a/sc2/src/uqm/planets/generate/genzoq.c b/sc2/src/uqm/planets/generate/genzoq.c index f7a5ad97a..5760c1ecb 100644 --- a/sc2/src/uqm/planets/generate/genzoq.c +++ b/sc2/src/uqm/planets/generate/genzoq.c @@ -143,28 +143,7 @@ GenerateZoqFotPik_generateEnergy (SOLARSYS_STATE *solarSys, PLANET_DESC *world, { if (matchWorld (solarSys, world, 0, MATCH_PLANET)) { - COUNT i; - DWORD rand_val; - DWORD old_rand; - - old_rand = TFB_SeedRandom ( - solarSys->SysInfo.PlanetInfo.ScanSeed[ENERGY_SCAN]); - - for (i = 0; i < 16; ++i) - { - rand_val = TFB_Random (); - solarSys->SysInfo.PlanetInfo.CurPt.x = - (LOBYTE (LOWORD (rand_val)) % (MAP_WIDTH - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurPt.y = - (HIBYTE (LOWORD (rand_val)) % (MAP_HEIGHT - (8 << 1))) + 8; - solarSys->SysInfo.PlanetInfo.CurType = 1; - solarSys->SysInfo.PlanetInfo.CurDensity = 0; - if (i >= *whichNode) - break; - } - *whichNode = i; - - TFB_SeedRandom (old_rand); + GenerateRandomRuins (&solarSys->SysInfo, 1, whichNode); return true; } diff --git a/sc2/src/uqm/planets/sundata.h b/sc2/src/uqm/planets/sundata.h index db6139969..47c17f161 100644 --- a/sc2/src/uqm/planets/sundata.h +++ b/sc2/src/uqm/planets/sundata.h @@ -43,6 +43,10 @@ typedef struct extern DWORD GenerateMineralDeposits (SYSTEM_INFO *SysInfoPtr, COUNT *pwhich_deposit); extern DWORD GenerateLifeForms (SYSTEM_INFO *SysInfoPtr, COUNT *pwhich_life); +extern void GenerateRandomLocation (SYSTEM_INFO *); +extern DWORD GenerateRandomNodes (SYSTEM_INFO *, COUNT scan, COUNT numNodes, + COUNT type, COUNT *whichNode); +extern DWORD GenerateRandomRuins (SYSTEM_INFO *, COUNT type, COUNT *whichNode); #define DWARF_ELEMENT_DENSITY 1 #define GIANT_ELEMENT_DENSITY 3 diff --git a/sc2/src/uqm/planets/surface.c b/sc2/src/uqm/planets/surface.c index 7a5ccfa1b..f927e56ec 100644 --- a/sc2/src/uqm/planets/surface.c +++ b/sc2/src/uqm/planets/surface.c @@ -47,8 +47,6 @@ CalcMineralDeposits (SYSTEM_INFO *SysInfoPtr, COUNT which_deposit) { #define MEDIUM_DEPOSIT_THRESHOLD 150 #define LARGE_DEPOSIT_THRESHOLD 225 - DWORD rand_val; - UWORD loword, hiword; COUNT deposit_quality_fine, deposit_quality_gross; @@ -64,13 +62,7 @@ CalcMineralDeposits (SYSTEM_INFO *SysInfoPtr, COUNT which_deposit) else deposit_quality_gross = 2; - rand_val = TFB_Random (); - loword = LOWORD (rand_val); - hiword = HIWORD (rand_val); - SysInfoPtr->PlanetInfo.CurPt.x = - (LOBYTE (loword) % (MAP_WIDTH - (8 << 1))) + 8; - SysInfoPtr->PlanetInfo.CurPt.y = - (HIBYTE (loword) % (MAP_HEIGHT - (8 << 1))) + 8; + GenerateRandomLocation (SysInfoPtr); SysInfoPtr->PlanetInfo.CurDensity = MAKE_WORD ( @@ -219,11 +211,7 @@ CalcLifeForms (SYSTEM_INFO *SysInfoPtr, COUNT which_life) num_creatures = (BYTE)((HIBYTE (rand_val) % 10) + 1); do { - rand_val = (UWORD)TFB_Random (); - SysInfoPtr->PlanetInfo.CurPt.x = - (LOBYTE (rand_val) % (MAP_WIDTH - (8 << 1))) + 8; - SysInfoPtr->PlanetInfo.CurPt.y = - (HIBYTE (rand_val) % (MAP_HEIGHT - (8 << 1))) + 8; + GenerateRandomLocation (SysInfoPtr); SysInfoPtr->PlanetInfo.CurType = index; if (num_life_forms >= which_life @@ -256,5 +244,44 @@ GenerateLifeForms (SYSTEM_INFO *SysInfoPtr, COUNT *pwhich_life) return (TFB_SeedRandom (old_rand)); } +void +GenerateRandomLocation (SYSTEM_INFO *SysInfoPtr) +{ + UWORD rand_val; + rand_val = (UWORD)TFB_Random (); + 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 +GenerateRandomNodes (SYSTEM_INFO *SysInfoPtr, COUNT scan, COUNT numNodes, + COUNT type, COUNT *whichNode) +{ + DWORD old_rand; + COUNT i; + + old_rand = TFB_SeedRandom (SysInfoPtr->PlanetInfo.ScanSeed[scan]); + + for (i = 0; i < numNodes; ++i) + { + GenerateRandomLocation (SysInfoPtr); + SysInfoPtr->PlanetInfo.CurType = type; + SysInfoPtr->PlanetInfo.CurDensity = 0; + + if (i >= *whichNode) + break; + } + + *whichNode = i; // only matters when count is requested + + return (TFB_SeedRandom (old_rand)); +} + +DWORD +GenerateRandomRuins (SYSTEM_INFO *SysInfoPtr, COUNT type, COUNT *whichNode) +{ + return GenerateRandomNodes (SysInfoPtr, ENERGY_SCAN, 16, type, whichNode); +}