From 641ebf214cd52696a2ad70652c4b56f2170f1ef1 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Wed, 5 May 2010 22:58:08 -0500 Subject: [PATCH] star map generation working --- bin/init_lacuna.pl | 201 ++++++++++----------- bin/install-pm.sh | 2 +- lib/Lacuna.pm | 13 +- lib/Lacuna/Cache.pm | 180 ++++++++++++++++++ lib/Lacuna/DB/Result.pm | 3 +- lib/Lacuna/DB/Result/Body.pm | 162 ++++++++++++++++- lib/Lacuna/DB/Result/Body/Planet.pm | 149 --------------- lib/Lacuna/DB/Result/Building.pm | 7 +- lib/Lacuna/DB/Result/Building/Energy.pm | 18 +- lib/Lacuna/DB/Result/Building/Food.pm | 50 ++--- lib/Lacuna/DB/Result/Building/Ore.pm | 14 +- lib/Lacuna/DB/Result/Building/Permanent.pm | 2 + lib/Lacuna/DB/Result/Building/Waste.pm | 10 +- lib/Lacuna/DB/Result/Building/Water.pm | 14 +- lib/Lacuna/DB/Result/Empire.pm | 4 +- lib/Lacuna/DB/Result/Party.pm | 2 +- lib/Lacuna/DB/Result/Probes.pm | 2 +- lib/Lacuna/DB/Result/ShipBuilds.pm | 2 +- lib/Lacuna/DB/Result/Ships.pm | 2 +- lib/Lacuna/DB/Result/Species.pm | 4 +- lib/Lacuna/DB/Result/Spies.pm | 4 +- lib/Lacuna/DB/Result/Star.pm | 5 +- lib/Lacuna/DB/Result/Trades.pm | 2 +- lib/Lacuna/Species.pm | 1 - 24 files changed, 515 insertions(+), 338 deletions(-) create mode 100644 lib/Lacuna/Cache.pm diff --git a/bin/init_lacuna.pl b/bin/init_lacuna.pl index a5d3c027..67e6c662 100644 --- a/bin/init_lacuna.pl +++ b/bin/init_lacuna.pl @@ -7,56 +7,30 @@ use Lacuna::Util qw(randint); use DateTime; my $config = Lacuna->config; -my $db = Lacuna::DB->new(access_key=>$config->get('access_key'), secret_key=>$config->get('secret_key'), cache_servers=>$config->get('memcached')); +my $db = Lacuna->db; my $lacunans; my $lacunans_have_been_placed = 0; +create_database(); create_species(); -create_aux_domains(); open my $star_names, "<", "../var/starnames.txt"; create_star_map(); close $star_names; -sub create_aux_domains { - foreach my $name (qw(empire session build_queue message travel_queue news spies ship_builds)) { - my $domain = $db->domain($name); - say "Deleting existing $name domain."; - $domain->delete; - say "Creating new $name domain."; - $domain->create; - } +sub create_database { + $db->deploy({ add_drop_table => 1 }); } sub create_species { - my $species = $db->domain('species'); - say "Deleting existing species domain."; - $species->delete; - say "Creating new species domain."; - $species->create; - say "Adding humans."; - $species->insert({ - name => 'Human', - description => 'A race of average intellect, and weak constitution.', - habitable_orbits => [3], - manufacturing_affinity => 4, # cost of building new stuff - deception_affinity => 4, # spying ability - research_affinity => 4, # cost of upgrading - management_affinity => 4, # speed to build - farming_affinity => 4, # food - mining_affinity => 4, # minerals - science_affinity => 4, # energy, propultion, and other tech - environmental_affinity => 4, # waste and water - political_affinity => 4, # happiness - trade_affinity => 4, # speed of cargoships, and amount of cargo hauled - growth_affinity => 4, # price and speed of colony ships, and planetary command center start level - }, id=>'human_species'); say "Adding Lacunans."; - $lacunans = $species->insert({ + $lacunans = $db->resultset('Lacuna::DB::Result::Species')->new({ + id => 1, name => 'Lacunan', description => 'The economic dieties that control the Lacuna Expanse.', - habitable_orbits => [1,2,3,4,5,6,7], - manufacturing_affinity => 1, # cost of building new stuff + min_orbit => 1, + max_orbit => 7, + manufacturing_affinity => 1, # cost of building new stuff deception_affinity => 7, # spying ability research_affinity => 1, # cost of upgrading management_affinity => 4, # speed to build @@ -67,7 +41,27 @@ sub create_species { political_affinity => 7, # happiness trade_affinity => 7, # speed of cargoships, and amount of cargo hauled growth_affinity => 7, # price and speed of colony ships, and planetary command center start level - }, id=>'lacunan_species'); + }); + $lacunans->insert; + say "Adding humans."; + $db->resultset('Lacuna::DB::Result::Species')->new({ + id => 2, + name => 'Human', + description => 'A race of average intellect, and weak constitution.', + min_orbit => 3, + max_orbit => 3, + manufacturing_affinity => 4, # cost of building new stuff + deception_affinity => 4, # spying ability + research_affinity => 4, # cost of upgrading + management_affinity => 4, # speed to build + farming_affinity => 4, # food + mining_affinity => 4, # minerals + science_affinity => 4, # energy, propultion, and other tech + environmental_affinity => 4, # waste and water + political_affinity => 4, # happiness + trade_affinity => 4, # speed of cargoships, and amount of cargo hauled + growth_affinity => 4, # price and speed of colony ships, and planetary command center start level + })->insert; } @@ -78,15 +72,6 @@ sub create_star_map { my ($start_z, $end_z) = @{$map_size->{z}}; my $star_count = abs($end_x - $start_x) * abs($end_y - $start_y) * abs($end_z - $start_z); my @star_colors = (qw(magenta red green blue yellow white)); - my %domains; - foreach my $domain (qw(star body ore water building waste energy food permanent)) { - $domains{$domain} = $db->domain($domain); - say "Deleting existing $domain domain."; - $domains{$domain}->delete; - say "Create new $domain domain."; - $domains{$domain}->create; - } - my $made_lacuna = 0; say "Adding stars."; for my $x ($start_x .. $end_x) { @@ -105,18 +90,16 @@ sub create_star_map { $name = 'Lacuna'; } say "Creating star $name at $x, $y, $z."; - my $star = Lacuna::DB::Result::Star->new( - simpledb => $db, + my $star = $db->resultset('Lacuna::DB::Result::Star')->new({ name => $name, - date_created=> DateTime->now, color => $star_colors[rand(scalar(@star_colors))], x => $x, y => $y, z => $z, - ); + }); $star->set_zone_from_xyz; - $star->put; - add_bodies(\%domains, $star); + $star->insert; + add_bodies($star); } say "End Z $z"; } @@ -128,7 +111,6 @@ sub create_star_map { sub add_bodies { - my $domains = shift; my $star = shift; my @body_types = ('habitable', 'asteroid', 'gas giant'); my @body_type_weights = (qw(60 15 15)); @@ -157,14 +139,15 @@ sub add_bodies { y => $star->y, z => $star->z, star_id => $star->id, - usable_as_starter => 'No', zone => $star->zone, + usable_as_starter => 0, + empire_id => 0, }; + my $body; if ($type eq 'habitable') { $params->{class} = $planet_classes[rand(scalar(@planet_classes))]; - $params->{empire_id} = 'None'; - $params->{size} = ($params->{orbit} == 3) ? randint(45,60) : randint(25,85); - $params->{usable_as_starter} = ($params->{size} >= 47 && $params->{size} <= 56) ? rand(99999) : 'No'; + $params->{size} = ($params->{orbit} == 3) ? randint(35,55) : randint(25,75); + $params->{usable_as_starter} = ($params->{size} >= 40 && $params->{size} <= 50) ? randint(1,9999) : 0; } elsif ($type eq 'asteroid') { $params->{class} = $asteroid_classes[rand(scalar(@asteroid_classes))]; @@ -172,75 +155,83 @@ sub add_bodies { } else { $params->{class} = $gas_giant_classes[rand(scalar(@gas_giant_classes))]; - $params->{empire_id} = 'None'; $params->{size} = randint(70,121); } - my $body = $domains->{body}->insert($params); - my $now = DateTime->now; + $body = $db->resultset('Lacuna::DB::Result::Body')->new($params); + $body->insert; if ($body->isa('Lacuna::DB::Result::Body::Planet') && !$body->isa('Lacuna::DB::Result::Body::Planet::GasGiant')) { if ($star->name eq 'Lacuna' && !$lacunans_have_been_placed) { - $body->name('Lacuna'); - $body->put; - create_lacuna_corp($body, $domains); - $lacunans_have_been_placed = 1; + # create_lacunan_home_world($body); next; } - say "\t\tAdding features to body."; - foreach my $x (-3, -1, 2, 4, 1) { - my $chance = randint(1,100); - my $y = randint(-5,5); - if ($chance <= 5) { - say "\t\t\tAdding lake."; - $domains->{permanent}->insert({ - date_created => $now, - level => 1, - x => $x, - y => $y, - class => 'Lacuna::DB::Result::Building::Permanent::Lake', - body_id => $body->id, - }); - } - elsif ($chance > 45 && $chance <= 50) { - say "\t\t\tAdding rocky outcropping."; - $domains->{permanent}->insert({ - date_created => $now, - level => 1, - x => $x, - y => $y, - class => 'Lacuna::DB::Result::Building::Permanent::RockyOutcrop', - body_id => $body->id, - }); - } - elsif ($chance > 95) { - say "\t\t\tAdding crater."; - $domains->{permanent}->insert({ - date_created => $now, - level => 1, - x => $x, - y => $y, - class => 'Lacuna::DB::Result::Building::Permanent::Crater', - body_id => $body->id, - }); - } + else { + add_features($body); } } } } } -sub create_lacuna_corp { - my ($body, $domains) = @_; +sub add_features { + my $body = shift; + say "\t\tAdding features to body."; + my $now = DateTime->now; + foreach my $x (-3, -1, 2, 4, 1) { + my $chance = randint(1,100); + my $y = randint(-5,5); + if ($chance <= 5) { + say "\t\t\tAdding lake."; + $db->resultset('Lacuna::DB::Result::Building::Permanent')->new({ + date_created => $now, + level => 1, + x => $x, + y => $y, + class => 'Lacuna::DB::Result::Building::Permanent::Lake', + body_id => $body->id, + })->insert; + } + elsif ($chance > 45 && $chance <= 50) { + say "\t\t\tAdding rocky outcropping."; + $db->resultset('Lacuna::DB::Result::Building::Permanent')->new({ + date_created => $now, + level => 1, + x => $x, + y => $y, + class => 'Lacuna::DB::Result::Building::Permanent::RockyOutcrop', + body_id => $body->id, + })->insert; + } + elsif ($chance > 95) { + say "\t\t\tAdding crater."; + $db->resultset('Lacuna::DB::Result::Building::Permanent')->new({ + date_created => $now, + level => 1, + x => $x, + y => $y, + class => 'Lacuna::DB::Result::Building::Permanent::Crater', + body_id => $body->id, + })->insert; + } + } +} + + +sub create_lacunan_home_world { + my $body = shift; + $body->update({name=>'Lacuna'}); say "\t\t\tMaking this the Lacunans home world."; my $empire = Lacuna::DB::Result::Empire->create( $db, {name=>'Lacuna Expanse Corp', password=>rand(9999999)}, 'lacuna_expanse_corp' ); - $empire->species_id($lacunans->id); - $empire->put; - $empire->found($body) + $empire->update({species_id => $lacunans->id}); + $empire->found($body); + $lacunans_have_been_placed = 1; } + + sub get_star_name { my $name = <$star_names>; chomp $name; diff --git a/bin/install-pm.sh b/bin/install-pm.sh index 03d51f64..dc57fe76 100755 --- a/bin/install-pm.sh +++ b/bin/install-pm.sh @@ -1 +1 @@ -cpanm JSON::XS JSON Config::JSON Starman JSON::RPC::Dispatcher String::Random List::Util::WeightedChoice List::Util List::MoreUtils DateTime Regexp::Common Pod::Simple::HTML File::Copy DateTime::Format::Duration XML::FeedPP SOAP::Amazon::S3 DBD::mysql DBIx::Class DBIx::Class::InflateColumn::Serializer DBIx::Class::DynamicSubclass +cpanm Memcached::libmemcached DateTime::Format::MySQL JSON::XS JSON Config::JSON Starman JSON::RPC::Dispatcher String::Random List::Util::WeightedChoice List::Util List::MoreUtils DateTime Regexp::Common Pod::Simple::HTML File::Copy DateTime::Format::Duration XML::FeedPP SOAP::Amazon::S3 DBD::mysql DBIx::Class DBIx::Class::InflateColumn::Serializer DBIx::Class::DynamicSubclass diff --git a/lib/Lacuna.pm b/lib/Lacuna.pm index ba4bab3a..4056a76e 100644 --- a/lib/Lacuna.pm +++ b/lib/Lacuna.pm @@ -9,7 +9,9 @@ useall __PACKAGE__; our $VERSION = 1.1001; -our $config = Config::JSON->new('/data/Lacuna-Server/etc/lacuna.conf'); +my $config = Config::JSON->new('/data/Lacuna-Server/etc/lacuna.conf'); +my $db = Lacuna::DB->connect($config->get('db/dsn'),$config->get('db/username')); +my $cache = Lacuna::Cache->new(servers => $config->get('memcached')); sub version { return $VERSION; @@ -19,4 +21,13 @@ sub config { return $config; } +sub db { + return $db; +} + +sub cache { + return $cache; +} + + 1; diff --git a/lib/Lacuna/Cache.pm b/lib/Lacuna/Cache.pm new file mode 100644 index 00000000..d5c23da9 --- /dev/null +++ b/lib/Lacuna/Cache.pm @@ -0,0 +1,180 @@ +package Lacuna::Cache; + +use strict; +use Moose; +use Memcached::libmemcached; +use JSON; + +has 'servers' => ( + is => 'ro', + required => 1, +); + +has 'memcached' => ( + is => 'ro', + lazy => 1, + clearer => 'clear_memcached', + default => sub { + my $self = shift; + my $memcached = Memcached::libmemcached::memcached_create(); + foreach my $server (@{$self->servers}) { + if (exists $server->{socket}) { + Memcached::libmemcached::memcached_server_add_unix_socket($memcached, $server->{socket}); + } + else { + Memcached::libmemcached::memcached_server_add($memcached, $server->{host}, $server->{port}); + } + } + return $memcached; + }, +); + +sub fix_key { + my ($self, $namespace, $id) = @_; + my $key = $namespace.":".$id; + $key =~ s/\s+/_/g; + return $key; +} + +sub delete { + my ($self, $namespace, $id, $retry) = @_; + my $key = $self->fix_key($namespace, $id); + my $memcached = $self->memcached; + Memcached::libmemcached::memcached_delete($memcached, $key); + if ($memcached->errstr eq 'SYSTEM ERROR Unknown error: 0') { + confess "Cannot connect to memcached server."; + } + elsif ($memcached->errstr eq 'UNKNOWN READ FAILURE' ) { + if ($retry) { + confess "Cannot connect to memcached server."; + } + else { + warn "Memcached went away, reconnecting."; + $self->clear_memcached; + $self->delete($namespace, $id, 1); + } + } + elsif ($memcached->errstr eq 'NOT FOUND' ) { + confess "The cache key $key has no value."; + } + elsif ($memcached->errstr eq 'NO SERVERS DEFINED') { + confess "No memcached servers specified."; + } + elsif ($memcached->errstr ne 'SUCCESS' # deleted + && $memcached->errstr ne 'PROTOCOL ERROR' # doesn't exist to delete + ) { + confess "Couldn't delete $key from cache because ".$memcached->errstr; + } +} + +sub flush { + my ($self, $retry) = @_; + my $memcached = $self->memcached; + Memcached::libmemcached::memcached_flush($memcached); + if ($memcached->errstr eq 'SYSTEM ERROR Unknown error: 0') { + confess "Cannot connect to memcached server."; + } + elsif ($memcached->errstr eq 'UNKNOWN READ FAILURE' ) { + confess "Cannot connect to memcached server." if $retry; + warn "Memcached went away, reconnecting."; + $self->clear_memcached; + return $self->flush(1); + } + elsif ($memcached->errstr eq 'NO SERVERS DEFINED') { + confess "No memcached servers specified."; + } + elsif ($memcached->errstr ne 'SUCCESS') { + confess "Couldn't flush cache because ".$memcached->errstr; + } +} + +sub get { + my ($self, $namespace, $id, $retry) = @_; + my $key = $self->fix_key($namespace, $id); + my $memcached = $self->memcached; + my $content = Memcached::libmemcached::memcached_get($memcached, $key); + $content = JSON::from_json($content); + if ($memcached->errstr eq 'SUCCESS') { + if (ref $content) { + return $content; + } + else { + confess "Couldn't thaw value for $key."; + } + } + elsif ($memcached->errstr eq 'NOT FOUND' ) { + confess "The cache key $key has no value."; + } + elsif ($memcached->errstr eq 'NO SERVERS DEFINED') { + confess "No memcached servers specified."; + } + elsif ($memcached->errstr eq 'SYSTEM ERROR Unknown error: 0' || $retry) { + confess "Cannot connect to memcached server."; + } + elsif ($memcached->errstr eq 'UNKNOWN READ FAILURE' ) { + warn "Memcached went away, reconnecting."; + $self->clear_memcached; + return $self->get($namespace, $id, 1); + } + confess "Couldn't get $key from cache because ".$memcached->errstr; +} + +sub mget { + my ($self, $names, $retry) = @_; + my @keys = map { $self->fix_key(@{$_}) } @{ $names }; + my %result; + my $memcached = $self->memcached; + $memcached->mget_into_hashref(\@keys, \%result); + if ($memcached->errstr eq 'SYSTEM ERROR Unknown error: 0') { + confess "Cannot connect to memcached server."; + } + elsif ($memcached->errstr eq 'UNKNOWN READ FAILURE' ) { + confess "Cannot connect to memcached server." if $retry; + warn "Memcached went away, reconnecting."; + $self->clear_memcached; + return $self->get($names, 1); + } + elsif ($memcached->errstr eq 'NO SERVERS DEFINED') { + confess "No memcached servers specified."; + } + # no other useful status messages are returned + my @values; + foreach my $key (@keys) { + my $content = JSON::from_json($result{$key}); + unless (ref $content) { + confess "Can't thaw object returned from memcache for $key."; + next; + } + push @values, $content; + } + return \@values; +} + +sub set { + my ($self, $namespace, $id, $value, $ttl, $retry) = @_; + my $key = $self->fix_key($namespace, $id); + $ttl ||= 60; + my $frozenValue = JSON::to_json($value); + my $memcached = $self->memcached; + Memcached::libmemcached::memcached_set($memcached, $key, $frozenValue, $ttl); + if ($memcached->errstr eq 'SUCCESS') { + return $value; + } + elsif ($memcached->errstr eq 'SYSTEM ERROR Unknown error: 0' || $retry) { + confess "Cannot connect to memcached server."; + } + elsif ($memcached->errstr eq 'UNKNOWN READ FAILURE' ) { + warn "Memcached went away, reconnecting."; + $self->clear_memcached; + return $self->set($namespace, $id, $value, $ttl, 1); + } + elsif ($memcached->errstr eq 'NO SERVERS DEFINED') { + confess "No memcached servers specified."; + } + confess "Couldn't set $key to cache because ".$memcached->errstr; +} + + +no Moose; +__PACKAGE__->meta->make_immutable; + diff --git a/lib/Lacuna/DB/Result.pm b/lib/Lacuna/DB/Result.pm index a9bc1033..e447c51d 100644 --- a/lib/Lacuna/DB/Result.pm +++ b/lib/Lacuna/DB/Result.pm @@ -3,7 +3,8 @@ package Lacuna::DB::Result; use Moose; extends qw/DBIx::Class/; -__PACKAGE__->load_components('DynamicSubclass', 'InflateColumn::DateTime', 'InflateColumn::Serializer', 'Core'); +#__PACKAGE__->load_components('DynamicSubclass', 'InflateColumn::DateTime', 'InflateColumn::Serializer', 'Core'); +__PACKAGE__->load_components('InflateColumn::DateTime', 'InflateColumn::Serializer', 'Core'); __PACKAGE__->table('noexist_basetable'); __PACKAGE__->add_columns( diff --git a/lib/Lacuna/DB/Result/Body.pm b/lib/Lacuna/DB/Result/Body.pm index 6234ed52..222128a0 100644 --- a/lib/Lacuna/DB/Result/Body.pm +++ b/lib/Lacuna/DB/Result/Body.pm @@ -4,18 +4,125 @@ use Moose; extends 'Lacuna::DB::Result'; use Lacuna::Util; +__PACKAGE__->load_components('DynamicSubclass'); __PACKAGE__->table('body'); __PACKAGE__->add_columns( - name => { data_type => 'char', size => 30, is_nullable => 0 }, - star_id => { data_type => 'int', size => 11, is_nullable => 0 }, - usable_as_starter => { data_type => 'int', size => 11, default_value => 0 }, - orbit => { data_type => 'int', size => 11, default_value => 0 }, - x => { data_type => 'int', size => 11, default_value => 0 }, # indexed here to speed up - y => { data_type => 'int', size => 11, default_value => 0 }, # searching of planets based - z => { data_type => 'int', size => 11, default_value => 0 }, # on stor location - zone => { data_type => 'char', size => 16, is_nullable => 0 }, # fast index for where we are - class => { data_type => 'char', size => 255, is_nullable => 0 }, - size => { data_type => 'int', size => 11, default_value => 0 }, + name => { data_type => 'char', size => 30, is_nullable => 0 }, + star_id => { data_type => 'int', size => 11, is_nullable => 0 }, + orbit => { data_type => 'int', size => 11, default_value => 0 }, + x => { data_type => 'int', size => 11, default_value => 0 }, # indexed here to speed up + y => { data_type => 'int', size => 11, default_value => 0 }, # searching of planets based + z => { data_type => 'int', size => 11, default_value => 0 }, # on stor location + zone => { data_type => 'char', size => 16, is_nullable => 0 }, # fast index for where we are + class => { data_type => 'char', size => 255, is_nullable => 0 }, + size => { data_type => 'int', size => 11, default_value => 0 }, + usable_as_starter => { data_type => 'int', size => 11, default_value => 0 }, + size => { data_type => 'int', size => 11, default_value => 0 }, + empire_id => { data_type => 'int', size => 11, is_nullable => 1 }, + last_tick => { data_type => 'datetime', is_nullable => 0 }, + building_count => { data_type => 'int', size => 11, default_value => 0 }, + happiness_hour => { data_type => 'int', size => 11, default_value => 0 }, + happiness => { data_type => 'int', size => 11, default_value => 0 }, + waste_hour => { data_type => 'int', size => 11, default_value => 0 }, + waste_stored => { data_type => 'int', size => 11, default_value => 0 }, + waste_capacity => { data_type => 'int', size => 11, default_value => 0 }, + energy_hour => { data_type => 'int', size => 11, default_value => 0 }, + energy_stored => { data_type => 'int', size => 11, default_value => 0 }, + energy_capacity => { data_type => 'int', size => 11, default_value => 0 }, + water_hour => { data_type => 'int', size => 11, default_value => 0 }, + water_stored => { data_type => 'int', size => 11, default_value => 0 }, + water_capacity => { data_type => 'int', size => 11, default_value => 0 }, + ore_capacity => { data_type => 'int', size => 11, default_value => 0 }, + rutile_stored => { data_type => 'int', size => 11, default_value => 0 }, + chromite_stored => { data_type => 'int', size => 11, default_value => 0 }, + chalcopyrite_stored => { data_type => 'int', size => 11, default_value => 0 }, + galena_stored => { data_type => 'int', size => 11, default_value => 0 }, + gold_stored => { data_type => 'int', size => 11, default_value => 0 }, + uraninite_stored => { data_type => 'int', size => 11, default_value => 0 }, + bauxite_stored => { data_type => 'int', size => 11, default_value => 0 }, + goethite_stored => { data_type => 'int', size => 11, default_value => 0 }, + halite_stored => { data_type => 'int', size => 11, default_value => 0 }, + gypsum_stored => { data_type => 'int', size => 11, default_value => 0 }, + trona_stored => { data_type => 'int', size => 11, default_value => 0 }, + kerogen_stored => { data_type => 'int', size => 11, default_value => 0 }, + methane_stored => { data_type => 'int', size => 11, default_value => 0 }, + anthracite_stored => { data_type => 'int', size => 11, default_value => 0 }, + sulfur_stored => { data_type => 'int', size => 11, default_value => 0 }, + zircon_stored => { data_type => 'int', size => 11, default_value => 0 }, + monazite_stored => { data_type => 'int', size => 11, default_value => 0 }, + fluorite_stored => { data_type => 'int', size => 11, default_value => 0 }, + beryl_stored => { data_type => 'int', size => 11, default_value => 0 }, + magnetite_stored => { data_type => 'int', size => 11, default_value => 0 }, + rutile_hour => { data_type => 'int', size => 11, default_value => 0 }, + chromite_hour => { data_type => 'int', size => 11, default_value => 0 }, + chalcopyrite_hour => { data_type => 'int', size => 11, default_value => 0 }, + galena_hour => { data_type => 'int', size => 11, default_value => 0 }, + gold_hour => { data_type => 'int', size => 11, default_value => 0 }, + uraninite_hour => { data_type => 'int', size => 11, default_value => 0 }, + bauxite_hour => { data_type => 'int', size => 11, default_value => 0 }, + goethite_hour => { data_type => 'int', size => 11, default_value => 0 }, + halite_hour => { data_type => 'int', size => 11, default_value => 0 }, + gypsum_hour => { data_type => 'int', size => 11, default_value => 0 }, + trona_hour => { data_type => 'int', size => 11, default_value => 0 }, + kerogen_hour => { data_type => 'int', size => 11, default_value => 0 }, + methane_hour => { data_type => 'int', size => 11, default_value => 0 }, + anthracite_hour => { data_type => 'int', size => 11, default_value => 0 }, + sulfur_hour => { data_type => 'int', size => 11, default_value => 0 }, + zircon_hour => { data_type => 'int', size => 11, default_value => 0 }, + monazite_hour => { data_type => 'int', size => 11, default_value => 0 }, + fluorite_hour => { data_type => 'int', size => 11, default_value => 0 }, + beryl_hour => { data_type => 'int', size => 11, default_value => 0 }, + magnetite_hour => { data_type => 'int', size => 11, default_value => 0 }, + ore_hour => { data_type => 'int', size => 11, default_value => 0 }, + food_capacity => { data_type => 'int', size => 11, default_value => 0 }, + food_consumption_hour => { data_type => 'int', size => 11, default_value => 0 }, + lapis_production_hour => { data_type => 'int', size => 11, default_value => 0 }, + potato_production_hour => { data_type => 'int', size => 11, default_value => 0 }, + apple_production_hour => { data_type => 'int', size => 11, default_value => 0 }, + root_production_hour => { data_type => 'int', size => 11, default_value => 0 }, + corn_production_hour => { data_type => 'int', size => 11, default_value => 0 }, + cider_production_hour => { data_type => 'int', size => 11, default_value => 0 }, + wheat_production_hour => { data_type => 'int', size => 11, default_value => 0 }, + bread_production_hour => { data_type => 'int', size => 11, default_value => 0 }, + soup_production_hour => { data_type => 'int', size => 11, default_value => 0 }, + chip_production_hour => { data_type => 'int', size => 11, default_value => 0 }, + pie_production_hour => { data_type => 'int', size => 11, default_value => 0 }, + pancake_production_hour => { data_type => 'int', size => 11, default_value => 0 }, + milk_production_hour => { data_type => 'int', size => 11, default_value => 0 }, + meal_production_hour => { data_type => 'int', size => 11, default_value => 0 }, + algae_production_hour => { data_type => 'int', size => 11, default_value => 0 }, + syrup_production_hour => { data_type => 'int', size => 11, default_value => 0 }, + fungus_production_hour => { data_type => 'int', size => 11, default_value => 0 }, + burger_production_hour => { data_type => 'int', size => 11, default_value => 0 }, + shake_production_hour => { data_type => 'int', size => 11, default_value => 0 }, + beetle_production_hour => { data_type => 'int', size => 11, default_value => 0 }, + bean_production_hour => { data_type => 'int', size => 11, default_value => 0 }, + bean_stored => { data_type => 'int', size => 11, default_value => 0 }, + lapis_stored => { data_type => 'int', size => 11, default_value => 0 }, + potato_stored => { data_type => 'int', size => 11, default_value => 0 }, + apple_stored => { data_type => 'int', size => 11, default_value => 0 }, + root_stored => { data_type => 'int', size => 11, default_value => 0 }, + corn_stored => { data_type => 'int', size => 11, default_value => 0 }, + cider_stored => { data_type => 'int', size => 11, default_value => 0 }, + wheat_stored => { data_type => 'int', size => 11, default_value => 0 }, + bread_stored => { data_type => 'int', size => 11, default_value => 0 }, + soup_stored => { data_type => 'int', size => 11, default_value => 0 }, + chip_stored => { data_type => 'int', size => 11, default_value => 0 }, + pie_stored => { data_type => 'int', size => 11, default_value => 0 }, + pancake_stored => { data_type => 'int', size => 11, default_value => 0 }, + milk_stored => { data_type => 'int', size => 11, default_value => 0 }, + meal_stored => { data_type => 'int', size => 11, default_value => 0 }, + algae_stored => { data_type => 'int', size => 11, default_value => 0 }, + syrup_stored => { data_type => 'int', size => 11, default_value => 0 }, + fungus_stored => { data_type => 'int', size => 11, default_value => 0 }, + burger_stored => { data_type => 'int', size => 11, default_value => 0 }, + shake_stored => { data_type => 'int', size => 11, default_value => 0 }, + beetle_stored => { data_type => 'int', size => 11, default_value => 0 }, + freebies => { data_type => 'mediumtext', is_nullable => 1, 'serializer_class' => 'JSON' }, + boost_enabled => { data_type => 'int', size => 1, default_value => 0 }, + needs_recalc => { data_type => 'int', size => 1, default_value => 0 }, + restrict_coverage => { data_type => 'int', size => 1, default_value => 1 }, + restrict_coverage_delta => { data_type => 'datetime', is_nullable => 0 }, ); __PACKAGE__->typecast_map(class => { @@ -24,9 +131,44 @@ __PACKAGE__->typecast_map(class => { 'Lacuna::DB::Result::Body::Asteroid::A3' => 'Lacuna::DB::Result::Body::Asteroid::A3', 'Lacuna::DB::Result::Body::Asteroid::A4' => 'Lacuna::DB::Result::Body::Asteroid::A4', 'Lacuna::DB::Result::Body::Asteroid::A5' => 'Lacuna::DB::Result::Body::Asteroid::A5', + 'Lacuna::DB::Result::Body::Planet::P1' => 'Lacuna::DB::Result::Body::Planet::P1', + 'Lacuna::DB::Result::Body::Planet::P2' => 'Lacuna::DB::Result::Body::Planet::P2', + 'Lacuna::DB::Result::Body::Planet::P3' => 'Lacuna::DB::Result::Body::Planet::P3', + 'Lacuna::DB::Result::Body::Planet::P4' => 'Lacuna::DB::Result::Body::Planet::P4', + 'Lacuna::DB::Result::Body::Planet::P5' => 'Lacuna::DB::Result::Body::Planet::P5', + 'Lacuna::DB::Result::Body::Planet::P6' => 'Lacuna::DB::Result::Body::Planet::P6', + 'Lacuna::DB::Result::Body::Planet::P7' => 'Lacuna::DB::Result::Body::Planet::P7', + 'Lacuna::DB::Result::Body::Planet::P8' => 'Lacuna::DB::Result::Body::Planet::P8', + 'Lacuna::DB::Result::Body::Planet::P9' => 'Lacuna::DB::Result::Body::Planet::P9', + 'Lacuna::DB::Result::Body::Planet::P10' => 'Lacuna::DB::Result::Body::Planet::P10', + 'Lacuna::DB::Result::Body::Planet::P11' => 'Lacuna::DB::Result::Body::Planet::P11', + 'Lacuna::DB::Result::Body::Planet::P12' => 'Lacuna::DB::Result::Body::Planet::P12', + 'Lacuna::DB::Result::Body::Planet::P13' => 'Lacuna::DB::Result::Body::Planet::P13', + 'Lacuna::DB::Result::Body::Planet::P14' => 'Lacuna::DB::Result::Body::Planet::P14', + 'Lacuna::DB::Result::Body::Planet::P15' => 'Lacuna::DB::Result::Body::Planet::P15', + 'Lacuna::DB::Result::Body::Planet::P16' => 'Lacuna::DB::Result::Body::Planet::P17', + 'Lacuna::DB::Result::Body::Planet::P17' => 'Lacuna::DB::Result::Body::Planet::P17', + 'Lacuna::DB::Result::Body::Planet::P18' => 'Lacuna::DB::Result::Body::Planet::P18', + 'Lacuna::DB::Result::Body::Planet::P19' => 'Lacuna::DB::Result::Body::Planet::P19', + 'Lacuna::DB::Result::Body::Planet::P20' => 'Lacuna::DB::Result::Body::Planet::P20', + 'Lacuna::DB::Result::Body::Planet::GasGiant::G1' => 'Lacuna::DB::Result::Body::Planet::GasGiant::G1', + 'Lacuna::DB::Result::Body::Planet::GasGiant::G2' => 'Lacuna::DB::Result::Body::Planet::GasGiant::G2', + 'Lacuna::DB::Result::Body::Planet::GasGiant::G3' => 'Lacuna::DB::Result::Body::Planet::GasGiant::G3', + 'Lacuna::DB::Result::Body::Planet::GasGiant::G4' => 'Lacuna::DB::Result::Body::Planet::GasGiant::G4', + 'Lacuna::DB::Result::Body::Planet::GasGiant::G5' => 'Lacuna::DB::Result::Body::Planet::GasGiant::G5', }); +# RELATIONSHIPS + __PACKAGE__->belongs_to('star', 'Lacuna::DB::Result::Star', 'star_id'); +#__PACKAGE__->belongs_to('empire', 'Lacuna::DB::Result::Empire', 'empire_id'); +#__PACKAGE__->has_many('regular_buildings','Lacuna::DB::Result::Building','body_id'); +#__PACKAGE__->has_many('food_buildings','Lacuna::DB::Result::Building::Food','body_id'); +#__PACKAGE__->has_many('water_buildings','Lacuna::DB::Result::Building::Water','body_id'); +#__PACKAGE__->has_many('waste_buildings','Lacuna::DB::Result::Building::Waste','body_id'); +#__PACKAGE__->has_many('ore_buildings','Lacuna::DB::Result::Building::Ore', 'body_id'); +#__PACKAGE__->has_many('energy_buildings','Lacuna::DB::Result::Building::Energy','body_id'); +__PACKAGE__->has_many('permanent_buildings','Lacuna::DB::Result::Building::Permanent','body_id'); with 'Lacuna::Role::Zoned'; diff --git a/lib/Lacuna/DB/Result/Body/Planet.pm b/lib/Lacuna/DB/Result/Body/Planet.pm index bc8e0365..c04afe50 100644 --- a/lib/Lacuna/DB/Result/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Body/Planet.pm @@ -8,155 +8,6 @@ use Lacuna::Util qw(to_seconds randint); use DateTime; no warnings 'uninitialized'; -__PACKAGE__->load_components(qw/DynamicSubclass/); -__PACKAGE__->table('planet'); -__PACKAGE__->add_columns( - size => { data_type => 'int', size => 11, default_value => 0 }, - empire_id => { data_type => 'int', size => 11, is_nullable => 1 }, - last_tick => { data_type => 'datetime', is_nullable => 0 }, - building_count => { data_type => 'int', size => 11, default_value => 0 }, - happiness_hour => { data_type => 'int', size => 11, default_value => 0 }, - happiness => { data_type => 'int', size => 11, default_value => 0 }, - waste_hour => { data_type => 'int', size => 11, default_value => 0 }, - waste_stored => { data_type => 'int', size => 11, default_value => 0 }, - waste_capacity => { data_type => 'int', size => 11, default_value => 0 }, - energy_hour => { data_type => 'int', size => 11, default_value => 0 }, - energy_stored => { data_type => 'int', size => 11, default_value => 0 }, - energy_capacity => { data_type => 'int', size => 11, default_value => 0 }, - water_hour => { data_type => 'int', size => 11, default_value => 0 }, - water_stored => { data_type => 'int', size => 11, default_value => 0 }, - water_capacity => { data_type => 'int', size => 11, default_value => 0 }, - ore_capacity => { data_type => 'int', size => 11, default_value => 0 }, - rutile_stored => { data_type => 'int', size => 11, default_value => 0 }, - chromite_stored => { data_type => 'int', size => 11, default_value => 0 }, - chalcopyrite_stored => { data_type => 'int', size => 11, default_value => 0 }, - galena_stored => { data_type => 'int', size => 11, default_value => 0 }, - gold_stored => { data_type => 'int', size => 11, default_value => 0 }, - uraninite_stored => { data_type => 'int', size => 11, default_value => 0 }, - bauxite_stored => { data_type => 'int', size => 11, default_value => 0 }, - goethite_stored => { data_type => 'int', size => 11, default_value => 0 }, - halite_stored => { data_type => 'int', size => 11, default_value => 0 }, - gypsum_stored => { data_type => 'int', size => 11, default_value => 0 }, - trona_stored => { data_type => 'int', size => 11, default_value => 0 }, - kerogen_stored => { data_type => 'int', size => 11, default_value => 0 }, - methane_stored => { data_type => 'int', size => 11, default_value => 0 }, - anthracite_stored => { data_type => 'int', size => 11, default_value => 0 }, - sulfur_stored => { data_type => 'int', size => 11, default_value => 0 }, - zircon_stored => { data_type => 'int', size => 11, default_value => 0 }, - monazite_stored => { data_type => 'int', size => 11, default_value => 0 }, - fluorite_stored => { data_type => 'int', size => 11, default_value => 0 }, - beryl_stored => { data_type => 'int', size => 11, default_value => 0 }, - magnetite_stored => { data_type => 'int', size => 11, default_value => 0 }, - rutile_hour => { data_type => 'int', size => 11, default_value => 0 }, - chromite_hour => { data_type => 'int', size => 11, default_value => 0 }, - chalcopyrite_hour => { data_type => 'int', size => 11, default_value => 0 }, - galena_hour => { data_type => 'int', size => 11, default_value => 0 }, - gold_hour => { data_type => 'int', size => 11, default_value => 0 }, - uraninite_hour => { data_type => 'int', size => 11, default_value => 0 }, - bauxite_hour => { data_type => 'int', size => 11, default_value => 0 }, - goethite_hour => { data_type => 'int', size => 11, default_value => 0 }, - halite_hour => { data_type => 'int', size => 11, default_value => 0 }, - gypsum_hour => { data_type => 'int', size => 11, default_value => 0 }, - trona_hour => { data_type => 'int', size => 11, default_value => 0 }, - kerogen_hour => { data_type => 'int', size => 11, default_value => 0 }, - methane_hour => { data_type => 'int', size => 11, default_value => 0 }, - anthracite_hour => { data_type => 'int', size => 11, default_value => 0 }, - sulfur_hour => { data_type => 'int', size => 11, default_value => 0 }, - zircon_hour => { data_type => 'int', size => 11, default_value => 0 }, - monazite_hour => { data_type => 'int', size => 11, default_value => 0 }, - fluorite_hour => { data_type => 'int', size => 11, default_value => 0 }, - beryl_hour => { data_type => 'int', size => 11, default_value => 0 }, - magnetite_hour => { data_type => 'int', size => 11, default_value => 0 }, - ore_hour => { data_type => 'int', size => 11, default_value => 0 }, - food_capacity => { data_type => 'int', size => 11, default_value => 0 }, - food_consumption_hour => { data_type => 'int', size => 11, default_value => 0 }, - lapis_production_hour => { data_type => 'int', size => 11, default_value => 0 }, - potato_production_hour => { data_type => 'int', size => 11, default_value => 0 }, - apple_production_hour => { data_type => 'int', size => 11, default_value => 0 }, - root_production_hour => { data_type => 'int', size => 11, default_value => 0 }, - corn_production_hour => { data_type => 'int', size => 11, default_value => 0 }, - cider_production_hour => { data_type => 'int', size => 11, default_value => 0 }, - wheat_production_hour => { data_type => 'int', size => 11, default_value => 0 }, - bread_production_hour => { data_type => 'int', size => 11, default_value => 0 }, - soup_production_hour => { data_type => 'int', size => 11, default_value => 0 }, - chip_production_hour => { data_type => 'int', size => 11, default_value => 0 }, - pie_production_hour => { data_type => 'int', size => 11, default_value => 0 }, - pancake_production_hour => { data_type => 'int', size => 11, default_value => 0 }, - milk_production_hour => { data_type => 'int', size => 11, default_value => 0 }, - meal_production_hour => { data_type => 'int', size => 11, default_value => 0 }, - algae_production_hour => { data_type => 'int', size => 11, default_value => 0 }, - syrup_production_hour => { data_type => 'int', size => 11, default_value => 0 }, - fungus_production_hour => { data_type => 'int', size => 11, default_value => 0 }, - burger_production_hour => { data_type => 'int', size => 11, default_value => 0 }, - shake_production_hour => { data_type => 'int', size => 11, default_value => 0 }, - beetle_production_hour => { data_type => 'int', size => 11, default_value => 0 }, - bean_production_hour => { data_type => 'int', size => 11, default_value => 0 }, - bean_stored => { data_type => 'int', size => 11, default_value => 0 }, - lapis_stored => { data_type => 'int', size => 11, default_value => 0 }, - potato_stored => { data_type => 'int', size => 11, default_value => 0 }, - apple_stored => { data_type => 'int', size => 11, default_value => 0 }, - root_stored => { data_type => 'int', size => 11, default_value => 0 }, - corn_stored => { data_type => 'int', size => 11, default_value => 0 }, - cider_stored => { data_type => 'int', size => 11, default_value => 0 }, - wheat_stored => { data_type => 'int', size => 11, default_value => 0 }, - bread_stored => { data_type => 'int', size => 11, default_value => 0 }, - soup_stored => { data_type => 'int', size => 11, default_value => 0 }, - chip_stored => { data_type => 'int', size => 11, default_value => 0 }, - pie_stored => { data_type => 'int', size => 11, default_value => 0 }, - pancake_stored => { data_type => 'int', size => 11, default_value => 0 }, - milk_stored => { data_type => 'int', size => 11, default_value => 0 }, - meal_stored => { data_type => 'int', size => 11, default_value => 0 }, - algae_stored => { data_type => 'int', size => 11, default_value => 0 }, - syrup_stored => { data_type => 'int', size => 11, default_value => 0 }, - fungus_stored => { data_type => 'int', size => 11, default_value => 0 }, - burger_stored => { data_type => 'int', size => 11, default_value => 0 }, - shake_stored => { data_type => 'int', size => 11, default_value => 0 }, - beetle_stored => { data_type => 'int', size => 11, default_value => 0 }, - freebies => { data_type => 'mediumtext', is_nullable => 1, 'serializer_class' => 'JSON' }, - boost_enabled => { data_type => 'int', size => 1, default_value => 0 }, - needs_recalc => { data_type => 'int', size => 1, default_value => 0 }, - restrict_coverage => { data_type => 'int', size => 1, default_value => 1 }, - restrict_coverage_delta => { data_type => 'datetime', is_nullable => 0 }, -); -__PACKAGE__->typecast_map(class => { - 'Lacuna::DB::Result::Body::Planet::P1' => 'Lacuna::DB::Result::Body::Planet::P1', - 'Lacuna::DB::Result::Body::Planet::P2' => 'Lacuna::DB::Result::Body::Planet::P2', - 'Lacuna::DB::Result::Body::Planet::P3' => 'Lacuna::DB::Result::Body::Planet::P3', - 'Lacuna::DB::Result::Body::Planet::P4' => 'Lacuna::DB::Result::Body::Planet::P4', - 'Lacuna::DB::Result::Body::Planet::P5' => 'Lacuna::DB::Result::Body::Planet::P5', - 'Lacuna::DB::Result::Body::Planet::P6' => 'Lacuna::DB::Result::Body::Planet::P6', - 'Lacuna::DB::Result::Body::Planet::P7' => 'Lacuna::DB::Result::Body::Planet::P7', - 'Lacuna::DB::Result::Body::Planet::P8' => 'Lacuna::DB::Result::Body::Planet::P8', - 'Lacuna::DB::Result::Body::Planet::P9' => 'Lacuna::DB::Result::Body::Planet::P9', - 'Lacuna::DB::Result::Body::Planet::P10' => 'Lacuna::DB::Result::Body::Planet::P10', - 'Lacuna::DB::Result::Body::Planet::P11' => 'Lacuna::DB::Result::Body::Planet::P11', - 'Lacuna::DB::Result::Body::Planet::P12' => 'Lacuna::DB::Result::Body::Planet::P12', - 'Lacuna::DB::Result::Body::Planet::P13' => 'Lacuna::DB::Result::Body::Planet::P13', - 'Lacuna::DB::Result::Body::Planet::P14' => 'Lacuna::DB::Result::Body::Planet::P14', - 'Lacuna::DB::Result::Body::Planet::P15' => 'Lacuna::DB::Result::Body::Planet::P15', - 'Lacuna::DB::Result::Body::Planet::P16' => 'Lacuna::DB::Result::Body::Planet::P17', - 'Lacuna::DB::Result::Body::Planet::P17' => 'Lacuna::DB::Result::Body::Planet::P17', - 'Lacuna::DB::Result::Body::Planet::P18' => 'Lacuna::DB::Result::Body::Planet::P18', - 'Lacuna::DB::Result::Body::Planet::P19' => 'Lacuna::DB::Result::Body::Planet::P19', - 'Lacuna::DB::Result::Body::Planet::P20' => 'Lacuna::DB::Result::Body::Planet::P20', - 'Lacuna::DB::Result::Body::Planet::GasGiant::G1' => 'Lacuna::DB::Result::Body::Planet::GasGiant::G1', - 'Lacuna::DB::Result::Body::Planet::GasGiant::G2' => 'Lacuna::DB::Result::Body::Planet::GasGiant::G2', - 'Lacuna::DB::Result::Body::Planet::GasGiant::G3' => 'Lacuna::DB::Result::Body::Planet::GasGiant::G3', - 'Lacuna::DB::Result::Body::Planet::GasGiant::G4' => 'Lacuna::DB::Result::Body::Planet::GasGiant::G4', - 'Lacuna::DB::Result::Body::Planet::GasGiant::G5' => 'Lacuna::DB::Result::Body::Planet::GasGiant::G5', -}); - -# RELATIONSHIPS - -__PACKAGE__->belongs_to('empire', 'Lacuna::DB::Result::Empire', 'empire_id'); -__PACKAGE__->has_many('regular_buildings','Lacuna::DB::Result::Building','body_id'); -__PACKAGE__->has_many('food_buildings','Lacuna::DB::Result::Building::Food','body_id'); -__PACKAGE__->has_many('water_buildings','Lacuna::DB::Result::Building::Water','body_id'); -__PACKAGE__->has_many('waste_buildings','Lacuna::DB::Result::Building::Waste','body_id'); -__PACKAGE__->has_many('ore_buildings','Lacuna::DB::Result::Building::Ore', 'body_id'); -__PACKAGE__->has_many('energy_buildings','Lacuna::DB::Result::Building::Energy','body_id'); -__PACKAGE__->has_many('permanent_buildings','Lacuna::DB::Result::Building::Permanent','body_id'); - sub builds { my ($self, $where, $reverse) = @_; my $order = 'date_complete'; diff --git a/lib/Lacuna/DB/Result/Building.pm b/lib/Lacuna/DB/Result/Building.pm index ad5fdc21..ffc4ec4d 100644 --- a/lib/Lacuna/DB/Result/Building.pm +++ b/lib/Lacuna/DB/Result/Building.pm @@ -5,6 +5,7 @@ extends 'Lacuna::DB::Result'; use Lacuna::Constants ':all'; use List::Util qw(shuffle); +__PACKAGE__->load_components('DynamicSubclass'); __PACKAGE__->table('building'); __PACKAGE__->add_columns( date_created => { data_type => 'datetime', is_nullable => 0 }, @@ -18,10 +19,10 @@ __PACKAGE__->add_columns( offline => { data_type => 'datetime', is_nullable => 0 }, ); -sub body {}; sub empire {}; -__PACKAGE__->belongs_to('build_queue', 'Lacuna::DB::Result::BuildQueue', 'build_queue_id'); -__PACKAGE__->belongs_to('empire', 'Lacuna::DB::Result::Empire', 'empire_id'); +#sub body {}; +#__PACKAGE__->belongs_to('build_queue', 'Lacuna::DB::Result::BuildQueue', 'build_queue_id'); +#__PACKAGE__->belongs_to('empire', 'Lacuna::DB::Result::Empire', 'empire_id'); __PACKAGE__->belongs_to('body', 'Lacuna::DB::Result::Body', 'body_id'); __PACKAGE__->typecast_map(class => { 'Lacuna::DB::Result::Building::Development' => 'Lacuna::DB::Result::Building::Development', diff --git a/lib/Lacuna/DB/Result/Building/Energy.pm b/lib/Lacuna/DB/Result/Building/Energy.pm index 41dec797..bd18aaf5 100644 --- a/lib/Lacuna/DB/Result/Building/Energy.pm +++ b/lib/Lacuna/DB/Result/Building/Energy.pm @@ -11,15 +11,15 @@ around 'build_tags' => sub { }; -__PACKAGE__->typecast_map(class => { - 'Lacuna::DB::Result::Building::Energy::' => 'Lacuna::DB::Result::Building::Energy::Fission', - 'Lacuna::DB::Result::Building::Energy::' => 'Lacuna::DB::Result::Building::Energy::Fusion', - 'Lacuna::DB::Result::Building::Energy::' => 'Lacuna::DB::Result::Building::Energy::Geo', - 'Lacuna::DB::Result::Building::Energy::' => 'Lacuna::DB::Result::Building::Energy::Hydrocarbon', - 'Lacuna::DB::Result::Building::Energy::' => 'Lacuna::DB::Result::Building::Energy::Reserve', - 'Lacuna::DB::Result::Building::Energy::' => 'Lacuna::DB::Result::Building::Energy::Singularity', - 'Lacuna::DB::Result::Building::Energy::' => 'Lacuna::DB::Result::Building::Energy::Waste', -}); +#__PACKAGE__->typecast_map(class => { +# 'Lacuna::DB::Result::Building::Energy::' => 'Lacuna::DB::Result::Building::Energy::Fission', +# 'Lacuna::DB::Result::Building::Energy::' => 'Lacuna::DB::Result::Building::Energy::Fusion', +# 'Lacuna::DB::Result::Building::Energy::' => 'Lacuna::DB::Result::Building::Energy::Geo', +# 'Lacuna::DB::Result::Building::Energy::' => 'Lacuna::DB::Result::Building::Energy::Hydrocarbon', +# 'Lacuna::DB::Result::Building::Energy::' => 'Lacuna::DB::Result::Building::Energy::Reserve', +# 'Lacuna::DB::Result::Building::Energy::' => 'Lacuna::DB::Result::Building::Energy::Singularity', +# 'Lacuna::DB::Result::Building::Energy::' => 'Lacuna::DB::Result::Building::Energy::Waste', +#}); no Moose; __PACKAGE__->meta->make_immutable(inline_constructor => 0); diff --git a/lib/Lacuna/DB/Result/Building/Food.pm b/lib/Lacuna/DB/Result/Building/Food.pm index 4cec000d..9b6d5071 100644 --- a/lib/Lacuna/DB/Result/Building/Food.pm +++ b/lib/Lacuna/DB/Result/Building/Food.pm @@ -10,31 +10,31 @@ around 'build_tags' => sub { return ($orig->($class), qw(Resources Food)); }; -__PACKAGE__->typecast_map(class => { - 'Lacuna::DB::Result::Building::Food::Reserve' => 'Lacuna::DB::Result::Building::Food::Reserve', - 'Lacuna::DB::Result::Building::Food::Factory::Bread' => 'Lacuna::DB::Result::Building::Food::Factory::Bread', - 'Lacuna::DB::Result::Building::Food::Factory::Burger' => 'Lacuna::DB::Result::Building::Food::Factory::Burger', - 'Lacuna::DB::Result::Building::Food::Factory::Cheese' => 'Lacuna::DB::Result::Building::Food::Factory::Cheese', - 'Lacuna::DB::Result::Building::Food::Factory::Chip' => 'Lacuna::DB::Result::Building::Food::Factory::Chip', - 'Lacuna::DB::Result::Building::Food::Factory::Cider' => 'Lacuna::DB::Result::Building::Food::Factory::Cider', - 'Lacuna::DB::Result::Building::Food::Factory::CornMeal' => 'Lacuna::DB::Result::Building::Food::Factory::CornMeal', - 'Lacuna::DB::Result::Building::Food::Factory::Pancake' => 'Lacuna::DB::Result::Building::Food::Factory::Pancake', - 'Lacuna::DB::Result::Building::Food::Factory::Pie' => 'Lacuna::DB::Result::Building::Food::Factory::Pie', - 'Lacuna::DB::Result::Building::Food::Factory::Shake' => 'Lacuna::DB::Result::Building::Food::Factory::Shake', - 'Lacuna::DB::Result::Building::Food::Factory::Soup' => 'Lacuna::DB::Result::Building::Food::Factory::Soup', - 'Lacuna::DB::Result::Building::Food::Factory::Syrup' => 'Lacuna::DB::Result::Building::Food::Factory::Syrup', - 'Lacuna::DB::Result::Building::Food::Farm::Algae' => 'Lacuna::DB::Result::Building::Food::Farm::Algae', - 'Lacuna::DB::Result::Building::Food::Farm::Apple' => 'Lacuna::DB::Result::Building::Food::Farm::Apple', - 'Lacuna::DB::Result::Building::Food::Farm::Beeldeban' => 'Lacuna::DB::Result::Building::Food::Farm::Beeldeban', - 'Lacuna::DB::Result::Building::Food::Farm::Bean' => 'Lacuna::DB::Result::Building::Food::Farm::Bean', - 'Lacuna::DB::Result::Building::Food::Farm::Corn' => 'Lacuna::DB::Result::Building::Food::Farm::Corn', - 'Lacuna::DB::Result::Building::Food::Farm::Dairy' => 'Lacuna::DB::Result::Building::Food::Farm::Dairy', - 'Lacuna::DB::Result::Building::Food::Farm::Lapis' => 'Lacuna::DB::Result::Building::Food::Farm::Lapis', - 'Lacuna::DB::Result::Building::Food::Farm::Malcud' => 'Lacuna::DB::Result::Building::Food::Farm::Malcud', - 'Lacuna::DB::Result::Building::Food::Farm::Potato' => 'Lacuna::DB::Result::Building::Food::Farm::Potato', - 'Lacuna::DB::Result::Building::Food::Farm::Root' => 'Lacuna::DB::Result::Building::Food::Farm::Root', - 'Lacuna::DB::Result::Building::Food::Farm::Wheat' => 'Lacuna::DB::Result::Building::Food::Farm::Wheat', -}); +#__PACKAGE__->typecast_map(class => { +# 'Lacuna::DB::Result::Building::Food::Reserve' => 'Lacuna::DB::Result::Building::Food::Reserve', +# 'Lacuna::DB::Result::Building::Food::Factory::Bread' => 'Lacuna::DB::Result::Building::Food::Factory::Bread', +# 'Lacuna::DB::Result::Building::Food::Factory::Burger' => 'Lacuna::DB::Result::Building::Food::Factory::Burger', +# 'Lacuna::DB::Result::Building::Food::Factory::Cheese' => 'Lacuna::DB::Result::Building::Food::Factory::Cheese', +# 'Lacuna::DB::Result::Building::Food::Factory::Chip' => 'Lacuna::DB::Result::Building::Food::Factory::Chip', +# 'Lacuna::DB::Result::Building::Food::Factory::Cider' => 'Lacuna::DB::Result::Building::Food::Factory::Cider', +# 'Lacuna::DB::Result::Building::Food::Factory::CornMeal' => 'Lacuna::DB::Result::Building::Food::Factory::CornMeal', +# 'Lacuna::DB::Result::Building::Food::Factory::Pancake' => 'Lacuna::DB::Result::Building::Food::Factory::Pancake', +# 'Lacuna::DB::Result::Building::Food::Factory::Pie' => 'Lacuna::DB::Result::Building::Food::Factory::Pie', +# 'Lacuna::DB::Result::Building::Food::Factory::Shake' => 'Lacuna::DB::Result::Building::Food::Factory::Shake', +# 'Lacuna::DB::Result::Building::Food::Factory::Soup' => 'Lacuna::DB::Result::Building::Food::Factory::Soup', +# 'Lacuna::DB::Result::Building::Food::Factory::Syrup' => 'Lacuna::DB::Result::Building::Food::Factory::Syrup', +# 'Lacuna::DB::Result::Building::Food::Farm::Algae' => 'Lacuna::DB::Result::Building::Food::Farm::Algae', +# 'Lacuna::DB::Result::Building::Food::Farm::Apple' => 'Lacuna::DB::Result::Building::Food::Farm::Apple', +# 'Lacuna::DB::Result::Building::Food::Farm::Beeldeban' => 'Lacuna::DB::Result::Building::Food::Farm::Beeldeban', +# 'Lacuna::DB::Result::Building::Food::Farm::Bean' => 'Lacuna::DB::Result::Building::Food::Farm::Bean', +# 'Lacuna::DB::Result::Building::Food::Farm::Corn' => 'Lacuna::DB::Result::Building::Food::Farm::Corn', +# 'Lacuna::DB::Result::Building::Food::Farm::Dairy' => 'Lacuna::DB::Result::Building::Food::Farm::Dairy', +# 'Lacuna::DB::Result::Building::Food::Farm::Lapis' => 'Lacuna::DB::Result::Building::Food::Farm::Lapis', +# 'Lacuna::DB::Result::Building::Food::Farm::Malcud' => 'Lacuna::DB::Result::Building::Food::Farm::Malcud', +# 'Lacuna::DB::Result::Building::Food::Farm::Potato' => 'Lacuna::DB::Result::Building::Food::Farm::Potato', +# 'Lacuna::DB::Result::Building::Food::Farm::Root' => 'Lacuna::DB::Result::Building::Food::Farm::Root', +# 'Lacuna::DB::Result::Building::Food::Farm::Wheat' => 'Lacuna::DB::Result::Building::Food::Farm::Wheat', +#}); no Moose; diff --git a/lib/Lacuna/DB/Result/Building/Ore.pm b/lib/Lacuna/DB/Result/Building/Ore.pm index c184d895..fd1f4af3 100644 --- a/lib/Lacuna/DB/Result/Building/Ore.pm +++ b/lib/Lacuna/DB/Result/Building/Ore.pm @@ -5,13 +5,13 @@ extends 'Lacuna::DB::Result::Building'; __PACKAGE__->table('ore'); -__PACKAGE__->typecast_map(class => { - 'Lacuna::DB::Result::Building::Ore::Mine' => 'Lacuna::DB::Result::Building::Ore::Mine', - 'Lacuna::DB::Result::Building::Ore::Ministry' => 'Lacuna::DB::Result::Building::Ore::Ministry', - 'Lacuna::DB::Result::Building::Ore::Platform' => 'Lacuna::DB::Result::Building::Ore::Platform', - 'Lacuna::DB::Result::Building::Ore::Refinery' => 'Lacuna::DB::Result::Building::Ore::Refinery', - 'Lacuna::DB::Result::Building::Ore::Storage' => 'Lacuna::DB::Result::Building::Ore::Storage', -}); +#__PACKAGE__->typecast_map(class => { +# 'Lacuna::DB::Result::Building::Ore::Mine' => 'Lacuna::DB::Result::Building::Ore::Mine', +# 'Lacuna::DB::Result::Building::Ore::Ministry' => 'Lacuna::DB::Result::Building::Ore::Ministry', +# 'Lacuna::DB::Result::Building::Ore::Platform' => 'Lacuna::DB::Result::Building::Ore::Platform', +# 'Lacuna::DB::Result::Building::Ore::Refinery' => 'Lacuna::DB::Result::Building::Ore::Refinery', +# 'Lacuna::DB::Result::Building::Ore::Storage' => 'Lacuna::DB::Result::Building::Ore::Storage', +#}); around 'build_tags' => sub { diff --git a/lib/Lacuna/DB/Result/Building/Permanent.pm b/lib/Lacuna/DB/Result/Building/Permanent.pm index c529d471..e13ba061 100644 --- a/lib/Lacuna/DB/Result/Building/Permanent.pm +++ b/lib/Lacuna/DB/Result/Building/Permanent.pm @@ -3,6 +3,8 @@ package Lacuna::DB::Result::Building::Permanent; use Moose; extends 'Lacuna::DB::Result::Building'; +__PACKAGE__->load_components('DynamicSubclass'); + __PACKAGE__->table('permanent'); __PACKAGE__->typecast_map(class => { diff --git a/lib/Lacuna/DB/Result/Building/Waste.pm b/lib/Lacuna/DB/Result/Building/Waste.pm index a39e1c15..bb75f5d2 100644 --- a/lib/Lacuna/DB/Result/Building/Waste.pm +++ b/lib/Lacuna/DB/Result/Building/Waste.pm @@ -5,11 +5,11 @@ extends 'Lacuna::DB::Result::Building'; __PACKAGE__->table('waste'); -__PACKAGE__->typecast_map(class => { - 'Lacuna::DB::Result::Building::Waste::Recycling' => 'Lacuna::DB::Result::Building::Waste::Recycling', - 'Lacuna::DB::Result::Building::Waste::Sequestration' => 'Lacuna::DB::Result::Building::Waste::Sequestration', - 'Lacuna::DB::Result::Building::Waste::Treatment' => 'Lacuna::DB::Result::Building::Waste::Treatment', -}); +#__PACKAGE__->typecast_map(class => { +# 'Lacuna::DB::Result::Building::Waste::Recycling' => 'Lacuna::DB::Result::Building::Waste::Recycling', +# 'Lacuna::DB::Result::Building::Waste::Sequestration' => 'Lacuna::DB::Result::Building::Waste::Sequestration', +# 'Lacuna::DB::Result::Building::Waste::Treatment' => 'Lacuna::DB::Result::Building::Waste::Treatment', +#}); around 'build_tags' => sub { my ($orig, $class) = @_; diff --git a/lib/Lacuna/DB/Result/Building/Water.pm b/lib/Lacuna/DB/Result/Building/Water.pm index 008e07e8..ab9de721 100644 --- a/lib/Lacuna/DB/Result/Building/Water.pm +++ b/lib/Lacuna/DB/Result/Building/Water.pm @@ -4,13 +4,13 @@ use Moose; extends 'Lacuna::DB::Result::Building'; __PACKAGE__->table('water'); - -__PACKAGE__->typecast_map(class => { - 'Lacuna::DB::Result::Building::Water::Production' => 'Lacuna::DB::Result::Building::Water::Production', - 'Lacuna::DB::Result::Building::Water::Purification' => 'Lacuna::DB::Result::Building::Water::Purification', - 'Lacuna::DB::Result::Building::Water::Reclamation' => 'Lacuna::DB::Result::Building::Water::Reclamation', - 'Lacuna::DB::Result::Building::Water::Storage' => 'Lacuna::DB::Result::Building::Water::Storage', -}); +# +#__PACKAGE__->typecast_map(class => { +# 'Lacuna::DB::Result::Building::Water::Production' => 'Lacuna::DB::Result::Building::Water::Production', +# 'Lacuna::DB::Result::Building::Water::Purification' => 'Lacuna::DB::Result::Building::Water::Purification', +# 'Lacuna::DB::Result::Building::Water::Reclamation' => 'Lacuna::DB::Result::Building::Water::Reclamation', +# 'Lacuna::DB::Result::Building::Water::Storage' => 'Lacuna::DB::Result::Building::Water::Storage', +#}); around 'build_tags' => sub { my ($orig, $class) = @_; diff --git a/lib/Lacuna/DB/Result/Empire.pm b/lib/Lacuna/DB/Result/Empire.pm index 09ba631b..0e995bc3 100644 --- a/lib/Lacuna/DB/Result/Empire.pm +++ b/lib/Lacuna/DB/Result/Empire.pm @@ -36,9 +36,9 @@ __PACKAGE__->add_columns( # personal confederacies __PACKAGE__->belongs_to('species', 'Lacuna::DB::Result::Species', 'species_id'); -__PACKAGE__->belongs_to('home_planet', 'Lacuna::DB::Result::Body::Planet', 'home_planet_id'); +__PACKAGE__->belongs_to('home_planet', 'Lacuna::DB::Result::Body', 'home_planet_id'); __PACKAGE__->has_many('sessions', 'Lacuna::DB::Result::Session', 'empire_id'); -__PACKAGE__->has_many('planets', 'Lacuna::DB::Result::Body::Planet', 'empire_id'); +__PACKAGE__->has_many('planets', 'Lacuna::DB::Result::Body', 'empire_id'); __PACKAGE__->has_many('sent_messages', 'Lacuna::DB::Result::Message', 'from_id'); __PACKAGE__->has_many('received_messages', 'Lacuna::DB::Result::Message', 'to_id'); __PACKAGE__->has_many('build_queues', 'Lacuna::DB::Result::BuildQueue', 'empire_id'); diff --git a/lib/Lacuna/DB/Result/Party.pm b/lib/Lacuna/DB/Result/Party.pm index 09d6d1c5..147c02c1 100644 --- a/lib/Lacuna/DB/Result/Party.pm +++ b/lib/Lacuna/DB/Result/Party.pm @@ -14,7 +14,7 @@ __PACKAGE__->add_columns( ); #__PACKAGE__->belongs_to('park', 'Lacuna::DB::Result::Building::Park', 'park_id'); -__PACKAGE__->belongs_to('body', 'Lacuna::DB::Result::Body::Planet', 'body_id'); +__PACKAGE__->belongs_to('body', 'Lacuna::DB::Result::Body', 'body_id'); sub party_seconds_remaining { my ($self) = @_; diff --git a/lib/Lacuna/DB/Result/Probes.pm b/lib/Lacuna/DB/Result/Probes.pm index c6c55ca1..c68c069c 100644 --- a/lib/Lacuna/DB/Result/Probes.pm +++ b/lib/Lacuna/DB/Result/Probes.pm @@ -14,7 +14,7 @@ __PACKAGE__->add_columns( __PACKAGE__->belongs_to('empire', 'Lacuna::DB::Result::Empire', 'empire_id'); __PACKAGE__->belongs_to('star', 'Lacuna::DB::Result::Star', 'star_id'); -__PACKAGE__->belongs_to('body', 'Lacuna::DB::Result::Body::Planet', 'body_id'); +__PACKAGE__->belongs_to('body', 'Lacuna::DB::Result::Body', 'body_id'); no Moose; diff --git a/lib/Lacuna/DB/Result/ShipBuilds.pm b/lib/Lacuna/DB/Result/ShipBuilds.pm index fbde220e..5ff68eb4 100644 --- a/lib/Lacuna/DB/Result/ShipBuilds.pm +++ b/lib/Lacuna/DB/Result/ShipBuilds.pm @@ -14,7 +14,7 @@ __PACKAGE__->add_columns( ); #__PACKAGE__->belongs_to('shipyard', 'Lacuna::DB::Result::Building::Shipyard', 'shipyard_id'); -__PACKAGE__->belongs_to('body', 'Lacuna::DB::Result::Body::Planet', 'body_id'); +__PACKAGE__->belongs_to('body', 'Lacuna::DB::Result::Body', 'body_id'); sub date_completed_formatted { my $self = shift; diff --git a/lib/Lacuna/DB/Result/Ships.pm b/lib/Lacuna/DB/Result/Ships.pm index 9d4b15dd..b8548023 100644 --- a/lib/Lacuna/DB/Result/Ships.pm +++ b/lib/Lacuna/DB/Result/Ships.pm @@ -23,7 +23,7 @@ __PACKAGE__->add_columns( ); __PACKAGE__->belongs_to('shipyard', 'Lacuna::DB::Result::Building::SpacePort', 'spaceport_id'); -__PACKAGE__->belongs_to('body', 'Lacuna::DB::Result::Body::Planet', 'body_id'); +__PACKAGE__->belongs_to('body', 'Lacuna::DB::Result::Body', 'body_id'); sub date_completed_formatted { my $self = shift; diff --git a/lib/Lacuna/DB/Result/Species.pm b/lib/Lacuna/DB/Result/Species.pm index fb423f3e..8efa70b3 100644 --- a/lib/Lacuna/DB/Result/Species.pm +++ b/lib/Lacuna/DB/Result/Species.pm @@ -25,8 +25,8 @@ __PACKAGE__->add_columns( growth_affinity => { data_type => 'int', size => 1, default_value => 4 }, # price and speed of colony ships, and planetary command center start level ); -__PACKAGE__->has_many('empires', 'Lacuna::DB::Result::Empire', 'species_id'); -__PACKAGE__->belongs_to('creator', 'Lacuna::DB::Result::Empire', 'empire_id'); +#__PACKAGE__->has_many('empires', 'Lacuna::DB::Result::Empire', 'species_id'); +#__PACKAGE__->belongs_to('creator', 'Lacuna::DB::Result::Empire', 'empire_id'); no Moose; diff --git a/lib/Lacuna/DB/Result/Spies.pm b/lib/Lacuna/DB/Result/Spies.pm index 57a674fd..4985bfec 100644 --- a/lib/Lacuna/DB/Result/Spies.pm +++ b/lib/Lacuna/DB/Result/Spies.pm @@ -18,8 +18,8 @@ __PACKAGE__->add_columns( ); __PACKAGE__->belongs_to('empire', 'Lacuna::DB::Result::Empire', 'empire_id'); -__PACKAGE__->belongs_to('from_body', 'Lacuna::DB::Result::Body::Planet', 'from_body_id'); -__PACKAGE__->belongs_to('on_body', 'Lacuna::DB::Result::Body::Planet', 'on_body_id'); +__PACKAGE__->belongs_to('from_body', 'Lacuna::DB::Result::Body', 'from_body_id'); +__PACKAGE__->belongs_to('on_body', 'Lacuna::DB::Result::Body', 'on_body_id'); sub format_available_on { my ($self) = @_; diff --git a/lib/Lacuna/DB/Result/Star.pm b/lib/Lacuna/DB/Result/Star.pm index 46679c2b..17efb31b 100644 --- a/lib/Lacuna/DB/Result/Star.pm +++ b/lib/Lacuna/DB/Result/Star.pm @@ -7,7 +7,7 @@ use Lacuna::Util; __PACKAGE__->table('star'); __PACKAGE__->add_columns( name => { data_type => 'char', size => 30, is_nullable => 0 }, - color => { data_type => 'char', size => 6, is_nullable => 0 }, + color => { data_type => 'char', size => 7, is_nullable => 0 }, x => { data_type => 'int', size => 11, default_value => 0 }, y => { data_type => 'int', size => 11, default_value => 0 }, z => { data_type => 'int', size => 11, default_value => 0 }, @@ -16,8 +16,7 @@ __PACKAGE__->add_columns( with 'Lacuna::Role::Zoned'; -__PACKAGE__->has_many('bodies', 'Lacuna::DB::Result::Body', 'star_id'); -__PACKAGE__->has_many('planets', 'Lacuna::DB::Result::Body::Planet', 'star_id'); +#__PACKAGE__->has_many('bodies', 'Lacuna::DB::Result::Body', 'star_id'); sub get_status { diff --git a/lib/Lacuna/DB/Result/Trades.pm b/lib/Lacuna/DB/Result/Trades.pm index d5884065..5d8b7ad0 100644 --- a/lib/Lacuna/DB/Result/Trades.pm +++ b/lib/Lacuna/DB/Result/Trades.pm @@ -66,7 +66,7 @@ __PACKAGE__->add_columns( magnetite => { data_type => 'int', size => 11, default_value => 0 }, ); -__PACKAGE__->belongs_to('body', 'Lacuna::DB::Result::Body::Planet', 'body_id'); +__PACKAGE__->belongs_to('body', 'Lacuna::DB::Result::Body', 'body_id'); sub add_trade { my ($class, %options) = @_; diff --git a/lib/Lacuna/Species.pm b/lib/Lacuna/Species.pm index 8a1d307f..2c6e5f87 100644 --- a/lib/Lacuna/Species.pm +++ b/lib/Lacuna/Species.pm @@ -2,7 +2,6 @@ package Lacuna::Species; use Moose; extends 'JSON::RPC::Dispatcher::App'; -use Lacuna::Util qw(cname); has simpledb => ( is => 'ro', -- knotmirror 0.0.1