Triggers now adapt if the object they want to do something with gets deleted or changes its index.

This commit is contained in:
Steffen Fündgens 2015-01-13 18:18:13 +01:00
parent f4408b76e8
commit a137d2544a
5 changed files with 36 additions and 25 deletions

View File

@ -21,8 +21,8 @@
<isBiggerThan>false</isBiggerThan> <isBiggerThan>false</isBiggerThan>
<objectNum>0</objectNum> <objectNum>0</objectNum>
<luaScript>deleteRandomObject</luaScript> <luaScript>deleteRandomObject</luaScript>
<toChangeIdGreen>1</toChangeIdGreen> <toChangeIdGreen>0</toChangeIdGreen>
<toChangeIdBlue>5</toChangeIdBlue> <toChangeIdBlue>0</toChangeIdBlue>
<toChangeObjNum>0</toChangeObjNum> <toChangeObjNum>0</toChangeObjNum>
</trigger> </trigger>
<trigger> <trigger>
@ -65,9 +65,9 @@
<isBiggerThan>false</isBiggerThan> <isBiggerThan>false</isBiggerThan>
<objectNum>0</objectNum> <objectNum>0</objectNum>
<luaScript>-</luaScript> <luaScript>-</luaScript>
<toChangeIdGreen>-</toChangeIdGreen> <toChangeIdGreen>0</toChangeIdGreen>
<toChangeIdBlue>-</toChangeIdBlue> <toChangeIdBlue>0</toChangeIdBlue>
<toChangeObjNum>-</toChangeObjNum> <toChangeObjNum>0</toChangeObjNum>
</trigger> </trigger>
</composition> </composition>
@ -94,9 +94,9 @@
<isBiggerThan>false</isBiggerThan> <isBiggerThan>false</isBiggerThan>
<objectNum>0</objectNum> <objectNum>0</objectNum>
<luaScript>-</luaScript> <luaScript>-</luaScript>
<toChangeIdGreen>-</toChangeIdGreen> <toChangeIdGreen>0</toChangeIdGreen>
<toChangeIdBlue>-</toChangeIdBlue> <toChangeIdBlue>0</toChangeIdBlue>
<toChangeObjNum>-</toChangeObjNum> <toChangeObjNum>0</toChangeObjNum>
</trigger> </trigger>
</composition> </composition>
@ -123,9 +123,9 @@
<isBiggerThan>false</isBiggerThan> <isBiggerThan>false</isBiggerThan>
<objectNum>0</objectNum> <objectNum>0</objectNum>
<luaScript>-</luaScript> <luaScript>-</luaScript>
<toChangeIdGreen>-</toChangeIdGreen> <toChangeIdGreen>0</toChangeIdGreen>
<toChangeIdBlue>-</toChangeIdBlue> <toChangeIdBlue>0</toChangeIdBlue>
<toChangeObjNum>-</toChangeObjNum> <toChangeObjNum>0</toChangeObjNum>
</trigger> </trigger>
</composition> </composition>
@ -152,9 +152,9 @@
<isBiggerThan>false</isBiggerThan> <isBiggerThan>false</isBiggerThan>
<objectNum>0</objectNum> <objectNum>0</objectNum>
<luaScript>-</luaScript> <luaScript>-</luaScript>
<toChangeIdGreen>-</toChangeIdGreen> <toChangeIdGreen>0</toChangeIdGreen>
<toChangeIdBlue>-</toChangeIdBlue> <toChangeIdBlue>0</toChangeIdBlue>
<toChangeObjNum>-</toChangeObjNum> <toChangeObjNum>0</toChangeObjNum>
</trigger> </trigger>
</composition> </composition>

View File

@ -194,9 +194,9 @@ std::vector<int> Converter::newComposition(int type, float posX, float posZ){
isBiggerThan->SetText("false"); isBiggerThan->SetText("false");
objectNum->SetText("0"); objectNum->SetText("0");
luaScript->SetText("-"); luaScript->SetText("-");
toChangeIdGreen->SetText("-"); toChangeIdGreen->SetText("0");
toChangeIdBlue->SetText("-"); toChangeIdBlue->SetText("0");
toChangeObjNum->SetText("-"); toChangeObjNum->SetText("0");
trigger->InsertEndChild(name); trigger->InsertEndChild(name);
trigger->InsertEndChild(xPosition); trigger->InsertEndChild(xPosition);

View File

@ -365,7 +365,7 @@ void Level::load() {
} }
std::string luaScript = charLuaScript; std::string luaScript = charLuaScript;
int toChangeIdGreen, toChangeIdBlue, toChangeObjNum, objectToChange=0; int toChangeIdGreen, toChangeIdBlue, toChangeObjNum, objectToChange=-1;
errorCheck(xmlTrigger->FirstChildElement("toChangeIdGreen")->QueryIntText(&toChangeIdGreen)); errorCheck(xmlTrigger->FirstChildElement("toChangeIdGreen")->QueryIntText(&toChangeIdGreen));
errorCheck(xmlTrigger->FirstChildElement("toChangeIdBlue")->QueryIntText(&toChangeIdBlue)); errorCheck(xmlTrigger->FirstChildElement("toChangeIdBlue")->QueryIntText(&toChangeIdBlue));
errorCheck(xmlTrigger->FirstChildElement("toChangeObjNum")->QueryIntText(&toChangeObjNum)); errorCheck(xmlTrigger->FirstChildElement("toChangeObjNum")->QueryIntText(&toChangeObjNum));
@ -375,13 +375,8 @@ void Level::load() {
} }
} }
if (object != 0) { if (object != 0) {
if (objectToChange != 0) { Trigger trigger = Trigger(position, distance, isBigger, object, luaScript, L, objectToChange);
Trigger trigger = Trigger(position, distance, isBigger, object, luaScript, L, objectToChange); triggers.push_back(trigger);
triggers.push_back(trigger);
}
else {
printf("Object to be changed by a trigger not found.\n");
}
} }
else { else {
printf("Triggering object not found.\n"); printf("Triggering object not found.\n");
@ -484,6 +479,11 @@ std::vector<Object*>* Level::getObjects() {
void Level::deleteObject(int objectIndex){ void Level::deleteObject(int objectIndex){
objects.erase(objects.begin() + objectIndex); objects.erase(objects.begin() + objectIndex);
for(unsigned int i = 0; i<triggers.size(); i++) {
if(triggers.at(i).deleteNotification(objectIndex)){
triggers.erase(triggers.begin() + i);
}
}
} }
int Level::getObjectCount(){ int Level::getObjectCount(){

View File

@ -34,3 +34,13 @@ void Trigger::triggerUpdate(){
} }
} }
} }
bool Trigger::deleteNotification(int deletedObjectIndex){
if (deletedObjectIndex < objectToChange){
objectToChange-=1;
}
if (deletedObjectIndex == objectToChange){
return true;
}
return false;
}

View File

@ -18,6 +18,7 @@ class Trigger {
Trigger(); Trigger();
~Trigger(); ~Trigger();
void triggerUpdate(); void triggerUpdate();
bool deleteNotification(int deletedObjectIndex);
private: private:
glm::vec3 position; glm::vec3 position;
float distance; float distance;