Skip to content

Instantly share code, notes, and snippets.

@KWKdesign
Last active August 29, 2015 14:12
Show Gist options
  • Save KWKdesign/012cdbdba7a3decf3dad to your computer and use it in GitHub Desktop.
Save KWKdesign/012cdbdba7a3decf3dad to your computer and use it in GitHub Desktop.
Schemaverse Packed Circle Map Creation
select
100000::numeric radius,
0::numeric y,
0::numeric a,
0::numeric b,
( null )::point ta,
( null )::point tb,
0::numeric angle,
1::int i,
0::int cnt,
-- 2000::int target,
( select count(1) * 1.05 from player )::int target,
( null )::point loc
into new_planet;
<<planet>>
while 1=1 loop
new_planet.y := new_planet.i * ( 2 * new_planet.radius );
new_planet.a := asin( new_planet.radius / pow( new_planet.y, 2 ) );
new_planet.b := pi() / 2;
new_planet.ta := point(
new_planet.radius * sin( new_planet.b - new_planet.a ),
new_planet.radius * -cos( new_planet.b - new_planet.a )
);
new_planet.tb := point(
new_planet.radius * -sin( new_planet.b + new_planet.a ),
new_planet.radius * cos( new_planet.b + new_planet.a )
);
new_planet.angle := sqrt( pow( new_planet.y, 2 ) * 3 / 4 );
new_planet.angle := 2 * asin( ( ( new_planet.ta <-> new_planet.tb ) / 2 ) / new_planet.angle );
new_planet.angle := 2 * pi() / floor( ( 2 * pi() ) / new_planet.angle );
for div in 1 .. floor( ( 2 * pi() ) / new_planet.angle ) loop
new_planet.loc := point(
round( new_planet.y * sin( div * new_planet.angle ) ),
round( new_planet.y * cos( div * new_planet.angle ) )
);
new_planet.cnt := new_planet.cnt + 1;
insert into planet ( id, fuel, mine_limit, difficulty, location, location_x, location_y )
values (
nextval( 'planet_id_seq' ),
greatest( ( random() * 1000000000 )::integer, 100000000 ),
greatest( ( random() * 100 )::integer, 30 ),
greatest( ( random() * 10 )::integer , 2 ),
new_planet.loc, new_planet.loc[0], new_planet.loc[1]
);
exit planet when new_planet.cnt >= new_planet.target;
end loop;
new_planet.i := new_planet.i + 1;
end loop;
for p in
select row_number() over ( order by random() ), id
from planet
where id <> 1
and name is null
loop
update planet set name = ( select case ( p.row_number - 1 ) % 12
when 0 then 'Aethra'
when 1 then 'Mony'
when 2 then 'Semper'
when 3 then 'Voit'
when 4 then 'Lester'
when 5 then 'Rio'
when 6 then 'Zergon'
when 7 then 'Cannibalon'
when 8 then 'Omicron Persei'
when 9 then 'Urectum'
when 10 then 'Wormulon'
when 11 then 'Kepler'
end ) || '_' || ( ( ( p.row_number - 1 ) / 12 ) + 1 )::text
where id = p.id;
end loop;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment