Flag.hpp

Uploaded: 15 Feb, 2014
Previous uploads by this submitter: 0

Author: David Simmerson

Downloads: 35

This is the flag System from my mud Infected City. (V1)

The flags work as a virtualized class (inheritance). An example would be the following:

class Critter : public Flag {
…..
…..
};


Now our flags the critter uses… (examples of course)

typedef enum { CR_DEAD, CR_BLIND, CR_PLAGUE, CR_IMM_POISON } critter_flags;


Now later on, somewhere in say, in a check for blind.

if(cr->hasFlag(CR_BLIND))
attacker->writeBuffer("But they are already blind!\n\r");
else
{
cr->setFlag(CR_BLIND, true);
attacker->writeBuffer(Format("You have blinded %s\n\r", cr->strings.pName));
cr->writeBuffer("\n\r*** You can't see!!! You've been blinded! ***\n\r");
}


For saving:

fprintf(fp, "Flag %s\n", cr->flagToString());


The data out looks like 01 (based on just having blind set)
it saves up to the highest flag set, so if you only have the 2nd flag, it only writes that.
Everything gets defaulted to 0 so happy day above your highest flag set.

Larger strings may look like 010001010111101010100011110101001011 etc.

Now reading, once you read in the string.
cr->stringToFlag(string_we_read_in_from_save_file_or_database);



I hope people find this useful, remember, once you add flags to your enum
you have to maintain adding flags at the end. If you put flags in the middle
say for naming convenience, you will skew the flags locations, thus corrupting
your flags, so *AWAYS* write new flags at the end of your enum.

I'm also sure there are ways to improve upon this, I just haven't invested time
in it to do so, it works pretty damned well and I have had no issues with it.

Cheers

Omega