Skip to content

Commit

Permalink
-Added LaunchedFrom property to ValueRef and parser.
Browse files Browse the repository at this point in the history
-Made Attack property return a fighter's damage in Variable<double>::Eval.
-Made Species property return a fighter's species in Variable<std::string>::Eval
  • Loading branch information
geoffthemedio committed Oct 21, 2018
1 parent 942539e commit d62cfa5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions parse/IntValueRefParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ parse::detail::simple_int_parser_rules::simple_int_parser_rules(const parse::lex
| tok.SpeciesID_
| tok.TurnsSinceFocusChange_
| tok.ETA_
| tok.LaunchedFrom_
;

free_variable_name
Expand Down
1 change: 1 addition & 0 deletions parse/Tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
(LastTurnBattleHere) \
(LastTurnConquered) \
(LastTurnResupplied) \
(LaunchedFrom) \
(LeastHappySpecies) \
(LocalCandidate) \
(Location) \
Expand Down
12 changes: 12 additions & 0 deletions universe/ValueRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "Species.h"
#include "System.h"
#include "Field.h"
#include "Fighter.h"
#include "Pathfinder.h"
#include "Universe.h"
#include "UniverseObject.h"
Expand Down Expand Up @@ -828,6 +829,8 @@ double Variable<double>::Eval(const ScriptingContext& context) const
return fleet->Damage();
if (auto ship = std::dynamic_pointer_cast<const Ship>(object))
return ship->TotalWeaponsDamage();
if (auto fighter = std::dynamic_pointer_cast<const Fighter>(object))
return fighter->Damage();

} else if (property_name == "PropagatedSupplyRange") {
const auto& ranges = GetSupplyManager().PropagatedSupplyRanges();
Expand Down Expand Up @@ -1079,6 +1082,13 @@ int Variable<int>::Eval(const ScriptingContext& context) const
}
else if (property_name == "NumSpecials") {
return object->Specials().size();

}
else if (property_name == "LaunchedFrom") {
if (auto fighter = std::dynamic_pointer_cast<const Fighter>(object))
return fighter->LaunchedFrom();
else
return INVALID_OBJECT_ID;
}

ErrorLogger() << "Variable<int>::Eval unrecognized object property: " << TraceReference(m_property_name, m_ref_type, context);
Expand Down Expand Up @@ -1207,6 +1217,8 @@ std::string Variable<std::string>::Eval(const ScriptingContext& context) const
return planet->SpeciesName();
else if (auto ship = std::dynamic_pointer_cast<const Ship>(object))
return ship->SpeciesName();
else if (auto fighter = std::dynamic_pointer_cast<const Fighter>(object))
return fighter->SpeciesName();

} else if (property_name == "Hull") {
if (auto ship = std::dynamic_pointer_cast<const Ship>(object))
Expand Down

0 comments on commit d62cfa5

Please sign in to comment.