From: Michael Andreen Date: Fri, 30 Jan 2009 20:36:06 +0000 (+0100) Subject: Add a calc link on raids X-Git-Url: https://ruin.nu/git/?p=ndwebbie.git;a=commitdiff_plain;h=4f142aefe97e62d8510e8f4c69e18cdad8766d13 Add a calc link on raids --- diff --git a/database/shipid.sql b/database/shipid.sql new file mode 100644 index 0000000..6b6e81e --- /dev/null +++ b/database/shipid.sql @@ -0,0 +1,2 @@ +ALTER TABLE ship_stats ADD id SERIAL UNIQUE NOT NULL; +UPDATE ship_stats SET id = id - 3; diff --git a/lib/NDWeb.pm b/lib/NDWeb.pm index b5fa7e4..313ba33 100644 --- a/lib/NDWeb.pm +++ b/lib/NDWeb.pm @@ -93,6 +93,7 @@ __PACKAGE__->allow_access_if('/calls/findCall',[qw/members/]); __PACKAGE__->deny_access_unless('/raids',[qw/raids_edit/]); __PACKAGE__->allow_access_if('/raids/index',[qw//]); __PACKAGE__->allow_access_if('/raids/view',[qw//]); +__PACKAGE__->allow_access_if('/raids/targetcalc',[qw//]); __PACKAGE__->allow_access_if('/raids/findRaid',[qw//]); __PACKAGE__->allow_access_if('/raids/log',[qw//]); __PACKAGE__->deny_access_unless('/intel',[qw/intel/]); diff --git a/lib/NDWeb/Controller/Raids.pm b/lib/NDWeb/Controller/Raids.pm index 2808d32..d13b670 100644 --- a/lib/NDWeb/Controller/Raids.pm +++ b/lib/NDWeb/Controller/Raids.pm @@ -572,6 +572,71 @@ sub posttargetalliances : Local { $c->res->redirect($c->uri_for('targetlist',join ',',$c->req->param('alliances'))); } +sub targetcalc : Local { + my ($self, $c, $target) = @_; + my $dbh = $c->model; + + my $target = $dbh->selectrow_hashref(q{ +SELECT p.id,p.value,p.score,metal_roids, crystal_roids, eonium_roids, ds.total, race +FROM raids r + JOIN raid_targets rt ON r.id = rt.raid + JOIN current_planet_stats p ON rt.planet = p.id + LEFT OUTER JOIN current_planet_scans ps ON p.id = ps.planet + LEFT OUTER JOIN current_development_scans ds ON p.id = ds.planet +WHERE rt.id = ? AND r.open AND not r.removed + AND r.id IN (SELECT raid FROM raid_access NATURAL JOIN groupmembers WHERE uid = ?) + },undef,$target,$c->user->id); + + my $planet = $dbh->selectrow_hashref(q{ +SELECT score,value FROM current_planet_stats WHERE id = $1 + },undef,$c->user->planet); + + my %races = (Ter => 1, Cat => 2, Xan => 3, Zik => 4, Etd => 5); + my @query = ( + "def_1_race=$races{$target->{race}}", + "def_structures=$target->{total}", + "def_metal_asteroids=$target->{metal_roids}", + "def_crystal_asteroids=$target->{crystal_roids}", + "def_eonium_asteroids=$target->{eonium_roids}", + #"def_planet_value_1=$target->{value}", + #"def_planet_score_1=$target->{score}", + "att_planet_value_1=$planet->{value}", + "att_planet_score_1=$planet->{score}", + ); + + my $fleets = $dbh->prepare(q{ +SELECT DISTINCT ON (name) name, tick, fid FROM fleets +WHERE planet = $1 AND mission = 'Full fleet' +ORDER BY name ASC, tick DESC + }); + my $ships = $dbh->prepare(q{ +SELECT id, amount FROM fleet_ships fs JOIN ship_stats s ON s.name = fs.ship +WHERE fid = $1 + }); + + for ('def','att'){ + my $planet = $c->user->planet; + $planet = $target->{id} if /^def/; + $fleets->execute($planet); + my $nrfleets = 0; + my $tick = 0; + while (my $fleet = $fleets->fetchrow_hashref){ + $ships->execute($fleet->{fid}); + next unless $tick < $fleet->{tick}; + $tick = $fleet->{tick}; + ++$nrfleets; + while (my $ship = $ships->fetchrow_hashref){ + push @query, "${_}_${nrfleets}_$ship->{id}=$ship->{amount}"; + } + } + push @query, "${_}_fleets=$nrfleets"; + } + my $query = join '&', @query; + #$c->res->body("http://game.planetarion.com/bcalc.pl?$query"); + $c->res->redirect("http://game.planetarion.com/bcalc.pl?$query"); +} + + sub listAlliances : Private { my ($self, $c) = @_; my @alliances; diff --git a/root/src/raids/view.tt2 b/root/src/raids/view.tt2 index 4b88e7a..d30885d 100644 --- a/root/src/raids/view.tt2 +++ b/root/src/raids/view.tt2 @@ -22,6 +22,7 @@ [% FOR t IN targets %]
Target: #[% t.id %]
    +
  • Calc
  • Size: [% t.size %]
  • Score: [% t.score %]
  • Value: [% t.value %]