Add isExitGridPid

This commit is contained in:
Alexander Batalov 2022-12-13 14:34:49 +03:00
parent e02dcdf69d
commit 280b55ab05
5 changed files with 17 additions and 14 deletions

View File

@ -2210,7 +2210,7 @@ static void opSetExitGrids(Program* program)
Object* object = objectFindFirstAtElevation(elevation); Object* object = objectFindFirstAtElevation(elevation);
while (object != NULL) { 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.map = destinationMap;
object->data.misc.tile = destinationTile; object->data.misc.tile = destinationTile;
object->data.misc.elevation = destinationElevation; object->data.misc.elevation = destinationElevation;

View File

@ -438,16 +438,16 @@ int objectRead(Object* obj, File* stream)
return -1; return -1;
} }
if (obj->pid < 0x5000010 || obj->pid > 0x5000017) { if (isExitGridPid(obj->pid)) {
if (PID_TYPE(obj->pid) == 0 && !(gMapHeader.flags & 0x01)) {
_object_fix_weapon_ammo(obj);
}
} else {
if (obj->data.misc.map <= 0) { if (obj->data.misc.map <= 0) {
if ((obj->fid & 0xFFF) < 33) { if ((obj->fid & 0xFFF) < 33) {
obj->fid = buildFid(OBJ_TYPE_MISC, (obj->fid & 0xFFF) + 16, FID_ANIM_TYPE(obj->fid), 0, 0); 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; return 0;
@ -1469,7 +1469,7 @@ int objectSetLocation(Object* obj, int tile, int elevation, Rect* rect)
if (elevation == elev) { if (elevation == elev) {
if (FID_TYPE(obj->fid) == OBJ_TYPE_MISC) { if (FID_TYPE(obj->fid) == OBJ_TYPE_MISC) {
if (obj->pid >= 0x5000010 && obj->pid <= 0x5000017) { if (isExitGridPid(obj->pid)) {
ObjectData* data = &(obj->data); ObjectData* data = &(obj->data);
MapTransition transition; MapTransition transition;

View File

@ -519,7 +519,7 @@ int objectDataRead(Object* obj, File* stream)
break; break;
case OBJ_TYPE_MISC: 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.map)) == -1) return -1;
if (fileReadInt32(stream, &(obj->data.misc.tile)) == -1) return -1; if (fileReadInt32(stream, &(obj->data.misc.tile)) == -1) return -1;
if (fileReadInt32(stream, &(obj->data.misc.elevation)) == -1) return -1; if (fileReadInt32(stream, &(obj->data.misc.elevation)) == -1) return -1;
@ -600,7 +600,7 @@ int objectDataWrite(Object* obj, File* stream)
} }
break; break;
case OBJ_TYPE_MISC: 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.map) == -1) return -1;
if (fileWriteInt32(stream, data->misc.tile) == -1) return -1; if (fileWriteInt32(stream, data->misc.tile) == -1) return -1;
if (fileWriteInt32(stream, data->misc.elevation) == -1) return -1; if (fileWriteInt32(stream, data->misc.elevation) == -1) return -1;
@ -674,7 +674,7 @@ static int _proto_update_gen(Object* obj)
} }
break; break;
case OBJ_TYPE_MISC: case OBJ_TYPE_MISC:
if (obj->pid >= 0x5000010 && obj->pid <= 0x5000017) { if (isExitGridPid(obj->pid)) {
data->misc.tile = -1; data->misc.tile = -1;
data->misc.elevation = 0; data->misc.elevation = 0;
data->misc.rotation = 0; data->misc.rotation = 0;

View File

@ -126,6 +126,11 @@ void _proto_remove_all();
int protoGetProto(int pid, Proto** out_proto); int protoGetProto(int pid, Proto** out_proto);
int _ResetPlayer(); int _ResetPlayer();
static bool isExitGridPid(int pid)
{
return pid >= FIRST_EXIT_GRID_PID && pid <= LAST_EXIT_GRID_PID;
}
} // namespace fallout } // namespace fallout
#endif /* PROTO_H */ #endif /* PROTO_H */

View File

@ -198,10 +198,8 @@ enum {
#define PROTO_ID_0x20001D6 0x20001D6 #define PROTO_ID_0x20001D6 0x20001D6
#define PROTO_ID_0x20001EB 0x20001EB #define PROTO_ID_0x20001EB 0x20001EB
#define FID_0x20001F5 0x20001F5 #define FID_0x20001F5 0x20001F5
// first exit grid #define FIRST_EXIT_GRID_PID 0x5000010
#define PROTO_ID_0x5000010 0x5000010 #define LAST_EXIT_GRID_PID 0x5000017
// last exit grid
#define PROTO_ID_0x5000017 0x5000017
typedef enum ItemProtoFlags { typedef enum ItemProtoFlags {
ItemProtoFlags_0x08 = 0x08, ItemProtoFlags_0x08 = 0x08,