From e8b3a6396bc263ab0e4bcc85fa4c48a8c893d4e4 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Sun, 23 May 2010 13:27:05 -0500 Subject: [PATCH] converted freebies to plans --- bin/handle_espionage.pl | 2 +- docs/PlanetaryCommand.pod | 6 +++--- lib/Lacuna/DB/Result/Building.pm | 6 +++--- lib/Lacuna/DB/Result/Freebies.pm | 4 ++-- lib/Lacuna/DB/Result/Map/Body/Planet.pm | 20 ++++++++++---------- lib/Lacuna/DB/Result/Ships.pm | 4 ++-- lib/Lacuna/RPC/Building.pm | 16 ++++++++-------- lib/Lacuna/RPC/Building/PlanetaryCommand.pm | 20 ++++++++++---------- lib/Lacuna/Tutorial.pm | 14 +++++++------- t/Command.t | 6 +++--- 10 files changed, 49 insertions(+), 49 deletions(-) diff --git a/bin/handle_espionage.pl b/bin/handle_espionage.pl index ebc202a9..886420fa 100644 --- a/bin/handle_espionage.pl +++ b/bin/handle_espionage.pl @@ -869,7 +869,7 @@ sub steal_building { { body_id => $planet->id, level => {'>=' => $level} }, {rows=>1} )->single; return undef unless defined $building; - $thief->from_body->add_freebie($building->class, $level); + $thief->from_body->add_plan($building->class, $level); $thief->empire->send_predefined_message( tags => ['Alert'], filename => 'building_theft_report.txt', diff --git a/docs/PlanetaryCommand.pod b/docs/PlanetaryCommand.pod index c2d091d1..022638cd 100644 --- a/docs/PlanetaryCommand.pod +++ b/docs/PlanetaryCommand.pod @@ -52,12 +52,12 @@ Command extends the view method to include a C section. } -=head2 view_freebies ( session_id, building_id ) +=head2 view_plans ( session_id, building_id ) -Freebies are buildings you can build for free. You can get them from contests, tutorials, and from spy missions. You can only have one freebie of each building type at once. And you can only have 10 freebies queued up at once. You must either spend them, or lose them. +Plans are buildings you can build for free. You can get them from contests, tutorials, and from spy missions. You can only have one plane for each building type at once. And you can only have 10 plans queued up at once. You must either spend them, or lose them. { - "freebies" : { + "plans" : { "Subspace Transporter" : 1, "Wheat Farm" : 4, }, diff --git a/lib/Lacuna/DB/Result/Building.pm b/lib/Lacuna/DB/Result/Building.pm index 79e62f87..c09e5146 100644 --- a/lib/Lacuna/DB/Result/Building.pm +++ b/lib/Lacuna/DB/Result/Building.pm @@ -529,7 +529,7 @@ sub check_build_prereqs { confess [1013, "Can't build a building outside of it's Goldilox zone.", [$self->min_orbit, $self->max_orbit]]; } - unless ($body->get_freebie($self->class, 1)) { + unless ($body->get_plan($self->class, 1)) { # check university level if ($self->university_prereq > $body->empire->university_level) { confess [1013, "University research too low.",$self->university_prereq]; @@ -620,8 +620,8 @@ sub cost_to_upgrade { my ($self) = @_; my $upgrade_cost = $self->upgrade_cost; my $upgrade_cost_reduction = $self->construction_cost_reduction_bonus; - my $freebie = $self->body->get_freebie($self->class, $self->level + 1); - if (defined $freebie) { + my $plan = $self->body->get_plan($self->class, $self->level + 1); + if (defined $plan) { $upgrade_cost_reduction = 0; } return { diff --git a/lib/Lacuna/DB/Result/Freebies.pm b/lib/Lacuna/DB/Result/Freebies.pm index 91cdfde6..ad7d66f9 100644 --- a/lib/Lacuna/DB/Result/Freebies.pm +++ b/lib/Lacuna/DB/Result/Freebies.pm @@ -1,11 +1,11 @@ -package Lacuna::DB::Result::Freebies; +package Lacuna::DB::Result::Plans; use Moose; extends 'Lacuna::DB::Result'; use Lacuna::Util qw(format_date); use DateTime; -__PACKAGE__->table('freebies'); +__PACKAGE__->table('plans'); __PACKAGE__->add_columns( body_id => { data_type => 'int', size => 11, is_nullable => 0 }, class => { data_type => 'char', size => 255, is_nullable => 0 }, diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index f75236a0..977735ce 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -10,7 +10,7 @@ no warnings 'uninitialized'; __PACKAGE__->has_many('ships','Lacuna::DB::Result::Ships','body_id'); -__PACKAGE__->has_many('freebies','Lacuna::DB::Result::Freebies','body_id'); +__PACKAGE__->has_many('plans','Lacuna::DB::Result::Plans','body_id'); sub ships_travelling { my ($self, $where, $reverse) = @_; @@ -27,23 +27,23 @@ sub ships_travelling { ); } -# FREEBIES -sub get_freebie { +# PLANS +sub get_plan { my ($self, $class, $level) = @_; - return $self->freebies->search({class => $class, level => $level},{rows => 1})->single; + return $self->plans->search({class => $class, level => $level},{rows => 1})->single; } -sub add_freebie { +sub add_plan { my ($self, $class, $level, $extra_build_level) = @_; - my $freebies = $self->freebies; + my $plans = $self->plans; # can't have more than 10 - if ($freebies->count >= 10) { - $freebies->next->delete; + if ($plans->count >= 10) { + $plans->next->delete; } # add it - return $freebies->new({ + return $plans->new({ body_id => $self->id, class => $class, level => $level, @@ -67,7 +67,7 @@ sub sanitize { cider_stored wheat_stored bread_stored soup_stored chip_stored pie_stored pancake_stored milk_stored meal_stored algae_stored syrup_stored fungus_stored burger_stored shake_stored beetle_stored bean_production_hour bean_stored ); - $self->freebies->delete_all; + $self->plans->delete_all; Lacuna->db->resultset('Lacuna::DB::Result::Ships')->search({foreign_body_id => $self->id})->delete_all; $self->ships->delete_all; foreach my $attribute (@attributes) { diff --git a/lib/Lacuna/DB/Result/Ships.pm b/lib/Lacuna/DB/Result/Ships.pm index 3e656eb9..d65b7ba1 100644 --- a/lib/Lacuna/DB/Result/Ships.pm +++ b/lib/Lacuna/DB/Result/Ships.pm @@ -139,7 +139,7 @@ sub arrive { if ($self->direction eq 'outgoing') { my $lab = $self->body->get_building_of_class('Lacuna::DB::Result::Building::TerraformingLab'); if (defined $lab) { - $self->foreign_body->add_freebie('Lacuna::DB::Result::Building::Permanent::TerraformingPlatform', 1, $lab->level); + $self->foreign_body->add_plan('Lacuna::DB::Result::Building::Permanent::TerraformingPlatform', 1, $lab->level); } } else { @@ -151,7 +151,7 @@ sub arrive { if ($self->direction eq 'outgoing') { my $lab = $self->body->get_building_of_class('Lacuna::DB::Result::Building::GasGiantLab'); if (defined $lab) { - $self->foreign_body->add_freebie('Lacuna::DB::Result::Building::Permanent::GasGiantPlatform', 1, $lab->level); + $self->foreign_body->add_plan('Lacuna::DB::Result::Building::Permanent::GasGiantPlatform', 1, $lab->level); } } else { diff --git a/lib/Lacuna/RPC/Building.pm b/lib/Lacuna/RPC/Building.pm index e312e437..d555032b 100644 --- a/lib/Lacuna/RPC/Building.pm +++ b/lib/Lacuna/RPC/Building.pm @@ -35,9 +35,9 @@ sub upgrade { # spend resources my $body = $building->body; - my $freebie = $body->get_freebie($building->class, $building->level + 1); - if (defined $freebie) { - $freebie->delete; + my $plan = $body->get_plan($building->class, $building->level + 1); + if (defined $plan) { + $plan->delete; } else { $body->spend_water($cost->{water}); @@ -134,12 +134,12 @@ sub build { $body = $body->can_build_building($building); # adjust resources - my $freebie = $body->get_freebie($building->class, 1); - if (defined $freebie) { - if ($freebie->extra_build_level) { - $building->level( $freebie->extra_build_level); + my $plan = $body->get_plan($building->class, 1); + if (defined $plan) { + if ($plan->extra_build_level) { + $building->level( $plan->extra_build_level); } - $freebie->delete; + $plan->delete; } else { $body->spend_food($building->food_to_build); diff --git a/lib/Lacuna/RPC/Building/PlanetaryCommand.pm b/lib/Lacuna/RPC/Building/PlanetaryCommand.pm index f42c2fca..ac7b4588 100644 --- a/lib/Lacuna/RPC/Building/PlanetaryCommand.pm +++ b/lib/Lacuna/RPC/Building/PlanetaryCommand.pm @@ -20,26 +20,26 @@ around 'view' => sub { return $out; }; -sub view_freebies { +sub view_plans { my ($self, $session_id, $building_id) = @_; my $empire = $self->get_empire_by_session($session_id); my $building = $self->get_building($empire, $building_id); - my $free_stuff = $building->body->freebies; - my %freebies; - while (my $freebie = $free_stuff->next) { - my $level = $freebie->level; - if ($freebie->extra_build_level) { - $level .= ' ('.$freebie->extra_build_level.')'; + my $free_stuff = $building->body->plans; + my %plans; + while (my $plan = $free_stuff->next) { + my $level = $plan->level; + if ($plan->extra_build_level) { + $level .= ' ('.$plan->extra_build_level.')'; } - $freebies{$freebie->class->name} = $level; + $plans{$plan->class->name} = $level; } return { - freebies => \%freebies, + plans => \%plans, status => $self->format_status($empire, $building->body), }; } -__PACKAGE__->register_rpc_method_names(qw(view_freebies)); +__PACKAGE__->register_rpc_method_names(qw(view_plans)); no Moose; diff --git a/lib/Lacuna/Tutorial.pm b/lib/Lacuna/Tutorial.pm index c112070a..e44e6ea2 100644 --- a/lib/Lacuna/Tutorial.pm +++ b/lib/Lacuna/Tutorial.pm @@ -48,7 +48,7 @@ sub explore_the_ui { if ($finish) { if ($home->name ne $empire->tutorial_scratch) { $empire->add_medal('pleased_to_meet_you'); - $home->add_freebie('Lacuna::DB::Result::Building::Food::Malcud', 1); + $home->add_plan('Lacuna::DB::Result::Building::Food::Malcud', 1); $self->start('get_food'); return undef; } @@ -162,7 +162,7 @@ sub pawn { if ($finish) { my $building = $home->get_building_of_class('Lacuna::DB::Result::Building::Intelligence'); if (defined $building && $building->level >= 1) { - $home->add_freebie('Lacuna::DB::Result::Building::Intelligence', 2); + $home->add_plan('Lacuna::DB::Result::Building::Intelligence', 2); $building->train_spy; $self->start('counter_spy'); return undef; @@ -211,7 +211,7 @@ sub explore { my $empire = $self->empire; if ($finish) { if ($empire->count_probed_stars > 1) { - $empire->home_planet->add_freebie('Lacuna::DB::Result::Building::Transporter', 1); + $empire->home_planet->add_plan('Lacuna::DB::Result::Building::Transporter', 1); $self->start('the_end'); return undef; } @@ -359,7 +359,7 @@ sub fool { my $home = $empire->home_planet; if ($finish) { if ($home->food_hour >= $empire->tutorial_scratch) { - $home->add_freebie('Lacuna::DB::Result::Building::Food::Reserve', 2); + $home->add_plan('Lacuna::DB::Result::Building::Food::Reserve', 2); $empire->add_essentia(35)->update; $self->start('essentia'); return undef; @@ -397,7 +397,7 @@ sub energy { my $home = $empire->home_planet; if ($finish) { if ($home->energy_hour >= $empire->tutorial_scratch) { - $home->add_freebie('Lacuna::DB::Result::Building::Energy::Reserve', 2); + $home->add_plan('Lacuna::DB::Result::Building::Energy::Reserve', 2); $self->start('the_300'); return undef; } @@ -419,8 +419,8 @@ sub the_300 { my $home = $empire->home_planet; if ($finish) { if ($home->ore_hour >= 50 && $home->water_hour >= 50) { - $home->add_freebie('Lacuna::DB::Result::Building::Ore::Storage', 2); - $home->add_freebie('Lacuna::DB::Result::Building::Water::Storage', 2); + $home->add_plan('Lacuna::DB::Result::Building::Ore::Storage', 2); + $home->add_plan('Lacuna::DB::Result::Building::Water::Storage', 2); $self->start('news'); return undef; } diff --git a/t/Command.t b/t/Command.t index ff1f531a..657452d3 100644 --- a/t/Command.t +++ b/t/Command.t @@ -24,10 +24,10 @@ foreach my $bid (keys %{$result->{result}{buildings}}) { $result = $tester->post('planetarycommand', 'view', [$session_id, $id]); is($result->{result}{planet}{building_count}, 1, "got building count"); -$tester->empire->home_planet->add_freebie('Lacuna::DB::Result::Building::SpacePort', 5); +$tester->empire->home_planet->add_plan('Lacuna::DB::Result::Building::SpacePort', 5); -$result = $tester->post('planetarycommand', 'view_freebies', [$session_id, $id]); -is($result->{result}{freebies}{'Space Port'}, 5, 'got freebies list'); +$result = $tester->post('planetarycommand', 'view_plans', [$session_id, $id]); +is($result->{result}{plans}{'Space Port'}, 5, 'got plans list'); END { $tester->cleanup; -- knotmirror 0.0.1