Skip to content

Commit

Permalink
Entirely more sophisticated ship building policy
Browse files Browse the repository at this point in the history
  • Loading branch information
cbbrowne committed Mar 21, 2012
1 parent cbec705 commit bc2eca4
Showing 1 changed file with 42 additions and 11 deletions.
53 changes: 42 additions & 11 deletions sample_script.sql
Expand Up @@ -35,21 +35,52 @@ pl.id = p.planet and pl.mine_limit > 0;
-- Refuel
perform id, current_fuel, refuel_ship(id) from my_ships where current_fuel < max_fuel and fleet_id = 231;
-- Get a bit of money
perform convert_resource(''FUEL'', 150);
perform convert_resource(''FUEL'', (select count(*) from planets where conqueror_id = (select id from my_player))::integer * 1000 * 3 + 150);
drop table if exists speediness;
create temp table speediness (ship_id integer, want_speed integer);
insert into speediness (ship_id, want_speed)
select id, (2000-max_speed)/20+5 from my_ships where fleet_id = 231 and max_speed < 1995 and current_health > 0
order by random limit 5;
-- Enhance speediness of my scouts
perform upgrade(id, ''MAX_SPEED'', (2000-max_speed)/20 + 5) from
(select id, max_speed from my_ships where fleet_id = 231 and max_speed < 1995 and current_health > 0 order by random() limit 10) as unspeedy;
select convert_resource(''FUEL'', (select sum(want_speed) from speediness));
-- Expand the fleet
-- Enhance speediness of my scouts
perform upgrade(ship_id, ''MAX_SPEED'', ship_id) from speediness;
-- Create a scout on each planet I own
insert into my_ships (fleet_id, name, attack, defense, engineering, prospecting, location_x, location_y) select f.id, ''Scout'', 5,4,4,7, p.location_x, p.location_y from my_fleets f, planets p, my_player pl where f.name = ''Scouts'' and p.conqueror_id = pl.id;
drop table if exists want_ships;
create temp table want_ships (fleet_id integer, name text, attack integer, defense integer, engineering integer, prospecting integer, location_x integer, location_y integer);
-- Create a prospector on each planet I own
insert into my_ships (fleet_id, name, attack, defense, engineering, prospecting, location_x, location_y) select f.id, ''Prospector'', 0,4,1,15, p.location_x, p.location_y from my_fleets f, planets p, my_player pl where f.name = ''Prospectors'' and p.conqueror_id = pl.id;
-- Expand the fleet
if (select fuel_reserve from my_player) > 5000 then
select convert_resource(''FUEL'', 2000);
-- Build a scout *and* a prospector
insert into want_ships (fleet_id, name, attack, defense, engineering, prospecting,location_x,location_y)
select 231, ''Scout'', 5,4,4,7, p.location_x, p.location_y, from planets p where conqueror_id = 231
order by random() limit 1;
insert into want_ships (fleet_id, name, attack, defense, engineering, prospecting,location_x,location_y)
select 234, ''Miner'', 0,2,2,16, p.location_x, p.location_y, from planets p where conqueror_id = 231
order by random() limit 1;
insert into my_ships (fleet_id, name, attack, defense, engineering, prospecting, location_x, location_y)
select fleet_id, name, attack, defense, engineering, prospecting, location_x, location_y
from want_ships;
elsif (select fuel_reserve from my_player > 1500) then
if random() > 0.8 then
insert into want_ships (fleet_id, name, attack, defense, engineering, prospecting,location_x,location_y)
select 231, ''Scout'', 5,4,4,7, p.location_x, p.location_y, from planets p where conqueror_id = 231
order by random() limit 1;
else
insert into want_ships (fleet_id, name, attack, defense, engineering, prospecting,location_x,location_y)
select 234, ''Miner'', 4,2,1,13, p.location_x, p.location_y, from planets p where conqueror_id = 231
order by random() limit 1;
end if;
insert into my_ships (fleet_id, name, attack, defense, engineering, prospecting, location_x, location_y)
select fleet_id, name, attack, defense, engineering, prospecting, location_x, location_y
from want_ships;
end if;
drop table if exists directed_scouts;
create temp table directed_scouts (ship_id integer, planet_id integer);
Expand Down

0 comments on commit bc2eca4

Please sign in to comment.