Skip to content

Commit

Permalink
Add a new ability to structures, added as a flag, which requires it t…
Browse files Browse the repository at this point in the history
…o be built

adjacent to another completed structure that this player owns. Thanks for NoQ
for code review. Closes ticket:4016
  • Loading branch information
perim committed May 18, 2013
1 parent 7901595 commit d7df351
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/structure.cpp
Expand Up @@ -484,6 +484,16 @@ bool loadStructureStats(QString filename)
psStats->upgrade[i].thermal = ini.value("thermal", 0).toUInt();
}

psStats->flags = 0;
QStringList flags = ini.value("flags").toStringList();
for (int i = 0; i < flags.size(); i++)
{
if (flags[i] == "Connected")
{
psStats->flags |= STRUCTURE_CONNECTED;
}
}

// set structure strength
QString strength = ini.value("strength", "").toString();
ASSERT_OR_RETURN(false, structStrength.contains(strength), "Invalid strength '%s' of structure '%s'", strength.toUtf8().constData(), getID(psStats));
Expand Down Expand Up @@ -4092,6 +4102,31 @@ bool validLocation(BASE_STATS *psStats, Vector2i pos, uint16_t direction, unsign
}
}
}
if (psBuilding->flags & STRUCTURE_CONNECTED)
{
bool connection = false;
for (int j = -1; j < b.size.y + 1; ++j)
{
for (int i = -1; i < b.size.x + 1; ++i)
{
//skip the actual area the structure will cover
if (i < 0 || i >= b.size.x || j < 0 || j >= b.size.y)
{
STRUCTURE const *psStruct = getTileStructure(b.map.x + i, b.map.y + j);
if (psStruct != NULL && psStruct->player == player && psStruct->status == SS_BUILT)
{
connection = true;
break;
}
}
}
}
if (!connection)
{
return false; // needed to be connected to another building
}
}

/*need to check each tile the structure will sit on*/
for (int j = 0; j < b.size.y; ++j)
for (int i = 0; i < b.size.x; ++i)
Expand Down
3 changes: 3 additions & 0 deletions src/structuredef.h
Expand Up @@ -100,6 +100,8 @@ enum STRUCT_ANIM_STATES
SAS_CLOSING,
};

#define STRUCTURE_CONNECTED 0x0001 ///< This structure must be built side by side with another of the same player

//this structure is used to hold the permenant stats for each type of building
struct STRUCTURE_STATS : public BASE_STATS
{
Expand All @@ -125,6 +127,7 @@ struct STRUCTURE_STATS : public BASE_STATS
UDWORD numWeaps; /*Number of weapons for default */

struct WEAPON_STATS *psWeapStat[STRUCT_MAXWEAPS];
uint64_t flags;

struct
{
Expand Down

0 comments on commit d7df351

Please sign in to comment.