… | |
… | |
31 | # ifdef HAVE_CRYPT_H |
31 | # ifdef HAVE_CRYPT_H |
32 | # include <crypt.h> |
32 | # include <crypt.h> |
33 | # endif |
33 | # endif |
34 | #endif |
34 | #endif |
35 | |
35 | |
36 | #ifndef __CEXTRACT__ |
|
|
37 | # include <sproto.h> |
36 | #include <sproto.h> |
38 | #endif |
|
|
39 | |
|
|
40 | #ifdef HAVE_TIME_H |
|
|
41 | # include <time.h> |
37 | #include <time.h> |
42 | #endif |
|
|
43 | |
38 | |
44 | #include <../random_maps/random_map.h> |
39 | #include <../random_maps/random_map.h> |
45 | #include <../random_maps/rproto.h> |
40 | #include <../random_maps/rproto.h> |
46 | #include "path.h" |
41 | #include "path.h" |
47 | |
42 | |
… | |
… | |
106 | new_draw_info (NDI_UNIQUE, 0, op, "Images and art:"); |
101 | new_draw_info (NDI_UNIQUE, 0, op, "Images and art:"); |
107 | new_draw_info (NDI_UNIQUE, 0, op, "Peter Gardner"); |
102 | new_draw_info (NDI_UNIQUE, 0, op, "Peter Gardner"); |
108 | new_draw_info (NDI_UNIQUE, 0, op, "David Gervais [david_eg@mail.com]"); |
103 | new_draw_info (NDI_UNIQUE, 0, op, "David Gervais [david_eg@mail.com]"); |
109 | new_draw_info (NDI_UNIQUE, 0, op, "Mitsuhiro Itakura [ita@gold.koma.jaeri.go.jp]"); |
104 | new_draw_info (NDI_UNIQUE, 0, op, "Mitsuhiro Itakura [ita@gold.koma.jaeri.go.jp]"); |
110 | new_draw_info (NDI_UNIQUE, 0, op, "Hansjoerg Malthaner [hansjoerg.malthaner@danet.de]"); |
105 | new_draw_info (NDI_UNIQUE, 0, op, "Hansjoerg Malthaner [hansjoerg.malthaner@danet.de]"); |
111 | new_draw_info (NDI_UNIQUE, 0, op, "Mårten Woxberg [maxmc@telia.com]"); |
106 | new_draw_info (NDI_UNIQUE, 0, op, "MÃ¥rten Woxberg [maxmc@telia.com]"); |
112 | new_draw_info (NDI_UNIQUE, 0, op, "And many more!"); |
107 | new_draw_info (NDI_UNIQUE, 0, op, "And many more!"); |
113 | } |
108 | } |
114 | |
109 | |
115 | void |
110 | void |
116 | info_keys (object *op) |
111 | info_keys (object *op) |
… | |
… | |
138 | void |
133 | void |
139 | start_info (object *op) |
134 | start_info (object *op) |
140 | { |
135 | { |
141 | char buf[MAX_BUF]; |
136 | char buf[MAX_BUF]; |
142 | |
137 | |
143 | sprintf (buf, "Welcome to Crossfire, v%s!", VERSION); |
138 | sprintf (buf, "Welcome to Crossfire v%s!", VERSION); |
144 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
139 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
145 | new_draw_info (NDI_UNIQUE, 0, op, "Press `?' for help"); |
140 | new_draw_info (NDI_UNIQUE, 0, op, "Press `?' for help"); |
146 | new_draw_info (NDI_UNIQUE, 0, op, " "); |
141 | new_draw_info (NDI_UNIQUE, 0, op, " "); |
147 | new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, op, "%s entered the game.", &op->name); |
142 | new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, op, "%s entered the game.", &op->name); |
148 | if (!op->contr->name_changed) |
|
|
149 | { |
|
|
150 | new_draw_info (NDI_UNIQUE, 0, op, "Note that you must set your name with the name"); |
|
|
151 | new_draw_info (NDI_UNIQUE, 0, op, "command to enter the highscore list."); |
|
|
152 | new_draw_info (NDI_UNIQUE, 0, op, "(You can also use the crossfire.name X-resource.)"); |
|
|
153 | } |
|
|
154 | } |
|
|
155 | |
|
|
156 | /* Really, there is no reason to crypt the passwords any system. But easier |
|
|
157 | * to just leave this enabled for backward compatibility. Put the |
|
|
158 | * simple case at top - no encryption - makes it easier to read. |
|
|
159 | */ |
|
|
160 | char * |
|
|
161 | crypt_string (char *str, char *salt) |
|
|
162 | { |
|
|
163 | #if defined(WIN32) || (defined(__FreeBSD__) && !defined(HAVE_LIBDES)) |
|
|
164 | return (str); |
|
|
165 | #else |
|
|
166 | static char *c = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./"; |
|
|
167 | char s[2]; |
|
|
168 | |
|
|
169 | if (salt == NULL) |
|
|
170 | s[0] = c[RANDOM () % (int) strlen (c)], s[1] = c[RANDOM () % (int) strlen (c)]; |
|
|
171 | else |
|
|
172 | s[0] = salt[0], s[1] = salt[1]; |
|
|
173 | |
|
|
174 | # ifdef HAVE_LIBDES |
|
|
175 | return (char *) des_crypt (str, s); |
|
|
176 | # endif |
|
|
177 | /* Default case - just use crypt */ |
|
|
178 | return (char *) crypt (str, s); |
|
|
179 | #endif |
|
|
180 | } |
|
|
181 | |
|
|
182 | int |
|
|
183 | check_password (char *typed, char *crypted) |
|
|
184 | { |
|
|
185 | return !strcmp (crypt_string (typed, crypted), crypted); |
|
|
186 | } |
143 | } |
187 | |
144 | |
188 | /* This is a basic little function to put the player back to his |
145 | /* This is a basic little function to put the player back to his |
189 | * savebed. We do some error checking - its possible that the |
146 | * savebed. We do some error checking - its possible that the |
190 | * savebed map may no longer exist, so we make sure the player |
147 | * savebed map may no longer exist, so we make sure the player |
191 | * goes someplace. |
148 | * goes someplace. |
192 | */ |
149 | */ |
193 | void |
150 | void |
194 | enter_player_savebed (object *op) |
151 | enter_player_savebed (object *op) |
195 | { |
152 | { |
196 | mapstruct *oldmap = op->map; |
153 | maptile *oldmap = op->map; |
197 | object *tmp; |
154 | object *tmp; |
198 | |
155 | |
199 | tmp = get_object (); |
156 | tmp = object::create (); |
200 | |
157 | |
201 | EXIT_PATH (tmp) = op->contr->savebed_map; |
158 | EXIT_PATH (tmp) = op->contr->savebed_map; |
202 | EXIT_X (tmp) = op->contr->bed_x; |
159 | EXIT_X (tmp) = op->contr->bed_x; |
203 | EXIT_Y (tmp) = op->contr->bed_y; |
160 | EXIT_Y (tmp) = op->contr->bed_y; |
204 | enter_exit (op, tmp); |
161 | enter_exit (op, tmp); |
… | |
… | |
217 | EXIT_PATH (tmp) = op->contr->savebed_map; |
174 | EXIT_PATH (tmp) = op->contr->savebed_map; |
218 | EXIT_X (tmp) = op->contr->bed_x; |
175 | EXIT_X (tmp) = op->contr->bed_x; |
219 | EXIT_Y (tmp) = op->contr->bed_y; |
176 | EXIT_Y (tmp) = op->contr->bed_y; |
220 | enter_exit (op, tmp); |
177 | enter_exit (op, tmp); |
221 | } |
178 | } |
222 | free_object (tmp); |
179 | |
|
|
180 | tmp->destroy (); |
223 | } |
181 | } |
224 | |
182 | |
225 | /* All this really is is a glorified remove_object that also updates |
183 | /* All this really is is a glorified remove_object that also updates |
226 | * the counts on the map if needed. |
184 | * the counts on the map if needed. |
227 | */ |
185 | */ |
228 | void |
186 | void |
229 | leave_map (object *op) |
187 | leave_map (object *op) |
230 | { |
188 | { |
231 | mapstruct *oldmap = op->map; |
189 | maptile *oldmap = op->map; |
232 | |
190 | |
233 | remove_ob (op); |
191 | op->remove (); |
234 | |
192 | |
235 | if (oldmap) |
193 | if (oldmap) |
236 | { |
194 | { |
237 | if (!op->contr->hidden) |
195 | if (!op->contr->hidden) |
238 | oldmap->players--; |
196 | oldmap->players--; |
|
|
197 | |
239 | if (oldmap->players <= 0) |
198 | if (oldmap->players <= 0) |
240 | { /* can be less than zero due to errors in tracking this */ |
199 | /* can be less than zero due to errors in tracking this */ |
241 | set_map_timeout (oldmap); |
200 | set_map_timeout (oldmap); |
242 | } |
|
|
243 | } |
201 | } |
244 | } |
202 | } |
245 | |
203 | |
246 | /* |
204 | /* |
247 | * enter_map(): Moves the player and pets from current map (if any) to |
205 | * enter_map(): Moves the player and pets from current map (if any) to |
… | |
… | |
249 | * player to - it could be the map he just came from if the load failed for |
207 | * player to - it could be the map he just came from if the load failed for |
250 | * whatever reason. If default map coordinates are to be used, then |
208 | * whatever reason. If default map coordinates are to be used, then |
251 | * the function that calls this should figure them out. |
209 | * the function that calls this should figure them out. |
252 | */ |
210 | */ |
253 | static void |
211 | static void |
254 | enter_map (object *op, mapstruct *newmap, int x, int y) |
212 | enter_map (object *op, maptile *newmap, int x, int y) |
255 | { |
213 | { |
256 | mapstruct *oldmap = op->map; |
214 | maptile *oldmap = op->map; |
257 | |
215 | |
258 | if (out_of_map (newmap, x, y)) |
216 | if (out_of_map (newmap, x, y)) |
259 | { |
217 | { |
260 | LOG (llevError, "enter_map: supplied coordinates are not within the map! (%s: %d, %d)\n", newmap->path, x, y); |
218 | LOG (llevError, "enter_map: supplied coordinates are not within the map! (%s: %d, %d)\n", newmap->path, x, y); |
261 | x = MAP_ENTER_X (newmap); |
219 | x = newmap->enter_x; |
262 | y = MAP_ENTER_Y (newmap); |
220 | y = newmap->enter_y; |
263 | if (out_of_map (newmap, x, y)) |
221 | if (out_of_map (newmap, x, y)) |
264 | { |
222 | { |
265 | LOG (llevError, "enter_map: map %s provides invalid default enter location (%d, %d) > (%d, %d)\n", |
223 | LOG (llevError, "enter_map: map %s provides invalid default enter location (%d, %d) > (%d, %d)\n", |
266 | newmap->path, x, y, MAP_WIDTH (newmap), MAP_HEIGHT (newmap)); |
224 | newmap->path, x, y, newmap->width, newmap->height); |
267 | new_draw_info (NDI_UNIQUE, 0, op, "The exit is closed"); |
225 | new_draw_info (NDI_UNIQUE, 0, op, "The exit is closed"); |
268 | return; |
226 | return; |
269 | } |
227 | } |
270 | } |
228 | } |
|
|
229 | |
271 | /* try to find a spot for the player */ |
230 | /* try to find a spot for the player */ |
272 | if (ob_blocked (op, newmap, x, y)) |
231 | if (ob_blocked (op, newmap, x, y)) |
273 | { /* First choice blocked */ |
232 | { /* First choice blocked */ |
274 | /* We try to find a spot for the player, starting closest in. |
233 | /* We try to find a spot for the player, starting closest in. |
275 | * We could use find_first_free_spot, but that doesn't randomize it at all, |
234 | * We could use find_first_free_spot, but that doesn't randomize it at all, |
… | |
… | |
284 | { |
243 | { |
285 | i = find_free_spot (op, newmap, x, y, 1, SIZEOFFREE2 + 1); |
244 | i = find_free_spot (op, newmap, x, y, 1, SIZEOFFREE2 + 1); |
286 | if (i == -1) |
245 | if (i == -1) |
287 | i = find_free_spot (op, newmap, x, y, 1, SIZEOFFREE); |
246 | i = find_free_spot (op, newmap, x, y, 1, SIZEOFFREE); |
288 | } |
247 | } |
|
|
248 | |
289 | if (i != -1) |
249 | if (i != -1) |
290 | { |
250 | { |
291 | x += freearr_x[i]; |
251 | x += freearr_x[i]; |
292 | y += freearr_y[i]; |
252 | y += freearr_y[i]; |
293 | } |
253 | } |
… | |
… | |
296 | /* not much we can do in this case. */ |
256 | /* not much we can do in this case. */ |
297 | 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); |
257 | 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); |
298 | } |
258 | } |
299 | } /* end if looking for free spot */ |
259 | } /* end if looking for free spot */ |
300 | |
260 | |
301 | if (op->map != NULL) |
261 | if (op->map) |
302 | { |
|
|
303 | INVOKE_PLAYER (MAP_CHANGE, op->contr, ARG_MAP (op->map), ARG_MAP (newmap)); |
|
|
304 | INVOKE_MAP (LEAVE, op->map, ARG_PLAYER (op->contr)); |
262 | if (INVOKE_MAP (LEAVE, op->map, ARG_PLAYER (op->contr))) |
305 | } |
263 | return; |
|
|
264 | |
|
|
265 | if (INVOKE_PLAYER (MAP_CHANGE, op->contr, ARG_MAP (newmap), ARG_INT (x), ARG_INT (y))) |
|
|
266 | return; |
|
|
267 | |
|
|
268 | if (INVOKE_MAP (ENTER, newmap, ARG_PLAYER (op->contr), ARG_INT (x), ARG_INT (y))) |
|
|
269 | return; |
306 | |
270 | |
307 | /* If it is a player login, he has yet to be inserted anyplace. |
271 | /* If it is a player login, he has yet to be inserted anyplace. |
308 | * otherwise, we need to deal with removing the player here. |
272 | * otherwise, we need to deal with removing the player here. |
309 | */ |
273 | */ |
310 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
274 | op->remove (); |
311 | remove_ob (op); |
|
|
312 | |
275 | |
313 | /* remove_ob clears these so they must be reset after the remove_ob call */ |
276 | /* remove_ob clears these so they must be reset after the remove_ob call */ |
314 | op->x = x; |
277 | op->x = x; |
315 | op->y = y; |
278 | op->y = y; |
316 | op->map = newmap; |
279 | op->map = newmap; |
|
|
280 | |
317 | insert_ob_in_map (op, op->map, NULL, INS_NO_WALK_ON); |
281 | insert_ob_in_map (op, op->map, NULL, INS_NO_WALK_ON); |
318 | |
|
|
319 | INVOKE_MAP (ENTER, op->map, ARG_PLAYER (op->contr)); |
|
|
320 | |
282 | |
321 | if (!op->contr->hidden) |
283 | if (!op->contr->hidden) |
322 | newmap->players++; |
284 | newmap->players++; |
323 | |
285 | |
324 | newmap->timeout = 0; |
286 | newmap->timeout = 0; |
… | |
… | |
334 | if (op->type == PLAYER && op->contr->ranges[range_golem] != NULL) |
296 | if (op->type == PLAYER && op->contr->ranges[range_golem] != NULL) |
335 | { |
297 | { |
336 | int i = find_free_spot (op->contr->ranges[range_golem], newmap, |
298 | int i = find_free_spot (op->contr->ranges[range_golem], newmap, |
337 | x, y, 1, SIZEOFFREE); |
299 | x, y, 1, SIZEOFFREE); |
338 | |
300 | |
339 | remove_ob (op->contr->ranges[range_golem]); |
301 | op->contr->ranges[range_golem]->remove (); |
|
|
302 | |
340 | if (i == -1) |
303 | if (i == -1) |
341 | { |
304 | { |
342 | remove_friendly_object (op->contr->ranges[range_golem]); |
305 | remove_friendly_object (op->contr->ranges[range_golem]); |
343 | free_object (op->contr->ranges[range_golem]); |
306 | op->contr->ranges[range_golem]->destroy (); |
344 | op->contr->ranges[range_golem] = NULL; |
307 | op->contr->ranges[range_golem] = 0; |
345 | op->contr->golem_count = 0; |
|
|
346 | } |
308 | } |
347 | else |
309 | else |
348 | { |
310 | { |
349 | object *tmp; |
|
|
350 | |
|
|
351 | for (tmp = op->contr->ranges[range_golem]; tmp != NULL; tmp = tmp->more) |
311 | for (object *tmp = op->contr->ranges[range_golem]; tmp != NULL; tmp = tmp->more) |
352 | { |
312 | { |
353 | tmp->x = x + freearr_x[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x); |
313 | tmp->x = x + freearr_x[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x); |
354 | tmp->y = y + freearr_y[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y); |
314 | tmp->y = y + freearr_y[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y); |
355 | tmp->map = newmap; |
315 | tmp->map = newmap; |
356 | } |
316 | } |
|
|
317 | |
357 | insert_ob_in_map (op->contr->ranges[range_golem], newmap, NULL, 0); |
318 | insert_ob_in_map (op->contr->ranges[range_golem], newmap, NULL, 0); |
358 | op->contr->ranges[range_golem]->direction = |
319 | op->contr->ranges[range_golem]->direction = |
359 | find_dir_2 (op->x - op->contr->ranges[range_golem]->x, op->y - op->contr->ranges[range_golem]->y); |
320 | find_dir_2 (op->x - op->contr->ranges[range_golem]->x, op->y - op->contr->ranges[range_golem]->y); |
360 | } |
321 | } |
361 | } |
322 | } |
|
|
323 | |
362 | op->direction = 0; |
324 | op->direction = 0; |
363 | |
325 | |
364 | /* since the players map is already loaded, we don't need to worry |
326 | /* since the players map is already loaded, we don't need to worry |
365 | * about pending objects. |
327 | * about pending objects. |
366 | */ |
328 | */ |
… | |
… | |
381 | } |
343 | } |
382 | } |
344 | } |
383 | } |
345 | } |
384 | |
346 | |
385 | void |
347 | void |
386 | set_map_timeout (mapstruct *oldmap) |
348 | set_map_timeout (maptile *oldmap) |
387 | { |
349 | { |
388 | #if MAP_MAXTIMEOUT |
350 | #if MAP_MAXTIMEOUT |
389 | oldmap->timeout = MAP_TIMEOUT (oldmap); |
351 | oldmap->timeout = oldmap->timeout; |
390 | /* Do MINTIMEOUT first, so that MAXTIMEOUT is used if that is |
352 | /* Do MINTIMEOUT first, so that MAXTIMEOUT is used if that is |
391 | * lower than the min value. |
353 | * lower than the min value. |
392 | */ |
354 | */ |
393 | # if MAP_MINTIMEOUT |
355 | # if MAP_MINTIMEOUT |
394 | if (oldmap->timeout < MAP_MINTIMEOUT) |
356 | if (oldmap->timeout < MAP_MINTIMEOUT) |
395 | { |
|
|
396 | oldmap->timeout = MAP_MINTIMEOUT; |
357 | oldmap->timeout = MAP_MINTIMEOUT; |
397 | } |
|
|
398 | # endif |
358 | # endif |
|
|
359 | |
399 | if (oldmap->timeout > MAP_MAXTIMEOUT) |
360 | if (oldmap->timeout > MAP_MAXTIMEOUT) |
400 | { |
|
|
401 | oldmap->timeout = MAP_MAXTIMEOUT; |
361 | oldmap->timeout = MAP_MAXTIMEOUT; |
402 | } |
362 | |
403 | #else |
363 | #else |
404 | /* save out the map */ |
364 | /* save out the map */ |
405 | swap_map (oldmap); |
365 | swap_map (oldmap); |
406 | #endif /* MAP_MAXTIMEOUT */ |
366 | #endif /* MAP_MAXTIMEOUT */ |
407 | } |
367 | } |
… | |
… | |
452 | */ |
412 | */ |
453 | |
413 | |
454 | static void |
414 | static void |
455 | enter_random_map (object *pl, object *exit_ob) |
415 | enter_random_map (object *pl, object *exit_ob) |
456 | { |
416 | { |
457 | mapstruct *new_map; |
417 | maptile *new_map; |
458 | char newmap_name[HUGE_BUF], *cp; |
418 | char newmap_name[HUGE_BUF], *cp; |
459 | static int reference_number = 0; |
419 | static int reference_number = 0; |
460 | RMParms rp; |
420 | RMParms rp; |
461 | |
421 | |
462 | memset (&rp, 0, sizeof (RMParms)); |
422 | memset (&rp, 0, sizeof (RMParms)); |
… | |
… | |
469 | rp.origin_y = exit_ob->y; |
429 | rp.origin_y = exit_ob->y; |
470 | strcpy (rp.origin_map, pl->map->path); |
430 | strcpy (rp.origin_map, pl->map->path); |
471 | |
431 | |
472 | /* If we have a final_map, use it as a base name to give some clue |
432 | /* If we have a final_map, use it as a base name to give some clue |
473 | * as where the player is. Otherwise, use the origin map. |
433 | * as where the player is. Otherwise, use the origin map. |
474 | * Take the last component (after the last slash) to give |
|
|
475 | * shorter names without bogus slashes. |
|
|
476 | */ |
434 | */ |
477 | if (rp.final_map[0]) |
435 | sprintf (newmap_name, "/random%s+%04d", |
478 | { |
436 | *rp.final_map ? rp.final_map : rp.origin_map, |
479 | cp = strrchr (rp.final_map, '/'); |
437 | reference_number++); |
480 | if (!cp) |
|
|
481 | cp = rp.final_map; |
|
|
482 | } |
|
|
483 | else |
|
|
484 | { |
|
|
485 | char buf[HUGE_BUF]; |
|
|
486 | |
|
|
487 | cp = strrchr (rp.origin_map, '/'); |
|
|
488 | if (!cp) |
|
|
489 | cp = rp.origin_map; |
|
|
490 | /* Need to strip of any trailing digits, if it has them */ |
|
|
491 | strcpy (buf, cp); |
|
|
492 | while (isdigit (buf[strlen (buf) - 1])) |
|
|
493 | buf[strlen (buf) - 1] = 0; |
|
|
494 | cp = buf; |
|
|
495 | } |
|
|
496 | |
|
|
497 | sprintf (newmap_name, "/random/%s%04d", cp + 1, reference_number++); |
|
|
498 | |
438 | |
499 | /* now to generate the actual map. */ |
439 | /* now to generate the actual map. */ |
500 | new_map = generate_random_map (newmap_name, &rp); |
440 | new_map = generate_random_map (newmap_name, &rp); |
501 | |
441 | |
502 | /* Update the exit_ob so it now points directly at the newly created |
442 | /* Update the exit_ob so it now points directly at the newly created |
… | |
… | |
507 | */ |
447 | */ |
508 | if (new_map) |
448 | if (new_map) |
509 | { |
449 | { |
510 | int x, y; |
450 | int x, y; |
511 | |
451 | |
512 | x = EXIT_X (exit_ob) = MAP_ENTER_X (new_map); |
452 | x = EXIT_X (exit_ob) = new_map->enter_x; |
513 | y = EXIT_Y (exit_ob) = MAP_ENTER_Y (new_map); |
453 | y = EXIT_Y (exit_ob) = new_map->enter_y; |
514 | EXIT_PATH (exit_ob) = newmap_name; |
454 | EXIT_PATH (exit_ob) = newmap_name; |
515 | strcpy (new_map->path, newmap_name); |
455 | strcpy (new_map->path, newmap_name); |
516 | enter_map (pl, new_map, x, y); |
456 | enter_map (pl, new_map, x, y); |
517 | } |
457 | } |
518 | } |
458 | } |
… | |
… | |
522 | */ |
462 | */ |
523 | |
463 | |
524 | static void |
464 | static void |
525 | enter_fixed_template_map (object *pl, object *exit_ob) |
465 | enter_fixed_template_map (object *pl, object *exit_ob) |
526 | { |
466 | { |
527 | mapstruct *new_map; |
467 | maptile *new_map; |
528 | char tmpnum[32], exitpath[HUGE_BUF], resultname[HUGE_BUF], tmpstring[HUGE_BUF], *sourcemap; |
468 | char tmpnum[32], exitpath[HUGE_BUF], resultname[HUGE_BUF], tmpstring[HUGE_BUF], *sourcemap; |
529 | const char *new_map_name; |
469 | const char *new_map_name; |
530 | |
470 | |
531 | /* Split the exit path string into two parts, one |
471 | /* Split the exit path string into two parts, one |
532 | * for where to store the map, and one for were |
472 | * for where to store the map, and one for were |
… | |
… | |
541 | */ |
481 | */ |
542 | LOG (llevError, "enter_fixed_template_map: Exit %s (%d,%d) on map %s has no source template.\n", |
482 | LOG (llevError, "enter_fixed_template_map: Exit %s (%d,%d) on map %s has no source template.\n", |
543 | &exit_ob->name, exit_ob->x, exit_ob->y, exit_ob->map->path); |
483 | &exit_ob->name, exit_ob->x, exit_ob->y, exit_ob->map->path); |
544 | return; |
484 | return; |
545 | } |
485 | } |
|
|
486 | |
546 | *sourcemap++ = '\0'; |
487 | *sourcemap++ = '\0'; |
547 | |
488 | |
548 | /* If we are not coming from a template map, we can use relative directories |
489 | /* If we are not coming from a template map, we can use relative directories |
549 | * for the map to generate from. |
490 | * for the map to generate from. |
550 | */ |
491 | */ |
551 | if (!exit_ob->map->templatemap) |
492 | if (!exit_ob->map->templatemap) |
552 | { |
|
|
553 | sourcemap = path_combine_and_normalize (exit_ob->map->path, sourcemap); |
493 | sourcemap = path_combine_and_normalize (exit_ob->map->path, sourcemap); |
554 | } |
|
|
555 | |
494 | |
556 | /* Do replacement of %x, %y, and %n to the x coord of the exit, the y coord |
495 | /* Do replacement of %x, %y, and %n to the x coord of the exit, the y coord |
557 | * of the exit, and the name of the map the exit is on, respectively. |
496 | * of the exit, and the name of the map the exit is on, respectively. |
558 | */ |
497 | */ |
559 | sprintf (tmpnum, "%d", exit_ob->x); |
498 | sprintf (tmpnum, "%d", exit_ob->x); |
… | |
… | |
568 | |
507 | |
569 | /* If we are coming from another template map, use reletive paths unless |
508 | /* If we are coming from another template map, use reletive paths unless |
570 | * indicated otherwise. |
509 | * indicated otherwise. |
571 | */ |
510 | */ |
572 | if (exit_ob->map->templatemap && (resultname[0] != '/')) |
511 | if (exit_ob->map->templatemap && (resultname[0] != '/')) |
573 | { |
|
|
574 | new_map_name = path_combine_and_normalize (exit_ob->map->path, resultname); |
512 | new_map_name = path_combine_and_normalize (exit_ob->map->path, resultname); |
575 | } |
|
|
576 | else |
513 | else |
577 | { |
|
|
578 | new_map_name = create_template_pathname (resultname); |
514 | new_map_name = create_template_pathname (resultname); |
579 | } |
|
|
580 | |
515 | |
581 | /* Attempt to load the map, if unable to, then |
516 | /* Attempt to load the map, if unable to, then |
582 | * create the map from the template. |
517 | * create the map from the template. |
583 | */ |
518 | */ |
584 | new_map = ready_map_name (new_map_name, MAP_PLAYER_UNIQUE); |
519 | new_map = ready_map_name (new_map_name, MAP_PLAYER_UNIQUE); |
… | |
… | |
606 | LOG (llevDebug, "enter_fixed_template_map: Exit %s (%d,%d) on map %s leads no where.\n", |
541 | LOG (llevDebug, "enter_fixed_template_map: Exit %s (%d,%d) on map %s leads no where.\n", |
607 | &exit_ob->name, exit_ob->x, exit_ob->y, exit_ob->map->path); |
542 | &exit_ob->name, exit_ob->x, exit_ob->y, exit_ob->map->path); |
608 | } |
543 | } |
609 | } |
544 | } |
610 | |
545 | |
611 | |
|
|
612 | /* The player is trying to enter a randomly generated template map. In this |
546 | /* The player is trying to enter a randomly generated template map. In this |
613 | * case, generate the map as needed. |
547 | * case, generate the map as needed. |
614 | */ |
548 | */ |
615 | |
549 | |
616 | static void |
550 | static void |
617 | enter_random_template_map (object *pl, object *exit_ob) |
551 | enter_random_template_map (object *pl, object *exit_ob) |
618 | { |
552 | { |
619 | mapstruct *new_map; |
553 | maptile *new_map; |
620 | char tmpnum[32], resultname[HUGE_BUF], tmpstring[HUGE_BUF]; |
554 | char tmpnum[32], resultname[HUGE_BUF], tmpstring[HUGE_BUF]; |
621 | const char *new_map_name; |
555 | const char *new_map_name; |
622 | RMParms rp; |
556 | RMParms rp; |
623 | |
557 | |
624 | /* Do replacement of %x, %y, and %n to the x coord of the exit, the y coord |
558 | /* Do replacement of %x, %y, and %n to the x coord of the exit, the y coord |
… | |
… | |
636 | |
570 | |
637 | /* If we are coming from another template map, use reletive paths unless |
571 | /* If we are coming from another template map, use reletive paths unless |
638 | * indicated otherwise. |
572 | * indicated otherwise. |
639 | */ |
573 | */ |
640 | if (exit_ob->map->templatemap && (resultname[0] != '/')) |
574 | if (exit_ob->map->templatemap && (resultname[0] != '/')) |
641 | { |
|
|
642 | new_map_name = path_combine_and_normalize (exit_ob->map->path, resultname); |
575 | new_map_name = path_combine_and_normalize (exit_ob->map->path, resultname); |
643 | } |
|
|
644 | else |
576 | else |
645 | { |
|
|
646 | new_map_name = create_template_pathname (resultname); |
577 | new_map_name = create_template_pathname (resultname); |
647 | } |
|
|
648 | |
578 | |
649 | new_map = ready_map_name (new_map_name, MAP_PLAYER_UNIQUE); |
579 | new_map = ready_map_name (new_map_name, MAP_PLAYER_UNIQUE); |
650 | if (!new_map) |
580 | if (!new_map) |
651 | { |
581 | { |
652 | memset (&rp, 0, sizeof (RMParms)); |
582 | memset (&rp, 0, sizeof (RMParms)); |
… | |
… | |
672 | */ |
602 | */ |
673 | if (new_map) |
603 | if (new_map) |
674 | { |
604 | { |
675 | int x, y; |
605 | int x, y; |
676 | |
606 | |
677 | x = EXIT_X (exit_ob) = MAP_ENTER_X (new_map); |
607 | x = EXIT_X (exit_ob) = new_map->enter_x; |
678 | y = EXIT_Y (exit_ob) = MAP_ENTER_Y (new_map); |
608 | y = EXIT_Y (exit_ob) = new_map->enter_y; |
679 | new_map->templatemap = 1; |
609 | new_map->templatemap = 1; |
680 | enter_map (pl, new_map, x, y); |
610 | enter_map (pl, new_map, x, y); |
681 | } |
611 | } |
682 | } |
612 | } |
683 | |
613 | |
… | |
… | |
686 | */ |
616 | */ |
687 | static void |
617 | static void |
688 | enter_unique_map (object *op, object *exit_ob) |
618 | enter_unique_map (object *op, object *exit_ob) |
689 | { |
619 | { |
690 | char apartment[HUGE_BUF]; |
620 | char apartment[HUGE_BUF]; |
691 | mapstruct *newmap; |
621 | maptile *newmap; |
692 | |
622 | |
693 | if (EXIT_PATH (exit_ob)[0] == '/') |
623 | if (EXIT_PATH (exit_ob)[0] == '/') |
694 | { |
624 | { |
695 | sprintf (apartment, "%s/%s/%s/%s", settings.localdir, settings.playerdir, &op->name, clean_path (EXIT_PATH (exit_ob))); |
625 | sprintf (apartment, "%s/%s/%s/%s", settings.localdir, settings.playerdir, &op->name, clean_path (EXIT_PATH (exit_ob))); |
696 | newmap = ready_map_name (apartment, MAP_PLAYER_UNIQUE); |
626 | newmap = ready_map_name (apartment, MAP_PLAYER_UNIQUE); |
… | |
… | |
780 | #define PORTAL_DESTINATION_NAME "Town portal destination" /* this one should really be in a header file */ |
710 | #define PORTAL_DESTINATION_NAME "Town portal destination" /* this one should really be in a header file */ |
781 | object *tmp; |
711 | object *tmp; |
782 | |
712 | |
783 | /* It may be nice to support other creatures moving across |
713 | /* It may be nice to support other creatures moving across |
784 | * exits, but right now a lot of the code looks at op->contr, |
714 | * exits, but right now a lot of the code looks at op->contr, |
785 | * so thta is an RFE. |
715 | * so that is an RFE. |
786 | */ |
716 | */ |
787 | if (op->type != PLAYER) |
717 | if (op->type != PLAYER) |
788 | return; |
718 | return; |
789 | |
719 | |
790 | /* First, lets figure out what map the player is going to go to */ |
720 | /* First, lets figure out what map the player is going to go to */ |
791 | if (exit_ob) |
721 | if (exit_ob) |
792 | { |
722 | { |
793 | |
|
|
794 | /* check to see if we make a template map */ |
723 | /* check to see if we make a template map */ |
795 | if (EXIT_PATH (exit_ob) && EXIT_PATH (exit_ob)[1] == '@') |
724 | if (EXIT_PATH (exit_ob) && EXIT_PATH (exit_ob)[1] == '@') |
796 | { |
725 | { |
797 | if (EXIT_PATH (exit_ob)[2] == '!') |
726 | if (EXIT_PATH (exit_ob)[2] == '!') |
798 | { |
727 | { |
… | |
… | |
819 | int x = EXIT_X (exit_ob), y = EXIT_Y (exit_ob); |
748 | int x = EXIT_X (exit_ob), y = EXIT_Y (exit_ob); |
820 | |
749 | |
821 | /* 'Normal' exits that do not do anything special |
750 | /* 'Normal' exits that do not do anything special |
822 | * Simple enough we don't need another routine for it. |
751 | * Simple enough we don't need another routine for it. |
823 | */ |
752 | */ |
824 | mapstruct *newmap; |
753 | maptile *newmap; |
825 | |
754 | |
826 | if (exit_ob->map) |
755 | if (exit_ob->map) |
827 | { |
756 | { |
828 | newmap = ready_map_name (path_combine_and_normalize (exit_ob->map->path, EXIT_PATH (exit_ob)), 0); |
757 | newmap = ready_map_name (path_combine_and_normalize (exit_ob->map->path, EXIT_PATH (exit_ob)), 0); |
829 | /* Random map was previously generated, but is no longer about. Lets generate a new |
758 | /* Random map was previously generated, but is no longer about. Lets generate a new |
… | |
… | |
880 | * using the new maps default coordinates, the exit ob should use |
809 | * using the new maps default coordinates, the exit ob should use |
881 | * something like -1, -1 so it is clear to do that. |
810 | * something like -1, -1 so it is clear to do that. |
882 | */ |
811 | */ |
883 | if (x == 0 && y == 0) |
812 | if (x == 0 && y == 0) |
884 | { |
813 | { |
885 | x = MAP_ENTER_X (newmap); |
814 | x = newmap->enter_x; |
886 | y = MAP_ENTER_Y (newmap); |
815 | y = newmap->enter_y; |
887 | LOG (llevDebug, "enter_exit: Exit %s (%d,%d) on map %s is 0 destination coordinates\n", |
816 | LOG (llevDebug, "enter_exit: Exit %s (%d,%d) on map %s is 0 destination coordinates\n", |
888 | &exit_ob->name, exit_ob->x, exit_ob->y, exit_ob->map ? exit_ob->map->path : "<nil>"); |
817 | &exit_ob->name, exit_ob->x, exit_ob->y, exit_ob->map ? exit_ob->map->path : "<nil>"); |
889 | } |
818 | } |
890 | |
819 | |
891 | /* mids 02/13/2002 if exit is damned, update players death & WoR home-position and delete town portal */ |
820 | /* mids 02/13/2002 if exit is damned, update players death & WoR home-position and delete town portal */ |
… | |
… | |
897 | if (tmp->type == FORCE && tmp->slaying && !strcmp (tmp->slaying, PORTAL_DESTINATION_NAME)) |
826 | if (tmp->type == FORCE && tmp->slaying && !strcmp (tmp->slaying, PORTAL_DESTINATION_NAME)) |
898 | break; |
827 | break; |
899 | } |
828 | } |
900 | if (tmp) |
829 | if (tmp) |
901 | { |
830 | { |
902 | remove_ob (tmp); |
831 | tmp->remove (); |
903 | free_object (tmp); |
832 | tmp->destroy (); |
904 | } |
833 | } |
905 | |
834 | |
906 | strcpy (op->contr->savebed_map, path_combine_and_normalize (exit_ob->map->path, EXIT_PATH (exit_ob))); |
835 | strcpy (op->contr->savebed_map, path_combine_and_normalize (exit_ob->map->path, EXIT_PATH (exit_ob))); |
907 | op->contr->bed_x = EXIT_X (exit_ob), op->contr->bed_y = EXIT_Y (exit_ob); |
836 | op->contr->bed_x = EXIT_X (exit_ob), op->contr->bed_y = EXIT_Y (exit_ob); |
908 | save_player (op, 1); |
837 | op->contr->save (); |
909 | /* LOG(llevDebug,"enter_exit: Taking damned exit %s to (%d,%d) on map %s\n", |
838 | /* LOG(llevDebug,"enter_exit: Taking damned exit %s to (%d,%d) on map %s\n", |
910 | * exit_ob->name?exit_ob->name:"(none)", exit_ob->x, exit_ob->y, |
839 | * exit_ob->name?exit_ob->name:"(none)", exit_ob->x, exit_ob->y, |
911 | * path_combine_and_normalize(exit_ob->map->path, EXIT_PATH(exit_ob))); */ |
840 | * path_combine_and_normalize(exit_ob->map->path, EXIT_PATH(exit_ob))); */ |
912 | } |
841 | } |
913 | |
842 | |
… | |
… | |
918 | hit_player (op, exit_ob->stats.dam, exit_ob, exit_ob->attacktype, 1); |
847 | hit_player (op, exit_ob->stats.dam, exit_ob, exit_ob->attacktype, 1); |
919 | } |
848 | } |
920 | else |
849 | else |
921 | { |
850 | { |
922 | int flags = 0; |
851 | int flags = 0; |
923 | mapstruct *newmap; |
852 | maptile *newmap; |
924 | |
|
|
925 | |
853 | |
926 | /* Hypothetically, I guess its possible that a standard map matches |
854 | /* Hypothetically, I guess its possible that a standard map matches |
927 | * the localdir, but that seems pretty unlikely - unlikely enough that |
855 | * the localdir, but that seems pretty unlikely - unlikely enough that |
928 | * I'm not going to attempt to try to deal with that possibility. |
856 | * I'm not going to attempt to try to deal with that possibility. |
929 | * We use the fact that when a player saves on a unique map, it prepends |
857 | * We use the fact that when a player saves on a unique map, it prepends |
… | |
… | |
950 | { |
878 | { |
951 | LOG (llevError, "enter_exit: could not load emergency map? Fatal error\n"); |
879 | LOG (llevError, "enter_exit: could not load emergency map? Fatal error\n"); |
952 | abort (); |
880 | abort (); |
953 | } |
881 | } |
954 | } |
882 | } |
|
|
883 | |
955 | enter_map (op, newmap, op->x, op->y); |
884 | enter_map (op, newmap, op->x, op->y); |
956 | } |
885 | } |
957 | } |
886 | } |
958 | |
|
|
959 | /* |
|
|
960 | * process_active_maps(): Works like process_events(), but it only |
|
|
961 | * processes maps which a player is on. |
|
|
962 | * |
|
|
963 | */ |
|
|
964 | |
|
|
965 | #if 0 // dead code, schmorp |
|
|
966 | void |
|
|
967 | process_active_maps () |
|
|
968 | { |
|
|
969 | for (mapstruct *map = first_map; map != NULL; map = map->next) |
|
|
970 | if (map->in_memory == MAP_IN_MEMORY) |
|
|
971 | if (players_on_map (map, TRUE)) |
|
|
972 | process_events (map); |
|
|
973 | } |
|
|
974 | #endif |
|
|
975 | |
887 | |
976 | /* process_players1 and process_players2 do all the player related stuff. |
888 | /* process_players1 and process_players2 do all the player related stuff. |
977 | * I moved it out of process events and process_map. This was to some |
889 | * I moved it out of process events and process_map. This was to some |
978 | * extent for debugging as well as to get a better idea of the time used |
890 | * extent for debugging as well as to get a better idea of the time used |
979 | * by the various functions. process_players1() does the processing before |
891 | * by the various functions. process_players1() does the processing before |
980 | * objects have been updated, process_players2() does the processing that |
892 | * objects have been updated, process_players2() does the processing that |
981 | * is needed after the players have been updated. |
893 | * is needed after the players have been updated. |
982 | */ |
894 | */ |
983 | |
895 | static void |
984 | void |
896 | process_players1 () |
985 | process_players1 (mapstruct *map) |
|
|
986 | { |
897 | { |
987 | int flag; |
898 | int flag; |
988 | player *pl, *plnext; |
|
|
989 | |
899 | |
990 | /* Basically, we keep looping until all the players have done their actions. */ |
900 | /* Basically, we keep looping until all the players have done their actions. */ |
991 | for (flag = 1; flag != 0;) |
901 | for (flag = 1; flag != 0;) |
992 | { |
902 | { |
993 | flag = 0; |
903 | flag = 0; |
994 | for (pl = first_player; pl != NULL; pl = plnext) |
904 | for_all_players (pl) |
995 | { |
905 | { |
996 | plnext = pl->next; /* In case a player exits the game in handle_player() */ |
906 | pl->refcnt_chk (); |
997 | |
907 | |
998 | if (pl->ob == NULL) |
908 | if (!pl->ob || !pl->ns) |
999 | continue; |
909 | continue; |
1000 | |
910 | |
1001 | if (map != NULL && pl->ob->map != map) |
|
|
1002 | continue; |
|
|
1003 | |
|
|
1004 | if (pl->ob->speed_left > 0) |
911 | if (pl->ob->speed_left > 0) |
1005 | { |
|
|
1006 | if (handle_newcs_player (pl->ob)) |
912 | if (handle_newcs_player (pl->ob)) |
1007 | flag = 1; |
913 | flag = 1; |
1008 | } /* end if player has speed left */ |
|
|
1009 | |
914 | |
1010 | /* If the player is not actively playing, don't make a |
915 | /* If the player is not actively playing, don't make a |
1011 | * backup save - nothing to save anyway. Plus, the |
916 | * backup save - nothing to save anyway. Plus, the |
1012 | * map may not longer be valid. This can happen when the |
917 | * map may not longer be valid. This can happen when the |
1013 | * player quits - they exist for purposes of tracking on the map, |
918 | * player quits - they exist for purposes of tracking on the map, |
… | |
… | |
1018 | |
923 | |
1019 | #ifdef AUTOSAVE |
924 | #ifdef AUTOSAVE |
1020 | /* check for ST_PLAYING state so that we don't try to save off when |
925 | /* check for ST_PLAYING state so that we don't try to save off when |
1021 | * the player is logging in. |
926 | * the player is logging in. |
1022 | */ |
927 | */ |
1023 | if ((pl->last_save_tick + AUTOSAVE) < (uint32) pticks && pl->state == ST_PLAYING) |
928 | if ((pl->last_save_tick + AUTOSAVE) < (uint32) pticks && pl->ns->state == ST_PLAYING) |
1024 | { |
|
|
1025 | /* Don't save the player on unholy ground. Instead, increase the |
|
|
1026 | * tick time so it will be about 10 seconds before we try and save |
|
|
1027 | * again. |
|
|
1028 | */ |
929 | { |
1029 | // if (get_map_flags(pl->ob->map, NULL, pl->ob->x, pl->ob->y, NULL, NULL) & P_NO_CLERIC) { |
930 | pl->ob->contr->save (); |
1030 | // pl->last_save_tick += 100; |
|
|
1031 | // } else { |
|
|
1032 | save_player (pl->ob, 1); |
|
|
1033 | pl->last_save_tick = pticks; |
931 | pl->last_save_tick = pticks; |
1034 | // } |
|
|
1035 | } |
932 | } |
1036 | #endif |
933 | #endif |
1037 | } /* end of for loop for all the players */ |
934 | } /* end of for loop for all the players */ |
1038 | } /* for flag */ |
935 | } /* for flag */ |
1039 | for (pl = first_player; pl != NULL; pl = pl->next) |
936 | |
|
|
937 | for_all_players (pl) |
1040 | { |
938 | { |
1041 | if (map != NULL && (pl->ob == NULL || pl->ob->map != map)) |
939 | if (!pl->ob || !pl->ns) |
1042 | continue; |
940 | continue; |
|
|
941 | |
1043 | if (settings.casting_time == TRUE) |
942 | if (settings.casting_time) |
1044 | { |
943 | { |
1045 | if (pl->ob->casting_time > 0) |
944 | if (pl->ob->casting_time > 0) |
1046 | { |
945 | { |
1047 | pl->ob->casting_time--; |
946 | pl->ob->casting_time--; |
1048 | pl->ob->start_holding = 1; |
947 | pl->ob->start_holding = 1; |
1049 | } |
948 | } |
|
|
949 | |
1050 | /* set spell_state so we can update the range in stats field */ |
950 | /* set spell_state so we can update the range in stats field */ |
1051 | if ((pl->ob->casting_time == 0) && (pl->ob->start_holding == 1)) |
951 | if ((pl->ob->casting_time == 0) && (pl->ob->start_holding == 1)) |
1052 | { |
|
|
1053 | pl->ob->start_holding = 0; |
952 | pl->ob->start_holding = 0; |
1054 | } |
953 | } |
1055 | } |
954 | |
1056 | do_some_living (pl->ob); |
955 | do_some_living (pl->ob); |
1057 | /* draw(pl->ob); *//* updated in socket code */ |
|
|
1058 | } |
956 | } |
1059 | } |
957 | } |
1060 | |
958 | |
1061 | void |
959 | static void |
1062 | process_players2 (mapstruct *map) |
960 | process_players2 () |
1063 | { |
961 | { |
1064 | player *pl; |
|
|
1065 | |
|
|
1066 | /* Then check if any players should use weapon-speed instead of speed */ |
962 | /* Then check if any players should use weapon-speed instead of speed */ |
1067 | for (pl = first_player; pl != NULL; pl = pl->next) |
963 | for_all_players (pl) |
1068 | { |
964 | { |
1069 | if (map != NULL) |
|
|
1070 | { |
|
|
1071 | if (pl->ob == NULL || QUERY_FLAG (pl->ob, FLAG_REMOVED)) |
|
|
1072 | continue; |
|
|
1073 | else if (pl->loading != NULL) /* Player is blocked */ |
|
|
1074 | pl->ob->speed_left -= pl->ob->speed; |
|
|
1075 | if (pl->ob->map != map) |
|
|
1076 | continue; |
|
|
1077 | } |
|
|
1078 | |
|
|
1079 | /* The code that did weapon_sp handling here was out of place - |
965 | /* The code that did weapon_sp handling here was out of place - |
1080 | * this isn't called until after the player has finished there |
966 | * this isn't called until after the player has finished there |
1081 | * actions, and is thus out of place. All we do here is bounds |
967 | * actions, and is thus out of place. All we do here is bounds |
1082 | * checking. |
968 | * checking. |
1083 | */ |
969 | */ |
… | |
… | |
1089 | /* This needs to be here - if the player is running, we need to |
975 | /* This needs to be here - if the player is running, we need to |
1090 | * clear this each tick, but new commands are not being received |
976 | * clear this each tick, but new commands are not being received |
1091 | * so execute_newserver_command() is never called |
977 | * so execute_newserver_command() is never called |
1092 | */ |
978 | */ |
1093 | pl->has_hit = 0; |
979 | pl->has_hit = 0; |
1094 | |
|
|
1095 | } |
980 | } |
1096 | else if (pl->ob->speed_left > pl->ob->speed) |
981 | else if (pl->ob->speed_left > pl->ob->speed) |
1097 | pl->ob->speed_left = pl->ob->speed; |
982 | pl->ob->speed_left = pl->ob->speed; |
1098 | } |
983 | } |
1099 | } |
984 | } |
1100 | |
985 | |
1101 | void |
986 | void |
1102 | process_events (mapstruct *map) |
987 | process_events () |
1103 | { |
988 | { |
1104 | object *op; |
989 | object *op; |
1105 | tag_t tag; |
|
|
1106 | |
990 | |
1107 | static object *marker; |
991 | static object_ptr marker_; |
1108 | |
992 | |
1109 | if (!marker) |
993 | if (!marker_) |
1110 | marker = get_object (); |
994 | marker_ = object::create (); |
1111 | |
995 | |
|
|
996 | object *marker = marker_; |
|
|
997 | |
1112 | process_players1 (map); |
998 | process_players1 (); |
1113 | |
999 | |
1114 | marker->active_next = active_objects; |
1000 | marker->active_next = active_objects; |
1115 | |
1001 | |
1116 | if (marker->active_next) |
1002 | if (marker->active_next) |
1117 | marker->active_next->active_prev = marker; |
1003 | marker->active_next->active_prev = marker; |
1118 | |
1004 | |
1119 | marker->active_prev = NULL; |
1005 | marker->active_prev = 0; |
1120 | active_objects = marker; |
1006 | active_objects = marker; |
1121 | |
1007 | |
1122 | while (marker->active_next) |
1008 | while (marker->active_next) |
1123 | { |
1009 | { |
1124 | op = marker->active_next; |
1010 | op = marker->active_next; |
1125 | tag = op->count; |
|
|
1126 | |
1011 | |
1127 | /* Move marker forward - swap op and marker */ |
1012 | /* Move marker forward - swap op and marker */ |
1128 | op->active_prev = marker->active_prev; |
1013 | op->active_prev = marker->active_prev; |
1129 | |
1014 | |
1130 | if (op->active_prev) |
1015 | if (op->active_prev) |
… | |
… | |
1142 | |
1027 | |
1143 | /* Now process op */ |
1028 | /* Now process op */ |
1144 | if (QUERY_FLAG (op, FLAG_FREED)) |
1029 | if (QUERY_FLAG (op, FLAG_FREED)) |
1145 | { |
1030 | { |
1146 | LOG (llevError, "BUG: process_events(): Free object on list\n"); |
1031 | LOG (llevError, "BUG: process_events(): Free object on list\n"); |
1147 | op->speed = 0; |
1032 | op->set_speed (0); |
1148 | update_ob_speed (op); |
|
|
1149 | continue; |
1033 | continue; |
1150 | } |
1034 | } |
1151 | |
1035 | |
1152 | /* I've seen occasional crashes due to this - the object is removed, |
1036 | /* I've seen occasional crashes due to this - the object is removed, |
1153 | * and thus the map it points to (last map it was on) may be bogus |
1037 | * and thus the map it points to (last map it was on) may be bogus |
… | |
… | |
1160 | * around. |
1044 | * around. |
1161 | */ |
1045 | */ |
1162 | if (QUERY_FLAG (op, FLAG_REMOVED) && op->type != PLAYER && op->map && op->map->in_memory != MAP_IN_MEMORY) |
1046 | if (QUERY_FLAG (op, FLAG_REMOVED) && op->type != PLAYER && op->map && op->map->in_memory != MAP_IN_MEMORY) |
1163 | { |
1047 | { |
1164 | LOG (llevError, "BUG: process_events(): Removed object on list\n"); |
1048 | LOG (llevError, "BUG: process_events(): Removed object on list\n"); |
1165 | dump_object (op); |
1049 | char *dump = dump_object (op); |
1166 | LOG (llevError, errmsg); |
1050 | LOG (llevError, dump); |
1167 | free_object (op); |
1051 | free (dump); |
|
|
1052 | op->destroy (); |
1168 | continue; |
1053 | continue; |
1169 | } |
1054 | } |
1170 | |
1055 | |
1171 | if (!op->speed) |
1056 | if (!op->speed) |
1172 | { |
1057 | { |
1173 | LOG (llevError, "BUG: process_events(): Object %s has no speed, " "but is on active list\n", &op->arch->name); |
1058 | LOG (llevError, "BUG: process_events(): Object %s has no speed, " |
1174 | update_ob_speed (op); |
1059 | "but is on active list\n", &op->arch->name); |
|
|
1060 | op->set_speed (0); |
1175 | continue; |
1061 | continue; |
1176 | } |
1062 | } |
1177 | |
1063 | |
1178 | if (op->map == NULL && op->env == NULL && op->name && op->type != MAP && map == NULL) |
1064 | if (op->map == NULL && op->env == NULL && op->name && op->type != MAP) |
1179 | { |
1065 | { |
1180 | LOG (llevError, "BUG: process_events(): Object without map or " "inventory is on active list: %s (%d)\n", &op->name, op->count); |
1066 | LOG (llevError, "BUG: process_events(): Object without map or " |
|
|
1067 | "inventory is on active list: %s (%d)\n", &op->name, op->count); |
1181 | op->speed = 0; |
1068 | op->set_speed (0); |
1182 | update_ob_speed (op); |
|
|
1183 | continue; |
1069 | continue; |
1184 | } |
1070 | } |
1185 | |
1071 | |
1186 | if (map != NULL && op->map != map) |
|
|
1187 | continue; |
|
|
1188 | |
|
|
1189 | /* Animate the object. Bug of feature that andim_speed |
1072 | /* Animate the object. Bug or feature that anim_speed |
1190 | * is based on ticks, and not the creatures speed? |
1073 | * is based on ticks, and not the creatures speed? |
1191 | */ |
1074 | */ |
1192 | if (op->anim_speed && op->last_anim >= op->anim_speed) |
1075 | if (op->anim_speed && op->last_anim >= op->anim_speed) |
1193 | { |
1076 | { |
1194 | if ((op->type == PLAYER) || (op->type == MONSTER)) |
1077 | if ((op->type == PLAYER)) |
1195 | animate_object (op, op->facing); |
1078 | animate_object (op, op->facing); |
1196 | else |
1079 | else |
1197 | animate_object (op, op->direction); |
1080 | animate_object (op, op->direction); |
1198 | |
1081 | |
1199 | op->last_anim = 1; |
1082 | op->last_anim = 1; |
… | |
… | |
1217 | LOG (llevDebug, "process_events: calling process_object with removed object %s\n", op->name ? op->name : "null"); |
1100 | LOG (llevDebug, "process_events: calling process_object with removed object %s\n", op->name ? op->name : "null"); |
1218 | } |
1101 | } |
1219 | #endif |
1102 | #endif |
1220 | --op->speed_left; |
1103 | --op->speed_left; |
1221 | process_object (op); |
1104 | process_object (op); |
|
|
1105 | |
1222 | if (was_destroyed (op, tag)) |
1106 | if (op->destroyed ()) |
1223 | continue; |
1107 | continue; |
1224 | } |
1108 | } |
|
|
1109 | |
1225 | if (settings.casting_time == TRUE && op->casting_time > 0) |
1110 | if (settings.casting_time == TRUE && op->casting_time > 0) |
1226 | op->casting_time--; |
1111 | op->casting_time--; |
|
|
1112 | |
1227 | if (op->speed_left <= 0) |
1113 | if (op->speed_left <= 0) |
1228 | op->speed_left += FABS (op->speed); |
1114 | op->speed_left += FABS (op->speed); |
1229 | } |
1115 | } |
1230 | |
1116 | |
1231 | /* Remove marker object from active list */ |
1117 | /* Remove marker object from active list */ |
1232 | if (marker->active_prev != NULL) |
1118 | if (marker->active_prev != NULL) |
1233 | marker->active_prev->active_next = NULL; |
1119 | marker->active_prev->active_next = NULL; |
1234 | else |
1120 | else |
1235 | active_objects = NULL; |
1121 | active_objects = NULL; |
1236 | |
1122 | |
1237 | process_players2 (map); |
1123 | process_players2 (); |
1238 | } |
1124 | } |
1239 | |
1125 | |
1240 | void |
1126 | void |
1241 | clean_tmp_files (void) |
1127 | clean_tmp_files (void) |
1242 | { |
1128 | { |
1243 | mapstruct *m, *next; |
1129 | maptile *m, *next; |
1244 | |
1130 | |
1245 | LOG (llevInfo, "Cleaning up...\n"); |
1131 | LOG (llevInfo, "Cleaning up...\n"); |
1246 | |
1132 | |
1247 | /* We save the maps - it may not be intuitive why, but if there are unique |
1133 | /* We save the maps - it may not be intuitive why, but if there are unique |
1248 | * items, we need to save the map so they get saved off. Perhaps we should |
1134 | * items, we need to save the map so they get saved off. Perhaps we should |
1249 | * just make a special function that only saves the unique items. |
1135 | * just make a special function that only saves the unique items. |
1250 | */ |
1136 | */ |
1251 | for (m = first_map; m != NULL; m = next) |
1137 | for (m = first_map; m; m = next) |
1252 | { |
1138 | { |
1253 | next = m->next; |
1139 | next = m->next; |
|
|
1140 | |
1254 | if (m->in_memory == MAP_IN_MEMORY) |
1141 | if (m->in_memory == MAP_IN_MEMORY) |
1255 | { |
1142 | { |
1256 | /* If we want to reuse the temp maps, swap it out (note that will also |
1143 | /* If we want to reuse the temp maps, swap it out (note that will also |
1257 | * update the log file. Otherwise, save the map (mostly for unique item |
1144 | * update the log file. |
1258 | * stuff). Note that the clean_tmp_map is called after the end of |
|
|
1259 | * the for loop but is in the #else bracket. IF we are recycling the maps, |
|
|
1260 | * we certainly don't want the temp maps removed. |
|
|
1261 | */ |
1145 | */ |
1262 | |
1146 | |
1263 | /* XXX The above comment is dead wrong */ |
|
|
1264 | if (settings.recycle_tmp_maps == TRUE) |
|
|
1265 | swap_map (m); |
1147 | swap_map (m); |
1266 | else |
|
|
1267 | { |
|
|
1268 | new_save_map (m, 0); /* note we save here into a overlay map */ |
|
|
1269 | clean_tmp_map (m); |
|
|
1270 | } |
1148 | } |
1271 | } |
|
|
1272 | } |
1149 | } |
|
|
1150 | |
1273 | write_todclock (); /* lets just write the clock here */ |
1151 | write_todclock (); /* lets just write the clock here */ |
1274 | } |
1152 | } |
1275 | |
1153 | |
1276 | /* clean up everything before exiting */ |
1154 | /* clean up everything before exiting */ |
1277 | void |
1155 | void |
1278 | cleanup (void) |
1156 | cleanup (bool make_core) |
1279 | { |
1157 | { |
1280 | LOG (llevDebug, "Cleanup called.\n"); |
1158 | LOG (llevDebug, "Cleanup called.\n"); |
|
|
1159 | |
|
|
1160 | if (init_done) |
|
|
1161 | { |
|
|
1162 | for_all_players (pl) |
|
|
1163 | pl->save (1); |
|
|
1164 | |
|
|
1165 | for_all_players (pl) |
|
|
1166 | if (!QUERY_FLAG (pl->ob, FLAG_REMOVED)) |
|
|
1167 | leave_map (pl->ob); |
|
|
1168 | |
|
|
1169 | clean_tmp_files (); |
1281 | write_book_archive (); |
1170 | write_book_archive (); |
1282 | |
1171 | |
1283 | INVOKE_GLOBAL (CLEANUP); |
1172 | INVOKE_GLOBAL (CLEANUP); |
|
|
1173 | } |
1284 | |
1174 | |
|
|
1175 | if (make_core) |
|
|
1176 | abort (); |
|
|
1177 | else |
1285 | _exit (0); |
1178 | _exit (0); |
1286 | } |
1179 | } |
1287 | |
1180 | |
1288 | void |
1181 | void |
1289 | leave (player *pl, int draw_exit) |
1182 | leave (player *pl, int draw_exit) |
1290 | { |
1183 | { |
1291 | if (pl != NULL) |
1184 | if (pl) |
1292 | { |
1185 | { |
|
|
1186 | if (pl->ob->type != DEAD_OBJECT) |
|
|
1187 | { |
|
|
1188 | /* If a hidden dm dropped connection do not create |
|
|
1189 | * inconsistencies by showing that they have left the game |
|
|
1190 | */ |
|
|
1191 | if (!(QUERY_FLAG (pl->ob, FLAG_WIZ) && pl->ob->contr->hidden) |
|
|
1192 | && draw_exit) |
|
|
1193 | { |
|
|
1194 | if (pl->ob->map) |
|
|
1195 | { |
|
|
1196 | INVOKE_PLAYER (LOGOUT, pl); |
|
|
1197 | LOG (llevInfo, "LOGOUT: Player named %s from ip %s\n", &pl->ob->name, pl->ns->host); |
|
|
1198 | } |
|
|
1199 | |
|
|
1200 | char buf[MAX_BUF]; |
|
|
1201 | |
|
|
1202 | sprintf (buf, "%s left the game.", &pl->ob->name); |
|
|
1203 | new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, 0, buf); |
|
|
1204 | } |
|
|
1205 | |
|
|
1206 | if (!QUERY_FLAG (pl->ob, FLAG_REMOVED)) |
|
|
1207 | leave_map (pl->ob); |
|
|
1208 | |
|
|
1209 | pl->ob->type = DEAD_OBJECT; /* To avoid problems with inventory window */ |
|
|
1210 | } |
|
|
1211 | |
1293 | /* We do this so that the socket handling routine can do the final |
1212 | /* We do this so that the socket handling routine can do the final |
1294 | * cleanup. We also leave that loop to actually handle the freeing |
1213 | * cleanup. We also leave that loop to actually handle the freeing |
1295 | * of the data. |
1214 | * of the data. |
1296 | */ |
1215 | */ |
1297 | if (pl->ob->type != DEAD_OBJECT) |
1216 | if (pl->ns) |
1298 | { |
1217 | pl->ns->destroy (); |
1299 | pl->socket.status = Ns_Dead; |
|
|
1300 | |
1218 | |
1301 | /* If a hidden dm dropped connection do not create |
|
|
1302 | * inconsistencies by showing that they have left the game |
|
|
1303 | */ |
|
|
1304 | if (!(QUERY_FLAG (pl->ob, FLAG_WIZ) && pl->ob->contr->hidden) |
|
|
1305 | && draw_exit && (pl->state != ST_GET_NAME && pl->state != ST_GET_PASSWORD && pl->state != ST_CONFIRM_PASSWORD)) |
|
|
1306 | { |
|
|
1307 | if (pl->ob->map) |
|
|
1308 | { |
|
|
1309 | INVOKE_PLAYER (LOGOUT, pl); |
|
|
1310 | LOG (llevInfo, "LOGOUT: Player named %s from ip %s\n", &pl->ob->name, pl->socket.host); |
|
|
1311 | } |
|
|
1312 | |
|
|
1313 | char buf[MAX_BUF]; |
|
|
1314 | |
|
|
1315 | sprintf (buf, "%s left the game.", &pl->ob->name); |
|
|
1316 | new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, buf); |
|
|
1317 | } |
|
|
1318 | |
|
|
1319 | if (!QUERY_FLAG (pl->ob, FLAG_REMOVED)) |
|
|
1320 | leave_map (pl->ob); |
|
|
1321 | |
|
|
1322 | pl->ob->type = DEAD_OBJECT; /* To avoid problems with inventory window */ |
|
|
1323 | } |
|
|
1324 | } |
1219 | } |
1325 | } |
1220 | } |
1326 | |
1221 | |
1327 | int |
1222 | int |
1328 | forbid_play (void) |
1223 | forbid_play (void) |
… | |
… | |
1391 | extern unsigned long todtick; |
1286 | extern unsigned long todtick; |
1392 | |
1287 | |
1393 | void |
1288 | void |
1394 | do_specials (void) |
1289 | do_specials (void) |
1395 | { |
1290 | { |
1396 | |
|
|
1397 | #ifdef WATCHDOG |
|
|
1398 | if (!(pticks % 503)) |
|
|
1399 | watchdog (); |
|
|
1400 | #endif |
|
|
1401 | |
|
|
1402 | if (!(pticks % PTICKS_PER_CLOCK)) |
1291 | if (!(pticks % PTICKS_PER_CLOCK)) |
1403 | tick_the_clock (); |
1292 | tick_the_clock (); |
1404 | |
1293 | |
1405 | if (!(pticks % 7)) |
1294 | if (!(pticks % 7)) |
1406 | shstr::gc (); |
1295 | shstr::gc (); |
… | |
… | |
1409 | flush_old_maps (); /* Clears the tmp-files of maps which have reset */ |
1298 | flush_old_maps (); /* Clears the tmp-files of maps which have reset */ |
1410 | |
1299 | |
1411 | if (!(pticks % 2503)) |
1300 | if (!(pticks % 2503)) |
1412 | fix_weight (); /* Hack to fix weightproblems caused by bugs */ |
1301 | fix_weight (); /* Hack to fix weightproblems caused by bugs */ |
1413 | |
1302 | |
1414 | if (!(pticks % 2521)) |
|
|
1415 | metaserver_update (); /* 2500 ticks is about 5 minutes */ |
|
|
1416 | |
|
|
1417 | if (!(pticks % 5003)) |
1303 | if (!(pticks % 5003)) |
1418 | write_book_archive (); |
1304 | write_book_archive (); |
1419 | |
1305 | |
1420 | if (!(pticks % 5009)) |
1306 | if (!(pticks % 5009)) |
1421 | clean_friendly_list (); |
1307 | clean_friendly_list (); |
… | |
… | |
1430 | void |
1316 | void |
1431 | server_tick () |
1317 | server_tick () |
1432 | { |
1318 | { |
1433 | nroferrors = 0; |
1319 | nroferrors = 0; |
1434 | |
1320 | |
|
|
1321 | // first do the user visible stuff |
1435 | doeric_server (); |
1322 | doeric_server (); |
1436 | INVOKE_GLOBAL (CLOCK); |
1323 | INVOKE_GLOBAL (CLOCK); |
1437 | process_events (NULL); /* "do" something with objects with speed */ |
1324 | process_events (); /* "do" something with objects with speed */ |
1438 | flush_sockets (); |
1325 | flush_sockets (); |
|
|
1326 | |
|
|
1327 | // then do some bookkeeping, should not really be here |
1439 | check_active_maps (); /* Removes unused maps after a certain timeout */ |
1328 | check_active_maps (); /* Removes unused maps after a certain timeout */ |
1440 | do_specials (); /* Routines called from time to time. */ |
1329 | do_specials (); /* Routines called from time to time. */ |
1441 | object::free_mortals (); |
1330 | attachable::check_mortals (); |
1442 | |
1331 | |
1443 | ++pticks; |
1332 | ++pticks; |
1444 | } |
1333 | } |
1445 | |
1334 | |
1446 | int |
1335 | int |
1447 | main (int argc, char **argv) |
1336 | main (int argc, char **argv) |
1448 | { |
1337 | { |
1449 | settings.argc = argc; |
1338 | settings.argc = argc; |
1450 | settings.argv = argv; |
1339 | settings.argv = argv; |
1451 | |
|
|
1452 | cfperl_init (); |
|
|
1453 | |
1340 | |
1454 | init (argc, argv); |
1341 | init (argc, argv); |
1455 | |
1342 | |
1456 | initPlugins (); |
1343 | initPlugins (); |
1457 | |
1344 | |