|
Atrinik Server 2.5
|
00001 /************************************************************************ 00002 * Atrinik, a Multiplayer Online Role Playing Game * 00003 * * 00004 * Copyright (C) 2009-2011 Alex Tokar and Atrinik Development Team * 00005 * * 00006 * Fork from Daimonin (Massive Multiplayer Online Role Playing Game) * 00007 * and Crossfire (Multiplayer game for X-windows). * 00008 * * 00009 * This program is free software; you can redistribute it and/or modify * 00010 * it under the terms of the GNU General Public License as published by * 00011 * the Free Software Foundation; either version 2 of the License, or * 00012 * (at your option) any later version. * 00013 * * 00014 * This program is distributed in the hope that it will be useful, * 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00017 * GNU General Public License for more details. * 00018 * * 00019 * You should have received a copy of the GNU General Public License * 00020 * along with this program; if not, write to the Free Software * 00021 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 00022 * * 00023 * The author can be reached at admin@atrinik.org * 00024 ************************************************************************/ 00025 00035 #include <global.h> 00036 00040 void magic_mirror_init(object *mirror) 00041 { 00042 sint16 mirror_x, mirror_y; 00043 00044 if (!mirror->map) 00045 { 00046 LOG(llevBug, "magic_mirror_init(): Magic mirror not on map.\n"); 00047 return; 00048 } 00049 00050 mirror_x = (mirror->stats.hp == -1 ? mirror->x : mirror->stats.hp); 00051 mirror_y = (mirror->stats.sp == -1 ? mirror->y : mirror->stats.sp); 00052 00053 /* X/Y adjust. */ 00054 if (mirror->stats.maxhp) 00055 { 00056 mirror_x += mirror->stats.maxhp; 00057 } 00058 00059 if (mirror->stats.maxsp) 00060 { 00061 mirror_y += mirror->stats.maxsp; 00062 } 00063 00064 /* No point in doing anything special if we're mirroring the same map. */ 00065 if (!mirror->slaying && mirror_x == mirror->x && mirror_y == mirror->y) 00066 { 00067 return; 00068 } 00069 00070 /* No map path specified, use mirror's map path. */ 00071 if (!mirror->slaying) 00072 { 00073 FREE_AND_ADD_REF_HASH(mirror->slaying, mirror->map->path); 00074 } 00075 /* Map path was specified, so try to normalize it. */ 00076 else 00077 { 00078 char tmp_path[HUGE_BUF]; 00079 00080 normalize_path(mirror->map->path, mirror->slaying, tmp_path); 00081 FREE_AND_COPY_HASH(mirror->slaying, tmp_path); 00082 } 00083 00084 /* Initialize custom_attrset. */ 00085 mirror->custom_attrset = malloc(sizeof(magic_mirror_struct)); 00086 /* Save x/y and clear map. */ 00087 MMIRROR(mirror)->x = mirror_x; 00088 MMIRROR(mirror)->y = mirror_y; 00089 MMIRROR(mirror)->map = NULL; 00090 } 00091 00097 void magic_mirror_deinit(object *mirror) 00098 { 00099 free(mirror->custom_attrset); 00100 } 00101 00108 mapstruct *magic_mirror_get_map(object *mirror) 00109 { 00110 magic_mirror_struct *data = MMIRROR(mirror); 00111 00112 /* Map good to go? */ 00113 if (data->map && data->map->in_memory == MAP_IN_MEMORY) 00114 { 00115 /* Reset timeout so the mirrored map doesn't get swapped out. */ 00116 MAP_TIMEOUT(data->map) = MAP_DEFAULTTIMEOUT; 00117 return data->map; 00118 } 00119 00120 /* Try to load the map. */ 00121 data->map = ready_map_name(mirror->slaying, MAP_NAME_SHARED); 00122 00123 if (!data->map) 00124 { 00125 LOG(llevBug, "magic_mirror_get_map(): Could not load map '%s'.\n", mirror->slaying); 00126 return NULL; 00127 } 00128 00129 return data->map; 00130 }
1.7.4