1 ##########################################################################
3 # Copyright (c) 2003-2012 Aymargeddon Development Team
5 # This file is part of "Last days of Aymargeddon" - a massive multi player
6 # onine game of strategy
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU Affero General Public License as
10 # published by the Free Software Foundation, either version 3 of the
11 # License, or (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 # See the GNU Affero General Public License for more details.
19 # You should have received a copy of the GNU Affero General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 ###########################################################################
25 # generell Aymargeddon-specific functions
29 # TODO: move color calculation from map.epl in this module
38 @Aymargeddon::ISA = qw(Game);
41 my ($class,$game,$user,$db,$lang) = @_; #TODO: $lang not used here?
43 my $self = Game->new($game,$user,$db);
51 unless (exists $self->{-map}){
52 #TODO: HOME dupplication correct?
53 $self->{-map} = $self->read_map("TERRAIN,HOME,OCCUPANT,TEMPLE,PLAGUE,HOME");
61 unless ($self->{-size}){
62 my @size = $self->{-db}->read_game($self->{-game},'SIZE');
63 $self->{-size} = $size[0] ? $size[0] : die "could not find size";
65 return $self->{-size};
69 my ($self, $other) = @_;
71 unless ($self->{-rel}){
73 # $self->{-rel} = $self->read_player_relations($self->{-game}, $self->{-user});
74 $self->{-rel} = $self->read_player_relations($self->{-user});
76 # print Dumper $self->{-rel};
77 my $stat = $self->{-rel}->{$other}->{'STATUS'};
78 return $stat ? $stat : 'NEUTRAL';
81 # FRIEND, ALLIED => FRIEND ; FOE, BETRAY => FOE
82 sub simplyfied_single_relation{
83 my ($self,$me,$you) = @_;
84 my $rel = $self->read_single_relation($me,$you);
86 return 'FRIEND' if Util::is_in($rel,'FRIEND','ALLIED');
87 return 'FOE' if Util::is_in($rel,'FOE','BETRAY');
93 my ($self,$loc_str) = @_;
94 my @ret = $self->read_field('GOD_ATTACKER',$loc_str);
95 return $ret[0] ? 1 : 0;
99 my ($self,$loc_str) = @_;
100 my @ret = $self->read_field('ATTACKER',$loc_str);
101 return $ret[0] ? 1 : 0;
105 my ($self,$loc_str) = @_;
106 my $arks_ref = $self->read_mobile('ID','ARK',$loc_str,1);
107 my @arks = @$arks_ref;
112 my ($self,$loc_str) = @_;
113 return $self->read_mobile('OWNER','AVATAR',$loc_str,1);
116 sub mobiles_available{
117 my ($self,$loc_str,$avail) = @_;
118 $avail = 1 unless defined $avail;
119 my $fields = 'ID, TYPE, OWNER, ADORING, COUNT, STATUS, MOVE_WITH';
120 return $self->read_mobile($fields,'',$loc_str, $avail);
127 # TODO: maybe the generell sight-stuff could go to Game.pm
129 # ATTENTION: this function generates the whole sight-matrix, if necessary.
130 # it could be very time-consuming
131 sub player_see_field{
132 my ($self,$loc) = @_;
134 my @players = $self->get_all_roles();
137 for my $player (@players){
138 # ($player) = @$player;
139 my $players_aym = new Aymargeddon($self->{-game},$player,
140 $self->{-db},$self->{-lang});
141 if ($players_aym->sight_of_field($loc)){
143 # print "$player sees $loc.\n";
149 # this two functions reads sight directly from database
151 my ($self,$loc) = @_;
153 return 1 if $self->role($self->{-user}) eq 'OBSERVER'; # admin sees all
155 my $player = $self->{-user};
156 my $map = HexTorus->new($self->get_size());
157 return 1 if $self->sight_of_field_of_player($loc,$player,$map);
159 # read all players, which give us informations
160 my $rel = $self->reverse_player_relations();
161 for my $friend (keys %$rel){
162 my $status = $rel->{$friend}->{'STATUS'};
163 if($status eq 'ALLIED' or $status eq 'BETRAY'){
164 if($self->is_earthling($friend) or $::conf->{-GODS_SHOW_EARTHLINGS}){
165 return 1 if $self->sight_of_field_of_player($loc,$friend,$map);
172 sub sight_of_field_of_player{
173 my ($self,$loc,$player,$map) = @_;
175 my ($ter,$own,$occ,$temple) = $self->read_field('TERRAIN,HOME,OCCUPANT,TEMPLE',$loc);
177 return 1 if($own == $player or $occ == $player);
178 return 1 if @{$self->own_in_mobile($loc,$player)};
180 my $location = Location->from_string($loc);
182 my @neighbours = $map->distant_neighbours($location,$dist);
183 # Util::log("neighbours: ",-2);
184 for my $l (@neighbours){
185 my $d = $map->distance($location,$l);
186 my $locstring = $l->to_string();
187 # Util::log(" $locstring ($d),",-2);
189 my ($neighbour_ter,$neighbour_home) = $self->read_field('TERRAIN,HOME',$locstring);
190 next if ($d > 1 && $neighbour_ter ne 'MOUNTAIN');
191 return 1 if $neighbour_home == $player;
192 return 1 if $neighbour_ter eq 'MOUNTAIN' and
193 $neighbour_home <= 0 and $self->is_god($player);
194 return 1 if @{$self->own_in_mobile($locstring,$player)};
200 # this function generates the whole sight if called
202 my ($self,$loc_str) = @_;
204 return 1 if $self->role($self->{-user}) eq 'OBSERVER'; # admin sees all
206 $self->generate_sight() unless $self->{-sight_map};
208 return 1 if $self->{-sight_map}->{$loc_str};
211 # overloads the function from Game-Class
215 # TODO-PERFORMANCE: make map a self-constructing member of class (like size)
216 my $map = HexTorus->new($self->get_size());
219 for my $loc ($map->get_all()){
220 my $ls = $loc->to_string();
221 push @ret, $ls if $self->sight($ls);
229 delete $self->{-sight_map};
231 my $rel = $self->reverse_player_relations();
233 $self->sight_of_player($self->{-user});
234 for my $player (keys %$rel){
235 my $status = $rel->{$player}->{'STATUS'};
236 if($status eq 'ALLIED' or $status eq 'BETRAY'){
237 if($self->is_earthling($player) or $::conf->{-GODS_SHOW_EARTHLINGS}){
238 $self->sight_of_player($player);
243 # print Dumper $self->{-sight_map};
247 my ($self,$player) = @_;
249 my $map = HexTorus->new($self->get_size());
251 my $selfmap = $self->get_map();
253 for my $row (@$selfmap){
254 my ($loc,$ter,$own,$occ,$temple,$plague,$home) = @$row;
256 if($own == $player or $occ == $player
257 or @{$self->own_in_mobile($loc,$player)}
258 or ($self->is_god($player) and $ter eq 'MOUNTAIN' and $home <= 0)){
259 $self->{-sight_map}->{$loc} = 1;
260 my $location = Location->from_string($loc);
262 $dist = 2 if $ter eq 'MOUNTAIN';
263 my @neighbours = $map->distant_neighbours($location,$dist);
264 for my $l (@neighbours){
265 $self->{-sight_map}->{$l->to_string()} = 1;
272 my ($self,$loc_str) = @_;
273 my ($ter) = $self->read_field('TERRAIN',$loc_str);
274 return 0 if($ter ne 'PLAIN' and $ter ne 'CITY' and $ter ne 'MOUNTAIN');
276 my $map = HexTorus->new($self->get_size());
277 my @neighbours = $map->neighbours(Location->from_string($loc_str));
278 for my $loc (@neighbours){
279 ($ter) = $self->read_field('TERRAIN',$loc->to_string());
280 return 1 if($ter eq 'ISLE' or $ter eq 'WATER');
286 my ($self, $loc_str) = @_;
288 return 1 if $loc_str eq $self->incarnation_place();
294 my ($self,$player) = @_;
295 $player = $self->{-user} unless defined $player;
296 return ($self->role($player) eq 'GOD');
300 my ($self,$player) = @_;
301 $player = $self->{-user} unless defined $player;
302 return ($self->role($player) eq 'EARTHLING');
307 return $self->get_all_roles('GOD');
312 return $self->get_all_roles('EARTHLING');
316 my ($self,$player) = @_;
317 $player = $self->{-user} unless defined $player;
318 return 0 if $player < 1;
320 my $stmt = "SELECT MANA from GOD where GAME=$self->{-game} AND PLAYER=$player";
321 my ($mana) = $self->{-db}->single_select($stmt);
322 return $mana ? $mana : 0;
326 my ($self,$player) = @_;
327 return 0 if $player < 1;
328 my @gen = $self->read_role($player, 'GENDER');
334 my ($self, $type) = @_;
335 return $self->{-db}->loc('FIELD_'.$type);
339 my ($self, $other) = @_;
340 my $rel = $self->get_relation($other);
342 $rel = 'NEUTRAL' if not $rel;
343 return $self->{-db}->loc('STAT_'.$rel);
347 my ($self, $type, $num) = @_;
348 my $tag = 'MOBILE_'.$type;
349 $tag .= '_PL' if $num != 1;
350 return $self->{-db}->loc($tag);
353 sub mobile_extended_string{
354 # count + localised type + adored god if any
355 my ($self, $type, $num, $adoring) = @_;
356 my $out = $num.' '.$self->mobile_string($type, $num);
357 if($type eq 'PRIEST' or $type eq 'PROPHET' or $type eq 'HERO'){
358 $out .= ' '.$self->{-db}->loc('ADJ_ADORING').' '.$self->charname($adoring);
364 my ($self, $player) = @_;
365 my $role = $self->role($player);
366 $role = 'UNDEFINED' unless defined $role;
367 my $tag = "ROLE_$role";
368 return $self->{-db}->loc($tag);
373 my($self,$role,$name,$gender,$desc) = @_;
374 $desc = 'none' unless defined $desc;
375 my $db = $self->{-db};
377 # my ($qname, $qgender, $qdesc, $qrole)
378 # = $db->quote_all($name, $gender, $desc, $role);
380 my $cond = 'GAME='.$self->{-game}." AND NICKNAME=$name";
381 return 0 if @{$db->select_array('ROLE','GAME',$cond)}; # error: dublicate name
383 my @homes; # all possible homes for this role
384 if($role ne 'OBSERVER'){
385 @homes = $self->open_homes($role);
386 return 0 if $#homes<0; # error: no home free
389 # dont allow names only in uppercase
390 return 0 if $name =~ /^\s*[A-Z_]{3,}\s*$/;
393 $db->insert_hash('ROLE',{'GAME' => $self->{-game},
394 'PLAYER' => $self->{-user},
398 'DESCRIPTION' => $desc}
400 if($role eq 'OBSERVER'){
406 my $home = $homes[rand($#homes + 1)]->[0];
409 # read actual default manapool from GAME
410 my ($mana,$ts) = $db->read_game($self->{-game},'START_MANA,TEMPLE_SIZE');
413 # write GAME, PLAYER, MANA in GOD
414 $db->insert_hash('GOD',{'GAME' => $self->{-game},
415 'PLAYER' => $self->{-user},
418 # choose second and third home
422 # while($home2 eq $home or $home3 eq $home or $home2 eq $home3){
423 # $home2 = $homes[rand($#homes + 1)]->[0];
424 # $home3 = $homes[rand($#homes + 1)]->[0];
428 # # change OWNER in MAP where LOCATION=$home or LOCATION=$home2
429 # # ($home,$home2) = $db->quote_all($home,$home2);
430 # $db->update_hash('MAP',
431 # "GAME=$self->{-game} AND".
432 # " (LOCATION=$home OR LOCATION=$home2 OR LOCATION=$home3)",
433 # {'HOME' => $self->{-user}});
436 # write GAME, PLAYER in EARTHLING
437 $db->insert_hash('EARTHLING',{'GAME' => $self->{-game},
438 'PLAYER' => $self->{-user}});
440 # change OCCUPANT, OWNER in MAP where LOCATION=$home
441 # ($home) = $db->quote_all($home);
442 $db->update_hash('MAP',
443 "GAME=$self->{-game} AND LOCATION=$home",
444 {'HOME' => $self->{-user},
445 'OCCUPANT' => $self->{-user}});
447 # change PLAYER of WARRIORS OR PRIESTs in MOBILE where LOCATION=$home
448 $db->update_hash('MOBILE',
449 "GAME=$self->{-game} AND LOCATION=$home AND OWNER=-1",
450 {'OWNER' => $self->{-user}});
452 # give additional start-warriors
453 my $warriors = $db->select_array('MOBILE',
455 "GAME=$self->{-game} AND LOCATION=$home ".
456 "AND OWNER=$self->{-user} AND TYPE=WARRIOR");
459 $db->update_hash('MOBILE',
461 {'COUNT' => "COUNT + $::conf->{-START_WARRIORS}"},
464 $db->insert_hash('MOBILE',
465 {'ID' => $db->find_first_free('MOBILE','ID'),
466 'GAME' => $self->{-game},
469 'COUNT' => $::conf->{-START_WARRIORS},
470 'OWNER' => $self->{-user},
471 'AVAILABLE' => 'Y'});
474 # modify PRODUCE Command
475 $db->update_hash('COMMAND',
476 "GAME=$self->{-game} AND COMMAND=PRODUCE ".
477 "AND LOCATION=$home",
478 # TODO: open question: is this redundant information?
479 {'PLAYER' => $self->{-user},
480 'ARGUMENTS' => "ROLE=$self->{-user}"});
484 # TODO: write MESSAGE to all members of this game: new player with role!
494 my $cond = "GAME=$self->{-game} AND ";
495 if($self->role($self->{-user}) eq 'OBSERVER'){
496 $cond .= 'TERRAIN='.$self->{-db}->quote('AYMARGEDDON');
498 $cond .= "HOME=$self->{-user}";
500 # TODO: what happens if both mountains are flooded?
501 return $self->{-db}->select_array('MAP','LOCATION',$cond)->[0]->[0];
506 my ($self,$role) = @_;
507 my $terrain = ($role eq 'GOD') ? 'MOUNTAIN' : 'CITY';
508 # ($terrain) = $self->{-db}->quote_all($terrain);
509 my $cond = 'GAME='.$self->{-game}." AND HOME=-1 AND TERRAIN=$terrain";
510 return @{$self->{-db}->select_array('MAP','LOCATION',$cond)};
514 my ($self,$terrain) = @_;
516 my $cond = "GAME=$self->{-game} AND HOME=-1";
518 $terrain = $self->{-db}->quote($terrain);
519 $cond .= "AND TERRAIN=$terrain";
521 my $unused = $self->{-db}->select_array('MAP','LOCATION','',$cond);
527 # TODO performance: we can do this whole function in one sophisticated SQL-statement.
528 sub incarnation_place{
529 my ($self,$player) = @_;
530 $player = $self->{-user} unless defined $player;
532 my $temples = $self->{-db}->select_array('MAP','LOCATION',
533 "TEMPLE='Y' AND HOME=$player");
537 for my $temple (@$temples){
538 my $loc = $temple->[0];
539 Util::log("check for $loc...",1);
540 # my ($qloc,$type,$yes) = $self->{-db}->quote_all($loc,'PRIEST','Y');
541 my $priests = $self->{-db}->single_hash_select('MOBILE',
542 "ADORING=$player AND ".
543 "LOCATION=$loc AND ".
546 "GAME=$self->{-game}");
548 if(defined $priests and $priests->{'COUNT'} > $max_priests){
550 $max_priests = $priests->{'COUNT'};
559 my ($fortune) = $self->{-db}->read_game($self->{-game},
564 # returns also empty neighbours, but no attacked neighbours
566 my ($self,$loc,$player) = @_;
567 $player = $self->{player} unless defined $player;
569 # print "own_neighbours($loc,$player)\n";
570 my $map = HexTorus->new($self->get_size());
571 my $location = Location->from_string($loc);
572 my @neighbours = $map->neighbours($location);
574 for my $n (@neighbours){
575 my $n_string = $n->to_string();
576 my ($occ,$att,$terrain) = $self->read_field('OCCUPANT,ATTACKER,TERRAIN',$n_string);
577 Util::log("$n_string occupied by $occ, attacked by $att",2);
579 next if $::conf->{-FIGHTS_WITHOUT_OWNER}->{$terrain} and not $occ;
580 push @own_neighbours, $n_string if $occ == $player or $occ <= 0;
582 # print Dumper \@own_neighbours;
583 Util::log("own_neighbours($loc,$player): @own_neighbours",2);
584 return @own_neighbours;
587 sub is_in_direction_from{
588 my($self,$to,$from) = @_;
590 my $map = HexTorus->new($self->get_size());
591 my $to_location = Location->from_string($to);
592 my $from_location = Location->from_string($from);
594 return $map->get_direction($from_location,$to_location);
599 my $db = $self->{-db};
601 my @earthlings = $self->get_all_roles('EARTHLING');
602 my @gods = $self->get_all_roles('GOD');
604 # show for god: own mana,
608 $out .= $db->loc('OWN_MANA',$self->get_mana());
611 # show for all: #priests of god (?), #citys of earthling, #temples to build,
612 # speed of game, fortune, last battle, fighting strength of earthlings
615 # strength of every god in last battle
616 $out .= $db->loc('LAST_BATTLE_HEADING') . '<p>';
618 # my $god = $god->[0];
620 my $strength=$self->strength_in_last_battle($god);
621 $out .= $db->loc('LAST_BATTLE_LINE',$self->charname($god),$strength) . '<br>';
623 # TODO?: count priests
627 $out .= '<p>' . $db->loc('CITY_HEADING'). '<p>';
628 for my $player (@earthlings){
629 # $player = $player->[0];
630 my $citys = $db->count('MAP',
631 "GAME=$self->{-game} AND OCCUPANT=$player AND TERRAIN=CITY");
632 $out .= $db->loc('STATISTIC_EARTHLING_CITY',
633 $self->charname($player),
638 # count temples to build for the end of the world
639 $out .= $db->loc('STATISTIC_UNBUILD', $self->unbuild()). " " .
640 $db->loc('STATISTIC_NEW_TEMPLES', $self->under_construction())."<p>\n";
642 my $game = $db->single_hash_select('GAME',
643 "GAME=$self->{-game}");
644 my $fortune = $game->{'FORTUNE'};
645 $out .= $db->loc('STATISTIC_FORTUNE',$fortune);
647 my $speed = $game->{'SPEED'};
648 $out .= $db->loc('STATISTIC_SPEED',"$speed sec");
653 # returns number of places for temples
656 return $self->{-db}->count('MAP',
657 "(TERRAIN=ISLE OR TERRAIN=MOUNTAIN) ".
658 "AND GAME=$self->{-game}");
661 # returns number of unbuild temples
664 return $self->{-db}->count('MAP',
665 "(TERRAIN=ISLE OR TERRAIN=MOUNTAIN) ".
666 "AND TEMPLE=N AND GAME=$self->{-game}");
669 # returns number of temples or arks which are currently under construction
670 sub under_construction{
671 my ($self,$type) = @_;
672 $type = 'TEMPLE' unless defined $type;
673 return $self->{-db}->count('EVENT',
674 "TAG=EVENT_BUILD_$type");
678 sub strength_in_last_battle{
680 $god = $self->{-player} unless defined $god;
681 my $db = $self->{-db};
684 $db->single_hash_select('GOD',
685 "GAME=$self->{-game} AND PLAYER=$god");
688 $db->single_hash_select('MAP',
689 "GAME=$self->{-game} AND".
690 " TERRAIN=AYMARGEDDON")->{'LOCATION'};
691 my $avatars = $self->count_mobile('AVATAR',$aymargeddon,$god);
693 my $strength = $::conf->{-LAST_BATTLE}->{-AVATAR} * $avatars +
694 $::conf->{-LAST_BATTLE}->{-DEATH_AVATAR} * $god_hash->{'DEATH_AVATAR'} +
695 $::conf->{-LAST_BATTLE}->{-DEATH_HERO} * $god_hash->{'DEATH_HERO'};
702 my ($self, $loc,$own,$occ,$temple,$ter,
703 $oid,$otype,$oown,$oado,$ocnt,$ostat,$omove) = @_;
705 # loc: location of the field
706 # own: the owner of the field (for cities and temples) (HOME)
707 # occ: the occupant of the field
708 # temple: wether there is a temple or not
709 # ter: terrain of field
711 # oid: id of the mobile
712 # otype: type of the mobile
713 # oown: owner of the mobile
714 # oado: which god the mobile adores
716 # ostat: status of the mobile (BLOCK, IGNORE or HELP)
717 # omove: the id of the mobile to move with (unused here)
719 my $user = $self->{-user};
720 my $db = $self->{-db};
725 $out .= $db->loc('PREP_OWN_PL').' '.$aym->mobile_string($otype,2);
726 if($otype eq 'PRIEST' or $otype eq 'PROPHET'){
727 $out .= $db->loc('ADJ_ADORING').' '.$aym->charname($oado);
729 $out .= ' (<a href="command.epl?cmd=CH_STATUS&other='.$oado.'">'.
730 $aym->relation_string($oado).
731 '</a>, <a href="command.epl?cmd=SEND_MSG&other='.$oado.'">'.
732 $db->loc('SEND_MESSAGE').'</a>)';
734 if(($ter eq 'ISLE' or $ter eq 'MOUNTAIN') and $temple eq 'N'){
735 $out .=' (<a href="command.epl?cmd=BUILD_TEMPLE&mob='.$oid.'&loc='.$loc.'">';
736 $out .= $db->loc('CMD_BUILD_TEMPLE').'</a>)';
738 }elsif($otype eq 'HERO'){
739 $out .= $db->loc('ADJ_ADORING');#.' <a href="command.epl?cmd=CH_ADORING&mob='.
741 $out .= ' ' . $aym->charname($oado); #.'</a>';
743 $out .= ' (<a href="command.epl?cmd=CH_STATUS&other='.$oado.'">'.
744 $aym->relation_string($oado).
745 '</a>, <a href="command.epl?cmd=SEND_MSG&other='.$oado.'">'.
746 $db->loc('SEND_MESSAGE').'</a>)';
748 }elsif($otype eq 'AVATAR'){
749 $out .= ' (<a href="command.epl?cmd=CH_ACTION&mob='.$oid.'">'.
750 $aym->mobile_string($ostat,1).'</a>)';
752 $out .= " (<a href=\"command.epl?cmd=DESTROY&loc=$loc\">".
753 $db->loc('CMD_DESTROY').'</a>)';
756 $out .= ' (<a href="command.epl?cmd=MOVE&mob='.$oid.'&loc='.$loc.'">'.
757 $db->loc('CMD_MOVE').'</a>)';
760 $out .= $aym->mobile_string($otype, $ocnt);
762 $out .= ' '.$db->loc('PREP_OWN_SG').' ';
763 $out .= $db->loc('ART_DAT_PL').' ' if $aym->gender($oown) eq 'PLURAL';
764 $out .= $aym->charname($oown);
765 if($own != $oown and $occ != $oown){
766 $out .= ' (<a href="command.epl?cmd=CH_STATUS&other='.$oown.'">'.
767 $aym->relation_string($oown).'</a>,'.
768 '<a href="command.epl?cmd=SEND_MSG&other='.$oown.'">'.
769 $db->loc('SEND_MESSAGE').'</a>)';
772 if($otype eq 'PRIEST' or $otype eq 'PROPHET'or $otype eq 'HERO'){
773 $out .= $db->loc('ADJ_ADORING').' ';
775 $out .= $db->loc( ($aym->gender($user) eq 'PLURAL') ?
776 'PPRO_DAT3_PL' : 'PPRO_DAT3_SG');
778 $out .= $aym->charname($oado);
779 if($own != $oown and $occ != $oown){
780 $out .= ' (<a href="command.epl?cmd=CH_STATUS&other='.$oado.'">'.
781 $aym->relation_string($oado).
782 '</a>, <a href="command.epl?cmd=SEND_MSG&other='.$oado.'">'.
783 $db->loc('SEND_MESSAGE').'</a>)';
786 }elsif($otype eq 'WARRIOR' and $aym->is_god($user)){
787 $out .= ' (<a href="command.epl?cmd=BLESS_PRIEST&mob='.$oid.'">'.
788 $db->loc('CMD_BLESS_PRIEST').'</a>)';
789 if($own==$user and $temple eq 'Y'){
790 $out .= ' (<a href="command.epl?cmd=BLESS_HERO&mob='.$oid.'">'.
791 $db->loc('CMD_BLESS_HERO').'</a>)';
798 # this overloads the same function in Game.pm
799 # we dont look on arks, that is special for Aymargeddon
801 # my($self,$loc,$player,$active) = @_;
802 # my $cond = "GAME=$self->{-game} AND LOCATION=$loc".
803 # " AND TYPE!=ARK AND (OWNER=$player OR ADORING=$player)";
804 # if(defined $active){
805 # # my $y = $self->{-db}->quote('Y');
806 # $cond .= " AND AVAILABLE='Y'";
808 # return $self->{-db}->select_array('MOBILE','ID',$cond);
812 # returns true if foreign eartlings approach to field
813 sub foreign_earthling_approaching{
814 my ($self,$loc,$earthling) = @_;
816 # TODO BUG: if $earthling < 1 => different names in different languages...
817 my $name = $self->charname($earthling);
818 my $ret = $self->{-db}->count('EVENT',
819 "LOCATION=$loc AND ".
820 "(TAG=EVENT_MOBILE_APPROACHING OR ".
821 "TAG=EVENT_ARK_APPROACHING) AND ".
822 "ARG1 != $name AND ".
823 "ARG4 != MOBILE_AVATAR AND ".
824 "ARG4 != MOBILE_AVATAR_PL");
829 # returns true if own avatar is there and if no god-fight is running
830 sub avatar_available{
831 my ($self,$loc,$god,$command) = @_;
833 my $avatars = $self->own_in_mobile($loc,$god,1);
834 my @avatars = @$avatars;
836 my ($godfight) = $self->read_field('GOD_ATTACKER',$loc);
838 unless($#avatars >= 0 and not $godfight){
839 $self->send_message_to($god,
840 {'MSG_TAG' => "MSG_$command\_NEED_AVATAR",
841 'ARG1' => $loc}) if defined $command;