Skip to content

Commit

Permalink
Fixed a few issues with schedulers
Browse files Browse the repository at this point in the history
  • Loading branch information
icydee authored and Iain C Docherty committed Feb 15, 2016
1 parent f05cc0f commit e9164a9
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 81 deletions.
40 changes: 14 additions & 26 deletions bin/schedule_building.pl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
# existing jobs
out('Reinitializing all jobs');
out('Deleting existing jobs');
my $schedule_rs = Lacuna->db->resultset('Schedule')->search;
my $schedule_rs = Lacuna->db->resultset('Schedule')->search({
task => [qw(finish_work finish_upgrade finish_construction)],
});
while (my $schedule = $schedule_rs->next) {
# note. deleting the DB entry also deletes the entry on beanstalk
$schedule->delete;
Expand Down Expand Up @@ -90,32 +92,18 @@
});
}

out('Adding ship building ends');
my $dt_parser = Lacuna->db->storage->datetime_parser;
my $now = $dt_parser->format_datetime( DateTime->now );
my $fleets = Lacuna->db->resultset('Fleet')->search({
date_available => { '<=' => $now },
task => 'Travelling',
out('Adding ship builds');
my $ship_rs = Lacuna->db->resultset('Fleet')->search({
task => 'Building',
});
while (my $fleet = $fleets->next ) {
if ($fleet->task eq 'Travelling') {
out('Fleet - arrive at '.$fleet->date_available);
Lacuna->db->resultset('Schedule')->create({
delivery => $fleet->date_available,
parent_table => 'Fleet',
parent_id => $fleet->id,
task => 'arrive',
});
}
elsif ($fleet->task eq 'Building') {
out('Fleet - finish_work at '.$fleet->date_available);
Lacuna->db->resultset('Schedule')->create({
delivery => $fleet->date_available,
parent_table => 'Fleet',
parent_id => $fleet->id,
task => 'finish_work',
});
}
while (my $ship = $ship_rs->next) {
# add to queue
my $schedule = Lacuna->db->resultset('Schedule')->create({
delivery => $ship->date_available,
parent_table => 'Fleet',
parent_id => $ship->id,
task => 'finish_construction',
});
}
}

Expand Down
12 changes: 6 additions & 6 deletions bin/schedule_ship_arrival.pl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
out('Reinitializing all jobs');
out('Deleting existing jobs');
my $schedule_rs = Lacuna->db->resultset('Schedule')->search({
parent_table => 'Ships',
parent_table => 'Fleet',
task => 'arrive',
});
while (my $schedule = $schedule_rs->next) {
Expand All @@ -64,16 +64,16 @@
}

out('Adding ship arrivals');
my $ship_rs = Lacuna->db->resultset('Ships')->search({
my $fleet_rs = Lacuna->db->resultset('Fleet')->search({
task => 'Travelling',
});
while (my $ship = $ship_rs->next) {
while (my $fleet = $fleet_rs->next) {
# add to queue
my $schedule = Lacuna->db->resultset('Schedule')->create({
delivery => $ship->date_available,
delivery => $fleet->date_available,
queue => 'arrive_queue',
parent_table => 'Ships',
parent_id => $ship->id,
parent_table => 'Fleet',
parent_id => $fleet->id,
task => 'arrive',
});
}
Expand Down
21 changes: 8 additions & 13 deletions lib/Lacuna/DB/Result/Building.pm
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,7 @@ sub finish_upgrade {
my $empire = $body->empire;
my $new_level = $self->level+1;

my $empire = $body->empire;
if ($empire) {
# 31 is the actual Max level for the Terra & Gas Platforms.
if ($new_level >= 1 and $new_level <= 31) {
Expand All @@ -960,10 +961,6 @@ sub finish_upgrade {
elsif ($new_level > 31) {
$empire->add_medal('buildingX');
}
my $type = $self->controller_class;
$type =~ s/^Lacuna::RPC::Building::(\w+)$/$1/;
$empire->add_medal($type);
$self->finish_upgrade_news($new_level, $empire);
}

$self->reschedule_queue;
Expand All @@ -975,15 +972,13 @@ sub finish_upgrade {
$body->needs_recalc(1);
$body->needs_surface_refresh(1);
$body->update;

my $empire = $body->empire;
$empire->add_medal('building'.$self->level);
my $type = $self->controller_class;
$type =~ s/^Lacuna::RPC::Building::(\w+)$/$1/;
$empire->add_medal($type);
if ($self->level % 5 == 0) {
my %levels = (5=>'a quiet',10=>'an extravagant',15=>'a lavish',20=>'a magnificent',25=>'a historic',30=>'a magical');
$self->body->add_news($self->level*4,"In %s ceremony, %s unveiled its newly augmented %s.", $levels{$self->level}, $empire->name, $self->name);

if ($empire) {
$empire->add_medal($type);
if ($new_level % 5 == 0) {
my %levels = (5=>'a quiet',10=>'an extravagant',15=>'a lavish',20=>'a magnificent',25=>'a historic',30=>'a magical');
$self->body->add_news($new_level*4,"In %s ceremony, %s unveiled its newly augmented %s.", $levels{$new_level}, $empire->name, $self->name);
}
}
$self->reschedule_queue;
}
Expand Down
13 changes: 0 additions & 13 deletions lib/Lacuna/DB/Result/Fleet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -606,19 +606,6 @@ sub start_construction {
return $self;
}

sub start_construction {
my ($self) = @_;

my $schedule = Lacuna->db->resultset('Schedule')->create({
delivery => $self->date_available,
parent_table => 'Fleet',
parent_id => $self->id,
task => 'finish_construction',
});

return $self;
}

sub finish_construction {
my ($self) = @_;
$self->body->empire->add_medal($self->type);
Expand Down
10 changes: 5 additions & 5 deletions lib/Lacuna/RPC/Building.pm
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,16 @@ sub view {

if (ref($args) ne "HASH") {
$args = {
session => $args,
building => shift,
session_id => $args,
building_id => shift,
};
}
if ($args->{no_status}) {
return {};
}

my $empire = $self->get_empire_by_session($args->{session});
my $building = $self->get_building($empire, $args->{building}, skip_offline => 1);
my $empire = $self->get_empire_by_session($args->{session_id});
my $building = $self->get_building($empire, $args->{building_id}, skip_offline => 1);
my $cost = $building->cost_to_upgrade;

my $can_upgrade = eval{$building->can_upgrade($cost)};
Expand Down Expand Up @@ -413,7 +413,7 @@ sub repair {


my $empire = $self->get_empire_by_session($args->{session_id});
my $building = $self->get_building($empire, $args->{building_id});
my $building = $self->get_building($empire, $args->{building_id}, skip_offline => 1);

my $costs = $building->get_repair_costs;
$building->can_repair($costs);
Expand Down
1 change: 0 additions & 1 deletion lib/Lacuna/RPC/Building/Trade.pm
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,6 @@ sub add_to_market {
}



__PACKAGE__->register_rpc_method_names(qw(
get_supply_ships
view_supply_chains
Expand Down
19 changes: 12 additions & 7 deletions t/460_fleet_spaceport.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use TestHelper;
#diag("Cleared all test empires");

my $tester = TestHelper->new->use_existing_test_empire;
my $enemy = TestHelper->new({empire_name => 'TLE Test Enemy'})->use_existing_test_empire;
#my $enemy = TestHelper->new({empire_name => 'TLE Test Enemy'})->use_existing_test_empire;

my $test_session_id = $tester->session->id;
my $test_empire = $tester->empire;
Expand All @@ -34,6 +34,7 @@ $result = $tester->post('spaceport','view', [{
building_id => $test_spaceport->id,
no_status => 1,
}]);

my $fleets = $test_home->fleets->search({
task => 'Docked',
});
Expand All @@ -45,21 +46,25 @@ foreach my $ship (sort keys %{$result->{result}{docked_ships}} ) {
is($result->{result}{docked_ships}{$ship}, $ships->{$ship}, "Correct number of docked $ship");
}




## spaceport - view_all_fleets
##
$result = $tester->post('spaceport','view', [{
session_id => $test_session_id,
building_id => $test_spaceport->id,
}]);
ok($result->{result}{docked_ships}, "Has docked ships");
ok($result->{result}{docked_ships}{sweeper} > 1000, "Has sweepers");
#$result = $tester->post('spaceport','view', [{
# session_id => $test_session_id,
# building_id => $test_spaceport->id,
#}]);
#ok($result->{result}{docked_ships}, "Has docked ships");
#ok($result->{result}{docked_ships}{sweeper} > 1000, "Has sweepers");

$result = $tester->post('spaceport','view_all_fleets', [{
session_id => $test_session_id,
building_id => $test_spaceport->id,
paging => {no_paging => 1},
no_status => 1,
}]);
exit;

my ($sweepers) = grep {$_->{details}{type} eq 'sweeper'} @{$result->{result}{fleets}};
ok($sweepers->{quantity} > 1000, "view_all_fleets sweepers");
Expand Down
67 changes: 57 additions & 10 deletions var/www/public/changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -412,16 +412,63 @@
- Mod: The Halls of Vrbansk can no longer be built from a plan.
- Mod: Disable upgrade button on Permanent E-Veins

3.0882:
- Fix: Timers on int ministries get zeroed on flipped planets.
- Mod: Halls no longer need x+1 free spaces to upgrade a level x building
- Mod: Hall buildings will sacrifice all but one unless needed.
- Mod: Added better logging to building upgrade and ship arrival queues
- Mod: Increased range of Trade Ministry
- Mod: Citadel of Knope is now more effective
- Add: Starter zones enabled via configuration.
- Add: When a planet implodes from fissures, empires newer than 60 days will not be damaged.
- Add: More info on available spies returned by training buildings.
4.0001:
- Add: Major reworking of ships into fleets.
- Mod: Most API calls involving ships have changed, if you use external scripts these will most likely need to be modified.
- Mod: Most API calls now have the option of named arguments as well as supporting the existing scheme for backwards compatibility
- Mod: A fleet is a collection of ships all having the same attributes and task
- Mod: Where previously you referred to a single ship, you now refer to a fleet (and perhaps a quantity of ships)
- Mod: The maximum level of Shipyard on a colony is now used in calculating a new ships attributes, not the current Shipyard
- Mod: 'own' and 'ally' on the incoming report for a Space Station now are in relation to your own empire.
- Fix: Fleets sort correctly in type/name order in Space Port view tab
- Mod: You can build any number of ships in a fleet in the Shipyard, subject to available building slots, resources and free docks
- Mod: You can now see all details of incoming allied ships in the Space Port incoming tab.
- Mod: You can now see details of incoming allied ships on the Star Map planet/star incoming tab
- Mod: You can now see details (subject to the local Space Port level) of incoming foreign ships on the Star Map planet incoming tab for allied planets or Space Stations
- Fix: UI - Number of docks available now decrements correctly when building multiple ships in Shipyard
- Fix: Added description of new ship types in Shipyard
- Mod: When sending a fleet you now specify the arrival date/time not the speed
- Mod: Spaceport, when sending spies, you can specify the arrival date/time
- Mod: The limit of sending no more than 20 ships in a fleet has been removed.
- Mod: Travelling ships not involved in a trade or an attack can be recalled
- Mod: Travelling ships not involved in an attack can be scuttled
- Mod: Removed option to skip incoming ships messages
- Fix: Stars now list in alphabetic order in Parliament, rename stars.
- Mod: Supply chains can now be set up to allied planets
- Mod: Fleets on defence no longer have a reset after a battle.
- Add: Ability to subsidize individual builds on the build queue
- Add: Ability to cancel individual builds on the build queue

- TEST: view_incoming_fleet: for visibility of foreign fleets.
- TODO: remove view_ships_orbiting from Police Station module
- TODO: Ability to subsidize individual fleet builds on the ship build queue

- TODO: Ability to 'delay' a fleet that is already in flight.
- TODO: Display the owner,body of orbiting/defending fleets
- TODO: Retrieve spies, should be able to specify 'own colony' spies, not retriev all 'own empire' spies
- TODO: Stop being able to send fighters to their home colony to 'Defend'.
- TODO: Make sure 'soonest' rounds up to the nearest 15 seconds.
- TODO: Allow for a timestring to specify the arrival time as well as the individual arguments
- TODO: N19 messages when ships in flight are detonated (suspect faulty engines or human error)
- TODO: If you have a probe at a star, you can now see all other 'orbiting' probes at that star
- TODO: Allow resources/ships/glyphs/plans to be pushed to allied planets
- TODO: Supply chains can be cancelled either from the supplying or the receiving body.
- TODO: ? Allow ships to 'stay' at allied planets during a push, they are then owned by that empire.
- TODO: Can send fighters to orbit stars, so that they can destroy incoming detonators.
- TODO: ? Should we treat probes as combat, so that we can destroy them with orbiting fighters?

- TODO: When viewing 'available' or 'unavailable' fleets to send to a body, select from all possible colonies.
- TODO: Filter foreign incoming ships status by level of space-port
- TODO: When removing a scow from a waste chain, it removes waste equivalent to the size of the scow.
- TODO: Battle logs should show fleets, not ships
- TODO: Give the Del both offensive and defensive spies.

- done: When ships arrive (fighters to Defend) set their available date to null
- done: Travelling ships should be sorted in arrival date order
- done: Cannot set up a supply chain to oneself

KNOWN BUGS:
- bug: Fleet format currently shows 'Foreign' for all fleets

3.0881:
- Fix: DevMin fix.
Expand Down

0 comments on commit e9164a9

Please sign in to comment.