ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/object.C
(Generate patch)

Comparing deliantra/server/common/object.C (file contents):
Revision 1.205 by root, Sun Apr 13 01:34:08 2008 UTC vs.
Revision 1.207 by root, Sun Apr 20 23:25:09 2008 UTC

22 */ 22 */
23 23
24/* Eneq(@csd.uu.se): Added weight-modifiers in environment of objects. 24/* Eneq(@csd.uu.se): Added weight-modifiers in environment of objects.
25 sub/add_weight will transcend the environment updating the carrying 25 sub/add_weight will transcend the environment updating the carrying
26 variable. */ 26 variable. */
27
27#include <global.h> 28#include <global.h>
28#include <stdio.h> 29#include <stdio.h>
29#include <sys/types.h> 30#include <sys/types.h>
30#include <sys/uio.h> 31#include <sys/uio.h>
31#include <object.h> 32#include <object.h>
326 327
327 /* Everything passes, must be OK. */ 328 /* Everything passes, must be OK. */
328 return 1; 329 return 1;
329} 330}
330 331
332static sint32
333weight_adjust (object *op, sint32 weight)
334{
335 return op->type == CONTAINER
336 ? lerp (weight, 0, 100, 0, 100 - op->stats.Str)
337 : weight;
338}
339
331/* 340/*
341 * add_weight(object, weight) adds the specified weight to an object,
342 * and also updates how much the environment(s) is/are carrying.
343 */
344static void
345add_weight (object *op, sint32 weight)
346{
347 while (op)
348 {
349 weight = weight_adjust (op, weight);
350
351 op->carrying += weight;
352 op = op->env;
353 }
354}
355
356/*
357 * sub_weight() recursively (outwards) subtracts a number from the
358 * weight of an object (and what is carried by it's environment(s)).
359 */
360static void
361sub_weight (object *op, long weight)
362{
363 add_weight (op, -weight);
364}
365
366/*
332 * sum_weight() is a recursive function which calculates the weight 367 * this is a recursive function which calculates the weight
333 * an object is carrying. It goes through in figures out how much 368 * an object is carrying. It goes through op and figures out how much
334 * containers are carrying, and sums it up. 369 * containers are carrying, and sums it up.
335 */ 370 */
336long 371void
337sum_weight (object *op) 372object::update_weight ()
338{ 373{
339 long sum; 374 sint32 sum = 0;
340 object *inv;
341 375
342 for (sum = 0, inv = op->inv; inv; inv = inv->below) 376 for (object *op = inv; op; op = op->below)
343 { 377 {
344 if (inv->inv) 378 if (op->inv)
345 sum_weight (inv); 379 op->update_weight ();
346 380
347 sum += inv->carrying + inv->weight * (inv->nrof ? inv->nrof : 1); 381 sum += op->total_weight ();
348 } 382 }
349 383
350 if (op->type == CONTAINER && op->stats.Str) 384 carrying = weight_adjust (this, sum);
351 sum = (sum * (100 - op->stats.Str)) / 100;
352
353 if (op->carrying != sum)
354 op->carrying = sum;
355
356 return sum;
357}
358
359/**
360 * Return the outermost environment object for a given object.
361 */
362
363object *
364object_get_env_recursive (object *op)
365{
366 while (op->env != NULL)
367 op = op->env;
368 return op;
369} 385}
370 386
371/* 387/*
372 * Used by: Crossedit: dump. Server DM commands: dumpbelow, dump. 388 * Used by: Crossedit: dump. Server DM commands: dumpbelow, dump.
373 * Some error messages. 389 * Some error messages.
863 * if some form of movement is allowed, let objects 879 * if some form of movement is allowed, let objects
864 * drop on that space. 880 * drop on that space.
865 */ 881 */
866 if (!drop_to_ground 882 if (!drop_to_ground
867 || !map 883 || !map
868 || map->in_memory != MAP_IN_MEMORY 884 || map->in_memory != MAP_ACTIVE
869 || map->nodrop 885 || map->nodrop
870 || ms ().move_block == MOVE_ALL) 886 || ms ().move_block == MOVE_ALL)
871 { 887 {
872 while (inv) 888 while (inv)
873 { 889 {
935 freed_map->width = 3; 951 freed_map->width = 3;
936 freed_map->height = 3; 952 freed_map->height = 3;
937 freed_map->nodrop = 1; 953 freed_map->nodrop = 1;
938 954
939 freed_map->alloc (); 955 freed_map->alloc ();
940 freed_map->in_memory = MAP_IN_MEMORY; 956 freed_map->in_memory = MAP_ACTIVE;
941 } 957 }
942 958
943 map = freed_map; 959 map = freed_map;
944 x = 1; 960 x = 1;
945 y = 1; 961 y = 1;
974 play_sound (sound_destroy); 990 play_sound (sound_destroy);
975 else if (flag [FLAG_MONSTER]) 991 else if (flag [FLAG_MONSTER])
976 play_sound (sound_find ("monster_destroy")); // quick hack, too lazy to create a generic mechanism 992 play_sound (sound_find ("monster_destroy")); // quick hack, too lazy to create a generic mechanism
977 993
978 attachable::destroy (); 994 attachable::destroy ();
979}
980
981/*
982 * sub_weight() recursively (outwards) subtracts a number from the
983 * weight of an object (and what is carried by it's environment(s)).
984 */
985void
986sub_weight (object *op, signed long weight)
987{
988 while (op != NULL)
989 {
990 if (op->type == CONTAINER)
991 weight = (signed long) (weight * (100 - op->stats.Str) / 100);
992
993 op->carrying -= weight;
994 op = op->env;
995 }
996} 995}
997 996
998/* op->remove (): 997/* op->remove ():
999 * This function removes the object op from the linked list of objects 998 * This function removes the object op from the linked list of objects
1000 * which it is currently tied to. When this function is done, the 999 * which it is currently tied to. When this function is done, the
1512 orig_ob->destroy (1); 1511 orig_ob->destroy (1);
1513 else if (!is_removed) 1512 else if (!is_removed)
1514 { 1513 {
1515 if (orig_ob->env != NULL) 1514 if (orig_ob->env != NULL)
1516 sub_weight (orig_ob->env, orig_ob->weight * nr); 1515 sub_weight (orig_ob->env, orig_ob->weight * nr);
1517 if (orig_ob->env == NULL && orig_ob->map->in_memory != MAP_IN_MEMORY) 1516 if (orig_ob->env == NULL && orig_ob->map->in_memory != MAP_ACTIVE)
1518 { 1517 {
1519 strcpy (errmsg, "Tried to split object whose map is not in memory."); 1518 strcpy (errmsg, "Tried to split object whose map is not in memory.");
1520 LOG (llevDebug, "Error, Tried to split object whose map is not in memory.\n"); 1519 LOG (llevDebug, "Error, Tried to split object whose map is not in memory.\n");
1521 return NULL; 1520 return NULL;
1522 } 1521 }
1609 return op; 1608 return op;
1610 else 1609 else
1611 { 1610 {
1612 op->destroy (); 1611 op->destroy ();
1613 return 0; 1612 return 0;
1614 }
1615}
1616
1617/*
1618 * add_weight(object, weight) adds the specified weight to an object,
1619 * and also updates how much the environment(s) is/are carrying.
1620 */
1621void
1622add_weight (object *op, signed long weight)
1623{
1624 while (op != NULL)
1625 {
1626 if (op->type == CONTAINER)
1627 weight = (signed long) (weight * (100 - op->stats.Str) / 100);
1628
1629 op->carrying += weight;
1630 op = op->env;
1631 } 1613 }
1632} 1614}
1633 1615
1634object * 1616object *
1635insert_ob_in_ob (object *op, object *where) 1617insert_ob_in_ob (object *op, object *where)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines