Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

worldmap.php

Go to the documentation of this file.
00001 <?php
00009 /***************************************************************************
00010  This program is free software; you can redistribute it and/or
00011  modify it under the terms of the GNU General Public License
00012  as published by the Free Software Foundation; either version 2
00013  of the License, or (at your option) any later version.
00014 
00015  This program is distributed in the hope that it will be useful,
00016  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  GNU General Public License for more details.
00019 
00020  You should have received a copy of the GNU General Public License
00021  along with this program; if not, write to the Free Software
00022  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00023  ***************************************************************************/
00024 
00025 require_once ('./general.php');
00026 require_once ('./lib/worldmap.php');
00027 
00028 // get styles
00029 $oStyle->setTemplate ( 'worldmap.html' );
00030 $oStyle->split_area('Anzeige');
00031 $oStyle->split_area('Town');
00032 $oStyle->split_area('Filter');
00033 $oStyle->split_area('FilterBit');
00034 $oStyle->split_area('Raster');
00035 
00036 $oWorldMap = new WorldMap ( $oMysql, $oUser );
00037 
00038 // get variables
00039 if(isset($_POST['zoom']))     $intZoom = intval($_POST['zoom']);
00040 elseif(isset($_GET['zoom']))  $intZoom = intval($_GET['zoom']);
00041 elseif(isset($_COOKIE[$strCookiePrefix]['wm_zoom'])) $intZoom = intval($_COOKIE[$strCookiePrefix]['wm_zoom']);
00042 else $intZoom = 1;
00043 
00044 if(isset($_POST['xpos']))     $intX = intval($_POST['xpos']);
00045 elseif(isset($_GET['xpos']))  $intX = intval($_GET['xpos']);
00046 elseif(isset($_COOKIE[$strCookiePrefix]['wm_xpos'])) $intX = intval($_COOKIE[$strCookiePrefix]['wm_xpos']);
00047 else $intX = 0;
00048 
00049 if(isset($_POST['ypos']))     $intY = intval($_POST['ypos']);
00050 elseif(isset($_GET['ypos']))  $intY = intval($_GET['ypos']);
00051 elseif(isset($_COOKIE[$strCookiePrefix]['wm_ypos'])) $intY = intval($_COOKIE[$strCookiePrefix]['wm_ypos']);
00052 else $intY = 0;
00053 
00054 if(isset($_POST['filter']))     $strFilter = $_POST['filter'];
00055 elseif(isset($_GET['filter']))  $strFilter = $_GET['filter'];
00056 else $strFilter = '';
00057 
00058 if(isset($_POST['mode']))     $intMapMode = intval($_POST['mode']);
00059 elseif(isset($_GET['mode']))  $intMapMode = intval($_GET['mode']);
00060 elseif(isset($_COOKIE[$strCookiePrefix]['wm_mode'])) $intMapMode = intval($_COOKIE[$strCookiePrefix]['wm_mode']);
00061 else $intMapMode = 0;
00062 
00063 // Check input
00064 if( !in_array( $intZoom, array( 1, 2, 4 ) ) )
00065 {
00066     $intZoom = 1;
00067 }
00068 if( $intX >= $intZoom || $intX < 0)
00069 {
00070     $intX = 0;
00071 }
00072 if( $intY >= $intZoom || $intY < 0)
00073 {
00074     $intY = 0;
00075 }
00076 
00077 // update cookies, if needed
00078 if( !isset($_COOKIE[$strCookiePrefix]['wm_zoom']) || $intZoom != $_COOKIE[$strCookiePrefix]['wm_zoom'] )
00079     setcookie ($strCookiePrefix.'[wm_zoom]', $intZoom, time()+7*24*60*60);
00080 
00081 if( !isset($_COOKIE[$strCookiePrefix]['wm_xpos']) || $intX != $_COOKIE[$strCookiePrefix]['wm_xpos'] )
00082     setcookie ($strCookiePrefix.'[wm_xpos]', $intX, time()+7*24*60*60);
00083 
00084 if( !isset($_COOKIE[$strCookiePrefix]['wm_ypos']) || $intY != $_COOKIE[$strCookiePrefix]['wm_ypos'] )
00085     setcookie ($strCookiePrefix.'[wm_ypos]', $intY, time()+7*24*60*60);
00086 
00087 if( !isset($_COOKIE[$strCookiePrefix]['wm_mode']) || $intMapMode != $_COOKIE[$strCookiePrefix]['wm_mode'] )
00088     setcookie ($strCookiePrefix.'[wm_mode]', $intMapMode, time()+7*24*60*60);
00089 
00090 if ( isset ( $_GET['action'] ) && $_GET['action'] == 'filter' )
00091 {
00092     $aGuilds = $oWorldMap->getGuilds();
00093 
00094     $aFilter = explode ( '_', substr($strFilter, 1) );
00095     $strFilterData = '';
00096     $i = 0;
00097     foreach ( $aGuilds AS $aRow )
00098     {
00099         $strSelect = ( in_array ( $aRow['guild_id'], $aFilter ) ) ? ' checked="checked"' : '';
00100         $oStyle->addReplacements ( array ( 'FILTER_ID' => $aRow['guild_id'],
00101                                            'FILTER_TAG' => $aRow['tag']!='' ? '['.$aRow['tag'].']' : '',
00102                                            'FILTER_SELECT' => $strSelect ) );
00103         $strFilterData .= $oStyle->get_area ( 'FilterBit' );
00104         $i++;
00105     }
00106     $strQuery = str_replace ( 'action=filter', '', $_SERVER['QUERY_STRING'] );
00107     $strQuery = htmlspecialchars ( str_replace ( 'filter='.$strFilter, '', $strQuery ) );
00108     $oStyle->addReplacements ( array ( 'FILTER_I' => $i,
00109                                        'FILTER_VARS' => $strQuery,
00110                                        'FILTER_DATA' => $strFilterData ) );
00111     echo trim ( $oStyle->get_area ( 'Filter' ) );
00112     die();
00113 }
00114 
00115 $intFields = $intMapSize / $intZoom;
00116 
00117 // init map size
00118 $mapWidth = 980;
00119 $mapHeight = 980;
00120 
00121 // build raster
00122 $strRaster = '';
00123 
00124 // vertical lines
00125 $intStart = $intX * $intFields;
00126 $intStart = 100 - ( $intStart % 100 ) + $intStart;
00127 $intEnd = ($intX+1) * $intFields;
00128 for ( $i = $intStart; $i < $intEnd; $i+=100 )
00129 {
00130     $rleft = round ( $i / $intFields * $mapWidth - $intX * $mapWidth );
00131     $rtop  = 0;
00132     $oStyle->addReplacements ( array ( 'RASTER_LEFT' => $rleft,
00133                                        'RASTER_TOP' => $rtop,
00134                                        'RASTER_WIDTH' => 1,
00135                                        'RASTER_HEIGHT' => $mapHeight
00136                                      )
00137                               );
00138     $strRaster .= $oStyle->get_area('Raster');
00139 }
00140 
00141 // horizontal lines
00142 $intStart = $intY * $intFields;
00143 $intStart = 100 - ( $intStart % 100 ) + $intStart;
00144 $intEnd = ($intY+1) * $intFields;
00145 for ( $i = $intStart; $i < $intEnd; $i+=100 )
00146 {
00147     $rleft = 0;
00148     $rtop  = round ( $i / $intFields * $mapHeight - $intY * $mapHeight );
00149     $oStyle->addReplacements ( array ( 'RASTER_LEFT' => $rleft,
00150                                        'RASTER_TOP' => $rtop,
00151                                        'RASTER_WIDTH' => $mapWidth,
00152                                        'RASTER_HEIGHT' => 1
00153                                      )
00154                               );
00155     $strRaster .= $oStyle->get_area('Raster');
00156 }
00157 
00158 
00159 // build town data
00160 $aTownData = $oWorldMap->getTowns ( $intFields, $intZoom, $intX, $intY, $strFilter );
00161 
00162 $strTowns = '';
00163 $i = 0;
00164 foreach ( $aTownData AS $aRow )
00165 {
00166     $intLeft = round ( $aRow['x'] / $intFields * $mapWidth - $intX * $mapWidth );
00167     $intTop  = round ( $aRow['y'] / $intFields * $mapHeight - $intY * $mapHeight );
00168 
00169     $aRow['diplomacy'] = intval( $aRow['diplomacy'] );
00170     // prefix if town position is not precise
00171     $strPrefix = ( $aRow['building'] == -2 ) ? '~' : '';
00172     $strGuild  = ( $aRow['tag'] ) ? '['.$aRow['tag'].']' : '';
00173     $strTownColor = ( $intMapMode == 1 ) ? $aDiploBgColor[$aRow['diplomacy']] : $aRow['bgcolor'];
00174     $strTownColor = str_replace ( '#', '', $strTownColor );
00175     if(empty( $strTownColor ) ) $strTownColor = "ffffff";
00176 
00177     $oStyle->addReplacements ( array ( 'TOWN_X' => $aRow['x'],
00178                                        'TOWN_Y' => $aRow['y'],
00179                                        'TOWN_LEFT' => $intLeft,
00180                                        'TOWN_TOP' => $intTop,
00181                                        'TOWN_PLAYER' => $aRow['name'],
00182                                        'TOWN_GUILD' => $strGuild,
00183                                        'TOWN_RACE' => $aRaces[$aRow['race']],
00184                                        'TOWN_TYPE' => $aTypes[$aRow['typ']],
00185                                        'TOWN_COLOR' => $strTownColor,
00186                                        'TOWN_PREFIX' => $strPrefix
00187                                      )
00188                               );
00189     $strTowns .= $oStyle->get_area ( 'Town' );
00190     $i++;
00191 }
00192 
00193 // create zoom links
00194 $strZoomLink = '';
00195 for ( $i = 1; $i < 5; $i++ )
00196 {
00197     if ($i == 3)
00198     {
00199         continue;
00200     }
00201     $strZoomLink .= ( $i == $intZoom ) ? '&nbsp;<b><u>'.$i.'x</u></b>&nbsp;'
00202                                        : '&nbsp;<a href="worldmap.php?zoom=' . $i . '&amp;mode=' . $intMapMode . '">'.$i.'x</a>&nbsp;';
00203 }
00204 
00205 // create movement links
00206 $strMoveLink = '';
00207 if ( $intZoom > 1 )
00208 {
00209     if ( $intX > 0 )
00210     {
00211         $strMoveLink .= '<a href="worldmap.php?zoom='.$intZoom.'&amp;xpos='.($intX-1).'&amp;ypos='.($intY).'&amp;mode=' . $intMapMode . '"><img alt="nach links" src="img/icon_menu_nl.gif" /></a>';
00212     }
00213     if ($intY > 0)
00214     {
00215         $strMoveLink .= '<a href="worldmap.php?zoom='.$intZoom.'&amp;xpos='.($intX).'&amp;ypos='.($intY-1).'&amp;mode=' . $intMapMode . '"><img alt="nach oben" src="img/icon_menu_no.gif" /></a>';
00216     }
00217     if ($intX < $intZoom-1)
00218     {
00219         $strMoveLink .= '<a href="worldmap.php?zoom='.$intZoom.'&amp;xpos='.($intX+1).'&amp;ypos='.($intY).'&amp;mode=' . $intMapMode . '"><img alt="nach rechts" src="img/icon_menu_nr.gif" /></a>';
00220     }
00221     if ($intY < $intZoom-1)
00222     {
00223         $strMoveLink .= '<a href="worldmap.php?zoom='.$intZoom.'&amp;xpos='.($intX).'&amp;ypos='.($intY+1).'&amp;mode=' . $intMapMode . '"><img alt="nach unten" src="img/icon_menu_nu.gif" /></a>';
00224     }
00225     $strMoveLink = '<td>'.$strMoveLink.'</td>';
00226 }
00227 
00228 // create Mode link
00229 $strModeLink = ( $intMapMode == 0 )
00230                    ? '<a href="' . $_SERVER['PHP_SELF'] . '?zoom=' . $intZoom . '&amp;xpos=' . ($intX) . '&amp;ypos=' . ($intY) . '&amp;mode=1">Diplomatiefarben</a>'
00231                    : '<a href="' . $_SERVER['PHP_SELF'] . '?zoom=' . $intZoom . '&amp;xpos=' . ($intX) . '&amp;ypos=' . ($intY) . '&amp;mode=0">Gildenfarben</a>';
00232 
00233 // add replacments
00234 $oStyle->addReplacements ( array ( 'WM_X' => $intX,
00235                                    'WM_Y' => $intY,
00236                                    'WM_ZOOM_LINK' => $strZoomLink,
00237                                    'WM_MODE_LINK' => $strModeLink,
00238                                    'WM_MOVE_LINK' => $strMoveLink,
00239                                    'WM_RASTER' => $strRaster,
00240                                    'WM_ZOOM' => $intZoom,
00241                                    'WM_TOWNS' => $strTowns,
00242                                    'WM_FILTER' => $strFilter,
00243                                    'WM_HEIGHT' => $mapHeight,
00244                                    'WM_WIDTH' => $mapWidth
00245                                  )
00246                           );
00247 
00248 // get the area
00249 $strTmpl_inhalt = $oStyle->get_area( 'Anzeige' );
00250 output();

Generated on Sun May 8 19:29:45 2005 for PhpMap by  doxygen 1.4.2