diff --git a/src/interpreter_extra.cc b/src/interpreter_extra.cc index fa9365e..221f4a5 100644 --- a/src/interpreter_extra.cc +++ b/src/interpreter_extra.cc @@ -2210,7 +2210,7 @@ static void opSetExitGrids(Program* program) Object* object = objectFindFirstAtElevation(elevation); while (object != NULL) { - if (object->pid >= PROTO_ID_0x5000010 && object->pid <= PROTO_ID_0x5000017) { + if (object->pid >= FIRST_EXIT_GRID_PID && object->pid <= LAST_EXIT_GRID_PID) { object->data.misc.map = destinationMap; object->data.misc.tile = destinationTile; object->data.misc.elevation = destinationElevation; diff --git a/src/object.cc b/src/object.cc index eb078ee..3bf12ea 100644 --- a/src/object.cc +++ b/src/object.cc @@ -438,16 +438,16 @@ int objectRead(Object* obj, File* stream) return -1; } - if (obj->pid < 0x5000010 || obj->pid > 0x5000017) { - if (PID_TYPE(obj->pid) == 0 && !(gMapHeader.flags & 0x01)) { - _object_fix_weapon_ammo(obj); - } - } else { + if (isExitGridPid(obj->pid)) { if (obj->data.misc.map <= 0) { if ((obj->fid & 0xFFF) < 33) { obj->fid = buildFid(OBJ_TYPE_MISC, (obj->fid & 0xFFF) + 16, FID_ANIM_TYPE(obj->fid), 0, 0); } } + } else { + if (PID_TYPE(obj->pid) == 0 && !(gMapHeader.flags & 0x01)) { + _object_fix_weapon_ammo(obj); + } } return 0; @@ -1469,7 +1469,7 @@ int objectSetLocation(Object* obj, int tile, int elevation, Rect* rect) if (elevation == elev) { if (FID_TYPE(obj->fid) == OBJ_TYPE_MISC) { - if (obj->pid >= 0x5000010 && obj->pid <= 0x5000017) { + if (isExitGridPid(obj->pid)) { ObjectData* data = &(obj->data); MapTransition transition; diff --git a/src/proto.cc b/src/proto.cc index 7e979cc..86d767b 100644 --- a/src/proto.cc +++ b/src/proto.cc @@ -519,7 +519,7 @@ int objectDataRead(Object* obj, File* stream) break; case OBJ_TYPE_MISC: - if (obj->pid >= 0x5000010 && obj->pid <= 0x5000017) { + if (isExitGridPid(obj->pid)) { if (fileReadInt32(stream, &(obj->data.misc.map)) == -1) return -1; if (fileReadInt32(stream, &(obj->data.misc.tile)) == -1) return -1; if (fileReadInt32(stream, &(obj->data.misc.elevation)) == -1) return -1; @@ -600,7 +600,7 @@ int objectDataWrite(Object* obj, File* stream) } break; case OBJ_TYPE_MISC: - if (obj->pid >= 0x5000010 && obj->pid <= 0x5000017) { + if (isExitGridPid(obj->pid)) { if (fileWriteInt32(stream, data->misc.map) == -1) return -1; if (fileWriteInt32(stream, data->misc.tile) == -1) return -1; if (fileWriteInt32(stream, data->misc.elevation) == -1) return -1; @@ -674,7 +674,7 @@ static int _proto_update_gen(Object* obj) } break; case OBJ_TYPE_MISC: - if (obj->pid >= 0x5000010 && obj->pid <= 0x5000017) { + if (isExitGridPid(obj->pid)) { data->misc.tile = -1; data->misc.elevation = 0; data->misc.rotation = 0; diff --git a/src/proto.h b/src/proto.h index 1b27ce0..c7f481d 100644 --- a/src/proto.h +++ b/src/proto.h @@ -126,6 +126,11 @@ void _proto_remove_all(); int protoGetProto(int pid, Proto** out_proto); int _ResetPlayer(); +static bool isExitGridPid(int pid) +{ + return pid >= FIRST_EXIT_GRID_PID && pid <= LAST_EXIT_GRID_PID; +} + } // namespace fallout #endif /* PROTO_H */ diff --git a/src/proto_types.h b/src/proto_types.h index 1095b5a..df7aac2 100644 --- a/src/proto_types.h +++ b/src/proto_types.h @@ -198,10 +198,8 @@ enum { #define PROTO_ID_0x20001D6 0x20001D6 #define PROTO_ID_0x20001EB 0x20001EB #define FID_0x20001F5 0x20001F5 -// first exit grid -#define PROTO_ID_0x5000010 0x5000010 -// last exit grid -#define PROTO_ID_0x5000017 0x5000017 +#define FIRST_EXIT_GRID_PID 0x5000010 +#define LAST_EXIT_GRID_PID 0x5000017 typedef enum ItemProtoFlags { ItemProtoFlags_0x08 = 0x08,