From a3e527ccf66488049d27f8f95df036c68d403826 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Thu, 29 Dec 2011 21:42:46 -0700 Subject: [PATCH 01/28] Beginning work on excavs. --- lib/Lacuna/DB/Result/Building/Archaeology.pm | 73 +++++++++++++++++++ lib/Lacuna/DB/Result/Map/Body/Planet.pm | 12 +++ .../Role/Ship/Arrive/DeployExcavator.pm | 63 ++++++++++++++++ 3 files changed, 148 insertions(+) create mode 100644 lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm diff --git a/lib/Lacuna/DB/Result/Building/Archaeology.pm b/lib/Lacuna/DB/Result/Building/Archaeology.pm index b0c021f5..baefdb90 100644 --- a/lib/Lacuna/DB/Result/Building/Archaeology.pm +++ b/lib/Lacuna/DB/Result/Building/Archaeology.pm @@ -66,6 +66,79 @@ sub get_ores_available_for_processing { return \%available; } +sub max_excavators { + my $self = shift; + return ($self->level); +} + +sub add_ship { + my ($self, $ship) = @_; + $ship->task('Excavating'); + $ship->update; + $self->recalc_excavating; + return $self; +} + +sub send_ship_home { + my ($self, $body, $ship) = @_; + $ship->send( + target => $body, + direction => 'in', + task => 'Travelling', + ); + $self->recalc_excavating; + return $self; +} + +sub excavators { + my $self = shift; + return Lacuna->db->resultset('Lacuna::DB::Result::Excavators')->search({ planet_id => $self->body_id }); +} + +sub can_add_excavator { + my ($self, $body, $on_arrival) = @_; + + # excavator count for archaeology + my $count = $self->excavators->count; + unless ($on_arrival) { + $count += Lacuna->db->resultset('Lacuna::DB::Result::Ships') + ->search({type=>'excavators', task=>'Travelling',body_id=>$self->body_id})->count; + } + if ($count >= $self->max_excavators) { + confess [1009, 'Already at the maximum number of platforms allowed at this Ministry level.']; + } + + # body count (Not sure if we want to implement this) +# $count = Lacuna->db->resultset('Lacuna::DB::Result::Excavators') +# ->search({ body_id => $body->id })->count; +# unless ($on_arrival) { +# $count += Lacuna->db->resultset('Lacuna::DB::Result::Ships') +# ->search( { +# type=>'excavators', +# foreign_body_id => $body->id, +# task=>'Travelling', +# body_id=>$self->body_id +# })->count; +# } +# if ($body->size <= $count) { +# confess [1010, $body->name.' cannot support any additional excavators.']; +# } + return 1; +} + +sub add_excavator { + my ($self, $body, $speed) = @_; + Lacuna->db->resultset('Lacuna::DB::Result::Excavators')->new({ + planet_id => $self->body_id, + planet => $self->body, + body_id => $asteroid->id, + body => $asteroid, + speed => $speed, + })->insert; + $self->recalc_excavating; + return $self; +} + sub can_search_for_glyph { my ($self, $ore) = @_; unless ($self->level > 0) { diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 3c835092..6b6edada 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -378,6 +378,18 @@ has oversight => ( }, ); +has archaeology => ( + 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); + return $building; + }, +); + has mining_ministry => ( is => 'rw', lazy => 1, diff --git a/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm b/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm new file mode 100644 index 00000000..471f8194 --- /dev/null +++ b/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm @@ -0,0 +1,63 @@ +package Lacuna::Role::Ship::Arrive::DeployExcavator.pm + +use strict; +use Moose::Role; + +after handle_arrival_procedures => sub { + my ($self) = @_; + + # we're coming home + return if ($self->direction eq 'in'); + + # do we have archaeology of level 15 or greater, if not, turn around + my $body = $self->body; + my $archaeology = $body->archaeology; + return unless ((defined $archaeology) && ($archaeology->level >= 15)); + + # can we deploy a excavator + my $empire = $body->empire; + my $foreign_body = $self->foreign_body; + my $can = eval{$ministry->can_add_platform($foreign_body, 1)}; + my $reason = $@; + + # yes, we can + if ($can && !$reason) { + $ministry->add_platform($foreign_body)->update; + $empire->send_predefined_message( + tags => ['Alert'], + filename => 'mining_platform_deployed.txt', + params => [$body->id, $body->name, $foreign_body->x, $foreign_body->y, $foreign_body->name, $self->name], + ); + $self->delete; + my $type = ref $foreign_body; + $type =~ s/^.*::(\w\d+)$/$1/; + $empire->add_medal($type); + confess [-1]; + } + + # no we can't + else { + my $message = (ref $reason eq 'ARRAY') ? $reason->[1] : 'We have encountered a glitch.'; + $empire->send_predefined_message( + tags => ['Alert'], + filename => 'cannot_deploy_mining_platform.txt', + params => [$message, $foreign_body->x, $foreign_body->y, $foreign_body->name, $body->id, $body->name, $self->name], + ); + } +}; + +after can_send_to_target => sub { + my ($self, $target) = @_; + my $ministry = $self->body->mining_ministry; + confess [1013, 'Cannot control platforms without a Mining Ministry.'] unless (defined $ministry); + $ministry->can_add_platform($target); + if ($target->star->station_id) { + if ($target->star->station->laws->search({type => 'MembersOnlyMiningRights'})->count) { + unless ($target->star->station->alliance_id == $self->body->empire->alliance_id) { + confess [1010, 'Only '.$target->star->station->alliance->name.' members can mine asteroids in the jurisdiction of the space station.']; + } + } + } +}; + +1; -- 2.51.2 From f22722766a93b28dc63ab93e2739878460710c3c Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 10 Jan 2012 23:10:07 -0700 Subject: [PATCH 02/28] Getting them more platform like. --- lib/Lacuna/DB/Result/Building/Archaeology.pm | 12 +++++++-- lib/Lacuna/DB/Result/Ships/Excavator.pm | 25 ++++++++++++------- .../Role/Ship/Arrive/DeployExcavator.pm | 23 +++++++++-------- var/messages/cannot_deploy_excavator.txt | 7 ++++++ var/messages/excavator_deployed.txt | 9 +++++++ 5 files changed, 54 insertions(+), 22 deletions(-) create mode 100644 var/messages/cannot_deploy_excavator.txt create mode 100644 var/messages/excavator_deployed.txt diff --git a/lib/Lacuna/DB/Result/Building/Archaeology.pm b/lib/Lacuna/DB/Result/Building/Archaeology.pm index baefdb90..136ab427 100644 --- a/lib/Lacuna/DB/Result/Building/Archaeology.pm +++ b/lib/Lacuna/DB/Result/Building/Archaeology.pm @@ -68,6 +68,7 @@ sub get_ores_available_for_processing { sub max_excavators { my $self = shift; + return 0 if ($self->level < 15); return ($self->level); } @@ -105,10 +106,16 @@ sub can_add_excavator { ->search({type=>'excavators', task=>'Travelling',body_id=>$self->body_id})->count; } if ($count >= $self->max_excavators) { - confess [1009, 'Already at the maximum number of platforms allowed at this Ministry level.']; + confess [1009, 'Already at the maximum number of excavators allowed at this Archaeology level.']; } - # body count (Not sure if we want to implement this) +# Allowed one per empire per asteroid. + $count = Lacuna->db->resultset('Lacuna::DB::Result::Excavators') + ->search({ body_id => $body->id, empire_id => $self->empire->id; })->count; + if ($count) { + confess [1010, $body-name.' already has an excavator from your empire.']; + } +# body count (Not sure if we want to implement this) (If we decide to go with size) # $count = Lacuna->db->resultset('Lacuna::DB::Result::Excavators') # ->search({ body_id => $body->id })->count; # unless ($on_arrival) { @@ -132,6 +139,7 @@ sub add_excavator { planet_id => $self->body_id, planet => $self->body, body_id => $asteroid->id, + empire_id => $self->empire->id; body => $asteroid, speed => $speed, })->insert; diff --git a/lib/Lacuna/DB/Result/Ships/Excavator.pm b/lib/Lacuna/DB/Result/Ships/Excavator.pm index 4da987a8..9b716716 100644 --- a/lib/Lacuna/DB/Result/Ships/Excavator.pm +++ b/lib/Lacuna/DB/Result/Ships/Excavator.pm @@ -6,19 +6,26 @@ no warnings qw(uninitialized); extends 'Lacuna::DB::Result::Ships'; use constant prereq => { class=> 'Lacuna::DB::Result::Building::Archaeology', level => 15 }; -use constant base_food_cost => 400; -use constant base_water_cost => 1000; -use constant base_energy_cost => 8500; -use constant base_ore_cost => 11000; -use constant base_time_cost => 20000; -use constant base_waste_cost => 1200; -use constant base_speed => 1800; +# use constant base_food_cost => 400; +# use constant base_water_cost => 1000; +# use constant base_energy_cost => 8500; +# use constant base_ore_cost => 11000; +# use constant base_time_cost => 20000; +# use constant base_waste_cost => 1200; +# use constant base_speed => 1800; +use constant base_food_cost => 100000; +use constant base_water_cost => 200000; +use constant base_energy_cost => 500000; +use constant base_ore_cost => 900000; +use constant base_time_cost => 8 * 60 * 60; +use constant base_waste_cost => 300000; +use constant base_speed => 1000; use constant base_stealth => 0; use constant base_hold_size => 0; use constant build_tags => ['Exploration']; -with "Lacuna::Role::Ship::Send::Body"; -with "Lacuna::Role::Ship::Arrive::Excavate"; +with "Lacuna::Role::Ship::Send::Asteroid"; +with "Lacuna::Role::Ship::Arrive::DeployExcavator"; no Moose; __PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm b/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm index 471f8194..d5e463d9 100644 --- a/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm +++ b/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm @@ -17,21 +17,21 @@ after handle_arrival_procedures => sub { # can we deploy a excavator my $empire = $body->empire; my $foreign_body = $self->foreign_body; - my $can = eval{$ministry->can_add_platform($foreign_body, 1)}; + my $can = eval{$archaeology->can_add_excavator($foreign_body, 1)}; my $reason = $@; # yes, we can if ($can && !$reason) { - $ministry->add_platform($foreign_body)->update; + $archaeology->add_excavator($foreign_body)->update; $empire->send_predefined_message( tags => ['Alert'], - filename => 'mining_platform_deployed.txt', + filename => 'excavator_deployed.txt', params => [$body->id, $body->name, $foreign_body->x, $foreign_body->y, $foreign_body->name, $self->name], ); $self->delete; - my $type = ref $foreign_body; - $type =~ s/^.*::(\w\d+)$/$1/; - $empire->add_medal($type); +# my $type = ref $foreign_body; +# $type =~ s/^.*::(\w\d+)$/$1/; +# $empire->add_medal($type); confess [-1]; } @@ -40,7 +40,7 @@ after handle_arrival_procedures => sub { my $message = (ref $reason eq 'ARRAY') ? $reason->[1] : 'We have encountered a glitch.'; $empire->send_predefined_message( tags => ['Alert'], - filename => 'cannot_deploy_mining_platform.txt', + filename => 'cannot_deploy_excavator.txt', params => [$message, $foreign_body->x, $foreign_body->y, $foreign_body->name, $body->id, $body->name, $self->name], ); } @@ -48,13 +48,14 @@ after handle_arrival_procedures => sub { after can_send_to_target => sub { my ($self, $target) = @_; - my $ministry = $self->body->mining_ministry; - confess [1013, 'Cannot control platforms without a Mining Ministry.'] unless (defined $ministry); - $ministry->can_add_platform($target); + my $archaeology = $self->body->archaeology; + confess [1013, 'Cannot control excavators without an Archaeology.'] unless (defined $archaeology); + confess [1013, 'Your Archaeology Ministry must be level 15 or higher in order to send excavators.'] unless ($archaeology->level >= 15); + $archaeology->can_add_excavator($target); if ($target->star->station_id) { if ($target->star->station->laws->search({type => 'MembersOnlyMiningRights'})->count) { unless ($target->star->station->alliance_id == $self->body->empire->alliance_id) { - confess [1010, 'Only '.$target->star->station->alliance->name.' members can mine asteroids in the jurisdiction of the space station.']; + confess [1010, 'Only '.$target->star->station->alliance->name.' members can excavate asteroids in the jurisdiction of the space station.']; } } } diff --git a/var/messages/cannot_deploy_excavator.txt b/var/messages/cannot_deploy_excavator.txt new file mode 100644 index 00000000..83b29015 --- /dev/null +++ b/var/messages/cannot_deploy_excavator.txt @@ -0,0 +1,7 @@ +Excavator Returning +~~~ +%s The ship is on its way back from {Starmap %s %s %s} to {Planet %s %s} now. + +Regards, + +%s Commander diff --git a/var/messages/excavator_deployed.txt b/var/messages/excavator_deployed.txt new file mode 100644 index 00000000..e3f169a4 --- /dev/null +++ b/var/messages/excavator_deployed.txt @@ -0,0 +1,9 @@ +Mining Platform Deployed +~~~ +The Excavator from {Planet %s %s} has deployed on {Starmap %s %s %s}. +It is operational and awaiting cargo ships. +It is now operational and will start sending back it's results. + +Regards, + +%s Commander -- 2.51.2 From e4927cf1f4869cef203bf43de53f9ea07a3a39e6 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Wed, 18 Jan 2012 21:55:57 -0700 Subject: [PATCH 03/28] More excav work. --- lib/Lacuna/DB/Result/Building/Archaeology.pm | 70 +++++++++++-------- lib/Lacuna/DB/Result/ExcavatorSite.pm | 19 +++++ lib/Lacuna/RPC/Building/Archaeology.pm | 37 +++++++++- .../Role/Ship/Arrive/DeployExcavator.pm | 64 ++++++++--------- 4 files changed, 126 insertions(+), 64 deletions(-) create mode 100644 lib/Lacuna/DB/Result/ExcavatorSite.pm diff --git a/lib/Lacuna/DB/Result/Building/Archaeology.pm b/lib/Lacuna/DB/Result/Building/Archaeology.pm index 136ab427..28d3ff6b 100644 --- a/lib/Lacuna/DB/Result/Building/Archaeology.pm +++ b/lib/Lacuna/DB/Result/Building/Archaeology.pm @@ -91,6 +91,7 @@ sub send_ship_home { return $self; } + sub excavators { my $self = shift; return Lacuna->db->resultset('Lacuna::DB::Result::Excavators')->search({ planet_id => $self->body_id }); @@ -104,49 +105,46 @@ sub can_add_excavator { unless ($on_arrival) { $count += Lacuna->db->resultset('Lacuna::DB::Result::Ships') ->search({type=>'excavators', task=>'Travelling',body_id=>$self->body_id})->count; - } - if ($count >= $self->max_excavators) { - confess [1009, 'Already at the maximum number of excavators allowed at this Archaeology level.']; - } + } + if ($count >= $self->max_excavators) { + confess [1009, 'Already at the maximum number of excavators allowed at this Archaeology level.']; + } # Allowed one per empire per asteroid. - $count = Lacuna->db->resultset('Lacuna::DB::Result::Excavators') - ->search({ body_id => $body->id, empire_id => $self->empire->id; })->count; - if ($count) { - confess [1010, $body-name.' already has an excavator from your empire.']; - } -# body count (Not sure if we want to implement this) (If we decide to go with size) -# $count = Lacuna->db->resultset('Lacuna::DB::Result::Excavators') -# ->search({ body_id => $body->id })->count; -# unless ($on_arrival) { -# $count += Lacuna->db->resultset('Lacuna::DB::Result::Ships') -# ->search( { -# type=>'excavators', -# foreign_body_id => $body->id, -# task=>'Travelling', -# body_id=>$self->body_id -# })->count; -# } -# if ($body->size <= $count) { -# confess [1010, $body->name.' cannot support any additional excavators.']; -# } - return 1; + $count = Lacuna->db->resultset('Lacuna::DB::Result::Excavators') + ->search({ body_id => $body->id, empire_id => $self->empire->id; })->count; + unless ($on_arrival) { + $count += Lacuna->db->resultset('Lacuna::DB::Result::Ships') + ->search( { + type=>'excavators', + foreign_body_id => $body->id, + task=>'Travelling', + body_id=>$self->body_id + })->count; + } + if ($count) { + confess [1010, $body-name.' already has an excavator from your empire (or one is on the way.']; + } + return 1; } sub add_excavator { my ($self, $body, $speed) = @_; Lacuna->db->resultset('Lacuna::DB::Result::Excavators')->new({ planet_id => $self->body_id, - planet => $self->body, - body_id => $asteroid->id, - empire_id => $self->empire->id; - body => $asteroid, - speed => $speed, + asteroid_id => $asteroid->id, +# speed => $speed, })->insert; $self->recalc_excavating; return $self; } +sub remove_excavator { + my ($self, $platform) = @_; + $platform->delete; + return $self; +} + sub can_search_for_glyph { my ($self, $ore) = @_; unless ($self->level > 0) { @@ -219,7 +217,7 @@ my %recipies = ( trona => { kerogen => { monazite => { - plan => 'Lacuna::DB::Result::Building::Permanent::MassadsHenge', +# plan => 'Lacuna::DB::Result::Building::Permanent::MassadsHenge', }, }, }, @@ -476,5 +474,15 @@ sub make_plan { return $self->body->add_plan($match->{plan}, 1); } +before 'can_downgrade' => sub { + my $self = shift; + if ($self->excavators->count > ($self->level - 1)) { + confess [1013, 'You must abandon one of your Excavator Sites before you can downgrade the Archaeology Ministry.']; + } + if ($self->excavators->count && ($self->level -1) < 15 ) { + confess [1013, 'You can not have any Excavator Sites if you are to downgrade your Archaeology Ministry below 15.']; + } +} + no Moose; __PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/ExcavatorSite.pm b/lib/Lacuna/DB/Result/ExcavatorSite.pm new file mode 100644 index 00000000..a2921f84 --- /dev/null +++ b/lib/Lacuna/DB/Result/ExcavatorSite.pm @@ -0,0 +1,19 @@ +package Lacuna::DB::Result::ExcavatorSite; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result'; + +__PACKAGE__->table('excavators'); +__PACKAGE__->add_columns( + planet_id => { data_type => 'int', size => 11, is_nullable => 0 }, + asteroid_id => { data_type => 'int', size => 11, is_nullable => 0 }, +); + +__PACKAGE__->belongs_to('asteroid', 'Lacuna::DB::Result::Map::Body', 'asteroid_id'); +__PACKAGE__->belongs_to('planet', 'Lacuna::DB::Result::Map::Body', 'planet_id'); + + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/RPC/Building/Archaeology.pm b/lib/Lacuna/RPC/Building/Archaeology.pm index 67539601..a80279a8 100644 --- a/lib/Lacuna/RPC/Building/Archaeology.pm +++ b/lib/Lacuna/RPC/Building/Archaeology.pm @@ -93,8 +93,43 @@ sub subsidize_search { return $self->view($empire, $building); } +sub view_excavators { + my ($self, $session_id, $building_id) = @_; + my $empire = $self->get_empire_by_session($session_id); + my $building = $self->get_building($empire, $building_id); + my $excavators = $building->excavators; + my @sites; + while (my $excav = $excavators->next) { + push @sites, { + id => $platform->id, + asteroid => $platform->asteroid->get_status, + }; + } + return { + platforms => \@sites, + max_platforms => $building->max_platforms, + status => $self->format_status($empire, $building->body), + }; +} + +sub abandon_excavator { + my ($self, $session_id, $building_id, $site_id) = @_; + my $empire = $self->get_empire_by_session($session_id); + my $building = $self->get_building($empire, $building_id); + my $site = Lacuna->db->resultset('Lacuna::DB::Result::Excavators')->find($site_id); + unless (defined $site) { + confess [1002, "Excavator Site not found."]; + } + unless ($site->planet_id eq $building->body_id) { + confess [1013, "You can't abandon an excavator site that is not yours."]; + } + $building->remove_excavator($site); + return { + status => $self->format_status($empire, $building->body), + }; +} -__PACKAGE__->register_rpc_method_names(qw(get_ores_available_for_processing assemble_glyphs search_for_glyph get_glyphs subsidize_search)); +__PACKAGE__->register_rpc_method_names(qw(get_ores_available_for_processing assemble_glyphs search_for_glyph get_glyphs subsidize_search view_excavators abandon_excavator)); no Moose; diff --git a/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm b/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm index d5e463d9..6d8351b8 100644 --- a/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm +++ b/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm @@ -4,46 +4,45 @@ use strict; use Moose::Role; after handle_arrival_procedures => sub { - my ($self) = @_; + my ($self) = @_; - # we're coming home - return if ($self->direction eq 'in'); + # we're coming home + return if ($self->direction eq 'in'); - # do we have archaeology of level 15 or greater, if not, turn around - my $body = $self->body; - my $archaeology = $body->archaeology; - return unless ((defined $archaeology) && ($archaeology->level >= 15)); + # do we have archaeology of level 15 or greater, if not, turn around + my $body = $self->body; + my $archaeology = $body->archaeology; + return unless ((defined $archaeology) && ($archaeology->level >= 15)); - # can we deploy a excavator - my $empire = $body->empire; - my $foreign_body = $self->foreign_body; - my $can = eval{$archaeology->can_add_excavator($foreign_body, 1)}; - my $reason = $@; + # can we deploy a excavator + my $empire = $body->empire; + my $foreign_body = $self->foreign_body; + my $can = eval{$archaeology->can_add_excavator($foreign_body, 1)}; + my $reason = $@; - # yes, we can - if ($can && !$reason) { - $archaeology->add_excavator($foreign_body)->update; - $empire->send_predefined_message( - tags => ['Alert'], - filename => 'excavator_deployed.txt', - params => [$body->id, $body->name, $foreign_body->x, $foreign_body->y, $foreign_body->name, $self->name], - ); - $self->delete; + # yes, we can + if ($can && !$reason) { + $archaeology->add_excavator($foreign_body)->update; + $empire->send_predefined_message( + tags => ['Alert'], + filename => 'excavator_deployed.txt', + params => [$body->id, $body->name, $foreign_body->x, $foreign_body->y, $foreign_body->name, $self->name], + ); + $self->delete; # my $type = ref $foreign_body; # $type =~ s/^.*::(\w\d+)$/$1/; # $empire->add_medal($type); confess [-1]; - } - - # no we can't - else { - my $message = (ref $reason eq 'ARRAY') ? $reason->[1] : 'We have encountered a glitch.'; - $empire->send_predefined_message( - tags => ['Alert'], - filename => 'cannot_deploy_excavator.txt', - params => [$message, $foreign_body->x, $foreign_body->y, $foreign_body->name, $body->id, $body->name, $self->name], - ); - } + } + # no we can't + else { + my $message = (ref $reason eq 'ARRAY') ? $reason->[1] : 'We have encountered a glitch.'; + $empire->send_predefined_message( + tags => ['Alert'], + filename => 'cannot_deploy_excavator.txt', + params => [$message, $foreign_body->x, $foreign_body->y, $foreign_body->name, $body->id, $body->name, $self->name], + ); + } }; after can_send_to_target => sub { @@ -52,6 +51,7 @@ after can_send_to_target => sub { confess [1013, 'Cannot control excavators without an Archaeology.'] unless (defined $archaeology); confess [1013, 'Your Archaeology Ministry must be level 15 or higher in order to send excavators.'] unless ($archaeology->level >= 15); $archaeology->can_add_excavator($target); +# Will need to make this only pertaining to excavation later. if ($target->star->station_id) { if ($target->star->station->laws->search({type => 'MembersOnlyMiningRights'})->count) { unless ($target->star->station->alliance_id == $self->body->empire->alliance_id) { -- 2.51.2 From f8a24dec4b182312e0d404f54d703dbb3c8b818a Mon Sep 17 00:00:00 2001 From: lemming552 Date: Mon, 23 Jan 2012 18:08:30 -0700 Subject: [PATCH 04/28] Fixed multiple syntax errors. --- lib/Lacuna/DB/Result/Building/Archaeology.pm | 13 +++++++++---- lib/Lacuna/RPC/Building/Archaeology.pm | 8 ++++---- lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/Lacuna/DB/Result/Building/Archaeology.pm b/lib/Lacuna/DB/Result/Building/Archaeology.pm index ba36fbd9..19d189dd 100644 --- a/lib/Lacuna/DB/Result/Building/Archaeology.pm +++ b/lib/Lacuna/DB/Result/Building/Archaeology.pm @@ -112,7 +112,7 @@ sub can_add_excavator { # Allowed one per empire per asteroid. $count = Lacuna->db->resultset('Lacuna::DB::Result::Excavators') - ->search({ body_id => $body->id, empire_id => $self->empire->id; })->count; + ->search({ body_id => $body->id, empire_id => $self->empire->id })->count; unless ($on_arrival) { $count += Lacuna->db->resultset('Lacuna::DB::Result::Ships') ->search( { @@ -123,7 +123,7 @@ sub can_add_excavator { })->count; } if ($count) { - confess [1010, $body-name.' already has an excavator from your empire (or one is on the way.']; + confess [1010, $body->name.' already has an excavator from your empire (or one is on the way.']; } return 1; } @@ -132,7 +132,7 @@ sub add_excavator { my ($self, $body, $speed) = @_; Lacuna->db->resultset('Lacuna::DB::Result::Excavators')->new({ planet_id => $self->body_id, - asteroid_id => $asteroid->id, + asteroid_id => $body->id, # speed => $speed, })->insert; $self->recalc_excavating; @@ -227,7 +227,12 @@ before 'can_downgrade' => sub { if ($self->excavators->count && ($self->level -1) < 15 ) { confess [1013, 'You can not have any Excavator Sites if you are to downgrade your Archaeology Ministry below 15.']; } -} +}; + +after 'downgrade' => sub { + my $self = shift; + $self->recalc_excavating; +}; no Moose; __PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/RPC/Building/Archaeology.pm b/lib/Lacuna/RPC/Building/Archaeology.pm index a80279a8..38867e56 100644 --- a/lib/Lacuna/RPC/Building/Archaeology.pm +++ b/lib/Lacuna/RPC/Building/Archaeology.pm @@ -101,13 +101,13 @@ sub view_excavators { my @sites; while (my $excav = $excavators->next) { push @sites, { - id => $platform->id, - asteroid => $platform->asteroid->get_status, + id => $excav->id, + asteroid => $excav->asteroid->get_status, }; } return { - platforms => \@sites, - max_platforms => $building->max_platforms, + excavators => \@sites, + max_excavators => $building->max_excavators, status => $self->format_status($empire, $building->body), }; } diff --git a/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm b/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm index 6d8351b8..672de18a 100644 --- a/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm +++ b/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm @@ -1,4 +1,4 @@ -package Lacuna::Role::Ship::Arrive::DeployExcavator.pm +package Lacuna::Role::Ship::Arrive::DeployExcavator; use strict; use Moose::Role; -- 2.51.2 From 7282711bdca405cdd460427bb1c71be7140b9ea5 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Thu, 26 Jan 2012 08:45:53 -0700 Subject: [PATCH 05/28] Sending excavs enabled to proper targets. --- lib/Lacuna/DB/Result/Building/Archaeology.pm | 107 ++++++++++----- lib/Lacuna/DB/Result/ExcavatorSite.pm | 19 --- lib/Lacuna/DB/Result/Excavators.pm | 19 +++ lib/Lacuna/DB/Result/Map/Body/Planet.pm | 7 +- lib/Lacuna/DB/Result/Ships/Excavator.pm | 2 +- lib/Lacuna/RPC/Building/Archaeology.pm | 5 +- lib/Lacuna/RPC/Building/SpacePort.pm | 14 +- .../Role/Ship/Arrive/DeployExcavator.pm | 3 +- lib/Lacuna/Role/Ship/Arrive/Excavate.pm | 127 ------------------ .../Role/Ship/Send/AsteroidAndUninhabited.pm | 13 ++ var/messages/excavator_deployed.txt | 3 +- 11 files changed, 125 insertions(+), 194 deletions(-) delete mode 100644 lib/Lacuna/DB/Result/ExcavatorSite.pm create mode 100644 lib/Lacuna/DB/Result/Excavators.pm delete mode 100644 lib/Lacuna/Role/Ship/Arrive/Excavate.pm create mode 100644 lib/Lacuna/Role/Ship/Send/AsteroidAndUninhabited.pm diff --git a/lib/Lacuna/DB/Result/Building/Archaeology.pm b/lib/Lacuna/DB/Result/Building/Archaeology.pm index 19d189dd..cd290cbe 100644 --- a/lib/Lacuna/DB/Result/Building/Archaeology.pm +++ b/lib/Lacuna/DB/Result/Building/Archaeology.pm @@ -69,26 +69,60 @@ sub get_ores_available_for_processing { sub max_excavators { my $self = shift; return 0 if ($self->level < 15); - return ($self->level); + return ($self->level - 14); } -sub add_ship { - my ($self, $ship) = @_; - $ship->task('Excavating'); - $ship->update; - $self->recalc_excavating; - return $self; -} +# sub add_ship { +# my ($self, $ship) = @_; +# $ship->task('Excavating'); +# $ship->update; +# $self->recalc_excavating; +# return $self; +# } + +# sub send_ship_home { +# my ($self, $body, $ship) = @_; +# $ship->send( +# target => $body, +# direction => 'in', +# task => 'Travelling', +# ); +# $self->recalc_excavating; +# return $self; +# } + +sub run_excavators { + my $self = shift; -sub send_ship_home { - my ($self, $body, $ship) = @_; - $ship->send( - target => $body, - direction => 'in', - task => 'Travelling', - ); - $self->recalc_excavating; - return $self; + +# Run thru excavators for each arch. +# 1) See what they find +# Glyph, Plan, resource, (artifact), something bad +# 2) Glyph +# a) Chances based on ore content. (total ore)/10,000 * level +# b) Each ore has at least 1%, but proportional to content. +# 3) Plan % equal to level/5 +# 1+floor(lvl/6) possible +# 5% something special, 50% chance of 1+0, otherwise rand(1,lvl/6) +# 4) Resource Lvl * 2 percent chance +# 5) If glyph building on uninhabited excav planet +# Chance of grabbing a lvl 1 plan of it (no dillon or e-veins) +# Chance of 1+X up to level of arch/2+1 or level of building +# If lvl 1 (50% chance of destroying building, or reduce by 1 level) +# If 1+x, destroy building +# 6) Ancient Horror released. All cases, excavator destroyed. 1% chance +# a) Ph'nglui Mglw'nafh Cthulhu R'lyeh wgah'nagi fhtagn. +# b) Klaatu Barada Ni*cough* +# c) Brass Doors +# d) flutes + + my $level = $self->level; +# Do once for arch + if ($level > 14) { + my $excavators = $self->excavators; + while (my $excav = $excavators->next) { + } + } } @@ -102,46 +136,51 @@ sub can_add_excavator { # excavator count for archaeology my $count = $self->excavators->count; +# print "Checking is more than $count are travelling.\n"; unless ($on_arrival) { $count += Lacuna->db->resultset('Lacuna::DB::Result::Ships') - ->search({type=>'excavators', task=>'Travelling',body_id=>$self->body_id})->count; + ->search({type=>'excavator', task=>'Travelling',body_id=>$self->body_id})->count; } - if ($count >= $self->max_excavators) { + my $max_e = $self->max_excavators; +# print "Count $count with max of $max_e\n"; + if ($count >= $max_e) { confess [1009, 'Already at the maximum number of excavators allowed at this Archaeology level.']; } -# Allowed one per empire per asteroid. +# Allowed one per empire per body. $count = Lacuna->db->resultset('Lacuna::DB::Result::Excavators') - ->search({ body_id => $body->id, empire_id => $self->empire->id })->count; + ->search({ body_id => $body->id, empire_id => $self->body->empire->id })->count; +# print "$count on body.\n"; unless ($on_arrival) { $count += Lacuna->db->resultset('Lacuna::DB::Result::Ships') ->search( { - type=>'excavators', + type=>'excavator', foreign_body_id => $body->id, task=>'Travelling', body_id=>$self->body_id })->count; } +# print "$count on body or on way.\n"; if ($count) { - confess [1010, $body->name.' already has an excavator from your empire (or one is on the way.']; + confess [1010, $body->name.' already has an excavator from your empire or one is on the way.']; } return 1; } sub add_excavator { - my ($self, $body, $speed) = @_; + my ($self, $body) = @_; Lacuna->db->resultset('Lacuna::DB::Result::Excavators')->new({ planet_id => $self->body_id, - asteroid_id => $body->id, -# speed => $speed, + body_id => $body->id, + empire_id => $self->body->empire->id, })->insert; - $self->recalc_excavating; +# $self->recalc_excavating; return $self; } sub remove_excavator { - my ($self, $platform) = @_; - $platform->delete; + my ($self, $excavator) = @_; + $excavator->delete; return $self; } @@ -221,7 +260,7 @@ sub make_plan { before 'can_downgrade' => sub { my $self = shift; - if ($self->excavators->count > ($self->level - 1)) { + if ($self->excavators->count > ($self->level - 15)) { confess [1013, 'You must abandon one of your Excavator Sites before you can downgrade the Archaeology Ministry.']; } if ($self->excavators->count && ($self->level -1) < 15 ) { @@ -229,10 +268,10 @@ before 'can_downgrade' => sub { } }; -after 'downgrade' => sub { - my $self = shift; - $self->recalc_excavating; -}; +#after 'downgrade' => sub { +# my $self = shift; +# $self->recalc_excavating; +#}; no Moose; __PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/ExcavatorSite.pm b/lib/Lacuna/DB/Result/ExcavatorSite.pm deleted file mode 100644 index a2921f84..00000000 --- a/lib/Lacuna/DB/Result/ExcavatorSite.pm +++ /dev/null @@ -1,19 +0,0 @@ -package Lacuna::DB::Result::ExcavatorSite; - -use Moose; -use utf8; -no warnings qw(uninitialized); -extends 'Lacuna::DB::Result'; - -__PACKAGE__->table('excavators'); -__PACKAGE__->add_columns( - planet_id => { data_type => 'int', size => 11, is_nullable => 0 }, - asteroid_id => { data_type => 'int', size => 11, is_nullable => 0 }, -); - -__PACKAGE__->belongs_to('asteroid', 'Lacuna::DB::Result::Map::Body', 'asteroid_id'); -__PACKAGE__->belongs_to('planet', 'Lacuna::DB::Result::Map::Body', 'planet_id'); - - -no Moose; -__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Excavators.pm b/lib/Lacuna/DB/Result/Excavators.pm new file mode 100644 index 00000000..f473784a --- /dev/null +++ b/lib/Lacuna/DB/Result/Excavators.pm @@ -0,0 +1,19 @@ +package Lacuna::DB::Result::Excavators; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result'; + +__PACKAGE__->table('excavators'); +__PACKAGE__->add_columns( + planet_id => { data_type => 'int', size => 11, is_nullable => 0 }, + body_id => { data_type => 'int', size => 11, is_nullable => 0 }, + empire_id => { data_type => 'int', size => 11, is_nullable => 0 }, +); + +__PACKAGE__->belongs_to('body', 'Lacuna::DB::Result::Map::Body', 'body_id'); +__PACKAGE__->belongs_to('planet', 'Lacuna::DB::Result::Map::Body', 'planet_id'); + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index fa6cd0a7..7c39c811 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -754,6 +754,7 @@ sub found_colony { $self->usable_as_starter_enabled(0); $self->last_tick(DateTime->now); $self->update; +# Clear Excavators, send message to both empires. # award medal my $type = ref $self; @@ -1056,6 +1057,10 @@ sub tick { $i++; } + # Process excavator sites + if( my $arch = $self->archaeology) { + $arch->run_excavators; + } # get ship tasks my $ships = Lacuna->db->resultset('Lacuna::DB::Result::Ships')->search({ body_id => $self->id, @@ -1077,7 +1082,7 @@ sub tick { } $i++; } - + # synchronize completion of tasks foreach my $key (sort keys %todo) { my ($object, $job) = ($todo{$key}{object}, $todo{$key}{type}); diff --git a/lib/Lacuna/DB/Result/Ships/Excavator.pm b/lib/Lacuna/DB/Result/Ships/Excavator.pm index 9b716716..f4ac78cb 100644 --- a/lib/Lacuna/DB/Result/Ships/Excavator.pm +++ b/lib/Lacuna/DB/Result/Ships/Excavator.pm @@ -24,7 +24,7 @@ use constant base_stealth => 0; use constant base_hold_size => 0; use constant build_tags => ['Exploration']; -with "Lacuna::Role::Ship::Send::Asteroid"; +with "Lacuna::Role::Ship::Send::AsteroidAndUninhabited"; with "Lacuna::Role::Ship::Arrive::DeployExcavator"; no Moose; diff --git a/lib/Lacuna/RPC/Building/Archaeology.pm b/lib/Lacuna/RPC/Building/Archaeology.pm index 38867e56..8008eb62 100644 --- a/lib/Lacuna/RPC/Building/Archaeology.pm +++ b/lib/Lacuna/RPC/Building/Archaeology.pm @@ -99,10 +99,11 @@ sub view_excavators { my $building = $self->get_building($empire, $building_id); my $excavators = $building->excavators; my @sites; +#XXX Different data return: Percent rates of rewards while (my $excav = $excavators->next) { push @sites, { - id => $excav->id, - asteroid => $excav->asteroid->get_status, + id => $excav->id, + body => $excav->body->get_status, }; } return { diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index ed6e06ab..5858b1be 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -163,7 +163,7 @@ sub send_fleet { } my @fleet; my $speed = 999999999; - my $excavator = 0; +# my $excavator = 0; for my $ship_id (@$ship_ids) { my $ship = Lacuna->db->resultset('Lacuna::DB::Result::Ships')->find($ship_id); unless (defined $ship) { @@ -172,15 +172,15 @@ sub send_fleet { unless ($ship->body->empire_id == $empire->id) { confess [1010, 'You do not own that ship.']; } - if ($ship->type eq 'excavator') { - $excavator++; - } +# if ($ship->type eq 'excavator') { +# $excavator++; +# } $speed = $ship->speed if ( $speed > $ship->speed ); push @fleet, $ship_id; } - unless ($excavator <= 1) { - confess [1010, 'Only one Excavator may be sent to a body in a 30 day period']; - } +# unless ($excavator <= 1) { +# confess [1010, 'Only one Excavator may be sent to a body in a 30 day period']; +# } unless ($set_speed <= $speed) { confess [1009, 'Set speed cannot exceed the speed of the slowest ship.']; } diff --git a/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm b/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm index 672de18a..ab1fc604 100644 --- a/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm +++ b/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm @@ -51,11 +51,12 @@ after can_send_to_target => sub { confess [1013, 'Cannot control excavators without an Archaeology.'] unless (defined $archaeology); confess [1013, 'Your Archaeology Ministry must be level 15 or higher in order to send excavators.'] unless ($archaeology->level >= 15); $archaeology->can_add_excavator($target); +# print "Possible to add excav\n"; # Will need to make this only pertaining to excavation later. if ($target->star->station_id) { if ($target->star->station->laws->search({type => 'MembersOnlyMiningRights'})->count) { unless ($target->star->station->alliance_id == $self->body->empire->alliance_id) { - confess [1010, 'Only '.$target->star->station->alliance->name.' members can excavate asteroids in the jurisdiction of the space station.']; + confess [1010, 'Only '.$target->star->station->alliance->name.' members can excavate bodies in the jurisdiction of the space station.']; } } } diff --git a/lib/Lacuna/Role/Ship/Arrive/Excavate.pm b/lib/Lacuna/Role/Ship/Arrive/Excavate.pm deleted file mode 100644 index 935268b9..00000000 --- a/lib/Lacuna/Role/Ship/Arrive/Excavate.pm +++ /dev/null @@ -1,127 +0,0 @@ -package Lacuna::Role::Ship::Arrive::Excavate; - -use strict; -use Moose::Role; -use Lacuna::Util qw(randint random_element); -use Lacuna::Constants qw(ORE_TYPES FOOD_TYPES); - -after handle_arrival_procedures => sub { - my ($self) = @_; - - # we're coming home - return if ($self->direction eq 'in'); - - # what are our chances - my $remote_body = $self->foreign_body; - my $body = $self->body; - my $distance_modifier = int($body->calculate_distance_to_target($remote_body) / 7500); - my $find = randint(1,100) - $distance_modifier; - - # found a plan - my $empire = $body->empire; - if ($find < 5) { - my $class = random_element([qw( - Lacuna::DB::Result::Building::Permanent::AlgaePond - Lacuna::DB::Result::Building::Permanent::AmalgusMeadow - Lacuna::DB::Result::Building::Permanent::Beach1 - Lacuna::DB::Result::Building::Permanent::Beach2 - Lacuna::DB::Result::Building::Permanent::Beach3 - Lacuna::DB::Result::Building::Permanent::Beach4 - Lacuna::DB::Result::Building::Permanent::Beach5 - Lacuna::DB::Result::Building::Permanent::Beach6 - Lacuna::DB::Result::Building::Permanent::Beach7 - Lacuna::DB::Result::Building::Permanent::Beach8 - Lacuna::DB::Result::Building::Permanent::Beach9 - Lacuna::DB::Result::Building::Permanent::Beach10 - Lacuna::DB::Result::Building::Permanent::Beach11 - Lacuna::DB::Result::Building::Permanent::Beach12 - Lacuna::DB::Result::Building::Permanent::Beach13 - Lacuna::DB::Result::Building::Permanent::BeeldebanNest - Lacuna::DB::Result::Building::Permanent::Crater - Lacuna::DB::Result::Building::Permanent::DentonBrambles - Lacuna::DB::Result::Building::Permanent::GeoThermalVent - Lacuna::DB::Result::Building::Permanent::Grove - Lacuna::DB::Result::Building::Permanent::Lagoon - Lacuna::DB::Result::Building::Permanent::Lake - Lacuna::DB::Result::Building::Permanent::LapisForest - Lacuna::DB::Result::Building::Permanent::MalcudField - Lacuna::DB::Result::Building::Permanent::NaturalSpring - Lacuna::DB::Result::Building::Permanent::Ravine - Lacuna::DB::Result::Building::Permanent::RockyOutcrop - Lacuna::DB::Result::Building::Permanent::Sand - Lacuna::DB::Result::Building::Permanent::Volcano - )]); - my $plan = $body->add_plan($class, 1, ($find == 1) ? randint(1,4) : 0); - if (!$empire->skip_excavator_plan) { - $empire->send_predefined_message( - tags => ['Excavator','Alert'], - filename => 'plan_discovered_by_excavator.txt', - params => [$remote_body->x, $remote_body->y, $remote_body->name, ($plan->level + $plan->extra_build_level), $class->name, $body->id, $body->name], - ); - } - } - - # found a glyph - elsif ($find < 16) { - my $ore = random_element([ORE_TYPES]); - $body->add_glyph($ore); - if (!$empire->skip_excavator_glyph) { - $empire->send_predefined_message( - tags => ['Excavator','Alert'], - filename => 'glyph_discovered_by_excavator.txt', - params => [$remote_body->x, $remote_body->y, $remote_body->name, $ore, $body->id, $body->name], - attachments => { - image => { - title => $ore, - url => 'https://d16cbq0l6kkf21.cloudfront.net/assets/glyphs/'.$ore.'.png', - } - } - ); - } - $empire->add_medal($ore.'_glyph'); - $body->add_news(20, sprintf('%s has uncovered a rare and ancient %s glyph on %s.',$empire->name, $ore, $remote_body->name)); - } - - # found some resources - elsif ($find < 80) { - $distance_modifier *= 75; - my $type = random_element([ORE_TYPES, FOOD_TYPES, qw(water energy)]); - my $amount = randint(100 + $distance_modifier, 2500 + $distance_modifier); - $body->add_type($type, $amount)->update; - if (!$empire->skip_excavator_resources) { - $empire->send_predefined_message( - tags => ['Excavator','Alert'], - filename => 'resources_discovered_by_excavator.txt', - params => [$remote_body->x, $remote_body->y, $remote_body->name, $amount, $type, $body->id, $body->name], - ); - } - } - - # wha wha wha wahaa - nothing! - else { - if (!$empire->skip_found_nothing) { - $empire->send_predefined_message( - tags => ['Excavator','Alert'], - filename => 'glyph_not_discovered_by_excavator.txt', - params => [$remote_body->x, $remote_body->y, $remote_body->name, $body->id, $body->name], - ); - } - } - - # all pow - $self->delete; - confess [-1]; -}; - -after send => sub { - my $self = shift; - Lacuna->cache->set('excavator_'.$self->foreign_body_id, $self->body->empire_id, 1, 60 * 60 * 24 * 30); -}; - - -after can_send_to_target => sub { - my ($self, $target) = @_; - confess [1010, 'You have already sent an Excavator there in the past 30 days.'] if (Lacuna->cache->get('excavator_'.$target->id, $self->body->empire->id)); -}; - -1; diff --git a/lib/Lacuna/Role/Ship/Send/AsteroidAndUninhabited.pm b/lib/Lacuna/Role/Ship/Send/AsteroidAndUninhabited.pm new file mode 100644 index 00000000..18bf6b64 --- /dev/null +++ b/lib/Lacuna/Role/Ship/Send/AsteroidAndUninhabited.pm @@ -0,0 +1,13 @@ +package Lacuna::Role::Ship::Send::AsteroidAndUninhabited; + +use strict; +use Moose::Role; + +after can_send_to_target => sub { + my ($self, $target) = @_; + confess [1009, 'Can only be sent to asteroids and uninhabited planets.'] unless + ( $target->isa('Lacuna::DB::Result::Map::Body::Asteroid') || + ($target->isa('Lacuna::DB::Result::Map::Body::Planet') and !(defined($target->empire_id)) )); +}; + +1; diff --git a/var/messages/excavator_deployed.txt b/var/messages/excavator_deployed.txt index e3f169a4..ee0255d6 100644 --- a/var/messages/excavator_deployed.txt +++ b/var/messages/excavator_deployed.txt @@ -1,7 +1,6 @@ -Mining Platform Deployed +Excavator Deployed ~~~ The Excavator from {Planet %s %s} has deployed on {Starmap %s %s %s}. -It is operational and awaiting cargo ships. It is now operational and will start sending back it's results. Regards, -- 2.51.2 From 55430e753f67ab25c7a10c41a3fd2c971a6e4c2b Mon Sep 17 00:00:00 2001 From: lemming552 Date: Thu, 26 Jan 2012 16:00:41 -0700 Subject: [PATCH 06/28] Activated a nice bug, but closer. --- lib/Lacuna/DB/Result/Building/Archaeology.pm | 151 ++++++++++++++++-- lib/Lacuna/DB/Result/Map/Body/Planet.pm | 2 +- lib/Lacuna/RPC/Building/Archaeology.pm | 17 +- .../Role/Ship/Arrive/DeployExcavator.pm | 1 + 4 files changed, 154 insertions(+), 17 deletions(-) diff --git a/lib/Lacuna/DB/Result/Building/Archaeology.pm b/lib/Lacuna/DB/Result/Building/Archaeology.pm index cd290cbe..7426e8f8 100644 --- a/lib/Lacuna/DB/Result/Building/Archaeology.pm +++ b/lib/Lacuna/DB/Result/Building/Archaeology.pm @@ -4,8 +4,10 @@ use Moose; use utf8; no warnings qw(uninitialized); extends 'Lacuna::DB::Result::Building'; -use Lacuna::Constants qw(ORE_TYPES); +use Lacuna::Constants qw(ORE_TYPES FOOD_TYPES); +use Lacuna::Util qw(randint random_element); use Clone qw(clone); +use feature 'switch'; around 'build_tags' => sub { my ($orig, $class) = @_; @@ -118,11 +120,148 @@ sub run_excavators { my $level = $self->level; # Do once for arch + my $result = $self->dig_it($self->body, $level, 1); + my @results = ($result); if ($level > 14) { my $excavators = $self->excavators; while (my $excav = $excavators->next) { + my $body = $excav->body; + my $result = $self->dig_it($body, $level, 0); + push @results, $result; + if ($result->{outcome} eq "Destroyed") { + $self->remove_excavator($excav); + } } } + for $result (@results) { + printf "%3d:%s - %s : %s\n", + $result->{id}, $result->{site}, + $result->{outcome}, $result->{message}; + } +} + +sub dig_it { + my ($self, $body, $level, $arch) = @_; + my $chances = $self->can_you_dig_it($body, $level, $arch); + + my $rnum = randint(0,100); + my $base = 0; + my $outcome = "nothing"; + for my $type (keys %$chances) { + if ($rnum < $chances->{$type} + $base) { + $outcome = $type; + last; + } + $base += $chances->{$type}; + } + my $result; + given ($outcome) { + when ("resource") { + my $type = random_element([ORE_TYPES, FOOD_TYPES, qw(water energy)]); + my $amount = randint(100 * $level, 1000 * $level); + $self->body->add_type($type, $amount)->update; + $result = { + message => "Found $amount of $type.", + outcome => "Resource", + }; + } + when ("plan") { + my ($plan, $lvl, $plus, $name) = random_plan($level); + $result = { + message => "Found level $lvl + $plus $name Plan.", + outcome => "Plan", + }; + } + when ("glyph") { + my $glyph = $self->found_glyph($body); + $result = { + message => "Found a $glyph glyph.", + outcome => "Glyph", + }; + } + when ("artifact") { + my ($plan, $lvl, $plus, $name) = $self->get_artifact($body, $level); + $result = { + message => "Found level $lvl + $plus $name Plan.", + outcome => "Artifact", + }; + } + when ("horror") { + $result = { + message => "Poor insane robots.", + outcome => "Destroyed", + }; + } + default { + $result = { + message => "No results found.", + outcome => "Nothing", + }; + } + } + $result->{id} = $self->id; + $result->{site} = $body->name; + return $result; +} + +sub get_artifact { + my ($self, $body, $level) = @_; + + my $plan = 0; + my $lvl = 0; + my $plus = 0; + my $name = "pending"; + + return ($plan, $lvl, $plus, $name); +} + +sub found_glyph { + my ($self, $body) = @_; + + my $glyph = "a glyph!"; + + return $glyph; +} + +sub random_plan { + my ($level) = @_; + + my $plan = 0; + my $lvl = 0; + my $plus = 0; + my $name = "pending"; + + return ($plan, $lvl, $plus, $name); +} + +sub can_you_dig_it { + my ($self, $body, $level, $arch) = @_; + + my $mult = $arch + 1; + my $plan = (int($level/5)+1) * $mult; # 1-7% + my $ore_total = 0; + for my $ore (ORE_TYPES) { + $ore_total += $body->$ore; + } + my $glyph = int($mult * $level * $ore_total/10_000)+1; #max 1-61% + my $resource = 2 * $level; # 2-60% + my $artifact = 0; + if (!$arch && $body->buildings->count) { + $artifact = 5; + } + my $horror = $arch ? 0 : 1; + my $most = $plan + $glyph + $artifact + $horror; + if ($most + $resource > 100) { + $resource -= ($most + $resource - 100); + } + my $return = { + plan => $plan, + glyph => $glyph, + resource => $resource, + artifact => $artifact, + horror => $horror, + }; + return $return; } @@ -136,13 +275,11 @@ sub can_add_excavator { # excavator count for archaeology my $count = $self->excavators->count; -# print "Checking is more than $count are travelling.\n"; unless ($on_arrival) { $count += Lacuna->db->resultset('Lacuna::DB::Result::Ships') ->search({type=>'excavator', task=>'Travelling',body_id=>$self->body_id})->count; } my $max_e = $self->max_excavators; -# print "Count $count with max of $max_e\n"; if ($count >= $max_e) { confess [1009, 'Already at the maximum number of excavators allowed at this Archaeology level.']; } @@ -150,7 +287,6 @@ sub can_add_excavator { # Allowed one per empire per body. $count = Lacuna->db->resultset('Lacuna::DB::Result::Excavators') ->search({ body_id => $body->id, empire_id => $self->body->empire->id })->count; -# print "$count on body.\n"; unless ($on_arrival) { $count += Lacuna->db->resultset('Lacuna::DB::Result::Ships') ->search( { @@ -160,7 +296,6 @@ sub can_add_excavator { body_id=>$self->body_id })->count; } -# print "$count on body or on way.\n"; if ($count) { confess [1010, $body->name.' already has an excavator from your empire or one is on the way.']; } @@ -174,7 +309,6 @@ sub add_excavator { body_id => $body->id, empire_id => $self->body->empire->id, })->insert; -# $self->recalc_excavating; return $self; } @@ -268,10 +402,5 @@ before 'can_downgrade' => sub { } }; -#after 'downgrade' => sub { -# my $self = shift; -# $self->recalc_excavating; -#}; - no Moose; __PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 7c39c811..9344d5b8 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -1057,7 +1057,7 @@ sub tick { $i++; } - # Process excavator sites + # Process excavator sites (Wrong spot, happens everytime planet is touched...) if( my $arch = $self->archaeology) { $arch->run_excavators; } diff --git a/lib/Lacuna/RPC/Building/Archaeology.pm b/lib/Lacuna/RPC/Building/Archaeology.pm index 8008eb62..5ccc0f4a 100644 --- a/lib/Lacuna/RPC/Building/Archaeology.pm +++ b/lib/Lacuna/RPC/Building/Archaeology.pm @@ -99,12 +99,19 @@ sub view_excavators { my $building = $self->get_building($empire, $building_id); my $excavators = $building->excavators; my @sites; -#XXX Different data return: Percent rates of rewards + my $level = $building->level; while (my $excav = $excavators->next) { - push @sites, { - id => $excav->id, - body => $excav->body->get_status, - }; + print "digging ", $excav->id, "\n"; + my $body = $excav->body; + my $chances = $building->can_you_dig_it($body, $level, 0); + my $excav_stat = { + id => $excav->id, + chances => $chances, + }; + push @sites, { + excavator => $excav_stat, + body => $excav->body->get_status, + }; } return { excavators => \@sites, diff --git a/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm b/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm index ab1fc604..623cf2e7 100644 --- a/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm +++ b/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm @@ -47,6 +47,7 @@ after handle_arrival_procedures => sub { after can_send_to_target => sub { my ($self, $target) = @_; + confess [1009, 'Can only be sent to asteroids and habitable planets.'] if ($target->isa('Lacuna::DB::Result::Map::Body::Planet::GasGiant')); my $archaeology = $self->body->archaeology; confess [1013, 'Cannot control excavators without an Archaeology.'] unless (defined $archaeology); confess [1013, 'Your Archaeology Ministry must be level 15 or higher in order to send excavators.'] unless ($archaeology->level >= 15); -- 2.51.2 From 7bf11ee58717dedcd226991ba266b18d0ccafad0 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Fri, 27 Jan 2012 17:23:51 -0700 Subject: [PATCH 07/28] All results accounted for. --- lib/Lacuna/DB/Result/Building/Archaeology.pm | 271 +++++++++++++++---- lib/Lacuna/RPC/Building/Archaeology.pm | 1 - var/messages/excavator_results.txt | 7 + 3 files changed, 218 insertions(+), 61 deletions(-) create mode 100644 var/messages/excavator_results.txt diff --git a/lib/Lacuna/DB/Result/Building/Archaeology.pm b/lib/Lacuna/DB/Result/Building/Archaeology.pm index 7426e8f8..2e991dc7 100644 --- a/lib/Lacuna/DB/Result/Building/Archaeology.pm +++ b/lib/Lacuna/DB/Result/Building/Archaeology.pm @@ -96,58 +96,61 @@ sub max_excavators { sub run_excavators { my $self = shift; - -# Run thru excavators for each arch. -# 1) See what they find -# Glyph, Plan, resource, (artifact), something bad -# 2) Glyph -# a) Chances based on ore content. (total ore)/10,000 * level -# b) Each ore has at least 1%, but proportional to content. -# 3) Plan % equal to level/5 -# 1+floor(lvl/6) possible -# 5% something special, 50% chance of 1+0, otherwise rand(1,lvl/6) -# 4) Resource Lvl * 2 percent chance -# 5) If glyph building on uninhabited excav planet -# Chance of grabbing a lvl 1 plan of it (no dillon or e-veins) -# Chance of 1+X up to level of arch/2+1 or level of building -# If lvl 1 (50% chance of destroying building, or reduce by 1 level) -# If 1+x, destroy building -# 6) Ancient Horror released. All cases, excavator destroyed. 1% chance -# a) Ph'nglui Mglw'nafh Cthulhu R'lyeh wgah'nagi fhtagn. -# b) Klaatu Barada Ni*cough* -# c) Brass Doors -# d) flutes - my $level = $self->level; -# Do once for arch +# Do once for arch itself. No chance of h orrors or artifacts. my $result = $self->dig_it($self->body, $level, 1); + $result->{id} = $self->id; my @results = ($result); if ($level > 14) { my $excavators = $self->excavators; while (my $excav = $excavators->next) { my $body = $excav->body; - my $result = $self->dig_it($body, $level, 0); + my $result; + if ($body->empire_id) { +#Oops, we didn't clean off the excav when settled. + $result = { + id => $excav->id, + site => $body->name, + outcome => "Destroyed", + message => "Colony wiped out dig.", + }; + } + else { + $result = $self->dig_it($body, $level, 0); + $result->{id} = $excav->id; + } push @results, $result; if ($result->{outcome} eq "Destroyed") { $self->remove_excavator($excav); } } } + my @report = (['Site','Type','Result']); for $result (@results) { - printf "%3d:%s - %s : %s\n", - $result->{id}, $result->{site}, - $result->{outcome}, $result->{message}; + push @report, [ + $result->{site}, + $result->{outcome}, + $result->{message}, + ]; } + $self->body->empire->send_predefined_message( + tags => ['Excavator','Alert'], + filename => 'excavator_results.txt', + params => [ $self->body->id, $self->body->name ], + attachments => { table => \@report}, + ); + return 1; } sub dig_it { my ($self, $body, $level, $arch) = @_; + my $chances = $self->can_you_dig_it($body, $level, $arch); - my $rnum = randint(0,100); + my $rnum = randint(0,999); my $base = 0; my $outcome = "nothing"; - for my $type (keys %$chances) { + for my $type (qw(horror artifact plan glyph resource)) { if ($rnum < $chances->{$type} + $base) { $outcome = $type; last; @@ -166,7 +169,7 @@ sub dig_it { }; } when ("plan") { - my ($plan, $lvl, $plus, $name) = random_plan($level); + my ($lvl, $plus, $name) = $self->found_plan($level); $result = { message => "Found level $lvl + $plus $name Plan.", outcome => "Plan", @@ -180,13 +183,26 @@ sub dig_it { }; } when ("artifact") { - my ($plan, $lvl, $plus, $name) = $self->get_artifact($body, $level); - $result = { - message => "Found level $lvl + $plus $name Plan.", - outcome => "Artifact", - }; + my ($lvl, $plus, $name) = $self->found_artifact($body, $level); + if ($name eq "Nothing") { + $result = { + message => "No results found.", + outcome => "Nothing", + }; + } + else { + $result = { + message => "Found level $lvl + $plus $name Plan.", + outcome => "Artifact", + }; + } } when ("horror") { +# 6) Ancient Horror released. All cases, excavator destroyed. 1% chance +# a) Ph'nglui Mglw'nafh Cthulhu R'lyeh wgah'nagi fhtagn. +# b) Klaatu Barada Ni*cough* +# c) Brass Doors +# d) flutes $result = { message => "Poor insane robots.", outcome => "Destroyed", @@ -204,55 +220,119 @@ sub dig_it { return $result; } -sub get_artifact { +sub found_plan { + my ($self, $level) = @_; + + my $plan_types = plans_of_type(); + my $class; + my $rand_cat = randint(0,19); + my $lvl = 1; + my $plus = 0; + if ($rand_cat < 1) { + $class = random_element($plan_types->{special}); + $plus = randint(0, int($level/7)); + } + elsif ($rand_cat < 10) { + $class = random_element($plan_types->{natural}); + $plus = randint(1, int($level/7)+1) if (randint(0,3) < 1); + } + else { + $class = random_element($plan_types->{decor}); + $plus = randint(1, int($level/5)+1) if (randint(0,2) < 1); + } + my $plan = $self->body->add_plan($class, $lvl, $plus); + + return ($lvl, $plus, $class->name); +} + +sub found_artifact { my ($self, $body, $level) = @_; - my $plan = 0; - my $lvl = 0; - my $plus = 0; - my $name = "pending"; + my $plan_types = plans_of_type(); + my @buildings; + my $buildings = $body->buildings; + while (my $building = $buildings->next) { + unless ( grep { $building->class eq $_ } @{$plan_types->{disallow}}) { + push @buildings, $building; + } + } + return (0,0,"Nothing") unless (@buildings); + my $select = random_element(\@buildings); + my $class; my $lvl; my $plus; my $name; my $destroy; + if ($level > $select->level and randint(1, int(3 * $level/2)) >= $select->level) { + $class = $select->class; + $lvl = 1; + $plus = $select->level - 1; + $name = $select->name; + $destroy = 100; + } + elsif (randint(1,2) == 1) { + $class = $select->class; + $lvl = 1; + $plus = 0; + $name = $select->name; + $destroy = 10; + } + else { + $class = $select->class; + $lvl = randint(1,$select->level); + $plus = 0; + $name = $select->name; + $destroy = 25; + } + $self->body->add_plan($class, $lvl, $plus); + if (randint(0,99) < $destroy) { + $select->delete; + } - return ($plan, $lvl, $plus, $name); + return ($lvl, $plus, $name); } sub found_glyph { my ($self, $body) = @_; - my $glyph = "a glyph!"; - + my %ores; + my $ore_total = 0; + for my $ore (ORE_TYPES) { + $ores{$ore} = $body->$ore; + $ore_total += $ores{$ore}; + } + my $base = 0; + my $rnum = randint(1,$ore_total); + my $glyph = "error"; + for my $ore (ORE_TYPES) { + if ($rnum < $ores{$ore} + $base) { + $glyph = $ore; + last; + } + $base += $ores{$ore}; + } + if ($glyph ne "error") { + $self->body->add_glyph($glyph); + } return $glyph; } -sub random_plan { - my ($level) = @_; - - my $plan = 0; - my $lvl = 0; - my $plus = 0; - my $name = "pending"; - - return ($plan, $lvl, $plus, $name); -} - sub can_you_dig_it { my ($self, $body, $level, $arch) = @_; my $mult = $arch + 1; - my $plan = (int($level/5)+1) * $mult; # 1-7% + my $plan = ($level/5+1) * $mult * 10; # 2.4-14% my $ore_total = 0; for my $ore (ORE_TYPES) { $ore_total += $body->$ore; } - my $glyph = int($mult * $level * $ore_total/10_000)+1; #max 1-61% - my $resource = 2 * $level; # 2-60% + my $glyph = int(10* $mult * $level * $ore_total/10_000)+1; #max 1-60% + $glyph = 600 if ($glyph > 600); + my $resource = 10 * 2 * $level; # 2-60% my $artifact = 0; if (!$arch && $body->buildings->count) { - $artifact = 5; + $artifact = 50; } my $horror = $arch ? 0 : 1; my $most = $plan + $glyph + $artifact + $horror; - if ($most + $resource > 100) { - $resource -= ($most + $resource - 100); + if ($most + $resource > 1000) { + $resource -= ($most + $resource - 1000); } my $return = { plan => $plan, @@ -264,6 +344,77 @@ sub can_you_dig_it { return $return; } +sub plans_of_type { + my $decor = [qw( + Lacuna::DB::Result::Building::Permanent::Beach1 + Lacuna::DB::Result::Building::Permanent::Beach2 + Lacuna::DB::Result::Building::Permanent::Beach3 + Lacuna::DB::Result::Building::Permanent::Beach4 + Lacuna::DB::Result::Building::Permanent::Beach5 + Lacuna::DB::Result::Building::Permanent::Beach6 + Lacuna::DB::Result::Building::Permanent::Beach7 + Lacuna::DB::Result::Building::Permanent::Beach8 + Lacuna::DB::Result::Building::Permanent::Beach9 + Lacuna::DB::Result::Building::Permanent::Beach10 + Lacuna::DB::Result::Building::Permanent::Beach11 + Lacuna::DB::Result::Building::Permanent::Beach12 + Lacuna::DB::Result::Building::Permanent::Beach13 + Lacuna::DB::Result::Building::Permanent::Crater + Lacuna::DB::Result::Building::Permanent::Grove + Lacuna::DB::Result::Building::Permanent::Lagoon + Lacuna::DB::Result::Building::Permanent::Lake + Lacuna::DB::Result::Building::Permanent::RockyOutcrop + Lacuna::DB::Result::Building::Permanent::Sand + )]; + my $natural = [qw( + Lacuna::DB::Result::Building::Permanent::AlgaePond + Lacuna::DB::Result::Building::Permanent::AmalgusMeadow + Lacuna::DB::Result::Building::Permanent::BeeldebanNest + Lacuna::DB::Result::Building::Permanent::DentonBrambles + Lacuna::DB::Result::Building::Permanent::GeoThermalVent + Lacuna::DB::Result::Building::Permanent::LapisForest + Lacuna::DB::Result::Building::Permanent::MalcudField + Lacuna::DB::Result::Building::Permanent::NaturalSpring + Lacuna::DB::Result::Building::Permanent::Ravine + Lacuna::DB::Result::Building::Permanent::Volcano + )]; + my $special = [qw( + Lacuna::DB::Result::Building::Permanent::BlackHoleGenerator + Lacuna::DB::Result::Building::Permanent::CitadelOfKnope + Lacuna::DB::Result::Building::Permanent::CrashedShipSite + Lacuna::DB::Result::Building::Permanent::GratchsGauntlet + Lacuna::DB::Result::Building::Permanent::InterDimensionalRift + Lacuna::DB::Result::Building::Permanent::KalavianRuins + Lacuna::DB::Result::Building::Permanent::LibraryOfJith + Lacuna::DB::Result::Building::Permanent::OracleOfAnid + Lacuna::DB::Result::Building::Permanent::PantheonOfHagness + Lacuna::DB::Result::Building::Permanent::TempleOfTheDrajilites + )]; + my $artifact = [qw( + Lacuna::DB::Result::Building::Permanent::HallsOfVrbansk + Lacuna::DB::Result::Building::Permanent::GasGiantPlatform + Lacuna::DB::Result::Building::Permanent::GreatBallOfJunk + Lacuna::DB::Result::Building::Permanent::JunkHengeSculpture + Lacuna::DB::Result::Building::Permanent::MetalJunkArches + Lacuna::DB::Result::Building::Permanent::PyramidJunkSculpture + Lacuna::DB::Result::Building::Permanent::SpaceJunkPark + Lacuna::DB::Result::Building::Permanent::TerraformingPlatform + )]; + my $disallow = [qw( + Lacuna::DB::Result::Building::Permanent::EssentiaVein + Lacuna::DB::Result::Building::Permanent::KasternsKeep + Lacuna::DB::Result::Building::Permanent::MassadsHenge + Lacuna::DB::Result::Building::Permanent::TheDillonForge + )]; + return { + decor => $decor, + natural => $natural, + special => $special, + artifact => $artifact, + disallow => $disallow, + }; +} + sub excavators { my $self = shift; diff --git a/lib/Lacuna/RPC/Building/Archaeology.pm b/lib/Lacuna/RPC/Building/Archaeology.pm index 5ccc0f4a..2a28dc0c 100644 --- a/lib/Lacuna/RPC/Building/Archaeology.pm +++ b/lib/Lacuna/RPC/Building/Archaeology.pm @@ -101,7 +101,6 @@ sub view_excavators { my @sites; my $level = $building->level; while (my $excav = $excavators->next) { - print "digging ", $excav->id, "\n"; my $body = $excav->body; my $chances = $building->can_you_dig_it($body, $level, 0); my $excav_stat = { diff --git a/var/messages/excavator_results.txt b/var/messages/excavator_results.txt new file mode 100644 index 00000000..72aba3e4 --- /dev/null +++ b/var/messages/excavator_results.txt @@ -0,0 +1,7 @@ +Excavator Results +~~~ +The Archeology Ministry of {Planet %s %s} has received the following results from it's excavator sites. + +Regards, + +Your Humble Assistant -- 2.51.2 From 5911b42a55236bf0020904f507cd1b253e8f7278 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Fri, 27 Jan 2012 22:18:00 -0700 Subject: [PATCH 08/28] Skipping mail and firming up results. --- lib/Lacuna.pm | 2 +- lib/Lacuna/DB/Result/Building/Archaeology.pm | 40 ++++++++++++------- lib/Lacuna/DB/Result/Empire.pm | 2 + lib/Lacuna/DB/Result/Excavators.pm | 1 + lib/Lacuna/DB/Result/Map/Body/Planet.pm | 8 ++-- lib/Lacuna/DB/Result/Ships/Excavator.pm | 2 + .../DB/Result/Ships/MiningPlatformShip.pm | 1 + lib/Lacuna/RPC/Building/Archaeology.pm | 1 + lib/Lacuna/RPC/Building/SpacePort.pm | 14 +++---- lib/Lacuna/RPC/Empire.pm | 14 +++++++ .../Role/Ship/Arrive/DeployExcavator.pm | 2 +- var/upgrades/3.0838.sql | 9 +++++ var/www/public/changes.txt | 3 ++ 13 files changed, 73 insertions(+), 26 deletions(-) create mode 100644 var/upgrades/3.0838.sql diff --git a/lib/Lacuna.pm b/lib/Lacuna.pm index f8218bd6..d9e78ca7 100644 --- a/lib/Lacuna.pm +++ b/lib/Lacuna.pm @@ -7,7 +7,7 @@ use Config::JSON; useall __PACKAGE__; -our $VERSION = 3.0837; +our $VERSION = 3.0838; 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/Building/Archaeology.pm b/lib/Lacuna/DB/Result/Building/Archaeology.pm index 2e991dc7..895163be 100644 --- a/lib/Lacuna/DB/Result/Building/Archaeology.pm +++ b/lib/Lacuna/DB/Result/Building/Archaeology.pm @@ -97,6 +97,7 @@ sub run_excavators { my $self = shift; my $level = $self->level; + my $empire = $self->body->empire; # Do once for arch itself. No chance of h orrors or artifacts. my $result = $self->dig_it($self->body, $level, 1); $result->{id} = $self->id; @@ -125,20 +126,29 @@ sub run_excavators { } } } - my @report = (['Site','Type','Result']); - for $result (@results) { + my @report; + for $result (sort { $a->{site} cmp $b->{site} } @results) { + next if ($empire->skip_found_nothing and $result->{outcome} eq "Nothing"); + next if ($empire->skip_excavator_artifact and $result->{outcome} eq "Artifact"); + next if ($empire->skip_excavator_resources and $result->{outcome} eq "Resource"); + next if ($empire->skip_excavator_plan and $result->{outcome} eq "Plan"); + next if ($empire->skip_excavator_glyph and $result->{outcome} eq "Glyph"); + next if ($empire->skip_excavator_destroyed and $result->{outcome} eq "Destroyed"); push @report, [ $result->{site}, $result->{outcome}, $result->{message}, ]; } - $self->body->empire->send_predefined_message( - tags => ['Excavator','Alert'], - filename => 'excavator_results.txt', - params => [ $self->body->id, $self->body->name ], - attachments => { table => \@report}, - ); + if (@report) { + unshift @report, (['Site','Type','Result']); + $empire->send_predefined_message( + tags => ['Excavator','Alert'], + filename => 'excavator_results.txt', + params => [ $self->body->id, $self->body->name ], + attachments => { table => \@report}, + ); + } return 1; } @@ -198,13 +208,14 @@ sub dig_it { } } when ("horror") { -# 6) Ancient Horror released. All cases, excavator destroyed. 1% chance -# a) Ph'nglui Mglw'nafh Cthulhu R'lyeh wgah'nagi fhtagn. -# b) Klaatu Barada Ni*cough* -# c) Brass Doors -# d) flutes + my $message = random_element([ + 'Ph\'nglui Mglw\'nafh Cthulhu R\'lyeh wgah\'nagi fhtagn.', + 'Klaatu Barada Ni*cough*', + 'The brazen temple doors open...', + 'It\'s full of stars' + ]); $result = { - message => "Poor insane robots.", + message => $message, outcome => "Destroyed", }; } @@ -330,6 +341,7 @@ sub can_you_dig_it { $artifact = 50; } my $horror = $arch ? 0 : 1; + $horror += 2 * $artifact; my $most = $plan + $glyph + $artifact + $horror; if ($most + $resource > 1000) { $resource -= ($most + $resource - 1000); diff --git a/lib/Lacuna/DB/Result/Empire.pm b/lib/Lacuna/DB/Result/Empire.pm index b68c5f99..6611eb5c 100644 --- a/lib/Lacuna/DB/Result/Empire.pm +++ b/lib/Lacuna/DB/Result/Empire.pm @@ -78,6 +78,8 @@ __PACKAGE__->add_columns( skip_spy_recovery => { data_type => 'tinyint', default_value => 0 }, skip_probe_detected => { data_type => 'tinyint', default_value => 0 }, skip_attack_messages => { data_type => 'tinyint', default_value => 0 }, + skip_excavator_artifact => { data_type => 'tinyint', default_value => 0 }, + skip_excavator_destroyed => { data_type => 'tinyint', default_value => 0 }, ); sub sqlt_deploy_hook { diff --git a/lib/Lacuna/DB/Result/Excavators.pm b/lib/Lacuna/DB/Result/Excavators.pm index f473784a..d3b533b1 100644 --- a/lib/Lacuna/DB/Result/Excavators.pm +++ b/lib/Lacuna/DB/Result/Excavators.pm @@ -14,6 +14,7 @@ __PACKAGE__->add_columns( __PACKAGE__->belongs_to('body', 'Lacuna::DB::Result::Map::Body', 'body_id'); __PACKAGE__->belongs_to('planet', 'Lacuna::DB::Result::Map::Body', 'planet_id'); +__PACKAGE__->belongs_to('empire', 'Lacuna::DB::Result::Empire', 'empire_id'); no Moose; __PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 9344d5b8..5c951c8b 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -754,7 +754,7 @@ sub found_colony { $self->usable_as_starter_enabled(0); $self->last_tick(DateTime->now); $self->update; -# Clear Excavators, send message to both empires. +# Excavators get cleared when being checked for results. # award medal my $type = ref $self; @@ -1057,9 +1057,11 @@ sub tick { $i++; } - # Process excavator sites (Wrong spot, happens everytime planet is touched...) - if( my $arch = $self->archaeology) { + # Process excavator sites + if ( my $arch = $self->archaeology and + not Lacuna->cache->get('excavator_'.$self->id)) { $arch->run_excavators; + Lacuna->cache->set('excavator_'.$self->id, 1, 600 ); } # get ship tasks my $ships = Lacuna->db->resultset('Lacuna::DB::Result::Ships')->search({ diff --git a/lib/Lacuna/DB/Result/Ships/Excavator.pm b/lib/Lacuna/DB/Result/Ships/Excavator.pm index f4ac78cb..34b68f95 100644 --- a/lib/Lacuna/DB/Result/Ships/Excavator.pm +++ b/lib/Lacuna/DB/Result/Ships/Excavator.pm @@ -6,6 +6,7 @@ no warnings qw(uninitialized); extends 'Lacuna::DB::Result::Ships'; use constant prereq => { class=> 'Lacuna::DB::Result::Building::Archaeology', level => 15 }; +# Keeping Old prices around just while testing stuff # use constant base_food_cost => 400; # use constant base_water_cost => 1000; # use constant base_energy_cost => 8500; @@ -25,6 +26,7 @@ use constant base_hold_size => 0; use constant build_tags => ['Exploration']; with "Lacuna::Role::Ship::Send::AsteroidAndUninhabited"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; with "Lacuna::Role::Ship::Arrive::DeployExcavator"; no Moose; diff --git a/lib/Lacuna/DB/Result/Ships/MiningPlatformShip.pm b/lib/Lacuna/DB/Result/Ships/MiningPlatformShip.pm index 7637ba9c..c728d745 100644 --- a/lib/Lacuna/DB/Result/Ships/MiningPlatformShip.pm +++ b/lib/Lacuna/DB/Result/Ships/MiningPlatformShip.pm @@ -20,6 +20,7 @@ use constant pilotable => 1; use constant build_tags => ['Mining']; with "Lacuna::Role::Ship::Send::Asteroid"; +with "Lacuna::Role::Ship::Arrive::TriggerDefense"; with "Lacuna::Role::Ship::Arrive::DeployMiningPlatform"; no Moose; diff --git a/lib/Lacuna/RPC/Building/Archaeology.pm b/lib/Lacuna/RPC/Building/Archaeology.pm index 2a28dc0c..9fc75380 100644 --- a/lib/Lacuna/RPC/Building/Archaeology.pm +++ b/lib/Lacuna/RPC/Building/Archaeology.pm @@ -103,6 +103,7 @@ sub view_excavators { while (my $excav = $excavators->next) { my $body = $excav->body; my $chances = $building->can_you_dig_it($body, $level, 0); + delete $chances->{horror}; my $excav_stat = { id => $excav->id, chances => $chances, diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index 5858b1be..ed6e06ab 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -163,7 +163,7 @@ sub send_fleet { } my @fleet; my $speed = 999999999; -# my $excavator = 0; + my $excavator = 0; for my $ship_id (@$ship_ids) { my $ship = Lacuna->db->resultset('Lacuna::DB::Result::Ships')->find($ship_id); unless (defined $ship) { @@ -172,15 +172,15 @@ sub send_fleet { unless ($ship->body->empire_id == $empire->id) { confess [1010, 'You do not own that ship.']; } -# if ($ship->type eq 'excavator') { -# $excavator++; -# } + if ($ship->type eq 'excavator') { + $excavator++; + } $speed = $ship->speed if ( $speed > $ship->speed ); push @fleet, $ship_id; } -# unless ($excavator <= 1) { -# confess [1010, 'Only one Excavator may be sent to a body in a 30 day period']; -# } + unless ($excavator <= 1) { + confess [1010, 'Only one Excavator may be sent to a body in a 30 day period']; + } unless ($set_speed <= $speed) { confess [1009, 'Set speed cannot exceed the speed of the slowest ship.']; } diff --git a/lib/Lacuna/RPC/Empire.pm b/lib/Lacuna/RPC/Empire.pm index 2128be5f..2663e7c7 100644 --- a/lib/Lacuna/RPC/Empire.pm +++ b/lib/Lacuna/RPC/Empire.pm @@ -403,6 +403,8 @@ sub view_profile { skip_excavator_resources => $empire->skip_excavator_resources, skip_excavator_glyph => $empire->skip_excavator_glyph, skip_excavator_plan => $empire->skip_excavator_plan, + skip_excavator_artifact => $empire->skip_excavator_artifact, + skip_excavator_destroyed => $empire->skip_excavator_destroyed, skip_spy_recovery => $empire->skip_spy_recovery, skip_probe_detected => $empire->skip_probe_detected, skip_attack_messages => $empire->skip_attack_messages, @@ -526,6 +528,18 @@ sub edit_profile { } $empire->skip_excavator_plan($profile->{skip_excavator_plan}); } + if (exists $profile->{skip_excavator_artifact}) { + if ($profile->{skip_excavator_artifact} < 0 || $profile->{skip_excavator_artifact} > 1) { + confess [1009, 'Skip Excavator Artifact must be a 1 or a 0.', 'skip_excavator_artifact'] + } + $empire->skip_excavator_resources($profile->{skip_excavator_artifact}); + } + if (exists $profile->{skip_excavator_destroyed}) { + if ($profile->{skip_excavator_destroyed} < 0 || $profile->{skip_excavator_destroyed} > 1) { + confess [1009, 'Skip Excavator Destroyed must be a 1 or a 0.', 'skip_excavator_destroyed'] + } + $empire->skip_excavator_resources($profile->{skip_excavator_destroyed}); + } if (exists $profile->{skip_spy_recovery}) { if ($profile->{skip_spy_recovery} < 0 || $profile->{skip_spy_recovery} > 1) { confess [1009, 'Skip Spy Recovery must be a 1 or a 0.', 'skip_spy_recovery'] diff --git a/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm b/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm index 623cf2e7..8aa45096 100644 --- a/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm +++ b/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm @@ -52,8 +52,8 @@ after can_send_to_target => sub { confess [1013, 'Cannot control excavators without an Archaeology.'] unless (defined $archaeology); confess [1013, 'Your Archaeology Ministry must be level 15 or higher in order to send excavators.'] unless ($archaeology->level >= 15); $archaeology->can_add_excavator($target); -# print "Possible to add excav\n"; # Will need to make this only pertaining to excavation later. +# MembersOnlyExcavators if ($target->star->station_id) { if ($target->star->station->laws->search({type => 'MembersOnlyMiningRights'})->count) { unless ($target->star->station->alliance_id == $self->body->empire->alliance_id) { diff --git a/var/upgrades/3.0838.sql b/var/upgrades/3.0838.sql new file mode 100644 index 00000000..79dbcf44 --- /dev/null +++ b/var/upgrades/3.0838.sql @@ -0,0 +1,9 @@ +CREATE TABLE `excavators` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `planet_id` int(11) NOT NULL, + `body_id` int(11) NOT NULL, + `empire_id` int(11) NOT NULL, + PRIMARY KEY (`id`) +); +alter table empire add column `skip_excavator_artifact` tinyint NOT NULL default 0; +alter table empire add column `skip_excavator_destroyed` tinyint NOT NULL default 0; diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 8e5f287d..bb8e500c 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,3 +1,6 @@ +3.0838: + - Mod: Major change to how excavators work. + 3.0837: - Mod: Trade Ministry now trades within a set distance rather than just within zone -- 2.51.2 From 2ef7642d2bcab4916037824c2d5d095b15ffd8d5 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Sun, 29 Jan 2012 11:46:24 -0700 Subject: [PATCH 09/28] Prepped Pod, digs happen once/hour. --- docs/Archaeology.pod | 62 ++++++++++++++++++++ lib/Lacuna/DB/Result/Building/Archaeology.pm | 44 +++++--------- lib/Lacuna/DB/Result/Map/Body.pm | 1 + lib/Lacuna/DB/Result/Map/Body/Planet.pm | 26 +++++--- var/upgrades/3.0838.sql | 1 + 5 files changed, 98 insertions(+), 36 deletions(-) diff --git a/docs/Archaeology.pod b/docs/Archaeology.pod index aca05c83..113cdd15 100644 --- a/docs/Archaeology.pod +++ b/docs/Archaeology.pod @@ -119,7 +119,69 @@ A session id. The unique id of the Archaeology Ministry. +=head2 view_excavators ( session_id, building_id ) +Returns a list of the excavator sites currently controlled by this ministry. + + { + "status" : { ... }, + "max_excavators" : 1, + "excavators" : [ + { + "id" : "id-goes-here", + "body" : { + "id" : "id-goes-here", + "name" : "Kuiper", + "x" : 0, + "y" : -444, + "image" : "a1-5", + ... + }, + "excavator" : { + "chances" : { + "artifact" : 50, + "glyph" : 301, + "plan" : 70, + "resource" : 528 + } + } + }, + ... + ] + } + +The C numbers give the chances out of 1000 that a certain result is found by your excavator each hour. + +=head3 session_id + +A session id. + +=head3 building_id + +The unique id of the archaeology ministry. + + +=head2 abandon_excavator ( session_id, building_id, site_id ) + +Close down an existing excavator site. + + { + "status" : { ... } + } + +Throws 1002. + +=head3 session_id + +A session id. + +=head3 building_id + +The unique id of the archaeology ministry. + +=head3 site_id + +The unique id of the excavator site you wish to abandon. =cut diff --git a/lib/Lacuna/DB/Result/Building/Archaeology.pm b/lib/Lacuna/DB/Result/Building/Archaeology.pm index 895163be..88f5b06f 100644 --- a/lib/Lacuna/DB/Result/Building/Archaeology.pm +++ b/lib/Lacuna/DB/Result/Building/Archaeology.pm @@ -74,31 +74,12 @@ sub max_excavators { return ($self->level - 14); } -# sub add_ship { -# my ($self, $ship) = @_; -# $ship->task('Excavating'); -# $ship->update; -# $self->recalc_excavating; -# return $self; -# } - -# sub send_ship_home { -# my ($self, $body, $ship) = @_; -# $ship->send( -# target => $body, -# direction => 'in', -# task => 'Travelling', -# ); -# $self->recalc_excavating; -# return $self; -# } - sub run_excavators { my $self = shift; my $level = $self->level; my $empire = $self->body->empire; -# Do once for arch itself. No chance of h orrors or artifacts. +# Do once for arch itself. No chance of horrors or artifacts. my $result = $self->dig_it($self->body, $level, 1); $result->{id} = $self->id; my @results = ($result); @@ -108,12 +89,13 @@ sub run_excavators { my $body = $excav->body; my $result; if ($body->empire_id) { -#Oops, we didn't clean off the excav when settled. +# Clean off the excav if planet gets settled. $result = { id => $excav->id, site => $body->name, outcome => "Destroyed", - message => "Colony wiped out dig.", + message => sprintf "Dig wiped out by new Colony from %s.", + $body->empire->name, }; } else { @@ -241,15 +223,15 @@ sub found_plan { my $plus = 0; if ($rand_cat < 1) { $class = random_element($plan_types->{special}); - $plus = randint(0, int($level/7)); + $plus = randint(0, int($level/7)) if (randint(0,19) < 1); } elsif ($rand_cat < 10) { $class = random_element($plan_types->{natural}); - $plus = randint(1, int($level/7)+1) if (randint(0,3) < 1); + $plus = randint(1, int($level/7)+1) if (randint(0,9) < 1); } else { $class = random_element($plan_types->{decor}); - $plus = randint(1, int($level/5)+1) if (randint(0,2) < 1); + $plus = randint(1, int($level/5)+1) if (randint(0,4) < 1); } my $plan = $self->body->add_plan($class, $lvl, $plus); @@ -273,7 +255,7 @@ sub found_artifact { if ($level > $select->level and randint(1, int(3 * $level/2)) >= $select->level) { $class = $select->class; $lvl = 1; - $plus = $select->level - 1; + $plus = int( ($select->level - 1) * 2/3); #Max doable would be 1+18 $name = $select->name; $destroy = 100; } @@ -286,15 +268,19 @@ sub found_artifact { } else { $class = $select->class; - $lvl = randint(1,$select->level); + $lvl = randint(1,$select->level); # Slight chance of getting a level 30 plan. $plus = 0; $name = $select->name; $destroy = 25; } $self->body->add_plan($class, $lvl, $plus); - if (randint(0,99) < $destroy) { + if ($select->level == 1 or randint(0,99) < $destroy) { $select->delete; } + else { + $select->level($select->level - 1); + $select->update; + } return ($lvl, $plus, $name); } @@ -341,7 +327,7 @@ sub can_you_dig_it { $artifact = 50; } my $horror = $arch ? 0 : 1; - $horror += 2 * $artifact; + $horror += $artifact; my $most = $plan + $glyph + $artifact + $horror; if ($most + $resource > 1000) { $resource -= ($most + $resource - 1000); diff --git a/lib/Lacuna/DB/Result/Map/Body.pm b/lib/Lacuna/DB/Result/Map/Body.pm index d2d8c7f8..de97d0bf 100644 --- a/lib/Lacuna/DB/Result/Map/Body.pm +++ b/lib/Lacuna/DB/Result/Map/Body.pm @@ -122,6 +122,7 @@ __PACKAGE__->add_columns( restrict_coverage => { data_type => 'tinyint', default_value => 0 }, plots_available => { data_type => 'tinyint', default_value => 0 }, surface_version => { data_type => 'tinyint', default_value => 0 }, + last_dig => { data_type => 'datetime', is_nullable => 0, set_on_create => 1 }, ); after 'sqlt_deploy_hook' => sub { diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 5c951c8b..c311ac32 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -1057,12 +1057,6 @@ sub tick { $i++; } - # Process excavator sites - if ( my $arch = $self->archaeology and - not Lacuna->cache->get('excavator_'.$self->id)) { - $arch->run_excavators; - Lacuna->cache->set('excavator_'.$self->id, 1, 600 ); - } # get ship tasks my $ships = Lacuna->db->resultset('Lacuna::DB::Result::Ships')->search({ body_id => $self->id, @@ -1147,12 +1141,30 @@ sub tick { sub tick_to { my ($self, $now) = @_; - my $seconds = $now->epoch - $self->last_tick->epoch; + my $seconds = $now->epoch - $self->last_tick->epoch; my $tick_rate = $seconds / 3600; $self->last_tick($now); if ($self->needs_recalc) { $self->recalc_stats; } + # Process excavator sites + if ( my $arch = $self->archaeology) { + if ($arch->efficiency == 100) { + my $dig_sec = $now->epoch - $self->last_dig->epoch; + if ($dig_sec >= 3600) { + my $dig_hours = int($dig_sec/3600); + my $new_ld = $self->last_dig->add( seconds => ($dig_hours * 3600)); + $dig_hours = 3 if $dig_hours > 3; + for (1..$dig_hours) { + $arch->run_excavators; + } + $self->last_dig($new_ld); + } + } + else { + $self->last_dig($now); + } + } # happiness $self->add_happiness(sprintf('%.0f', $self->happiness_hour * $tick_rate)); diff --git a/var/upgrades/3.0838.sql b/var/upgrades/3.0838.sql index 79dbcf44..ffe5bb64 100644 --- a/var/upgrades/3.0838.sql +++ b/var/upgrades/3.0838.sql @@ -7,3 +7,4 @@ CREATE TABLE `excavators` ( ); alter table empire add column `skip_excavator_artifact` tinyint NOT NULL default 0; alter table empire add column `skip_excavator_destroyed` tinyint NOT NULL default 0; +alter table body add column `last_dig` datetime NOT NULL default '2012-01-29 15:00:00'; -- 2.51.2 From 9ed4ec449749bd1c87a39182cf7df8dd7cd61019 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Sun, 29 Jan 2012 14:02:19 -0700 Subject: [PATCH 10/28] Rethought excav ship costs. --- lib/Lacuna/DB/Result/Ships/Excavator.pm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Lacuna/DB/Result/Ships/Excavator.pm b/lib/Lacuna/DB/Result/Ships/Excavator.pm index 34b68f95..a321b5d3 100644 --- a/lib/Lacuna/DB/Result/Ships/Excavator.pm +++ b/lib/Lacuna/DB/Result/Ships/Excavator.pm @@ -14,12 +14,12 @@ use constant prereq => { class=> 'Lacuna::DB::Result::Building:: # use constant base_time_cost => 20000; # use constant base_waste_cost => 1200; # use constant base_speed => 1800; -use constant base_food_cost => 100000; -use constant base_water_cost => 200000; -use constant base_energy_cost => 500000; -use constant base_ore_cost => 900000; +use constant base_food_cost => 3000; +use constant base_water_cost => 5000; +use constant base_energy_cost => 20000; +use constant base_ore_cost => 80000; use constant base_time_cost => 8 * 60 * 60; -use constant base_waste_cost => 300000; +use constant base_waste_cost => 10000; use constant base_speed => 1000; use constant base_stealth => 0; use constant base_hold_size => 0; -- 2.51.2 From 060ede8259d73c7b74094787fce80efe2882e518 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Sun, 29 Jan 2012 17:41:42 -0700 Subject: [PATCH 11/28] Fixed downgrade for arch's below level 15. --- lib/Lacuna/DB/Result/Building/Archaeology.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Lacuna/DB/Result/Building/Archaeology.pm b/lib/Lacuna/DB/Result/Building/Archaeology.pm index 88f5b06f..477c6b8c 100644 --- a/lib/Lacuna/DB/Result/Building/Archaeology.pm +++ b/lib/Lacuna/DB/Result/Building/Archaeology.pm @@ -543,10 +543,11 @@ sub make_plan { before 'can_downgrade' => sub { my $self = shift; - if ($self->excavators->count > ($self->level - 15)) { + my $ecount = $self->excavators->count; + if ($ecount > 0 and $ecount > ($self->level - 15)) { confess [1013, 'You must abandon one of your Excavator Sites before you can downgrade the Archaeology Ministry.']; } - if ($self->excavators->count && ($self->level -1) < 15 ) { + if ($ecount > 0 && ($self->level -1) < 15 ) { confess [1013, 'You can not have any Excavator Sites if you are to downgrade your Archaeology Ministry below 15.']; } }; -- 2.51.2 From d2d699ec99da067f23818f2d6f1bd3718d196c4d Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 31 Jan 2012 16:26:27 -0700 Subject: [PATCH 12/28] last_check moved to building. n19 added. Percents messed with. --- lib/Lacuna/DB/Result/Building.pm | 7 ++ lib/Lacuna/DB/Result/Building/Archaeology.pm | 70 +++++++++++++------- lib/Lacuna/DB/Result/Map/Body.pm | 1 - lib/Lacuna/DB/Result/Map/Body/Planet.pm | 10 +-- lib/Lacuna/RPC/Building/Archaeology.pm | 2 +- var/upgrades/3.0838.sql | 6 +- 6 files changed, 62 insertions(+), 34 deletions(-) diff --git a/lib/Lacuna/DB/Result/Building.pm b/lib/Lacuna/DB/Result/Building.pm index 7cfc0c0e..a27245e3 100755 --- a/lib/Lacuna/DB/Result/Building.pm +++ b/lib/Lacuna/DB/Result/Building.pm @@ -25,6 +25,8 @@ __PACKAGE__->add_columns( is_working => { data_type => 'bit', default => 0 }, work => { data_type => 'mediumblob', is_nullable => 1, 'serializer_class' => 'JSON' }, efficiency => { data_type => 'int', default_value => 100, is_nullable => 0 }, + last_check => { data_type => 'datetime', is_nullable => 0, set_on_create => 1 }, + ); sub sqlt_deploy_hook { @@ -862,6 +864,11 @@ sub finish_work { return $self; } +sub last_check_formatted { + my $self = shift; + return format_date($self->last_check); +} + # EFFICIENCY / REPAIR sub is_offline { diff --git a/lib/Lacuna/DB/Result/Building/Archaeology.pm b/lib/Lacuna/DB/Result/Building/Archaeology.pm index 477c6b8c..c963524c 100644 --- a/lib/Lacuna/DB/Result/Building/Archaeology.pm +++ b/lib/Lacuna/DB/Result/Building/Archaeology.pm @@ -79,7 +79,7 @@ sub run_excavators { my $level = $self->level; my $empire = $self->body->empire; -# Do once for arch itself. No chance of horrors or artifacts. +# Do once for arch itself. No chance of destroy or artifacts. my $result = $self->dig_it($self->body, $level, 1); $result->{id} = $self->id; my @results = ($result); @@ -102,6 +102,7 @@ sub run_excavators { $result = $self->dig_it($body, $level, 0); $result->{id} = $excav->id; } +#N19 push @results, $result; if ($result->{outcome} eq "Destroyed") { $self->remove_excavator($excav); @@ -138,11 +139,12 @@ sub dig_it { my ($self, $body, $level, $arch) = @_; my $chances = $self->can_you_dig_it($body, $level, $arch); + my $empire_name = $self->body->empire->name; - my $rnum = randint(0,999); + my $rnum = randint(0,99); my $base = 0; my $outcome = "nothing"; - for my $type (qw(horror artifact plan glyph resource)) { + for my $type (qw(destroy artifact plan glyph resource)) { if ($rnum < $chances->{$type} + $base) { $outcome = $type; last; @@ -159,6 +161,8 @@ sub dig_it { message => "Found $amount of $type.", outcome => "Resource", }; + $self->body->add_news(1,sprintf("%s uncovered a cache of %s on %s.", + $empire_name, $type, $body->name)); } when ("plan") { my ($lvl, $plus, $name) = $self->found_plan($level); @@ -166,6 +170,8 @@ sub dig_it { message => "Found level $lvl + $plus $name Plan.", outcome => "Plan", }; + $self->body->add_news(5,sprintf("%s uncovered a %s plan on %s.", + $empire_name, $name, $body->name)); } when ("glyph") { my $glyph = $self->found_glyph($body); @@ -173,6 +179,8 @@ sub dig_it { message => "Found a $glyph glyph.", outcome => "Glyph", }; + $self->body->add_news(5,sprintf("%s uncovered a %s glyph on %s.", + $empire_name, $glyph, $body->name)); } when ("artifact") { my ($lvl, $plus, $name) = $self->found_artifact($body, $level); @@ -187,19 +195,31 @@ sub dig_it { message => "Found level $lvl + $plus $name Plan.", outcome => "Artifact", }; + $self->body->add_news(20,sprintf("%s uncovered a rare %s plan on %s.", + $empire_name, $name, $body->name)); } } - when ("horror") { - my $message = random_element([ - 'Ph\'nglui Mglw\'nafh Cthulhu R\'lyeh wgah\'nagi fhtagn.', - 'Klaatu Barada Ni*cough*', - 'The brazen temple doors open...', - 'It\'s full of stars' - ]); - $result = { - message => $message, - outcome => "Destroyed", - }; + when ("destroy") { + if (randint(0,99) < 10) { +# This should give an excavator a + my $message = random_element([ + 'Ph\'nglui Mglw\'nafh Cthulhu R\'lyeh wgah\'nagi fhtagn.', + 'Klaatu Barada Ni*cough*', + 'The brazen temple doors open...', + 'It\'s full of stars' + ]); + $result = { + message => $message, + outcome => "Destroyed", + }; + $self->body->add_news(10, $message); + } + else { + $result = { + message => "No results found.", + outcome => "Nothing", + }; + } } default { $result = { @@ -314,30 +334,30 @@ sub can_you_dig_it { my ($self, $body, $level, $arch) = @_; my $mult = $arch + 1; - my $plan = ($level/5+1) * $mult * 10; # 2.4-14% + my $plan = ($level/5+1) * $mult; # 2.4-14% my $ore_total = 0; for my $ore (ORE_TYPES) { $ore_total += $body->$ore; } - my $glyph = int(10* $mult * $level * $ore_total/10_000)+1; #max 1-60% - $glyph = 600 if ($glyph > 600); - my $resource = 10 * 2 * $level; # 2-60% + $ore_total = 10_000 if $ore_total > 10_000; + my $glyph = int($mult * $level * $ore_total/10_000)+1; # 1-30% (2x if arch run) + my $resource = 2 * $level; # 2-60% my $artifact = 0; if (!$arch && $body->buildings->count) { - $artifact = 50; + $artifact = 5; } - my $horror = $arch ? 0 : 1; - $horror += $artifact; - my $most = $plan + $glyph + $artifact + $horror; - if ($most + $resource > 1000) { - $resource -= ($most + $resource - 1000); + my $destroy = $arch ? 0 : 1; + $destroy += $artifact; + my $most = $plan + $glyph + $artifact + $destroy; + if ($most + $resource > 100) { + $resource -= ($most + $resource - 100); } my $return = { plan => $plan, glyph => $glyph, resource => $resource, artifact => $artifact, - horror => $horror, + destroy => $destroy, }; return $return; } diff --git a/lib/Lacuna/DB/Result/Map/Body.pm b/lib/Lacuna/DB/Result/Map/Body.pm index de97d0bf..d2d8c7f8 100644 --- a/lib/Lacuna/DB/Result/Map/Body.pm +++ b/lib/Lacuna/DB/Result/Map/Body.pm @@ -122,7 +122,6 @@ __PACKAGE__->add_columns( restrict_coverage => { data_type => 'tinyint', default_value => 0 }, plots_available => { data_type => 'tinyint', default_value => 0 }, surface_version => { data_type => 'tinyint', default_value => 0 }, - last_dig => { data_type => 'datetime', is_nullable => 0, set_on_create => 1 }, ); after 'sqlt_deploy_hook' => sub { diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index c311ac32..c69a922e 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -1150,19 +1150,21 @@ sub tick_to { # Process excavator sites if ( my $arch = $self->archaeology) { if ($arch->efficiency == 100) { - my $dig_sec = $now->epoch - $self->last_dig->epoch; + my $dig_sec = $now->epoch - $arch->last_check->epoch; if ($dig_sec >= 3600) { my $dig_hours = int($dig_sec/3600); - my $new_ld = $self->last_dig->add( seconds => ($dig_hours * 3600)); + my $new_ld = $arch->last_check->add( seconds => ($dig_hours * 3600)); $dig_hours = 3 if $dig_hours > 3; for (1..$dig_hours) { $arch->run_excavators; } - $self->last_dig($new_ld); + $arch->last_check($new_ld); + $arch->update; } } else { - $self->last_dig($now); + $arch->last_check($now); + $arch->update; } } # happiness diff --git a/lib/Lacuna/RPC/Building/Archaeology.pm b/lib/Lacuna/RPC/Building/Archaeology.pm index 9fc75380..e99dc482 100644 --- a/lib/Lacuna/RPC/Building/Archaeology.pm +++ b/lib/Lacuna/RPC/Building/Archaeology.pm @@ -103,7 +103,7 @@ sub view_excavators { while (my $excav = $excavators->next) { my $body = $excav->body; my $chances = $building->can_you_dig_it($body, $level, 0); - delete $chances->{horror}; + delete $chances->{destroy}; my $excav_stat = { id => $excav->id, chances => $chances, diff --git a/var/upgrades/3.0838.sql b/var/upgrades/3.0838.sql index ffe5bb64..e973e7f3 100644 --- a/var/upgrades/3.0838.sql +++ b/var/upgrades/3.0838.sql @@ -5,6 +5,6 @@ CREATE TABLE `excavators` ( `empire_id` int(11) NOT NULL, PRIMARY KEY (`id`) ); -alter table empire add column `skip_excavator_artifact` tinyint NOT NULL default 0; -alter table empire add column `skip_excavator_destroyed` tinyint NOT NULL default 0; -alter table body add column `last_dig` datetime NOT NULL default '2012-01-29 15:00:00'; +alter table empire add column `skip_excavator_artifact` tinyint NOT NULL default 0; +alter table empire add column `skip_excavator_destroyed` tinyint NOT NULL default 0; +alter table building add column `last_check` datetime NOT NULL default '2012-01-31 15:00:00'; -- 2.51.2 From 2051d418b6b93f17e82234970e998f6c004e2ac9 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 31 Jan 2012 17:21:47 -0700 Subject: [PATCH 13/28] Updated pod. --- docs/Archaeology.pod | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/Archaeology.pod b/docs/Archaeology.pod index 113cdd15..04f131db 100644 --- a/docs/Archaeology.pod +++ b/docs/Archaeology.pod @@ -139,10 +139,10 @@ Returns a list of the excavator sites currently controlled by this ministry. }, "excavator" : { "chances" : { - "artifact" : 50, - "glyph" : 301, - "plan" : 70, - "resource" : 528 + "artifact" : 5, + "glyph" : 30, + "plan" : 7, + "resource" : 53 } } }, @@ -150,7 +150,7 @@ Returns a list of the excavator sites currently controlled by this ministry. ] } -The C numbers give the chances out of 1000 that a certain result is found by your excavator each hour. +The C numbers give the chances out of 100 that a certain result is found by your excavator each hour. =head3 session_id -- 2.51.2 From a3f3afa38be76706fe7e9de93ba8e7044e561ecf Mon Sep 17 00:00:00 2001 From: lemming552 Date: Wed, 1 Feb 2012 20:12:22 -0700 Subject: [PATCH 14/28] Dropping Excav entry to level 11. --- lib/Lacuna/DB/Result/Building/Archaeology.pm | 18 +++++++++--------- lib/Lacuna/DB/Result/Ships/Excavator.pm | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/Lacuna/DB/Result/Building/Archaeology.pm b/lib/Lacuna/DB/Result/Building/Archaeology.pm index c963524c..70852667 100644 --- a/lib/Lacuna/DB/Result/Building/Archaeology.pm +++ b/lib/Lacuna/DB/Result/Building/Archaeology.pm @@ -70,8 +70,8 @@ sub get_ores_available_for_processing { sub max_excavators { my $self = shift; - return 0 if ($self->level < 15); - return ($self->level - 14); + return 0 if ($self->level < 11); + return ($self->level - 10); } sub run_excavators { @@ -83,7 +83,7 @@ sub run_excavators { my $result = $self->dig_it($self->body, $level, 1); $result->{id} = $self->id; my @results = ($result); - if ($level > 14) { + if ($level > 10) { my $excavators = $self->excavators; while (my $excav = $excavators->next) { my $body = $excav->body; @@ -200,8 +200,8 @@ sub dig_it { } } when ("destroy") { - if (randint(0,99) < 10) { -# This should give an excavator a + if (randint(0,99) < 5) { +# This should give an excavator a 1.2% survival each day. Unless on artifact planets. my $message = random_element([ 'Ph\'nglui Mglw\'nafh Cthulhu R\'lyeh wgah\'nagi fhtagn.', 'Klaatu Barada Ni*cough*', @@ -344,7 +344,7 @@ sub can_you_dig_it { my $resource = 2 * $level; # 2-60% my $artifact = 0; if (!$arch && $body->buildings->count) { - $artifact = 5; + $artifact = 10; } my $destroy = $arch ? 0 : 1; $destroy += $artifact; @@ -564,11 +564,11 @@ sub make_plan { before 'can_downgrade' => sub { my $self = shift; my $ecount = $self->excavators->count; - if ($ecount > 0 and $ecount > ($self->level - 15)) { + if ($ecount > 0 and $ecount > ($self->level - 11)) { confess [1013, 'You must abandon one of your Excavator Sites before you can downgrade the Archaeology Ministry.']; } - if ($ecount > 0 && ($self->level -1) < 15 ) { - confess [1013, 'You can not have any Excavator Sites if you are to downgrade your Archaeology Ministry below 15.']; + if ($ecount > 0 && ($self->level -1) < 11 ) { + confess [1013, 'You can not have any Excavator Sites if you are to downgrade your Archaeology Ministry below 11.']; } }; diff --git a/lib/Lacuna/DB/Result/Ships/Excavator.pm b/lib/Lacuna/DB/Result/Ships/Excavator.pm index a321b5d3..bd93f7b8 100644 --- a/lib/Lacuna/DB/Result/Ships/Excavator.pm +++ b/lib/Lacuna/DB/Result/Ships/Excavator.pm @@ -5,7 +5,7 @@ use utf8; no warnings qw(uninitialized); extends 'Lacuna::DB::Result::Ships'; -use constant prereq => { class=> 'Lacuna::DB::Result::Building::Archaeology', level => 15 }; +use constant prereq => { class=> 'Lacuna::DB::Result::Building::Archaeology', level => 11 }; # Keeping Old prices around just while testing stuff # use constant base_food_cost => 400; # use constant base_water_cost => 1000; -- 2.51.2 From 32785b4af56c6116d8b9f7a15a44359611c748f1 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Thu, 2 Feb 2012 12:36:54 -0700 Subject: [PATCH 15/28] Detonators, Pod, N19, return values, and some probabilities. --- docs/Archaeology.pod | 12 +- lib/Lacuna.pm | 2 +- lib/Lacuna/DB/Result/Ships/Detonator.pm | 4 +- lib/Lacuna/RPC/Building/Archaeology.pm | 13 +- .../Ship/Arrive/DestroyMinersExcavators.pm | 128 ++++++++++++++++++ .../Role/Ship/Send/AsteroidStarUninhabited.pm | 13 ++ .../detonator_destroyed_excavators.txt | 7 + .../detonator_destroyed_mining_excavators.txt | 7 + var/messages/detonator_wasted.txt | 7 + var/messages/excavator_destroyed.txt | 7 + var/www/public/changes.txt | 6 + 11 files changed, 188 insertions(+), 18 deletions(-) create mode 100644 lib/Lacuna/Role/Ship/Arrive/DestroyMinersExcavators.pm create mode 100644 lib/Lacuna/Role/Ship/Send/AsteroidStarUninhabited.pm create mode 100644 var/messages/detonator_destroyed_excavators.txt create mode 100644 var/messages/detonator_destroyed_mining_excavators.txt create mode 100644 var/messages/detonator_wasted.txt create mode 100644 var/messages/excavator_destroyed.txt diff --git a/docs/Archaeology.pod b/docs/Archaeology.pod index 04f131db..9d29306e 100644 --- a/docs/Archaeology.pod +++ b/docs/Archaeology.pod @@ -137,14 +137,10 @@ Returns a list of the excavator sites currently controlled by this ministry. "image" : "a1-5", ... }, - "excavator" : { - "chances" : { - "artifact" : 5, - "glyph" : 30, - "plan" : 7, - "resource" : 53 - } - } + "artifact" : 5, + "glyph" : 30, + "plan" : 7, + "resource" : 53 }, ... ] diff --git a/lib/Lacuna.pm b/lib/Lacuna.pm index d9e78ca7..daa42937 100644 --- a/lib/Lacuna.pm +++ b/lib/Lacuna.pm @@ -7,7 +7,7 @@ use Config::JSON; useall __PACKAGE__; -our $VERSION = 3.0838; +our $VERSION = 3.0839; 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/Ships/Detonator.pm b/lib/Lacuna/DB/Result/Ships/Detonator.pm index 660b5a28..27c2031c 100644 --- a/lib/Lacuna/DB/Result/Ships/Detonator.pm +++ b/lib/Lacuna/DB/Result/Ships/Detonator.pm @@ -18,11 +18,11 @@ use constant base_stealth => 0; use constant base_hold_size => 0; use constant build_tags => ['War']; -with "Lacuna::Role::Ship::Send::AsteroidAndStar"; +with "Lacuna::Role::Ship::Send::AsteroidStarUninhabited"; with "Lacuna::Role::Ship::Send::IsHostile"; with "Lacuna::Role::Ship::Arrive::TriggerDefense"; with "Lacuna::Role::Ship::Arrive::DestroyProbes"; -with "Lacuna::Role::Ship::Arrive::DestroyMiningPlatforms"; +with "Lacuna::Role::Ship::Arrive::DestroyMinersExcavators"; no Moose; __PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/RPC/Building/Archaeology.pm b/lib/Lacuna/RPC/Building/Archaeology.pm index e99dc482..334d2dd8 100644 --- a/lib/Lacuna/RPC/Building/Archaeology.pm +++ b/lib/Lacuna/RPC/Building/Archaeology.pm @@ -103,14 +103,13 @@ sub view_excavators { while (my $excav = $excavators->next) { my $body = $excav->body; my $chances = $building->can_you_dig_it($body, $level, 0); - delete $chances->{destroy}; - my $excav_stat = { - id => $excav->id, - chances => $chances, - }; push @sites, { - excavator => $excav_stat, - body => $excav->body->get_status, + body => $excav->body->get_status, + id => $excav->id, + artifact => $chances->{artifact}, + glyph => $chances->{glyph}, + plan => $chances->{plan}, + resource => $chances->{resource}, }; } return { diff --git a/lib/Lacuna/Role/Ship/Arrive/DestroyMinersExcavators.pm b/lib/Lacuna/Role/Ship/Arrive/DestroyMinersExcavators.pm new file mode 100644 index 00000000..de52880a --- /dev/null +++ b/lib/Lacuna/Role/Ship/Arrive/DestroyMinersExcavators.pm @@ -0,0 +1,128 @@ +package Lacuna::Role::Ship::Arrive::DestroyMinersExcavators; + +use strict; +use Moose::Role; + +after handle_arrival_procedures => sub { + my ($self) = @_; + + # we're coming home + return if ($self->direction eq 'in'); + + my $body_attacked = $self->foreign_body; + my $is_asteroid = $body_attacked->isa('Lacuna::DB::Result::Map::Body::Asteroid'); + my $is_uninhabit = ($body_attacked->isa('Lacuna::DB::Result::Map::Body::Planet') and !(defined($body_attacked->empire_id)) ); +# not an asteroid or uninhabited planet + return unless ( $self->foreign_body_id && ($is_asteroid || $is_uninhabit)); + + my $logs = Lacuna->db->resultset('Lacuna::DB::Result::Log::Battles'); + my $mcount = 0; + my $ecount = 0; +# find mining platforms to destroy + if ($is_asteroid) { + my $platforms = Lacuna->db->resultset('Lacuna::DB::Result::MiningPlatforms')->search({asteroid_id => $self->foreign_body_id }); +# destroy those suckers + while (my $platform = $platforms->next) { + my $empire = $platform->planet->empire; + + unless ($empire->skip_attack_messages) { + $empire->send_predefined_message( + tags => ['Attack','Alert'], + filename => 'mining_platform_destroyed.txt', + params => [$body_attacked->x, $body_attacked->y, $body_attacked->name, $self->body->empire_id, $self->body->empire->name], + ); + } + + $logs->new({ + date_stamp => DateTime->now, + attacking_empire_id => $self->body->empire_id, + attacking_empire_name => $self->body->empire->name, + attacking_body_id => $self->body_id, + attacking_body_name => $self->body->name, + attacking_unit_name => $self->name, + attacking_type => $self->type_formatted, + defending_empire_id => $empire->id, + defending_empire_name => $empire->name, + defending_body_id => $body_attacked->id, + defending_body_name => $body_attacked->name, + defending_unit_name => 'Mining Platform', + defending_type => 'Mining Platform', + attacked_empire_id => $empire->id, + attacked_empire_name => $empire->name, + attacked_body_id => $body_attacked->id, + attacked_body_name => $body_attacked->name, + victory_to => 'attacker', + })->insert; + $mcount++; + $platform->delete; + } + } +# Destroy Excavs + my $excavs = Lacuna->db->resultset('Lacuna::DB::Result::Excavators')->search({body_id => $self->foreign_body_id }); + while (my $excav = $excavs->next) { + my $empire = $excav->planet->empire; + + unless ($empire->skip_attack_messages) { + $empire->send_predefined_message( + tags => ['Attack','Alert'], + filename => 'excavator_destroyed.txt', + params => [$body_attacked->x, $body_attacked->y, $body_attacked->name, $self->body->empire_id, $self->body->empire->name], + ); + } + + $logs->new({ + date_stamp => DateTime->now, + attacking_empire_id => $self->body->empire_id, + attacking_empire_name => $self->body->empire->name, + attacking_body_id => $self->body_id, + attacking_body_name => $self->body->name, + attacking_unit_name => $self->name, + attacking_type => $self->type_formatted, + defending_empire_id => $empire->id, + defending_empire_name => $empire->name, + defending_body_id => $body_attacked->id, + defending_body_name => $body_attacked->name, + defending_unit_name => 'Excavator', + defending_type => 'Excavator', + attacked_empire_id => $empire->id, + attacked_empire_name => $empire->name, + attacked_body_id => $body_attacked->id, + attacked_body_name => $body_attacked->name, + victory_to => 'attacker', + })->insert; + $ecount++; + $excav->delete; + } + # notify about destruction + $self->body->add_news(20, sprintf("A bright flash was observed on the surface of %s today.", $body_attacked->name)); + unless ($self->body->empire->skip_attack_messages) { + my $filename; my $params; + if ($mcount > 0 and $ecount > 0) { + $filename = "detonator_destroyed_mining_excavators.txt"; + $params = [$mcount, $ecount, $body_attacked->x, $body_attacked->y, $body_attacked->name]; + } + elsif ($mcount > 0) { + $filename = "detonator_destroyed_mining_platforms.txt"; + $params = [$mcount, $body_attacked->x, $body_attacked->y, $body_attacked->name]; + } + elsif ($ecount > 0) { + $filename = "detonator_destroyed_excavators.txt"; + $params = [$ecount, $body_attacked->x, $body_attacked->y, $body_attacked->name]; + } + else { + $filename = "detonator_wasted.txt"; + $params = [$body_attacked->x, $body_attacked->y, $body_attacked->name]; + } + $self->body->empire->send_predefined_message( + tags => ['Attack','Alert'], + filename => $filename, + params => $params, + ); + } + + # it's all over but the cryin + $self->delete; + confess [-1]; +}; + +1; diff --git a/lib/Lacuna/Role/Ship/Send/AsteroidStarUninhabited.pm b/lib/Lacuna/Role/Ship/Send/AsteroidStarUninhabited.pm new file mode 100644 index 00000000..7e524408 --- /dev/null +++ b/lib/Lacuna/Role/Ship/Send/AsteroidStarUninhabited.pm @@ -0,0 +1,13 @@ +package Lacuna::Role::Ship::Send::AsteroidStarUninhabited; + +use strict; +use Moose::Role; + +after can_send_to_target => sub { + my ($self, $target) = @_; + confess [1009, 'Can only be sent to asteroids, stars, and uninhabited planets.'] unless + ( $target->isa('Lacuna::DB::Result::Map::Body::Asteroid') || $target->isa('Lacuna::DB::Result::Map::Star') || + ($target->isa('Lacuna::DB::Result::Map::Body::Planet') and !(defined($target->empire_id)) )); +}; + +1; diff --git a/var/messages/detonator_destroyed_excavators.txt b/var/messages/detonator_destroyed_excavators.txt new file mode 100644 index 00000000..69a3ec40 --- /dev/null +++ b/var/messages/detonator_destroyed_excavators.txt @@ -0,0 +1,7 @@ +Detonator Report +~~~ +Our Detonator has destroyed %s excavators on {Starmap %s %s %s}. + +Regards, + +Your Humble Assistant diff --git a/var/messages/detonator_destroyed_mining_excavators.txt b/var/messages/detonator_destroyed_mining_excavators.txt new file mode 100644 index 00000000..27a2d361 --- /dev/null +++ b/var/messages/detonator_destroyed_mining_excavators.txt @@ -0,0 +1,7 @@ +Detonator Report +~~~ +Our Detonator has destroyed %s mining platforms and %s excavators on {Starmap %s %s %s}. + +Regards, + +Your Humble Assistant diff --git a/var/messages/detonator_wasted.txt b/var/messages/detonator_wasted.txt new file mode 100644 index 00000000..02842d97 --- /dev/null +++ b/var/messages/detonator_wasted.txt @@ -0,0 +1,7 @@ +Detonator Report +~~~ +Our Detonator was wasted on {Starmap %s %s %s}. + +Regards, + +Your Humble Assistant diff --git a/var/messages/excavator_destroyed.txt b/var/messages/excavator_destroyed.txt new file mode 100644 index 00000000..277b4705 --- /dev/null +++ b/var/messages/excavator_destroyed.txt @@ -0,0 +1,7 @@ +Excavating Site Destroyed +~~~ +We just lost contact with our excavating site on {Starmap %s %s %s}. Just before it went dark, our excavator transmitted an image of an incoming ship. We've determined it was a Detonator sent by {Empire %s %s}. We must assume the excavator has been destroyed. + +Regards, + +Your Humble Assistant diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index bb8e500c..1286976a 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,3 +1,9 @@ +3.0839: + - Mod: Detonators now destroy excavators. + - Mod: N19 reports on excavators and detonators. + - Mod: Updated Archaeology.pod + - Mod: Adjusted percentages of results. + 3.0838: - Mod: Major change to how excavators work. -- 2.51.2 From 533b07387b8ac96b1092645afb748d1c1c2e0ad3 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Mon, 6 Feb 2012 18:41:14 -0700 Subject: [PATCH 16/28] Arch Min probablities passed back with view_excavators. --- lib/Lacuna.pm | 2 +- lib/Lacuna/RPC/Building/Archaeology.pm | 11 ++++++++++- var/www/public/changes.txt | 3 +++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/Lacuna.pm b/lib/Lacuna.pm index daa42937..d04e6880 100644 --- a/lib/Lacuna.pm +++ b/lib/Lacuna.pm @@ -7,7 +7,7 @@ use Config::JSON; useall __PACKAGE__; -our $VERSION = 3.0839; +our $VERSION = 3.0840; 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/RPC/Building/Archaeology.pm b/lib/Lacuna/RPC/Building/Archaeology.pm index 334d2dd8..416d7cb9 100644 --- a/lib/Lacuna/RPC/Building/Archaeology.pm +++ b/lib/Lacuna/RPC/Building/Archaeology.pm @@ -97,9 +97,18 @@ sub view_excavators { my ($self, $session_id, $building_id) = @_; my $empire = $self->get_empire_by_session($session_id); my $building = $self->get_building($empire, $building_id); - my $excavators = $building->excavators; my @sites; my $level = $building->level; + my $chances = $building->can_you_dig_it($building->body, $level, 1); + push @sites, { + body => $building->body->get_status, + id => $building->id, + artifact => $chances->{artifact}, + glyph => $chances->{glyph}, + plan => $chances->{plan}, + resource => $chances->{resource}, + }; + my $excavators = $building->excavators; while (my $excav = $excavators->next) { my $body = $excav->body; my $chances = $building->can_you_dig_it($body, $level, 0); diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 1286976a..e6530191 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,3 +1,6 @@ +3.0840: + - Mod: Include ArchMin is probabilities passed back by view_excavators. + 3.0839: - Mod: Detonators now destroy excavators. - Mod: N19 reports on excavators and detonators. -- 2.51.2 From 2b762e9bdfd860f012efedf38ec76f6eaa4aa369 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 14 Feb 2012 13:53:59 -0700 Subject: [PATCH 17/28] Check on send for Arch 11, not 15. --- lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm b/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm index 8aa45096..ca4701f3 100644 --- a/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm +++ b/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm @@ -9,10 +9,10 @@ after handle_arrival_procedures => sub { # we're coming home return if ($self->direction eq 'in'); - # do we have archaeology of level 15 or greater, if not, turn around + # do we have archaeology of level 11 or greater, if not, turn around my $body = $self->body; my $archaeology = $body->archaeology; - return unless ((defined $archaeology) && ($archaeology->level >= 15)); + return unless ((defined $archaeology) && ($archaeology->level >= 11)); # can we deploy a excavator my $empire = $body->empire; @@ -50,7 +50,7 @@ after can_send_to_target => sub { confess [1009, 'Can only be sent to asteroids and habitable planets.'] if ($target->isa('Lacuna::DB::Result::Map::Body::Planet::GasGiant')); my $archaeology = $self->body->archaeology; confess [1013, 'Cannot control excavators without an Archaeology.'] unless (defined $archaeology); - confess [1013, 'Your Archaeology Ministry must be level 15 or higher in order to send excavators.'] unless ($archaeology->level >= 15); + confess [1013, 'Your Archaeology Ministry must be level 11 or higher in order to send excavators.'] unless ($archaeology->level >= 11); $archaeology->can_add_excavator($target); # Will need to make this only pertaining to excavation later. # MembersOnlyExcavators -- 2.51.2 From a78b703ee25e23c7d8a01b4045abcbae11ece7d8 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Mon, 20 Feb 2012 23:40:12 -0700 Subject: [PATCH 18/28] Added current excavs visible on bodies via get_ships_for from spaceport --- lib/Lacuna/DB/Result/Building/Archaeology.pm | 4 ++-- lib/Lacuna/RPC/Building/SpacePort.pm | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/Lacuna/DB/Result/Building/Archaeology.pm b/lib/Lacuna/DB/Result/Building/Archaeology.pm index 70852667..59d481fb 100644 --- a/lib/Lacuna/DB/Result/Building/Archaeology.pm +++ b/lib/Lacuna/DB/Result/Building/Archaeology.pm @@ -344,9 +344,9 @@ sub can_you_dig_it { my $resource = 2 * $level; # 2-60% my $artifact = 0; if (!$arch && $body->buildings->count) { - $artifact = 10; + $artifact = 15; } - my $destroy = $arch ? 0 : 1; + my $destroy = $arch ? 0 : 2; $destroy += $artifact; my $most = $plan + $glyph + $artifact + $destroy; if ($most + $resource > 100) { diff --git a/lib/Lacuna/RPC/Building/SpacePort.pm b/lib/Lacuna/RPC/Building/SpacePort.pm index ed6e06ab..ba0a1ab4 100644 --- a/lib/Lacuna/RPC/Building/SpacePort.pm +++ b/lib/Lacuna/RPC/Building/SpacePort.pm @@ -124,6 +124,17 @@ sub get_ships_for { }; } } + if ( $target->isa('Lacuna::DB::Result::Map::Body::Asteroid') || + $target->isa('Lacuna::DB::Result::Map::Body::Planet') ) { + 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, + }; + } + } return \%out; } -- 2.51.2 From 6c5a854d34c6192c2785bd24bb30d94231dc6998 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Mon, 27 Feb 2012 16:31:33 -0700 Subject: [PATCH 19/28] Only spend Essentia to prevent self destruct once per day. --- bin/clean_up_empires.pl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bin/clean_up_empires.pl b/bin/clean_up_empires.pl index ec1a8df5..0fc1eee8 100644 --- a/bin/clean_up_empires.pl +++ b/bin/clean_up_empires.pl @@ -61,8 +61,11 @@ my $inactivity_time_out = Lacuna->config->get('self_destruct_after_inactive_days my $inactives = $empires->search({ last_login => { '<' => DateTime->now->subtract( days => $inactivity_time_out ) }, self_destruct_active => 0, id => { '>' => 1}}); while (my $empire = $inactives->next) { if ($empire->essentia >= 1) { + unless (Lacuna->cache->get('empire_inactive',$empire->id)) { out('Preventing self-destruct by spending essentia.'); $empire->spend_essentia(1, 'prevent self-destruct')->update; + Lacuna->cache->set('empire_inactive',$empire->id,1,60*60*24); + } } else { out('Enabling self destruct on '.$empire->name); -- 2.51.2 From e9140a8092b33c0a3b70f6b69dd3aaad6a7fd901 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Mon, 5 Mar 2012 20:46:17 -0700 Subject: [PATCH 20/28] Space Station and excavator interaction. --- lib/Lacuna.pm | 2 +- lib/Lacuna/DB/Result/Building/Archaeology.pm | 6 +- lib/Lacuna/DB/Result/Propositions.pm | 2 + .../DB/Result/Propositions/EvictExcavator.pm | 33 ++++++++++ .../Propositions/MembersOnlyExcavation.pm | 19 ++++++ lib/Lacuna/RPC/Building/Archaeology.pm | 4 +- lib/Lacuna/RPC/Building/Parliament.pm | 63 ++++++++++++++++++- .../Role/Ship/Arrive/DeployExcavator.pm | 4 +- lib/Lacuna/Role/Ship/Arrive/ScanSurface.pm | 13 +++- lib/Lacuna/Role/Ship/Arrive/SurveySurface.pm | 16 ++++- var/messages/parliament_evict_excavator.txt | 3 + var/messages/scan_asteroid.txt | 7 +++ var/www/public/changes.txt | 6 ++ 13 files changed, 167 insertions(+), 11 deletions(-) create mode 100644 lib/Lacuna/DB/Result/Propositions/EvictExcavator.pm create mode 100644 lib/Lacuna/DB/Result/Propositions/MembersOnlyExcavation.pm create mode 100644 var/messages/parliament_evict_excavator.txt create mode 100644 var/messages/scan_asteroid.txt diff --git a/lib/Lacuna.pm b/lib/Lacuna.pm index 04673f7b..a4f7f604 100644 --- a/lib/Lacuna.pm +++ b/lib/Lacuna.pm @@ -7,7 +7,7 @@ use Config::JSON; useall __PACKAGE__; -our $VERSION = 3.0841; +our $VERSION = 3.0842; 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/Building/Archaeology.pm b/lib/Lacuna/DB/Result/Building/Archaeology.pm index 59d481fb..ac301e23 100644 --- a/lib/Lacuna/DB/Result/Building/Archaeology.pm +++ b/lib/Lacuna/DB/Result/Building/Archaeology.pm @@ -340,7 +340,7 @@ sub can_you_dig_it { $ore_total += $body->$ore; } $ore_total = 10_000 if $ore_total > 10_000; - my $glyph = int($mult * $level * $ore_total/10_000)+1; # 1-30% (2x if arch run) + my $glyph = int($mult * $level * $ore_total/15_000)+1; # 1-20% (2x if arch run) +1 my $resource = 2 * $level; # 2-60% my $artifact = 0; if (!$arch && $body->buildings->count) { @@ -349,6 +349,7 @@ sub can_you_dig_it { my $destroy = $arch ? 0 : 2; $destroy += $artifact; my $most = $plan + $glyph + $artifact + $destroy; +# resources get cut down if over 100% if ($most + $resource > 100) { $resource -= ($most + $resource - 100); } @@ -442,6 +443,9 @@ sub excavators { sub can_add_excavator { my ($self, $body, $on_arrival) = @_; + if (defined($body->empire_id)) { + confess [1010, $body->name.' was colonized since we launched our excavator.']; + } # excavator count for archaeology my $count = $self->excavators->count; unless ($on_arrival) { diff --git a/lib/Lacuna/DB/Result/Propositions.pm b/lib/Lacuna/DB/Result/Propositions.pm index 95a4550a..9af37106 100644 --- a/lib/Lacuna/DB/Result/Propositions.pm +++ b/lib/Lacuna/DB/Result/Propositions.pm @@ -30,6 +30,7 @@ __PACKAGE__->typecast_map(type => { DowngradeModule => 'Lacuna::DB::Result::Propositions::DowngradeModule', EnactWrit => 'Lacuna::DB::Result::Propositions::EnactWrit', ElectNewLeader => 'Lacuna::DB::Result::Propositions::ElectNewLeader', + EvictExcavator => 'Lacuna::DB::Result::Propositions::EvictExcavator', EvictMiningPlatform => 'Lacuna::DB::Result::Propositions::EvictMiningPlatform', ExpelMember => 'Lacuna::DB::Result::Propositions::ExpelMember', FireBfg => 'Lacuna::DB::Result::Propositions::FireBfg', @@ -37,6 +38,7 @@ __PACKAGE__->typecast_map(type => { InductMember => 'Lacuna::DB::Result::Propositions::InductMember', InstallModule => 'Lacuna::DB::Result::Propositions::InstallModule', MembersOnlyColonization => 'Lacuna::DB::Result::Propositions::MembersOnlyColonization', + MembersOnlyExcavation => 'Lacuna::DB::Result::Propositions::MembersOnlyExcavation', MembersOnlyMiningRights => 'Lacuna::DB::Result::Propositions::MembersOnlyMiningRights', RenameAsteroid => 'Lacuna::DB::Result::Propositions::RenameAsteroid', RenameStar => 'Lacuna::DB::Result::Propositions::RenameStar', diff --git a/lib/Lacuna/DB/Result/Propositions/EvictExcavator.pm b/lib/Lacuna/DB/Result/Propositions/EvictExcavator.pm new file mode 100644 index 00000000..0830ffa5 --- /dev/null +++ b/lib/Lacuna/DB/Result/Propositions/EvictExcavator.pm @@ -0,0 +1,33 @@ +package Lacuna::DB::Result::Propositions::EvictExcavator; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Propositions'; + +before pass => sub { + my ($self) = @_; + my $excav = Lacuna->db->resultset('Lacuna::DB::Result::Excavators')->find($self->scratch->{excav_id}); + my $station = $self->station; + my $bodies = Lacuna->db->resultset('Lacuna::DB::Result::Map::Body'); + my $body = $bodies->find($self->scratch->{excav_id}); + my $name = $self->scratch->{name}; + if (! defined $excav) { + $self->pass_extra_message('Unfortunately, by the time the proposition passed, the excavator had already been destroyed, effectively nullifying the vote.'); + } + elsif ($self->station_id != $excav->body->star->station_id) { + $self->pass_extra_message('Unfortunately, by the time the proposition passed, the body was no longer under the jurisdiction of this station, effectively nullifying the vote.'); + } + else { + $excav->planet->empire->send_predefined_message( + filename => 'parliament_evict_excavator.txt', + params => [$station->alliance->name, $excav->body->x, $excav->body->y, $excav->body->name], + from => $station->alliance->leader, + tags => ['Parliament','Correspondence'], + ); + $excav->planet->get_building_of_class('Lacuna::DB::Result::Building::Archaeology')->remove_excavator($excav); + } +}; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Propositions/MembersOnlyExcavation.pm b/lib/Lacuna/DB/Result/Propositions/MembersOnlyExcavation.pm new file mode 100644 index 00000000..5b2e4ace --- /dev/null +++ b/lib/Lacuna/DB/Result/Propositions/MembersOnlyExcavation.pm @@ -0,0 +1,19 @@ +package Lacuna::DB::Result::Propositions::MembersOnlyExcavation; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Propositions'; + +before pass => sub { + my ($self) = @_; + my $law = Lacuna->db->resultset('Lacuna::DB::Result::Laws')->new({ + name => $self->name, + description => $self->description, + type => 'MembersOnlyExcavation', + station_id => $self->station_id, + })->insert; +}; + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/RPC/Building/Archaeology.pm b/lib/Lacuna/RPC/Building/Archaeology.pm index 416d7cb9..52cd90f0 100644 --- a/lib/Lacuna/RPC/Building/Archaeology.pm +++ b/lib/Lacuna/RPC/Building/Archaeology.pm @@ -102,7 +102,7 @@ sub view_excavators { my $chances = $building->can_you_dig_it($building->body, $level, 1); push @sites, { body => $building->body->get_status, - id => $building->id, + id => 0, # This makes it easy to tell which ID belongs to the building. artifact => $chances->{artifact}, glyph => $chances->{glyph}, plan => $chances->{plan}, @@ -137,7 +137,7 @@ sub abandon_excavator { confess [1002, "Excavator Site not found."]; } unless ($site->planet_id eq $building->body_id) { - confess [1013, "You can't abandon an excavator site that is not yours."]; + confess [1013, "You can't abandon an excavator site that is not from this planet."]; } $building->remove_excavator($site); return { diff --git a/lib/Lacuna/RPC/Building/Parliament.pm b/lib/Lacuna/RPC/Building/Parliament.pm index 4145bd6c..b965373a 100644 --- a/lib/Lacuna/RPC/Building/Parliament.pm +++ b/lib/Lacuna/RPC/Building/Parliament.pm @@ -529,6 +529,31 @@ sub propose_members_only_mining_rights { }; } +sub propose_members_only_excavation { + my ($self, $session_id, $building_id) = @_; + my $empire = $self->get_empire_by_session($session_id); + if ($empire->current_session->is_sitter) { + confess [1015, 'Sitters cannot create propositions.']; + } + my $building = $self->get_building($empire, $building_id); + unless ($building->level >= 20) { + confess [1013, 'Parliament must be level 20 to propose members only excavation rights.',20]; + } + my $proposition = Lacuna->db->resultset('Lacuna::DB::Result::Propositions')->new({ + type => 'MembersOnlyExcavation', + name => 'Members Only Excavation', + description => 'Only members of {Alliance '.$building->body->alliance_id.' '.$building->body->alliance->name.'} should be allowed to excavate bodies in the jurisdiction of {Starmap '.$building->body->x.' '.$building->body->y.' '.$building->body->name.'}.', + proposed_by_id => $empire->id, + }); + $proposition->station($building->body); + $proposition->proposed_by($empire); + $proposition->insert; + return { + status => $self->format_status($empire, $building->body), + proposition => $proposition->get_status($empire), + }; +} + sub propose_members_only_colonization { my ($self, $session_id, $building_id) = @_; my $empire = $self->get_empire_by_session($session_id); @@ -590,6 +615,42 @@ sub propose_evict_mining_platform { }; } +sub propose_evict_excavator { + my ($self, $session_id, $building_id, $excav_id) = @_; + my $empire = $self->get_empire_by_session($session_id); + if ($empire->current_session->is_sitter) { + confess [1015, 'Sitters cannot create propositions.']; + } + my $building = $self->get_building($empire, $building_id); + unless ($building->level >= 21) { + confess [1013, 'Parliament must be level 21 to evict an excavator.',21]; + } + unless ($excav_id) { + confess [1002, 'You must specify an excavator id.']; + } + my $excav = Lacuna->db->resultset('Lacuna::DB::Result::Excavators')->find($excav_id); + unless (defined $excav) { + confess [1002, 'Excavator not found.']; + } + unless ($excav->body->star->station_id == $building->body_id) { + confess [1009, 'That excavator is not in your jurisdiction.']; + } + my $proposition = Lacuna->db->resultset('Lacuna::DB::Result::Propositions')->new({ + type => 'EvictExcavator', + name => 'Evict '.$excav->planet->empire->name.' Excavator', + description => 'Evict a excavator on {Starmap '.$excav->body->x.' '.$excav->body->y.' '.$excav->body->name.'} controlled by {Empire '.$excav->planet->empire_id.' '.$excav->planet->empire->name.'}.', + scratch => { excav_id => $excav_id }, + proposed_by_id => $empire->id, + }); + $proposition->station($building->body); + $proposition->proposed_by($empire); + $proposition->insert; + return { + status => $self->format_status($empire, $building->body), + proposition => $proposition->get_status($empire), + }; +} + sub propose_elect_new_leader { my ($self, $session_id, $building_id, $to_empire_id) = @_; my $empire = $self->get_empire_by_session($session_id); @@ -815,7 +876,7 @@ sub view_taxes_collected { -__PACKAGE__->register_rpc_method_names(qw(get_bodies_for_star_in_jurisdiction get_mining_platforms_for_asteroid_in_jurisdiction propose_evict_mining_platform propose_members_only_mining_rights propose_members_only_colonization propose_rename_asteroid propose_rename_uninhabited propose_broadcast_on_network19 get_stars_in_jurisdiction propose_rename_star propose_repeal_law propose_seize_star propose_transfer_station_ownership view_propositions view_laws cast_vote propose_fire_bfg propose_writ propose_elect_new_leader propose_induct_member propose_expel_member propose_taxation view_taxes_collected propose_foreign_aid)); +__PACKAGE__->register_rpc_method_names(qw(get_bodies_for_star_in_jurisdiction get_mining_platforms_for_asteroid_in_jurisdiction propose_evict_mining_platform propose_members_only_mining_rights propose_members_only_colonization propose_rename_asteroid propose_rename_uninhabited propose_broadcast_on_network19 get_stars_in_jurisdiction propose_rename_star propose_repeal_law propose_seize_star propose_transfer_station_ownership view_propositions view_laws cast_vote propose_fire_bfg propose_writ propose_elect_new_leader propose_induct_member propose_expel_member propose_taxation view_taxes_collected propose_foreign_aid propose_evict_excavator propose_members_only_excavation)); no Moose; __PACKAGE__->meta->make_immutable; diff --git a/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm b/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm index ca4701f3..908a4322 100644 --- a/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm +++ b/lib/Lacuna/Role/Ship/Arrive/DeployExcavator.pm @@ -52,10 +52,8 @@ after can_send_to_target => sub { confess [1013, 'Cannot control excavators without an Archaeology.'] unless (defined $archaeology); confess [1013, 'Your Archaeology Ministry must be level 11 or higher in order to send excavators.'] unless ($archaeology->level >= 11); $archaeology->can_add_excavator($target); -# Will need to make this only pertaining to excavation later. -# MembersOnlyExcavators if ($target->star->station_id) { - if ($target->star->station->laws->search({type => 'MembersOnlyMiningRights'})->count) { + if ($target->star->station->laws->search({type => 'MembersOnlyExcavation'})->count) { unless ($target->star->station->alliance_id == $self->body->empire->alliance_id) { confess [1010, 'Only '.$target->star->station->alliance->name.' members can excavate bodies in the jurisdiction of the space station.']; } diff --git a/lib/Lacuna/Role/Ship/Arrive/ScanSurface.pm b/lib/Lacuna/Role/Ship/Arrive/ScanSurface.pm index 71177491..4bf2442e 100644 --- a/lib/Lacuna/Role/Ship/Arrive/ScanSurface.pm +++ b/lib/Lacuna/Role/Ship/Arrive/ScanSurface.pm @@ -8,9 +8,20 @@ after handle_arrival_procedures => sub { # we're coming home return if ($self->direction eq 'in'); + + my $body_attacked = $self->foreign_body; + # Found an asteroid + if ($body_attacked->isa('Lacuna::DB::Result::Map::Body::Asteroid')) { + $self->body->empire->send_predefined_message( + tags => ['Attack','Alert'], + filename => 'scan_asteroid.txt', + params => ['Scanner', $body_attacked->x, $body_attacked->y, $body_attacked->name], + ); + $self->delete; + confess [-1]; + } # do the scan - my $body_attacked = $self->foreign_body; my @map; my $buildings = $body_attacked->buildings; while (my $building = $buildings->next) { diff --git a/lib/Lacuna/Role/Ship/Arrive/SurveySurface.pm b/lib/Lacuna/Role/Ship/Arrive/SurveySurface.pm index cbbd99ab..3100229f 100644 --- a/lib/Lacuna/Role/Ship/Arrive/SurveySurface.pm +++ b/lib/Lacuna/Role/Ship/Arrive/SurveySurface.pm @@ -8,9 +8,21 @@ after handle_arrival_procedures => sub { # we're coming home return if ($self->direction eq 'in'); - - # do the scan + my $body_attacked = $self->foreign_body; + + # Found an asteroid + if ($body_attacked->isa('Lacuna::DB::Result::Map::Body::Asteroid')) { + $self->body->empire->send_predefined_message( + tags => ['Attack','Alert'], + filename => 'scan_asteroid.txt', + params => ['Scanner', $body_attacked->x, $body_attacked->y, $body_attacked->name], + ); + $self->delete; + confess [-1]; + } + + # do the scan my @map; my @table = ([qw(Name Level X Y Efficiency)]); my $buildings = $body_attacked->buildings->search(undef,{order_by => ['x','y']}); diff --git a/var/messages/parliament_evict_excavator.txt b/var/messages/parliament_evict_excavator.txt new file mode 100644 index 00000000..f55deb6f --- /dev/null +++ b/var/messages/parliament_evict_excavator.txt @@ -0,0 +1,3 @@ +Excavator Evicted +~~~ +%s has voted to evict your excavator from {Starmap %s %s %s}. diff --git a/var/messages/scan_asteroid.txt b/var/messages/scan_asteroid.txt new file mode 100644 index 00000000..9b896885 --- /dev/null +++ b/var/messages/scan_asteroid.txt @@ -0,0 +1,7 @@ +Asteroid Found +~~~ +Our %s arrived at {Starmap %s %s %s} and found an asteroid. + +Regards, + +Your Humble Assistant diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 84547b1e..0909b643 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,3 +1,9 @@ +3.0842: + - Mod: Tweaked probabilities of glyph returns. + - Mod: Zero is ID of the archeaology ministry itself on returned data. + - Fix: Scanners & Surveyors do not cause an exception when they arrive at an asteroid. + - Add: Space Stations can propose Members Only Excavation Rights. + 3.0841: - Mod: Include ArchMin is probabilities passed back by view_excavators. -- 2.51.2 From 3a1b81ffdccc31e393d5ab3d6e18f29ff6b28725 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 6 Mar 2012 14:05:59 -0700 Subject: [PATCH 21/28] Slight percentage changes. --- lib/Lacuna/DB/Result/Building/Archaeology.pm | 4 ++-- lib/Lacuna/RPC/Building/Archaeology.pm | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Lacuna/DB/Result/Building/Archaeology.pm b/lib/Lacuna/DB/Result/Building/Archaeology.pm index ac301e23..e39214a0 100644 --- a/lib/Lacuna/DB/Result/Building/Archaeology.pm +++ b/lib/Lacuna/DB/Result/Building/Archaeology.pm @@ -334,14 +334,14 @@ sub can_you_dig_it { my ($self, $body, $level, $arch) = @_; my $mult = $arch + 1; - my $plan = ($level/5+1) * $mult; # 2.4-14% + my $plan = int($level/4 + 1) * $mult; # 1-8% * 2 my $ore_total = 0; for my $ore (ORE_TYPES) { $ore_total += $body->$ore; } $ore_total = 10_000 if $ore_total > 10_000; my $glyph = int($mult * $level * $ore_total/15_000)+1; # 1-20% (2x if arch run) +1 - my $resource = 2 * $level; # 2-60% + my $resource = int(5/2 * $level); # 2-75% my $artifact = 0; if (!$arch && $body->buildings->count) { $artifact = 15; diff --git a/lib/Lacuna/RPC/Building/Archaeology.pm b/lib/Lacuna/RPC/Building/Archaeology.pm index 52cd90f0..dcb594b1 100644 --- a/lib/Lacuna/RPC/Building/Archaeology.pm +++ b/lib/Lacuna/RPC/Building/Archaeology.pm @@ -134,7 +134,7 @@ sub abandon_excavator { my $building = $self->get_building($empire, $building_id); my $site = Lacuna->db->resultset('Lacuna::DB::Result::Excavators')->find($site_id); unless (defined $site) { - confess [1002, "Excavator Site not found."]; + confess [1002, "Excavator Site :".$site_id.": not found."]; } unless ($site->planet_id eq $building->body_id) { confess [1013, "You can't abandon an excavator site that is not from this planet."]; -- 2.51.2 From dcfc13369e8d46b67723d5357b530b0f2fc1c357 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Tue, 6 Mar 2012 18:45:01 -0700 Subject: [PATCH 22/28] Fixed skip message --- lib/Lacuna/DB/Result/Building/Archaeology.pm | 6 ++++++ lib/Lacuna/RPC/Empire.pm | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/Lacuna/DB/Result/Building/Archaeology.pm b/lib/Lacuna/DB/Result/Building/Archaeology.pm index e39214a0..8fe57c42 100644 --- a/lib/Lacuna/DB/Result/Building/Archaeology.pm +++ b/lib/Lacuna/DB/Result/Building/Archaeology.pm @@ -207,6 +207,12 @@ sub dig_it { 'Klaatu Barada Ni*cough*', 'The brazen temple doors open...', 'It\'s full of stars' + 'This is obviously some strange usage of the word safe that I wasn\'t previously aware of.', + 'Oh no, not again.', + 'That\'s it man, game over man, game over!', + 'I say we take off and nuke the site from orbit. It\'s the only way to be sure.', + 'Trust me, I\'m trained to do this.', + 'Oops? What oops? No oops!', ]); $result = { message => $message, diff --git a/lib/Lacuna/RPC/Empire.pm b/lib/Lacuna/RPC/Empire.pm index 2663e7c7..1c8ce042 100644 --- a/lib/Lacuna/RPC/Empire.pm +++ b/lib/Lacuna/RPC/Empire.pm @@ -532,13 +532,13 @@ sub edit_profile { if ($profile->{skip_excavator_artifact} < 0 || $profile->{skip_excavator_artifact} > 1) { confess [1009, 'Skip Excavator Artifact must be a 1 or a 0.', 'skip_excavator_artifact'] } - $empire->skip_excavator_resources($profile->{skip_excavator_artifact}); + $empire->skip_excavator_artifact($profile->{skip_excavator_artifact}); } if (exists $profile->{skip_excavator_destroyed}) { if ($profile->{skip_excavator_destroyed} < 0 || $profile->{skip_excavator_destroyed} > 1) { confess [1009, 'Skip Excavator Destroyed must be a 1 or a 0.', 'skip_excavator_destroyed'] } - $empire->skip_excavator_resources($profile->{skip_excavator_destroyed}); + $empire->skip_excavator_destroyed($profile->{skip_excavator_destroyed}); } if (exists $profile->{skip_spy_recovery}) { if ($profile->{skip_spy_recovery} < 0 || $profile->{skip_spy_recovery} > 1) { -- 2.51.2 From 3954a591b74ab1e2cceb50a59464bca1439b6194 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Fri, 9 Mar 2012 10:45:04 -0700 Subject: [PATCH 23/28] Fixed missing comma. --- lib/Lacuna/DB/Result/Building/Archaeology.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Lacuna/DB/Result/Building/Archaeology.pm b/lib/Lacuna/DB/Result/Building/Archaeology.pm index 8fe57c42..97f745a9 100644 --- a/lib/Lacuna/DB/Result/Building/Archaeology.pm +++ b/lib/Lacuna/DB/Result/Building/Archaeology.pm @@ -206,7 +206,7 @@ sub dig_it { 'Ph\'nglui Mglw\'nafh Cthulhu R\'lyeh wgah\'nagi fhtagn.', 'Klaatu Barada Ni*cough*', 'The brazen temple doors open...', - 'It\'s full of stars' + 'It\'s full of stars', 'This is obviously some strange usage of the word safe that I wasn\'t previously aware of.', 'Oh no, not again.', 'That\'s it man, game over man, game over!', -- 2.51.2 From eeae2694318a8ba128fa2db35c3c41b489f3f2af Mon Sep 17 00:00:00 2001 From: lemming552 Date: Sat, 10 Mar 2012 01:33:41 -0700 Subject: [PATCH 24/28] Resources returned modified, running cost and upgrade cost adjusted. --- lib/Lacuna/DB/Result/Building/Archaeology.pm | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/Lacuna/DB/Result/Building/Archaeology.pm b/lib/Lacuna/DB/Result/Building/Archaeology.pm index 97f745a9..28452824 100644 --- a/lib/Lacuna/DB/Result/Building/Archaeology.pm +++ b/lib/Lacuna/DB/Result/Building/Archaeology.pm @@ -33,15 +33,15 @@ use constant water_to_build => 190; use constant waste_to_build => 250; -use constant time_to_build => 500; +use constant time_to_build => 480; use constant food_consumption => 20; use constant energy_consumption => 5; -use constant ore_consumption => 5; +use constant ore_consumption => 15; -use constant water_consumption => 30; +use constant water_consumption => 25; use constant waste_production => 20; @@ -102,7 +102,6 @@ sub run_excavators { $result = $self->dig_it($body, $level, 0); $result->{id} = $excav->id; } -#N19 push @results, $result; if ($result->{outcome} eq "Destroyed") { $self->remove_excavator($excav); @@ -155,7 +154,7 @@ sub dig_it { given ($outcome) { when ("resource") { my $type = random_element([ORE_TYPES, FOOD_TYPES, qw(water energy)]); - my $amount = randint(100 * $level, 1000 * $level); + my $amount = randint(10 * $level, 200 * $level); $self->body->add_type($type, $amount)->update; $result = { message => "Found $amount of $type.", -- 2.51.2 From e33a93eb62fd6508bb2d7e906b1a67789ec7e2b0 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Sat, 10 Mar 2012 14:55:39 -0700 Subject: [PATCH 25/28] AIs don't send redundant probes now. --- lib/Lacuna/AI.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Lacuna/AI.pm b/lib/Lacuna/AI.pm index 4abe89e2..8b8c8c27 100644 --- a/lib/Lacuna/AI.pm +++ b/lib/Lacuna/AI.pm @@ -451,7 +451,7 @@ sub start_attack { $seconds = 1; } my $probe = $db->resultset('Lacuna::DB::Result::Ships')->search({body_id => $attacking_colony->id, type => 'probe', task=>'Docked'},{rows => 1})->single; - if (defined $probe) { + if (defined $probe and $seconds == 0) { say ' Has a probe to launch for '.$target_colony->name.'...'; $probe->send(target => $target_colony->star); $seconds = $probe->date_available->epoch - time(); -- 2.51.2 From 6f1c40a7aca7c79f22a9f9aadfc2eb9a98b4d011 Mon Sep 17 00:00:00 2001 From: lemming552 Date: Sat, 10 Mar 2012 23:53:50 -0700 Subject: [PATCH 26/28] Both empires noted in trades, sst, mercs, and referral E. --- lib/Lacuna.pm | 2 +- lib/Lacuna/AI/DeLambert.pm | 4 ++-- lib/Lacuna/DB/Result/Building/University.pm | 2 +- lib/Lacuna/DB/Result/Empire.pm | 12 ++++++++++-- lib/Lacuna/DB/Result/EssentiaCode.pm | 1 + lib/Lacuna/DB/Result/Log/Essentia.pm | 2 ++ lib/Lacuna/RPC/Building/MercenariesGuild.pm | 17 +++++++++++++---- lib/Lacuna/RPC/Building/Trade.pm | 4 ++-- lib/Lacuna/RPC/Building/Transporter.pm | 4 ++-- lib/Lacuna/Web/Admin.pm | 6 ++++-- var/upgrades/3.0843.sql | 3 +++ var/www/public/changes.txt | 5 +++++ 12 files changed, 46 insertions(+), 16 deletions(-) create mode 100644 var/upgrades/3.0843.sql diff --git a/lib/Lacuna.pm b/lib/Lacuna.pm index a4f7f604..4b4cc676 100644 --- a/lib/Lacuna.pm +++ b/lib/Lacuna.pm @@ -7,7 +7,7 @@ use Config::JSON; useall __PACKAGE__; -our $VERSION = 3.0842; +our $VERSION = 3.0843; 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 8f6393be..3da7c045 100644 --- a/lib/Lacuna/AI/DeLambert.pm +++ b/lib/Lacuna/AI/DeLambert.pm @@ -408,8 +408,8 @@ sub buy_trade { my $offer_ship = Lacuna->db->resultset('Lacuna::DB::Result::Ships')->find($trade->ship_id); return if not defined $offer_ship; - $self->empire->spend_essentia($trade->ask, 'Trade Price')->update; - $trade->body->empire->add_essentia($trade->ask, 'Trade Income')->update; + $self->empire->spend_essentia($trade->ask, 'Trade Price', 0, $trade->body->empire->id, $trade->body->empire->name )->update; + $trade->body->empire->add_essentia($trade->ask, 'Trade Income', 0, $self->empire->id, $self->empire->name)->update; $offer_ship->send( target => $colony, diff --git a/lib/Lacuna/DB/Result/Building/University.pm b/lib/Lacuna/DB/Result/Building/University.pm index 0282a938..3c9f57a3 100644 --- a/lib/Lacuna/DB/Result/Building/University.pm +++ b/lib/Lacuna/DB/Result/Building/University.pm @@ -55,7 +55,7 @@ after finish_upgrade => sub { if (defined $invite) { my $inviter = $invite->inviter; if (defined $inviter) { - $inviter->add_essentia(5, 'invited friend university upgrade')->update; + $inviter->add_essentia(5, 'invited friend university upgrade', 0, $empire->id, $empire->name)->update; $inviter->send_predefined_message( filename => 'friend_essentia.txt', params => [$empire->id, $empire->name], diff --git a/lib/Lacuna/DB/Result/Empire.pm b/lib/Lacuna/DB/Result/Empire.pm index 6611eb5c..1cdc06f8 100644 --- a/lib/Lacuna/DB/Result/Empire.pm +++ b/lib/Lacuna/DB/Result/Empire.pm @@ -221,7 +221,9 @@ sub add_medal { } sub spend_essentia { - my ($self, $value, $note, $transaction_id) = @_; + my ($self, $value, $note, $transaction_id, $from_id, $from_name) = @_; + $from_id = 0 unless defined($from_id); + $from_name = "" unless defined($from_name); $self->essentia( $self->essentia - $value ); Lacuna->db->resultset('Lacuna::DB::Result::Log::Essentia')->new({ empire_id => $self->id, @@ -230,12 +232,16 @@ sub spend_essentia { description => $note, api_key => (defined $self->current_session) ? $self->current_session->api_key : undef, transaction_id => $transaction_id, + from_id => $from_id, + from_name => $from_name, })->insert; return $self; } sub add_essentia { - my ($self, $value, $note, $transaction_id) = @_; + my ($self, $value, $note, $transaction_id, $from_id, $from_name) = @_; + $from_id = 0 unless defined($from_id); + $from_name = "" unless defined($from_name); $self->essentia( $self->essentia + $value ); Lacuna->db->resultset('Lacuna::DB::Result::Log::Essentia')->new({ empire_id => $self->id, @@ -244,6 +250,8 @@ sub add_essentia { description => $note, transaction_id => $transaction_id, api_key => (defined $self->current_session) ? $self->current_session->api_key : undef, + from_id => $from_id, + from_name => $from_name, })->insert; return $self; } diff --git a/lib/Lacuna/DB/Result/EssentiaCode.pm b/lib/Lacuna/DB/Result/EssentiaCode.pm index 13f9cda6..605e4d65 100644 --- a/lib/Lacuna/DB/Result/EssentiaCode.pm +++ b/lib/Lacuna/DB/Result/EssentiaCode.pm @@ -13,6 +13,7 @@ __PACKAGE__->add_columns( date_created => { data_type => 'datetime', is_nullable => 0, set_on_create => 1 }, description => { data_type => 'varchar', size => 50, is_nullable => 0 }, used => { data_type => 'tinyint', is_nullable => 0, default_value => 0 }, + empire_id => { data_type => 'int', size => 11, is_nullable => 0 }, ); sub sqlt_deploy_hook { diff --git a/lib/Lacuna/DB/Result/Log/Essentia.pm b/lib/Lacuna/DB/Result/Log/Essentia.pm index 4ee34a48..15663519 100644 --- a/lib/Lacuna/DB/Result/Log/Essentia.pm +++ b/lib/Lacuna/DB/Result/Log/Essentia.pm @@ -12,6 +12,8 @@ __PACKAGE__->add_columns( amount => { data_type => 'float', size => [11,1], is_nullable => 0 }, description => { data_type => 'varchar', size => 90, is_nullable => 0 }, transaction_id => { data_type => 'varchar', size => 32, is_nullable => 1 }, + from_id => { data_type => 'int', size => 11, is_nullable => 0 }, + from_name => { data_type => 'varchar', size => 30, is_nullable => 0 }, ); after 'sqlt_deploy_hook' => sub { diff --git a/lib/Lacuna/RPC/Building/MercenariesGuild.pm b/lib/Lacuna/RPC/Building/MercenariesGuild.pm index f41dc419..7699d143 100644 --- a/lib/Lacuna/RPC/Building/MercenariesGuild.pm +++ b/lib/Lacuna/RPC/Building/MercenariesGuild.pm @@ -89,8 +89,14 @@ sub accept_from_market { $guard->cancel; - $empire->spend_essentia($trade->ask, 'Mercenary Price')->update; - $trade->body->empire->add_essentia($trade->ask, 'Mercenary Income')->update; + if ($trade->body->empire->id == $empire->id) { + # Selling to oneself + $empire->spend_essentia(0, 'Mercanary Price', 0, $trade->body->empire->id, $trade->body->empire->name )->update; + } + else { + $empire->spend_essentia($trade->ask, 'Mercanary Price', 0, $trade->body->empire->id, $trade->body->empire->name )->update; + $trade->body->empire->add_essentia($trade->ask, 'Mercanary Income', 0, $empire->id, $empire->name)->update; + } #my $cargo_log = Lacuna->db->resultset('Lacuna::DB::Result::Log::Cargo'); #$cargo_log->new({ # message => 'mercenaries guild offer accepted', @@ -111,11 +117,14 @@ sub accept_from_market { # object_id => $offer_ship->id, #})->insert; - $trade->body->empire->send_predefined_message( + if ($trade->body->empire->id != $empire->id) { + # Don't notify yourself + $trade->body->empire->send_predefined_message( tags => ['Trade','Alert'], filename => 'trade_accepted.txt', params => [$trade->format_description_of_payload, $trade->ask.' essentia', $empire->id, $empire->name], - ); + ); + } $trade->delete; return { diff --git a/lib/Lacuna/RPC/Building/Trade.pm b/lib/Lacuna/RPC/Building/Trade.pm index d6766049..d0c7f9a0 100644 --- a/lib/Lacuna/RPC/Building/Trade.pm +++ b/lib/Lacuna/RPC/Building/Trade.pm @@ -144,8 +144,8 @@ sub accept_from_market { $guard->cancel; - $empire->spend_essentia($trade->ask, 'Trade Price')->update; - $trade->body->empire->add_essentia($trade->ask, 'Trade Income')->update; + $empire->spend_essentia($trade->ask, 'Trade Price', 0, $trade->body->empire->id, $trade->body->empire->name )->update; + $trade->body->empire->add_essentia($trade->ask, 'Trade Income', 0, $empire->id, $empire->name)->update; #my $cargo_log = Lacuna->db->resultset('Lacuna::DB::Result::Log::Cargo'); #$cargo_log->new({ # message => 'trade ministry offer accepted', diff --git a/lib/Lacuna/RPC/Building/Transporter.pm b/lib/Lacuna/RPC/Building/Transporter.pm index 95fd21b3..850731a4 100644 --- a/lib/Lacuna/RPC/Building/Transporter.pm +++ b/lib/Lacuna/RPC/Building/Transporter.pm @@ -142,8 +142,8 @@ sub accept_from_market { $guard->cancel; - $empire->spend_essentia($trade->ask + 1, 'Trade Price and Transporter Cost')->update; - $trade->body->empire->add_essentia($trade->ask, 'Trade Income')->update; + $empire->spend_essentia($trade->ask + 1, 'Trade Price and Transporter Cost', 0, $trade->body->empire->id, $trade->body->empire->name)->update; + $trade->body->empire->add_essentia($trade->ask, 'Trade Income', 0, $empire->id, $empire->name)->update; #my $cargo_log = Lacuna->db->resultset('Lacuna::DB::Result::Log::Cargo'); #$cargo_log->new({ # message => 'transporter offer accepted', diff --git a/lib/Lacuna/Web/Admin.pm b/lib/Lacuna/Web/Admin.pm index 6b9148d0..82eab0aa 100644 --- a/lib/Lacuna/Web/Admin.pm +++ b/lib/Lacuna/Web/Admin.pm @@ -116,9 +116,11 @@ sub www_view_essentia_log { my $transactions = Lacuna->db->resultset('Lacuna::DB::Result::Log::Essentia')->search({empire_id => $empire_id}, {order_by => { -desc => 'date_stamp' }}); my $out = '

Essentia Transaction Log

'; $out .= sprintf('Back To Empire', $empire_id); - $out .= ''; + $out .= '
DateAmountDescriptionTransaction ID
'; while (my $transaction = $transactions->next) { - $out .= sprintf('', $transaction->date_stamp, $transaction->amount, $transaction->description, $transaction->transaction_id); + $out .= sprintf('', + $transaction->date_stamp, $transaction->amount, $transaction->description, + $transaction->from_id, $transaction->from_name, $transaction->transaction_id); } $out .= '
DateAmountDescriptionFrom IDFromTransaction ID
%s%s%s%s
%s%s%s%d%s%s
'; return $self->wrap($out); diff --git a/var/upgrades/3.0843.sql b/var/upgrades/3.0843.sql new file mode 100644 index 00000000..bbc2b512 --- /dev/null +++ b/var/upgrades/3.0843.sql @@ -0,0 +1,3 @@ +alter table essentia_code add column `empire_id` int default 0; +alter table essentia_log add column `from_id` int default 0; +alter table essentia_log add column `from_name` varchar(30) default ""; diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 0909b643..50e61067 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,3 +1,8 @@ +3.0843: + - Mod: Amount of resources returned by excavators brought down to reasonable levels. + - Mod: AIs stop sending redundant probes. + - Mod: Secret stuff. + 3.0842: - Mod: Tweaked probabilities of glyph returns. - Mod: Zero is ID of the archeaology ministry itself on returned data. -- 2.51.2 From 937e9aa16fb29629ec2d8b810aa4f28606545aea Mon Sep 17 00:00:00 2001 From: lemming552 Date: Wed, 14 Mar 2012 21:14:13 -0600 Subject: [PATCH 27/28] Trades 0.1 to 100.0. Plan result from excav more related to arch level. --- docs/MercenariesGuild.pod | 2 +- lib/Lacuna.pm | 2 +- lib/Lacuna/DB/Result/Building/Archaeology.pm | 13 ++++++++++--- lib/Lacuna/DB/Result/Building/MercenariesGuild.pm | 5 +++-- lib/Lacuna/DB/Result/Building/Trade.pm | 5 +++-- lib/Lacuna/DB/Result/Building/Transporter.pm | 5 +++-- var/www/public/changes.txt | 4 ++++ 7 files changed, 25 insertions(+), 11 deletions(-) diff --git a/docs/MercenariesGuild.pod b/docs/MercenariesGuild.pod index cb7a58a8..16d82092 100644 --- a/docs/MercenariesGuild.pod +++ b/docs/MercenariesGuild.pod @@ -1,6 +1,6 @@ =head1 Mercenaries Guild Methods -The Mercenaries Guild is accessible via the URL C. It allows you to send spies to other players via spy pods. Due to the vast distance of space, you may only trade with other players in your zone. It costs essentia to use it. +The Mercenaries Guild is accessible via the URL C. It allows you to send spies to other players via spy pods. It costs essentia to use it. The list of methods below represents changes and additions to the methods that all L share. diff --git a/lib/Lacuna.pm b/lib/Lacuna.pm index 4b4cc676..0e62396c 100644 --- a/lib/Lacuna.pm +++ b/lib/Lacuna.pm @@ -7,7 +7,7 @@ use Config::JSON; useall __PACKAGE__; -our $VERSION = 3.0843; +our $VERSION = 3.0844; 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/Building/Archaeology.pm b/lib/Lacuna/DB/Result/Building/Archaeology.pm index 28452824..f3860461 100644 --- a/lib/Lacuna/DB/Result/Building/Archaeology.pm +++ b/lib/Lacuna/DB/Result/Building/Archaeology.pm @@ -248,15 +248,20 @@ sub found_plan { my $plus = 0; if ($rand_cat < 1) { $class = random_element($plan_types->{special}); - $plus = randint(0, int($level/7)) if (randint(0,19) < 1); + if (randint(0,100) < int($level/3)) { + $plus = randint(0, int($level/8)); + if ($level == 30 && $plus > 0) { + $plus++; + } + } } elsif ($rand_cat < 10) { $class = random_element($plan_types->{natural}); - $plus = randint(1, int($level/7)+1) if (randint(0,9) < 1); + $plus = randint(1, int($level/6)+1) if (randint(0,100) < int($level/2)); } else { $class = random_element($plan_types->{decor}); - $plus = randint(1, int($level/5)+1) if (randint(0,4) < 1); + $plus = randint(1, int($level/5)+1) if (randint(0,100) < $level); } my $plan = $self->body->add_plan($class, $lvl, $plus); @@ -298,6 +303,8 @@ sub found_artifact { $name = $select->name; $destroy = 25; } + $lvl = 30 if ($lvl > 30); + $plus = 30 if ($plus > 30); $self->body->add_plan($class, $lvl, $plus); if ($select->level == 1 or randint(0,99) < $destroy) { $select->delete; diff --git a/lib/Lacuna/DB/Result/Building/MercenariesGuild.pm b/lib/Lacuna/DB/Result/Building/MercenariesGuild.pm index ff0ca2e8..1012053a 100644 --- a/lib/Lacuna/DB/Result/Building/MercenariesGuild.pm +++ b/lib/Lacuna/DB/Result/Building/MercenariesGuild.pm @@ -66,8 +66,9 @@ sub available_market { sub add_to_market { my ($self, $cost, $spy_id, $ask, $ship_id) = @_; confess $offer_nothing_exception unless $spy_id; - unless ($ask >= 0.1 && $ask < 100 ) { - confess [1009, "You must ask for between 0.1 and 99 essentia to create a trade."]; + $ask = sprintf("%0.1f", $ask); + unless ($ask >= 0.1 && $ask <= 100 ) { + confess [1009, "You must ask for between 0.1 and 100 essentia to create a trade."]; } my $ship = $self->next_available_trade_ship($ship_id); unless (defined $ship) { diff --git a/lib/Lacuna/DB/Result/Building/Trade.pm b/lib/Lacuna/DB/Result/Building/Trade.pm index a39a02f6..1137330b 100644 --- a/lib/Lacuna/DB/Result/Building/Trade.pm +++ b/lib/Lacuna/DB/Result/Building/Trade.pm @@ -53,8 +53,9 @@ sub add_to_market { unless (defined $ship) { confess [1011, "You do not have any ships available that can carry trade goods."]; } - unless ($ask >= 0.1 && $ask < 100 ) { - confess [1009, "You must ask for between 0.1 and 99 essentia to create a trade."]; + $ask = sprintf("%0.1f", $ask); + unless ($ask >= 0.1 && $ask <= 100 ) { + confess [1009, "You must ask for between 0.1 and 100 essentia to create a trade."]; } unless ($self->level > $self->my_market->count) { confess [1009, "This Trade Ministry can only support ".$self->level." trades at one time."]; diff --git a/lib/Lacuna/DB/Result/Building/Transporter.pm b/lib/Lacuna/DB/Result/Building/Transporter.pm index 19c1eb6e..94d8bbd5 100644 --- a/lib/Lacuna/DB/Result/Building/Transporter.pm +++ b/lib/Lacuna/DB/Result/Building/Transporter.pm @@ -49,8 +49,9 @@ use constant waste_production => 1; sub add_to_market { my ($self, $offer, $ask) = @_; - unless ($ask >= 0.1 && $ask < 100 ) { - confess [1009, "You must ask for between 0.1 and 99 essentia to create a trade."]; + $ask = sprintf("%0.1f", $ask); + unless ($ask >= 0.1 && $ask <= 100 ) { + confess [1009, "You must ask for between 0.1 and 100 essentia to create a trade."]; } unless ($self->level > $self->my_market->count) { confess [1009, "This Subspace Transporter can only support ".$self->level." trades at one time."]; diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 50e61067..7d10cb0d 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,3 +1,7 @@ +3.0844: + - Mod: Excavator plan returns adjusted slightly. + - Mod: Trades are 0.1 to 100.0 inclusive. Rounding happens after 1 decimal point. + 3.0843: - Mod: Amount of resources returned by excavators brought down to reasonable levels. - Mod: AIs stop sending redundant probes. -- 2.51.2 From b4145be2bcce7f5ebcd9340efbc6118af3c560ce Mon Sep 17 00:00:00 2001 From: lemming552 Date: Sat, 24 Mar 2012 09:57:35 -0600 Subject: [PATCH 28/28] sql added for clearing excavators. --- lib/Lacuna.pm | 2 +- lib/Lacuna/DB/Result/Building/Archaeology.pm | 24 +++++++++++++------- var/upgrades/3.0838.sql | 2 +- var/upgrades/3.0845.sql | 1 + var/www/public/changes.txt | 4 ++++ 5 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 var/upgrades/3.0845.sql diff --git a/lib/Lacuna.pm b/lib/Lacuna.pm index 0e62396c..2d6f4f08 100644 --- a/lib/Lacuna.pm +++ b/lib/Lacuna.pm @@ -7,7 +7,7 @@ use Config::JSON; useall __PACKAGE__; -our $VERSION = 3.0844; +our $VERSION = 3.0845; 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/Building/Archaeology.pm b/lib/Lacuna/DB/Result/Building/Archaeology.pm index f3860461..7b7f8d42 100644 --- a/lib/Lacuna/DB/Result/Building/Archaeology.pm +++ b/lib/Lacuna/DB/Result/Building/Archaeology.pm @@ -202,16 +202,24 @@ sub dig_it { if (randint(0,99) < 5) { # This should give an excavator a 1.2% survival each day. Unless on artifact planets. my $message = random_element([ - 'Ph\'nglui Mglw\'nafh Cthulhu R\'lyeh wgah\'nagi fhtagn.', - 'Klaatu Barada Ni*cough*', - 'The brazen temple doors open...', + 'Dave, this conversation can serve no purpose anymore. Goodbye.', + 'Did you notice anything weird a minute ago?', + 'Hasta la vista, baby', + 'Houston.. we have a problem', + 'I say we take off and nuke the site from orbit. It\'s the only way to be sure.', + 'It\'s just a harmless little bunny...', 'It\'s full of stars', - 'This is obviously some strange usage of the word safe that I wasn\'t previously aware of.', + 'Looks like I picked the wrong week to stop sniffing glue.', + 'Klaatu Barada Ni*cough*', 'Oh no, not again.', + 'Oops? What oops? No oops!', + 'Ph\'nglui Mglw\'nafh Cthulhu R\'lyeh wgah\'nagi fhtagn.', 'That\'s it man, game over man, game over!', - 'I say we take off and nuke the site from orbit. It\'s the only way to be sure.', + 'The brazen temple doors open...', + 'There are things in the mist', + 'They\'re here already! You\'re next! You\'re next, You\'re next...!', + 'This is obviously some strange usage of the word safe that I wasn\'t previously aware of.', 'Trust me, I\'m trained to do this.', - 'Oops? What oops? No oops!', ]); $result = { message => $message, @@ -356,9 +364,9 @@ sub can_you_dig_it { my $resource = int(5/2 * $level); # 2-75% my $artifact = 0; if (!$arch && $body->buildings->count) { - $artifact = 15; + $artifact = 14; } - my $destroy = $arch ? 0 : 2; + my $destroy = $arch ? 0 : 1; $destroy += $artifact; my $most = $plan + $glyph + $artifact + $destroy; # resources get cut down if over 100% diff --git a/var/upgrades/3.0838.sql b/var/upgrades/3.0838.sql index e973e7f3..14a22d4a 100644 --- a/var/upgrades/3.0838.sql +++ b/var/upgrades/3.0838.sql @@ -7,4 +7,4 @@ CREATE TABLE `excavators` ( ); alter table empire add column `skip_excavator_artifact` tinyint NOT NULL default 0; alter table empire add column `skip_excavator_destroyed` tinyint NOT NULL default 0; -alter table building add column `last_check` datetime NOT NULL default '2012-01-31 15:00:00'; +alter table building add column `last_check` datetime NOT NULL default '2012-03-23 23:00:00'; diff --git a/var/upgrades/3.0845.sql b/var/upgrades/3.0845.sql new file mode 100644 index 00000000..ddeddd28 --- /dev/null +++ b/var/upgrades/3.0845.sql @@ -0,0 +1 @@ +delete from ships where type = 'excavator'; diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 7d10cb0d..17dc8b93 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -1,3 +1,7 @@ +3.0845: + - Mod: A few more messages added to excavator destroyed. + - Mod: Destruction odds modified down. + 3.0844: - Mod: Excavator plan returns adjusted slightly. - Mod: Trades are 0.1 to 100.0 inclusive. Rounding happens after 1 decimal point. -- 2.51.2