Hello.
I was thinking how to make a structure know its functionalities in my 2d top down game.
The first thought i had is make bit flags and turn on and off what the structure does:
For example:
enum StructureFunctions{
SFStorage = 0x01,//Used to drop resources
SFRest = 0x02,//Used to sleep at night
SFTownHall = 0x04,//Used to get actions from
SFBarrack = 0x08,//Used for training/ getting battle/scout/guard actions for day
SFOnWater = 0x10,//This structure is on water
SFOnLand = 0x20,//This structure is on land
SFOperationable = 0x40,//Uses people to operate, instead of automatic
SFProduces = 0x80,//Produces resources
};
class Structure
{
public:
int Functions;
};
//Somewhere in cpp
Structure Farm;
Structure FishingDocks;
Structure Church;
Structure Barrack;
Farm.Functions = SFProduces | SFOperationable | SFOnLand | SFStorage;
FishingDocks.Functions = SFProduces | SFOperationable | SFOnLand | SFOnWater | SFStorage;
Church.Functions = SFRest | SFOnLand | SFProduces;
Barrack.Functions = SFRest | SFBarrack | SFOnLand;
The big question is:
I require more flag states, and i never worked with them so i got no experience in that field except tutorials and examples i saw.
How do i make specific structures have attributes as such that would be efficient?
I need to be able to make a object of structure and the structure stats with base value "Is on land", then i will add crafting table intro the structure i will turn "Crafting" on for that structure, if i add barrel intro it i will add "Storage"
Then when i require something as
//A unit just finished harvesting wood, find a place to drop resources
for(all structures)
{
if(Structure.Function has Storage)
//Check if storage has space left
//Check if storage can take type the unit is carrying (Barrel, is made for liquid or small type objects as fish, not for wood storage)
}
//A unit has decided to go rest
for(all structures)
{
if(Structure.Function has Rest)
//If not occupied
}
Have you done anything like this before? would you be willing to trow some ideas this way?
If you didn't do something like this before? would you be willing to trow some ideas this way.