00001 #include <game.h>
00002
00003 localItem::localItem()
00004 {
00005
00006 }
00007
00008 localItem::~localItem()
00009 {
00010
00011 }
00012
00013 int localItem::init(int i,stringw t,stringc p)
00014 {
00015 id = i;
00016 text = new stringw(t);
00017 path = new stringc(p);
00018 return 1;
00019 }
00020
00021 int localItem::getId()
00022 {
00023 return id;
00024 }
00025
00026
00027 stringw localItem::getText()
00028 {
00029 return *text;
00030 }
00031
00032
00033 stringc localItem::getPath()
00034 {
00035 return *path;
00036 }
00037
00038
00039
00040 local::local() : base("local")
00041 {
00042 observationMesh = new std::vector<localItem*>;
00043 observationItem = new std::vector<localItem*>;
00044 combinaison = new std::vector<localItem*>;
00045 }
00046
00047 local::~local()
00048 {
00049 delete observationMesh;
00050 delete observationItem;
00051 delete combinaison;
00052 }
00053
00054 int local::init(int i,coeur* c,IXMLReader* xmlLocal)
00055 {
00056 base::init(i,c);
00057 log(stringc("Local xml : ") + stringc(i) + " loading ...");
00058 while(xmlLocal && xmlLocal->read())
00059 {
00060 if (xmlLocal->getNodeType()==EXN_ELEMENT)
00061 {
00062 if (core::stringw("local") == xmlLocal->getNodeName())
00063 {
00064 observationMesh->reserve(xmlLocal->getAttributeValueAsInt(L"nbrobsm"));
00065 observationItem->reserve(xmlLocal->getAttributeValueAsInt(L"nbrobsi"));
00066 combinaison->reserve(xmlLocal->getAttributeValueAsInt(L"nbrcombi"));
00067 }
00068 else if (core::stringw("observationMesh") == xmlLocal->getNodeName())
00069 {
00070 addObservationMesh(xmlLocal->getAttributeValueAsInt(L"id"),xmlLocal->getAttributeValue(L"text"),xmlLocal->getAttributeValue(L"file"));
00071 log( stringc("New observationMesh text : id:") + xmlLocal->getAttributeValue(L"id") + ", text: " + xmlLocal->getAttributeValue(L"text") + ", sound file: " + xmlLocal->getAttributeValue(L"file"));
00072 }
00073 else if (core::stringw("observationItem") == xmlLocal->getNodeName())
00074 {
00075 addObservationItem(xmlLocal->getAttributeValueAsInt(L"id"),xmlLocal->getAttributeValue(L"text"),xmlLocal->getAttributeValue(L"file"));
00076 log( stringc("New observationItem text : id:") + xmlLocal->getAttributeValue(L"id") + ", text: " + xmlLocal->getAttributeValue(L"text") + ", sound file: " + xmlLocal->getAttributeValue(L"file"));
00077 }
00078 else if (core::stringw("combinaison") == xmlLocal->getNodeName())
00079 {
00080 addCombinaison(xmlLocal->getAttributeValueAsInt(L"id"),xmlLocal->getAttributeValue(L"text"),xmlLocal->getAttributeValue(L"file"));
00081 log( stringc("New combinaisonItem text : id:") + xmlLocal->getAttributeValue(L"id") + ", text: " + xmlLocal->getAttributeValue(L"text") + ", sound file: " + xmlLocal->getAttributeValue(L"file"));
00082 }
00083 else if (core::stringw("caption") == xmlLocal->getNodeName())
00084 {
00085 caption = xmlLocal->getAttributeValue(L"text");
00086 log( stringc("New caption text : ") + xmlLocal->getAttributeValue(L"text"));
00087 }
00088 }
00089 }
00090
00091
00092 return 1;
00093 }
00094
00095 int local::update()
00096 {
00097 return 1;
00098 }
00099
00100 int local::close()
00101 {
00102 log("Closing each observationMesh text");
00103 while (!observationMesh->empty())
00104 {
00105 log(stringc("Deleting observationMesh text") + stringc(observationMesh->back()->getId()));
00106 delete observationMesh->back();
00107 observationMesh->pop_back();
00108 }
00109 log("Closing each observationItem text");
00110 while (!observationItem->empty())
00111 {
00112 log(stringc("Deleting observationItem text") + stringc(observationItem->back()->getId()));
00113 delete observationItem->back();
00114 observationItem->pop_back();
00115 }
00116 log("Closing each combinaison text");
00117 while (!combinaison->empty())
00118 {
00119 log(stringc("Deleting combinaison text") + stringc(combinaison->back()->getId()));
00120 delete combinaison->back();
00121 combinaison->pop_back();
00122 }
00123 base::close();
00124 return 1;
00125 }
00126
00127 int local::addObservationMesh(int id,stringw text,stringc path)
00128 {
00129 localItem* l = new localItem();
00130 l->init(id,text,path);
00131 observationMesh->push_back(l);
00132 log("observationMesh text added");
00133 return 1;
00134 }
00135
00136 int local::addObservationItem(int id,stringw text,stringc path)
00137 {
00138 localItem* l = new localItem();
00139 l->init(id,text,path);
00140 observationItem->push_back(l);
00141 log("observationItem text added");
00142 return 1;
00143 }
00144
00145 int local::addCombinaison(int id,stringw text,stringc path)
00146 {
00147 localItem* l = new localItem();
00148 l->init(id,text,path);
00149 combinaison->push_back(l);
00150 log("combinaison text added");
00151 return 1;
00152 }
00153
00154 localItem* local::getCombinaison()
00155 {
00156 return (*combinaison)[rand()%combinaison->size()];
00157 }
00158
00159 stringw local::getCaption()
00160 {
00161 return caption;
00162 }
00163
00164 bool local::OnEvent(const SEvent& event)
00165 {
00166 return false;
00167 }
00168
00169 localItem* local::getObservationMesh(int id)
00170 {
00171 for (unsigned int i=0;i<observationMesh->size();i++)
00172 if (observationMesh->at(i)->getId() == id)
00173 {
00174 return (*observationMesh)[i];
00175 }
00176 return 0;
00177 }
00178
00179 localItem* local::getObservationItem(int id)
00180 {
00181 for (unsigned int i=0;i<observationItem->size();i++)
00182 if (observationItem->at(i)->getId() == id)
00183 {
00184 return observationItem->at(i);
00185 }
00186 return 0;
00187 }
00188