00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00023 #include <game.h>
00024
00076
00077 chap::chap() : base("chap")
00078 {
00079 listItem = new std::vector<item>;
00080 }
00081
00083 chap::~chap()
00084 {
00085 delete listItem;
00086 }
00087
00093 int chap::init(int Id,coeur* c,IXMLReader* xmlChap)
00094 {
00095 int l;
00096
00097 l=0;
00098
00099
00100 if (!xmlChap)
00101 return -1;
00102
00103
00104 base::init(Id,c);
00105
00106 log(stringc("Chap xml : ") + stringc(Id) + " loading ...");
00107 while(xmlChap && xmlChap->read())
00108 {
00109 if (xmlChap->getNodeType()==EXN_ELEMENT)
00110 {
00111
00112 if(core::stringw("chapter") == xmlChap->getNodeName())
00113 listItem->reserve(xmlChap->getAttributeValueAsInt(L"nbr"));
00114
00115 else if(core::stringw("item") == xmlChap->getNodeName())
00116 {
00118 if ( (xmlChap->getAttributeValueAsInt(L"combi")>-1) && (xmlChap->getAttributeValueAsInt(L"combiResult")<0))
00119 log( stringc("Warning : the item") + xmlChap->getAttributeValue(L"id") + " can be combine but has no result, it is ignore");
00120 addItem(
00121 xmlChap->getAttributeValueAsInt(L"id"),
00122 stringc(xmlChap->getAttributeValue(L"texture")),
00123 xmlChap->getAttributeValueAsInt(L"combi"),
00124 xmlChap->getAttributeValueAsInt(L"combiResult")
00125 );
00126 log( stringc("New item : id:") + xmlChap->getAttributeValue(L"id") + ", texture: " + xmlChap->getAttributeValue(L"texture") + ", combi: " + xmlChap->getAttributeValue(L"combi") + ", combiResult: " + xmlChap->getAttributeValue(L"combiResult"));
00127 }
00128
00129 else if (core::stringw("lieu") == xmlChap->getNodeName())
00130 {
00131 l = xmlChap->getAttributeValueAsInt(L"id");
00132 log(stringc("Chosen lieu is ") + stringc(l));
00133 }
00134 }
00135 }
00136 return l;
00137 }
00138
00141 int chap::update()
00142 {
00143 return 0;
00144 }
00145
00148 int chap::close()
00149 {
00150 log("Closing each item :");
00151 while (! listItem->empty())
00152 {
00153 log(stringc("Deleting item ") + stringc(listItem->back().getId()));
00154 listItem->pop_back();
00155 }
00156 return base::close();
00157 }
00158
00165 item chap::addItem(int Id,stringc tex,int Combi,int CombiResult)
00166 {
00167 item Item;
00168 if (Item.init(Id,tex,Combi,CombiResult))
00169 return item();
00170 listItem->push_back(Item);
00171 log(stringc("item ") + stringc(Id) + "added");
00172 return Item;
00173 }
00174
00178 item chap::getItemFromId(int Id)
00179 {
00180 for (unsigned int i=0;i<listItem->size();i++)
00181 if (listItem->at(i).getId() == Id)
00182 return listItem->at(i);
00183 return item();
00184 }
00185
00190 bool chap::OnEvent(const SEvent& event)
00191 {
00192 return false;
00193 }
00194