]> ruin.nu Git - ndwebbie.git/commitdiff
alliance resources
authorMichael Andreen <harv@ruin.nu>
Fri, 15 Dec 2006 12:38:23 +0000 (12:38 +0000)
committerMichael Andreen <harv@ruin.nu>
Fri, 15 Dec 2006 12:38:23 +0000 (12:38 +0000)
index.pl
resources.pl [new file with mode: 0644]
templates/resources.tmpl [new file with mode: 0644]
templates/skel.tmpl

index fe1572b68330d920d1e89d4fd2256bc5c513aa33..31beaf5ce486f3a2159fb571bf263ea700825ea0 100755 (executable)
--- a/index.pl
+++ b/index.pl
@@ -64,7 +64,7 @@ while (my ($name,$attack,$gid) = $query->fetchrow()){
 our $LOG = $DBH->prepare('INSERT INTO log (uid,text) VALUES(?,?)');
 
 my $page = 'main';
-if (param('page') =~ /^(main|check|motd|points|covop|top100|launchConfirmation|addintel|defrequest|raids|editRaid|calls|intel|users|alliances|memberIntel)$/){
+if (param('page') =~ /^(main|check|motd|points|covop|top100|launchConfirmation|addintel|defrequest|raids|editRaid|calls|intel|users|alliances|memberIntel|resources)$/){
        $page = $1;
 }
 
diff --git a/resources.pl b/resources.pl
new file mode 100644 (file)
index 0000000..5e63b7a
--- /dev/null
@@ -0,0 +1,60 @@
+#**************************************************************************
+#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
+#                                                                         *
+#   This program is free software; you can redistribute it and/or modify  *
+#   it under the terms of the GNU General Public License as published by  *
+#   the Free Software Foundation; either version 2 of the License, or     *
+#   (at your option) any later version.                                   *
+#                                                                         *
+#   This program is distributed in the hope that it will be useful,       *
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+#   GNU General Public License for more details.                          *
+#                                                                         *
+#   You should have received a copy of the GNU General Public License     *
+#   along with this program; if not, write to the                         *
+#   Free Software Foundation, Inc.,                                       *
+#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+#**************************************************************************/
+
+use strict;
+use POSIX;
+our $BODY;
+our $DBH;
+our $LOG;
+my $error;
+
+$ND::TEMPLATE->param(TITLE => 'Alliance Resources');
+
+die "You don't have access" unless isHC();
+
+my $order = "respplanet DESC";
+if (param('order') =~ /^(score|resources|respplanet|nscore|nscore2|nscore3)$/){
+       $order = "$1 DESC";
+}
+
+
+my $query = $DBH->prepare(qq{
+SELECT a.id,a.name,a.relationship,s.members,s.score,s.size,r.resources,r.planets, resources/planets AS respplanet, 
+       resources / 300 AS scoregain, score + (resources / 300) AS nscore, 
+       (resources/planets*LEAST(members,60))/300 AS scoregain2, score + (resources/planets*LEAST(members,60))/300 AS nscore2,
+       (s.size::int8*(1464-tick())*250)/100 + score + (resources/planets*LEAST(members,60))/300 AS nscore3,
+       (s.size::int8*(1464-tick())*250)/100 AS scoregain3
+FROM (SELECT alliance_id AS id,sum(metal+crystal+eonium) AS resources, count(*) AS planets 
+               FROM planets p join covop_targets c ON p.id = c.planet GROUP by alliance_id) r 
+       NATURAL JOIN alliances a 
+       LEFT OUTER JOIN (SELECT * FROM alliance_stats WHERE tick = (SELECT max(tick) FROM alliance_stats)) s ON a.id = s.id
+ORDER BY $order
+       });
+$query->execute;
+my @alliances;
+my $i = 0;
+while (my $alliance = $query->fetchrow_hashref){
+       $alliance->{ODD} = $i % 2;
+       push @alliances,$alliance;
+       $i++
+}
+$BODY->param(Alliances => \@alliances);
+
+$BODY->param(Error => $error);
+1;
diff --git a/templates/resources.tmpl b/templates/resources.tmpl
new file mode 100644 (file)
index 0000000..5010c65
--- /dev/null
@@ -0,0 +1,30 @@
+<TMPL_VAR NAME=Error>
+<table>
+       <tr>
+               <th>Name</th><th>Relationship</th><th>Members (in res calc)</th>
+               <th><a href="index.pl?page=resources&amp;order=score">Score</a></th>
+               <th><a href="index.pl?page=resources&amp;order=size">Size</a></th>
+               <th><a href="index.pl?page=resources&amp;order=resources">Resources</a></th>
+               <th><a href="index.pl?page=resources&amp;order=respplanet">Resources / Planet</a></th>
+               <th><a href="index.pl?page=resources&amp;order=nscore">Res score (gain)</a>[1]</th>
+               <th><a href="index.pl?page=resources&amp;order=nscore2">Avg res score (gain)</a>[2]</th>
+               <th><a href="index.pl?page=resources&amp;order=nscore3">Estimated score</a>[3]</th>
+       </tr>
+<TMPL_LOOP Alliances>
+       <tr class="<TMPL_IF ODD>odd<TMPL_ELSE>even</TMPL_IF>">
+               <td><a href="index.pl?page=alliances&amp;alliance=<TMPL_VAR NAME=Id>"><TMPL_VAR NAME=Name></a></td>
+               <td class="<TMPL_VAR NAME=relationship>"><TMPL_VAR NAME=relationship></td>
+               <td><TMPL_VAR NAME=members> (<TMPL_VAR NAME=planets>)</td>
+               <td><TMPL_VAR NAME=score></td>
+               <td><TMPL_VAR NAME=size></td>
+               <td><TMPL_VAR NAME=resources></td>
+               <td><TMPL_VAR NAME=respplanet></td>
+               <td><TMPL_VAR NAME=nscore> (<TMPL_VAR NAME=scoregain>)</td>
+               <td> <TMPL_VAR NAME=nscore2> (<TMPL_VAR NAME=scoregain2>)</td>
+               <td> <TMPL_VAR NAME=nscore3> (<TMPL_VAR NAME=scoregain3>)</td>
+       </tr>
+</TMPL_LOOP>
+</table>
+<p>[1] = New score if resources are spent (gain is just the extra value compared to unspent resources)</p>
+<p>[2] = Same as [1] but calculated with avg resources and max 60 members</p>
+<p>[3] = Same as [2] but also includes resources if roids are kept to end of round (gain is just from the roids)</p>
index 681038b674b9d12bc99fd3d4c5aea79e3587efec..1100a1cee2532f3f5bb0eb67fb61b9bc9fdd4e6f 100644 (file)
@@ -59,7 +59,7 @@
                        <li><a href="index.pl?page=intel">Intel</a></li>
                        <li><a href="index.pl?page=alliances">Alliances</a></li>
                        <li><a href="index.pl?page=memberIntel">Member Intel</a></li>
-                       <li><a href="index.pl?page=allianceRes">Alliance resources</a></li>
+                       <li><a href="index.pl?page=resources">Alliance resources</a></li>
                </ul>
                </TMPL_IF>
        <TMPL_VAR NAME=LEFTBAR>