some bugs with json fixed
[aymargeddon/current.git] / html / field.epl
1 <html>
2 <head><link rel="stylesheet" type="text/css" href="aymargeddon.css">
3 </head>
4 <body>
5 [$ if exists $fdat{'x'} and exists $fdat{'y'} $]
6   [- $udat{-loc} = $fdat{'x'}.'_'.$fdat{'y'}; -]
7 [$ endif $]
8
9 [$ if exists $udat{-id} and exists $udat{-game} and $udat{-loc} $]
10
11 [-
12  use FROGS::HexTorus;
13  use Aymargeddon;
14
15  $escmode = 0;
16
17  my $game = $udat{-game};
18  my $user = $udat{-id};
19  my $loc = $udat{-loc};
20
21  my $db = DataBase->new();
22  my $aym = Aymargeddon->new($game,$user,$db);
23  $db->set_language($udat{-lang});
24
25  # maybe you cant see this field (for hackers, which try to look direct
26  # in the field via url)
27  unless ($aym->sight_of_field($loc)){
28    print OUT "Mogeln gildet nich!\n";
29  } else {
30
31    my ($ter,$own,$occ,$temple,$plague) =
32      $aym->read_field('TERRAIN,HOME,OCCUPANT,TEMPLE,PLAGUE',$loc);
33
34    #####################
35    # general field info
36    #####################
37
38    $out .= $db->loc('FIELD_'.$ter).' '.Location::pretty($loc).' '.
39      $db->loc('PREP_IS_SG').' ';
40    if ($occ) {
41      $out .= $db->loc('OCCUPIED').' ';
42      if ($occ==$user) {
43        # it is our own field
44        $out .= $db->loc( ($aym->gender($occ) eq 'PLURAL') ? 
45                          'PPRO_DAT3_PL' : 'PPRO_DAT3_SG' );
46      } else {
47        # the field belongs to someone else
48        $out .= $db->loc('ART_DAT_PL').' ' if $aym->gender($occ) eq 'PLURAL';
49        $out .= $aym->charname($occ).' (<a href="command.epl?cmd=CH_STATUS&other='.
50          $occ.'">'.$aym->relation_string($occ).
51            '</a>, <a href="command.epl?cmd=SEND_MSG&other='.$occ.'">'.
52               $db->loc('SEND_MESSAGE').'</a>)';
53      }
54    } else {
55      $out .= $db->loc('NOT_OCCUPIED');
56    }
57    $out .= ".\n";
58
59    if ($own > 0) {
60      # some fields have some specials
61      if ($ter eq 'CITY') {
62        $out .= $db->loc('HOMECITY');
63      } elsif ($temple eq 'Y') {
64        $out .= $db->loc('TEMPLE');
65      } elsif ($ter eq 'MOUNTAIN') {
66        $out .= $db->loc('HOMEHOLY');
67      }
68      if($ter ne 'ISLE' or $temple eq 'Y'){
69        $out .= ' '.$db->loc('PREP_OWN_SG').' ';
70        if ($own==$user) {
71          $out .= $db->loc( ($aym->gender($own) eq 'PLURAL') ? 
72                            'PPRO_DAT3_PL' : 'PPRO_DAT3_SG' );
73        } elsif ($occ == $own) {
74          my $gen = $aym->gender($own);
75          $out .= $db->loc( ($gen eq 'PLURAL') ? 'PPRO_DAT_PL' : 
76                          (($gen eq 'MALE') ? 'PPRO_DAT_M' : 'PPRO_DAT_F') );
77        } else {
78          $out .= $db->loc('ART_DAT_PL').' ' if $aym->gender($own) eq 'PLURAL';
79          $out .= $aym->charname($own).' (<a href="command.epl?cmd=CH_STATUS&other='.
80            $own.'">'.$aym->relation_string($own).
81            '</a>, <a href="command.epl?cmd=SEND_MSG&other='.$own.'">'.
82              $db->loc('SEND_MESSAGE').'</a>)';
83        }
84        $out .= '.';
85      }
86    }
87    $out .= $db->loc('PLAGUE_IN_FIELD',lc($plague)) if $plague;
88    $out .= "<p>\n";
89
90    ###################
91    # show the mobiles
92    ###################
93
94    $mob = $aym->mobiles_available($loc);
95    $mobcount = @$mob;
96
97    if ($mobcount) {
98      $out .= $db->loc('ADJ_HERE').' ';
99      $out .= $db->loc( ($mobcount == 1 and @{$mob->[0]}[4] == 1) ?
100                        'PREP_IS_SG' : 'PREP_IS_PL' );
101
102      $out .= ($mobcount > 1) ? ":\n<p>" : ' ';
103      foreach $i (0..$mobcount-1) {
104        my ($oid,$otype,$oown,$oado,$ocnt,$ostat,$omove) = @{$mob->[$i]};
105        # check for MOVE_WITH
106        next if $omove;
107        $out .= $aym->mobile_to_html( $loc,$own,$occ,$temple,$ter, @{$mob->[$i]});
108         
109        my $transports = 0;
110        foreach $j (0..$mobcount-1) {
111          ($xid,$xtype,$xown,$xado,$xcnt,$xstat,$xmove) = @{$mob->[$j]};
112          if ($xmove == $oid) {
113            if (!$transports) {
114              $out .= ', '.$db->loc('MSG_TRANSPORTS').":<ul>\n";
115              $transports = 1;
116            }
117            $out .= '<li>'.
118              $aym->mobile_to_html( $loc,$own,$occ,$temple,$ter, @{$mob->[$j]})."</li>\n";
119          }
120        }
121        if ($transports) {
122          $out .= '</ul>';
123        } else {
124          $out .= ($i < $mobcount-1) ? ',' : '.';
125          $out .= "\n<p>";
126        }
127      } # end foreach $mobcount
128    }
129
130    ##################################
131    # general commands for this field:
132    ##################################
133
134    if ($aym->is_earthling($user)) {
135      $out .= "\n<p><a href=\"command.epl?cmd=DIE_ORDER\">".
136        $db->loc('CMD_DIE_ORDER').'</a>';
137    }
138    if ($aym->is_god($user)) {
139      if ($aym->is_arrival($loc)) {
140        $out .= "\n<p><a href=\"command.epl?cmd=INCARNATE&loc=$loc\">".
141          $db->loc('CMD_INCARNATE').'</a>';
142      }
143      if($aym->is_coast($loc)){
144        $out .= "\n<p><a href=\"command.epl?cmd=BUILD_ARK&loc=$loc\">".
145          $db->loc('CMD_BUILD_ARK').'</a>';
146        if($ter ne 'CITY'){
147          $out .= "\n<p><a href=\"command.epl?cmd=FLOOD&loc=$loc\">".
148            $db->loc('CMD_FLOOD').'</a>';
149        }
150      }
151      $out .= "\n<p><a href=\"command.epl?cmd=PLAGUE&loc=$loc\">".
152        $db->loc('CMD_PLAGUE').'</a>';
153      $out .= "\n<p><a href=\"command.epl?cmd=CH_LUCK\">".$db->loc('CMD_CH_LUCK').'</a>';
154    }
155
156    #############################
157    # show events for this field
158    #############################
159
160    $events = $aym->field_events($loc);
161    #use Data::Dumper;
162    #print OUT Dumper $events;
163    $out .= "\n<p><strong>".$db->loc('PLAYER_EVENTS')."</strong><p>\n" if %$events;
164    for my $ev ( keys %$events) {
165      $out .= $aym->show_event($ev, 0) .'<p>';
166    }
167
168    ############################
169    # show unavailable units
170    ############################
171
172    # mobile info:
173    #$mob = $aym->mobiles_available($loc,-1);
174    #$mobcount = $#{@$mob}+1;
175
176    #if ($mobcount) {
177    #  $out .= '<p>';            
178    #  $out .= '<strong> '.$db->loc('UNAVAILABLE_UNITS').":</strong><p>";
179    #  foreach $i (0..$mobcount-1) {
180    #    ($oid,$otype,$oown,$oado,$ocnt,$ostat) = @{$mob->[$i]};
181    #    $out .= $ocnt.' ';
182    #    if ($oown == $user) {
183    #     $out .= $db->loc('PREP_OWN_PL').' '.$aym->mobile_string($otype,2);
184    #     if ($otype eq 'PRIEST' or $otype eq 'PROPHET') {
185    #       $out .= $db->loc('ADJ_ADORING').' '.$aym->charname($oado);
186    #     } elsif ($otype eq 'HERO') {
187    #       $out .= $db->loc('ADJ_ADORING');
188    #       $out .= $aym->charname($oado).'</a>';
189    #     } elsif ($otype eq 'AVATAR') {
190    #       $out .= $aym->mobile_string($ostat,1);
191    #     }
192    #    } else {
193    #     $out .= $aym->mobile_string($otype, $ocnt);
194    #     if ($otype ne 'ARK') {
195    #       $out .= ' '.$db->loc('PREP_OWN_SG').' ';
196    #       $out .= $db->loc('ART_DAT_PL').' ' if $aym->gender($oown) eq 'PLURAL';
197    #       $out .= $aym->charname($oown);
198    #     }
199    #     if ($otype eq 'PRIEST' or $otype eq 'PROPHET'or $otype eq 'HERO') {
200    #       $out .= $db->loc('ADJ_ADORING').' ';
201    #       if ($oado == $user) {
202    #         $out .= $db->loc( ($aym->gender($user) eq 'PLURAL') ?
203    #                           'PPRO_DAT3_PL' : 'PPRO_DAT3_SG');
204    #       } else {
205    #         $out .= $aym->charname($oado);
206    #       }
207    #     }
208    #    }
209    #    $out .= ($i < $mobcount-1) ? ',' : '.';
210    #    $out .= "\n<p>";
211    #  } # end foreach $mobcount
212    #}
213
214    print OUT $out;
215  } # unless sight
216  -]
217
218 [$ else $]
219
220   To view an Aymargeddon field, you must first <a href="login.epl" target="_top">login</a>,
221   because we need to know which game to display and for whom.
222
223 [$ endif $]
224 </body></html>