So for the game I'm working on, there will be events hosted on a regular basis. Anytime a player joins the stage, I want to print test in the chatbox showing them the rules. I have the code done via 2 maps, but I'd like to convert it over to an xml, that way patching is simpler (no need to patch executable, just update the xml file and patch the file containing the xml), however, I have little experience with xmls, so I was wondering if someone could give me some tips on how to do this via xml rather than hardcoding. Here's my current method for it:
std::map<string, string> EventNames;
void GetEventNames()
{
EventNames["0"] = "dodgeball";
}
std::map<string, string> EventDesc;
void GetEventDesc()
{
EventDesc["0"] = "DodgeBall rules to be decided";
}
if (uidChar == GetPlayerUID())
{
GetInterface()->GetChat()->Clear(StageChat);
char szTmp[ 256];
sprintf(szTmp, "(%03d)%s", nRoomNo, szStageName);
GetMsg( szText, MSG_JOINED_STAGE, 1, szTmp);
ChatOutput(szText, ChatType::SystemWide, StageChat);
GetEventNames();
for (auto itor = EventNames.begin(); itor != EventNames.end(); ++itor)
{
if (strstr(m_szStageName, (*itor).second.c_str()))
{
GetEventDesc();
for (auto itor = EventDesc.begin(); itor != EventDesc.end(); ++itor)
{
ChatOutput(Color(255, 255, 0), (*itor).second.c_str(), StageChat);
}
}
}
}
Update: Wrote the xml reader code after reading a bit about how xml's work, but I'm not really sure how to iterate through a list that has multiple tags with the same name (using msxml). Currently it outputs that it has all information, but if i perform a second log after the executable has initialized, it only lists one of the names, which tells me I probably need to use an iterator and go through the list to avoid overwriting any data, but I'm not quite sure how to do that with an xml.Here's the current code:
#include "stdafx.h"
#include "MEventInfo.h"
#define MTAG_EVENTINFO "EVENTINFO"
#define MTAG_EVENT "EVENT"
#define MTAG_EVENT_NAME "name"
#define MTAG_EVENT_SECONDARYNAME "secondaryname"
#define MTAG_EVENT_TERTIARYNAME "tertiaryname"
#define MTAG_EVENT_QUARTERARYNAME "quarteraryname"
#define MTAG_EVENT_OBJECTIVE "objective"
#define MTAG_EVENT_DESC "description"
MEvents::MEvents()
{
}
MEvents::~MEvents()
{
}
MEvents* MEvents::GetInstance()
{
static MEvents m_EventMgr;
return &m_EventMgr;
}
bool MEvents::ReadXml(const char* szFileName)
{
MXmlDocument xmlIniData;
xmlIniData.Create();
if (!xmlIniData.LoadFromFile(szFileName))
{
xmlIniData.Destroy();
return false;
}
MXmlElement rootElement, chrElement, attrElement;
char szTagName[256];
rootElement = xmlIniData.GetDocumentElement();
int iCount = rootElement.GetChildNodeCount();
for (int i = 0; i < iCount; i++)
{
chrElement = rootElement.GetChildNode(i);
chrElement.GetTagName(szTagName);
if (szTagName[0] == '#') continue;
if (!stricmp(szTagName, MTAG_EVENTINFO))
{
LoadEventInfo(chrElement);
}
}
xmlIniData.Destroy();
return true;
}
void MEvents::LoadEventInfo(MXmlElement& element)
{
char szAttrValue[256];
char szAttrName[64];
char szTagName[128];
int nChildCount = element.GetChildNodeCount();
MXmlElement chrElement;
for (int i = 0; i < nChildCount; i++)
{
chrElement = element.GetChildNode(i);
chrElement.GetTagName(szTagName);
if (szTagName[0] == '#') continue;
if (!stricmp(szTagName, MTAG_EVENT))
{
int nAttrCount = chrElement.GetAttributeCount();
for (int j = 0; j < nAttrCount; ++j)
{
Log(3, "%s - %s\n", szAttrName, szAttrValue); //3 = logs to a text document and logs in the gui window
chrElement.GetAttribute(j, szAttrName, szAttrValue);
if (!stricmp(szAttrName, MTAG_EVENT_NAME))
{
strEventName = szAttrValue;
}
else if (!stricmp(szAttrName, MTAG_EVENT_SECONDARYNAME))
{
strSecondaryName = szAttrValue;
}
else if (!stricmp(szAttrName, MTAG_EVENT_TERTIARYNAME))
{
strTertiaryName = szAttrValue;
}
else if (!stricmp(szAttrName, MTAG_EVENT_QUARTERARYNAME))
{
strQuarteraryName = szAttrValue;
}
else if (!stricmp(szAttrName, MTAG_EVENT_OBJECTIVE))
{
strEventObjective = szAttrValue;
}
else if (!stricmp(szAttrName, MTAG_EVENT_DESC))
{
strEventDesc = szAttrValue;
}
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire