diff --git a/dmc/src/DmsInterpretationModel/Interpreter.h b/dmc/src/DmsInterpretationModel/Interpreter.h index ac3f922..f95ea9e 100644 --- a/dmc/src/DmsInterpretationModel/Interpreter.h +++ b/dmc/src/DmsInterpretationModel/Interpreter.h @@ -16,6 +16,7 @@ #include "../DmsObjects/DmsScenario.h" #include "lib/rang.hpp" +#undef max class RuntimeException: public std::exception { public: diff --git a/dmc/src/DmsInterpretationModel/Resolver.cpp b/dmc/src/DmsInterpretationModel/Resolver.cpp index 2f04f2a..2f8a0ca 100644 --- a/dmc/src/DmsInterpretationModel/Resolver.cpp +++ b/dmc/src/DmsInterpretationModel/Resolver.cpp @@ -49,7 +49,7 @@ void Resolver::resolve() { if (enemy == nullptr) { throw ResolveException(enemy_field.get_name(), ResolveException::VariableUndefined); } - encounter->addSpawner(static_cast(enemy->get_value()), enemy_field.get_value()); + encounter->add_spawner(static_cast(enemy->get_value()), static_cast(enemy_field.get_value())); } } diff --git a/dmc/src/DmsObjects/DmsCharacter.cpp b/dmc/src/DmsObjects/DmsCharacter.cpp index a84dbd1..233d30e 100644 --- a/dmc/src/DmsObjects/DmsCharacter.cpp +++ b/dmc/src/DmsObjects/DmsCharacter.cpp @@ -13,10 +13,10 @@ DmsCharacter::DmsCharacter(DmsFieldScope *enclosing_scope) bool DmsCharacter::verify() { if (field_scope.get_field("hit_chance") != nullptr) { - if (field_scope.get_field("hit_chance")->get_value() > 1.0) { - field_scope.set_field_value("hit_chance", 1.0, true); - } else if (field_scope.get_field("hit_chance")->get_value() < 0.0) { - field_scope.set_field_value("hit_chance", 0.01, true); + if (field_scope.get_field("hit_chance")->get_value() > 1.0f) { + field_scope.set_field_value("hit_chance", 1.0f, true); + } else if (field_scope.get_field("hit_chance")->get_value() < 0.0f) { + field_scope.set_field_value("hit_chance", 0.01f, true); } } diff --git a/dmc/src/DmsObjects/DmsEncounter.cpp b/dmc/src/DmsObjects/DmsEncounter.cpp index 3dcc923..2c56585 100644 --- a/dmc/src/DmsObjects/DmsEncounter.cpp +++ b/dmc/src/DmsObjects/DmsEncounter.cpp @@ -47,7 +47,7 @@ bool DmsEncounter::verify() { return true && field_scope.get_field("name") != nullptr; } -void DmsEncounter::addSpawner(DmsEnemy *enemy, int amount) { +void DmsEncounter::add_spawner(DmsEnemy *enemy, int amount) { enemies.push_back(new DmsDuplicator(enemy, amount)); } diff --git a/dmc/src/DmsObjects/DmsEncounter.h b/dmc/src/DmsObjects/DmsEncounter.h index 70343cf..076f44f 100644 --- a/dmc/src/DmsObjects/DmsEncounter.h +++ b/dmc/src/DmsObjects/DmsEncounter.h @@ -13,7 +13,7 @@ class DmsEncounter: public DmsObject { ~DmsEncounter(); bool verify(); - void addSpawner(DmsEnemy *enemy, int amount); + void add_spawner(DmsEnemy *enemy, int amount); std::vector*> getSpawners() { return enemies; } std::string serialize(); diff --git a/dmc/src/DmsObjects/DmsScenario.cpp b/dmc/src/DmsObjects/DmsScenario.cpp index 275675b..f2db937 100644 --- a/dmc/src/DmsObjects/DmsScenario.cpp +++ b/dmc/src/DmsObjects/DmsScenario.cpp @@ -46,7 +46,7 @@ bool DmsScenario::verify() { return true && field_scope.get_field("name") != nullptr; } -void DmsScenario::addEncounter(DmsEncounter *encounter, int amount) { +void DmsScenario::add_encounter(DmsEncounter *encounter, int amount) { encounters.push_back(new DmsDuplicator(encounter, amount)); } diff --git a/dmc/src/DmsObjects/DmsScenario.h b/dmc/src/DmsObjects/DmsScenario.h index 6c529b9..a3a1256 100644 --- a/dmc/src/DmsObjects/DmsScenario.h +++ b/dmc/src/DmsObjects/DmsScenario.h @@ -16,7 +16,7 @@ class DmsScenario: public DmsObject { ~DmsScenario(); bool verify(); - void addEncounter(DmsEncounter *encounter, int amount); + void add_encounter(DmsEncounter *encounter, int amount); std::vector*> getEncounters() { return encounters; } std::string serialize(); diff --git a/dmc/src/Parser.h b/dmc/src/Parser.h index 8758ef4..30fe81d 100644 --- a/dmc/src/Parser.h +++ b/dmc/src/Parser.h @@ -227,7 +227,7 @@ class Parser { field = game->constants->field_scope.get_field(token.lexem()); } - float new_value; + float new_value = 0.0f; if (field) { //value = field->get_value(); token = scanner.next_token(); @@ -277,10 +277,10 @@ class Parser { scope = current; current = nullptr; - bool isEncounter = false; + bool is_encounter = false; if (scope == game->encounters) { set_current(new DmsEncounter()); - isEncounter = true; + is_encounter = true; } else if (scope == game->scenarios) { set_current(new DmsScenario()); } else { @@ -294,7 +294,7 @@ class Parser { if (token.lexem() == "has") { token = scanner.next_token(); - if (!THING(isEncounter)) return Error; + if (!THING(is_encounter)) return Error; scope->field_scope.set_field_value(lexem, current, true); current = scope; @@ -309,16 +309,16 @@ class Parser { return Error; } - bool THING(bool isEncounter) { + bool THING(bool is_encounter) { if (token.type() == Token::Identifier) { std::string occurrence_name = token.lexem(); token = scanner.next_token(); - if (!OCCURRENCES(occurrence_name, isEncounter)) return Error; + if (!OCCURRENCES(occurrence_name, is_encounter)) return Error; if (token.lexem() == "+") { token = scanner.next_token(); - return THING(isEncounter); + return THING(is_encounter); } else { return Ok; } @@ -327,12 +327,12 @@ class Parser { return Error; } - bool OCCURRENCES(std::string occurrence_name, bool isEncounter) { + bool OCCURRENCES(std::string occurrence_name, bool is_encounter) { if (token.lexem() == "*") { token = scanner.next_token(); if (token.type() == Token::Float) { - if (isEncounter) { + if (is_encounter) { // Encounter float temp = 0; DmsField *previous = current->field_scope.get_field(occurrence_name); @@ -348,7 +348,7 @@ class Parser { } DmsEncounter *encounter = static_cast(field->get_value()); - static_cast(current)->addEncounter(encounter, std::stof(token.lexem())); + static_cast(current)->add_encounter(encounter, std::stoi(token.lexem())); } @@ -359,7 +359,7 @@ class Parser { } } - if (isEncounter) { + if (is_encounter) { // Encounter current->field_scope.set_field_value(occurrence_name, 1, true); } else { @@ -370,7 +370,7 @@ class Parser { } DmsEncounter *encounter = static_cast(field->get_value()); - static_cast(current)->addEncounter(encounter, 1); + static_cast(current)->add_encounter(encounter, 1); } return Ok; @@ -405,8 +405,8 @@ class Parser { std::string sign = token.lexem(); token = scanner.next_token(); - float new_in_value; - float new_out_value; + float new_in_value = 0.0f; + float new_out_value = 0.0f; bool ret = T(new_in_value); ret = ret && EE(new_in_value, new_out_value); if (sign == "-") { @@ -432,8 +432,8 @@ class Parser { std::string sign = token.lexem(); token = scanner.next_token(); - float new_in_value; - float new_out_value; + float new_in_value = 0.0f; + float new_out_value = 0.0f; bool ret = F(new_in_value); ret = ret && TT(new_in_value, new_out_value); @@ -442,9 +442,9 @@ class Parser { } else if (sign == "/") { out_value = in_value / new_out_value; } else if (sign == "^") { - out_value = pow(in_value, new_out_value); + out_value = std::pow(in_value, new_out_value); } else if (sign == "%") { - out_value = int(in_value) % int(new_out_value); + out_value = std::fmod(in_value, new_out_value);; } return ret;