… | |
… | |
136 | * the function that calls this should figure them out. |
136 | * the function that calls this should figure them out. |
137 | */ |
137 | */ |
138 | void |
138 | void |
139 | object::enter_map (maptile *newmap, int x, int y) |
139 | object::enter_map (maptile *newmap, int x, int y) |
140 | { |
140 | { |
141 | if (!newmap->load ()) |
|
|
142 | return; |
|
|
143 | |
|
|
144 | if (out_of_map (newmap, x, y)) |
141 | if (out_of_map (newmap, x, y)) |
145 | { |
142 | { |
146 | LOG (llevError, "enter_map: supplied coordinates are not within the map! (%s: %d, %d)\n", &newmap->path, x, y); |
143 | LOG (llevError, "enter_map: supplied coordinates are not within the map! (%s: %d, %d)\n", &newmap->path, x, y); |
147 | x = newmap->enter_x; |
144 | x = newmap->enter_x; |
148 | y = newmap->enter_y; |
145 | y = newmap->enter_y; |
… | |
… | |
152 | &newmap->path, x, y, newmap->width, newmap->height); |
149 | &newmap->path, x, y, newmap->width, newmap->height); |
153 | new_draw_info (NDI_UNIQUE, 0, this, "The exit is closed"); |
150 | new_draw_info (NDI_UNIQUE, 0, this, "The exit is closed"); |
154 | return; |
151 | return; |
155 | } |
152 | } |
156 | } |
153 | } |
|
|
154 | |
|
|
155 | if (map) |
|
|
156 | if (INVOKE_MAP (LEAVE, map, ARG_PLAYER (contr))) |
|
|
157 | return; |
|
|
158 | |
|
|
159 | /* If it is a player login, he has yet to be inserted anyplace. |
|
|
160 | * otherwise, we need to deal with removing the player here. |
|
|
161 | */ |
|
|
162 | remove (); |
157 | |
163 | |
158 | /* try to find a spot for the player */ |
164 | /* try to find a spot for the player */ |
159 | if (ob_blocked (this, newmap, x, y)) |
165 | if (ob_blocked (this, newmap, x, y)) |
160 | { /* First choice blocked */ |
166 | { /* First choice blocked */ |
161 | /* We try to find a spot for the player, starting closest in. |
167 | /* We try to find a spot for the player, starting closest in. |
… | |
… | |
182 | else |
188 | else |
183 | /* not much we can do in this case. */ |
189 | /* not much we can do in this case. */ |
184 | LOG (llevInfo, "enter_map: Could not find free spot for player - will dump on top of object (%s: %d, %d)\n", &newmap->path, x, y); |
190 | LOG (llevInfo, "enter_map: Could not find free spot for player - will dump on top of object (%s: %d, %d)\n", &newmap->path, x, y); |
185 | } |
191 | } |
186 | |
192 | |
187 | if (map) |
|
|
188 | if (INVOKE_MAP (LEAVE, map, ARG_PLAYER (contr))) |
|
|
189 | return; |
|
|
190 | |
|
|
191 | if (INVOKE_PLAYER (MAP_CHANGE, contr, ARG_MAP (newmap), ARG_INT (x), ARG_INT (y))) |
193 | if (INVOKE_PLAYER (MAP_CHANGE, contr, ARG_MAP (newmap), ARG_INT (x), ARG_INT (y))) |
192 | return; |
194 | return; |
193 | |
195 | |
194 | if (INVOKE_MAP (ENTER, newmap, ARG_PLAYER (contr), ARG_INT (x), ARG_INT (y))) |
196 | if (INVOKE_MAP (ENTER, newmap, ARG_PLAYER (contr), ARG_INT (x), ARG_INT (y))) |
195 | return; |
197 | return; |
196 | |
|
|
197 | /* If it is a player login, he has yet to be inserted anyplace. |
|
|
198 | * otherwise, we need to deal with removing the player here. |
|
|
199 | */ |
|
|
200 | remove (); |
|
|
201 | |
198 | |
202 | this->x = x; |
199 | this->x = x; |
203 | this->y = y; |
200 | this->y = y; |
204 | map = newmap; |
201 | map = newmap; |
205 | |
202 | |
… | |
… | |
247 | |
244 | |
248 | /* since the players map is already loaded, we don't need to worry |
245 | /* since the players map is already loaded, we don't need to worry |
249 | * about pending objects. |
246 | * about pending objects. |
250 | */ |
247 | */ |
251 | remove_all_pets (newmap); |
248 | remove_all_pets (newmap); |
252 | } |
|
|
253 | |
|
|
254 | /* clean_path takes a path and replaces all / with _ |
|
|
255 | * We do a strcpy so that we do not change the original string. |
|
|
256 | */ |
|
|
257 | char * |
|
|
258 | clean_path (const char *file) |
|
|
259 | { |
|
|
260 | static char newpath[MAX_BUF], *cp; |
|
|
261 | assign (newpath, file); |
|
|
262 | |
|
|
263 | for (cp = newpath; *cp != '\0'; cp++) |
|
|
264 | if (*cp == '/') |
|
|
265 | *cp = '_'; |
|
|
266 | |
|
|
267 | return newpath; |
|
|
268 | } |
|
|
269 | |
|
|
270 | /* unclean_path takes a path and replaces all _ with / |
|
|
271 | * This basically undoes clean path. |
|
|
272 | * We do a strcpy so that we do not change the original string. |
|
|
273 | * We are smart enough to start after the last / in case we |
|
|
274 | * are getting passed a string that points to a unique map |
|
|
275 | * path. |
|
|
276 | */ |
|
|
277 | char * |
|
|
278 | unclean_path (const char *src) |
|
|
279 | { |
|
|
280 | static char newpath[MAX_BUF], *cp; |
|
|
281 | |
|
|
282 | cp = strrchr (src, '/'); |
|
|
283 | assign (newpath, cp ? cp + 1 : src); |
|
|
284 | |
|
|
285 | for (cp = newpath; *cp != '\0'; cp++) |
|
|
286 | if (*cp == '_') |
|
|
287 | *cp = '/'; |
|
|
288 | |
|
|
289 | return newpath; |
|
|
290 | } |
249 | } |
291 | |
250 | |
292 | /* process_players1 and process_players2 do all the player related stuff. |
251 | /* process_players1 and process_players2 do all the player related stuff. |
293 | * I moved it out of process events and process_map. This was to some |
252 | * I moved it out of process events and process_map. This was to some |
294 | * extent for debugging as well as to get a better idea of the time used |
253 | * extent for debugging as well as to get a better idea of the time used |
… | |
… | |
455 | free (dump); |
414 | free (dump); |
456 | op->destroy (); |
415 | op->destroy (); |
457 | continue; |
416 | continue; |
458 | } |
417 | } |
459 | |
418 | |
460 | if (!op->speed) |
419 | if (!op->has_active_speed ()) |
461 | { |
420 | { |
462 | LOG (llevError, "BUG: process_events(): Object %s has no speed, " |
421 | LOG (llevError, "BUG: process_events(): Object %s has no speed (%f), " |
463 | "but is on active list\n", &op->arch->name); |
422 | "but is on active list\n", op->debug_desc (), op->speed); |
464 | op->set_speed (0); |
423 | op->set_speed (0); |
465 | continue; |
424 | continue; |
466 | } |
425 | } |
467 | |
426 | |
468 | if (op->map == NULL && op->env == NULL && op->name && op->type != MAP) |
427 | if (op->map == NULL && op->env == NULL && op->name && op->type != MAP) |
… | |
… | |
554 | void |
513 | void |
555 | cleanup (bool make_core) |
514 | cleanup (bool make_core) |
556 | { |
515 | { |
557 | LOG (llevDebug, "cleanup begin.\n"); |
516 | LOG (llevDebug, "cleanup begin.\n"); |
558 | |
517 | |
|
|
518 | if (init_done && !in_cleanup) |
|
|
519 | { |
559 | in_cleanup = true; |
520 | in_cleanup = true; |
560 | |
|
|
561 | if (init_done) |
|
|
562 | emergency_save (); |
521 | emergency_save (); |
|
|
522 | } |
|
|
523 | else |
|
|
524 | in_cleanup = true; |
563 | |
525 | |
564 | LOG (llevDebug, "running cleanup handlers.\n"); |
526 | LOG (llevDebug, "running cleanup handlers.\n"); |
565 | INVOKE_GLOBAL (CLEANUP); |
527 | INVOKE_GLOBAL (CLEANUP); |
566 | |
528 | |
567 | LOG (llevDebug, "cleanup done.\n"); |
529 | LOG (llevDebug, "cleanup done.\n"); |
… | |
… | |
729 | initPlugins (); |
691 | initPlugins (); |
730 | |
692 | |
731 | for (;;) |
693 | for (;;) |
732 | cfperl_main (); |
694 | cfperl_main (); |
733 | |
695 | |
734 | // unreached |
|
|
735 | cleanup (); |
696 | cleanup (true); |
736 | |
|
|
737 | return 0; |
|
|
738 | } |
697 | } |
|
|
698 | |