-
organizing data
No code to post... just looking for some ideas. Here's the situation. I have a linked list full of "settlements". Each settlement is of a certain type (village, town, or city). You can build certain structures in the various settlements, and some structures are unique to certain settlement types. For example, you can build a market in a village, town, or city. You can build a port in a town or city (but not a village), and you can build a wall in a city (but not a village or town).
During the CreateBuilding function, I want a simple test to determine if a building/structure is allowed to be built, based upon the type of settlement. I can think of some ugly ways to do this, but is there a pretty way?
Code:
Here's how I keep the data:
class Structure {
private:
// parallel arrays to keep track of the settlement's structures
bool structure_status[MAX_NUM_BUILDINGS]; // 0 = does not exist, 1 = exists
int structural_integrity[MAX_NUM_BUILDINGS];
...
};
-
What if you enumerated the possible settlement/building types?
Then just check against them, ie:
Code:
//pseudo..
enum Bldg
{
Wall,
Port,
Market,
} NewBldgType;
if(Settlement1==0) //for instance 0 = village
{
switch(NewBldgType)
{
case 0: //wall
case 1: //port
//not ok
break;
case 2:
//ok, build it
break;
}
}