]> ruin.nu Git - ndwebbie.git/commitdiff
Add a calc link on raids
authorMichael Andreen <harv@ruin.nu>
Fri, 30 Jan 2009 20:36:06 +0000 (21:36 +0100)
committerMichael Andreen <harv@ruin.nu>
Fri, 30 Jan 2009 20:36:06 +0000 (21:36 +0100)
database/shipid.sql [new file with mode: 0644]
lib/NDWeb.pm
lib/NDWeb/Controller/Raids.pm
root/src/raids/view.tt2

diff --git a/database/shipid.sql b/database/shipid.sql
new file mode 100644 (file)
index 0000000..6b6e81e
--- /dev/null
@@ -0,0 +1,2 @@
+ALTER TABLE ship_stats ADD id SERIAL UNIQUE NOT NULL;
+UPDATE ship_stats SET id = id - 3;
index b5fa7e4e52e617eb1770b295f44c7101c0d2d19c..313ba3369911b6c2adc235e7908d0329ad19fe7c 100644 (file)
@@ -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/]);
index 2808d3297dfc304ce6ab7cc83a0f024b1cec5796..d13b6704895b533fddf03e6ae9e6298c7dc6e2ae 100644 (file)
@@ -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;
index 4b88e7ad0c3b784019a0571288b406558398a250..d30885d01b33a0bb8b14033d342c68f62e40ee2c 100644 (file)
@@ -22,6 +22,7 @@
 [% FOR t IN targets %]
 <fieldset class="[% t.style %]"> <legend><a name="target[% t.id %]">Target: #[% t.id %]</a></legend>
        <div class="leftinfo"><ul>
+               <li><a href="[% c.uri_for('targetcalc',t.id) %]" rel="external">Calc</a></li>
                <li>Size: [% t.size %]</li>
                <li class="[% t.scorebash %]">Score: [% t.score %]</li>
                <li class="[% t.valuebash %]">Value: [% t.value %]</li>