From d1354797bcc5ae07d06c36489f8604459d41474a Mon Sep 17 00:00:00 2001 From: lemming552 Date: Fri, 22 Jun 2012 20:03:28 -0600 Subject: [PATCH 01/19] No burning sold prisoners. --- lib/Lacuna/RPC/Building/Intelligence.pm | 2 +- var/www/public/changes.txt | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Lacuna/RPC/Building/Intelligence.pm b/lib/Lacuna/RPC/Building/Intelligence.pm index 5fa0313e..de49c0d7 100644 --- a/lib/Lacuna/RPC/Building/Intelligence.pm +++ b/lib/Lacuna/RPC/Building/Intelligence.pm @@ -101,7 +101,7 @@ sub burn_spy { if ($spy->task eq 'Waiting On Trade' || $spy->task eq 'Mercenary Transport') { confess [1010, "You can't burn a spy involved in a trade. You must wait for the trade to complete."]; } - if ($spy->task eq 'Captured') { + if ($spy->task eq 'Captured' or $spy->task eq 'Prisoner Transport') { confess [1010, "You can't burn a spy that has been captured. If you did he would have no reason not to tell your enemy all your secrets."]; } if ($spy->task eq 'Killed In Action') { diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index fe0b3240..d44f8ae6 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,10 +1,11 @@ 3.0855: - Mod: Intelligence Building Level doesn't factor into training costs. - Mod: Burning a spy has more consequences. + - Fix: No burning spies while they're being transported. 3.0854: - Add: Backend support only for fleet actions. No changes to gameplay at this time. - - Fix: None-permanent buildings on abandoned planets have been cleared. + - Fix: Non-permanent buildings on abandoned planets have been cleared. - Fix: Spies no longer stealing level 1 buildings. - Fix: 0% Efficiency Saws will no longer shoot down zero combat ships. -- 2.51.2 From f77228d0bf38168380608588e59536b1d10744ba Mon Sep 17 00:00:00 2001 From: fireartist Date: Sat, 23 Jun 2012 21:01:37 +0100 Subject: [PATCH 02/19] show supply-chain stalled status in API --- lib/Lacuna/DB/Result/SupplyChain.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Lacuna/DB/Result/SupplyChain.pm b/lib/Lacuna/DB/Result/SupplyChain.pm index f34a9c72..899668fa 100644 --- a/lib/Lacuna/DB/Result/SupplyChain.pm +++ b/lib/Lacuna/DB/Result/SupplyChain.pm @@ -37,6 +37,7 @@ sub get_status { resource_hour => $self->resource_hour, resource_type => $self->resource_type, percent_transferred => $self->percent_transferred, + stalled => $self->stalled, }; } -- 2.51.2 From 019872d7e42f991919a1708626e840999d19f609 Mon Sep 17 00:00:00 2001 From: fireartist Date: Sat, 23 Jun 2012 21:05:13 +0100 Subject: [PATCH 03/19] add view_supply_chain {stalled} to docs --- docs/Trade.pod | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/Trade.pod b/docs/Trade.pod index 12bb177f..6aa23e94 100644 --- a/docs/Trade.pod +++ b/docs/Trade.pod @@ -597,6 +597,7 @@ Returns a list of the supply chains currently controlled by this Trade Ministry "resource_hour" : 10000000, "resource_type" : 'water', "percent_transferred" : 95, + "stalled" : 0, } ], "max_supply_chains" : 30 @@ -620,6 +621,8 @@ it is at or above 100. Above 100 and you have more ship capacity than you need, still only transfer the specified B, it just means some ships will be idle or not fully filled. +B is true if there are no more of the chain's resource available in storage to push. + =head2 view_waste_chains ( session_id, building_id ) -- 2.51.2 From 5f8d998dd8b20126dad3d06ab3fc41185d0bac8d Mon Sep 17 00:00:00 2001 From: ian docherty Date: Sat, 23 Jun 2012 17:01:18 -0400 Subject: [PATCH 04/19] Some improvements in calculating supply chains --- docs/PlanetaryCommand.pod | 18 +- lib/Lacuna/DB/Result/Map/Body/Planet.pm | 390 ++++++++++++-------- lib/Lacuna/RPC/Building/PlanetaryCommand.pm | 2 + lib/Lacuna/RPC/Building/Shipyard.pm | 2 +- 4 files changed, 248 insertions(+), 164 deletions(-) diff --git a/docs/PlanetaryCommand.pod b/docs/PlanetaryCommand.pod index ffc2ccf8..eeeb82b5 100644 --- a/docs/PlanetaryCommand.pod +++ b/docs/PlanetaryCommand.pod @@ -49,8 +49,22 @@ Command extends the view method to include a C section. "waste_capacity" : 13000, "water_stored" : 9929, "water_hour" : 295, - "water_capacity" : 51050 - } + "water_capacity" : 51050, + "food" : { + "algae_hour" : 24, + "algae_stored" :1322, + "bean_hour" : 1, + "bean_stored" :42, + .. + } + "ore" : { + "anthracite_hour" : 333, + "anthracite_stored" : 34444, + "bauxite_hour" : 22, + "bauxite_stored" : 1235, + ... + } + } } diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 783cead2..1f2482c5 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -217,14 +217,40 @@ before abandon => sub { $self->sanitize; }; +sub get_ore_status { + my ($self) = @_; + + my $out; + foreach my $type (ORE_TYPES) { + my $arg = "${type}_hour"; + $out->{$arg} = $self->$arg; + $arg = "${type}_stored"; + $out->{$arg} = $self->$arg; + } + return $out; +} + +sub get_food_status { + my ($self) = @_; + + my $out; + foreach my $type (FOOD_TYPES) { + my $arg = "${type}_production_hour"; + $out->{"${type}_hour"} = $self->$arg; + $arg = "${type}_stored"; + $out->{$arg} = $self->$arg; + } + return $out; +} + around get_status => sub { my ($orig, $self, $empire) = @_; my $out = $orig->($self); - my %ore; + my $ore; foreach my $type (ORE_TYPES) { - $ore{$type} = $self->$type(); + $ore->{$type} = $self->$type(); } - $out->{ore} = \%ore; + $out->{ore} = $ore; $out->{water} = $self->water; if ($self->empire_id) { $out->{empire} = { @@ -428,10 +454,10 @@ use constant water => 0; # BUILDINGS has population => ( - is => 'ro', - lazy => 1, - builder => '_build_population', -); + is => 'ro', + lazy => 1, + builder => '_build_population', + ); sub _build_population { my ($self) = @_; @@ -446,10 +472,10 @@ sub _build_population { } has building_count => ( - is => 'rw', - lazy => 1, - builder => '_build_building_count', -); + is => 'rw', + lazy => 1, + builder => '_build_building_count', + ); sub _build_building_count { my ($self) = @_; @@ -480,112 +506,112 @@ sub find_building { } has command => ( - is => 'rw', - lazy => 1, - default => sub { + is => 'rw', + lazy => 1, + default => sub { my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::PlanetaryCommand'); return undef unless defined $building; #$building->body($self); return $building; - }, -); + }, + ); has oversight => ( - is => 'rw', - lazy => 1, - default => sub { + is => 'rw', + lazy => 1, + default => sub { my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Oversight'); return undef unless defined $building; #$building->body($self); return $building; - }, -); + }, + ); has archaeology => ( - is => 'rw', - lazy => 1, - default => sub { + is => 'rw', + lazy => 1, + default => sub { my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Archaeology'); return undef unless defined $building; -# #$building->body($self); + # #$building->body($self); return $building; - }, -); + }, + ); has mining_ministry => ( - is => 'rw', - lazy => 1, - default => sub { + is => 'rw', + lazy => 1, + default => sub { my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Ore::Ministry'); return undef unless defined $building; #$building->body($self); return $building; - }, -); + }, + ); has network19 => ( - is => 'rw', - lazy => 1, - default => sub { + is => 'rw', + lazy => 1, + default => sub { my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Network19'); return undef unless defined $building; #$building->body($self); return $building; - }, -); + }, + ); has development => ( - is => 'rw', - lazy => 1, - default => sub { + is => 'rw', + lazy => 1, + default => sub { my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Development'); return undef unless defined $building; #$building->body($self); return $building; - }, -); + }, + ); has refinery => ( - is => 'rw', - lazy => 1, - default => sub { + is => 'rw', + lazy => 1, + default => sub { my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Ore::Refinery'); return undef unless defined $building; #$building->body($self); return $building; - }, -); + }, + ); has spaceport => ( - is => 'rw', - lazy => 1, - default => sub { + is => 'rw', + lazy => 1, + default => sub { my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::SpacePort'); return undef unless defined $building; #$building->body($self); return $building; - }, -); + }, + ); has embassy => ( - is => 'rw', - lazy => 1, - default => sub { + is => 'rw', + lazy => 1, + default => sub { my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Embassy'); return undef unless defined $building; #$building->body($self); return $building; - }, -); + }, + ); sub is_space_free { my ($self, $x, $y) = @_; @@ -673,34 +699,34 @@ sub has_room_in_build_queue { use constant operating_resource_names => qw(food_hour energy_hour ore_hour water_hour); has future_operating_resources => ( - is => 'rw', - clearer => 'clear_future_operating_resources', - lazy => 1, - default => sub { + is => 'rw', + clearer => 'clear_future_operating_resources', + lazy => 1, + default => sub { my $self = shift; - + # get current my %future; foreach my $method ($self->operating_resource_names) { - $future{$method} = $self->$method; + $future{$method} = $self->$method; } - + # adjust for what's already in build queue my @queued_builds = @{$self->builds}; foreach my $build (@queued_builds) { - $build->body($self); - my $other = $build->stats_after_upgrade; - foreach my $method ($self->operating_resource_names) { - $future{$method} += $other->{$method} - $build->$method; - } + $build->body($self); + my $other = $build->stats_after_upgrade; + foreach my $method ($self->operating_resource_names) { + $future{$method} += $other->{$method} - $build->$method; + } } return \%future; - }, -); + }, + ); sub has_resources_to_operate { my ($self, $building) = @_; - + # get future my $future = $self->future_operating_resources; @@ -710,7 +736,7 @@ sub has_resources_to_operate { # check our ability to sustain ourselves foreach my $method ($self->operating_resource_names) { my $delta = $after->{$method} - $building->$method; - # don't allow it if it sucks resources && its sucking more than we're producing + # don't allow it if it sucks resources && its sucking more than we're producing if ($delta < 0 && $future->{$method} + $delta < 0) { my $resource = $method; $resource =~ s/(\w+)_hour/$1/; @@ -722,13 +748,13 @@ sub has_resources_to_operate { sub has_resources_to_operate_after_building_demolished { my ($self, $building) = @_; - + # get future my $planet = $self->future_operating_resources; # check our ability to sustain ourselves foreach my $method ($self->operating_resource_names) { - # don't allow it if it sucks resources && its sucking more than we're producing + # don't allow it if it sucks resources && its sucking more than we're producing if ($planet->{$method} - $building->$method < 0) { my $resource = $method; $resource =~ s/(\w+)_hour/$1/; @@ -811,7 +837,7 @@ sub found_colony { $self->usable_as_starter_enabled(0); $self->last_tick(DateTime->now); $self->update; -# Excavators get cleared when being checked for results. + # Excavators get cleared when being checked for results. # award medal my $type = ref $self; @@ -825,11 +851,11 @@ sub found_colony { # add command building my $command = Lacuna->db->resultset('Lacuna::DB::Result::Building')->new({ - x => 0, - y => 0, - class => 'Lacuna::DB::Result::Building::PlanetaryCommand', - level => $empire->growth_affinity - 1, - }); + x => 0, + y => 0, + class => 'Lacuna::DB::Result::Building::PlanetaryCommand', + level => $empire->growth_affinity - 1, + }); $self->build_building($command); $command->finish_upgrade; @@ -837,7 +863,7 @@ sub found_colony { foreach my $crater (@craters) { $crater->finish_work->update; } - + # add starting resources $self->needs_recalc(1); $self->tick; @@ -846,10 +872,10 @@ sub found_colony { $self->add_water(700); $self->add_ore(700); $self->update; - + # newsworthy $self->add_news(75,'%s founded a new colony on %s.', $empire->name, $self->name); - + return $self; } @@ -871,34 +897,34 @@ sub convert_to_station { # clean it my @all_buildings = @{$self->building_cache}; $self->delete_buildings(\@all_buildings); - + # add command building my $command = Lacuna->db->resultset('Lacuna::DB::Result::Building')->new({ - x => 0, - y => 0, - class => 'Lacuna::DB::Result::Building::Module::StationCommand', - }); + x => 0, + y => 0, + class => 'Lacuna::DB::Result::Building::Module::StationCommand', + }); $self->build_building($command); $command->finish_upgrade; - + # add parliament my $parliament = Lacuna->db->resultset('Lacuna::DB::Result::Building')->new({ - x => -1, - y => 0, - class => 'Lacuna::DB::Result::Building::Module::Parliament', - }); + x => -1, + y => 0, + class => 'Lacuna::DB::Result::Building::Module::Parliament', + }); $self->build_building($parliament); $parliament->finish_upgrade; - + # add warehouse my $warehouse = Lacuna->db->resultset('Lacuna::DB::Result::Building')->new({ - x => 1, - y => 0, - class => 'Lacuna::DB::Result::Building::Module::Warehouse', - }); + x => 1, + y => 0, + class => 'Lacuna::DB::Result::Building::Module::Warehouse', + }); $self->build_building($warehouse); $warehouse->finish_upgrade; - + # add starting resources $self->tick; $self->add_algae(2500); @@ -906,25 +932,25 @@ sub convert_to_station { $self->add_water(2500); $self->add_rutile(2500); $self->update; - + # newsworthy $self->add_news(100,'%s deployed a space station at %s.', $empire->name, $self->name); - + return $self; } has total_ore_concentration => ( - is => 'ro', - lazy => 1, - default => sub { + is => 'ro', + lazy => 1, + default => sub { my $self = shift; my $tally = 0; foreach my $type (ORE_TYPES) { - $tally += $self->$type; + $tally += $self->$type; } return $tally; - }, -); + }, + ); sub is_food { my ($self, $resource) = @_; @@ -984,7 +1010,7 @@ sub recalc_stats { } $stats{max_berth} = 1; #calculate building production - my ($gas_giant_platforms, $terraforming_platforms, $station_command, $pantheon_of_hagness, $total_ore_production_hour, $ore_production_hour, $ore_consumption_hour) = 0; + my ($gas_giant_platforms, $terraforming_platforms, $station_command, $pantheon_of_hagness, $ore_production_hour, $ore_consumption_hour) = 0; foreach my $building (@{$self->building_cache}) { $stats{waste_capacity} += $building->waste_capacity; $stats{water_capacity} += $building->water_capacity; @@ -1003,7 +1029,7 @@ sub recalc_stats { $stats{$method} += $building->$method(); } if ($building->isa('Lacuna::DB::Result::Building::SpacePort') and $building->efficiency == 100) { - $stats{max_berth} = $building->level if ($building->level > $stats{max_berth}); + $stats{max_berth} = $building->level if ($building->level > $stats{max_berth}); } if ($building->isa('Lacuna::DB::Result::Building::Ore::Ministry')) { my $platforms = Lacuna->db->resultset('Lacuna::DB::Result::MiningPlatforms')->search({planet_id => $self->id}); @@ -1011,7 +1037,6 @@ sub recalc_stats { foreach my $type (ORE_TYPES) { my $method = $type.'_hour'; $stats{$method} += $platform->$method(); - $total_ore_production_hour += $platform->$method(); } } } @@ -1029,14 +1054,12 @@ sub recalc_stats { my $output_chains = Lacuna->db->resultset('Lacuna::DB::Result::SupplyChain')->search({planet_id => $self->id}); while (my $out_chain = $output_chains->next) { my $percent = $out_chain->percent_transferred; - $percent = $percent > 100 ? 100 : $percent; - $percent *= $building->efficiency / 100; + $percent = $percent > 100 ? 100 : $percent; + $percent *= $building->efficiency / 100; + my $resource_hour = sprintf('%.0f',$out_chain->resource_hour * $percent / 100); - my $resource_name = $self->resource_name($out_chain->resource_type); + my $resource_name = $self->resource_name($out_chain->resource_type); $stats{$resource_name} -= $resource_hour; - if ($self->is_ore($out_chain->resource_type)) { - $total_ore_production_hour -= $resource_hour; - } } } if ($building->isa('Lacuna::DB::Result::Building::Permanent::GasGiantPlatform')) { @@ -1055,10 +1078,10 @@ sub recalc_stats { # active supply chains sent *to* this planet my $input_chains = Lacuna->db->resultset('Lacuna::DB::Result::SupplyChain')->search({ - target_id => $self->id, - stalled => 0, - },{prefetch => 'building'} - ); + target_id => $self->id, + stalled => 0, + },{prefetch => 'building'} + ); while (my $in_chain = $input_chains->next) { my $percent = $in_chain->percent_transferred; @@ -1067,9 +1090,6 @@ sub recalc_stats { my $resource_hour = sprintf('%.0f',$in_chain->resource_hour * $percent / 100); my $resource_name = $self->resource_name($in_chain->resource_type); $stats{$resource_name} += $resource_hour; - if ($self->is_ore($in_chain->resource_type)) { - $total_ore_production_hour += $resource_hour; - } } # local ore production @@ -1077,17 +1097,27 @@ sub recalc_stats { my $method = $type.'_hour'; my $domestic_ore_hour = sprintf('%.0f',$self->$type * $ore_production_hour / $self->total_ore_concentration); $stats{$method} += $domestic_ore_hour; - $total_ore_production_hour += $domestic_ore_hour; } - # subtract ore consumption + # For all ore production that is positive, deduct a percentage for ore consumption + my $positive_ore_hour = 0; foreach my $type (ORE_TYPES) { - my $method = $type.'_hour'; - $stats{$method} -= sprintf('%.0f', ($total_ore_production_hour) ? $ore_consumption_hour * $stats{$method} / $total_ore_production_hour: 0); + my $resource_name = $self->resource_name($type); + if ($stats{$resource_name} > 0) { + $positive_ore_hour += $stats{$resource_name}; + } } - - # overall ore production - $stats{ore_hour} = $total_ore_production_hour - $ore_consumption_hour; + my $reduce_factor = 1; + if ($positive_ore_hour >= $ore_consumption_hour) { + $reduce_factor = $ore_consumption_hour / $positive_ore_hour; + } + foreach my $type (ORE_TYPES) { + my $resource_name = $self->resource_name($type); + if ($stats{$resource_name} > 0) { + $stats{$resource_name} -= $stats{$resource_name} * $reduce_factor; + } + } + $stats{ore_hour} = $positive_ore_hour - $ore_consumption_hour; # deal with negative amounts stored $self->water_stored = 0 if $self->water_stored < 0; @@ -1125,10 +1155,10 @@ sub recalc_stats { } } $stats{plots_available} = $max_plots - $self->building_count; -# Decrease happiness production if short on plots. + # Decrease happiness production if short on plots. if ($stats{plots_available} < 0) { my $plot_tax = int(50 * 1.62 ** (abs($stats{plots_available})-1)); -# Set max to at least -10k + # Set max to at least -10k my $neg_hr = $self->happiness > 100_000 ? -1 * $self->happiness/10 : -10_000; if ( $stats{happiness_hour} < 0 and $stats{happiness_hour} > $neg_hr) { @@ -1301,7 +1331,7 @@ sub tick_to { my $seconds = $now->epoch - $self->last_tick->epoch; my $tick_rate = $seconds / 3600; $self->last_tick($now); -# Check to see if downward spiral still happening in happiness from negative plots. + # Check to see if downward spiral still happening in happiness from negative plots. $self->needs_recalc(1) if ($self->happiness < 0 and $self->happiness_hour < -20_000); if ($self->needs_recalc) { $self->recalc_stats; @@ -1323,8 +1353,7 @@ sub tick_to { } else { $arch->last_check($now); - $arch->update; - } + } } # happiness $self->add_happiness(sprintf('%.0f', $self->happiness_hour * $tick_rate)); @@ -1353,27 +1382,53 @@ sub tick_to { $self->add_water(sprintf('%.0f', $self->water_hour * $tick_rate)); } + + # OK, tricky stuff coming up! + # + # TERMS: + # + # $self->ore_hour + # $self->ore_hour - the net amount of ore produced on this colony per hour + # it also includes any ore imported via supply chains and any exported by supply chains. + # + # $ore_consumption_hour - the amount of generic ore type consumed by buildings + # consumption comes out of stored ore. + # + # $self->xxx_hour - the net amount of a specific ore (e.g. xxx = gold) produced/consumed by + # this colony. Includes all local production, platform production, incoming supply + # chains and outgoing supply chains. + # + # ALGORITHM: + # + # Every tick, we need to calculate the amount of each ore + # + # Where a xxx_hour ore rate is specified then calculate the resulting +ve or -ve change in + # the amount of ore stored for that specific ore type. If -ve and ore stored goes to zero + # then don't 'complain', this just means that a supply chain will become stalled which is + # handled elsewhere. + # + # For $ore_consumption_hour we remove from stored ore proportionate to the amount of ore + # stored of each type. In this case if a stored ore goes to zero then we *do* complain + # and part of that complaint might be to damage buildings. + # + # ore - my $ore_hour = 0; foreach my $type (ORE_TYPES) { my $hour_method = $type.'_hour'; - $ore_hour += $self->$hour_method; - if ($self->$hour_method < 0 ) { # if it gets negative, spend out of storage + if ($self->$hour_method < 0 ) { $self->spend_ore_type($type, sprintf('%.0f',abs($self->$hour_method) * $tick_rate)); } - else { + elsif ($self->$hour_method > 0 ) { $self->add_ore_type($type, sprintf('%.0f', $self->$hour_method * $tick_rate)); } } - if ($ore_hour == 0 && $self->ore_hour != 0) { - if ($self->ore_hour < 0) { - $self->spend_ore(sprintf('%.0f', abs($self->ore_hour) * $tick_rate)); - } - else { - $self->add_ore(sprintf('%.0f', $self->ore_hour * $tick_rate)); - } + if ($self->ore_hour > 0) { + $self->add_ore(sprintf('%.0f', $self->ore_hour * $tick_rate)); } - + if ($self->ore_hour < 0) { + $self->spend_ore(sprintf('%.0f', abs($self->ore_hour) * $tick_rate, 'complain')); + } + # food my %food; my $food_produced; @@ -1497,13 +1552,13 @@ sub add_type { my $empire = $self->empire; if (defined $empire && !$empire->skip_resource_warnings && !$empire->check_for_repeat_message('complaint_overflow'.$self->id)) { $empire->send_predefined_message( - filename => 'complaint_overflow.txt', - params => [$type, $self->id, $self->name], - repeat_check=> 'complaint_overflow'.$self->id, - tags => ['Complaint','Alert'], - ); + filename => 'complaint_overflow.txt', + params => [$type, $self->id, $self->name], + repeat_check=> 'complaint_overflow'.$self->id, + tags => ['Complaint','Alert'], + ); } - + } $self->$method($value); return $self; @@ -1539,13 +1594,18 @@ sub add_ore_type { } sub spend_ore_type { - my ($self, $type, $amount_spent) = @_; + my ($self, $type, $amount_spent, $complain) = @_; my $amount_stored = $self->type_stored($type); if ($amount_spent > $amount_stored && $amount_spent > 0) { my $difference = $amount_spent - $amount_stored; $self->spend_happiness($difference); $self->type_stored($type, 0); - $self->complain_about_lack_of_resources('ore') if ((($difference * 100) / $amount_spent) > 5); # help avoid rounding errors causing messages + + if ($complain && + ($difference * 100) / $amount_spent > 5) { + + $self->complain_about_lack_of_resources('ore'); + } } else { $self->type_stored($type, $amount_stored - $amount_spent ); @@ -1761,11 +1821,11 @@ sub spend_ore { foreach my $type (ORE_TYPES) { $ore_stored += $self->type_stored($type); } - + # spend proportionally and save if ($ore_stored) { foreach my $type (ORE_TYPES) { - $self->spend_ore_type($type, sprintf('%.0f', ($ore_consumed * $self->type_stored($type)) / $ore_stored)); + $self->spend_ore_type($type, sprintf('%.0f', ($ore_consumed * $self->type_stored($type)) / $ore_stored),'complain'); } } return $self; @@ -1802,13 +1862,19 @@ sub add_food_type { } sub spend_food_type { - my ($self, $type, $amount_spent) = @_; + my ($self, $type, $amount_spent, $complain) = @_; my $amount_stored = $self->type_stored($type); if ($amount_spent > 0 && $amount_spent > $amount_stored) { my $difference = $amount_spent - $amount_stored; $self->spend_happiness($difference); $self->type_stored($type, 0); - $self->complain_about_lack_of_resources('food') if ((($difference * 100) / $amount_spent) > 5); # help avoid rounding errors causing messages + + # Complain about lack of resources if required but avoid rounding errors + if ($complain && + ($difference * 100) / $amount_spent > 5) { + + $self->complain_about_lack_of_resources('food'); + } } else { $self->type_stored($type, $amount_stored - $amount_spent ); @@ -2052,7 +2118,9 @@ sub spend_food { # spend proportionally and save if ($food_stored) { foreach my $type (FOOD_TYPES) { - $self->spend_food_type($type, sprintf('%.0f', ($food_consumed * $self->type_stored($type)) / $food_stored)); + # We 'complain' about lack of food if we are spending out of generic food + # we don't complain about specific foods, because we can always substitute. + $self->spend_food_type($type, sprintf('%.0f', ($food_consumed * $self->type_stored($type)) / $food_stored),'complain'); } } diff --git a/lib/Lacuna/RPC/Building/PlanetaryCommand.pm b/lib/Lacuna/RPC/Building/PlanetaryCommand.pm index fdb9a999..5870f9e5 100644 --- a/lib/Lacuna/RPC/Building/PlanetaryCommand.pm +++ b/lib/Lacuna/RPC/Building/PlanetaryCommand.pm @@ -19,6 +19,8 @@ around 'view' => sub { my $building = $self->get_building($empire, $building_id, skip_offline => 1); my $out = $orig->($self, $empire, $building); $out->{planet} = $building->body->get_status($empire); + $out->{ore} = $building->body->get_ore_status; + $out->{food} = $building->body->get_food_status; $out->{next_colony_cost} = $empire->next_colony_cost; return $out; }; diff --git a/lib/Lacuna/RPC/Building/Shipyard.pm b/lib/Lacuna/RPC/Building/Shipyard.pm index 187db1a6..09704303 100644 --- a/lib/Lacuna/RPC/Building/Shipyard.pm +++ b/lib/Lacuna/RPC/Building/Shipyard.pm @@ -116,7 +116,7 @@ sub get_buildable { next unless ($tag ~~ \@tags); } my $can = eval{$building->can_build_ship($ship)}; - my $reason = $@; + my $reason = $@; $buildable{$type} = { attributes => { speed => $building->set_ship_speed($ship), -- 2.51.2 From 9fc4ca16149e22397acbeae90469447dc4549ead Mon Sep 17 00:00:00 2001 From: ian docherty Date: Sun, 24 Jun 2012 12:37:54 -0400 Subject: [PATCH 05/19] Updated changes.txt --- var/www/public/changes.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index d44f8ae6..68bab8c3 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -2,6 +2,7 @@ - Mod: Intelligence Building Level doesn't factor into training costs. - Mod: Burning a spy has more consequences. - Fix: No burning spies while they're being transported. + - Add: Supply chain now shows 'stalled' status (API only) 3.0854: - Add: Backend support only for fleet actions. No changes to gameplay at this time. -- 2.51.2 From 893dfe9e3c61d180ad2155f35de51da3862195d0 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Sun, 24 Jun 2012 19:55:26 -0600 Subject: [PATCH 06/19] Space Station kludge --- lib/Lacuna/DB/Result/Building/Module.pm | 2 +- var/messages/space_station_destroyed.txt | 1 + var/www/public/changes.txt | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Lacuna/DB/Result/Building/Module.pm b/lib/Lacuna/DB/Result/Building/Module.pm index f2340c99..40a001c3 100644 --- a/lib/Lacuna/DB/Result/Building/Module.pm +++ b/lib/Lacuna/DB/Result/Building/Module.pm @@ -90,7 +90,7 @@ around demolish => sub { filename => 'space_station_destroyed.txt', params => [$body->id, $body->name], ); - $body->sanitize; +# $body->sanitize; } }; diff --git a/var/messages/space_station_destroyed.txt b/var/messages/space_station_destroyed.txt index c3e56d55..14643fe5 100644 --- a/var/messages/space_station_destroyed.txt +++ b/var/messages/space_station_destroyed.txt @@ -1,6 +1,7 @@ Space Station Destroyed ~~~ We have just received word that our station named {Planet %s %s} has been destroyed. +Dev Note: Temporary fix for seeing if we can track down the SS destruction bug. Contact an admin, so we can check the state of your station if you got this message. Regards, diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index d44f8ae6..141fb031 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -2,6 +2,7 @@ - Mod: Intelligence Building Level doesn't factor into training costs. - Mod: Burning a spy has more consequences. - Fix: No burning spies while they're being transported. + - Grr: Space Stations shouldn't turn into asteroids. However, they won't die if you want them until we fix the bug. 3.0854: - Add: Backend support only for fleet actions. No changes to gameplay at this time. -- 2.51.2 From fe14989c3dc924f7fedbd1faff900388a9ba191b Mon Sep 17 00:00:00 2001 From: ian docherty Date: Tue, 26 Jun 2012 04:13:43 -0400 Subject: [PATCH 07/19] Weakened several potential memory leak references --- lib/Lacuna/DB/Result/Building/Development.pm | 1 - .../DB/Result/Building/SubspaceSupplyDepot.pm | 1 - lib/Lacuna/DB/Result/Building/Trade.pm | 2 + lib/Lacuna/DB/Result/Empire.pm | 3 + lib/Lacuna/DB/Result/Map/Body.pm | 7 ++- lib/Lacuna/DB/Result/Map/Body/Planet.pm | 56 ++++++++++++------- lib/Lacuna/DB/Result/Ships.pm | 2 + lib/Lacuna/DB/Result/Spies.pm | 25 +++++++-- t/TestHelper.pm | 3 +- 9 files changed, 68 insertions(+), 32 deletions(-) diff --git a/lib/Lacuna/DB/Result/Building/Development.pm b/lib/Lacuna/DB/Result/Building/Development.pm index 619cf191..f103950c 100644 --- a/lib/Lacuna/DB/Result/Building/Development.pm +++ b/lib/Lacuna/DB/Result/Building/Development.pm @@ -9,7 +9,6 @@ sub subsidize_build_queue { my ($self) = @_; $self->body->tick; foreach my $build (@{$self->body->builds}) { - $build->body($self->body); $build->finish_upgrade; } } diff --git a/lib/Lacuna/DB/Result/Building/SubspaceSupplyDepot.pm b/lib/Lacuna/DB/Result/Building/SubspaceSupplyDepot.pm index 47c5c74a..bf551752 100644 --- a/lib/Lacuna/DB/Result/Building/SubspaceSupplyDepot.pm +++ b/lib/Lacuna/DB/Result/Building/SubspaceSupplyDepot.pm @@ -94,7 +94,6 @@ sub complete_build_queue { $self->work_ends($self->work_ends->subtract(seconds => $time_to_complete)); $self->update; foreach my $build (@{$self->body->builds}) { - $build->body($self->body); $build->finish_upgrade; } } diff --git a/lib/Lacuna/DB/Result/Building/Trade.pm b/lib/Lacuna/DB/Result/Building/Trade.pm index 5d4d668a..b42727e0 100644 --- a/lib/Lacuna/DB/Result/Building/Trade.pm +++ b/lib/Lacuna/DB/Result/Building/Trade.pm @@ -3,6 +3,7 @@ package Lacuna::DB::Result::Building::Trade; use Moose; use List::Util qw(max min); use Carp; +use Scalar::Util qw(weaken); use utf8; use List::Util qw(max); @@ -423,6 +424,7 @@ sub push_items { if ($options->{stay}) { $ship->body_id($target->id); $ship->body($target); + weaken($ship->{_relationship_data}{body}); $ship->send( target => $self->body, direction => 'in', diff --git a/lib/Lacuna/DB/Result/Empire.pm b/lib/Lacuna/DB/Result/Empire.pm index 8a4547c1..3ff13021 100644 --- a/lib/Lacuna/DB/Result/Empire.pm +++ b/lib/Lacuna/DB/Result/Empire.pm @@ -5,6 +5,7 @@ use utf8; no warnings qw(uninitialized); extends 'Lacuna::DB::Result'; use DateTime; +use Scalar::Util qw(weaken); use Lacuna::Util qw(format_date); use Digest::SHA; use List::MoreUtils qw(uniq); @@ -502,6 +503,8 @@ sub found { $self->stage('founded'); $self->update; $self->home_planet($home_planet); + weaken($self->{_relationship_data}{home_planet}); + $self->add_probe($home_planet->star_id, $home_planet->id); # found colony diff --git a/lib/Lacuna/DB/Result/Map/Body.pm b/lib/Lacuna/DB/Result/Map/Body.pm index 386f8b3e..87071dde 100644 --- a/lib/Lacuna/DB/Result/Map/Body.pm +++ b/lib/Lacuna/DB/Result/Map/Body.pm @@ -232,11 +232,12 @@ has building_cache => ( sub _build_building_cache { my ($self) = @_; - my $buildings = []; - my $bld_rs = $self->_buildings->search({},{prefetch => 'body'}); + my $bld_rs = $self->_buildings->search({}); while (my $building = $bld_rs->next) { - push @$buildings, $building; + $building->body($self); + weaken($building->{_relationship_data}{body}); + push @$buildings,$building; } return $buildings; } diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 783cead2..2227d955 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -486,7 +486,8 @@ has command => ( my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::PlanetaryCommand'); return undef unless defined $building; - #$building->body($self); + $building->body($self); + weaken($building->{_relationship_data}{body}); return $building; }, ); @@ -498,7 +499,9 @@ has oversight => ( my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Oversight'); return undef unless defined $building; - #$building->body($self); + $building->body($self); + weaken($building->{_relationship_data}{body}); + return $building; }, ); @@ -510,7 +513,8 @@ has archaeology => ( my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Archaeology'); return undef unless defined $building; -# #$building->body($self); + $building->body($self); + weaken($building->{_relationship_data}{body}); return $building; }, ); @@ -522,7 +526,8 @@ has mining_ministry => ( my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Ore::Ministry'); return undef unless defined $building; - #$building->body($self); + $building->body($self); + weaken($building->{_relationship_data}{body}); return $building; }, ); @@ -534,7 +539,8 @@ has network19 => ( my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Network19'); return undef unless defined $building; - #$building->body($self); + $building->body($self); + weaken($building->{_relationship_data}{body}); return $building; }, ); @@ -546,7 +552,8 @@ has development => ( my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Development'); return undef unless defined $building; - #$building->body($self); + $building->body($self); + weaken($building->{_relationship_data}{body}); return $building; }, ); @@ -558,7 +565,8 @@ has refinery => ( my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Ore::Refinery'); return undef unless defined $building; - #$building->body($self); + $building->body($self); + weaken($building->{_relationship_data}{body}); return $building; }, ); @@ -570,7 +578,8 @@ has spaceport => ( my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::SpacePort'); return undef unless defined $building; - #$building->body($self); + $building->body($self); + weaken($building->{_relationship_data}{body}); return $building; }, ); @@ -582,7 +591,8 @@ has embassy => ( my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Embassy'); return undef unless defined $building; - #$building->body($self); + $building->body($self); + weaken($building->{_relationship_data}{body}); return $building; }, ); @@ -688,19 +698,18 @@ has future_operating_resources => ( # adjust for what's already in build queue my @queued_builds = @{$self->builds}; foreach my $build (@queued_builds) { - $build->body($self); - my $other = $build->stats_after_upgrade; - foreach my $method ($self->operating_resource_names) { - $future{$method} += $other->{$method} - $build->$method; - } + my $other = $build->stats_after_upgrade; + foreach my $method ($self->operating_resource_names) { + $future{$method} += $other->{$method} - $build->$method; + } } return \%future; }, -); + ); sub has_resources_to_operate { my ($self, $building) = @_; - + # get future my $future = $self->future_operating_resources; @@ -710,7 +719,7 @@ sub has_resources_to_operate { # check our ability to sustain ourselves foreach my $method ($self->operating_resource_names) { my $delta = $after->{$method} - $building->$method; - # don't allow it if it sucks resources && its sucking more than we're producing + # don't allow it if it sucks resources && its sucking more than we're producing if ($delta < 0 && $future->{$method} + $delta < 0) { my $resource = $method; $resource =~ s/(\w+)_hour/$1/; @@ -722,13 +731,13 @@ sub has_resources_to_operate { sub has_resources_to_operate_after_building_demolished { my ($self, $building) = @_; - + # get future my $planet = $self->future_operating_resources; # check our ability to sustain ourselves foreach my $method ($self->operating_resource_names) { - # don't allow it if it sucks resources && its sucking more than we're producing + # don't allow it if it sucks resources && its sucking more than we're producing if ($planet->{$method} - $building->$method < 0) { my $resource = $method; $resource =~ s/(\w+)_hour/$1/; @@ -799,7 +808,8 @@ sub build_building { $building->body_id($self->id); $building->level(0) unless $building->level; $building->insert; - #$building->body($self); + $building->body($self); + weaken($building->{_relationship_data}{body}); $building->start_upgrade(undef, $in_parallel); $self->building_cache([@{$self->building_cache}, $building]); } @@ -808,10 +818,11 @@ sub found_colony { my ($self, $empire) = @_; $self->empire_id($empire->id); $self->empire($empire); + weaken($self->{_relationship_data}{empire}); $self->usable_as_starter_enabled(0); $self->last_tick(DateTime->now); $self->update; -# Excavators get cleared when being checked for results. + # Excavators get cleared when being checked for results. # award medal my $type = ref $self; @@ -859,6 +870,8 @@ sub convert_to_station { $self->plots_available(0); $self->empire_id($empire->id); $self->empire($empire); + weaken($self->{_relationship_data}{empire}); + $self->usable_as_starter_enabled(0); $self->last_tick(DateTime->now); $self->alliance_id($empire->alliance_id); @@ -1240,6 +1253,7 @@ sub tick { foreach my $key (sort keys %todo) { my ($object, $job) = ($todo{$key}{object}, $todo{$key}{type}); $object->body($self); + weaken($object->{_relationship_data}{body}); if ($job eq 'ship built') { $self->tick_to($object->date_available); $object->finish_construction; diff --git a/lib/Lacuna/DB/Result/Ships.pm b/lib/Lacuna/DB/Result/Ships.pm index f6941df7..3ab43752 100644 --- a/lib/Lacuna/DB/Result/Ships.pm +++ b/lib/Lacuna/DB/Result/Ships.pm @@ -6,6 +6,7 @@ no warnings qw(uninitialized); extends 'Lacuna::DB::Result'; use Lacuna::Util qw(format_date randint); use DateTime; +use Scalar::Util qw(weaken); use feature "switch"; has 'hostile_action' => ( @@ -291,6 +292,7 @@ sub send { if ($options{target}->isa('Lacuna::DB::Result::Map::Body')) { $self->foreign_body_id($options{target}->id); $self->foreign_body($options{target}); + weaken($self->{_relationship_data}{foreign_body}); $self->foreign_star_id(undef); $self->foreign_star(undef); } diff --git a/lib/Lacuna/DB/Result/Spies.pm b/lib/Lacuna/DB/Result/Spies.pm index 5dba7ff5..36f88f4e 100644 --- a/lib/Lacuna/DB/Result/Spies.pm +++ b/lib/Lacuna/DB/Result/Spies.pm @@ -647,7 +647,10 @@ sub get_defender { empire_id => { 'not_in' => \@member_ids } }, { rows => 1, order_by => 'rand()' } )->single; - $defender->on_body($self->on_body) if defined $defender; + if (defined $defender) { + $defender->on_body($self->on_body); + weaken($defender->{_relationship_data}{on_body}); + } return $defender; } @@ -674,7 +677,10 @@ sub get_attacker { { rows => 1, order_by => 'rand()' } ) ->single; - $attacker->on_body($self->on_body) if defined $attacker; + if (defined $attacker) { + $attacker->on_body($self->on_body); + weaken($attacker->{_relationship_data}{on_body}); + } return $attacker; } @@ -702,7 +708,10 @@ sub get_idle_attacker { my $attacker = random_element(\@attackers); - $attacker->on_body($self->on_body) if defined $attacker; + if (defined $attacker) { + $attacker->on_body($self->on_body); + weaken($attacker->{_relationship_data}{on_body}); + } return $attacker; } @@ -716,7 +725,10 @@ sub get_random_prisoner { ) ->all; my $prisoner = random_element(\@prisoners); - $prisoner->on_body($self->on_body) if defined $prisoner; + if (defined $prisoner) { + $prisoner->on_body($self->on_body); + weaken($prisoner->{_relationship_data}{on_body}); + } return $prisoner; } @@ -1713,6 +1725,7 @@ sub abduct_operative { return $self->ship_not_found->id unless (defined $ship); return $self->no_contact->id unless (defined $defender); $ship->body($self->from_body); + weaken($ship->{_relationship_data}{from_body}); $ship->send( target => $self->on_body, direction => 'in', @@ -2018,6 +2031,7 @@ sub steal_resources { } $on_body->update; $ship->body($self->from_body); + weaken($ship->{_relationship_data}{body}); $ship->send( target => $self->on_body, direction => 'in', @@ -2067,6 +2081,7 @@ sub steal_glyph { my $glyph = $on_body->glyphs->search(undef, {rows => 1, order_by => 'rand()'})->single; return $self->mission_objective_not_found('glyph')->id unless defined $glyph; $ship->body($self->from_body); + weaken($ship->{_relationship_data}{body}); $ship->send( target => $self->on_body, direction => 'in', @@ -2113,6 +2128,7 @@ sub steal_ships { )->single; return $self->ship_not_found->id unless (defined $ship); $ship->body($self->from_body); + weaken($ship->{_relationship_data}{body}); $ship->send( target => $self->on_body, direction => 'in', @@ -2255,7 +2271,6 @@ sub shut_down_building { filename => 'building_loss_of_power.txt', params => [$building->name, $self->on_body->id, $self->on_body->name], ); - $building->body($self->on_body); $building->spend_efficiency($self->level)->update; $self->on_body->add_news(25, 'Employees at the %s on %s were left in the dark today during a power outage.', diff --git a/t/TestHelper.pm b/t/TestHelper.pm index 32007a26..6f83c68d 100644 --- a/t/TestHelper.pm +++ b/t/TestHelper.pm @@ -61,6 +61,8 @@ sub clear_all_test_empires { name => {like => $name}, }); while (my $empire = $empires->next) { + $empire->essentia(0); + $empire->update; my $planets = $empire->planets; while ( my $planet = $planets->next ) { @@ -68,7 +70,6 @@ sub clear_all_test_empires { $planet->delete_buildings(\@buildings); } - $empire->delete; } } -- 2.51.2 From 919c7fe4ac57dfe7d1ef80445afb2158ab34d9a8 Mon Sep 17 00:00:00 2001 From: ian docherty Date: Tue, 26 Jun 2012 04:44:03 -0400 Subject: [PATCH 08/19] Added missing Scalar::Util calls --- lib/Lacuna/DB/Result/Map/Body/Planet.pm | 1 + lib/Lacuna/DB/Result/Spies.pm | 2 ++ 2 files changed, 3 insertions(+) diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 2227d955..3464e59a 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -10,6 +10,7 @@ use List::Util qw(shuffle max min); use Lacuna::Util qw(randint format_date); use DateTime; use Data::Dumper; +use Scalar::Util qw(weaken); no warnings 'uninitialized'; __PACKAGE__->has_many('ships','Lacuna::DB::Result::Ships','body_id'); diff --git a/lib/Lacuna/DB/Result/Spies.pm b/lib/Lacuna/DB/Result/Spies.pm index 36f88f4e..c7e33a2b 100644 --- a/lib/Lacuna/DB/Result/Spies.pm +++ b/lib/Lacuna/DB/Result/Spies.pm @@ -7,6 +7,8 @@ extends 'Lacuna::DB::Result'; use List::Util qw(shuffle); use Lacuna::Util qw(format_date randint random_element); use DateTime; +use Scalar::Util qw(weaken); + use feature "switch"; use Lacuna::Constants qw(ORE_TYPES FOOD_TYPES SHIP_TYPES); -- 2.51.2 From a7f079fb23956b53b816d079c3bcc2b52be3e6c8 Mon Sep 17 00:00:00 2001 From: Ian Docherty Date: Tue, 26 Jun 2012 14:39:09 -0400 Subject: [PATCH 09/19] DeLambert now offer glyphs in same-type trades. --- lib/Lacuna.pm | 2 +- lib/Lacuna/AI/DeLambert.pm | 6 ++-- lib/Lacuna/Web/Admin.pm | 66 ++++++++++++++++++++------------------ var/www/public/changes.txt | 3 ++ 4 files changed, 42 insertions(+), 35 deletions(-) diff --git a/lib/Lacuna.pm b/lib/Lacuna.pm index 37b007d6..14e5941f 100644 --- a/lib/Lacuna.pm +++ b/lib/Lacuna.pm @@ -7,7 +7,7 @@ use Config::JSON; useall __PACKAGE__; -our $VERSION = 3.0855; +our $VERSION = 3.0856; my $config = Config::JSON->new('/data/Lacuna-Server/etc/lacuna.conf'); my $db = Lacuna::DB->connect($config->get('db/dsn'),$config->get('db/username'),$config->get('db/password'), { mysql_enable_utf8 => 1}); diff --git a/lib/Lacuna/AI/DeLambert.pm b/lib/Lacuna/AI/DeLambert.pm index 3da7c045..e59659da 100644 --- a/lib/Lacuna/AI/DeLambert.pm +++ b/lib/Lacuna/AI/DeLambert.pm @@ -230,9 +230,11 @@ sub sell_glyph_trade { $quantity = int(100 / $cost_per); } my @glyphs; + my @glyph_types = split(/,/, $scratchpad->{sell_glyph_type}); + my $glyph_type = random_element(\@glyph_types); + for (1..$quantity) { - my $ore = random_element([ORE_TYPES]); - push @glyphs, $ore; + push @glyphs, $glyph_type; } if ($quantity) { say "Creating a trade for $quantity glyphs"; diff --git a/lib/Lacuna/Web/Admin.pm b/lib/Lacuna/Web/Admin.pm index 6929b4cd..923a4432 100644 --- a/lib/Lacuna/Web/Admin.pm +++ b/lib/Lacuna/Web/Admin.pm @@ -24,8 +24,8 @@ sub www_send_test_message { } $empire->send_message( - from => $empire, - body => 'This is a test message that contains all the components possible in a message. + from => $empire, + body => 'This is a test message that contains all the components possible in a message. {food} {water} {ore} {energy} {waste} {happiness} {essentia} {build} {time} {Empire 1 Lacuna Expanse Corp} {Planet '.$empire->home_planet->id.' '.$empire->home_planet->name.'} @@ -33,38 +33,38 @@ sub www_send_test_message { {Starmap 0 0 The Center of the Map} [http://www.lacunaexpanse.com] ', - subject => 'Test Message', - tags => ['Alert'], - attachments => { + subject => 'Test Message', + tags => ['Alert'], + attachments => { table => [ - ['Header 1', 'Header 2'], - ['Row 1 Field 1', 'Row 1 Field 2'], - ['Row 2 Field 1', 'Row 2 Field 2'], - ], + ['Header 1', 'Header 2'], + ['Row 1 Field 1', 'Row 1 Field 2'], + ['Row 2 Field 1', 'Row 2 Field 2'], + ], image => { - url => 'http://bloximages.chicago2.vip.townnews.com/host.madison.com/content/tncms/assets/editorial/8/ec/604/8ec6048a-998e-11de-b821-001cc4c002e0.preview-300.jpg', - title => 'JT Rocks', - link => 'http://host.madison.com/wsj/business/article_bd9f8c96-998d-11de-87d3-001cc4c002e0.html', - }, + url => 'http://bloximages.chicago2.vip.townnews.com/host.madison.com/content/tncms/assets/editorial/8/ec/604/8ec6048a-998e-11de-b821-001cc4c002e0.preview-300.jpg', + title => 'JT Rocks', + link => 'http://host.madison.com/wsj/business/article_bd9f8c96-998d-11de-87d3-001cc4c002e0.html', + }, link => { - url => 'http://www.plainblack.com/', - label => 'Plain Black', - }, + url => 'http://www.plainblack.com/', + label => 'Plain Black', + }, map => { - surface => 'surface-p12', - buildings => [ - { - x => 0, - y => 0, - image => 'command4', - }, - { - x => -4, - y => 2, - image => 'apples9', - }, - ] - } + surface => 'surface-p12', + buildings => [ + { + x => 0, + y => 0, + image => 'command4', + }, + { + x => -4, + y => 2, + image => 'apples9', + }, + ] + } } ); @@ -339,7 +339,7 @@ sub www_view_ships { elsif ($ship->task ~~ [qw(Defend Orbiting)]) { my $target = Lacuna->db->resultset('Lacuna::DB::Result::Map::Body')->find($ship->foreign_body_id); $out .= sprintf('%s
%s (%d, %d)
', $ship->task, $target->name, $target->x, $target->y, $ship->id, $body_id); - } + } elsif ($ship->task ne 'Docked') { $out .= sprintf('%s
', $ship->task, $ship->id, $body_id); } @@ -366,7 +366,7 @@ sub www_recall_ship { my ($self, $request) = @_; my $ship_id = $request->param('ship_id'); my $ship = Lacuna->db->resultset('Lacuna::DB::Result::Ships')->find($ship_id); - my $target = Lacuna->db->resultset('Lacuna::DB::Result::Map::Body')->find($ship->foreign_body_id); + my $target = Lacuna->db->resultset('Lacuna::DB::Result::Map::Body')->find($ship->foreign_body_id); my $body = $ship->body; $ship->send( @@ -1186,6 +1186,7 @@ sub www_delambert { $scratchpad->{buy_max_price_per_plan} = $request->param('buy_max_price_per_plan'); $scratchpad->{buy_trades_probability} = $request->param('buy_trades_probability'); $scratchpad->{sell_glyph_probability} = $request->param('sell_glyph_probability'); + $scratchpad->{sell_glyph_type} = $request->param('sell_glyph_type'); $scratchpad->{sell_glyph_min_e} = $request->param('sell_glyph_min_e'); $scratchpad->{sell_glyph_max_e} = $request->param('sell_glyph_max_e'); $scratchpad->{sell_glyph_max_batch} = $request->param('sell_glyph_max_batch'); @@ -1216,6 +1217,7 @@ sub www_delambert { $out .= 'Minimum selling price per glyph'; $out .= 'Maximum selling price per glyph'; $out .= 'Maximum number of glyphs to batch in sale'; + $out .= 'Glyphs to sell, comma separate'; $out .= 'Probability of Colony selling plans each hour (%)'; $out .= 'Minimum plan level to sell'; $out .= 'Maximum plan level to sell'; diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 30435b90..51fcf58c 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,3 +1,6 @@ +3.0856: + - Mod: DeLambert now offer glyph trades with all the same type + 3.0855: - Mod: Intelligence Building Level doesn't factor into training costs. - Mod: Burning a spy has more consequences. -- 2.51.2 From 15608eae96914d9f433596b93eb377f99b31b6b4 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 26 Jun 2012 14:06:13 -0600 Subject: [PATCH 10/19] Delete orphaned platforms instead of throwing an exception. --- lib/Lacuna/RPC/Building/SpacePort.pm | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index 5d4be8c2..ccd4897d 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -172,10 +172,15 @@ sub get_ships_for { my $platforms = Lacuna->db->resultset('Lacuna::DB::Result::MiningPlatforms')->search({asteroid_id => $target->id}); while (my $platform = $platforms->next) { my $empire = $platform->planet->empire; - push @{$out{mining_platforms}}, { - empire_id => $empire->id, - empire_name => $empire->name, - }; + if (defined $empire) { + push @{$out{mining_platforms}}, { + empire_id => $empire->id, + empire_name => $empire->name, + }; + } + else { + $platform->delete; + } } } if ( $target->isa('Lacuna::DB::Result::Map::Body::Asteroid') || @@ -183,10 +188,15 @@ sub get_ships_for { my $excavators = Lacuna->db->resultset('Lacuna::DB::Result::Excavators')->search({body_id => $target->id}); while (my $excav = $excavators->next) { my $empire = $excav->planet->empire; - push @{$out{excavators}}, { - empire_id => $empire->id, - empire_name => $empire->name, - }; + if (defined $empire) { + push @{$out{excavators}}, { + empire_id => $empire->id, + empire_name => $empire->name, + }; + } + else { + $excav->delete; + } } } -- 2.51.2 From 3f967ba028b0c69fa3db43ed6a413c0f3be2b52e Mon Sep 17 00:00:00 2001 From: fireartist Date: Wed, 27 Jun 2012 15:01:55 +0100 Subject: [PATCH 11/19] couple of new perl modules missing from the installer --- bin/setup/install-pm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/setup/install-pm.sh b/bin/setup/install-pm.sh index 8f123025..01251686 100755 --- a/bin/setup/install-pm.sh +++ b/bin/setup/install-pm.sh @@ -1,2 +1,2 @@ -cpanm AnyEvent Email::Valid Chat::Envolve Text::CSV_XS Log::Log4perl UUID::Tiny DateTime::Format::MySQL DBIx::Class::TimeStamp JSON::XS JSON Config::JSON Starman JSON::RPC::Dispatcher Log::Any::Adapter Log::Any::Adapter::Log4perl String::Random List::Util::WeightedChoice List::Util List::MoreUtils DateTime Regexp::Common Pod::Simple::HTML File::Copy DateTime::Format::Duration XML::FeedPP SOAP::Amazon::S3 DBD::mysql DBIx::Class JSON::Any DBIx::Class::InflateColumn::Serializer DBIx::Class::DynamicSubclass Memcached::libmemcached Server::Starter IO::Socket::SSL Net::Server::SS::PreFork Email::Stuff Facebook::Graph File::Path namespace::autoclean Clone Plack::Middleware::CrossOrigin Net::Amazon::S3 Path::Class Git::Wrapper Guard Digest::MD5 Digest::HMAC_SHA1 XML::Hash::LX Tie::IxHash LWP::UserAgent XML::Parser SOAP::Lite Business::PayPal::API +cpanm AnyEvent Email::Valid Chat::Envolve Text::CSV_XS Log::Log4perl UUID::Tiny DateTime::Format::MySQL DBIx::Class::TimeStamp JSON::XS JSON Config::JSON Starman JSON::RPC::Dispatcher Log::Any::Adapter Log::Any::Adapter::Log4perl String::Random List::Util::WeightedChoice List::Util List::MoreUtils DateTime Regexp::Common Pod::Simple::HTML File::Copy DateTime::Format::Duration XML::FeedPP SOAP::Amazon::S3 DBD::mysql DBIx::Class JSON::Any DBIx::Class::InflateColumn::Serializer DBIx::Class::DynamicSubclass Memcached::libmemcached Server::Starter IO::Socket::SSL Net::Server::SS::PreFork Email::Stuff Facebook::Graph File::Path namespace::autoclean Clone Plack::Middleware::CrossOrigin Net::Amazon::S3 Path::Class Git::Wrapper Guard Digest::MD5 Digest::HMAC_SHA1 XML::Hash::LX Tie::IxHash LWP::UserAgent XML::Parser SOAP::Lite Business::PayPal::API URI::Encode XML::Hash::LX -- 2.51.2 From fccb3dffa109a55cb2c1a93ebf06f6b63e048968 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Wed, 27 Jun 2012 13:53:36 -0600 Subject: [PATCH 12/19] Stop dumplicate missions from being in a zone. --- bin/add_missions.pl | 18 +++++++++++++++++- lib/Lacuna.pm | 2 +- var/upgrades/3.0856.sql | 3 +++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 var/upgrades/3.0856.sql diff --git a/bin/add_missions.pl b/bin/add_missions.pl index d6ae8c13..036b3ab4 100644 --- a/bin/add_missions.pl +++ b/bin/add_missions.pl @@ -40,13 +40,29 @@ if ($mission ne '' && $zone ne '') { } else { out('Adding missions...'); + out(scalar @mission_files. " mission files"); my @zones = $db->resultset('Lacuna::DB::Result::Map::Body')->search( { empire_id => { '>' => 0 }}, { distinct => 1 })->get_column('zone')->all; foreach my $zone (@zones) { out($zone); + my $current_missions = $db->resultset('Lacuna::DB::Result::Mission')->search( + { zone => "$zone" }); + my @current; + while (my $mission = $current_missions->next) { + push @current, $mission->mission_file_name; + } + out(scalar @current. " current missions"); + my @avail; + for my $mission (@mission_files) { + push @avail, $mission unless ( grep { $mission eq $_ } @current); + } + out(scalar @avail. " to pick from"); + foreach (1..3) { - my $mission = Lacuna::DB::Result::Mission->initialize($zone, $mission_files[rand @mission_files]); + last unless scalar @avail > 0; + my $mission_file = splice(@avail, rand(@avail), 1); + my $mission = Lacuna::DB::Result::Mission->initialize($zone, $mission_file); say $mission->params->get('name'); } } diff --git a/lib/Lacuna.pm b/lib/Lacuna.pm index 37b007d6..14e5941f 100644 --- a/lib/Lacuna.pm +++ b/lib/Lacuna.pm @@ -7,7 +7,7 @@ use Config::JSON; useall __PACKAGE__; -our $VERSION = 3.0855; +our $VERSION = 3.0856; my $config = Config::JSON->new('/data/Lacuna-Server/etc/lacuna.conf'); my $db = Lacuna::DB->connect($config->get('db/dsn'),$config->get('db/username'),$config->get('db/password'), { mysql_enable_utf8 => 1}); diff --git a/var/upgrades/3.0856.sql b/var/upgrades/3.0856.sql new file mode 100644 index 00000000..ffbbb80a --- /dev/null +++ b/var/upgrades/3.0856.sql @@ -0,0 +1,3 @@ + +delete from mission; + -- 2.51.2 From a09781018ce993810cd1bf72144bcf1ca8d52d37 Mon Sep 17 00:00:00 2001 From: Ian Docherty Date: Thu, 28 Jun 2012 02:32:07 -0400 Subject: [PATCH 13/19] Fix Arrival Procedure bug with Excavators/SAWs --- lib/Lacuna/DB/Result/Map/Body/Planet.pm | 36 +++---------------- lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm | 6 +++- 2 files changed, 9 insertions(+), 33 deletions(-) diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 3464e59a..3541ffce 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -486,9 +486,6 @@ has command => ( default => sub { my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::PlanetaryCommand'); - return undef unless defined $building; - $building->body($self); - weaken($building->{_relationship_data}{body}); return $building; }, ); @@ -499,10 +496,6 @@ has oversight => ( default => sub { my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Oversight'); - return undef unless defined $building; - $building->body($self); - weaken($building->{_relationship_data}{body}); - return $building; }, ); @@ -513,9 +506,6 @@ has archaeology => ( default => sub { my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Archaeology'); - return undef unless defined $building; - $building->body($self); - weaken($building->{_relationship_data}{body}); return $building; }, ); @@ -526,9 +516,6 @@ has mining_ministry => ( default => sub { my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Ore::Ministry'); - return undef unless defined $building; - $building->body($self); - weaken($building->{_relationship_data}{body}); return $building; }, ); @@ -539,9 +526,6 @@ has network19 => ( default => sub { my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Network19'); - return undef unless defined $building; - $building->body($self); - weaken($building->{_relationship_data}{body}); return $building; }, ); @@ -552,9 +536,6 @@ has development => ( default => sub { my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Development'); - return undef unless defined $building; - $building->body($self); - weaken($building->{_relationship_data}{body}); return $building; }, ); @@ -565,9 +546,6 @@ has refinery => ( default => sub { my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Ore::Refinery'); - return undef unless defined $building; - $building->body($self); - weaken($building->{_relationship_data}{body}); return $building; }, ); @@ -578,9 +556,6 @@ has spaceport => ( default => sub { my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::SpacePort'); - return undef unless defined $building; - $building->body($self); - weaken($building->{_relationship_data}{body}); return $building; }, ); @@ -591,9 +566,6 @@ has embassy => ( default => sub { my $self = shift; my $building = $self->get_building_of_class('Lacuna::DB::Result::Building::Embassy'); - return undef unless defined $building; - $building->body($self); - weaken($building->{_relationship_data}{body}); return $building; }, ); @@ -818,8 +790,8 @@ sub build_building { sub found_colony { my ($self, $empire) = @_; $self->empire_id($empire->id); - $self->empire($empire); - weaken($self->{_relationship_data}{empire}); +# $self->empire($empire); +# weaken($self->{_relationship_data}{empire}); $self->usable_as_starter_enabled(0); $self->last_tick(DateTime->now); $self->update; @@ -870,8 +842,8 @@ sub convert_to_station { $self->size(3); $self->plots_available(0); $self->empire_id($empire->id); - $self->empire($empire); - weaken($self->{_relationship_data}{empire}); +# $self->empire($empire); +# weaken($self->{_relationship_data}{empire}); $self->usable_as_starter_enabled(0); $self->last_tick(DateTime->now); diff --git a/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm b/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm index c6aa1ef3..18f3e895 100644 --- a/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm +++ b/lib/Lacuna/Role/Ship/Arrive/TriggerDefense.pm @@ -349,7 +349,11 @@ sub saw_stats { my @planet_saws = $body->get_buildings_of_class('Lacuna::DB::Result::Building::SAW'); - my $planet_combat = 0; + # unweaken body + map {$_->body($_->body)} @planet_saws; + + +my $planet_combat = 0; my $cnt = 0; my @defending_saws; for my $saw (@planet_saws) { -- 2.51.2 From 14eb2d2e120d8716789792b27d0102812b1ade8f Mon Sep 17 00:00:00 2001 From: fireartist Date: Thu, 28 Jun 2012 11:05:19 +0100 Subject: [PATCH 14/19] docs didn't match code - also {planet}{ore} clashed with already existing data --- docs/PlanetaryCommand.pod | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/PlanetaryCommand.pod b/docs/PlanetaryCommand.pod index eeeb82b5..59541661 100644 --- a/docs/PlanetaryCommand.pod +++ b/docs/PlanetaryCommand.pod @@ -14,6 +14,20 @@ Command extends the view method to include a C section. "building" : { ... }, "status" : { ... }, "next_colony_cost" : 750000, # the amount of happiness required to settle your next colony + "food" : { + "algae_hour" : 24, + "algae_stored" :1322, + "bean_hour" : 1, + "bean_stored" :42, + .. + }, + "ore" : { + "anthracite_hour" : 333, + "anthracite_stored" : 34444, + "bauxite_hour" : 22, + "bauxite_stored" : 1235, + ... + }, "planet" : { "id" : "id-goes-here", "x" : -4, @@ -49,22 +63,8 @@ Command extends the view method to include a C section. "waste_capacity" : 13000, "water_stored" : 9929, "water_hour" : 295, - "water_capacity" : 51050, - "food" : { - "algae_hour" : 24, - "algae_stored" :1322, - "bean_hour" : 1, - "bean_stored" :42, - .. - } - "ore" : { - "anthracite_hour" : 333, - "anthracite_stored" : 34444, - "bauxite_hour" : 22, - "bauxite_stored" : 1235, - ... - } - } + "water_capacity" : 51050 + } } -- 2.51.2 From 32c4b631f576bb48a963f1904fc2f424e1e685b4 Mon Sep 17 00:00:00 2001 From: fireartist Date: Thu, 28 Jun 2012 13:50:45 +0100 Subject: [PATCH 15/19] new view_incoming_supply_chains API method --- docs/PlanetaryCommand.pod | 35 +++++++++++++++++++ docs/StationCommand.pod | 35 +++++++++++++++++++ .../Result/Building/Module/StationCommand.pm | 6 ++++ .../DB/Result/Building/PlanetaryCommand.pm | 6 ++++ lib/Lacuna/DB/Result/SupplyChain.pm | 21 +++++++++++ lib/Lacuna/RPC/Building/PlanetaryCommand.pm | 4 ++- lib/Lacuna/RPC/Building/StationCommand.pm | 4 ++- lib/Lacuna/Role/IncomingSupplyChains.pm | 25 +++++++++++++ 8 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 lib/Lacuna/Role/IncomingSupplyChains.pm diff --git a/docs/PlanetaryCommand.pod b/docs/PlanetaryCommand.pod index 59541661..5f1f87e1 100644 --- a/docs/PlanetaryCommand.pod +++ b/docs/PlanetaryCommand.pod @@ -97,4 +97,39 @@ A session id. The unique id of the PCC. +=head2 view_incoming_supply_chains ( session_id, building_id ) + +Returns a list of all incoming supply chains feeding this planet. + + { + "status" : { ... }, + "incoming_supply_chains" : [ + { + "id" : "id-goes-here", + "from_body" : { + "id" : "id-goes-here", + "name" : "Mars", + "x" : 0, + "y" : -123, + "image" : "station" + }, + "resource_hour" : 10000000, + "resource_type" : 'water', + "percent_transferred" : 95, + "stalled" : 0, + }, + ... + ] + } + + +=head3 session_id + +A session id. + +=head3 building_id + +The unique id of the PCC. + + =cut diff --git a/docs/StationCommand.pod b/docs/StationCommand.pod index a1c01f8b..d7572180 100644 --- a/docs/StationCommand.pod +++ b/docs/StationCommand.pod @@ -80,4 +80,39 @@ A session id. The unique id of the PCC. +=head2 view_incoming_supply_chains ( session_id, building_id ) + +Returns a list of all incoming supply chains feeding this planet. + + { + "status" : { ... }, + "incoming_supply_chains" : [ + { + "id" : "id-goes-here", + "from_body" : { + "id" : "id-goes-here", + "name" : "Mars", + "x" : 0, + "y" : -123, + "image" : "station" + }, + "resource_hour" : 10000000, + "resource_type" : 'water', + "percent_transferred" : 95, + "stalled" : 0, + }, + ... + ] + } + + +=head3 session_id + +A session id. + +=head3 building_id + +The unique id of the PCC. + + =cut \ No newline at end of file diff --git a/lib/Lacuna/DB/Result/Building/Module/StationCommand.pm b/lib/Lacuna/DB/Result/Building/Module/StationCommand.pm index a4fa7bbf..29e7aa70 100644 --- a/lib/Lacuna/DB/Result/Building/Module/StationCommand.pm +++ b/lib/Lacuna/DB/Result/Building/Module/StationCommand.pm @@ -14,6 +14,12 @@ use constant ore_consumption => 90; use constant water_consumption => 110; use constant energy_consumption => 110; +sub incoming_supply_chains { + my ($self) = @_; + + return Lacuna->db->resultset('Lacuna::DB::Result::SupplyChain')->search({ target_id => $self->body_id }); +} + no Moose; __PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Building/PlanetaryCommand.pm b/lib/Lacuna/DB/Result/Building/PlanetaryCommand.pm index 6cbbeb8b..6bf1bf5e 100644 --- a/lib/Lacuna/DB/Result/Building/PlanetaryCommand.pm +++ b/lib/Lacuna/DB/Result/Building/PlanetaryCommand.pm @@ -65,6 +65,12 @@ around produces_food_items => sub { return $foods; }; +sub incoming_supply_chains { + my ($self) = @_; + + return Lacuna->db->resultset('Lacuna::DB::Result::SupplyChain')->search({ target_id => $self->body_id }); +} + no Moose; __PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/SupplyChain.pm b/lib/Lacuna/DB/Result/SupplyChain.pm index f34a9c72..93730fe7 100644 --- a/lib/Lacuna/DB/Result/SupplyChain.pm +++ b/lib/Lacuna/DB/Result/SupplyChain.pm @@ -40,6 +40,27 @@ sub get_status { }; } +sub get_incoming_status { + my ($self) = @_; + + my $planet = $self->planet; + return { + id => $self->id, + from_body => { + id => $planet->id, + name => $planet->name, + x => $planet->x, + y => $planet->y, + image => $planet->image, + }, + building_id => $self->building_id, + resource_hour => $self->resource_hour, + resource_type => $self->resource_type, + stalled => $self->stalled, + percent_transferred => $self->percent_transferred, + }; +} + no Moose; __PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/RPC/Building/PlanetaryCommand.pm b/lib/Lacuna/RPC/Building/PlanetaryCommand.pm index 5870f9e5..23e8c6fa 100644 --- a/lib/Lacuna/RPC/Building/PlanetaryCommand.pm +++ b/lib/Lacuna/RPC/Building/PlanetaryCommand.pm @@ -5,6 +5,8 @@ use utf8; no warnings qw(uninitialized); extends 'Lacuna::RPC::Building'; +with 'Lacuna::Role::IncomingSupplyChains'; + sub app_url { return '/planetarycommand'; } @@ -54,7 +56,7 @@ sub view_plans { } } -__PACKAGE__->register_rpc_method_names(qw(view_plans)); +__PACKAGE__->register_rpc_method_names(qw(view_plans view_incoming_supply_chains)); diff --git a/lib/Lacuna/RPC/Building/StationCommand.pm b/lib/Lacuna/RPC/Building/StationCommand.pm index b1534039..27c0b4ec 100644 --- a/lib/Lacuna/RPC/Building/StationCommand.pm +++ b/lib/Lacuna/RPC/Building/StationCommand.pm @@ -5,6 +5,8 @@ use utf8; no warnings qw(uninitialized); extends 'Lacuna::RPC::Building'; +with 'Lacuna::Role::IncomingSupplyChains'; + sub app_url { return '/stationcommand'; } @@ -52,7 +54,7 @@ sub view_plans { } } -__PACKAGE__->register_rpc_method_names(qw(view_plans)); +__PACKAGE__->register_rpc_method_names(qw(view_plans view_incoming_supply_chains)); diff --git a/lib/Lacuna/Role/IncomingSupplyChains.pm b/lib/Lacuna/Role/IncomingSupplyChains.pm new file mode 100644 index 00000000..c32fe55a --- /dev/null +++ b/lib/Lacuna/Role/IncomingSupplyChains.pm @@ -0,0 +1,25 @@ +package Lacuna::Role::IncomingSupplyChains; + +use Moose::Role; + + +sub view_incoming_supply_chains { + my ($self, $session_id, $building_id) = @_; + my $empire = $self->get_empire_by_session($session_id); + my $building = $self->get_building($empire, $building_id); + unless ($building) { + confess [1002, "Cannot find that building."]; + } + + my @supply_chains; + my $chains = $building->incoming_supply_chains; + while (my $chain = $chains->next) { + push @supply_chains, $chain->get_incoming_status; + } + return { + status => $self->format_status($empire, $building->body), + supply_chains => \@supply_chains, + }; +} + +1; -- 2.51.2 From bb6f89fb4bd9139a9cf13573f617907433714724 Mon Sep 17 00:00:00 2001 From: fireartist Date: Thu, 28 Jun 2012 13:51:47 +0100 Subject: [PATCH 16/19] remove unused vars - saves a method call --- lib/Lacuna/RPC/Building/Trade.pm | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/Lacuna/RPC/Building/Trade.pm b/lib/Lacuna/RPC/Building/Trade.pm index 8506561f..a53cf7f2 100644 --- a/lib/Lacuna/RPC/Building/Trade.pm +++ b/lib/Lacuna/RPC/Building/Trade.pm @@ -212,7 +212,6 @@ sub view_supply_chains { } my $max_chains = $building->level * 3; - my $body = $building->body; my @supply_chains; my $chains = $building->supply_chains; while (my $chain = $chains->next) { @@ -233,7 +232,6 @@ sub view_waste_chains { unless ($building) { confess [1002, "Cannot find that building."]; } - my $body = $building->body; my @waste_chains; my $chains = $building->waste_chains; while (my $waste_push = $chains->next) { -- 2.51.2 From 069a024185e99a690e339c65a579687041b78d3f Mon Sep 17 00:00:00 2001 From: Ian Docherty Date: Fri, 29 Jun 2012 14:33:05 -0400 Subject: [PATCH 17/19] Added stats to show the total number of glyphs of each type in the game --- bin/summarize_server.pl | 11 ++++++++++- lib/Lacuna/RPC/Stats.pm | 28 ++++++++++++++-------------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/bin/summarize_server.pl b/bin/summarize_server.pl index 0406dfc3..764cbd01 100644 --- a/bin/summarize_server.pl +++ b/bin/summarize_server.pl @@ -7,7 +7,7 @@ use Lacuna::Util qw(format_date); use Getopt::Long; use JSON; use SOAP::Amazon::S3; -use Lacuna::Constants qw(SHIP_TYPES); +use Lacuna::Constants qw(SHIP_TYPES ORE_TYPES); use utf8; @@ -53,6 +53,7 @@ sub generate_overview { my $bodies = $db->resultset('Lacuna::DB::Result::Map::Body'); my @off_limits = $bodies->search({empire_id => {'<' => 2}})->get_column('id')->all; my $ships = $db->resultset('Lacuna::DB::Result::Ships')->search({body_id => { 'not in' => \@off_limits}}); + my $glyphs = $db->resultset('Glyphs')->search({body_id => { 'not in' => \@off_limits}}); my $spies = $db->resultset('Lacuna::DB::Result::Spies')->search({empire_id => { '>' => 1}}); my $buildings = $db->resultset('Lacuna::DB::Result::Building')->search({body_id => { 'not in' => \@off_limits}}); my $empires = $db->resultset('Lacuna::DB::Result::Empire')->search({id => { '>' => 1}}); @@ -166,6 +167,14 @@ sub generate_overview { }; } + # flesh out glyphs + out('Flesh Out Glyphs Stats'); + foreach my $type (ORE_TYPES) { + my $type_rs = $glyphs->search({type => $type}); + my $count = $type_rs->count; + $out{glyphs}{types}{$type} = $count; + } + out('Write To S3'); my $config = Lacuna->config; my $s3 = SOAP::Amazon::S3->new($config->get('access_key'), $config->get('secret_key'), { RaiseError => 1 }); diff --git a/lib/Lacuna/RPC/Stats.pm b/lib/Lacuna/RPC/Stats.pm index 132c6146..70bc8a31 100644 --- a/lib/Lacuna/RPC/Stats.pm +++ b/lib/Lacuna/RPC/Stats.pm @@ -65,10 +65,10 @@ sub alliance_rank { }; } return { - status => $self->format_status($empire), - alliances => \@alliances, - total_alliances => $ranks->pager->total_entries, - page_number => $page_number, + status => $self->format_status($empire), + alliances => \@alliances, + total_alliances => $ranks->pager->total_entries, + page_number => $page_number, }; } @@ -139,10 +139,10 @@ sub empire_rank { }; } return { - status => $self->format_status($empire), - empires => \@empires, - total_empires => $ranks->pager->total_entries, - page_number => $page_number, + status => $self->format_status($empire), + empires => \@empires, + total_empires => $ranks->pager->total_entries, + page_number => $page_number, }; } @@ -196,8 +196,8 @@ sub colony_rank { } } return { - status => $self->format_status($empire), - colonies => \@colonies, + status => $self->format_status($empire), + colonies => \@colonies, }; } @@ -225,8 +225,8 @@ sub spy_rank { } } return { - status => $self->format_status($empire), - spies => \@spies, + status => $self->format_status($empire), + spies => \@spies, }; } @@ -245,8 +245,8 @@ sub weekly_medal_winners { } } return { - status => $self->format_status($empire), - winners => \@winners, + status => $self->format_status($empire), + winners => \@winners, }; } -- 2.51.2 From d2dcc1b7cc15e7bd4efb082aaccfee189f6c5e9f Mon Sep 17 00:00:00 2001 From: Ian Docherty Date: Fri, 29 Jun 2012 14:43:43 -0400 Subject: [PATCH 18/19] Corrected alliance stats population --- lib/Lacuna.pm | 2 +- lib/Lacuna/DB/Result/Log/Alliance.pm | 2 +- var/upgrades/3.0857.sql | 1 + var/www/public/changes.txt | 3 +++ 4 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 var/upgrades/3.0857.sql diff --git a/lib/Lacuna.pm b/lib/Lacuna.pm index 14e5941f..c2475b4b 100644 --- a/lib/Lacuna.pm +++ b/lib/Lacuna.pm @@ -7,7 +7,7 @@ use Config::JSON; useall __PACKAGE__; -our $VERSION = 3.0856; +our $VERSION = 3.0857; my $config = Config::JSON->new('/data/Lacuna-Server/etc/lacuna.conf'); my $db = Lacuna::DB->connect($config->get('db/dsn'),$config->get('db/username'),$config->get('db/password'), { mysql_enable_utf8 => 1}); diff --git a/lib/Lacuna/DB/Result/Log/Alliance.pm b/lib/Lacuna/DB/Result/Log/Alliance.pm index 9eeeab39..76b70b8a 100644 --- a/lib/Lacuna/DB/Result/Log/Alliance.pm +++ b/lib/Lacuna/DB/Result/Log/Alliance.pm @@ -16,7 +16,7 @@ __PACKAGE__->add_columns( influence => { data_type => 'int', is_nullable => 0 }, influence_rank => { data_type => 'int', is_nullable => 0 }, colony_count => { data_type => 'int', is_nullable => 0 }, - population => { data_type => 'int', size => 11, is_nullable => 0 }, + population => { data_type => 'bigint', is_nullable => 0 }, population_rank => { data_type => 'int', is_nullable => 0 }, average_empire_size => { data_type => 'bigint', is_nullable => 0 }, average_empire_size_rank => { data_type => 'int', is_nullable => 0 }, diff --git a/var/upgrades/3.0857.sql b/var/upgrades/3.0857.sql new file mode 100644 index 00000000..99fbd50e --- /dev/null +++ b/var/upgrades/3.0857.sql @@ -0,0 +1 @@ +alter table alliance_log change population population bigint not null; diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 51fcf58c..db941938 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,3 +1,6 @@ +3.0857: + - Add: Number of glyphs of each type are now shown in Stats/General + 3.0856: - Mod: DeLambert now offer glyph trades with all the same type -- 2.51.2 From 113d8c515f283a47da0c3da1cdae5436b358b8d9 Mon Sep 17 00:00:00 2001 From: Ian Docherty Date: Sun, 1 Jul 2012 00:09:57 -0400 Subject: [PATCH 19/19] Bumped version and added changes.txt --- lib/Lacuna.pm | 2 +- var/www/public/changes.txt | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/Lacuna.pm b/lib/Lacuna.pm index c2475b4b..566cc0b4 100644 --- a/lib/Lacuna.pm +++ b/lib/Lacuna.pm @@ -7,7 +7,7 @@ use Config::JSON; useall __PACKAGE__; -our $VERSION = 3.0857; +our $VERSION = 3.0858; my $config = Config::JSON->new('/data/Lacuna-Server/etc/lacuna.conf'); my $db = Lacuna::DB->connect($config->get('db/dsn'),$config->get('db/username'),$config->get('db/password'), { mysql_enable_utf8 => 1}); diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index db941938..4b60b9d0 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,3 +1,9 @@ +3.0858: + - Add: Resources per hour for all food/ore types now shown in PCC and SCC + - Add: PCC and SCC now show all incoming supply chains + - Fix: Planet plan and starmap should now scroll correctly in IE9 + - Mod: Supply chain type can now be modified + 3.0857: - Add: Number of glyphs of each type are now shown in Stats/General -- 2.51.2