… | |
… | |
35 | |
35 | |
36 | int nrofallocobjects = 0; |
36 | int nrofallocobjects = 0; |
37 | static UUID uuid; |
37 | static UUID uuid; |
38 | const uint64 UUID_SKIP = 1<<19; |
38 | const uint64 UUID_SKIP = 1<<19; |
39 | |
39 | |
40 | object *objects; /* Pointer to the list of used objects */ |
|
|
41 | object *active_objects; /* List of active objects that need to be processed */ |
40 | object *active_objects; /* List of active objects that need to be processed */ |
42 | |
41 | |
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, |
42 | 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 |
43 | 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 | }; |
44 | }; |
… | |
… | |
447 | void |
446 | void |
448 | dump_all_objects (void) |
447 | dump_all_objects (void) |
449 | { |
448 | { |
450 | object *op; |
449 | object *op; |
451 | |
450 | |
452 | for (op = objects; op != NULL; op = op->next) |
451 | for (op = object::first; op != NULL; op = op->next) |
453 | { |
452 | { |
454 | dump_object (op); |
453 | dump_object (op); |
455 | fprintf (logfile, "Object %d\n:%s\n", op->count, errmsg); |
454 | fprintf (logfile, "Object %d\n:%s\n", op->count, errmsg); |
456 | } |
455 | } |
457 | } |
456 | } |
… | |
… | |
483 | object * |
482 | object * |
484 | find_object (tag_t i) |
483 | find_object (tag_t i) |
485 | { |
484 | { |
486 | object *op; |
485 | object *op; |
487 | |
486 | |
488 | for (op = objects; op != NULL; op = op->next) |
487 | for (op = object::first; op != NULL; op = op->next) |
489 | if (op->count == i) |
488 | if (op->count == i) |
490 | break; |
489 | break; |
491 | return op; |
490 | return op; |
492 | } |
491 | } |
493 | |
492 | |
… | |
… | |
501 | find_object_name (const char *str) |
500 | find_object_name (const char *str) |
502 | { |
501 | { |
503 | shstr_cmp str_ (str); |
502 | shstr_cmp str_ (str); |
504 | object *op; |
503 | object *op; |
505 | |
504 | |
506 | for (op = objects; op != NULL; op = op->next) |
505 | for (op = object::first; op != NULL; op = op->next) |
507 | if (op->name == str_) |
506 | if (op->name == str_) |
508 | break; |
507 | break; |
509 | |
508 | |
510 | return op; |
509 | return op; |
511 | } |
510 | } |
… | |
… | |
895 | |
894 | |
896 | if (op->more != NULL) |
895 | if (op->more != NULL) |
897 | update_object (op->more, action); |
896 | update_object (op->more, action); |
898 | } |
897 | } |
899 | |
898 | |
900 | static unordered_vector<object *> mortals; |
899 | object::vector object::mortals; |
|
|
900 | object::vector object::objects; // not yet used |
|
|
901 | object *object::first; |
901 | |
902 | |
902 | void object::free_mortals () |
903 | void object::free_mortals () |
903 | { |
904 | { |
904 | for (unordered_vector<object *>::iterator i = mortals.begin (); i != mortals.end ();) |
905 | for (AUTODECL (i, mortals.begin ()); i != mortals.end ();) |
905 | if ((*i)->refcnt) |
906 | if ((*i)->refcnt) |
906 | ++i; // further delay freeing |
907 | ++i; // further delay freeing |
907 | else |
908 | else |
908 | { |
909 | { |
909 | delete *i; |
910 | delete *i; |
… | |
… | |
936 | { |
937 | { |
937 | count = ++ob_count; |
938 | count = ++ob_count; |
938 | uuid = gen_uuid (); |
939 | uuid = gen_uuid (); |
939 | |
940 | |
940 | prev = 0; |
941 | prev = 0; |
941 | next = objects; |
942 | next = object::first; |
942 | |
943 | |
943 | if (objects) |
944 | if (object::first) |
944 | objects->prev = this; |
945 | object::first->prev = this; |
945 | |
946 | |
946 | objects = this; |
947 | object::first = this; |
947 | } |
948 | } |
948 | |
949 | |
949 | void object::unlink () |
950 | void object::unlink () |
950 | { |
951 | { |
951 | //count = 0;//D |
952 | //count = 0;//D |
952 | if (!prev && !next) return;//D |
953 | if (!prev && !next) return;//D |
953 | |
954 | |
954 | if (this == objects) |
955 | if (this == object::first) |
955 | objects = next; |
956 | object::first = next; |
956 | |
957 | |
957 | /* Remove this object from the list of used objects */ |
958 | /* Remove this object from the list of used objects */ |
958 | if (prev) prev->next = next; |
959 | if (prev) prev->next = next; |
959 | if (next) next->prev = prev; |
960 | if (next) next->prev = prev; |
960 | |
961 | |
… | |
… | |
1063 | sub_weight (object *op, signed long weight) |
1064 | sub_weight (object *op, signed long weight) |
1064 | { |
1065 | { |
1065 | while (op != NULL) |
1066 | while (op != NULL) |
1066 | { |
1067 | { |
1067 | if (op->type == CONTAINER) |
1068 | if (op->type == CONTAINER) |
1068 | { |
|
|
1069 | weight = (signed long) (weight * (100 - op->stats.Str) / 100); |
1069 | weight = (signed long) (weight * (100 - op->stats.Str) / 100); |
1070 | } |
1070 | |
1071 | op->carrying -= weight; |
1071 | op->carrying -= weight; |
1072 | op = op->env; |
1072 | op = op->env; |
1073 | } |
1073 | } |
1074 | } |
1074 | } |
1075 | |
1075 | |
… | |
… | |
1083 | */ |
1083 | */ |
1084 | |
1084 | |
1085 | void |
1085 | void |
1086 | remove_ob (object *op) |
1086 | remove_ob (object *op) |
1087 | { |
1087 | { |
|
|
1088 | object *tmp, *last = 0; |
1088 | object * |
1089 | object *otmp; |
1089 | tmp, * |
|
|
1090 | last = NULL; |
|
|
1091 | object * |
|
|
1092 | otmp; |
|
|
1093 | |
1090 | |
1094 | tag_t |
1091 | tag_t tag; |
1095 | tag; |
|
|
1096 | int |
|
|
1097 | check_walk_off; |
1092 | int check_walk_off; |
1098 | mapstruct * |
1093 | mapstruct *m; |
1099 | m; |
|
|
1100 | |
1094 | |
1101 | sint16 |
1095 | sint16 x, y; |
1102 | x, |
|
|
1103 | y; |
|
|
1104 | |
1096 | |
1105 | if (QUERY_FLAG (op, FLAG_REMOVED)) |
1097 | if (QUERY_FLAG (op, FLAG_REMOVED)) |
1106 | return; |
1098 | return; |
1107 | |
1099 | |
1108 | SET_FLAG (op, FLAG_REMOVED); |
1100 | SET_FLAG (op, FLAG_REMOVED); |
… | |
… | |
1296 | free_object (op); |
1288 | free_object (op); |
1297 | return top; |
1289 | return top; |
1298 | } |
1290 | } |
1299 | } |
1291 | } |
1300 | |
1292 | |
1301 | return NULL; |
1293 | return 0; |
1302 | } |
1294 | } |
1303 | |
1295 | |
1304 | /* |
1296 | /* |
1305 | * same as insert_ob_in_map except it handle separate coordinates and do a clean |
1297 | * same as insert_ob_in_map except it handle separate coordinates and do a clean |
1306 | * job preparing multi-part monsters |
1298 | * job preparing multi-part monsters |