1 | |
|
|
2 | /* |
1 | /* |
3 | CrossFire, A Multiplayer game for X-windows |
2 | CrossFire, A Multiplayer game for X-windows |
4 | |
3 | |
5 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
4 | Copyright (C) 2001 Mark Wedel & Crossfire Development Team |
6 | Copyright (C) 1992 Frank Tore Johansen |
5 | Copyright (C) 1992 Frank Tore Johansen |
… | |
… | |
17 | |
16 | |
18 | You should have received a copy of the GNU General Public License |
17 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
18 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
21 | |
20 | |
22 | The authors can be reached via e-mail at crossfire-devel@real-time.com |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
23 | */ |
22 | */ |
24 | |
23 | |
25 | /* Eneq(@csd.uu.se): Added weight-modifiers in environment of objects. |
24 | /* Eneq(@csd.uu.se): Added weight-modifiers in environment of objects. |
26 | sub/add_weight will transcend the environment updating the carrying |
25 | sub/add_weight will transcend the environment updating the carrying |
27 | variable. */ |
26 | variable. */ |
… | |
… | |
35 | |
34 | |
36 | int nrofallocobjects = 0; |
35 | int nrofallocobjects = 0; |
37 | static UUID uuid; |
36 | static UUID uuid; |
38 | const uint64 UUID_SKIP = 1<<19; |
37 | const uint64 UUID_SKIP = 1<<19; |
39 | |
38 | |
40 | object *objects; /* Pointer to the list of used objects */ |
|
|
41 | object *active_objects; /* List of active objects that need to be processed */ |
39 | object *active_objects; /* List of active objects that need to be processed */ |
42 | |
40 | |
43 | short freearr_x[SIZEOFFREE] = { 0, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1, |
41 | short freearr_x[SIZEOFFREE] = { 0, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1, |
44 | 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -3, -3, -3, -3, -2, -1 |
42 | 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -3, -3, -3, -3, -2, -1 |
45 | }; |
43 | }; |
… | |
… | |
447 | void |
445 | void |
448 | dump_all_objects (void) |
446 | dump_all_objects (void) |
449 | { |
447 | { |
450 | object *op; |
448 | object *op; |
451 | |
449 | |
452 | for (op = objects; op != NULL; op = op->next) |
450 | for (op = object::first; op != NULL; op = op->next) |
453 | { |
451 | { |
454 | dump_object (op); |
452 | dump_object (op); |
455 | fprintf (logfile, "Object %d\n:%s\n", op->count, errmsg); |
453 | fprintf (logfile, "Object %d\n:%s\n", op->count, errmsg); |
456 | } |
454 | } |
457 | } |
455 | } |
… | |
… | |
483 | object * |
481 | object * |
484 | find_object (tag_t i) |
482 | find_object (tag_t i) |
485 | { |
483 | { |
486 | object *op; |
484 | object *op; |
487 | |
485 | |
488 | for (op = objects; op != NULL; op = op->next) |
486 | for (op = object::first; op != NULL; op = op->next) |
489 | if (op->count == i) |
487 | if (op->count == i) |
490 | break; |
488 | break; |
491 | return op; |
489 | return op; |
492 | } |
490 | } |
493 | |
491 | |
… | |
… | |
501 | find_object_name (const char *str) |
499 | find_object_name (const char *str) |
502 | { |
500 | { |
503 | shstr_cmp str_ (str); |
501 | shstr_cmp str_ (str); |
504 | object *op; |
502 | object *op; |
505 | |
503 | |
506 | for (op = objects; op != NULL; op = op->next) |
504 | for (op = object::first; op != NULL; op = op->next) |
507 | if (op->name == str_) |
505 | if (op->name == str_) |
508 | break; |
506 | break; |
509 | |
507 | |
510 | return op; |
508 | return op; |
511 | } |
509 | } |
… | |
… | |
895 | |
893 | |
896 | if (op->more != NULL) |
894 | if (op->more != NULL) |
897 | update_object (op->more, action); |
895 | update_object (op->more, action); |
898 | } |
896 | } |
899 | |
897 | |
900 | static unordered_vector<object *> mortals; |
898 | object::vector object::mortals; |
|
|
899 | object::vector object::objects; // not yet used |
|
|
900 | object *object::first; |
901 | |
901 | |
902 | void object::free_mortals () |
902 | void object::free_mortals () |
903 | { |
903 | { |
904 | for (unordered_vector<object *>::iterator i = mortals.begin (); i != mortals.end ();) |
904 | for (AUTODECL (i, mortals.begin ()); i != mortals.end ();) |
905 | if ((*i)->refcnt) |
905 | if ((*i)->refcnt) |
906 | ++i; // further delay freeing |
906 | ++i; // further delay freeing |
907 | else |
907 | else |
908 | { |
908 | { |
909 | delete *i; |
909 | delete *i; |
… | |
… | |
936 | { |
936 | { |
937 | count = ++ob_count; |
937 | count = ++ob_count; |
938 | uuid = gen_uuid (); |
938 | uuid = gen_uuid (); |
939 | |
939 | |
940 | prev = 0; |
940 | prev = 0; |
941 | next = objects; |
941 | next = object::first; |
942 | |
942 | |
943 | if (objects) |
943 | if (object::first) |
944 | objects->prev = this; |
944 | object::first->prev = this; |
945 | |
945 | |
946 | objects = this; |
946 | object::first = this; |
947 | } |
947 | } |
948 | |
948 | |
949 | void object::unlink () |
949 | void object::unlink () |
950 | { |
950 | { |
951 | //count = 0;//D |
951 | //count = 0;//D |
952 | if (!prev && !next) return;//D |
952 | if (!prev && !next) return;//D |
953 | |
953 | |
954 | if (this == objects) |
954 | if (this == object::first) |
955 | objects = next; |
955 | object::first = next; |
956 | |
956 | |
957 | /* Remove this object from the list of used objects */ |
957 | /* Remove this object from the list of used objects */ |
958 | if (prev) prev->next = next; |
958 | if (prev) prev->next = next; |
959 | if (next) next->prev = prev; |
959 | if (next) next->prev = prev; |
960 | |
960 | |
… | |
… | |
1063 | sub_weight (object *op, signed long weight) |
1063 | sub_weight (object *op, signed long weight) |
1064 | { |
1064 | { |
1065 | while (op != NULL) |
1065 | while (op != NULL) |
1066 | { |
1066 | { |
1067 | if (op->type == CONTAINER) |
1067 | if (op->type == CONTAINER) |
1068 | { |
|
|
1069 | weight = (signed long) (weight * (100 - op->stats.Str) / 100); |
1068 | weight = (signed long) (weight * (100 - op->stats.Str) / 100); |
1070 | } |
1069 | |
1071 | op->carrying -= weight; |
1070 | op->carrying -= weight; |
1072 | op = op->env; |
1071 | op = op->env; |
1073 | } |
1072 | } |
1074 | } |
1073 | } |
1075 | |
1074 | |
… | |
… | |
1083 | */ |
1082 | */ |
1084 | |
1083 | |
1085 | void |
1084 | void |
1086 | remove_ob (object *op) |
1085 | remove_ob (object *op) |
1087 | { |
1086 | { |
|
|
1087 | object *tmp, *last = 0; |
1088 | object * |
1088 | object *otmp; |
1089 | tmp, * |
|
|
1090 | last = NULL; |
|
|
1091 | object * |
|
|
1092 | otmp; |
|
|
1093 | |
1089 | |
1094 | tag_t |
1090 | tag_t tag; |
1095 | tag; |
|
|
1096 | int |
|
|
1097 | check_walk_off; |
1091 | int check_walk_off; |
1098 | mapstruct * |
1092 | mapstruct *m; |
1099 | m; |
|
|
1100 | |
1093 | |
1101 | sint16 |
1094 | sint16 x, y; |
1102 | x, |
|
|
1103 | y; |
|
|
1104 | |
1095 | |
1105 | if (QUERY_FLAG (op, FLAG_REMOVED)) |
1096 | if (QUERY_FLAG (op, FLAG_REMOVED)) |
1106 | return; |
1097 | return; |
1107 | |
1098 | |
1108 | SET_FLAG (op, FLAG_REMOVED); |
1099 | SET_FLAG (op, FLAG_REMOVED); |
… | |
… | |
1296 | free_object (op); |
1287 | free_object (op); |
1297 | return top; |
1288 | return top; |
1298 | } |
1289 | } |
1299 | } |
1290 | } |
1300 | |
1291 | |
1301 | return NULL; |
1292 | return 0; |
1302 | } |
1293 | } |
1303 | |
1294 | |
1304 | /* |
1295 | /* |
1305 | * same as insert_ob_in_map except it handle separate coordinates and do a clean |
1296 | * same as insert_ob_in_map except it handle separate coordinates and do a clean |
1306 | * job preparing multi-part monsters |
1297 | * job preparing multi-part monsters |
… | |
… | |
1633 | remove_ob (tmp); |
1624 | remove_ob (tmp); |
1634 | free_object (tmp); |
1625 | free_object (tmp); |
1635 | } |
1626 | } |
1636 | } |
1627 | } |
1637 | |
1628 | |
1638 | tmp1 = arch_to_object (find_archetype (arch_string)); |
1629 | tmp1 = arch_to_object (archetype::find (arch_string)); |
1639 | |
1630 | |
1640 | tmp1->x = op->x; |
1631 | tmp1->x = op->x; |
1641 | tmp1->y = op->y; |
1632 | tmp1->y = op->y; |
1642 | insert_ob_in_map (tmp1, op->map, op, 0); |
1633 | insert_ob_in_map (tmp1, op->map, op, 0); |
1643 | } |
1634 | } |