Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
203 changes: 88 additions & 115 deletions Client/mods/deathmatch/logic/CVehicleUpgrades.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@
*****************************************************************************/

#include <StdInc.h>
#include <cstdint>
#include <unordered_map>
#include <vector>
#include <cstdint>
#include <cstddef>

#define NUM_MODELS 212
#define NUM_SLOTS 17

char szUpgradeNameEmpty[] = "";

Expand All @@ -42,115 +38,99 @@ static const SFixedArray<SUpgradeName, 17> UpgradeNames = {{{"Hood"},
{"Rear Bumper"},
{"Misc"}}};

using Slots = std::array<std::uint32_t, 7>;
static const std::array<Slots, NUM_MODELS> slots = {
{
{0x33c2700, 0x0, 0xfffe00, 0x7},
{0x29be7ff, 0x14060000, 0xfffe00, 0x7, 0x400dcc00, 0x1c},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2bbe78f, 0x14060000, 0xfffe00, 0x7, 0x400c0c00, 0x1c},
{0x2bdc70f, 0x14060000, 0xfffe00, 0x7, 0x400c0c00, 0x1c},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x3bbe78f, 0x14060000, 0xfffe00, 0x7, 0x400c0c00, 0x1c},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x28fc78f, 0x14060000, 0xfffe00, 0x7, 0x400c0c00, 0x1c},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x0, 0x0, 0x400000},
{0x2b1c74f, 0x14060000, 0xfffe00, 0x7, 0x400c0c00, 0x1c},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2a9c73f, 0x14060000, 0xfffe00, 0x7, 0x400c0c00, 0x1c},
{0x2bdc70f, 0x14060000, 0xfffe00, 0x7, 0x400c0c00, 0x1c},
{0x23a0780, 0x0, 0xfffe00, 0x7},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x0, 0x0, 0x400000},
{0x2a9c77f, 0x14060000, 0xfffe00, 0x7, 0x400c0c00, 0x1c},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2000700, 0x0, 0xfffe00, 0x7},
{},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2fbe7cf, 0x14060000, 0xfffe00, 0x7, 0x400c0c00, 0x1c},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x283e78f, 0x14060000, 0xfffe00, 0x7, 0x400fcc00, 0x1c},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2000700, 0x0, 0xfffe00, 0x7},
{},
{0x0, 0x0, 0x400000},
{0x0, 0x0, 0x400000},
{},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2000700, 0x0, 0xfffe00, 0x7},
{},
{},
{},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x281c70f, 0x14060000, 0xfffe00, 0x7, 0x400c0c00, 0x1c},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2000000, 0x0, 0x7ffe00, 0x7},
{0x0, 0x0, 0x400000},
{0x0, 0x0, 0x400000},
{0x0, 0x0, 0x400000},
{0x2000000, 0x0, 0x7ffe00, 0x7},
{0x0, 0x0, 0x400000},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x0, 0x0, 0x400000},
{0x0, 0x0, 0x400000},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2000700, 0x0, 0xfffe00, 0x7},
{},
{},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2000000, 0x0, 0x7ffe00, 0x7},
{0x23e07c0, 0x0, 0xfffe00, 0x7},
{0x2701730, 0x0, 0xfffe00, 0x7},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x0, 0x0, 0x400000},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x0, 0x0, 0x400000},
{0x0, 0x0, 0x400000},
{0x39de77f, 0x14060000, 0xfffe00, 0x7, 0x400c0c00, 0x1c},
{0x2000700, 0x0, 0xfffe00, 0x7},
{0x2000700, 0x0, 0xfffe00, 0x7}
}
};

CVehicleUpgrades::CVehicleUpgrades(CClientVehicle* pVehicle)
{
m_pVehicle = pVehicle;
memset(&m_SlotStates[0], 0, sizeof(m_SlotStates));
m_usLastLocalAddNitroType = 0;

m_slots[400] = {1020, 1021, 1019, 1018, 1013, 1024, 1008, 1009, 1010};
m_slots[401] = {1005, 1004, 1142, 1143, 1144, 114, 1020, 1019, 1013, 1008, 1009, 1010, 1006, 1001, 1003, 1017, 1007};
m_slots[402] = {1009, 1010};
m_slots[404] = {1020, 1021, 1019, 1013, 1008, 1009, 1010, 1002, 1016, 1000, 1017, 1007};
m_slots[405] = {1020, 1021, 1019, 1018, 1008, 1009, 1010, 1001, 1014, 1023, 1000};
m_slots[409] = {1009};
m_slots[410] = {1019, 1021, 1020, 1013, 1024, 1008, 1009, 1010, 1001, 1023, 1003, 1017, 1007};
m_slots[411] = {1008, 1009, 1010};
m_slots[412] = {1008, 1009, 1010};
m_slots[415] = {1019, 1018, 1008, 1009, 1010, 1001, 1023, 1003, 1017, 1007};
m_slots[418] = {1020, 1021, 1008, 1009, 1010, 1006, 1002, 1016};
m_slots[419] = {1008, 1009, 1010};
m_slots[420] = {1005, 1004, 1021, 1019, 1008, 1009, 1010, 1001, 1003};
m_slots[421] = {1020, 1021, 1019, 1018, 1008, 1009, 1010, 1014, 1023, 1016, 1000};
m_slots[422] = {1020, 1021, 1019, 1013, 1008, 1009, 1010, 1017, 1007};
m_slots[426] = {1005, 1004, 1021, 1019, 1008, 1009, 1010, 1006, 1001, 1003};
m_slots[429] = {1008, 1009, 1010};
m_slots[436] = {1020, 1021, 1022, 1019, 1013, 1008, 1009, 1010, 1006, 1001, 1003, 1017, 1007};
m_slots[438] = {1008, 1009, 1010};
m_slots[439] = {1003, 1023, 1001, 1008, 1009, 1010, 1017, 1007, 1142, 1143, 1144, 1145, 1013};
m_slots[442] = {1008, 1009, 1010};
m_slots[445] = {1008, 1009, 1010};
m_slots[451] = {1008, 1009, 1010};
m_slots[458] = {1008, 1009, 1010};
m_slots[466] = {1008, 1009, 1010};
m_slots[467] = {1008, 1009, 1010};
m_slots[474] = {1008, 1009, 1010};
m_slots[475] = {1008, 1009, 1010};
m_slots[477] = {1020, 1021, 1019, 1018, 1008, 1009, 1010, 1006, 1017, 1007};
m_slots[478] = {1005, 1004, 1012, 1020, 1021, 1022, 1013, 1024, 1008, 1009, 1010};
m_slots[479] = {1008, 1009, 1010};
m_slots[480] = {1008, 1009, 1010};
m_slots[489] = {1005, 1004, 1020, 1019, 1018, 1013, 1024, 1008, 1009, 1010, 1006, 1002, 1016, 1000};
m_slots[491] = {1142, 1143, 1144, 1145, 1020, 1021, 1019, 1018, 1008, 1009, 1010, 1014, 1023, 1003, 1017, 1007};
m_slots[492] = {1005, 1004, 1008, 1009, 1010, 1006, 1016, 1000};
m_slots[496] = {1006, 1017, 1007, 1011, 1019, 1023, 1001, 1008, 1009, 1010, 1003, 1002, 1142, 1143, 1020};
m_slots[500] = {1020, 1021, 1019, 1013, 1024, 1008, 1009, 1010};
m_slots[506] = {1009};
m_slots[507] = {1008, 1009, 1010};
m_slots[516] = {1004, 1020, 1021, 1019, 1018, 1008, 1009, 1010, 1002, 1015, 1016, 1000, 1017, 1007};
m_slots[517] = {1142, 1143, 1144, 1145, 1020, 1019, 1018, 1008, 1009, 1010, 1002, 1023, 1016, 1003, 1017, 1007};
m_slots[518] = {1005, 1142, 1143, 1144, 1145, 1020, 1018, 1013, 1008, 1009, 1010, 1006, 1001, 1023, 1003, 1017, 1007};
m_slots[526] = {1008, 1009, 1010};
m_slots[527] = {1021, 1020, 1018, 1008, 1009, 1010, 1001, 1014, 1015, 1017, 1007};
m_slots[529] = {1012, 1011, 1020, 1019, 1018, 1008, 1009, 1010, 1006, 1001, 1023, 1003, 1017, 1007};
m_slots[533] = {1008, 1009, 1010};
m_slots[534] = {1126, 1127, 1179, 1185, 1100, 1123, 1125, 1008, 1009, 1010, 1180, 1178, 1101, 1122, 1124, 1106};
m_slots[535] = {1109, 1110, 1113, 1114, 1115, 1116, 1117, 1008, 1009, 1010, 1120, 1118, 1121, 1119};
m_slots[536] = {1104, 1105, 1182, 1181, 1008, 1009, 1010, 1184, 1183, 1128, 1103, 1107, 1108};
m_slots[540] = {1004, 1142, 1143, 1144, 1145, 1020, 1019, 1018, 1024, 1008, 1009, 1010, 1006, 1001, 1023, 1017, 1007};
m_slots[541] = {1008, 1009, 1010};
m_slots[542] = {1144, 1145, 1020, 1021, 1019, 1018, 1008, 1009, 1010, 1014, 1015};
m_slots[545] = {1008, 1009, 1010};
m_slots[546] = {1004, 1142, 1143, 1144, 1145, 1019, 1018, 1024, 1008, 1009, 1010, 1006, 1002, 1001, 1023, 1017, 1007};
m_slots[547] = {1142, 1143, 1020, 1021, 1019, 1018, 1008, 1009, 1010, 1016, 1003, 1000};
m_slots[549] = {1012, 1011, 1142, 1143, 1144, 1145, 1020, 1019, 1018, 1008, 1009, 1010, 1001, 1023, 1003, 1017, 1007};
m_slots[550] = {1005, 1004, 1142, 1143, 1144, 1145, 1020, 1019, 1018, 1008, 1009, 1010, 1006, 1001, 1023, 1003};
m_slots[551] = {1005, 1020, 1021, 1019, 1018, 1008, 1009, 1010, 1006, 1002, 1023, 1016, 1003};
m_slots[555] = {1008, 1009, 1010};
m_slots[558] = {1092, 1089, 1166, 1165, 1008, 1009, 1010, 1168, 1167, 1088, 1091, 1164, 1163, 1094, 1090, 1095, 1093};
m_slots[559] = {1065, 1066, 1160, 1173, 1008, 1009, 1010, 1159, 1161, 1162, 1158, 1067, 1068, 1071, 1069, 1072, 1070};
m_slots[560] = {1028, 1029, 1169, 1170, 1008, 1009, 1010, 1141, 1140, 1032, 1033, 1138, 1139, 1027, 1026, 1030, 1031};
m_slots[561] = {1064, 1059, 1155, 1157, 1008, 1009, 1010, 1154, 1156, 1055, 1061, 1058, 1060, 1062, 1056, 1063, 1057};
m_slots[562] = {1034, 1037, 1171, 1172, 1008, 1009, 1010, 1149, 1148, 1038, 1035, 1147, 1146, 1040, 1036, 1041, 1039};
m_slots[565] = {1046, 1045, 1153, 1152, 1008, 1009, 1010, 1150, 1151, 1054, 1053, 1049, 1050, 1051, 1047, 1052, 1048};
m_slots[566] = {1008, 1009, 1010};
m_slots[567] = {1129, 1132, 1189, 1188, 1008, 1009, 1010, 1187, 1186, 1130, 1131, 1102, 1133};
m_slots[575] = {1044, 1043, 1174, 1175, 1008, 1009, 1010, 1176, 1177, 1099, 1042};
m_slots[576] = {1136, 1135, 1191, 1190, 1008, 1009, 1010, 1192, 1193, 1137, 1134};
m_slots[579] = {1008, 1009, 1010};
m_slots[580] = {1020, 1018, 1008, 1009, 1010, 1006, 1001, 1023, 1017, 1007};
m_slots[585] = {1142, 1143, 1144, 1145, 1020, 1019, 1018, 1013, 1008, 1009, 1010, 1006, 1001, 1023, 1003, 1017, 1007};
m_slots[587] = {1008, 1009, 1010};
m_slots[589] = {1005, 1004, 1144, 1145, 1020, 1018, 1008, 1009, 1010, 1024, 1013, 1006, 1016, 1000, 1017, 1007};
m_slots[600] = {1005, 1004, 1020, 1022, 1018, 1013, 1008, 1009, 1010, 1006, 1017, 1007};
m_slots[602] = {1008, 1009, 1010};
m_slots[603] = {1144, 1145, 1142, 1143, 1020, 1019, 1018, 1024, 1008, 1009, 1010, 1006, 1001, 1023, 1017, 1007};
}

bool CVehicleUpgrades::IsUpgrade(unsigned short usModel)
{
return (usModel >= 1000 && usModel <= 1193);
}

bool CVehicleUpgrades::IsUpgradeCompatible(const std::uint16_t upgrade)
bool CVehicleUpgrades::IsUpgradeCompatible(const std::uint16_t upgrade) noexcept
{
eClientVehicleType type = m_pVehicle->GetVehicleType();
const auto type = m_pVehicle->GetVehicleType();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to avoid replacing small types with auto.


if (type == CLIENTVEHICLE_TRAIN || type == CLIENTVEHICLE_BOAT)
{
Expand All @@ -167,31 +147,24 @@ bool CVehicleUpgrades::IsUpgradeCompatible(const std::uint16_t upgrade)
return false;
}

std::uint16_t model = m_pVehicle->GetModel();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to avoid replacing small types with auto.

auto model = m_pVehicle->GetModel();
auto* info = g_pGame->GetModelInfo(model);

if (info && info->GetParentID() != 0)
{
model = static_cast<std::uint16_t>(info->GetParentID());
}

try
{
const std::size_t id = model - 400;
const Slots& array = slots.at(id);

const std::size_t selected = upgrade - 1000;
const std::size_t index = selected / 32;

const std::uint32_t slot = array.at(index);
const std::size_t bit = selected - (index * 32);
const auto it = m_slots.find(model);

return slot & (1 << bit);
}
catch (const std::out_of_range&)
if (it == m_slots.end())
{
return false;
}

const auto& set = it->second;

return set.find(upgrade) != set.end();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about it->second.count(upgrade) > 0;

}

bool CVehicleUpgrades::GetSlotFromUpgrade(unsigned short us, unsigned char& ucSlot)
Expand Down
3 changes: 2 additions & 1 deletion Client/mods/deathmatch/logic/CVehicleUpgrades.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class CVehicleUpgrades
CVehicleUpgrades(CClientVehicle* pVehicle);

static bool IsUpgrade(unsigned short usModel);
bool IsUpgradeCompatible(const std::uint16_t upgrade);
bool IsUpgradeCompatible(const std::uint16_t upgrade) noexcept;
static bool GetSlotFromUpgrade(unsigned short usUpgrade, unsigned char& ucSlot);

bool AddUpgrade(unsigned short usUpgrade, bool bAddedLocally);
Expand All @@ -52,4 +52,5 @@ class CVehicleUpgrades
CClientVehicle* m_pVehicle;
ushort m_usLastLocalAddNitroType;
CElapsedTime m_lastLocalAddNitroTimer;
std::unordered_map<std::uint16_t, std::unordered_set<std::uint16_t>> m_slots;
};
Loading