Skip to main content
GameDev.net gamedev.net
🔒 Locked

#define C# 0

Started by Thevenin Dec 13, 2005 at 9:57 PM 5 replies 800+ views
Original Post
Thevenin
Thevenin
In C, I had a file called cCommon.c, which stored all my flags (As you can see, I used it quite intensively in my MMORPG)
/* Winsock Flags. */
#define flag_MaxConnections 1000

/* Macro's. */
#define flag_FRandom (rand()/(RAND_MAX/1.0))
#define flag_FWindowY ( (13*16)+2+1+6)
#define flag_FCharacters ((guiSmallWidth-90-2)/6)
#define flag_FSetDefinition(n,a,d,w,s,c) gaoItemDefinitions[n].lucAttack = a; gaoItemDefinitions[n].lucDefense = d; gaoItemDefinitions[n].lucWalkEquip = w; gaoItemDefinitions[n].lucStackSize = s; gaoItemDefinitions[n].lucClass = c;

/* Identity Tags */
#define flag_IDCreature 0
#define flag_IDBuilding 3
#define flag_IDItem 1
#define flag_IDDecal 2
#define flag_IDPoof 6
#define flag_IDField 7
#define flag_IDProjectile 4

#define flag_IDDamageMsg 5
#define flag_IDChatMsg 8
#define flag_IDGlobalMsg 11
#define flag_IDSkillMsg 12
#define flag_IDPrivateMsg 9
#define flag_IDItemMsg 10


/* Winsock Tags (Its important that none of these are 0) */

#define flag_PAKMovement 1
#define flag_PAKCreatures 2
#define flag_PAKNothing 3
#define flag_PAKMessage 4
#define flag_PAKInventoryUse 5
#define flag_PAKInventoryMove 6
#define flag_PAKAccount 7
#define flag_PAKChangeOutfit 8

#define flag_PAKDamage 10
#define flag_PAKHealth 11
#define flag_PAKTarget 12
#define flag_PAKInventoryUpdate 13
#define flag_PAKInventoryTransfer 14
#define flag_PAKDeath 16
#define flag_PAKBroadcast 17
#define flag_PAKSkills 18
#define flag_PAKFlush 19
#define flag_PAKEffect 20
#define flag_PAKPushWorldObject 21

#define flag_PAKSpawn 23
#define flag_PAKPopUp 24
#define flag_PAKLog 25


/* Creation Flags */
#define flag_MapPlayer1 1
#define flag_MapKnight 4

/* Vocation Flags. */
#define flag_VocKnight 0
#define flag_VocArcher 1
#define flag_VocMage 2
#define flag_VocGM 3
#define flag_VocCPU 4

/* Item Flags */
#define flag_ITMHead 1
#define flag_ITMBody 3
#define flag_ITMLeg 6
#define flag_ITMShield 4
#define flag_ITMWeapon 2
#define flag_ITMAmulet 0
#define flag_ITMLRing 5
#define flag_ITMRRing 7
#define flag_ITMBoots 8

#define flag_ITMNoEquip 100

#define flag_CLASword 1
#define flag_CLAAxe 2
#define flag_CLADistance 3
#define flag_CLAClub 4


/* Skill Flags.*/
#define flag_SkiLevel 1
#define flag_SkiSword 2
#define flag_SkiShield 3
#define flag_SkiMagic 4

/* Graphics Flags for Effects */
#define flag_FXSingleEffect 1
#define flag_FXProjectile 2
#define flag_FXDamage 3
#define flag_FXXP 4
#define flag_FXSpell 5

/* Sub-category of FXSpell */
	#define flag_SpellExplosion 1 
	#define flag_SpellUE 2 
	#define flag_SpellEnergyWave 3
	#define flag_SpellFireWave 4
	#define flag_SpellFireBall 5
	#define flag_SpellFireBomb 7
	#define flag_SpellHealingWind 8
	#define flag_SpellEnergyBeam 9

/* Poof Graphics */
#define flag_PoofDeath 0
#define flag_PoofEnergy 1
#define flag_PoofSmoke 2
#define flag_PoofSparkle 3
#define flag_PoofFire 4
#define flag_PoofBlood 5


/* Program Locations */
#define flag_Menu 1
#define flag_MenuPass 2
#define flag_MenuIP 3
#define flag_Level 10
#define flag_Dead 11
#define flag_Quit 32


/* Projectile Graphics */
#define flag_ProArrow 0
#define flag_ProSD 1
#define flag_ProBeholder 2
#define flag_ProMissile 3

/* Channel Flags. */
#define flag_ChnDefault 0
#define flag_ChnGamechat 1
#define flag_ChnTradechat 2
#define flag_ChnOptions 3
#define flag_ChnPrivateMessage 4
#define flag_ChnBroadcast 5

/* Direction Facing */
#define flag_North 2
#define flag_East 3
#define flag_South 0
#define flag_West 1

	/* Sub: Movement. */
	#define flag_NoMove 4

/* Projectile Directions */
#define flag_ProjectSouth 0
#define flag_ProjectSouthWest 1
#define flag_ProjectWest 2
#define flag_ProjectNorthWest 3
#define flag_ProjectNorth 4
#define flag_ProjectNorthEast 5
#define flag_ProjectEast 6
#define flag_ProjectSouthEast 7

/* Tile Status */
#define flag_Solid 1
#define flag_ShootThrough 2
#define flag_Walkable 3

/* Mouse Information */
#define flag_MouseNormal 1
#define flag_MouseLDown 2
#define flag_MouseRDown 3

/* Display modes for the MiniMap */
#define flag_DISMap 1
#define flag_DISEQ 0

/* Global Flags. */
#define flag_NOPARAM 30000
#define flag_Version "Build-07"

/* A* Pathfinding. */
#define flag_AStarNoGo 0
#define flag_AStarNorth 1
#define flag_AStarSouth 2
#define flag_AStarWest 3
#define flag_AStarEast 4
In C# however, not only is the #define restricted to a single file, but it only defines a symbol (I can't put the value on the end). How should I overcome this?
MaulingMonkey
MaulingMonkey
Quote:
Original post by Thevenin
In C, I had a file called cCommon.c, which stored all my flags (As you can see, I used it quite intensively in my MMORPG)
*** Source Snippet Removed ***

In C# however, not only is the #define restricted to a single file, but it only defines a symbol (I can't put the value on the end).

How should I overcome this?


Simple: stop abusing macros. Replace constants with constants, and functions with functions.

In C++, this would look like:

const size_t flag_MaxConnections = 1000;inline float flag_FRandom() { return rand() / (RAND_MAX/1.0); }inline void flag_FSetDefinition(    gaoItemDefinitionsType & gaoItemDefinitions ,    size_t index ,    lucAttackType lucAttack ,    lucDefenceType lucDefence ,    lucWalkEquipType lucWalkEquip ,    lucStackSizeType lucStackSize ,    lucClassType lucClass ){    gaoItemDefinitions[index].lucAttack = lucAttack;    gaoItemDefinitions[index].lucDefense = lucDefense;    gaoItemDefinitions[index].lucWalkEquip = lucWalkEquip;    gaoItemDefinitions[index].lucStackSize = lucStackSize;    gaoItemDefinitions[index].lucClass = lucClass ;}
Conner McCloud
Conner McCloud
The same way you're supposed to overcome it in C: using constant variables and functions as appropriate.

CM
outRider
outRider
Constants or Enums, i.e:

const uint flag_MaxConnections = 1000;

or

enum ID
{
Creature = 0,
Building = 3,
Item = 1,
Decal = 2,
Poof = 6,
Field = 7,
Projectile = 4,
};

Which can be used as ID.Creature or ID.Item
Telastyn
Telastyn
Probably a static class with public enums for the flags or const params. Something akin to [sorry no expert]:

[source lang=c#]public static class game_flags{    public enum PAK{        Movement=1,        Creatures=2,        Nothing=3,        Message=4,        //        // ...        //    }    public const string version="Build=07";    //    // ...    //}...  game_flags.PAK.Movement ...


Though the different language likely would be better with slightly different orginization than simply dumping them all together.

[edit: eep, really slow.]
Arild Fines
Arild Fines
If you absolutely want C-style macros in C#, there's nothing preventing you from running a C preprocessor on your source files as a pre-build step.
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
odi
odi
you can do something like this:
class GlobalClass{   internal static const flag_IDItem = 1;   internal static int rand()   {       //do stuff...   }  ...  ...};

and then you can access the fields without creating an instance of the class.
you can replace internal with public if you wish. [smile]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.