40 userErrorFnc = vuserErrorFnc;
41 progErrorFnc = vprogErrorFnc;
58 for(i=0;i<=
lasttrade;i++) strcpy_s(tradnames[i],commodities[i].name);
62 galaxynum=1; buildgalaxy(galaxynum);
65 localmarket = genmarket(0x00,galaxy[
numforLave]);
92 std::vector<int> * myLocalSystems =
new std::vector<int>;
94 for(syscount=0;syscount<
galsize;++syscount)
95 { d=distance(galaxy[syscount],galaxy[currentplanet]);
98 myLocalSystems->push_back(syscount);
101 return myLocalSystems;
107 unsigned int right,
unsigned int bottom,
unsigned int top)
110 std::vector<int> * mySystems =
new std::vector<int>;
112 if (left < 0) left = 0;
113 if (bottom < 0) bottom = 0;
114 if (right < 0) right = 0;
115 if (top < 0) top = 0;
117 for(syscount=0;syscount<
galsize;++syscount)
119 if( (galaxy[syscount].
x >= left)
120 && (galaxy[syscount].
x <= right)
121 && (galaxy[syscount].
y >= bottom)
122 && (galaxy[syscount].
y <= top))
124 mySystems->push_back(syscount);
135 if (number<0 || number >=
galsize) {
136 progErrorFnc(
"The integer in 'number' has to be between 0 and 256! Error occured in getSystemInformation(int number) in txtelite.cpp");
137 mySystem.
name =
"Error! No System";
150 plansys mySys = galaxy[number];
152 mySystem.
posx = mySys.
x;
153 mySystem.
posy = mySys.
y;
163 mySystem.
description = goat_soup(
"\x8F is \x97.",&mySys);
172 uint d=distance(galaxy[number],galaxy[currentplanet]);
180 uint d=distance(galaxy[number],galaxy[currentplanet]);
181 return (d <= maxfuel);
187 return (
float)(fuel/10);
193 return (
float)(maxfuel/10);
202 std::vector<MarketplaceItem> * result =
new std::vector<MarketplaceItem>;
208 result->push_back(mi);
216 std::vector<int> * result =
new std::vector<int>;
219 result->push_back(shipshold[i]);
237 if ((commodities[i].units)==
tons) t+=shipshold[i];
239 return (t+holdspace);
259 return ((commodities[number].units)==
tons);
270 if (amount > maxfuel){
271 progErrorFnc(
"'amount' must be between 0.0 and 7.0. Error occured in setFuel in txtelite.cpp");
290 if ((commodities[i].units)==
tons) t+=shipshold[i];
293 progErrorFnc(
"The cargo bay cannot be set to this value because there is too much cargo. Error occured in setCargoBay in txtelite.cpp.");
306 if (number < 0 || number >
galsize)
308 progErrorFnc(
"The integer in 'number' has to be between 0 and 256! Error occured in performJump(int number) in txtelite.cpp");
return; };
310 uint d=distance(galaxy[number],galaxy[currentplanet]);
314 userErrorFnc(
"Jump too far (system not in range, even with full fuel)");
return; };
318 userErrorFnc(
"Jump too far (system in range, but not enough fuel)");
return; };
320 if (number == currentplanet)
321 { userErrorFnc(
"Already there!");
return; };
325 currentplanet=number;
326 localmarket = genmarket(randbyte(),galaxy[number]);
329 std::string report =
"Jumped to ";
330 report += galaxy[number].
name;
332 userErrorFnc(report);
340 std::string errorreport;
343 progErrorFnc(
"'number' is too high. This error occured in the function performPurchase in the file txtelite.cpp");
348 errorreport =
"Nothing was bought";
350 if (amount == 0)
return errorreport;
352 userErrorFnc(
"You don't have any cash.");
355 t = mymin((
uint)floor((
double)cash/(localmarket.
price[number])),t);
357 std::string errortext =
"You don't have enough cash to buy anything.";
358 userErrorFnc(errortext);
361 if (localmarket.
quantity[number] <= 0){
362 userErrorFnc(
"The market does not sell this at the moment.");
365 t = mymin(localmarket.
quantity[number],t);
366 if ((commodities[number].units)==
tons){
368 userErrorFnc(
"Your cargo bay is full! You can only buy items that weigh less than a ton.");
371 t = mymin(holdspace,t);
373 shipshold[number]+=t;
375 cash-=t*(localmarket.
price[number]);
376 if ((commodities[number].units)==
tons) {holdspace-=t;}
378 std::stringstream freport;
382 std::string report=
"Bought ";
384 report += unitnames[commodities[number].
units];
386 report += tradnames[number];
397 progErrorFnc(
"'number' is too high. This error occured in the function performPurchase in the file txtelite.cpp");
401 if (shipshold[number] == 0) {
402 userErrorFnc(
"You don't have any of these.");
403 return "Nothing was selled";
405 shipshold[number]-=t;
407 if ((commodities[number].units)==
tons) {holdspace+=t;}
408 cash+=t*(localmarket.
price[number]);
410 std::stringstream freport;
414 std::string report=
"Sold ";
416 report += unitnames[commodities[number].
units];
418 report += tradnames[number];
427 userErrorFnc(
"Can't buy any fuel (Tank is already full).");
433 userErrorFnc(
"Buying less fuel (otherwise it doesn't fit into the tank). ");
438 if ((
int)f*fuelcost>cash)
440 f = (
uint)(cash/fuelcost);
442 userErrorFnc(
"Buying less fuel (not enough cash available to buy whole amount). ");
444 userErrorFnc(
"Can't buy any fuel (Not enough cash).");
451 std::stringstream freport;
453 freport << (float)f/10;
455 std::string report=
"Bought ";
457 report +=
" LY fuel.";
458 userErrorFnc(report);
472 strcpy_s(unitnames[0],
"t");
473 strcpy_s(unitnames[1],
"kg");
474 strcpy_s(unitnames[2],
"g");
480 commodities[0].
units=0;
481 strcpy_s(commodities[0].name,
"Food ");
487 commodities[1].
units=0;
488 strcpy_s(commodities[1].name,
"Textiles");
494 commodities[2].
units=0;
495 strcpy_s(commodities[2].name,
"Radioactives");
501 commodities[3].
units=0;
502 #if POLITICALLY_CORRECT
503 strcpy_s(commodities[3].name,
"Robot Slaves");
505 strcpy_s(commodities[3].name,
"Slaves");
512 commodities[4].
units=0;
513 #if POLITICALLY_CORRECT
514 strcpy_s(commodities[4].name,
"Beverages ");
516 strcpy_s(commodities[4].name,
"Liquor/Wines");
523 commodities[5].
units=0;
524 strcpy_s(commodities[5].name,
"Luxuries");
530 commodities[6].
units=0;
531 #if POLITICALLY_CORRECT
532 strcpy_s(commodities[6].name,
"Rare Species");
534 strcpy_s(commodities[6].name,
"Narcotics ");
541 commodities[7].
units=0;
542 strcpy_s(commodities[7].name,
"Computers ");
548 commodities[8].
units=0;
549 strcpy_s(commodities[8].name,
"Machinery ");
555 commodities[9].
units=0;
556 strcpy_s(commodities[9].name,
"Alloys");
562 commodities[10].
units=0;
563 strcpy_s(commodities[10].name,
"Firearms");
569 commodities[11].
units=0;
570 strcpy_s(commodities[11].name,
"Furs ");
576 commodities[12].
units=0;
577 strcpy_s(commodities[12].name,
"Minerals");
583 commodities[13].
units=1;
584 strcpy_s(commodities[13].name,
"Gold ");
590 commodities[14].
units=1;
591 strcpy_s(commodities[14].name,
"Platinum");
597 commodities[15].
units=2;
598 strcpy_s(commodities[15].name,
"Gem-Strones ");
604 commodities[16].
units=0;
605 strcpy_s(commodities[16].name,
"Alien Items ");
607 for (
int i = 0; i <
lasttrade+1; i++) { shipshold[i] = 0; }
652 void TextEliteGame::mysrand(
unsigned int seed)
657 int TextEliteGame::myrand(
void)
659 if(nativerand) r=rand();
662 r = (((((((((((lastrand << 3) - lastrand) << 3)
663 + lastrand) << 1) + lastrand) << 4)
664 - lastrand) << 1) - lastrand) + 0xe60)
671 char TextEliteGame::randbyte(
void)
673 return (
char)(myrand()&0xFF);
685 signed int TextEliteGame::ftoi(
double value)
686 {
return ((
signed int)floor(value+0.5));
689 void TextEliteGame::tweakseed(
seedtype *s)
691 temp = ((*s).w0)+((*s).w1)+((*s).w2);
700 void TextEliteGame::stripout(
char *s,
const char c)
703 {
if(s[i]!=c) { s[j]=s[i]; j++;}
709 int TextEliteGame::toupper(
char c)
710 {
if((c>=
'a')&&(c<=
'z'))
return(c+
'A'-
'a');
714 int TextEliteGame::tolower(
char c)
715 {
if((c>=
'A')&&(c<=
'Z'))
return(c+
'a'-
'A');
741 signed int product = (p.
economy)*(commodities[i].gradient);
742 signed int changing = fluct & (commodities[i].
maskbyte);
743 q =(commodities[i].
basequant) + changing - product;
749 q =(commodities[i].
baseprice) + changing + product;
762 char pairs[] =
"..lexegezacebiso"
768 uint pair1,pair2,pair3,pair4;
769 uint16 longnameflag=((*s).w0)&64;
771 thissys.
x=(((*s).w1)>>8);
772 thissys.
y=(((*s).w0)>>8);
774 thissys.
govtype =((((*s).w1)>>3)&7);
776 thissys.
economy =((((*s).w0)>>8)&7);
792 thissys.
radius = 256*(((((*s).w2)>>8)&15)+11) + thissys.
x;
799 pair1=2*((((*s).w2)>>8)&31);tweakseed(s);
800 pair2=2*((((*s).w2)>>8)&31);tweakseed(s);
801 pair3=2*((((*s).w2)>>8)&31);tweakseed(s);
802 pair4=2*((((*s).w2)>>8)&31); tweakseed(s);
805 (thissys.
name)[0]=pairs[pair1];
806 (thissys.
name)[1]=pairs[pair1+1];
807 (thissys.
name)[2]=pairs[pair2];
808 (thissys.
name)[3]=pairs[pair2+1];
809 (thissys.
name)[4]=pairs[pair3];
810 (thissys.
name)[5]=pairs[pair3+1];
814 (thissys.
name)[6]=pairs[pair4];
815 (thissys.
name)[7]=pairs[pair4+1];
818 else (thissys.
name)[6]=0;
819 stripout(thissys.
name,
'.');
821 if (thissys.
name[0] != 0)
822 thissys.
name[0] = toupper(thissys.
name[0]);
837 return (2*(x&127))+(temp>>7);
841 {
return (
uint16)((256*rotatel(x>>8))+rotatel(x&255));
844 void TextEliteGame::nextgalaxy(
seedtype *s)
845 { (*s).w0 = twist((*s).w0);
846 (*s).w1 = twist((*s).w1);
847 (*s).w2 = twist((*s).w2);
851 void TextEliteGame::buildgalaxy(
uint galaxynum)
852 {
uint syscount,galcount;
853 seed.
w0=base0; seed.
w1=base1; seed.
w2=base2;
854 for(galcount=1;galcount<galaxynum;++galcount) nextgalaxy(&seed);
856 for(syscount=0;syscount<
galsize;++syscount) galaxy[syscount]=makesystem(&seed);
864 {
return (
uint)ftoi(4*sqrt((
float)((a.
x-b.
x)*(a.
x-b.
x)+(a.
y-b.
y)*(a.
y-b.
y)/4)));
867 myboolean TextEliteGame::dogalhyp(
char *s)
872 if(galaxynum==9) {galaxynum=1;}
873 buildgalaxy(galaxynum);
885 int TextEliteGame::gen_rnd_number (
void)
887 x = (rnd_seed.
a * 2) & 0xFF;
889 if (rnd_seed.
a > 127) a++;
890 rnd_seed.
a = a & 0xFF;
895 a = (a + x + rnd_seed.
d) & 0xFF;
901 std::string TextEliteGame::goat_soup(
const char *source,
plansys * psy)
903 static struct desc_choice desc_list[] =
905 {
"fabled",
"notable",
"well known",
"famous",
"noted"},
906 {
"very",
"mildly",
"most",
"reasonably",
""},
907 {
"ancient",
"\x95",
"great",
"vast",
"pink"},
908 {
"\x9E \x9D plantations",
"mountains",
"\x9C",
"\x94 forests",
"oceans"},
909 {
"shyness",
"silliness",
"mating traditions",
"loathing of \x86",
"love for \x86"},
910 {
"food blenders",
"tourists",
"poetry",
"discos",
"\x8E"},
911 {
"talking tree",
"crab",
"bat",
"lobst",
"\xB2"},
912 {
"beset",
"plagued",
"ravaged",
"cursed",
"scourged"},
913 {
"\x96 civil war",
"\x9B \x98 \x99s",
"a \x9B disease",
"\x96 earthquakes",
"\x96 solar activity"},
914 {
"its \x83 \x84",
"the \xB1 \x98 \x99",
"its inhabitants' \x9A \x85",
"\xA1",
"its \x8D \x8E"},
915 {
"juice",
"brandy",
"water",
"brew",
"gargle blasters"},
916 {
"\xB2",
"\xB1 \x99",
"\xB1 \xB2",
"\xB1 \x9B",
"\x9B \xB2"},
917 {
"fabulous",
"exotic",
"hoopy",
"unusual",
"exciting"},
918 {
"cuisine",
"night life",
"casinos",
"sit coms",
" \xA1 "},
919 {
"\xB0",
"The planet \xB0",
"The world \xB0",
"This planet",
"This world"},
920 {
"n unremarkable",
" boring",
" dull",
" tedious",
" revolting"},
921 {
"planet",
"world",
"place",
"little planet",
"dump"},
922 {
"wasp",
"moth",
"grub",
"ant",
"\xB2"},
923 {
"poet",
"arts graduate",
"yak",
"snail",
"slug"},
924 {
"tropical",
"dense",
"rain",
"impenetrable",
"exuberant"},
925 {
"funny",
"wierd",
"unusual",
"strange",
"peculiar"},
926 {
"frequent",
"occasional",
"unpredictable",
"dreadful",
"deadly"},
927 {
"\x82 \x81 for \x8A",
"\x82 \x81 for \x8A and \x8A",
"\x88 by \x89",
"\x82 \x81 for \x8A but \x88 by \x89",
"a\x90 \x91"},
928 {
"\x9B",
"mountain",
"edible",
"tree",
"spotted"},
929 {
"\x9F",
"\xA0",
"\x87oid",
"\x93",
"\x92"},
930 {
"ancient",
"exceptional",
"eccentric",
"ingrained",
"\x95"},
931 {
"killer",
"deadly",
"evil",
"lethal",
"vicious"},
932 {
"parking meters",
"dust clouds",
"ice bergs",
"rock formations",
"volcanoes"},
933 {
"plant",
"tulip",
"banana",
"corn",
"\xB2weed"},
934 {
"\xB2",
"\xB1 \xB2",
"\xB1 \x9B",
"inhabitant",
"\xB1 \xB2"},
935 {
"shrew",
"beast",
"bison",
"snake",
"wolf"},
936 {
"leopard",
"cat",
"monkey",
"goat",
"fish"},
937 {
"\x8C \x8B",
"\xB1 \x9F \xA2",
"its \x8D \xA0 \xA2",
"\xA3 \xA4",
"\x8C \x8B"},
938 {
"meat",
"cutlet",
"steak",
"burgers",
"soup"},
939 {
"ice",
"mud",
"Zero-G",
"vacuum",
"\xB1 ultra"},
940 {
"hockey",
"cricket",
"karate",
"polo",
"tennis"}
942 char pairs0[]=
"ABOUSEITILETSTONLONUTHNO";
944 std::string result =
"";
948 {
uint8 c=*(source++);
955 {
int rnd = gen_rnd_number();
956 result += goat_soup(desc_list[c-0x81].option[(rnd >= 0x33)+(rnd >= 0x66)+(rnd >= 0x99)+(rnd >= 0xCC)],psy);
961 result += psy->
name[0];
962 while(psy->
name[i]!=
'\0')
964 result += tolower(psy->
name[i++]);
969 result += psy->
name[0];
970 while(psy->
name[i]!=
'\0')
971 {
if((psy->
name[i+1]!=
'\0') || ((psy->
name[i]!=
'E') && (psy->
name[i]!=
'I')))
973 result += tolower(psy->
name[i]);
981 int len = gen_rnd_number() & 3;
983 {
int x = gen_rnd_number() & 0x3e;
988 if(i && (pairs0[x+1]!=
'.'))
990 result += pairs0[x+1];
994 default:
return "<bad char in data [%X]>";