… | |
… | |
357 | /* |
357 | /* |
358 | * Used by: Crossedit: dump. Server DM commands: dumpbelow, dump. |
358 | * Used by: Crossedit: dump. Server DM commands: dumpbelow, dump. |
359 | * Some error messages. |
359 | * Some error messages. |
360 | * The result of the dump is stored in the static global errmsg array. |
360 | * The result of the dump is stored in the static global errmsg array. |
361 | */ |
361 | */ |
362 | |
|
|
363 | char * |
362 | char * |
364 | dump_object (object *op) |
363 | dump_object (object *op) |
365 | { |
364 | { |
366 | if (!op) |
365 | if (!op) |
367 | return strdup ("[NULLOBJ]"); |
366 | return strdup ("[NULLOBJ]"); |
368 | |
367 | |
369 | object_freezer freezer; |
368 | object_freezer freezer; |
370 | save_object (freezer, op, 1); |
369 | op->write (freezer); |
371 | return freezer.as_string (); |
370 | return freezer.as_string (); |
372 | } |
371 | } |
373 | |
372 | |
374 | /* |
373 | /* |
375 | * get_nearest_part(multi-object, object 2) returns the part of the |
374 | * get_nearest_part(multi-object, object 2) returns the part of the |
… | |
… | |
522 | } |
521 | } |
523 | } |
522 | } |
524 | } |
523 | } |
525 | |
524 | |
526 | dst->set_speed (dst->speed); |
525 | dst->set_speed (dst->speed); |
|
|
526 | } |
|
|
527 | |
|
|
528 | void |
|
|
529 | object::instantiate () |
|
|
530 | { |
|
|
531 | if (!uuid.seq) // HACK |
|
|
532 | uuid = gen_uuid (); |
|
|
533 | |
|
|
534 | speed_left = -0.1f; |
|
|
535 | /* copy the body_info to the body_used - this is only really |
|
|
536 | * need for monsters, but doesn't hurt to do it for everything. |
|
|
537 | * by doing so, when a monster is created, it has good starting |
|
|
538 | * values for the body_used info, so when items are created |
|
|
539 | * for it, they can be properly equipped. |
|
|
540 | */ |
|
|
541 | memcpy (body_used, body_info, sizeof (body_used)); |
|
|
542 | |
|
|
543 | attachable::instantiate (); |
527 | } |
544 | } |
528 | |
545 | |
529 | object * |
546 | object * |
530 | object::clone () |
547 | object::clone () |
531 | { |
548 | { |
… | |
… | |
589 | * UP_OBJ_FACE: only the objects face has changed. |
606 | * UP_OBJ_FACE: only the objects face has changed. |
590 | */ |
607 | */ |
591 | void |
608 | void |
592 | update_object (object *op, int action) |
609 | update_object (object *op, int action) |
593 | { |
610 | { |
594 | MoveType move_on, move_off, move_block, move_slow; |
|
|
595 | |
|
|
596 | if (op == NULL) |
611 | if (op == NULL) |
597 | { |
612 | { |
598 | /* this should never happen */ |
613 | /* this should never happen */ |
599 | LOG (llevDebug, "update_object() called for NULL object.\n"); |
614 | LOG (llevDebug, "update_object() called for NULL object.\n"); |
600 | return; |
615 | return; |
… | |
… | |
819 | |
834 | |
820 | if (flag [FLAG_IS_LINKED]) |
835 | if (flag [FLAG_IS_LINKED]) |
821 | remove_button_link (this); |
836 | remove_button_link (this); |
822 | |
837 | |
823 | if (flag [FLAG_FRIENDLY]) |
838 | if (flag [FLAG_FRIENDLY]) |
|
|
839 | { |
824 | remove_friendly_object (this); |
840 | remove_friendly_object (this); |
|
|
841 | |
|
|
842 | if (type == GOLEM |
|
|
843 | && owner |
|
|
844 | && owner->type == PLAYER |
|
|
845 | && owner->contr->ranges[range_golem] == this) |
|
|
846 | owner->contr->ranges[range_golem] = 0; |
|
|
847 | } |
825 | |
848 | |
826 | if (!flag [FLAG_REMOVED]) |
849 | if (!flag [FLAG_REMOVED]) |
827 | remove (); |
850 | remove (); |
828 | |
851 | |
829 | destroy_inv (true); |
852 | destroy_inv (true); |
… | |
… | |
901 | * This function removes the object op from the linked list of objects |
924 | * This function removes the object op from the linked list of objects |
902 | * which it is currently tied to. When this function is done, the |
925 | * which it is currently tied to. When this function is done, the |
903 | * object will have no environment. If the object previously had an |
926 | * object will have no environment. If the object previously had an |
904 | * environment, the x and y coordinates will be updated to |
927 | * environment, the x and y coordinates will be updated to |
905 | * the previous environment. |
928 | * the previous environment. |
906 | * Beware: This function is called from the editor as well! |
|
|
907 | */ |
929 | */ |
908 | void |
930 | void |
909 | object::remove_slow () |
931 | object::do_remove () |
910 | { |
932 | { |
911 | object *tmp, *last = 0; |
933 | object *tmp, *last = 0; |
912 | object *otmp; |
934 | object *otmp; |
913 | |
935 | |
914 | if (QUERY_FLAG (this, FLAG_REMOVED)) |
936 | if (QUERY_FLAG (this, FLAG_REMOVED)) |
… | |
… | |
957 | } |
979 | } |
958 | else if (map) |
980 | else if (map) |
959 | { |
981 | { |
960 | if (type == PLAYER) |
982 | if (type == PLAYER) |
961 | { |
983 | { |
|
|
984 | // leaving a spot always closes any open container on the ground |
|
|
985 | if (container && !container->env) |
|
|
986 | // this causes spurious floorbox updates, but it ensures |
|
|
987 | // that the CLOSE event is being sent. |
|
|
988 | close_container (); |
|
|
989 | |
962 | --map->players; |
990 | --map->players; |
963 | map->touch (); |
991 | map->touch (); |
964 | } |
992 | } |
965 | |
993 | |
966 | map->dirty = true; |
994 | map->dirty = true; |
… | |
… | |
1401 | tmp1->x = op->x; |
1429 | tmp1->x = op->x; |
1402 | tmp1->y = op->y; |
1430 | tmp1->y = op->y; |
1403 | insert_ob_in_map (tmp1, op->map, op, 0); |
1431 | insert_ob_in_map (tmp1, op->map, op, 0); |
1404 | } |
1432 | } |
1405 | |
1433 | |
|
|
1434 | // XXX: function not returning object* |
1406 | object * |
1435 | object * |
1407 | object::insert_at (object *where, object *originator, int flags) |
1436 | object::insert_at (object *where, object *originator, int flags) |
1408 | { |
1437 | { |
1409 | where->map->insert (this, where->x, where->y, originator, flags); |
1438 | where->map->insert (this, where->x, where->y, originator, flags); |
1410 | } |
1439 | } |
… | |
… | |
1968 | } |
1997 | } |
1969 | |
1998 | |
1970 | if (!index) |
1999 | if (!index) |
1971 | return -1; |
2000 | return -1; |
1972 | |
2001 | |
1973 | return altern[RANDOM () % index]; |
2002 | return altern [rndm (index)]; |
1974 | } |
2003 | } |
1975 | |
2004 | |
1976 | /* |
2005 | /* |
1977 | * find_first_free_spot(archetype, maptile, x, y) works like |
2006 | * find_first_free_spot(archetype, maptile, x, y) works like |
1978 | * find_free_spot(), but it will search max number of squares. |
2007 | * find_free_spot(), but it will search max number of squares. |
… | |
… | |
1999 | { |
2028 | { |
2000 | arr += begin; |
2029 | arr += begin; |
2001 | end -= begin; |
2030 | end -= begin; |
2002 | |
2031 | |
2003 | while (--end) |
2032 | while (--end) |
2004 | swap (arr [end], arr [RANDOM () % (end + 1)]); |
2033 | swap (arr [end], arr [rndm (end + 1)]); |
2005 | } |
2034 | } |
2006 | |
2035 | |
2007 | /* new function to make monster searching more efficient, and effective! |
2036 | /* new function to make monster searching more efficient, and effective! |
2008 | * This basically returns a randomized array (in the passed pointer) of |
2037 | * This basically returns a randomized array (in the passed pointer) of |
2009 | * the spaces to find monsters. In this way, it won't always look for |
2038 | * the spaces to find monsters. In this way, it won't always look for |
… | |
… | |
2321 | insert_ob_in_ob (object_create_clone (item), dst); |
2350 | insert_ob_in_ob (object_create_clone (item), dst); |
2322 | |
2351 | |
2323 | return dst; |
2352 | return dst; |
2324 | } |
2353 | } |
2325 | |
2354 | |
2326 | /* GROS - Creates an object using a string representing its content. */ |
|
|
2327 | /* Basically, we save the content of the string to a temp file, then call */ |
|
|
2328 | /* load_object on it. I admit it is a highly inefficient way to make things, */ |
|
|
2329 | /* but it was simple to make and allows reusing the load_object function. */ |
|
|
2330 | /* Remember not to use load_object_str in a time-critical situation. */ |
|
|
2331 | /* Also remember that multiparts objects are not supported for now. */ |
|
|
2332 | object * |
|
|
2333 | load_object_str (const char *obstr) |
|
|
2334 | { |
|
|
2335 | object *op; |
|
|
2336 | char filename[MAX_BUF]; |
|
|
2337 | |
|
|
2338 | sprintf (filename, "%s/cfloadobstr2044", settings.tmpdir); |
|
|
2339 | |
|
|
2340 | FILE *tempfile = fopen (filename, "w"); |
|
|
2341 | |
|
|
2342 | if (tempfile == NULL) |
|
|
2343 | { |
|
|
2344 | LOG (llevError, "Error - Unable to access load object temp file\n"); |
|
|
2345 | return NULL; |
|
|
2346 | } |
|
|
2347 | |
|
|
2348 | fprintf (tempfile, obstr); |
|
|
2349 | fclose (tempfile); |
|
|
2350 | |
|
|
2351 | op = object::create (); |
|
|
2352 | |
|
|
2353 | object_thawer thawer (filename); |
|
|
2354 | |
|
|
2355 | if (thawer) |
|
|
2356 | load_object (thawer, op, 0); |
|
|
2357 | |
|
|
2358 | LOG (llevDebug, " load str completed, object=%s\n", &op->name); |
|
|
2359 | CLEAR_FLAG (op, FLAG_REMOVED); |
|
|
2360 | |
|
|
2361 | return op; |
|
|
2362 | } |
|
|
2363 | |
|
|
2364 | /* This returns the first object in who's inventory that |
2355 | /* This returns the first object in who's inventory that |
2365 | * has the same type and subtype match. |
2356 | * has the same type and subtype match. |
2366 | * returns NULL if no match. |
2357 | * returns NULL if no match. |
2367 | */ |
2358 | */ |
2368 | object * |
2359 | object * |
… | |
… | |
2571 | { |
2562 | { |
2572 | char flagdesc[512]; |
2563 | char flagdesc[512]; |
2573 | char info2[256 * 4]; |
2564 | char info2[256 * 4]; |
2574 | char *p = info; |
2565 | char *p = info; |
2575 | |
2566 | |
2576 | p += snprintf (p, 512, "{cnt:%d,uuid:<1,%" PRIx64 ">,name:\"%s\"%s%s,flags:[%s],type:%d}", |
2567 | p += snprintf (p, 512, "{cnt:%d,uuid:<1.%" PRIx64 ">,name:\"%s\"%s%s,flags:[%s],type:%d}", |
2577 | count, uuid.seq, |
2568 | count, uuid.seq, |
2578 | &name, |
2569 | &name, |
2579 | title ? "\",title:\"" : "", |
2570 | title ? "\",title:\"" : "", |
2580 | title ? (const char *)title : "", |
2571 | title ? (const char *)title : "", |
2581 | flag_desc (flagdesc, 512), type); |
2572 | flag_desc (flagdesc, 512), type); |
… | |
… | |
2601 | { |
2592 | { |
2602 | static char info[256 * 4]; |
2593 | static char info[256 * 4]; |
2603 | return debug_desc (info); |
2594 | return debug_desc (info); |
2604 | } |
2595 | } |
2605 | |
2596 | |
|
|
2597 | struct region * |
|
|
2598 | object::region () const |
|
|
2599 | { |
|
|
2600 | return map ? map->region (x, y) |
|
|
2601 | : region::default_region (); |
|
|
2602 | } |
|
|
2603 | |
|
|
2604 | const materialtype_t * |
|
|
2605 | object::dominant_material () const |
|
|
2606 | { |
|
|
2607 | if (materialtype_t *mat = name_to_material (materialname)) |
|
|
2608 | return mat; |
|
|
2609 | |
|
|
2610 | // omfg this is slow, this has to be temporary :) |
|
|
2611 | shstr unknown ("unknown"); |
|
|
2612 | |
|
|
2613 | return name_to_material (unknown); |
|
|
2614 | } |
|
|
2615 | |
|
|
2616 | void |
|
|
2617 | object::open_container (object *new_container) |
|
|
2618 | { |
|
|
2619 | if (container == new_container) |
|
|
2620 | return; |
|
|
2621 | |
|
|
2622 | if (object *old_container = container) |
|
|
2623 | { |
|
|
2624 | if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) |
|
|
2625 | return; |
|
|
2626 | |
|
|
2627 | #if 0 |
|
|
2628 | // remove the "Close old_container" object. |
|
|
2629 | if (object *closer = old_container->inv) |
|
|
2630 | if (closer->type == CLOSE_CON) |
|
|
2631 | closer->destroy (); |
|
|
2632 | #endif |
|
|
2633 | |
|
|
2634 | old_container->flag [FLAG_APPLIED] = 0; |
|
|
2635 | container = 0; |
|
|
2636 | |
|
|
2637 | esrv_update_item (UPD_FLAGS, this, old_container); |
|
|
2638 | new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); |
|
|
2639 | } |
|
|
2640 | |
|
|
2641 | if (new_container) |
|
|
2642 | { |
|
|
2643 | if (INVOKE_OBJECT (OPEN, new_container, ARG_OBJECT (this))) |
|
|
2644 | return; |
|
|
2645 | |
|
|
2646 | // TODO: this does not seem to serve any purpose anymore? |
|
|
2647 | #if 0 |
|
|
2648 | // insert the "Close Container" object. |
|
|
2649 | if (archetype *closer = new_container->other_arch) |
|
|
2650 | { |
|
|
2651 | object *closer = arch_to_object (new_container->other_arch); |
|
|
2652 | closer->flag [FLAG_NO_MAP_SAVE] = 1; |
|
|
2653 | new_container->insert (closer); |
|
|
2654 | } |
|
|
2655 | #endif |
|
|
2656 | |
|
|
2657 | new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container)); |
|
|
2658 | |
|
|
2659 | new_container->flag [FLAG_APPLIED] = 1; |
|
|
2660 | container = new_container; |
|
|
2661 | |
|
|
2662 | esrv_update_item (UPD_FLAGS, this, new_container); |
|
|
2663 | esrv_send_inventory (this, new_container); |
|
|
2664 | } |
|
|
2665 | } |
|
|
2666 | |
|
|
2667 | |