Advertisement
Guest User

Frontier generator

a guest
Mar 27th, 2013
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.80 KB | None | 0 0
  1. #include <string.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. char *namepart[] = {
  6.     "en" , "la" , "can", "be" ,
  7.     "and", "phi", "eth", "ol" ,
  8.     "ve" , "ho" , "a"  , "lia",
  9.     "an" , "ar" , "ur" , "mi" ,
  10.     "in" , "ti" , "qu" , "so" ,
  11.     "ed" , "ess", "ex" , "io" ,
  12.     "ce" , "ze" , "fa" , "ay" ,
  13.     "wa" , "da" , "ack", "gre"
  14. };
  15.  
  16. int SystemParam_0;
  17. int SystemParam_1;
  18.  
  19. unsigned char TheMilkyWay[129];
  20.  
  21. unsigned int SystemDensity[] = {
  22.     0xBF78, 0x5B2F, 0xDF85, 0x3C14, 0xDADD, 0x38DF, 0xE08F, 0x88D7,
  23.     0xB3AB, 0xEA86, 0x1200, 0x8DB3, 0xFF0D, 0xA593, 0xEC66, 0x1988,
  24.     0x8500, 0xC1E7, 0x9281, 0xD7EB, 0x5F77, 0xD6A5, 0x310B, 0x2C98,
  25.     0x906E, 0x2CB6, 0xF137, 0x8ADC, 0x0FC7, 0x76B8, 0xB587, 0x2D1B,
  26.     0xAD4C, 0x1AEB, 0xB749, 0xC60D, 0xB914, 0x1B3A, 0xAA5E, 0x3764,
  27.     0xD7A0, 0x650E, 0xDB8D, 0x3E98, 0x1DDD, 0xD3BB, 0x54A4, 0x66BA,
  28.     0x164F, 0xF3B8, 0x7460, 0xBF9A, 0x7AA7, 0x459C, 0x61EC, 0xF706,
  29.     0x958C, 0x8B54, 0x86E8, 0xC653, 0x5D7C, 0x6AC9, 0xAD35, 0x8B1F,
  30.     0x30C6, 0x7EF7, 0x4E4F, 0xD1F3, 0xD042, 0x4AAC, 0x6F5A, 0x15C4,
  31.     0x4DC3, 0x923C, 0x04E2, 0x2C8B, 0xAB14, 0x9689, 0x5553, 0x92F7,
  32.     0x3BC6, 0x7C86, 0x5E8D, 0xFF7F, 0x8F5C, 0x0450, 0x0BD3, 0xB01F,
  33.     0x2744, 0xDF20, 0xE40E, 0x932C, 0x8B90, 0xCF40, 0x6E2B, 0x81BE,
  34.     0x200B, 0xA64F, 0x2BA4, 0xDCB8, 0xEA35, 0xACC4, 0x1421, 0x9025,
  35.     0x9A98, 0x4993, 0x99EF, 0xB4FD, 0x0BCF, 0x7434, 0x7287, 0xC67F,
  36.     0x1967, 0xF486, 0x12AD, 0xDF33, 0xDF74, 0x2913, 0x2FF4, 0xD76B,
  37.     0x5A2A, 0x8B80, 0xCB01, 0x742B, 0x09B4, 0xC203, 0x56AF, 0xDAD6,
  38.     0x8000, 0x5555, 0x4000, 0x3333, 0x2AAA, 0x2492, 0x1FF0, 0x1C71,
  39.     0x1999, 0x1745, 0x1555, 0x13B1, 0x1249, 0x1111, 0x0FF0, 0x0F0F
  40. };
  41.  
  42. unsigned int KnownSpaceCoord[49][2] = {
  43.     5912,5412, 5913,5412, 5913,5413, 5912,5413, 5911,5413, 5911,5412, 5911,5411,
  44.     5912,5411, 5913,5411, 5914,5411, 5914,5412, 5914,5413, 5913,5414, 5912,5414,
  45.     5911,5414, 5910,5413, 5910,5412, 5910,5411, 5911,5410, 5912,5410, 5913,5410,
  46.     5909,5414, 5917,5414, 5917,5411, 5913,5408, 5916,5416, 5918,5416, 5918,5406,
  47.     5908,5395, 5906,5372, 5873,5378, 5971,5426, 6004,5418, 5944,5444, 5912,5488,
  48.     5766,5497, 5908,5422, 5912,5417, 5912,5416, 5913,5418, 5914,5417, 5915,5417,
  49.     5909,5419, 5909,5406, 5910,5406, 5909,5407, 5908,5407, 5908,5406, 5910,5416 };
  50.  
  51. char *KnownSpace[117] = {
  52.     "Sol",          // Start of sector (0,0)
  53.     "Alpha Centauri",
  54.     "Wolf 359",
  55.     "Lalande 21185 ",
  56.     "UV Ceti",
  57.     "Ross 128",
  58.     "Tau Ceti",
  59.     "LET 118",
  60.     "Wolf 424",
  61.     "CD-37º15492",
  62.     "Lalande 25372",
  63.     "Sirius",           // sector (1,0)
  64.     "Epsilon Eridani",
  65.     "Procyon",
  66.     "BD+5º1668",
  67.     "BD+20º2465",
  68.     "Groombridge 1618", // 1,1
  69.     "Luyten 1159-16",
  70.     "WX Ursa Majoris",
  71.     "+53º1320",
  72.     "Ross 248",         // 0,1
  73.     "Groombridge 34",
  74.     "van Maanens Star",
  75.     "Giclas 158-27",
  76.     "61 Cygni",         // -1,1
  77.     "Struve 2398",
  78.     "1º4774",
  79.     "Barnards Star",    // -1,0
  80.     "Ross 154",
  81.     "Luyten 789-6",
  82.     "Lacaille 9352",
  83.     "Lacaille 8760",
  84.     "Ross 780",
  85.     "Fomalhaut",
  86.     "Epsilon Indi",     // -1,-1
  87.     "BD 4523",
  88.     "CD-46º11540",
  89.     "CD-49º13515",
  90.     "CD-44º11909",
  91.     "-11º3759",
  92.     "Kapteyns Star",    // 1,-1
  93.     "82 Eridani",
  94.     "Luyten 674-15",    // 2,-1
  95.     "Ross 614",         // 2,0
  96.     "Omicron Eridani",
  97.     "YZ Canis Minoris",
  98.     "-21º1377",
  99.     "HD 36395",
  100.     "LP 658-2",
  101.     "Ross 986",         // 2,1
  102.     "Ross 47",
  103.     "Wolf 294",
  104.     "Stein 2051",       // 1,2
  105.     "AC+79º3888",      // 0,2
  106.     "Eta Cassiopeia",
  107.     "Krüger 60",       // -1,2
  108.     "BD 946",
  109.     "BD+43º4305",
  110.     "Sigma Draconis",
  111.     "+19º5116",
  112.     "Altair",           // -2,1
  113.     "FU 46",
  114.     "70 Ophiuchi",      // -2,0
  115.     "VB 10",
  116.     "Arcturus",
  117.     "36 Ophiuchi",      // -2,1
  118.     "HR 7703",
  119.     "Luyten 347-14",
  120.     "Wolf 630",
  121.     "Delta Pavonis",    // -1,-2
  122.     "Luyten 205-128",
  123.     "-40º9712",
  124.     "-45º13677",
  125.     "Luyten 145-41",    // 0,-2
  126.     "Beta Hydri",
  127.     "Luyten 97-12",     // 1,-2
  128.     "Vega",             // -3,2
  129.     "Castor",           // 5,2
  130.     "Pollux",
  131.     "Regulus",          // 5,-1
  132.     "Achenar",          // 1,-4
  133.     "Capella",          // 4,4
  134.     "Aldebaran",        // 6,4
  135.     "Canopus",          // 6,-6
  136.     "Spica",            // -4,-17
  137.     "Hadar",            // -6,-40
  138.     "Antares",          // -39,-34
  139.     "Betelgeuse",       // 59,14
  140.     "Rigel",            // 92,6
  141.     "Alcyone",          // 32,32; the Pleiades
  142.     "Atlas",
  143.     "Electra",
  144.     "Maia",
  145.     "Merope",
  146.     "Taygete",
  147.     "Pleione",
  148.     "Polaris",          // 0,76
  149.     "Beta Lyrae",       // -146,85
  150.     "Alkaid",           // -4,10
  151.     "Mizar",            // 0,5
  152.     "Alcor",
  153.     "Alioth",           // 0,4
  154.     "Megrez",           // 1,6
  155.     "Phekda",           // 2,5
  156.     "Merak",            // 3,5
  157.     "Dubhe",            // -3,7
  158.     "Lave",             // -3,-6; some original Elite systems
  159.     "Diso",
  160.     "Riedquat",
  161.     "Leesti",
  162.     "Orerve",
  163.     "Zaonce",           // -2,-6
  164.     "Tionisla",
  165.     "Reorte",           // -3,-5
  166.     "Uszaa",
  167.     "Orrere",
  168.     "Quator"
  169. };
  170.  
  171. int counter=0;
  172. int generate_sector (unsigned int coordx, unsigned int coordy, int galaxyScale)
  173. {
  174.  
  175.  
  176.     unsigned long p1,p2,p3,p4;
  177.     unsigned long eax,ebx,ecx,edx,esi,edi;
  178.     int pixelval;
  179.     if (coordx > 0x1fff || coordy > 0x1fff) return 0;
  180.     pixelval = (coordx/64)+2*(coordy & 0x1fc0);
  181.  
  182.     printf("%i %d\n",    counter++, pixelval );
  183.     return 0;
  184.  
  185.     p1 = TheMilkyWay[pixelval];    // Current center
  186.     p3 = TheMilkyWay[pixelval+128];    // Next row
  187.     p4 = TheMilkyWay[pixelval+129];    // Next row, next column
  188.     p2 = TheMilkyWay[pixelval+1];    // Next column
  189.     coordx = (coordx * 0x200) & 0x7e00;
  190.     coordy = (coordy * 0x200) & 0x7e00;
  191.     ebx = (p2-p1)*coordx + (p3-p1)*coordy;    // -0x0FB0400...0x0FB0400
  192.     esi = (coordx*coordy)>>15;        // 0..0x7C08
  193.     edi = p4 - p3 - p2 + p1;
  194.     esi *= edi;
  195.     ebx += esi;
  196.     ebx += ebx;
  197.     p1 <<= 16;                // p1 is now VVVV.VVVV.0000.0000
  198.     ebx += p1;
  199.     ecx = ebx >> 8;
  200.  
  201.  
  202.     if (galaxyScale < 16)
  203.     {
  204.         ebx = coordx + ecx;
  205.         eax =coordx * coordy;
  206. //        (signed long)eax >>= 15;
  207.     eax >>= 15;
  208.  
  209.         ebx ^= eax;
  210. //        (signed long)ebx >>= 5;
  211.     ebx >>= 5;
  212.  
  213. //  printf("%d",ebx);
  214.  
  215.         ebx &= 0x7f;
  216.         eax = SystemDensity[ebx];
  217.         if (galaxyScale)
  218.         {
  219.             edx = 16-galaxyScale;
  220.             edx *= eax;
  221. //            (signed long)edx >>= 5;
  222.     edx >>= 5;
  223.             eax = 0xffff-edx;
  224.             ecx *= eax;
  225.             ecx >>= 16;
  226.         } else
  227.         {
  228.             ecx *= eax;
  229.             ecx >>= 16;
  230.         }
  231.     }
  232.     p1 = ecx;
  233.     p1 >>= 10;
  234.     return (int)p1;
  235. }
  236.  
  237. void rotate_some (void)
  238. {
  239.     unsigned long Tmp1,Tmp2;
  240.  
  241.     Tmp1 = (SystemParam_0 << 3) | (SystemParam_0 >> 29);
  242.     Tmp2 = SystemParam_0 + SystemParam_1;
  243.     Tmp1 += Tmp2;
  244.     SystemParam_0 = Tmp1;
  245.     SystemParam_1 = (Tmp2 << 5) | (Tmp2 >> 27);
  246. }
  247.  
  248. int StarChance_Type[] = {
  249.     0, 0, 0, 1, 1, 1, 1, 1,
  250.     1, 1, 1, 1, 1, 1, 1, 1,
  251.     2, 2, 2, 2, 2, 3, 3, 3,
  252.     3, 4, 4, 4, 5, 6, 7, 8
  253. };
  254.  
  255. char *StarDesc[]={
  256.     "Type'M'flare star",     //  0
  257.     "Faint type'M'red star", //  1
  258.     "Type'M'red star",       //  2
  259.     "Type'K'orange star",    //  3
  260.     "Type'G'yellow star",    //  4
  261.     "Type'F'white star",     //  5
  262.     "Type'A'hot white star", //  6
  263.     "White dwarf star",      //  7
  264.     "Red giant star"         //  8
  265.     "Bright giant star",     //  9
  266.     "Type'B'hot blue star",  // 10
  267.     "Supergiant star",       // 11
  268.     "Blue supergiant star",  // 12
  269.     "Contact binary star"    // 13
  270.     };
  271.  
  272. int StarChance_Multiples[] = {
  273.     0, 0, 0, 0, 0, 0, 0, 0,
  274.     0, 0, 0, 0, 0, 0, 0, 0,
  275.     0, 0, 0, 1, 1, 1, 1, 1,
  276.     1, 1, 2, 2, 2, 3, 4, 5
  277. };
  278.  
  279. typedef struct {
  280.     signed char x,y,z;
  281.     unsigned char stardesc,multiple;
  282. } coords_t;
  283.  
  284. coords_t coords[64];
  285.  
  286. // 64? ah well let's make it a (binary) round number anyway. Though YOU can make it 62 if you like.
  287.  
  288. void Shuffle_Coordinates (unsigned int coordx, unsigned int coordy, int number_of_systems)
  289. {
  290.     int i;
  291.  
  292.     SystemParam_0 = (coordx<<16)+coordy;
  293.     SystemParam_1 = (coordy<<16)+coordx;
  294.  
  295.     rotate_some();
  296.     rotate_some();
  297.     rotate_some();
  298.  
  299.     for (i=0; i<number_of_systems; i++)
  300.     {
  301.         rotate_some();
  302.  
  303.         coords[i].z = (SystemParam_0 & 0xFF0000)>>16;
  304.         coords[i].y = (SystemParam_0 >> 8);
  305.         coords[i].y /= 2;
  306.         coords[i].x = (SystemParam_0 & 0x0001FE)>> 1;
  307.         coords[i].x /= 2;
  308.         coords[i].multiple = StarChance_Multiples[SystemParam_1 & 0x1f];
  309.         coords[i].stardesc = StarChance_Type[(SystemParam_1 >> 16) & 0x1f];
  310.     }
  311. }
  312.  
  313. int SizeForStar[] = {
  314.     300, 300, 350, 400,
  315.     450, 500, 500, 200,
  316.     700, 900, 800, 1100,
  317.     1400, 600
  318. };
  319.  
  320. #define RGB(r, g, b) (r<<16)|(g<<8)|b
  321.  
  322. int ColorForStar[] = {
  323.     RGB(200,  0,  0),    // Type'M'flare star
  324.     RGB(200,  0,  0),    // Faint type'M'red star
  325.     RGB(200,  0,  0),    // Type'M'red star
  326.     RGB(200,136,  0),    // Type'K'orange star
  327.     RGB(200,200,  0),    // Type'G'yellow star
  328.     RGB(200,200,200),    // Type'F'white star
  329.     RGB(200,200,200),    // Type'A'hot white star
  330.     RGB(200,200,200),    // White dwarf star
  331.     RGB(200,  0,  0),    // Red giant star
  332.     RGB(200,200,200),    // Bright giant star
  333.     RGB(168,200,232),    // Type'B'hot blue star
  334.     RGB(192,136,  0),    // Supergiant star
  335.     RGB(168,200,232),    // Blue supergiant star
  336.     RGB(200,200,  0),    // Contact binary star
  337. };
  338.  
  339.  
  340. void GetSystemName(unsigned int coordx,unsigned int coordy, int Sysnum, char *dest)
  341. {
  342.     coordx += Sysnum;
  343.     coordy += coordx;
  344.     coordx = _rotl (coordx, 3);
  345.     coordx += coordy;
  346.     coordy = _rotl (coordy, 5);
  347.     coordy += coordx;
  348.     coordy = _rotl (coordy, 4);
  349.     coordx = _rotl (coordx, Sysnum);
  350.     coordx += coordy;
  351.  
  352.     strcpy (dest, namepart[(coordx>>2) & 31]);
  353.     coordx = _rotr (coordx, 5);
  354.     strcat (dest, namepart[(coordx>>2) & 31]);
  355.     coordx = _rotr (coordx, 5);
  356.     strcat (dest, namepart[(coordx>>2) & 31]);
  357.     dest[0] ^= 0x20;
  358. }
  359.  
  360. int main()
  361. {
  362.     char name[10];
  363.     memset(TheMilkyWay,0, sizeof(TheMilkyWay));
  364.    
  365.     for (int i=0; i<49; i++)
  366.     {
  367.         GetSystemName(KnownSpaceCoord[i][0], KnownSpaceCoord[i][1], rand(), name);
  368.         printf("%d %s\n",i, name);
  369.  
  370. //      generate_sector(KnownSpaceCoord[i][0], KnownSpaceCoord[i][1], 1);
  371.  
  372.     }
  373.     return 0;
  374. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement