From 936b6772dcdc1dadc519785b760933a70b059367 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Sun, 27 Mar 2011 17:41:37 -0500 Subject: [PATCH] added space stations to stars and bodies --- docs/Body.pod | 12 ++++++++++- docs/Map.pod | 6 ++++++ lib/Lacuna/DB/Result/Laws.pm | 2 ++ lib/Lacuna/DB/Result/Map/Body.pm | 9 ++++++++ lib/Lacuna/DB/Result/Map/Body/Planet.pm | 6 ++++++ .../DB/Result/Map/Body/Planet/Station.pm | 1 + lib/Lacuna/DB/Result/Map/Star.pm | 21 ++++++++++++++++++- var/upgrades/3.0400.sql | 7 ++++++- var/www/public/changes.txt | 2 ++ 9 files changed, 63 insertions(+), 3 deletions(-) diff --git a/docs/Body.pod b/docs/Body.pod index 6930e872..7032f009 100644 --- a/docs/Body.pod +++ b/docs/Body.pod @@ -66,7 +66,17 @@ B You should probably B call this method directly, as it is a wast "is_ally" : 1 # is this from a planet within our alliance }, ... - ] + ], + "station" : { # only shows up if this planet is under the influence of a space station + "id" : "id-goes-here", + "x" : 143, + "y" : -27, + "name" : "The Death Star" + } + "alliance" : { # only shows up if type is "space station" + "id" : "id-goes-here", + "name" : "Imperial Empire" + } } } diff --git a/docs/Map.pod b/docs/Map.pod index c25edbf5..fdedd639 100644 --- a/docs/Map.pod +++ b/docs/Map.pod @@ -23,6 +23,12 @@ Retrieves a chunk of the map and returns it as an array of hashes. B Coor "color" : "yellow", "x" : -41, "y" : 27, + "station" : { # only shows up if this star is under the influence of a space station + "id" : "id-goes-here", + "x" : 143, + "y" : -27, + "name" : "The Death Star" + }, "bodies" : [ # only added if a probe is present { same data as get_status() on /body diff --git a/lib/Lacuna/DB/Result/Laws.pm b/lib/Lacuna/DB/Result/Laws.pm index 328bcda1..e9a8005f 100644 --- a/lib/Lacuna/DB/Result/Laws.pm +++ b/lib/Lacuna/DB/Result/Laws.pm @@ -16,6 +16,7 @@ __PACKAGE__->add_columns( type => { data_type => 'varchar', size => 30, is_nullable => 0 }, scratch => { data_type => 'mediumblob', is_nullable => 1, 'serializer_class' => 'JSON' }, date_enacted => { data_type => 'datetime', is_nullable => 0, set_on_create => 1 }, + star_id => { data_type => 'int', is_nullable => 1 }, ); __PACKAGE__->typecast_map(type => { @@ -23,6 +24,7 @@ __PACKAGE__->typecast_map(type => { }); __PACKAGE__->belongs_to('station', 'Lacuna::DB::Result::Map::Body', 'station_id'); +__PACKAGE__->belongs_to('star', 'Lacuna::DB::Result::Map::Star', 'star_id', { on_delete => 'set null' }); sub sqlt_deploy_hook { my ($self, $sqlt_table) = @_; diff --git a/lib/Lacuna/DB/Result/Map/Body.pm b/lib/Lacuna/DB/Result/Map/Body.pm index 1bf5c430..6af5da93 100644 --- a/lib/Lacuna/DB/Result/Map/Body.pm +++ b/lib/Lacuna/DB/Result/Map/Body.pm @@ -241,6 +241,15 @@ sub get_status { zone => $self->zone, id => $self->id, ); + if ($self->star->station_id) { + my $station = $self->star->station; + $out{station} = { + id => $station->id, + x => $station->x, + y => $station->y, + name => $station->name, + }; + } return \%out; } diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet.pm b/lib/Lacuna/DB/Result/Map/Body/Planet.pm index 55996159..4354e877 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet.pm @@ -237,6 +237,12 @@ around get_status => sub { $out->{empire}{alignment} = $self->empire->is_isolationist ? 'ally-isolationist' : 'ally'; } } + if ($self->isa('Lacuna::DB::Result::Map::Body::Planet::Station') && defined $self->alliance) { + $out->{alliance} = { + id => $self->alliance->id, + name => $self->alliance->name, + } + } } return $out; }; diff --git a/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm b/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm index 2b1c4f05..b35af9da 100644 --- a/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm +++ b/lib/Lacuna/DB/Result/Map/Body/Planet/Station.pm @@ -9,6 +9,7 @@ use Lacuna::Util qw(randint); use constant image => 'station'; __PACKAGE__->has_many('propositions','Lacuna::DB::Result::Propositions','station_id'); __PACKAGE__->has_many('laws','Lacuna::DB::Result::Laws','station_id'); +__PACKAGE__->has_many('stars','Lacuna::DB::Result::Map::Star','station_id'); has parliament => ( is => 'rw', diff --git a/lib/Lacuna/DB/Result/Map/Star.pm b/lib/Lacuna/DB/Result/Map/Star.pm index 65d7e2e5..1198bb4d 100644 --- a/lib/Lacuna/DB/Result/Map/Star.pm +++ b/lib/Lacuna/DB/Result/Map/Star.pm @@ -9,10 +9,20 @@ use Lacuna::Util; __PACKAGE__->table('star'); __PACKAGE__->add_columns( color => { data_type => 'varchar', size => 7, is_nullable => 0 }, + station_id => { data_type => 'int', is_nullable => 1 }, ); __PACKAGE__->has_many('bodies', 'Lacuna::DB::Result::Map::Body', 'star_id'); - +__PACKAGE__->has_many('laws', 'Lacuna::DB::Result::Laws', 'star_id'); +__PACKAGE__->belongs_to('station', 'Lacuna::DB::Result::Map::Body', 'station_id', { on_delete => 'set null' }); + +sub send_predefined_message { + my ($self, %options) = @_; + my $members = $self->bodies->search({empire_id => {'!=' => undef } }); + while (my $body = $members->next) { + $body->empire->send_predefined_message(%options); + } +} sub get_status { my ($self, $empire, $override_probe) = @_; @@ -32,6 +42,15 @@ sub get_status { push @orbits, $body->get_status($empire); } $out->{bodies} = \@orbits; + if ($self->station_id) { + my $station = $self->station; + $out->{station} = { + id => $station->id, + x => $station->x, + y => $station->y, + name => $station->name, + }; + } } } return $out; diff --git a/var/upgrades/3.0400.sql b/var/upgrades/3.0400.sql index 3af2ef73..4897d898 100644 --- a/var/upgrades/3.0400.sql +++ b/var/upgrades/3.0400.sql @@ -6,8 +6,13 @@ CREATE TABLE `laws` ( `type` varchar(30) NOT NULL, `scratch` mediumblob, `date_enacted` datetime NOT NULL, + `star_id` int(11) DEFAULT NULL, PRIMARY KEY (`id`), + KEY `laws_idx_star_id` (`star_id`), KEY `laws_idx_station_id` (`station_id`), KEY `idx_date_enacted` (`date_enacted`), + CONSTRAINT `laws_fk_star_id` FOREIGN KEY (`star_id`) REFERENCES `star` (`id`) ON DELETE SET NULL, CONSTRAINT `laws_fk_station_id` FOREIGN KEY (`station_id`) REFERENCES `body` (`id`) -); +); +alter table star add column station_id int; +alter table star add foreign key star_fk_alliance_id (station_id) references body (id) on delete set null; diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index 7f923436..4dfff930 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -2,6 +2,8 @@ - Add: Added the Opera House, Art Museum, and Culinary Institute space station modules. - Rule: SAWs now cost less in upkeep. - Rule: Station modules cannot be upgraded past the station command level. + - API: Added "station" element to the status of bodies and probed stars. + - API: Added "alliance" element to the status of bodies that are space stations. - API: Added proposing enacting writs at Parliament level 4. - API: Added transfering ownership of stations at Parliament level 5. - API: Added proposing firing the station's BFG at Parliament level 30. -- 2.51.2