2 * Elite - The New Kind.
4 * Reverse engineered from the BBC disk version of Elite.
5 * Additional material by C.J.Pinder.
7 * The original Elite code is (C) I.Bell & D.Braben 1984.
8 * This version re-engineered in C by C.J.Pinder 1999-2001.
10 * email: <christian@newkind.co.uk>
16 * Handle the generation of planet info...
31 extern struct galaxy_seed hyperspace_planet
;
42 static struct random_seed rnd_seed
;
44 static char *digrams
="ABOUSEITILETSTONLONUTHNOALLEXEGEZACEBISOUSESARMAINDIREA?ERATENBERALAVETIEDORQUANTEISRION";
46 static char *inhabitant_desc1
[] = {"Large ", "Fierce ", "Small "};
48 static char *inhabitant_desc2
[] = {"Green ", "Red ", "Yellow ", "Blue ", "Black ", "Harmless "};
50 static char *inhabitant_desc3
[] = {"Slimy ", "Bug-Eyed ", "Horned ", "Bony ", "Fat ", "Furry "};
52 static char *inhabitant_desc4
[] = {"Rodent", "Frog", "Lizard", "Lobster", "Bird", "Humanoid", "Feline", "Insect"};
55 static char planet_description
[300];
56 static char *desc_ptr
;
61 static char *desc_list
[36][5] =
63 /* 0 */ {"fabled", "notable", "well known", "famous", "noted"},
64 /* 1 */ {"very", "mildly", "most", "reasonably", ""},
65 /* 2 */ {"ancient", "<20>", "great", "vast", "pink"},
66 /* 3 */ {"<29> <28> plantations", "mountains", "<27>", "<19> forests", "oceans"},
67 /* 4 */ {"shyness", "silliness", "mating traditions", "loathing of <5>", "love for <5>"},
68 /* 5 */ {"food blenders", "tourists", "poetry", "discos", "<13>"},
69 /* 6 */ {"talking tree", "crab", "bat", "lobst", "%R"},
70 /* 7 */ {"beset", "plagued", "ravaged", "cursed", "scourged"},
71 /* 8 */ {"<21> civil war", "<26> <23> <24>s", "a <26> disease", "<21> earthquakes", "<21> solar activity"},
72 /* 9 */ {"its <2> <3>", "the %I <23> <24>","its inhabitants' <25> <4>", "<32>", "its <12> <13>"},
73 /* 10 */ {"juice", "brandy", "water", "brew", "gargle blasters"},
74 /* 11 */ {"%R", "%I <24>", "%I %R", "%I <26>", "<26> %R"},
75 /* 12 */ {"fabulous", "exotic", "hoopy", "unusual", "exciting"},
76 /* 13 */ {"cuisine", "night life", "casinos", "sit coms", " <32> "},
77 /* 14 */ {"%H", "The planet %H", "The world %H", "This planet", "This world"},
78 /* 15 */ {"n unremarkable", " boring", " dull", " tedious", " revolting"},
79 /* 16 */ {"planet", "world", "place", "little planet", "dump"},
80 /* 17 */ {"wasp", "moth", "grub", "ant", "%R"},
81 /* 18 */ {"poet", "arts graduate", "yak", "snail", "slug"},
82 /* 19 */ {"tropical", "dense", "rain", "impenetrable", "exuberant"},
83 /* 20 */ {"funny", "wierd", "unusual", "strange", "peculiar"},
84 /* 21 */ {"frequent", "occasional", "unpredictable", "dreadful", "deadly"},
85 /* 22 */ {"<1> <0> for <9>", "<1> <0> for <9> and <9>", "<7> by <8>", "<1> <0> for <9> but <7> by <8>"," a<15> <16>"},
86 /* 23 */ {"<26>", "mountain", "edible", "tree", "spotted"},
87 /* 24 */ {"<30>", "<31>", "<6>oid", "<18>", "<17>"},
88 /* 25 */ {"ancient", "exceptional", "eccentric", "ingrained", "<20>"},
89 /* 26 */ {"killer", "deadly", "evil", "lethal", "vicious"},
90 /* 27 */ {"parking meters", "dust clouds", "ice bergs", "rock formations", "volcanoes"},
91 /* 28 */ {"plant", "tulip", "banana", "corn", "%Rweed"},
92 /* 29 */ {"%R", "%I %R", "%I <26>", "inhabitant", "%I %R"},
93 /* 30 */ {"shrew", "beast", "bison", "snake", "wolf"},
94 /* 31 */ {"leopard", "cat", "monkey", "goat", "fish"},
95 /* 32 */ {"<11> <10>", "%I <30> <33>","its <12> <31> <33>", "<34> <35>", "<11> <10>"},
96 /* 33 */ {"meat", "cutlet", "steak", "burgers", "soup"},
97 /* 34 */ {"ice", "mud", "Zero-G", "vacuum", "%I ultra"},
98 /* 35 */ {"hockey", "cricket", "karate", "polo", "tennis"}
109 * Generate a random number between 0 and 255.
110 * This is the version used in the 6502 Elites.
113 int gen_rnd_number (void)
117 x
= (rnd_seed
.a
* 2) & 0xFF;
119 if (rnd_seed
.a
> 127)
121 rnd_seed
.a
= a
& 0xFF;
124 a
= a
/ 256; /* a = any carry left from above */
126 a
= (a
+ x
+ rnd_seed
.d
) & 0xFF;
134 * Generate a random number between 0 and 255.
135 * This is the version used in the MSX and 16bit Elites.
139 int gen_msx_rnd_number (void)
146 rnd_seed
.a
= rnd_seed
.c
;
147 rnd_seed
.b
= rnd_seed
.d
;
150 b
= (b
+ rnd_seed
.d
) & 255;
160 return rnd_seed
.c
/ 0x34;
164 void waggle_galaxy (struct galaxy_seed
*glx_ptr
)
168 extern int carry_flag
;
170 x
= glx_ptr
->a
+ glx_ptr
->c
;
171 y
= glx_ptr
->b
+ glx_ptr
->d
;
180 glx_ptr
->a
= glx_ptr
->c
;
181 glx_ptr
->b
= glx_ptr
->d
;
182 glx_ptr
->c
= glx_ptr
->e
;
183 glx_ptr
->d
= glx_ptr
->f
;
207 struct galaxy_seed
find_planet (int cx
, int cy
)
209 int min_dist
= 10000;
210 struct galaxy_seed glx
;
211 struct galaxy_seed planet
;
218 for (i
= 0; i
< 256; i
++)
221 dx
= abs(cx
- glx
.d
);
222 dy
= abs(cy
- glx
.b
);
225 distance
= (dx
+ dx
+ dy
) / 2;
227 distance
= (dx
+ dy
+ dy
) / 2;
229 if (distance
< min_dist
)
235 waggle_galaxy (&glx
);
236 waggle_galaxy (&glx
);
237 waggle_galaxy (&glx
);
238 waggle_galaxy (&glx
);
245 int find_planet_number (struct galaxy_seed planet
)
247 struct galaxy_seed glx
;
252 for (i
= 0; i
< 256; i
++)
255 if ((planet
.a
== glx
.a
) &&
256 (planet
.b
== glx
.b
) &&
257 (planet
.c
== glx
.c
) &&
258 (planet
.d
== glx
.d
) &&
259 (planet
.e
== glx
.e
) &&
263 waggle_galaxy (&glx
);
264 waggle_galaxy (&glx
);
265 waggle_galaxy (&glx
);
266 waggle_galaxy (&glx
);
274 void name_planet (char *gname
, struct galaxy_seed glx
)
284 if ((glx
.a
& 0x40) == 0)
289 for (i
= 0; i
< size
; i
++)
297 if (digrams
[x
+1] != '?')
298 *gp
++ = digrams
[x
+1];
301 waggle_galaxy (&glx
);
308 void capitalise_name (char *name
)
315 *ptr
= toupper(*ptr
);
320 *ptr
= tolower(*ptr
);
326 void describe_inhabitants (char *str
, struct galaxy_seed planet
)
334 strcat (str
, "Human Colonial");
338 inhab
= (planet
.f
/ 4) & 7;
340 strcat (str
, inhabitant_desc1
[inhab
]);
342 inhab
= planet
.f
/ 32;
344 strcat (str
, inhabitant_desc2
[inhab
]);
346 inhab
= (planet
.d
^ planet
.b
) & 7;
348 strcat (str
, inhabitant_desc3
[inhab
]);
350 inhab
= (inhab
+ (planet
.f
& 3)) & 7;
351 strcat (str
, inhabitant_desc4
[inhab
]);
359 void expand_description (char *source
)
368 while (*source
!= '\0')
374 while (*source
!= '>')
382 option
= gen_msx_rnd_number();
386 rnd
= gen_rnd_number();
388 if (rnd
>= 0x33) option
++;
389 if (rnd
>= 0x66) option
++;
390 if (rnd
>= 0x99) option
++;
391 if (rnd
>= 0xCC) option
++;
394 expand_description (desc_list
[num
][option
]);
404 name_planet (str
, hyperspace_planet
);
405 capitalise_name (str
);
406 for (ptr
= str
; *ptr
!= '\0';)
407 *desc_ptr
++ = *ptr
++;
411 name_planet (str
, hyperspace_planet
);
412 capitalise_name (str
);
413 for (ptr
= str
; *ptr
!= '\0';)
414 *desc_ptr
++ = *ptr
++;
416 strcpy (desc_ptr
, "ian");
421 len
= gen_rnd_number() & 3;
422 for (i
= 0; i
<= len
; i
++)
424 x
= gen_rnd_number() & 0x3e;
426 *desc_ptr
++ = digrams
[x
];
428 *desc_ptr
++ = tolower(digrams
[x
]);
429 *desc_ptr
++ = tolower(digrams
[x
+1]);
438 *desc_ptr
++ = *source
++;
448 char *describe_planet (struct galaxy_seed planet
)
452 if (cmdr
.mission
== 1)
454 mission_text
= mission_planet_desc (planet
);
455 if (mission_text
!= NULL
)
459 rnd_seed
.a
= planet
.c
;
460 rnd_seed
.b
= planet
.d
;
461 rnd_seed
.c
= planet
.e
;
462 rnd_seed
.d
= planet
.f
;
466 rnd_seed
.a
^= planet
.a
;
467 rnd_seed
.b
^= planet
.b
;
468 rnd_seed
.c
^= rnd_seed
.a
;
469 rnd_seed
.d
^= rnd_seed
.b
;
472 desc_ptr
= planet_description
;
474 expand_description ("<14> is <22>.");
476 return planet_description
;
481 void generate_planet_data (struct planet_data
*pl
, struct galaxy_seed planet_seed
)
484 pl
->government
= (planet_seed
.c
/ 8) & 7;
486 pl
->economy
= planet_seed
.b
& 7;
488 if (pl
->government
< 2)
489 pl
->economy
= pl
->economy
| 2;
491 pl
->techlevel
= pl
->economy
^ 7;
492 pl
->techlevel
+= planet_seed
.d
& 3;
493 pl
->techlevel
+= (pl
->government
/ 2) + (pl
->government
& 1);
496 pl
->population
= pl
->techlevel
* 4;
497 pl
->population
+= pl
->government
;
498 pl
->population
+= pl
->economy
;
501 pl
->productivity
= (pl
->economy
^ 7) + 3;
502 pl
->productivity
*= pl
->government
+ 4;
503 pl
->productivity
*= pl
->population
;
504 pl
->productivity
*= 8;
506 pl
->radius
= (((planet_seed
.f
& 15) + 11) * 256) + planet_seed
.d
;