Fix bug #1402 - addMultiPlayerRandomArtifacts could send incorrect number of artifacts.
git-svn-id: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/trunk@9151 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
d8295761fc
commit
7553718c8d
|
@ -45,6 +45,7 @@
|
|||
#include "scriptcb.h"
|
||||
#include "loop.h"
|
||||
#include "transporter.h"
|
||||
#include "mission.h" // for INVALID_XY
|
||||
|
||||
#include "lib/netplay/netplay.h"
|
||||
#include "multiplay.h"
|
||||
|
@ -624,7 +625,7 @@ static const char *feature_names[] =
|
|||
void addMultiPlayerRandomArtifacts(uint8_t quantity, FEATURE_TYPE type)
|
||||
{
|
||||
FEATURE *pF;
|
||||
int i, count;
|
||||
int i, featureStat, count;
|
||||
uint32_t x, y;
|
||||
uint8_t player = ANYPLAYER;
|
||||
|
||||
|
@ -633,34 +634,53 @@ void addMultiPlayerRandomArtifacts(uint8_t quantity, FEATURE_TYPE type)
|
|||
NETuint8_t(&quantity);
|
||||
NETenum(&type);
|
||||
|
||||
for(i = 0; i < numFeatureStats && asFeatureStats[i].subType != type; i++);
|
||||
for(featureStat = 0; featureStat < numFeatureStats && asFeatureStats[featureStat].subType != type; featureStat++);
|
||||
|
||||
ASSERT(mapWidth > 20, "map not big enough");
|
||||
ASSERT(mapHeight > 20, "map not big enough");
|
||||
|
||||
for (count = 0; count < quantity; count++)
|
||||
{
|
||||
// Between 10 and mapwidth - 10
|
||||
x = (rand() % (mapWidth - 20)) + 10;
|
||||
y = (rand() % (mapHeight - 20)) + 10;
|
||||
|
||||
if (!pickATileGen(&x, &y, LOOK_FOR_EMPTY_TILE, zonedPAT))
|
||||
for (i = 0; i < 3; i++) // try three times
|
||||
{
|
||||
debug(LOG_FEATURE, "Unable to find a free location.");
|
||||
break;
|
||||
}
|
||||
// Between 10 and mapwidth - 10
|
||||
x = (rand() % (mapWidth - 20)) + 10;
|
||||
y = (rand() % (mapHeight - 20)) + 10;
|
||||
|
||||
pF = buildFeature(asFeatureStats + i, world_coord(x), world_coord(y), false);
|
||||
if (pickATileGen(&x, &y, LOOK_FOR_EMPTY_TILE, zonedPAT))
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if (i == 2)
|
||||
{
|
||||
debug(LOG_FEATURE, "Unable to find a free location after 3 tries; giving up.");
|
||||
x = INVALID_XY;
|
||||
}
|
||||
}
|
||||
if (x != INVALID_XY) // at least one of the tries succeeded
|
||||
{
|
||||
pF = buildFeature(asFeatureStats + featureStat, world_coord(x), world_coord(y), false);
|
||||
if (pF)
|
||||
{
|
||||
pF->player = player;
|
||||
}
|
||||
else
|
||||
{
|
||||
x = INVALID_XY;
|
||||
}
|
||||
}
|
||||
|
||||
NETuint32_t(&x);
|
||||
NETuint32_t(&y);
|
||||
NETuint32_t(&pF->id);
|
||||
NETuint8_t(&player);
|
||||
|
||||
if (pF)
|
||||
{
|
||||
pF->player = player;
|
||||
NETuint32_t(&pF->id);
|
||||
}
|
||||
else
|
||||
{
|
||||
NETuint32_t(&x); // just give them a dummy value; it'll never be used
|
||||
}
|
||||
NETuint8_t(&player);
|
||||
}
|
||||
|
||||
NETend();
|
||||
|
@ -700,7 +720,11 @@ void recvMultiPlayerRandomArtifacts()
|
|||
NETuint32_t(&ref);
|
||||
NETuint8_t(&player);
|
||||
|
||||
if (!tileOnMap(tx, ty))
|
||||
if (tx == INVALID_XY)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else if (!tileOnMap(tx, ty))
|
||||
{
|
||||
debug(LOG_ERROR, "Bad tile coordinates (%u,%u)", tx, ty);
|
||||
continue;
|
||||
|
|
Loading…
Reference in New Issue