> 16)&0xFFFF; $Seed=$result2&0xFFFF; return $rand_count&0x7FFF; } function c_srand($seed) { global $Seed, $rand_count; $rand_count = 0; $Seed = $seed; //if ($Seed < 0) $Seed += 65536; //$Seed &= 0xFFFF; //Doesn't work (anymore?) with numbers < -2147483648 //BOH????? $tokens = explode(".", $seed); $Seed = $tokens[0]+0; while ($Seed < 0 || $Seed > 65535) { if ($Seed < 0) $Seed += 65536; else $Seed -= 65536; } //fin qua //while ($Seed > 65535) $Seed -= 65535; //echo "seed: $Seed\n" ; } function zrandom ($range) { return (c_random($range) - c_random($range)); } function c_random($num) { global $RAND_MAX; return intval( (c_rand() * $num )/($RAND_MAX+1)); } function extract_target_info(&$sysinfo) { global $star_classes, $class_ray, $class_rayvar, $class_rgb; $x = intval($sysinfo['x']); $y = intval($sysinfo['y']); $z = intval($sysinfo['z']); //echo "$x\n$y\n$z\n"; /* $ss = intval($x / 100000 * $y / 100000 * $z / 100000); echo $ss."\n"; c_srand($ss); */ //c_srand(intval($x/100000*$y/100000*$z/100000)); //This one needed some bashing too :( $op_a = $x/100000; $op_b = $op_a *$y; $op_c = $op_b /100000; $op_d = $op_c *$z; $val = $op_d/100000; c_srand($val); //fino a qua $class = c_random ($star_classes); $ray = ($class_ray[$class] + c_random($class_rayvar[$class])) * 0.001; $r = $class_rgb[3*$class+0]; $g = $class_rgb[3*$class+1]; $b = $class_rgb[3*$class+2]; $spin = 0; if ($class==11) $spin = c_random (30) + 1; if ($class==7) $spin = c_random (12) + 1; if ($class==2) $spin = c_random (4) + 1; $sysinfo['class'] = $class; $sysinfo['ray'] = $ray; $sysinfo['spin'] = $spin; $sysinfo['r'] = $r; $sysinfo['g'] = $g; $sysinfo['b'] = $b; } function prepare_star(&$sysinfo) { global $class_planets, $planet_types, $planet_possiblemoons, $planet_orb_scaling, $avg_planet_sizing, $moon_orb_scaling, $avg_moon_sizing, $avg_planet_ray, $maxbodies, $deg, $qt_M_PI; $key_radius; $nearstar_p_orb_orient = array(); $nearstar_p_orb_seed = array(); $nearstar_p_tilt = array(); $nearstar_p_orb_tilt = array(); $nearstar_p_orb_ecc = array(); $nearstar_p_ray = array(); $nearstar_p_ring = array(); $nearstar_p_type = array(); $nearstar_p_orb_ray = array(); $no_moons = 0; $x = intval($sysinfo['x']); $y = intval($sysinfo['y']); $z = intval($sysinfo['z']); $class = intval($sysinfo['class']); $ray = intval($sysinfo['ray']); $s_m = $qt_M_PI * $ray * $ray * $ray * 0.01e-7; //c_srand(intval($x)%10000*intval($y)%10000*intval($z)%10000); // I'm splitting all this up because % tries to automatically // cast both operands to integer and it causes unexpected results $op_a = $x%10000; $op_b = $op_a *$y; while ($op_b < -2147483648 || $op_b > 2147483647) { if ($op_b < 0) $op_b += 0x100000000; else if ($op_b > 0) $op_b -= 0x100000000; } $op_c = $op_b %10000; $op_d = $op_c *$z; while ($op_d < -2147483648 || $op_d > 2147483647) { if ($op_d < 0) $op_d += 0x100000000; else if ($op_d > 0) $op_d -= 0x100000000; } $val = $op_d%10000; c_srand($val); $nop = c_random ($class_planets[$class] + 1); for ($n=0; $n<$nop; $n++) { $nearstar_p_orb_orient[$n] = $deg * c_random (360); $nearstar_p_orb_seed[$n] = 3 * ($n*$n+1) * $ray + c_random (300 * $ray) / 100; $nearstar_p_tilt[$n] = zrandom (10*$nearstar_p_orb_seed[$n]) / 500; $nearstar_p_orb_tilt[$n] = zrandom (10*$nearstar_p_orb_seed[$n]) / 5000; $nearstar_p_orb_ecc[$n] = 1 - c_random ($nearstar_p_orb_seed[$n] + 10*abs($nearstar_p_orb_tilt[$n])) / 2000; $nearstar_p_ray[$n] = c_random ($nearstar_p_orb_seed[$n]) * 0.001 + 0.01; $nearstar_p_ring[$n] = zrandom ($nearstar_p_ray[$n]) * (1 + c_random (1000) / 100); /* $nearstar_p_orb_orient[$n] = intval($deg * c_random (360)); $nearstar_p_orb_seed[$n] = intval(3 * ($n*$n+1) * $ray + c_random (300 * $ray) / 100); $nearstar_p_tilt[$n] = intval(zrandom (10*$nearstar_p_orb_seed[$n]) / 500); $nearstar_p_orb_tilt[$n] = intval(zrandom (10*$nearstar_p_orb_seed[$n]) / 5000); $nearstar_p_orb_ecc[$n] = intval(1 - c_random ($nearstar_p_orb_seed[$n] + 10*abs($nearstar_p_orb_tilt[$n])) / 2000); $nearstar_p_ray[$n] = intval(c_random ($nearstar_p_orb_seed[$n]) * 0.001 + 0.01); $nearstar_p_ring[$n] = intval(zrandom ($nearstar_p_ray[$n]) * (1 + c_random (1000) / 100)); */ if ($class != 8) $nearstar_p_type[$n] = c_random ($planet_types); else { if (c_random(2)) { $nearstar_p_type[$n] = 10; $nearstar_p_orb_tilt[$n] *= 100; } else $nearstar_p_type[$n] = c_random ($planet_types); } if ($class==2||$class==7||$class==15) $nearstar_p_orb_seed[$n] *= 10; } if ($class == 0) { if (c_random(4)==2) $nearstar_p_type[2] = 3; if (c_random(4)==2) $nearstar_p_type[3] = 3; if (c_random(4)==2) $nearstar_p_type[4] = 3; } for ($n=0; $n<$nop; $n++) { switch ($class) { case 2: while ($nearstar_p_type[$n]==3) $nearstar_p_type[$n] = c_random (10); break; case 5: while ($nearstar_p_type[$n]==6|| $nearstar_p_type[$n]==9) $nearstar_p_type[$n] = c_random (10); break; case 7: $nearstar_p_type[$n] = 9; break; case 9: while ($nearstar_p_type[$n]!=0&& $nearstar_p_type[$n]!=6&& $nearstar_p_type[$n]!=9) $nearstar_p_type[$n] = c_random (10); break; case 11:while ($nearstar_p_type[$n]!=1&& $nearstar_p_type[$n]!=7) $nearstar_p_type[$n] = c_random (10); } } for ($n=0; $n<$nop; $n++) { switch ($nearstar_p_type[$n]) { case 0: if (c_random(8)) $nearstar_p_type[$n] ++; break; case 3: if (($n<2)||($n>6)||($class && c_random(4))) { if (c_random(2)) $nearstar_p_type[$n]++; else $nearstar_p_type[$n]--; } break; case 7: if ($n<7) { if (c_random(2)) $nearstar_p_type[$n] --; else $nearstar_p_type[$n] -= 2; } break; } } $nob = $nop; if ($class==2||$class==7||$class==15) $no_moons = 1; // goto no_moons if (!$no_moons) { for ($n=0; $n<$nop; $n++) { // ($t=) Number of satellites for planet $s = $nearstar_p_type[$n]; if ($n < 2) { $t = 0; if ($s == 10) $t = c_random (3); } else $t = c_random ($planet_possiblemoons[$s] + 1); if ($nob + $t > $maxbodies) $t = $maxbodies - $nob; for ($c=0; $c<$t; $c++) { $q = $nob + $c; $nearstar_p_owner[$q] = $n; $nearstar_p_moonid[$q] = $c; $nearstar_p_orb_orient[$q] = $deg * c_random (360); $nearstar_p_orb_seed[$q] = ($c*$c+4) * $nearstar_p_ray[$n] + zrandom (300 * $nearstar_p_ray[$n]) / 100; $nearstar_p_tilt[$q] = zrandom (10*$nearstar_p_orb_seed[$q]) / 50; $nearstar_p_orb_tilt[$q] = zrandom (10*$nearstar_p_orb_seed[$q]) / 500; $nearstar_p_orb_ecc[$q] = 1 - c_random ($nearstar_p_orb_seed[$q] + 10*abs($nearstar_p_orb_tilt[$q])) / 2000; $nearstar_p_ray[$q] = c_random ($nearstar_p_orb_seed[$n]) * 0.05 + 0.1; $nearstar_p_ring[$q] = 0; $nearstar_p_type[$q] = c_random ($planet_types); $r = $nearstar_p_type[$q]; if ($r==9 && $s != 10) $r = 2; if ($r==6 && $s < 9) $r = 5; if ($n > 7 && c_random($c)) $r = 7; if ($n > 9 && c_random($c)) $r = 7; if ($r==2 || $r==3 || $r==4 || $r==8) { if ($s != 6 && $s < 9) $r = 1; } if ($r==3 && $s < 9) { if ($n > 7) $r = 7; if ($class && c_random(4)) $r = 5; if ($class == 2 ||$class == 7 || $class == 11) $r = 8; } if ($r==7 && $n <= 5) $r = 1; if (($class==2||$class==5|| $class==7|| $class==11) && c_random($n)) $r = 7; $nearstar_p_type[$q] = $r; } $nob += $t; } } // no_moons: (label) $key_radius = $ray * $planet_orb_scaling; if ($class == 8) $key_radius *= 2; if ($class == 2) $key_radius *= 16; if ($class == 7) $key_radius *= 18; if ($class == 11) $key_radius *= 20; for ($n=0; $n<$nop; $n++) { $nearstar_p_ray[$n] = $avg_planet_ray[$nearstar_p_type[$n]] + $avg_planet_ray[$nearstar_p_type[$n]] * zrandom (100) / 200; $nearstar_p_ray[$n] *= $avg_planet_sizing; $nearstar_p_orb_ray[$n] = $key_radius + $key_radius * zrandom (100) / 500; $nearstar_p_orb_ray[$n] += $key_radius * $avg_planet_ray[$nearstar_p_type[$n]]; if ($n < 8) $key_radius += $nearstar_p_orb_ray[$n]; else $key_radius += 0.22 * $nearstar_p_orb_ray[$n]; } // the following code should be needed, and rings corrections sill are lacking // by the way, orbits stuff is a mess /* $n = $nop; while ($n < $nob) { $q = 0; $c = $nearstar_p_owner[$n]; $key_radius = $nearstar_p_ray[$c] * $moon_orb_scaling; while ($n<$nob && $nearstar_p_owner[$n] == $c) { $nearstar_p_ray[$n] = $avg_planet_ray[$nearstar_p_type[$n]] + $avg_planet_ray[$nearstar_p_type[$n]] * zrandom (100) / 200; $nearstar_p_ray[$n] *= $avg_moon_sizing; $nearstar_p_orb_ray[$n] = $key_radius + $key_radius * zrandom (100) / 250; $nearstar_p_orb_ray[$n] += $key_radius * $avg_planet_ray[$nearstar_p_type[$n]]; if ($q < 2) $key_radius += $nearstar_p_orb_ray[$n]; if ($q >= 2 && $q < 8) $key_radius += 0.12 * $nearstar_p_orb_ray[$n]; if ($q >= 8) $key_radius += 0.025 * $nearstar_p_orb_ray[$n]; $q++; $n++; } } */ $sysinfo['nop'] = $nop; // NON Ë un array $sysinfo['s_m'] = $s_m; // NON Ë un array $sysinfo['p_type'] = $nearstar_p_type; $sysinfo['p_orb_orient'] = $nearstar_p_orb_orient; $sysinfo['p_orb_seed'] = $nearstar_p_orb_seed; $sysinfo['p_tilt'] = $nearstar_p_tilt; $sysinfo['p_orb_tilt'] = $nearstar_p_orb_tilt; $sysinfo['p_orb_ecc'] = $nearstar_p_orb_ecc; $sysinfo['p_ray'] = $nearstar_p_ray; $sysinfo['p_ring'] = $nearstar_p_ring; $sysinfo['p_orb_ray'] = $nearstar_p_orb_ray; $sysinfo['nob'] = $nob; // NON Ë un array //solo delle lune $sysinfo['p_owner'] = $nearstar_p_owner; $sysinfo['p_moonid'] = $nearstar_p_moonid; } // calculates the period of revolution in seconds // planets: around the star // moons: around the planet function rtp ($p_owner, $p_orb_ray, $p_ray, $s_m) { global $qt_M_PI; $ors = $p_orb_ray * $p_orb_ray; if ($p_owner > -1) { // Check this out..was the original this way? // xx = nearstar_p_ray[nearstar_p_owner[n]]; $xx = $p_ray; $p_m = $qt_M_PI * $xx * $xx * $xx * 0.44e-4; $p_riv = sqrt ($p_m / $ors); } else $p_riv = sqrt ($s_m / $ors); return (360 / $p_riv); //return intval((360 / $p_riv)); } // see if it's the case of adding these informations to prepare_star. // as of now, I prefer keeping this separate, also because other // functions written in assemply are needed (all in NOCTIS-0.cpp) // . void fast_srand (long seed) // . long fast_random (long mask) // . float fast_flandom () -- this is not in assembly but it calls fast_random function calc_star_mass($ray, $class, $x) { global $qt_M_PI; $starmass_correction = array( 1.886, 1.50, 8000.40, 0.05, 2.44, 3.10, 9.30, 48.00, 1.00, 1.00, 0.07, 15000.00 ); //$tmp_float = 1e-3 * $qt_M_PI * $ray * $ray * $ray; $tmp_float = bcmul (1e-3, $qt_M_PI,8); $tmp_float = bcmul ($tmp_float, $ray,8); $tmp_float = bcmul ($tmp_float, $ray,8); $tmp_float = bcmul ($tmp_float, $ray,8); //$tmp_float *= $starmass_correction[$class]; $tmp_float = bcmul($tmp_float,$starmass_correction[$class],8); if ($class == 8 || $class == 9) { fast_srand (intval($x%32000)); switch (fast_random(5)) { case 0: $tmp_float /= 1 + 5 * fast_flandom(); break; case 1: $tmp_float /= 1 + fast_flandom(); break; case 2: $tmp_float *= 1 + fast_flandom(); break; case 3: $tmp_float *= 1 + 20 * fast_flandom(); break; case 4: $tmp_float *= 1 + 50 * fast_flandom(); } } return $tmp_float; } function calc_star_mass_BKP($ray, $class, $x) { global $qt_M_PI; $starmass_correction = array( 1.886, 1.50, 8000.40, 0.05, 2.44, 3.10, 9.30, 48.00, 1.00, 1.00, 0.07, 15000.00 ); $tmp_float = 1e-3 * $qt_M_PI * $ray * $ray * $ray; $tmp_float *= $starmass_correction[$class]; if ($class == 8 || $class == 9) { fast_srand (intval($x%32000)); switch (fast_random(5)) { case 0: $tmp_float /= 1 + 5 * fast_flandom(); break; case 1: $tmp_float /= 1 + fast_flandom(); break; case 2: $tmp_float *= 1 + fast_flandom(); break; case 3: $tmp_float *= 1 + 20 * fast_flandom(); break; case 4: $tmp_float *= 1 + 50 * fast_flandom(); } } return $tmp_float; } $FR_Seed = 1; function fast_srand( $lse) { global $FR_Seed; $FR_Seed = $lse | 3; } function fast_random($mask) { global $FR_Seed; $a = $FR_Seed&0xFFFF; $a*=$a; $b = $a; $b &=0xFFFF; $a >> 16; //$a &= 0xFFFF; // mio $a+=$b; $a &=0xFFFF; $res = $a; $res &= $mask; $FR_Seed += $a; $a &=15; $b = 1; $b << $a; //$b &=0xFFFF; // mio $FR_Seed= $FR_Seed | $b; return intval($res); } // as I was writing earlier, this function only lacks fast_random() to be working function fast_flandom () { return (fast_random(32767) * 0.000030518); } // Other info: pressure, surface temp (planets) function surface_details($p_ray) { // For now only gravity, for the others, more functions are probably needed. $tp_gravity = 1; $pp_gravity = 1; $tp_temp = 22; $pp_temp = 22; $tp_pressure = 1; $pp_pressure = 1; $gravity = $p_ray; $planet_grav = $gravity * 2000; $pp_gravity = $gravity * 38.26; $gravity *= 1E4; $pp_delta = ($pp_gravity - $tp_gravity) * 0.25; $tp_gravity += $pp_delta; $pp_delta = ($pp_temp - $tp_temp) * 0.05; $tp_temp += $pp_delta; $pp_delta = ($pp_pressure - $tp_pressure) * 0.02; $tp_pressure += $pp_delta; /*$pp_delta = ($pp_pulse - $tp_pulse) * 0.01; $tp_pulse += $pp_delta; */ return $tp_gravity; } /* pp_delta = (pp_gravity - tp_gravity) * 0.25; tp_gravity += pp_delta; pp_delta = (pp_temp - tp_temp) * 0.05; tp_temp += pp_delta; pp_delta = (pp_pressure - tp_pressure) * 0.02; tp_pressure += pp_delta; pp_delta = (pp_pulse - tp_pulse) * 0.01; tp_pulse += pp_delta; sprintf (outhudbuffer, "GRAVITY %2.3f FG & TEMPERATURE %+3.1f@C & PRESSURE %2.3f ATM & PULSE %3.0f PPS", tp_gravity, tp_temp, tp_pressure, tp_pulse); */ ?>