Browse Source

Bug Fixes

iam 11 months ago
parent
commit
896bddd2a3
6 changed files with 73 additions and 40 deletions
  1. 0 3
      developper.txt
  2. 1 1
      includes/gameController.h
  3. 0 6
      irc.txt
  4. 18 5
      src/checkCondition.cpp
  5. 30 11
      src/gameController.cpp
  6. 24 14
      src/main.cpp

+ 0 - 3
developper.txt

@@ -1,3 +0,0 @@
1
-;1;
2
-    
3
-end

+ 1 - 1
includes/gameController.h

@@ -61,7 +61,7 @@ class GameController
61 61
     int addStoryline(std::string storylineName, std::string storylineData); //return index of new storyline
62 62
     
63 63
     bool sendInput(std::string input);
64
-    void getOptions(std::vector<std::string> &toReturn);
64
+    bool getOptions(std::vector<std::string> &toReturn);
65 65
     
66 66
     bool parseLine(std::string line, std::string currentCondition, std::vector<Command*> &commands); //line parsing here so it can be accessed by options and storylines
67 67
     void addCommand(std::string command, std::string condition, std::string commandType, std::vector<Command*> &commands);

+ 0 - 6
irc.txt

@@ -474,9 +474,3 @@ end
474 474
             goto: ;1.2.5.1.1;
475 475
         endoption
476 476
 end
477
-
478
-
479
-;1.2.5.2;
480
-
481
-    
482
-end

+ 18 - 5
src/checkCondition.cpp

@@ -18,6 +18,7 @@ std::string GameController::getVariableValue(std::string variable)
18 18
     for(int place = 0; place < variables.size(); place++)
19 19
         if(variables.at(place) == variable)
20 20
             return variablesValue.at(place);
21
+    return "NULL";
21 22
 }
22 23
 
23 24
 bool GameController::checkConditionGeneric(int (GameController::*getValueFunction)(std::string toSend), std::string itemString)
@@ -70,7 +71,7 @@ std::string parseConditionBoolean(std::string condition)
70 71
         if(condition[place] == '(')
71 72
             inBracket = place;
72 73
         else if(condition[place] == ')')
73
-        { 
74
+        {
74 75
             bracketCondition = condition.substr(inBracket+1, place-inBracket-1);
75 76
             condition.erase(inBracket, place-inBracket+1);
76 77
             condition.insert(inBracket, parseConditionBoolean(bracketCondition));
@@ -126,10 +127,21 @@ bool GameController::checkVariable(std::string variableString)
126 127
     std::string variableValue;
127 128
     bool found = false;
128 129
     
130
+    bool isNegate = false;
131
+    
129 132
     for(int place = 0; place < variableString.length(); place++)
130 133
     {
131
-        if(variableString[place] == '=')
134
+        if(place < variableString.length() && variableString[place] == '=' && variableString[place+1] == '=')
135
+        {
136
+            found = true;
137
+            place++;
138
+        }
139
+        else if(place < variableString.length() && variableString[place] == '!' && variableString[place+1] == '=')
140
+        {
132 141
             found = true;
142
+            isNegate = true;
143
+            place++;
144
+        }
133 145
         else if(found)
134 146
             variableValue += variableString[place];
135 147
         else
@@ -137,10 +149,11 @@ bool GameController::checkVariable(std::string variableString)
137 149
     }
138 150
     
139 151
     for(int place = 0; place < variables.size(); place++)
152
+    {
140 153
         if(variables.at(place) == variableName && variablesValue.at(place) == variableValue)
141
-            return true;
142
-    
143
-    return false;
154
+            return !isNegate;
155
+    }
156
+    return isNegate;
144 157
 }
145 158
 
146 159
 bool GameController::checkCondition(std::string condition)

+ 30 - 11
src/gameController.cpp

@@ -43,7 +43,6 @@ bool GameController::sendInput(std::string input)
43 43
         if(place->storylineName == storyline)
44 44
         {
45 45
             returnString = place->getOption(input, chooseFrom);
46
-            
47 46
             if(returnString == "")
48 47
             {
49 48
                 storyline[storyline.size()-1] = '.';
@@ -52,6 +51,7 @@ bool GameController::sendInput(std::string input)
52 51
             }
53 52
             else if(returnString[0] != ';')
54 53
             {
54
+                std::cout << returnString << " " << sessionKey << std::endl;
55 55
                 return 0;
56 56
             }
57 57
             else
@@ -62,17 +62,39 @@ bool GameController::sendInput(std::string input)
62 62
         }
63 63
 }
64 64
 
65
-void GameController::getOptions(std::vector<std::string> &toReturn)
65
+bool GameController::getOptions(std::vector<std::string> &toReturn)
66 66
 {
67
+    std::string returnString;
68
+    
67 69
     for(auto place : storylines)
68 70
         if(place->storylineName == storyline)
69 71
         {
70
-            place->displayOptions(chooseFrom, toReturn);
71
-            doCommandBlock(place->commands);
72
+            returnString = doCommandBlock(place->commands);
73
+            
74
+            //returnString is from parsing only what is found in the storyline, not the options
75
+            if(returnString == "")
76
+            {
77
+                place->displayOptions(chooseFrom, toReturn);
78
+                return 1;
79
+            }
80
+            else if(returnString[0] != ';')
81
+            {
82
+                std::cout << returnString << " " << sessionKey << std::endl;
83
+                return 0;
84
+            }
85
+            else
86
+            {
87
+                storyline = returnString;
88
+                toReturn.clear();
89
+                
90
+                //if a new storyline is found, change storylines and then parse the options for it
91
+                return getOptions(toReturn);
92
+            }
93
+            
72 94
             break;
73 95
         }
74 96
     
75
-    return;
97
+    return 1;
76 98
 }
77 99
 
78 100
 std::string GameController::doCommandBlock(std::vector<Command*> &commands)
@@ -129,8 +151,6 @@ bool GameController::parseFile(std::string fileName) //return false on error
129 151
 
130 152
 std::string doRand(std::string line)
131 153
 {
132
-    srand(time(NULL));
133
-    
134 154
     std::vector<std::string> parts;
135 155
     stringsplit('|', line, parts);
136 156
 
@@ -169,6 +189,8 @@ std::string GameController::doHealth(std::string command)
169 189
         health += stoi(amount);
170 190
     else if(type == '-')
171 191
         health -= stoi(amount);
192
+    else if(type == '=')
193
+        health = stoi(amount);
172 194
     
173 195
     if(health <= 0)
174 196
         return message;
@@ -296,10 +318,7 @@ std::string GameController::doCommand(Command* command)
296 318
         if(command->commandType == "item")
297 319
             addItem(macroCommand);
298 320
         else if(command->commandType == "endgame")
299
-        {
300
-            std::cout << macroCommand << " " << sessionKey << std::endl;
301
-            return "|";
302
-        }
321
+            return macroCommand;
303 322
         else if(command->commandType == "goto")
304 323
             return macroCommand;
305 324
         else if(command->commandType == "rand")

+ 24 - 14
src/main.cpp

@@ -4,6 +4,11 @@
4 4
 #include "gameController.h"
5 5
 #include "extras.h"
6 6
 
7
+//for random numbers
8
+#include <cstdlib>
9
+#include <time.h>
10
+#include <ctime>
11
+
7 12
 struct GameContainer
8 13
 {
9 14
     int optionNumber;
@@ -24,14 +29,19 @@ int findGamePlace(std::vector<GameContainer*> *mainGameVector, std::string gameN
24 29
 int printOptions(int gameIndex, std::vector<GameContainer*> *mainGameVector)
25 30
 {
26 31
     mainGameVector->at(gameIndex)->optionNumber = 0;
27
-    mainGameVector->at(gameIndex)->game->getOptions(mainGameVector->at(gameIndex)->optionVector);
28
-    
29
-    for(auto w : mainGameVector->at(gameIndex)->optionVector)
32
+    if(mainGameVector->at(gameIndex)->game->getOptions(mainGameVector->at(gameIndex)->optionVector))
33
+    {
34
+        for(auto w : mainGameVector->at(gameIndex)->optionVector)
35
+        {
36
+            std::cout << w << " " << mainGameVector->at(gameIndex)->sessionKey << std::endl;
37
+            //std::cout << w << std::endl;
38
+            if(w.find("    ") == 0)
39
+                mainGameVector->at(gameIndex)->optionNumber++;
40
+        }
41
+    }
42
+    else
30 43
     {
31
-        std::cout << w << " " << mainGameVector->at(gameIndex)->sessionKey << std::endl;
32
-        //std::cout << w << std::endl;
33
-        if(w.find("    ") == 0)
34
-            mainGameVector->at(gameIndex)->optionNumber++;
44
+        return -1;
35 45
     }
36 46
 }
37 47
 
@@ -55,7 +65,7 @@ std::string getUserInput(std::vector<GameContainer*> *mainGameVector, int *gameI
55 65
         std::getline(std::cin,userInput);
56 66
         
57 67
         /////
58
-        userInput += " moo|";
68
+        //userInput += " moo|";
59 69
         /////
60 70
         
61 71
         // Input is from user
@@ -128,19 +138,20 @@ std::string getUserInput(std::vector<GameContainer*> *mainGameVector, int *gameI
128 138
 
129 139
 int main()
130 140
 {
141
+    srand(time(NULL));
142
+    
131 143
     std::vector<GameContainer*> mainGameVector;
132 144
     
133 145
     std::string userInput;
134 146
     int gameIndex;
135
-    
136
-    
147
+    /*
137 148
     mainGameVector.push_back(new GameContainer);
138 149
     mainGameVector.at(mainGameVector.size()-1)->game = new GameController("moo"); //moo
139 150
     mainGameVector.at(mainGameVector.size()-1)->sessionKey = "moo"; //moo
140 151
     mainGameVector.at(mainGameVector.size()-1)->game->parseFile("developper.txt"); //game.txt
141 152
     mainGameVector.at(mainGameVector.size()-1)->game->storyline = ";1;"; //;setup;
142 153
     printOptions(mainGameVector.size()-1, &mainGameVector);
143
-    
154
+    */
144 155
     
145 156
     while(true)
146 157
     {
@@ -148,15 +159,14 @@ int main()
148 159
         
149 160
         userInput = getUserInput(&mainGameVector, &gameIndex);
150 161
         
151
-        if(!mainGameVector.at(gameIndex)->game->sendInput(userInput))
162
+        //sendInput returns false if game ends from inside an option. if printOptions returns -1, game end was found when parsing storyline
163
+        if(!mainGameVector.at(gameIndex)->game->sendInput(userInput) || printOptions(gameIndex, &mainGameVector) == -1)
152 164
         {
153 165
             std::cout << "DEATH " << mainGameVector.at(gameIndex)->sessionKey << std::endl;
154 166
             delete mainGameVector.at(gameIndex)->game;
155 167
             delete mainGameVector.at(gameIndex);
156 168
             mainGameVector.erase(mainGameVector.begin() + gameIndex);
157 169
         }
158
-        else
159
-            printOptions(gameIndex, &mainGameVector);
160 170
     }
161 171
     
162 172
     return 0;