another $escmode, mobcount-bug, TODO-Editing
[aymargeddon/current.git] / html / command_frames.epl
1 [# get command and maybe some parameters #]
2
3 [-
4   use Aymargeddon;
5   $db = DataBase->new();
6   $aym = Aymargeddon->new($udat{-game},$udat{-id},$db);
7   $db->set_language($udat{-lang});
8
9   $escmode = 0;
10 -]
11
12 [$ if $fdat{'cmd'} $] [# show form to enter the required parameters #]
13
14 [-
15 #  my ($gname) = $db->read_game($udat{-game},'NAME');
16 #  my $cname = $aym->charname($udat{-id});
17
18 #  $out = "<strong>$gname</strong> $cname.<p>\n"
19   $out = '<form method="get" action="command.epl">';
20
21   my $cmd = $udat{-cmd} = $fdat{'cmd'};
22   $udat{-cmd_loc} = $fdat{'loc'} if $fdat{'loc'};
23
24   if($cmd eq 'SEND_MSG' and exists $fdat{'other'}){ # anybody, always
25     $udat{-cmd_args} = 'OTHER='.$fdat{'other'};
26     my $to = $aym->charname($fdat{'other'});
27     $out .= $db->loc('SEND_MESSAGE_TO',$to).
28       '<textarea name="message" cols="20" rows="20"></textarea>'
29   }elsif($cmd eq 'CH_STATUS' and exists $fdat{'other'}){ # anybody, always
30     $udat{-cmd_args} = 'OTHER='.$fdat{'other'};
31     $out .= $db->loc('CMD_CH_STATUS_MSG').' '.$aym->charname($fdat{'other'}).":<p>\n"
32          .'<input type="radio" name="status" value="ALLIED">'.$db->loc('STAT_ALLIED')."<p>\n"
33          .'<input type="radio" name="status" value="FRIEND">'.$db->loc('STAT_FRIEND')."<p>\n"
34          .'<input type="radio" name="status" value="NEUTRAL">'.$db->loc('STAT_NEUTRAL')."<p>\n"
35          .'<input type="radio" name="status" value="FOE">'.$db->loc('STAT_FOE')."<p>\n"
36          .'<input type="radio" name="status" value="BETRAY">'.$db->loc('STAT_BETRAY')."<p>\n";
37   }elsif($cmd eq 'DIE_ORDER'){ # earthling, always
38     $out .= $db->loc('CMD_DIE_ORDER_MSG').":<p>\n"
39          .'<input type="radio" name="dying" value="PKH">'.$db->loc('MOBILE_PRIEST_PL').', '.$db->loc('MOBILE_WARRIOR_PL').', '.$db->loc('MOBILE_HERO_PL')."<p>\n"
40          .'<input type="radio" name="dying" value="PHK">'.$db->loc('MOBILE_PRIEST_PL').', '.$db->loc('MOBILE_HERO_PL').', '.$db->loc('MOBILE_WARRIOR_PL')."<p>\n"
41          .'<input type="radio" name="dying" value="KPH">'.$db->loc('MOBILE_WARRIOR_PL').', '.$db->loc('MOBILE_PRIEST_PL').', '.$db->loc('MOBILE_HERO_PL')."<p>\n"
42          .'<input type="radio" name="dying" value="KHP">'.$db->loc('MOBILE_WARRIOR_PL').', '.$db->loc('MOBILE_HERO_PL').', '.$db->loc('MOBILE_PRIEST_PL')."<p>\n"
43          .'<input type="radio" name="dying" value="HPK">'.$db->loc('MOBILE_HERO_PL').', '.$db->loc('MOBILE_PRIEST_PL').', '.$db->loc('MOBILE_WARRIOR_PL')."<p>\n"
44          .'<input type="radio" name="dying" value="HKP">'.$db->loc('MOBILE_HERO_PL').', '.$db->loc('MOBILE_WARRIOR_PL').', '.$db->loc('MOBILE_PRIEST_PL')."<p>\n"
45   }elsif($cmd eq 'CH_LUCK'){ # god, always
46     $out .= $db->loc('CMD_CH_LUCK_MSG').":<p>\n"
47          . '<input type="text" name="bonus"><p>'."\n";
48     # TODO: inc/dec button
49   }elsif($cmd eq 'MOVE' and exists $fdat{'mob'} and exists $fdat{'loc'}){ # any mobile
50     $udat{-cmd_args} = 'MOBILE='.$fdat{'mob'};
51     my ($type, $count, $adoring, $movewith) =
52       $aym->get_mobile_info($fdat{'mob'}, 'TYPE, COUNT, ADORING, MOVE_WITH');
53     $out .= $db->loc('CMD_MOVE_MSG',$aym->mobile_extended_string($type,$count,$adoring)).":<p>\n"
54          .'<input type="text" name="dir">';
55     $out .= $db->loc('CMD_COUNT').':<input type="text" name="count">'."max. $count" if $count > 1;
56     $out .= "<p>\n";
57
58     # arks cant move with other units
59     if($type ne 'ARK'){
60       # MOVE_WITH
61       my $mob = $aym->mobiles_available($fdat{'loc'});
62       my $mobcount = $#{@$mob}+1;
63       my $transporters = 0;
64       if ($mobcount > 1){
65         foreach $i (0..$mobcount-1){
66           my ($oid,$otype,$oown,$oado,$ocnt,$ostat,$omove) = @{$mob->[$i]};
67           next if($oid == $fdat{'mob'} or $otype eq 'AVATAR' );
68           next if $omove;
69           if(! $transporters){
70             $out .= $db->loc('MSG_MOVE_WITH').":<p>\n";
71             $transporters = 1;
72           }
73           if($movewith == $oid){
74             $out .= '<input type="radio" name="movewith" value="0">'.
75               $db->loc('MSG_DONT_MOVE_WITH')."<p>\n";
76           }else{
77             $out .= '<input type="radio" name="movewith" value="'.$oid.'">'.
78               $aym->mobile_extended_string($otype, $ocnt, $oado)."<p>\n";
79           }
80         }
81       }
82     }
83     #}elsif($cmd eq 'CH_ADORING' and exists $fdat{'mob'}){ # hero
84     # $udat{-cmd_args} = 'MOBILE='.$fdat{'mob'};
85     # $out .= $db->loc('CMD_CH_ADORING_MSG').":<p>\n";
86     # my @gods = $aym->gods();
87     # for my $god (@gods){
88     #      $out .= '<input type="radio" name="god" value="'.$god.'">'.$aym->charname($god)."<p>\n";
89     #   }
90   }elsif($cmd eq 'CH_ACTION' and exists $fdat{'mob'}){ # avatar
91     $udat{-cmd_args} = 'MOBILE='.$fdat{'mob'};
92     $out .= $db->loc('CMD_CH_ACTION_MSG').":<p>\n"
93          . '<input type="radio" name="action" value="BLOCK">'.$db->loc('MOBILE_BLOCK')."<p>\n"
94          . '<input type="radio" name="action" value="HELP">'.$db->loc('MOBILE_HELP')."<p>\n"
95          . '<input type="radio" name="action" value="IGNORE">'.$db->loc('MOBILE_IGNORE')."<p>\n";
96   }elsif($cmd eq 'BLESS_PRIEST' and exists $fdat{'mob'}){ # warrior
97     $udat{-cmd_args} = 'MOBILE='.$fdat{'mob'};
98     $out .= $db->loc('CMD_BLESS_PRIEST_MSG').".<p>\n";
99   }elsif($cmd eq 'BLESS_HERO' and exists $fdat{'mob'}){ # warrior
100     $udat{-cmd_args} = 'MOBILE='.$fdat{'mob'};
101     $out .= $db->loc('CMD_BLESS_HERO_MSG').".<p>\n";
102     $out .= ':<input type="text" name="count"><p>'."\n";
103   }elsif($cmd eq 'BUILD_TEMPLE' and exists $fdat{'mob'}){
104     # priest or prophet at mountain (of the god they adore) or isle without temple
105     $udat{-cmd_args} = 'MOBILE='.$fdat{'mob'}; # needed to change its type to priest if it was a prophet
106     $out .= $db->loc('CMD_BUILD_TEMPLE_MSG').' '.$fdat{'loc'}.".<p>\n";
107   }elsif($cmd eq 'DESTROY'){ # avatar at mountain or isle with temple
108     $out .= $db->loc('CMD_DESTROY_MSG').' '.$fdat{'loc'}.".<p>\n";
109   }elsif($cmd eq 'MOVE_MTN'){ # earthling at a mountain with more priests of one god than luck+5
110     $out .= $db->loc('FIELD_MOUNTAIN')." $loc ".$db->loc('CMD_MOVE_MTN_MSG').":<p>\n";
111     # TODO: list target locations (where prophets adoring same god are)
112   }elsif($cmd eq 'INCARNATE'){ # god at his arrival temple (temple with most priests adoring him)
113     $out .= $db->loc('CMD_INCARNATE_MSG').":<p>\n"
114          .':<input type="text" name="count"><p>'."\n";
115   }elsif($cmd eq 'BUILD_ARK'){ # god at any coast field
116     $out .= $db->loc('CMD_BUILD_ARK_MSG').' '.$fdat{'loc'}.".<p>\n";
117   }elsif($cmd eq 'PLAGUE'){ # god at any field
118     $out .= $db->loc('CMD_PLAGUE_MSG').' '.$fdat{'loc'}.":<p>\n";
119     for my $plague (@{$::conf->{-PLAGUES}}){
120       $out .= '<input type="radio" name="type" value="'.$plague.'">'."$plague<p>\n"
121     }
122   }elsif($cmd eq 'FLOOD'){ # god at any coast field (without city)
123     $out .= $db->loc('CMD_FLOOD_MSG').' '.$fdat{'loc'}.".<p>\n";
124
125   }else{
126     delete $udat{-cmd};
127     delete $udat{-cmd_loc};
128     $out = $db->loc('CMD_ERROR_MSG')."<p>\n"; # unknown, illegal or incomplete command
129   }
130
131   if(exists $udat{-cmd}){
132     $out .= '<input type="submit" value="'.$db->loc('FORM_OK_BUTTON').'"></form>';
133     $udat{-back} = $ENV{'HTTP_REFERER'};
134   }
135   $out .= '<form method="get" action="'.$ENV{'HTTP_REFERER'}.'">'
136        .'<input type="submit" value="'.$db->loc('FORM_BACK_BUTTON').'"></form><p>';
137         
138   print OUT $out;
139 -]
140
141 [$ elsif exists $udat{-cmd} $] [# complete the command with the given form-data #]
142
143 [-
144  my ($cmd) = $udat{-cmd}; delete $udat{-cmd};
145  my ($args) = $udat{-cmd_args}; delete $udat{-cmd_args} if exists $udat{-cmd_args};
146  my ($loc) = $udat{-cmd_loc}; delete $udat{-cmd_loc} if exists $udat{-cmd_loc};
147  my $failure = 0;
148
149  # global
150  if($cmd eq 'SEND_MSG'){
151    my $msg = $db->quote($fdat{'message'});
152
153    # uggly workaround necessary for Command::parse_args()
154    $msg =~ s/,/__COMMA__/g;
155    $msg =~ s/=/__EQUAL__/g;
156
157    $args .= ", MESSAGE=$msg"
158  }elsif($cmd eq 'CH_STATUS'){
159    $failure = 1 if not exists $fdat{'status'};
160    $args .= ', STATUS='.$fdat{'status'};
161  }elsif($cmd eq 'DIE_ORDER'){
162    $failure = 1 if not exists $fdat{'dying'};
163    $args = 'DYING='.$fdat{'dying'};
164  }elsif($cmd eq 'CH_LUCK'){
165    $failure = 1 if not exists $fdat{'bonus'};
166    $args = 'BONUS='.$fdat{'bonus'};
167
168    # mobile
169  }elsif($cmd eq 'MOVE'){
170    $failure = 1 if (not exists $fdat{'dir'} and not exists $fdat{'movewith'});
171    my $count = (exists $fdat{'count'}) ? $fdat{'count'} : 1;
172    if(exists $fdat{'movewith'}){
173      $cmd = 'MOVE_WITH';
174      $args .= ', COUNT='.$count.', TARGET='.$fdat{'movewith'};
175    }else{
176      $args .= ', COUNT='.$count.', DIR='.$fdat{'dir'};
177    }
178  #}elsif($cmd eq 'CH_ADORING'){
179    #$failure = 1 if not exists $fdat{'god'};
180    #$args .= ', GOD='.$fdat{'god'};
181  }elsif($cmd eq 'CH_ACTION'){
182    $failure = 1 if not exists $fdat{'action'};
183    $args .= ', ACTION='.$fdat{'action'};
184  }elsif($cmd eq 'BLESS_HERO'){
185     my $count = exists $fdat{'count'} ? $fdat{'count'} : 1;
186     $args .= ", COUNT=$count";
187     # local
188   }elsif($cmd eq 'MOVE_MTN'){
189     $failure = 1 if not exists $fdat{'target'};
190     $args = 'TARGET='.$fdat{'target'};
191   }elsif($cmd eq 'INCARNATE'){
192     my $count = (exists $fdat{'count'}) ? $fdat{'count'} : 1;
193     $args = 'COUNT='.$count;
194   }elsif($cmd eq 'PLAGUE'){
195     $failure = 1 if not exists $fdat{'type'};
196     $args = 'TYPE='.$fdat{'type'};
197   }# elsif($cmd eq 'DESTROY'){
198     
199
200   my $ub = $udat{-back};
201   delete $udat{-back};
202
203   if($failure)
204   {
205     $out = $db->loc('CMD_ERROR_MSG')."<p>\n"; # unknown, illegal or incomplete command
206     $out .= '<form method="get" action="'.$ub.'">'
207          .'<input type="submit" value="'.$db->loc('FORM_BACK_BUTTON').'"></form><p>';
208     print OUT $out;
209   }else{
210     $args = '' if not $args;
211     $aym->insert_command($cmd,$args,$loc) unless $failure;
212     $db->commit();
213
214     # redirect to field
215     $http_headers_out{'Location'} = $ub;
216   }
217 -]
218
219 [$ else $]
220
221    Hey, kein Befehl ?!?!
222
223 [$ endif $]