00001 /* 00002 * The Mana World Server 00003 * Copyright 2004 The Mana World Development Team 00004 * 00005 * This file is part of The Mana World. 00006 * 00007 * The Mana World is free software; you can redistribute it and/or modify it 00008 * under the terms of the GNU General Public License as published by the Free 00009 * Software Foundation; either version 2 of the License, or any later version. 00010 * 00011 * The Mana World is distributed in the hope that it will be useful, but 00012 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 00013 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 00014 * more details. 00015 * 00016 * You should have received a copy of the GNU General Public License along 00017 * with The Mana World; if not, write to the Free Software Foundation, Inc., 00018 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 */ 00020 00021 #include "game-server/actor.hpp" 00022 00023 #include "game-server/map.hpp" 00024 #include "game-server/mapcomposite.hpp" 00025 00026 #include <cassert> 00027 00028 void Actor::setPosition(const Point &p) 00029 { 00030 mPos = p; 00031 00032 // Update blockmap 00033 if (getMap()) 00034 { 00035 const Point &oldP = getPosition(); 00036 if ((oldP.x / 32 != p.x / 32 || oldP.y / 32 != p.y / 32)) 00037 { 00038 getMap()->getMap()->freeTile(oldP.x / 32, oldP.y / 32, getBlockType()); 00039 getMap()->getMap()->blockTile(p.x / 32, p.y / 32, getBlockType()); 00040 } 00041 } 00042 } 00043 00044 void Actor::setMap(MapComposite *map) 00045 { 00046 assert (map); 00047 MapComposite *oldMap = getMap(); 00048 Point p = getPosition(); 00049 00050 if (oldMap) 00051 { 00052 oldMap->getMap()->freeTile(p.x / 32, p.y / 32, getBlockType()); 00053 } 00054 Thing::setMap(map); 00055 map->getMap()->blockTile(p.x / 32, p.y / 32, getBlockType()); 00056 /* the last line might look illogical because the current position is 00057 * invalid on the new map, but it is necessary to block the old position 00058 * because the next call of setPosition() will automatically free the old 00059 * position. When we don't block the position now the occupation counting 00060 * will be off. 00061 */ 00062 }