… | |
… | |
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); |
… | |
… | |
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 | */ |
929 | */ |
907 | void |
930 | void |
908 | object::remove_slow () |
931 | object::do_remove () |
909 | { |
932 | { |
910 | object *tmp, *last = 0; |
933 | object *tmp, *last = 0; |
911 | object *otmp; |
934 | object *otmp; |
912 | |
935 | |
913 | if (QUERY_FLAG (this, FLAG_REMOVED)) |
936 | if (QUERY_FLAG (this, FLAG_REMOVED)) |
… | |
… | |
956 | } |
979 | } |
957 | else if (map) |
980 | else if (map) |
958 | { |
981 | { |
959 | if (type == PLAYER) |
982 | if (type == PLAYER) |
960 | { |
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 | |
961 | --map->players; |
990 | --map->players; |
962 | map->touch (); |
991 | map->touch (); |
963 | } |
992 | } |
964 | |
993 | |
965 | map->dirty = true; |
994 | map->dirty = true; |
… | |
… | |
1260 | * looks like instead of lots of conditions here. |
1289 | * looks like instead of lots of conditions here. |
1261 | * makes things faster, and effectively the same result. |
1290 | * makes things faster, and effectively the same result. |
1262 | */ |
1291 | */ |
1263 | |
1292 | |
1264 | /* Have object 'fall below' other objects that block view. |
1293 | /* Have object 'fall below' other objects that block view. |
1265 | * Unless those objects are exits, type 66 |
1294 | * Unless those objects are exits. |
1266 | * If INS_ON_TOP is used, don't do this processing |
1295 | * If INS_ON_TOP is used, don't do this processing |
1267 | * Need to find the object that in fact blocks view, otherwise |
1296 | * Need to find the object that in fact blocks view, otherwise |
1268 | * stacking is a bit odd. |
1297 | * stacking is a bit odd. |
1269 | */ |
1298 | */ |
1270 | if (!(flag & INS_ON_TOP) |
1299 | if (!(flag & INS_ON_TOP) |
1271 | && ms.flags () & P_BLOCKSVIEW |
1300 | && ms.flags () & P_BLOCKSVIEW |
1272 | && (op->face && !op->face->visibility)) |
1301 | && (op->face && !faces [op->face].visibility)) |
1273 | { |
1302 | { |
1274 | for (last = top; last != floor; last = last->below) |
1303 | for (last = top; last != floor; last = last->below) |
1275 | if (QUERY_FLAG (last, FLAG_BLOCKSVIEW) && (last->type != EXIT)) |
1304 | if (QUERY_FLAG (last, FLAG_BLOCKSVIEW) && (last->type != EXIT)) |
1276 | break; |
1305 | break; |
1277 | |
1306 | |
… | |
… | |
1400 | tmp1->x = op->x; |
1429 | tmp1->x = op->x; |
1401 | tmp1->y = op->y; |
1430 | tmp1->y = op->y; |
1402 | insert_ob_in_map (tmp1, op->map, op, 0); |
1431 | insert_ob_in_map (tmp1, op->map, op, 0); |
1403 | } |
1432 | } |
1404 | |
1433 | |
|
|
1434 | // XXX: function not returning object* |
1405 | object * |
1435 | object * |
1406 | object::insert_at (object *where, object *originator, int flags) |
1436 | object::insert_at (object *where, object *originator, int flags) |
1407 | { |
1437 | { |
1408 | where->map->insert (this, where->x, where->y, originator, flags); |
1438 | where->map->insert (this, where->x, where->y, originator, flags); |
1409 | } |
1439 | } |
… | |
… | |
2320 | insert_ob_in_ob (object_create_clone (item), dst); |
2350 | insert_ob_in_ob (object_create_clone (item), dst); |
2321 | |
2351 | |
2322 | return dst; |
2352 | return dst; |
2323 | } |
2353 | } |
2324 | |
2354 | |
2325 | /* GROS - Creates an object using a string representing its content. */ |
|
|
2326 | /* Basically, we save the content of the string to a temp file, then call */ |
|
|
2327 | /* load_object on it. I admit it is a highly inefficient way to make things, */ |
|
|
2328 | /* but it was simple to make and allows reusing the load_object function. */ |
|
|
2329 | /* Remember not to use load_object_str in a time-critical situation. */ |
|
|
2330 | /* Also remember that multiparts objects are not supported for now. */ |
|
|
2331 | object * |
|
|
2332 | load_object_str (const char *obstr) |
|
|
2333 | { |
|
|
2334 | object *op; |
|
|
2335 | char filename[MAX_BUF]; |
|
|
2336 | |
|
|
2337 | sprintf (filename, "%s/cfloadobstr2044", settings.tmpdir); |
|
|
2338 | |
|
|
2339 | FILE *tempfile = fopen (filename, "w"); |
|
|
2340 | |
|
|
2341 | if (tempfile == NULL) |
|
|
2342 | { |
|
|
2343 | LOG (llevError, "Error - Unable to access load object temp file\n"); |
|
|
2344 | return NULL; |
|
|
2345 | } |
|
|
2346 | |
|
|
2347 | fprintf (tempfile, obstr); |
|
|
2348 | fclose (tempfile); |
|
|
2349 | |
|
|
2350 | op = object::create (); |
|
|
2351 | |
|
|
2352 | object_thawer thawer (filename); |
|
|
2353 | |
|
|
2354 | if (thawer) |
|
|
2355 | load_object (thawer, op, 0); |
|
|
2356 | |
|
|
2357 | LOG (llevDebug, " load str completed, object=%s\n", &op->name); |
|
|
2358 | CLEAR_FLAG (op, FLAG_REMOVED); |
|
|
2359 | |
|
|
2360 | return op; |
|
|
2361 | } |
|
|
2362 | |
|
|
2363 | /* This returns the first object in who's inventory that |
2355 | /* This returns the first object in who's inventory that |
2364 | * has the same type and subtype match. |
2356 | * has the same type and subtype match. |
2365 | * returns NULL if no match. |
2357 | * returns NULL if no match. |
2366 | */ |
2358 | */ |
2367 | object * |
2359 | object * |
… | |
… | |
2420 | if (link->key == canonical_key) |
2412 | if (link->key == canonical_key) |
2421 | return link->value; |
2413 | return link->value; |
2422 | |
2414 | |
2423 | return 0; |
2415 | return 0; |
2424 | } |
2416 | } |
2425 | |
|
|
2426 | |
2417 | |
2427 | /* |
2418 | /* |
2428 | * Updates the canonical_key in op to value. |
2419 | * Updates the canonical_key in op to value. |
2429 | * |
2420 | * |
2430 | * canonical_key is a shared string (value doesn't have to be). |
2421 | * canonical_key is a shared string (value doesn't have to be). |
… | |
… | |
2570 | { |
2561 | { |
2571 | char flagdesc[512]; |
2562 | char flagdesc[512]; |
2572 | char info2[256 * 4]; |
2563 | char info2[256 * 4]; |
2573 | char *p = info; |
2564 | char *p = info; |
2574 | |
2565 | |
2575 | p += snprintf (p, 512, "{cnt:%d,uuid:<1,%" PRIx64 ">,name:\"%s\"%s%s,flags:[%s],type:%d}", |
2566 | p += snprintf (p, 512, "{cnt:%d,uuid:<1.%" PRIx64 ">,name:\"%s\"%s%s,flags:[%s],type:%d}", |
2576 | count, uuid.seq, |
2567 | count, uuid.seq, |
2577 | &name, |
2568 | &name, |
2578 | title ? "\",title:\"" : "", |
2569 | title ? "\",title:\"" : "", |
2579 | title ? (const char *)title : "", |
2570 | title ? (const char *)title : "", |
2580 | flag_desc (flagdesc, 512), type); |
2571 | flag_desc (flagdesc, 512), type); |
… | |
… | |
2607 | { |
2598 | { |
2608 | return map ? map->region (x, y) |
2599 | return map ? map->region (x, y) |
2609 | : region::default_region (); |
2600 | : region::default_region (); |
2610 | } |
2601 | } |
2611 | |
2602 | |
|
|
2603 | const materialtype_t * |
|
|
2604 | object::dominant_material () const |
|
|
2605 | { |
|
|
2606 | if (materialtype_t *mat = name_to_material (materialname)) |
|
|
2607 | return mat; |
|
|
2608 | |
|
|
2609 | // omfg this is slow, this has to be temporary :) |
|
|
2610 | shstr unknown ("unknown"); |
|
|
2611 | |
|
|
2612 | return name_to_material (unknown); |
|
|
2613 | } |
|
|
2614 | |
|
|
2615 | void |
|
|
2616 | object::open_container (object *new_container) |
|
|
2617 | { |
|
|
2618 | if (container == new_container) |
|
|
2619 | return; |
|
|
2620 | |
|
|
2621 | if (object *old_container = container) |
|
|
2622 | { |
|
|
2623 | if (INVOKE_OBJECT (CLOSE, old_container, ARG_OBJECT (this))) |
|
|
2624 | return; |
|
|
2625 | |
|
|
2626 | #if 0 |
|
|
2627 | // remove the "Close old_container" object. |
|
|
2628 | if (object *closer = old_container->inv) |
|
|
2629 | if (closer->type == CLOSE_CON) |
|
|
2630 | closer->destroy (); |
|
|
2631 | #endif |
|
|
2632 | |
|
|
2633 | old_container->flag [FLAG_APPLIED] = 0; |
|
|
2634 | container = 0; |
|
|
2635 | |
|
|
2636 | esrv_update_item (UPD_FLAGS, this, old_container); |
|
|
2637 | new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); |
|
|
2638 | } |
|
|
2639 | |
|
|
2640 | if (new_container) |
|
|
2641 | { |
|
|
2642 | if (INVOKE_OBJECT (OPEN, new_container, ARG_OBJECT (this))) |
|
|
2643 | return; |
|
|
2644 | |
|
|
2645 | // TODO: this does not seem to serve any purpose anymore? |
|
|
2646 | #if 0 |
|
|
2647 | // insert the "Close Container" object. |
|
|
2648 | if (archetype *closer = new_container->other_arch) |
|
|
2649 | { |
|
|
2650 | object *closer = arch_to_object (new_container->other_arch); |
|
|
2651 | closer->flag [FLAG_NO_MAP_SAVE] = 1; |
|
|
2652 | new_container->insert (closer); |
|
|
2653 | } |
|
|
2654 | #endif |
|
|
2655 | |
|
|
2656 | new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container)); |
|
|
2657 | |
|
|
2658 | new_container->flag [FLAG_APPLIED] = 1; |
|
|
2659 | container = new_container; |
|
|
2660 | |
|
|
2661 | esrv_update_item (UPD_FLAGS, this, new_container); |
|
|
2662 | esrv_send_inventory (this, new_container); |
|
|
2663 | } |
|
|
2664 | } |
|
|
2665 | |
|
|
2666 | |