… | |
… | |
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) |
… | |
… | |
133 | new_draw_info (NDI_UNIQUE, 0, op, "Ctrl-R = refresh Ctrl-C = clear"); |
128 | new_draw_info (NDI_UNIQUE, 0, op, "Ctrl-R = refresh Ctrl-C = clear"); |
134 | new_draw_info (NDI_UNIQUE, 0, op, "You can type a number before most commands."); |
129 | new_draw_info (NDI_UNIQUE, 0, op, "You can type a number before most commands."); |
135 | new_draw_info (NDI_UNIQUE, 0, op, "(For instance 3d drops 3 items.)"); |
130 | new_draw_info (NDI_UNIQUE, 0, op, "(For instance 3d drops 3 items.)"); |
136 | } |
131 | } |
137 | |
132 | |
138 | void |
|
|
139 | start_info (object *op) |
|
|
140 | { |
|
|
141 | char buf[MAX_BUF]; |
|
|
142 | |
|
|
143 | sprintf (buf, "Welcome to Crossfire, v%s!", VERSION); |
|
|
144 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
|
|
145 | new_draw_info (NDI_UNIQUE, 0, op, "Press `?' for help"); |
|
|
146 | 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); |
|
|
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 | } |
|
|
187 | |
|
|
188 | /* This is a basic little function to put the player back to his |
133 | /* This is a basic little function to put the player back to his |
189 | * savebed. We do some error checking - its possible that the |
134 | * savebed. We do some error checking - its possible that the |
190 | * savebed map may no longer exist, so we make sure the player |
135 | * savebed map may no longer exist, so we make sure the player |
191 | * goes someplace. |
136 | * goes someplace. |
192 | */ |
137 | */ |
193 | void |
138 | void |
194 | enter_player_savebed (object *op) |
139 | enter_player_savebed (object *op) |
195 | { |
140 | { |
196 | mapstruct *oldmap = op->map; |
141 | maptile *oldmap = op->map; |
197 | object *tmp; |
142 | object *tmp; |
198 | |
143 | |
199 | tmp = get_object (); |
144 | tmp = object::create (); |
200 | |
145 | |
201 | EXIT_PATH (tmp) = op->contr->savebed_map; |
146 | EXIT_PATH (tmp) = op->contr->savebed_map; |
202 | EXIT_X (tmp) = op->contr->bed_x; |
147 | EXIT_X (tmp) = op->contr->bed_x; |
203 | EXIT_Y (tmp) = op->contr->bed_y; |
148 | EXIT_Y (tmp) = op->contr->bed_y; |
204 | enter_exit (op, tmp); |
149 | enter_exit (op, tmp); |
… | |
… | |
217 | EXIT_PATH (tmp) = op->contr->savebed_map; |
162 | EXIT_PATH (tmp) = op->contr->savebed_map; |
218 | EXIT_X (tmp) = op->contr->bed_x; |
163 | EXIT_X (tmp) = op->contr->bed_x; |
219 | EXIT_Y (tmp) = op->contr->bed_y; |
164 | EXIT_Y (tmp) = op->contr->bed_y; |
220 | enter_exit (op, tmp); |
165 | enter_exit (op, tmp); |
221 | } |
166 | } |
222 | free_object (tmp); |
167 | |
|
|
168 | tmp->destroy (); |
223 | } |
169 | } |
224 | |
170 | |
225 | /* All this really is is a glorified remove_object that also updates |
171 | /* All this really is is a glorified remove_object that also updates |
226 | * the counts on the map if needed. |
172 | * the counts on the map if needed. |
227 | */ |
173 | */ |
228 | void |
174 | void |
229 | leave_map (object *op) |
175 | leave_map (object *op) |
230 | { |
176 | { |
231 | mapstruct *oldmap = op->map; |
177 | maptile *oldmap = op->map; |
232 | |
178 | |
233 | remove_ob (op); |
179 | op->remove (); |
234 | |
180 | |
235 | if (oldmap) |
181 | if (oldmap) |
236 | { |
182 | { |
237 | if (!op->contr->hidden) |
183 | if (!op->contr->hidden) |
238 | oldmap->players--; |
184 | oldmap->players--; |
|
|
185 | |
239 | if (oldmap->players <= 0) |
186 | if (oldmap->players <= 0) |
240 | { /* can be less than zero due to errors in tracking this */ |
187 | /* can be less than zero due to errors in tracking this */ |
241 | set_map_timeout (oldmap); |
188 | set_map_timeout (oldmap); |
242 | } |
|
|
243 | } |
189 | } |
244 | } |
190 | } |
245 | |
191 | |
246 | /* |
192 | /* |
247 | * enter_map(): Moves the player and pets from current map (if any) to |
193 | * 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 |
195 | * 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 |
196 | * whatever reason. If default map coordinates are to be used, then |
251 | * the function that calls this should figure them out. |
197 | * the function that calls this should figure them out. |
252 | */ |
198 | */ |
253 | static void |
199 | static void |
254 | enter_map (object *op, mapstruct *newmap, int x, int y) |
200 | enter_map (object *op, maptile *newmap, int x, int y) |
255 | { |
201 | { |
256 | mapstruct *oldmap = op->map; |
202 | maptile *oldmap = op->map; |
257 | |
203 | |
258 | if (out_of_map (newmap, x, y)) |
204 | if (out_of_map (newmap, x, y)) |
259 | { |
205 | { |
260 | LOG (llevError, "enter_map: supplied coordinates are not within the map! (%s: %d, %d)\n", newmap->path, x, y); |
206 | 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); |
207 | x = newmap->enter_x; |
262 | y = MAP_ENTER_Y (newmap); |
208 | y = newmap->enter_y; |
263 | if (out_of_map (newmap, x, y)) |
209 | if (out_of_map (newmap, x, y)) |
264 | { |
210 | { |
265 | LOG (llevError, "enter_map: map %s provides invalid default enter location (%d, %d) > (%d, %d)\n", |
211 | 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)); |
212 | newmap->path, x, y, newmap->width, newmap->height); |
267 | new_draw_info (NDI_UNIQUE, 0, op, "The exit is closed"); |
213 | new_draw_info (NDI_UNIQUE, 0, op, "The exit is closed"); |
268 | return; |
214 | return; |
269 | } |
215 | } |
270 | } |
216 | } |
|
|
217 | |
271 | /* try to find a spot for the player */ |
218 | /* try to find a spot for the player */ |
272 | if (ob_blocked (op, newmap, x, y)) |
219 | if (ob_blocked (op, newmap, x, y)) |
273 | { /* First choice blocked */ |
220 | { /* First choice blocked */ |
274 | /* We try to find a spot for the player, starting closest in. |
221 | /* 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, |
222 | * We could use find_first_free_spot, but that doesn't randomize it at all, |
… | |
… | |
284 | { |
231 | { |
285 | i = find_free_spot (op, newmap, x, y, 1, SIZEOFFREE2 + 1); |
232 | i = find_free_spot (op, newmap, x, y, 1, SIZEOFFREE2 + 1); |
286 | if (i == -1) |
233 | if (i == -1) |
287 | i = find_free_spot (op, newmap, x, y, 1, SIZEOFFREE); |
234 | i = find_free_spot (op, newmap, x, y, 1, SIZEOFFREE); |
288 | } |
235 | } |
|
|
236 | |
289 | if (i != -1) |
237 | if (i != -1) |
290 | { |
238 | { |
291 | x += freearr_x[i]; |
239 | x += freearr_x[i]; |
292 | y += freearr_y[i]; |
240 | y += freearr_y[i]; |
293 | } |
241 | } |
… | |
… | |
296 | /* not much we can do in this case. */ |
244 | /* 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); |
245 | 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 | } |
246 | } |
299 | } /* end if looking for free spot */ |
247 | } /* end if looking for free spot */ |
300 | |
248 | |
301 | if (op->map != NULL) |
249 | 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)); |
250 | if (INVOKE_MAP (LEAVE, op->map, ARG_PLAYER (op->contr))) |
305 | } |
251 | return; |
|
|
252 | |
|
|
253 | if (INVOKE_PLAYER (MAP_CHANGE, op->contr, ARG_MAP (newmap), ARG_INT (x), ARG_INT (y))) |
|
|
254 | return; |
|
|
255 | |
|
|
256 | if (INVOKE_MAP (ENTER, newmap, ARG_PLAYER (op->contr), ARG_INT (x), ARG_INT (y))) |
|
|
257 | return; |
306 | |
258 | |
307 | /* If it is a player login, he has yet to be inserted anyplace. |
259 | /* If it is a player login, he has yet to be inserted anyplace. |
308 | * otherwise, we need to deal with removing the player here. |
260 | * otherwise, we need to deal with removing the player here. |
309 | */ |
261 | */ |
310 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
262 | op->remove (); |
311 | remove_ob (op); |
|
|
312 | |
263 | |
313 | /* remove_ob clears these so they must be reset after the remove_ob call */ |
264 | /* remove_ob clears these so they must be reset after the remove_ob call */ |
314 | op->x = x; |
265 | op->x = x; |
315 | op->y = y; |
266 | op->y = y; |
316 | op->map = newmap; |
267 | op->map = newmap; |
|
|
268 | |
317 | insert_ob_in_map (op, op->map, NULL, INS_NO_WALK_ON); |
269 | insert_ob_in_map (op, op->map, NULL, INS_NO_WALK_ON); |
318 | |
|
|
319 | INVOKE_MAP (ENTER, op->map, ARG_PLAYER (op->contr)); |
|
|
320 | |
270 | |
321 | if (!op->contr->hidden) |
271 | if (!op->contr->hidden) |
322 | newmap->players++; |
272 | newmap->players++; |
323 | |
273 | |
324 | newmap->timeout = 0; |
274 | newmap->timeout = 0; |
… | |
… | |
334 | if (op->type == PLAYER && op->contr->ranges[range_golem] != NULL) |
284 | if (op->type == PLAYER && op->contr->ranges[range_golem] != NULL) |
335 | { |
285 | { |
336 | int i = find_free_spot (op->contr->ranges[range_golem], newmap, |
286 | int i = find_free_spot (op->contr->ranges[range_golem], newmap, |
337 | x, y, 1, SIZEOFFREE); |
287 | x, y, 1, SIZEOFFREE); |
338 | |
288 | |
339 | remove_ob (op->contr->ranges[range_golem]); |
289 | op->contr->ranges[range_golem]->remove (); |
|
|
290 | |
340 | if (i == -1) |
291 | if (i == -1) |
341 | { |
292 | { |
342 | remove_friendly_object (op->contr->ranges[range_golem]); |
293 | remove_friendly_object (op->contr->ranges[range_golem]); |
343 | free_object (op->contr->ranges[range_golem]); |
294 | op->contr->ranges[range_golem]->destroy (); |
344 | op->contr->ranges[range_golem] = NULL; |
295 | op->contr->ranges[range_golem] = 0; |
345 | op->contr->golem_count = 0; |
|
|
346 | } |
296 | } |
347 | else |
297 | else |
348 | { |
298 | { |
349 | object *tmp; |
|
|
350 | |
|
|
351 | for (tmp = op->contr->ranges[range_golem]; tmp != NULL; tmp = tmp->more) |
299 | for (object *tmp = op->contr->ranges[range_golem]; tmp != NULL; tmp = tmp->more) |
352 | { |
300 | { |
353 | tmp->x = x + freearr_x[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x); |
301 | 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); |
302 | tmp->y = y + freearr_y[i] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y); |
355 | tmp->map = newmap; |
303 | tmp->map = newmap; |
356 | } |
304 | } |
|
|
305 | |
357 | insert_ob_in_map (op->contr->ranges[range_golem], newmap, NULL, 0); |
306 | insert_ob_in_map (op->contr->ranges[range_golem], newmap, NULL, 0); |
358 | op->contr->ranges[range_golem]->direction = |
307 | 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); |
308 | find_dir_2 (op->x - op->contr->ranges[range_golem]->x, op->y - op->contr->ranges[range_golem]->y); |
360 | } |
309 | } |
361 | } |
310 | } |
|
|
311 | |
362 | op->direction = 0; |
312 | op->direction = 0; |
363 | |
313 | |
364 | /* since the players map is already loaded, we don't need to worry |
314 | /* since the players map is already loaded, we don't need to worry |
365 | * about pending objects. |
315 | * about pending objects. |
366 | */ |
316 | */ |
… | |
… | |
381 | } |
331 | } |
382 | } |
332 | } |
383 | } |
333 | } |
384 | |
334 | |
385 | void |
335 | void |
386 | set_map_timeout (mapstruct *oldmap) |
336 | set_map_timeout (maptile *oldmap) |
387 | { |
337 | { |
388 | #if MAP_MAXTIMEOUT |
338 | #if MAP_MAXTIMEOUT |
389 | oldmap->timeout = MAP_TIMEOUT (oldmap); |
339 | oldmap->timeout = oldmap->timeout; |
390 | /* Do MINTIMEOUT first, so that MAXTIMEOUT is used if that is |
340 | /* Do MINTIMEOUT first, so that MAXTIMEOUT is used if that is |
391 | * lower than the min value. |
341 | * lower than the min value. |
392 | */ |
342 | */ |
393 | # if MAP_MINTIMEOUT |
343 | # if MAP_MINTIMEOUT |
394 | if (oldmap->timeout < MAP_MINTIMEOUT) |
344 | if (oldmap->timeout < MAP_MINTIMEOUT) |
395 | { |
|
|
396 | oldmap->timeout = MAP_MINTIMEOUT; |
345 | oldmap->timeout = MAP_MINTIMEOUT; |
397 | } |
|
|
398 | # endif |
346 | # endif |
|
|
347 | |
399 | if (oldmap->timeout > MAP_MAXTIMEOUT) |
348 | if (oldmap->timeout > MAP_MAXTIMEOUT) |
400 | { |
|
|
401 | oldmap->timeout = MAP_MAXTIMEOUT; |
349 | oldmap->timeout = MAP_MAXTIMEOUT; |
402 | } |
350 | |
403 | #else |
351 | #else |
404 | /* save out the map */ |
352 | /* save out the map */ |
405 | swap_map (oldmap); |
353 | swap_map (oldmap); |
406 | #endif /* MAP_MAXTIMEOUT */ |
354 | #endif /* MAP_MAXTIMEOUT */ |
407 | } |
355 | } |
… | |
… | |
452 | */ |
400 | */ |
453 | |
401 | |
454 | static void |
402 | static void |
455 | enter_random_map (object *pl, object *exit_ob) |
403 | enter_random_map (object *pl, object *exit_ob) |
456 | { |
404 | { |
457 | mapstruct *new_map; |
405 | maptile *new_map; |
458 | char newmap_name[HUGE_BUF], *cp; |
406 | char newmap_name[HUGE_BUF], *cp; |
459 | static int reference_number = 0; |
407 | static int reference_number = 0; |
460 | RMParms rp; |
408 | RMParms rp; |
461 | |
409 | |
462 | memset (&rp, 0, sizeof (RMParms)); |
410 | memset (&rp, 0, sizeof (RMParms)); |
… | |
… | |
469 | rp.origin_y = exit_ob->y; |
417 | rp.origin_y = exit_ob->y; |
470 | strcpy (rp.origin_map, pl->map->path); |
418 | strcpy (rp.origin_map, pl->map->path); |
471 | |
419 | |
472 | /* If we have a final_map, use it as a base name to give some clue |
420 | /* 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. |
421 | * 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 | */ |
422 | */ |
477 | if (rp.final_map[0]) |
423 | sprintf (newmap_name, "/random%s+%04d", |
478 | { |
424 | *rp.final_map ? rp.final_map : rp.origin_map, |
479 | cp = strrchr (rp.final_map, '/'); |
425 | 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 | |
426 | |
499 | /* now to generate the actual map. */ |
427 | /* now to generate the actual map. */ |
500 | new_map = generate_random_map (newmap_name, &rp); |
428 | new_map = generate_random_map (newmap_name, &rp); |
501 | |
429 | |
502 | /* Update the exit_ob so it now points directly at the newly created |
430 | /* Update the exit_ob so it now points directly at the newly created |
… | |
… | |
507 | */ |
435 | */ |
508 | if (new_map) |
436 | if (new_map) |
509 | { |
437 | { |
510 | int x, y; |
438 | int x, y; |
511 | |
439 | |
512 | x = EXIT_X (exit_ob) = MAP_ENTER_X (new_map); |
440 | x = EXIT_X (exit_ob) = new_map->enter_x; |
513 | y = EXIT_Y (exit_ob) = MAP_ENTER_Y (new_map); |
441 | y = EXIT_Y (exit_ob) = new_map->enter_y; |
514 | EXIT_PATH (exit_ob) = newmap_name; |
442 | EXIT_PATH (exit_ob) = newmap_name; |
515 | strcpy (new_map->path, newmap_name); |
443 | strcpy (new_map->path, newmap_name); |
516 | enter_map (pl, new_map, x, y); |
444 | enter_map (pl, new_map, x, y); |
517 | } |
445 | } |
518 | } |
446 | } |
… | |
… | |
522 | */ |
450 | */ |
523 | |
451 | |
524 | static void |
452 | static void |
525 | enter_fixed_template_map (object *pl, object *exit_ob) |
453 | enter_fixed_template_map (object *pl, object *exit_ob) |
526 | { |
454 | { |
527 | mapstruct *new_map; |
455 | maptile *new_map; |
528 | char tmpnum[32], exitpath[HUGE_BUF], resultname[HUGE_BUF], tmpstring[HUGE_BUF], *sourcemap; |
456 | char tmpnum[32], exitpath[HUGE_BUF], resultname[HUGE_BUF], tmpstring[HUGE_BUF], *sourcemap; |
529 | const char *new_map_name; |
457 | const char *new_map_name; |
530 | |
458 | |
531 | /* Split the exit path string into two parts, one |
459 | /* Split the exit path string into two parts, one |
532 | * for where to store the map, and one for were |
460 | * for where to store the map, and one for were |
… | |
… | |
541 | */ |
469 | */ |
542 | LOG (llevError, "enter_fixed_template_map: Exit %s (%d,%d) on map %s has no source template.\n", |
470 | 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); |
471 | &exit_ob->name, exit_ob->x, exit_ob->y, exit_ob->map->path); |
544 | return; |
472 | return; |
545 | } |
473 | } |
|
|
474 | |
546 | *sourcemap++ = '\0'; |
475 | *sourcemap++ = '\0'; |
547 | |
476 | |
548 | /* If we are not coming from a template map, we can use relative directories |
477 | /* If we are not coming from a template map, we can use relative directories |
549 | * for the map to generate from. |
478 | * for the map to generate from. |
550 | */ |
479 | */ |
551 | if (!exit_ob->map->templatemap) |
480 | if (!exit_ob->map->templatemap) |
552 | { |
|
|
553 | sourcemap = path_combine_and_normalize (exit_ob->map->path, sourcemap); |
481 | sourcemap = path_combine_and_normalize (exit_ob->map->path, sourcemap); |
554 | } |
|
|
555 | |
482 | |
556 | /* Do replacement of %x, %y, and %n to the x coord of the exit, the y coord |
483 | /* 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. |
484 | * of the exit, and the name of the map the exit is on, respectively. |
558 | */ |
485 | */ |
559 | sprintf (tmpnum, "%d", exit_ob->x); |
486 | sprintf (tmpnum, "%d", exit_ob->x); |
… | |
… | |
568 | |
495 | |
569 | /* If we are coming from another template map, use reletive paths unless |
496 | /* If we are coming from another template map, use reletive paths unless |
570 | * indicated otherwise. |
497 | * indicated otherwise. |
571 | */ |
498 | */ |
572 | if (exit_ob->map->templatemap && (resultname[0] != '/')) |
499 | if (exit_ob->map->templatemap && (resultname[0] != '/')) |
573 | { |
|
|
574 | new_map_name = path_combine_and_normalize (exit_ob->map->path, resultname); |
500 | new_map_name = path_combine_and_normalize (exit_ob->map->path, resultname); |
575 | } |
|
|
576 | else |
501 | else |
577 | { |
|
|
578 | new_map_name = create_template_pathname (resultname); |
502 | new_map_name = create_template_pathname (resultname); |
579 | } |
|
|
580 | |
503 | |
581 | /* Attempt to load the map, if unable to, then |
504 | /* Attempt to load the map, if unable to, then |
582 | * create the map from the template. |
505 | * create the map from the template. |
583 | */ |
506 | */ |
584 | new_map = ready_map_name (new_map_name, MAP_PLAYER_UNIQUE); |
507 | 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", |
529 | 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); |
530 | &exit_ob->name, exit_ob->x, exit_ob->y, exit_ob->map->path); |
608 | } |
531 | } |
609 | } |
532 | } |
610 | |
533 | |
611 | |
|
|
612 | /* The player is trying to enter a randomly generated template map. In this |
534 | /* The player is trying to enter a randomly generated template map. In this |
613 | * case, generate the map as needed. |
535 | * case, generate the map as needed. |
614 | */ |
536 | */ |
615 | |
537 | |
616 | static void |
538 | static void |
617 | enter_random_template_map (object *pl, object *exit_ob) |
539 | enter_random_template_map (object *pl, object *exit_ob) |
618 | { |
540 | { |
619 | mapstruct *new_map; |
541 | maptile *new_map; |
620 | char tmpnum[32], resultname[HUGE_BUF], tmpstring[HUGE_BUF]; |
542 | char tmpnum[32], resultname[HUGE_BUF], tmpstring[HUGE_BUF]; |
621 | const char *new_map_name; |
543 | const char *new_map_name; |
622 | RMParms rp; |
544 | RMParms rp; |
623 | |
545 | |
624 | /* Do replacement of %x, %y, and %n to the x coord of the exit, the y coord |
546 | /* Do replacement of %x, %y, and %n to the x coord of the exit, the y coord |
… | |
… | |
636 | |
558 | |
637 | /* If we are coming from another template map, use reletive paths unless |
559 | /* If we are coming from another template map, use reletive paths unless |
638 | * indicated otherwise. |
560 | * indicated otherwise. |
639 | */ |
561 | */ |
640 | if (exit_ob->map->templatemap && (resultname[0] != '/')) |
562 | if (exit_ob->map->templatemap && (resultname[0] != '/')) |
641 | { |
|
|
642 | new_map_name = path_combine_and_normalize (exit_ob->map->path, resultname); |
563 | new_map_name = path_combine_and_normalize (exit_ob->map->path, resultname); |
643 | } |
|
|
644 | else |
564 | else |
645 | { |
|
|
646 | new_map_name = create_template_pathname (resultname); |
565 | new_map_name = create_template_pathname (resultname); |
647 | } |
|
|
648 | |
566 | |
649 | new_map = ready_map_name (new_map_name, MAP_PLAYER_UNIQUE); |
567 | new_map = ready_map_name (new_map_name, MAP_PLAYER_UNIQUE); |
650 | if (!new_map) |
568 | if (!new_map) |
651 | { |
569 | { |
652 | memset (&rp, 0, sizeof (RMParms)); |
570 | memset (&rp, 0, sizeof (RMParms)); |
… | |
… | |
672 | */ |
590 | */ |
673 | if (new_map) |
591 | if (new_map) |
674 | { |
592 | { |
675 | int x, y; |
593 | int x, y; |
676 | |
594 | |
677 | x = EXIT_X (exit_ob) = MAP_ENTER_X (new_map); |
595 | x = EXIT_X (exit_ob) = new_map->enter_x; |
678 | y = EXIT_Y (exit_ob) = MAP_ENTER_Y (new_map); |
596 | y = EXIT_Y (exit_ob) = new_map->enter_y; |
679 | new_map->templatemap = 1; |
597 | new_map->templatemap = 1; |
680 | enter_map (pl, new_map, x, y); |
598 | enter_map (pl, new_map, x, y); |
681 | } |
599 | } |
682 | } |
600 | } |
683 | |
601 | |
… | |
… | |
686 | */ |
604 | */ |
687 | static void |
605 | static void |
688 | enter_unique_map (object *op, object *exit_ob) |
606 | enter_unique_map (object *op, object *exit_ob) |
689 | { |
607 | { |
690 | char apartment[HUGE_BUF]; |
608 | char apartment[HUGE_BUF]; |
691 | mapstruct *newmap; |
609 | maptile *newmap; |
692 | |
610 | |
693 | if (EXIT_PATH (exit_ob)[0] == '/') |
611 | if (EXIT_PATH (exit_ob)[0] == '/') |
694 | { |
612 | { |
695 | sprintf (apartment, "%s/%s/%s/%s", settings.localdir, settings.playerdir, &op->name, clean_path (EXIT_PATH (exit_ob))); |
613 | 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); |
614 | 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 */ |
698 | #define PORTAL_DESTINATION_NAME "Town portal destination" /* this one should really be in a header file */ |
781 | object *tmp; |
699 | object *tmp; |
782 | |
700 | |
783 | /* It may be nice to support other creatures moving across |
701 | /* It may be nice to support other creatures moving across |
784 | * exits, but right now a lot of the code looks at op->contr, |
702 | * exits, but right now a lot of the code looks at op->contr, |
785 | * so thta is an RFE. |
703 | * so that is an RFE. |
786 | */ |
704 | */ |
787 | if (op->type != PLAYER) |
705 | if (op->type != PLAYER) |
788 | return; |
706 | return; |
789 | |
707 | |
790 | /* First, lets figure out what map the player is going to go to */ |
708 | /* First, lets figure out what map the player is going to go to */ |
791 | if (exit_ob) |
709 | if (exit_ob) |
792 | { |
710 | { |
793 | |
|
|
794 | /* check to see if we make a template map */ |
711 | /* check to see if we make a template map */ |
795 | if (EXIT_PATH (exit_ob) && EXIT_PATH (exit_ob)[1] == '@') |
712 | if (EXIT_PATH (exit_ob) && EXIT_PATH (exit_ob)[1] == '@') |
796 | { |
713 | { |
797 | if (EXIT_PATH (exit_ob)[2] == '!') |
714 | if (EXIT_PATH (exit_ob)[2] == '!') |
798 | { |
715 | { |
… | |
… | |
819 | int x = EXIT_X (exit_ob), y = EXIT_Y (exit_ob); |
736 | int x = EXIT_X (exit_ob), y = EXIT_Y (exit_ob); |
820 | |
737 | |
821 | /* 'Normal' exits that do not do anything special |
738 | /* 'Normal' exits that do not do anything special |
822 | * Simple enough we don't need another routine for it. |
739 | * Simple enough we don't need another routine for it. |
823 | */ |
740 | */ |
824 | mapstruct *newmap; |
741 | maptile *newmap; |
825 | |
742 | |
826 | if (exit_ob->map) |
743 | if (exit_ob->map) |
827 | { |
744 | { |
828 | newmap = ready_map_name (path_combine_and_normalize (exit_ob->map->path, EXIT_PATH (exit_ob)), 0); |
745 | 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 |
746 | /* 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 |
797 | * using the new maps default coordinates, the exit ob should use |
881 | * something like -1, -1 so it is clear to do that. |
798 | * something like -1, -1 so it is clear to do that. |
882 | */ |
799 | */ |
883 | if (x == 0 && y == 0) |
800 | if (x == 0 && y == 0) |
884 | { |
801 | { |
885 | x = MAP_ENTER_X (newmap); |
802 | x = newmap->enter_x; |
886 | y = MAP_ENTER_Y (newmap); |
803 | y = newmap->enter_y; |
887 | LOG (llevDebug, "enter_exit: Exit %s (%d,%d) on map %s is 0 destination coordinates\n", |
804 | 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>"); |
805 | &exit_ob->name, exit_ob->x, exit_ob->y, exit_ob->map ? exit_ob->map->path : "<nil>"); |
889 | } |
806 | } |
890 | |
807 | |
891 | /* mids 02/13/2002 if exit is damned, update players death & WoR home-position and delete town portal */ |
808 | /* 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)) |
814 | if (tmp->type == FORCE && tmp->slaying && !strcmp (tmp->slaying, PORTAL_DESTINATION_NAME)) |
898 | break; |
815 | break; |
899 | } |
816 | } |
900 | if (tmp) |
817 | if (tmp) |
901 | { |
818 | { |
902 | remove_ob (tmp); |
819 | tmp->remove (); |
903 | free_object (tmp); |
820 | tmp->destroy (); |
904 | } |
821 | } |
905 | |
822 | |
906 | strcpy (op->contr->savebed_map, path_combine_and_normalize (exit_ob->map->path, EXIT_PATH (exit_ob))); |
823 | 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); |
824 | op->contr->bed_x = EXIT_X (exit_ob), op->contr->bed_y = EXIT_Y (exit_ob); |
908 | save_player (op, 1); |
825 | op->contr->save (); |
909 | /* LOG(llevDebug,"enter_exit: Taking damned exit %s to (%d,%d) on map %s\n", |
826 | /* 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, |
827 | * 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))); */ |
828 | * path_combine_and_normalize(exit_ob->map->path, EXIT_PATH(exit_ob))); */ |
912 | } |
829 | } |
913 | |
830 | |
… | |
… | |
918 | hit_player (op, exit_ob->stats.dam, exit_ob, exit_ob->attacktype, 1); |
835 | hit_player (op, exit_ob->stats.dam, exit_ob, exit_ob->attacktype, 1); |
919 | } |
836 | } |
920 | else |
837 | else |
921 | { |
838 | { |
922 | int flags = 0; |
839 | int flags = 0; |
923 | mapstruct *newmap; |
840 | maptile *newmap; |
924 | |
|
|
925 | |
841 | |
926 | /* Hypothetically, I guess its possible that a standard map matches |
842 | /* Hypothetically, I guess its possible that a standard map matches |
927 | * the localdir, but that seems pretty unlikely - unlikely enough that |
843 | * the localdir, but that seems pretty unlikely - unlikely enough that |
928 | * I'm not going to attempt to try to deal with that possibility. |
844 | * 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 |
845 | * We use the fact that when a player saves on a unique map, it prepends |
… | |
… | |
950 | { |
866 | { |
951 | LOG (llevError, "enter_exit: could not load emergency map? Fatal error\n"); |
867 | LOG (llevError, "enter_exit: could not load emergency map? Fatal error\n"); |
952 | abort (); |
868 | abort (); |
953 | } |
869 | } |
954 | } |
870 | } |
|
|
871 | |
955 | enter_map (op, newmap, op->x, op->y); |
872 | enter_map (op, newmap, op->x, op->y); |
956 | } |
873 | } |
957 | } |
874 | } |
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 | |
875 | |
976 | /* process_players1 and process_players2 do all the player related stuff. |
876 | /* 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 |
877 | * 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 |
878 | * 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 |
879 | * by the various functions. process_players1() does the processing before |
980 | * objects have been updated, process_players2() does the processing that |
880 | * objects have been updated, process_players2() does the processing that |
981 | * is needed after the players have been updated. |
881 | * is needed after the players have been updated. |
982 | */ |
882 | */ |
983 | |
883 | static void |
984 | void |
884 | process_players1 () |
985 | process_players1 (mapstruct *map) |
|
|
986 | { |
885 | { |
987 | int flag; |
886 | int flag; |
988 | player *pl, *plnext; |
|
|
989 | |
887 | |
990 | /* Basically, we keep looping until all the players have done their actions. */ |
888 | /* Basically, we keep looping until all the players have done their actions. */ |
991 | for (flag = 1; flag != 0;) |
889 | for (flag = 1; flag != 0;) |
992 | { |
890 | { |
993 | flag = 0; |
891 | flag = 0; |
994 | for (pl = first_player; pl != NULL; pl = plnext) |
892 | for_all_players (pl) |
995 | { |
893 | { |
996 | plnext = pl->next; /* In case a player exits the game in handle_player() */ |
894 | pl->refcnt_chk (); |
997 | |
895 | |
998 | if (pl->ob == NULL) |
896 | if (!pl->ob || !pl->ns) |
999 | continue; |
897 | continue; |
1000 | |
898 | |
1001 | if (map != NULL && pl->ob->map != map) |
|
|
1002 | continue; |
|
|
1003 | |
|
|
1004 | if (pl->ob->speed_left > 0) |
899 | if (pl->ob->speed_left > 0) |
1005 | { |
|
|
1006 | if (handle_newcs_player (pl->ob)) |
900 | if (handle_newcs_player (pl->ob)) |
1007 | flag = 1; |
901 | flag = 1; |
1008 | } /* end if player has speed left */ |
|
|
1009 | |
902 | |
1010 | /* If the player is not actively playing, don't make a |
903 | /* If the player is not actively playing, don't make a |
1011 | * backup save - nothing to save anyway. Plus, the |
904 | * backup save - nothing to save anyway. Plus, the |
1012 | * map may not longer be valid. This can happen when the |
905 | * map may not longer be valid. This can happen when the |
1013 | * player quits - they exist for purposes of tracking on the map, |
906 | * player quits - they exist for purposes of tracking on the map, |
… | |
… | |
1018 | |
911 | |
1019 | #ifdef AUTOSAVE |
912 | #ifdef AUTOSAVE |
1020 | /* check for ST_PLAYING state so that we don't try to save off when |
913 | /* check for ST_PLAYING state so that we don't try to save off when |
1021 | * the player is logging in. |
914 | * the player is logging in. |
1022 | */ |
915 | */ |
1023 | if ((pl->last_save_tick + AUTOSAVE) < (uint32) pticks && pl->state == ST_PLAYING) |
916 | 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 | */ |
917 | { |
1029 | // if (get_map_flags(pl->ob->map, NULL, pl->ob->x, pl->ob->y, NULL, NULL) & P_NO_CLERIC) { |
918 | pl->ob->contr->save (); |
1030 | // pl->last_save_tick += 100; |
|
|
1031 | // } else { |
|
|
1032 | save_player (pl->ob, 1); |
|
|
1033 | pl->last_save_tick = pticks; |
919 | pl->last_save_tick = pticks; |
1034 | // } |
|
|
1035 | } |
920 | } |
1036 | #endif |
921 | #endif |
1037 | } /* end of for loop for all the players */ |
922 | } /* end of for loop for all the players */ |
1038 | } /* for flag */ |
923 | } /* for flag */ |
1039 | for (pl = first_player; pl != NULL; pl = pl->next) |
924 | |
|
|
925 | for_all_players (pl) |
1040 | { |
926 | { |
1041 | if (map != NULL && (pl->ob == NULL || pl->ob->map != map)) |
927 | if (!pl->ob || !pl->ns) |
1042 | continue; |
928 | continue; |
|
|
929 | |
1043 | if (settings.casting_time == TRUE) |
930 | if (settings.casting_time) |
1044 | { |
931 | { |
1045 | if (pl->ob->casting_time > 0) |
932 | if (pl->ob->casting_time > 0) |
1046 | { |
933 | { |
1047 | pl->ob->casting_time--; |
934 | pl->ob->casting_time--; |
1048 | pl->ob->start_holding = 1; |
935 | pl->ob->start_holding = 1; |
1049 | } |
936 | } |
|
|
937 | |
1050 | /* set spell_state so we can update the range in stats field */ |
938 | /* set spell_state so we can update the range in stats field */ |
1051 | if ((pl->ob->casting_time == 0) && (pl->ob->start_holding == 1)) |
939 | if ((pl->ob->casting_time == 0) && (pl->ob->start_holding == 1)) |
1052 | { |
|
|
1053 | pl->ob->start_holding = 0; |
940 | pl->ob->start_holding = 0; |
1054 | } |
941 | } |
1055 | } |
942 | |
1056 | do_some_living (pl->ob); |
943 | do_some_living (pl->ob); |
1057 | /* draw(pl->ob); *//* updated in socket code */ |
|
|
1058 | } |
944 | } |
1059 | } |
945 | } |
1060 | |
946 | |
1061 | void |
947 | static void |
1062 | process_players2 (mapstruct *map) |
948 | process_players2 () |
1063 | { |
949 | { |
1064 | player *pl; |
|
|
1065 | |
|
|
1066 | /* Then check if any players should use weapon-speed instead of speed */ |
950 | /* Then check if any players should use weapon-speed instead of speed */ |
1067 | for (pl = first_player; pl != NULL; pl = pl->next) |
951 | for_all_players (pl) |
1068 | { |
952 | { |
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 - |
953 | /* The code that did weapon_sp handling here was out of place - |
1080 | * this isn't called until after the player has finished there |
954 | * 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 |
955 | * actions, and is thus out of place. All we do here is bounds |
1082 | * checking. |
956 | * checking. |
1083 | */ |
957 | */ |
… | |
… | |
1089 | /* This needs to be here - if the player is running, we need to |
963 | /* 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 |
964 | * clear this each tick, but new commands are not being received |
1091 | * so execute_newserver_command() is never called |
965 | * so execute_newserver_command() is never called |
1092 | */ |
966 | */ |
1093 | pl->has_hit = 0; |
967 | pl->has_hit = 0; |
1094 | |
|
|
1095 | } |
968 | } |
1096 | else if (pl->ob->speed_left > pl->ob->speed) |
969 | else if (pl->ob->speed_left > pl->ob->speed) |
1097 | pl->ob->speed_left = pl->ob->speed; |
970 | pl->ob->speed_left = pl->ob->speed; |
1098 | } |
971 | } |
1099 | } |
972 | } |
1100 | |
973 | |
1101 | void |
974 | void |
1102 | process_events (mapstruct *map) |
975 | process_events () |
1103 | { |
976 | { |
1104 | object *op; |
977 | object *op; |
1105 | |
978 | |
1106 | static object *marker; |
979 | static object_ptr marker_; |
|
|
980 | |
1107 | if (!marker) |
981 | if (!marker_) |
1108 | marker = get_object (); |
982 | marker_ = object::create (); |
1109 | |
983 | |
|
|
984 | object *marker = marker_; |
|
|
985 | |
1110 | process_players1 (map); |
986 | process_players1 (); |
1111 | |
987 | |
1112 | marker->active_next = active_objects; |
988 | marker->active_next = active_objects; |
1113 | |
989 | |
1114 | if (marker->active_next) |
990 | if (marker->active_next) |
1115 | marker->active_next->active_prev = marker; |
991 | marker->active_next->active_prev = marker; |
1116 | |
992 | |
1117 | marker->active_prev = NULL; |
993 | marker->active_prev = 0; |
1118 | active_objects = marker; |
994 | active_objects = marker; |
1119 | |
995 | |
1120 | while (marker->active_next) |
996 | while (marker->active_next) |
1121 | { |
997 | { |
1122 | op = marker->active_next; |
998 | op = marker->active_next; |
… | |
… | |
1139 | |
1015 | |
1140 | /* Now process op */ |
1016 | /* Now process op */ |
1141 | if (QUERY_FLAG (op, FLAG_FREED)) |
1017 | if (QUERY_FLAG (op, FLAG_FREED)) |
1142 | { |
1018 | { |
1143 | LOG (llevError, "BUG: process_events(): Free object on list\n"); |
1019 | LOG (llevError, "BUG: process_events(): Free object on list\n"); |
1144 | op->speed = 0; |
1020 | op->set_speed (0); |
1145 | update_ob_speed (op); |
|
|
1146 | continue; |
1021 | continue; |
1147 | } |
1022 | } |
1148 | |
1023 | |
1149 | /* I've seen occasional crashes due to this - the object is removed, |
1024 | /* I've seen occasional crashes due to this - the object is removed, |
1150 | * and thus the map it points to (last map it was on) may be bogus |
1025 | * and thus the map it points to (last map it was on) may be bogus |
… | |
… | |
1157 | * around. |
1032 | * around. |
1158 | */ |
1033 | */ |
1159 | if (QUERY_FLAG (op, FLAG_REMOVED) && op->type != PLAYER && op->map && op->map->in_memory != MAP_IN_MEMORY) |
1034 | if (QUERY_FLAG (op, FLAG_REMOVED) && op->type != PLAYER && op->map && op->map->in_memory != MAP_IN_MEMORY) |
1160 | { |
1035 | { |
1161 | LOG (llevError, "BUG: process_events(): Removed object on list\n"); |
1036 | LOG (llevError, "BUG: process_events(): Removed object on list\n"); |
1162 | dump_object (op); |
1037 | char *dump = dump_object (op); |
1163 | LOG (llevError, errmsg); |
1038 | LOG (llevError, dump); |
1164 | free_object (op); |
1039 | free (dump); |
|
|
1040 | op->destroy (); |
1165 | continue; |
1041 | continue; |
1166 | } |
1042 | } |
1167 | |
1043 | |
1168 | if (!op->speed) |
1044 | if (!op->speed) |
1169 | { |
1045 | { |
1170 | LOG (llevError, "BUG: process_events(): Object %s has no speed, " "but is on active list\n", &op->arch->name); |
1046 | LOG (llevError, "BUG: process_events(): Object %s has no speed, " |
1171 | update_ob_speed (op); |
1047 | "but is on active list\n", &op->arch->name); |
|
|
1048 | op->set_speed (0); |
1172 | continue; |
1049 | continue; |
1173 | } |
1050 | } |
1174 | |
1051 | |
1175 | if (op->map == NULL && op->env == NULL && op->name && op->type != MAP && map == NULL) |
1052 | if (op->map == NULL && op->env == NULL && op->name && op->type != MAP) |
1176 | { |
1053 | { |
1177 | LOG (llevError, "BUG: process_events(): Object without map or " "inventory is on active list: %s (%d)\n", &op->name, op->count); |
1054 | LOG (llevError, "BUG: process_events(): Object without map or " |
|
|
1055 | "inventory is on active list: %s (%d)\n", &op->name, op->count); |
1178 | op->speed = 0; |
1056 | op->set_speed (0); |
1179 | update_ob_speed (op); |
|
|
1180 | continue; |
1057 | continue; |
1181 | } |
1058 | } |
1182 | |
1059 | |
1183 | if (map != NULL && op->map != map) |
|
|
1184 | continue; |
|
|
1185 | |
|
|
1186 | /* Animate the object. Bug of feature that andim_speed |
1060 | /* Animate the object. Bug or feature that anim_speed |
1187 | * is based on ticks, and not the creatures speed? |
1061 | * is based on ticks, and not the creatures speed? |
1188 | */ |
1062 | */ |
1189 | if (op->anim_speed && op->last_anim >= op->anim_speed) |
1063 | if (op->anim_speed && op->last_anim >= op->anim_speed) |
1190 | { |
1064 | { |
1191 | if ((op->type == PLAYER) || (op->type == MONSTER)) |
1065 | if ((op->type == PLAYER)) |
1192 | animate_object (op, op->facing); |
1066 | animate_object (op, op->facing); |
1193 | else |
1067 | else |
1194 | animate_object (op, op->direction); |
1068 | animate_object (op, op->direction); |
1195 | |
1069 | |
1196 | op->last_anim = 1; |
1070 | op->last_anim = 1; |
… | |
… | |
1232 | if (marker->active_prev != NULL) |
1106 | if (marker->active_prev != NULL) |
1233 | marker->active_prev->active_next = NULL; |
1107 | marker->active_prev->active_next = NULL; |
1234 | else |
1108 | else |
1235 | active_objects = NULL; |
1109 | active_objects = NULL; |
1236 | |
1110 | |
1237 | process_players2 (map); |
1111 | process_players2 (); |
1238 | } |
1112 | } |
1239 | |
1113 | |
1240 | void |
1114 | void |
1241 | clean_tmp_files (void) |
1115 | clean_tmp_files (void) |
1242 | { |
1116 | { |
1243 | mapstruct *m, *next; |
1117 | maptile *m, *next; |
1244 | |
1118 | |
1245 | LOG (llevInfo, "Cleaning up...\n"); |
1119 | LOG (llevInfo, "Cleaning up...\n"); |
1246 | |
1120 | |
1247 | /* We save the maps - it may not be intuitive why, but if there are unique |
1121 | /* 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 |
1122 | * 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. |
1123 | * just make a special function that only saves the unique items. |
1250 | */ |
1124 | */ |
1251 | for (m = first_map; m != NULL; m = next) |
1125 | for_all_maps (m) |
1252 | { |
|
|
1253 | next = m->next; |
|
|
1254 | if (m->in_memory == MAP_IN_MEMORY) |
1126 | if (m->in_memory == MAP_IN_MEMORY) |
1255 | { |
|
|
1256 | /* If we want to reuse the temp maps, swap it out (note that will also |
1127 | /* 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 |
1128 | * 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 | */ |
1129 | */ |
1262 | |
|
|
1263 | /* XXX The above comment is dead wrong */ |
|
|
1264 | if (settings.recycle_tmp_maps == TRUE) |
|
|
1265 | swap_map (m); |
1130 | swap_map (m); |
1266 | else |
1131 | |
1267 | { |
|
|
1268 | new_save_map (m, 0); /* note we save here into a overlay map */ |
|
|
1269 | clean_tmp_map (m); |
|
|
1270 | } |
|
|
1271 | } |
|
|
1272 | } |
|
|
1273 | write_todclock (); /* lets just write the clock here */ |
1132 | write_todclock (); /* lets just write the clock here */ |
1274 | } |
1133 | } |
1275 | |
1134 | |
1276 | /* clean up everything before exiting */ |
1135 | /* clean up everything before exiting */ |
1277 | void |
1136 | void |
1278 | cleanup (void) |
1137 | cleanup (bool make_core) |
1279 | { |
1138 | { |
1280 | LOG (llevDebug, "Cleanup called.\n"); |
1139 | LOG (llevDebug, "Cleanup called.\n"); |
|
|
1140 | |
|
|
1141 | if (init_done) |
|
|
1142 | { |
|
|
1143 | for_all_players (pl) |
|
|
1144 | pl->save (1); |
|
|
1145 | |
|
|
1146 | for_all_players (pl) |
|
|
1147 | if (!QUERY_FLAG (pl->ob, FLAG_REMOVED)) |
|
|
1148 | leave_map (pl->ob); |
|
|
1149 | |
|
|
1150 | clean_tmp_files (); |
1281 | write_book_archive (); |
1151 | write_book_archive (); |
1282 | |
1152 | |
1283 | INVOKE_GLOBAL (CLEANUP); |
1153 | INVOKE_GLOBAL (CLEANUP); |
|
|
1154 | } |
1284 | |
1155 | |
|
|
1156 | if (make_core) |
|
|
1157 | abort (); |
|
|
1158 | else |
1285 | _exit (0); |
1159 | _exit (0); |
1286 | } |
1160 | } |
1287 | |
1161 | |
1288 | void |
1162 | void |
1289 | leave (player *pl, int draw_exit) |
1163 | leave (player *pl, int draw_exit) |
1290 | { |
1164 | { |
1291 | if (pl != NULL) |
1165 | if (pl) |
1292 | { |
1166 | { |
|
|
1167 | if (pl->ob->type != DEAD_OBJECT) |
|
|
1168 | { |
|
|
1169 | /* If a hidden dm dropped connection do not create |
|
|
1170 | * inconsistencies by showing that they have left the game |
|
|
1171 | */ |
|
|
1172 | if (!(QUERY_FLAG (pl->ob, FLAG_WIZ) && pl->ob->contr->hidden) |
|
|
1173 | && draw_exit) |
|
|
1174 | { |
|
|
1175 | if (pl->ob->map) |
|
|
1176 | { |
|
|
1177 | INVOKE_PLAYER (LOGOUT, pl); |
|
|
1178 | LOG (llevInfo, "LOGOUT: Player named %s from ip %s\n", &pl->ob->name, pl->ns->host); |
|
|
1179 | } |
|
|
1180 | |
|
|
1181 | char buf[MAX_BUF]; |
|
|
1182 | |
|
|
1183 | sprintf (buf, "%s left the game.", &pl->ob->name); |
|
|
1184 | new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, 0, buf); |
|
|
1185 | } |
|
|
1186 | |
|
|
1187 | if (!QUERY_FLAG (pl->ob, FLAG_REMOVED)) |
|
|
1188 | leave_map (pl->ob); |
|
|
1189 | |
|
|
1190 | pl->ob->type = DEAD_OBJECT; /* To avoid problems with inventory window */ |
|
|
1191 | } |
|
|
1192 | |
1293 | /* We do this so that the socket handling routine can do the final |
1193 | /* 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 |
1194 | * cleanup. We also leave that loop to actually handle the freeing |
1295 | * of the data. |
1195 | * of the data. |
1296 | */ |
1196 | */ |
1297 | if (pl->ob->type != DEAD_OBJECT) |
1197 | if (pl->ns) |
1298 | { |
1198 | pl->ns->destroy (); |
1299 | pl->socket.status = Ns_Dead; |
|
|
1300 | |
1199 | |
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 | } |
1200 | } |
1325 | } |
1201 | } |
1326 | |
1202 | |
1327 | int |
1203 | int |
1328 | forbid_play (void) |
1204 | forbid_play (void) |
… | |
… | |
1391 | extern unsigned long todtick; |
1267 | extern unsigned long todtick; |
1392 | |
1268 | |
1393 | void |
1269 | void |
1394 | do_specials (void) |
1270 | do_specials (void) |
1395 | { |
1271 | { |
1396 | |
|
|
1397 | #ifdef WATCHDOG |
|
|
1398 | if (!(pticks % 503)) |
|
|
1399 | watchdog (); |
|
|
1400 | #endif |
|
|
1401 | |
|
|
1402 | if (!(pticks % PTICKS_PER_CLOCK)) |
1272 | if (!(pticks % PTICKS_PER_CLOCK)) |
1403 | tick_the_clock (); |
1273 | tick_the_clock (); |
1404 | |
1274 | |
1405 | if (!(pticks % 7)) |
1275 | if (!(pticks % 7)) |
1406 | shstr::gc (); |
1276 | shstr::gc (); |
… | |
… | |
1409 | flush_old_maps (); /* Clears the tmp-files of maps which have reset */ |
1279 | flush_old_maps (); /* Clears the tmp-files of maps which have reset */ |
1410 | |
1280 | |
1411 | if (!(pticks % 2503)) |
1281 | if (!(pticks % 2503)) |
1412 | fix_weight (); /* Hack to fix weightproblems caused by bugs */ |
1282 | fix_weight (); /* Hack to fix weightproblems caused by bugs */ |
1413 | |
1283 | |
1414 | if (!(pticks % 2521)) |
|
|
1415 | metaserver_update (); /* 2500 ticks is about 5 minutes */ |
|
|
1416 | |
|
|
1417 | if (!(pticks % 5003)) |
1284 | if (!(pticks % 5003)) |
1418 | write_book_archive (); |
1285 | write_book_archive (); |
1419 | |
1286 | |
1420 | if (!(pticks % 5009)) |
1287 | if (!(pticks % 5009)) |
1421 | clean_friendly_list (); |
1288 | clean_friendly_list (); |
… | |
… | |
1430 | void |
1297 | void |
1431 | server_tick () |
1298 | server_tick () |
1432 | { |
1299 | { |
1433 | nroferrors = 0; |
1300 | nroferrors = 0; |
1434 | |
1301 | |
|
|
1302 | // first do the user visible stuff |
1435 | doeric_server (); |
1303 | doeric_server (); |
1436 | INVOKE_GLOBAL (CLOCK); |
1304 | INVOKE_GLOBAL (CLOCK); |
1437 | process_events (NULL); /* "do" something with objects with speed */ |
1305 | process_events (); /* "do" something with objects with speed */ |
1438 | flush_sockets (); |
1306 | flush_sockets (); |
|
|
1307 | |
|
|
1308 | // then do some bookkeeping, should not really be here |
1439 | check_active_maps (); /* Removes unused maps after a certain timeout */ |
1309 | check_active_maps (); /* Removes unused maps after a certain timeout */ |
1440 | do_specials (); /* Routines called from time to time. */ |
1310 | do_specials (); /* Routines called from time to time. */ |
1441 | object::free_mortals (); |
1311 | attachable::check_mortals (); |
1442 | |
1312 | |
1443 | ++pticks; |
1313 | ++pticks; |
1444 | } |
1314 | } |
1445 | |
1315 | |
1446 | int |
1316 | int |
1447 | main (int argc, char **argv) |
1317 | main (int argc, char **argv) |
1448 | { |
1318 | { |
1449 | settings.argc = argc; |
1319 | settings.argc = argc; |
1450 | settings.argv = argv; |
1320 | settings.argv = argv; |
1451 | |
|
|
1452 | cfperl_init (); |
|
|
1453 | |
1321 | |
1454 | init (argc, argv); |
1322 | init (argc, argv); |
1455 | |
1323 | |
1456 | initPlugins (); |
1324 | initPlugins (); |
1457 | |
1325 | |