Skip to content

Commit

Permalink
Changes int8 to int16 in serializers
Browse files Browse the repository at this point in the history
to pass more than 256 weapons parts in game engine logic
fixing bug #4677
  • Loading branch information
EuPhobos committed Jan 24, 2018
1 parent 1a05e38 commit c05e4f7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/droid.cpp
Expand Up @@ -1364,7 +1364,7 @@ UDWORD calcDroidWeight(DROID_TEMPLATE *psTemplate)
return weight;
}

static uint32_t calcDroidOrTemplateBody(uint8_t (&asParts)[DROID_MAXCOMP], unsigned numWeaps, uint8_t (&asWeaps)[MAX_WEAPONS], unsigned player)
static uint32_t calcDroidOrTemplateBody(uint8_t (&asParts)[DROID_MAXCOMP], unsigned numWeaps, uint16_t (&asWeaps)[MAX_WEAPONS], unsigned player)
{
const auto &bodyStats = asBodyStats[asParts[COMP_BODY]];

Expand Down Expand Up @@ -1419,7 +1419,7 @@ UDWORD calcTemplateBody(DROID_TEMPLATE *psTemplate, UBYTE player)
// Calculate the base body points of a droid with upgrades
static UDWORD calcDroidBaseBody(DROID *psDroid)
{
uint8_t asWeaps[MAX_WEAPONS];
uint16_t asWeaps[MAX_WEAPONS];
std::transform(std::begin(psDroid->asWeaps), std::end(psDroid->asWeaps), asWeaps, [](WEAPON &weap) {
return weap.nStat;
});
Expand Down
4 changes: 2 additions & 2 deletions src/droiddef.h
Expand Up @@ -67,8 +67,8 @@ struct DROID_TEMPLATE : public BASE_STATS
*/
uint8_t asParts[DROID_MAXCOMP];
/* The weapon systems */
int8_t numWeaps; ///< Number of weapons
uint8_t asWeaps[MAX_WEAPONS]; ///< weapon indices
int16_t numWeaps; ///< Number of weapons
uint16_t asWeaps[MAX_WEAPONS]; ///< weapon indices
DROID_TYPE droidType; ///< The type of droid
UDWORD multiPlayerID; ///< multiplayer unique descriptor(cant use id's for templates). Used for save games as well now - AB 29/10/98
bool prefab; ///< Not player designed, not saved, never delete or change
Expand Down
8 changes: 4 additions & 4 deletions src/multibot.cpp
Expand Up @@ -346,10 +346,10 @@ bool SendDroid(DROID_TEMPLATE *pTemplate, uint32_t x, uint32_t y, uint8_t player
NETuint8_t(&pTemplate->asParts[COMP_ECM]);
NETuint8_t(&pTemplate->asParts[COMP_SENSOR]);
NETuint8_t(&pTemplate->asParts[COMP_CONSTRUCT]);
NETint8_t(&pTemplate->numWeaps);
NETint16_t(&pTemplate->numWeaps);
for (int i = 0; i < pTemplate->numWeaps; i++)
{
NETuint8_t(&pTemplate->asWeaps[i]);
NETuint16_t(&pTemplate->asWeaps[i]);
}
NETbool(&haveInitialOrders);
if (haveInitialOrders)
Expand Down Expand Up @@ -394,11 +394,11 @@ bool recvDroid(NETQUEUE queue)
NETuint8_t(&pT->asParts[COMP_ECM]);
NETuint8_t(&pT->asParts[COMP_SENSOR]);
NETuint8_t(&pT->asParts[COMP_CONSTRUCT]);
NETint8_t(&pT->numWeaps);
NETint16_t(&pT->numWeaps);
ASSERT_OR_RETURN(false, pT->numWeaps >= 0 && pT->numWeaps <= ARRAY_SIZE(pT->asWeaps), "Bad numWeaps %d", pT->numWeaps);
for (int i = 0; i < pT->numWeaps; i++)
{
NETuint8_t(&pT->asWeaps[i]);
NETuint16_t(&pT->asWeaps[i]);
}
NETbool(&haveInitialOrders);
if (haveInitialOrders)
Expand Down
8 changes: 4 additions & 4 deletions src/multistruct.cpp
Expand Up @@ -295,10 +295,10 @@ void sendStructureInfo(STRUCTURE *psStruct, STRUCTURE_INFO structureInfo_, DROID
NETuint8_t(&pT->asParts[COMP_ECM]);
NETuint8_t(&pT->asParts[COMP_SENSOR]);
NETuint8_t(&pT->asParts[COMP_CONSTRUCT]);
NETint8_t(&pT->numWeaps);
NETint16_t(&pT->numWeaps);
for (int i = 0; i < pT->numWeaps; i++)
{
NETuint8_t(&pT->asWeaps[i]);
NETuint16_t(&pT->asWeaps[i]);
}
}
NETend();
Expand Down Expand Up @@ -329,11 +329,11 @@ void recvStructureInfo(NETQUEUE queue)
NETuint8_t(&pT->asParts[COMP_ECM]);
NETuint8_t(&pT->asParts[COMP_SENSOR]);
NETuint8_t(&pT->asParts[COMP_CONSTRUCT]);
NETint8_t(&pT->numWeaps);
NETint16_t(&pT->numWeaps);
ASSERT_OR_RETURN(, pT->numWeaps >= 0 && pT->numWeaps <= ARRAY_SIZE(pT->asWeaps), "Bad numWeaps %d", pT->numWeaps);
for (int i = 0; i < pT->numWeaps; i++)
{
NETuint8_t(&pT->asWeaps[i]);
NETuint16_t(&pT->asWeaps[i]);
}
pT->droidType = (DROID_TYPE)droidType;
pT = copyTemplate(player, pT);
Expand Down

0 comments on commit c05e4f7

Please sign in to comment.