4 * Created on: Aug 26, 2012
8 #include "Interpreter.h"
10 #include "ParsedSource.h"
11 #include "../battle/Hero.h"
12 #include "../battle/Monster.h"
13 #include "../battle/PartyLayout.h"
14 #include "../common/Ikari.h"
15 #include "../common/Item.h"
16 #include "../common/Spell.h"
17 #include "../common/TargetingMode.h"
18 #include "../graphics/ComplexAnimation.h"
19 #include "../graphics/Font.h"
20 #include "../graphics/Frame.h"
21 #include "../graphics/Gauge.h"
22 #include "../graphics/SimpleAnimation.h"
23 #include "../graphics/Sprite.h"
27 #include <SDL_image.h>
30 using battle::Monster;
31 using battle::PartyLayout;
36 using common::TargetingMode;
37 using graphics::Animation;
38 using graphics::Color;
40 using graphics::Frame;
41 using graphics::Gauge;
42 using graphics::ComplexAnimation;
43 using graphics::SimpleAnimation;
44 using graphics::Sprite;
45 using geometry::Vector;
54 Interpreter::~Interpreter() {
55 for (vector<ComplexAnimation *>::const_iterator i(complexAnimations.begin()), end(complexAnimations.end()); i != end; ++i) {
58 for (vector<Font *>::const_iterator i(fonts.begin()), end(fonts.end()); i != end; ++i) {
61 for (vector<Frame *>::const_iterator i(frames.begin()), end(frames.end()); i != end; ++i) {
64 for (vector<Gauge *>::const_iterator i(gauges.begin()), end(gauges.end()); i != end; ++i) {
67 for (vector<Hero *>::const_iterator i(heroes.begin()), end(heroes.end()); i != end; ++i) {
70 for (vector<Ikari *>::const_iterator i(ikaris.begin()), end(ikaris.end()); i != end; ++i) {
73 for (vector<SDL_Surface *>::const_iterator i(images.begin()), end(images.end()); i != end; ++i) {
76 for (vector<Item *>::const_iterator i(items.begin()), end(items.end()); i != end; ++i) {
79 for (vector<Monster *>::const_iterator i(monsters.begin()), end(monsters.end()); i != end; ++i) {
82 for (vector<PartyLayout *>::const_iterator i(partyLayouts.begin()), end(partyLayouts.end()); i != end; ++i) {
85 for (vector<SimpleAnimation *>::const_iterator i(simpleAnimations.begin()), end(simpleAnimations.end()); i != end; ++i) {
88 for (vector<Spell *>::const_iterator i(spells.begin()), end(spells.end()); i != end; ++i) {
91 for (vector<Sprite *>::const_iterator i(sprites.begin()), end(sprites.end()); i != end; ++i) {
94 for (vector<const char *>::const_iterator i(strings.begin()), end(strings.end()); i != end; ++i) {
97 for (vector<TargetingMode *>::const_iterator i(targetingModes.begin()), end(targetingModes.end()); i != end; ++i) {
103 Animation *Interpreter::GetAnimation(const std::string &name) {
104 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
105 if (i != parsedDefinitions.end()) {
106 if (i->second.type == COMPLEX_ANIMATION) {
107 return complexAnimations[i->second.index];
108 } else if (i->second.type == SIMPLE_ANIMATION) {
109 return simpleAnimations[i->second.index];
111 throw Error("cannot cast " + i->second.dfn->TypeName() + " to Animation");
114 throw Error("access to undefined Animation " + name);
118 bool Interpreter::GetBoolean(const std::string &name) const {
119 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
120 if (i != parsedDefinitions.end()) {
121 if (i->second.type == BOOLEAN) {
122 return booleans[i->second.index];
124 throw Error("cannot cast " + i->second.dfn->TypeName() + " to Boolean");
127 throw Error("access to undefined Boolean " + name);
131 const Color &Interpreter::GetColor(const std::string &name) const {
132 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
133 if (i != parsedDefinitions.end()) {
134 if (i->second.type == COLOR) {
135 return colors[i->second.index];
137 throw Error("cannot cast " + i->second.dfn->TypeName() + " to Color");
140 throw Error("access to undefined Color " + name);
144 Font *Interpreter::GetFont(const std::string &name) {
145 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
146 if (i != parsedDefinitions.end()) {
147 if (i->second.type == FONT) {
148 return fonts[i->second.index];
150 throw Error("cannot cast " + i->second.dfn->TypeName() + " to Font");
153 throw Error("access to undefined Font " + name);
157 Frame *Interpreter::GetFrame(const std::string &name) {
158 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
159 if (i != parsedDefinitions.end()) {
160 if (i->second.type == FRAME) {
161 return frames[i->second.index];
163 throw Error("cannot cast " + i->second.dfn->TypeName() + " to Frame");
166 throw Error("access to undefined Frame " + name);
170 Gauge *Interpreter::GetGauge(const std::string &name) {
171 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
172 if (i != parsedDefinitions.end()) {
173 if (i->second.type == GAUGE) {
174 return gauges[i->second.index];
176 throw Error("cannot cast " + i->second.dfn->TypeName() + " to Gauge");
179 throw Error("access to undefined Gauge " + name);
183 Hero *Interpreter::GetHero(const std::string &name) {
184 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
185 if (i != parsedDefinitions.end()) {
186 if (i->second.type == HERO) {
187 return heroes[i->second.index];
189 throw Error("cannot cast " + i->second.dfn->TypeName() + " to Hero");
192 throw Error("access to undefined Hero " + name);
196 Ikari *Interpreter::GetIkari(const std::string &name) {
197 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
198 if (i != parsedDefinitions.end()) {
199 if (i->second.type == IKARI) {
200 return ikaris[i->second.index];
202 throw Error("cannot cast " + i->second.dfn->TypeName() + " to Ikari");
205 throw Error("access to undefined Ikari " + name);
209 Item *Interpreter::GetItem(const std::string &name) {
210 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
211 if (i != parsedDefinitions.end()) {
212 if (i->second.type == ITEM) {
213 return items[i->second.index];
215 throw Error("cannot cast " + i->second.dfn->TypeName() + " to Item");
218 throw Error("access to undefined Item " + name);
222 Monster *Interpreter::GetMonster(const std::string &name) {
223 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
224 if (i != parsedDefinitions.end()) {
225 if (i->second.type == MONSTER) {
226 return monsters[i->second.index];
228 throw Error("cannot cast " + i->second.dfn->TypeName() + " to Monster");
231 throw Error("access to undefined Monster " + name);
235 int Interpreter::GetNumber(const std::string &name) const {
236 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
237 if (i != parsedDefinitions.end()) {
238 if (i->second.type == NUMBER) {
239 return numbers[i->second.index];
241 throw Error("cannot cast " + i->second.dfn->TypeName() + " to Number");
244 throw Error("access to undefined Number " + name);
248 PartyLayout *Interpreter::GetPartyLayout(const std::string &name) {
249 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
250 if (i != parsedDefinitions.end()) {
251 if (i->second.type == PARTY_LAYOUT) {
252 return partyLayouts[i->second.index];
254 throw Error("cannot cast " + i->second.dfn->TypeName() + " to PartyLayout");
257 throw Error("access to undefined PartyLayout " + name);
261 const char *Interpreter::GetPath(const std::string &name) const {
262 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
263 if (i != parsedDefinitions.end()) {
264 if (i->second.type == PATH) {
265 return strings[i->second.index];
267 throw Error("cannot cast " + i->second.dfn->TypeName() + " to Path");
270 throw Error("access to undefined Path " + name);
274 Spell *Interpreter::GetSpell(const std::string &name) {
275 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
276 if (i != parsedDefinitions.end()) {
277 if (i->second.type == SPELL) {
278 return spells[i->second.index];
280 throw Error("cannot cast " + i->second.dfn->TypeName() + " to Spell");
283 throw Error("access to undefined Spell " + name);
287 Sprite *Interpreter::GetSprite(const std::string &name) {
288 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
289 if (i != parsedDefinitions.end()) {
290 if (i->second.type == SPRITE) {
291 return sprites[i->second.index];
293 throw Error("cannot cast " + i->second.dfn->TypeName() + " to Sprite");
296 throw Error("access to undefined Sprite " + name);
300 const char *Interpreter::GetString(const std::string &name) const {
301 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
302 if (i != parsedDefinitions.end()) {
303 // TODO: enable path to string casting some time
304 if (i->second.type == STRING /* || i->second.type == PATH */) {
305 return strings[i->second.index];
307 throw Error("cannot cast " + i->second.dfn->TypeName() + " to String");
310 throw Error("access to undefined String " + name);
314 TargetingMode *Interpreter::GetTargetingMode(const std::string &name) {
315 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
316 if (i != parsedDefinitions.end()) {
317 if (i->second.type == TARGETING_MODE) {
318 return targetingModes[i->second.index];
320 throw Error("cannot cast " + i->second.dfn->TypeName() + " to TargetingMode");
323 throw Error("access to undefined TargetingMode " + name);
327 Vector<int> Interpreter::GetVector(const std::string &name) const {
328 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
329 if (i != parsedDefinitions.end()) {
330 if (i->second.type == VECTOR) {
331 return vectors[i->second.index];
333 throw Error("cannot cast " + i->second.dfn->TypeName() + " to Vector");
336 throw Error("access to undefined Vector " + name);
341 void Interpreter::ReadSource() {
342 for (set<string>::const_iterator i(source.Exports().begin()), end(source.Exports().end()); i != end; ++i) {
343 ReadDefinition(source.GetDefinition(*i));
347 void Interpreter::ReadDefinition(const Definition &dfn) {
348 if (parsedDefinitions.find(dfn.Identifier()) != parsedDefinitions.end()) {
351 if (dfn.HasLiteralValue()) {
358 void Interpreter::ReadLiteral(const Definition &dfn) {
359 switch (dfn.GetLiteral()->GetType()) {
360 case Literal::ARRAY_VALUES:
361 valueArrays.push_back(dfn.GetLiteral()->GetValues());
362 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, VALUE_ARRAY, valueArrays.size() - 1)));
364 case Literal::ARRAY_PROPS:
365 propertyListArrays.push_back(dfn.GetLiteral()->GetPropertyLists());
366 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, PROPERTY_LIST_ARRAY, propertyListArrays.size() - 1)));
368 case Literal::BOOLEAN:
369 booleans.push_back(dfn.GetLiteral()->GetBoolean());
370 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, BOOLEAN, booleans.size() - 1)));
373 colors.push_back(Color(dfn.GetLiteral()->GetRed(), dfn.GetLiteral()->GetGreen(), dfn.GetLiteral()->GetBlue(), dfn.GetLiteral()->GetAlpha()));
374 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, COLOR, colors.size() - 1)));
376 case Literal::NUMBER:
377 numbers.push_back(dfn.GetLiteral()->GetNumber());
378 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, NUMBER, numbers.size() - 1)));
382 char *str(new char[dfn.GetLiteral()->GetString().size() + 1]);
383 std::memcpy(str, dfn.GetLiteral()->GetString().c_str(), dfn.GetLiteral()->GetString().size());
384 str[dfn.GetLiteral()->GetString().size()] = '\0';
385 strings.push_back(str);
387 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, PATH, strings.size() - 1)));
389 case Literal::STRING:
391 char *str(new char[dfn.GetLiteral()->GetString().size() + 1]);
392 std::memcpy(str, dfn.GetLiteral()->GetString().c_str(), dfn.GetLiteral()->GetString().size());
393 str[dfn.GetLiteral()->GetString().size()] = '\0';
394 strings.push_back(str);
396 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, STRING, strings.size() - 1)));
398 case Literal::VECTOR:
399 vectors.push_back(Vector<int>(dfn.GetLiteral()->GetX(), dfn.GetLiteral()->GetY()));
400 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, VECTOR, vectors.size() - 1)));
402 case Literal::OBJECT:
408 Animation *Interpreter::GetAnimation(const Value &v) {
410 if (v.GetLiteral().GetTypeName() == "ComplexAnimation") {
411 ComplexAnimation *a(new ComplexAnimation);
412 ReadComplexAnimation(*a, *v.GetLiteral().GetProperties());
413 complexAnimations.push_back(a);
416 SimpleAnimation *a(new SimpleAnimation);
417 ReadSimpleAnimation(*a, *v.GetLiteral().GetProperties());
418 simpleAnimations.push_back(a);
422 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
423 return GetAnimation(v.GetIdentifier());
427 bool Interpreter::GetBoolean(const Value &v) {
429 return v.GetLiteral().GetBoolean();
431 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
432 return GetBoolean(v.GetIdentifier());
436 Color Interpreter::GetColor(const Value &v) {
438 return Color(v.GetLiteral().GetRed(), v.GetLiteral().GetGreen(), v.GetLiteral().GetBlue(), v.GetLiteral().GetAlpha());
440 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
441 return GetColor(v.GetIdentifier());
445 Font *Interpreter::GetFont(const Value &v) {
448 ReadFont(*f, *v.GetLiteral().GetProperties());
451 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
452 return GetFont(v.GetIdentifier());
456 Frame *Interpreter::GetFrame(const Value &v) {
459 ReadFrame(*f, *v.GetLiteral().GetProperties());
462 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
463 return GetFrame(v.GetIdentifier());
467 Gauge *Interpreter::GetGauge(const Value &v) {
470 ReadGauge(*g, *v.GetLiteral().GetProperties());
473 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
474 return GetGauge(v.GetIdentifier());
478 Hero *Interpreter::GetHero(const Value &v) {
481 ReadHero(*h, *v.GetLiteral().GetProperties());
484 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
485 return GetHero(v.GetIdentifier());
489 Ikari *Interpreter::GetIkari(const Value &v) {
492 ReadIkari(*i, *v.GetLiteral().GetProperties());
495 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
496 return GetIkari(v.GetIdentifier());
500 SDL_Surface *Interpreter::GetImage(const Value &v) {
501 string path(GetPath(v));
502 map<string, SDL_Surface *>::const_iterator i(imageCache.find(path));
503 if (i == imageCache.end()) {
504 SDL_Surface *image(IMG_Load(path.c_str()));
505 images.push_back(image);
506 imageCache.insert(make_pair(path, image));
513 Item *Interpreter::GetItem(const Value &v) {
516 ReadItem(*i, *v.GetLiteral().GetProperties());
519 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
520 return GetItem(v.GetIdentifier());
524 int Interpreter::GetNumber(const Value &v) {
526 return v.GetLiteral().GetNumber();
528 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
529 return GetNumber(v.GetIdentifier());
533 PartyLayout *Interpreter::GetPartyLayout(const Value &v) {
535 PartyLayout *l(new PartyLayout);
536 ReadPartyLayout(*l, *v.GetLiteral().GetProperties());
539 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
540 return GetPartyLayout(v.GetIdentifier());
544 const char *Interpreter::GetPath(const Value &v) {
546 return v.GetLiteral().GetString().c_str();
548 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
549 return GetPath(v.GetIdentifier());
553 const PropertyList *Interpreter::GetPropertyList(const Value &v) {
555 return v.GetLiteral().GetProperties();
557 throw Error("cannot reference property lists");
561 const vector<PropertyList *> &Interpreter::GetPropertyListArray(const Value &v) {
563 return v.GetLiteral().GetPropertyLists();
565 throw Error("cannot reference property list arrays");
569 Spell *Interpreter::GetSpell(const Value &v) {
572 ReadSpell(*s, *v.GetLiteral().GetProperties());
575 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
576 return GetSpell(v.GetIdentifier());
580 Sprite *Interpreter::GetSprite(const Value &v) {
582 Sprite *s(new Sprite);
583 ReadSprite(*s, *v.GetLiteral().GetProperties());
586 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
587 return GetSprite(v.GetIdentifier());
591 const char *Interpreter::GetString(const Value &v) {
593 return v.GetLiteral().GetString().c_str();
595 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
596 return GetString(v.GetIdentifier());
600 TargetingMode *Interpreter::GetTargetingMode(const Value &v) {
602 TargetingMode *t(new TargetingMode);
603 ReadTargetingMode(*t, *v.GetLiteral().GetProperties());
606 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
607 return GetTargetingMode(v.GetIdentifier());
611 Vector<int> Interpreter::GetVector(const Value &v) {
613 return Vector<int>(v.GetLiteral().GetX(), v.GetLiteral().GetY());
615 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
616 return GetVector(v.GetIdentifier());
620 const vector<Value *> &Interpreter::GetValueArray(const Value &v) {
622 return v.GetLiteral().GetValues();
624 throw Error("cannot reference value arrays");
629 void Interpreter::ReadObject(const Definition &dfn) {
630 if (dfn.TypeName() == "ComplexAnimation") {
631 ComplexAnimation *animation(new ComplexAnimation);
632 int index(complexAnimations.size());
633 complexAnimations.push_back(animation);
634 ReadComplexAnimation(*animation, *dfn.GetProperties());
635 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, COMPLEX_ANIMATION, index)));
636 } else if (dfn.TypeName() == "Font") {
637 Font *font(new Font);
638 int index(fonts.size());
639 fonts.push_back(font);
640 ReadFont(*font, *dfn.GetProperties());
641 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, FONT, index)));
642 } else if (dfn.TypeName() == "Frame") {
643 Frame *frame(new Frame);
644 int index(frames.size());
645 frames.push_back(frame);
646 ReadFrame(*frame, *dfn.GetProperties());
647 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, FRAME, index)));
648 } else if (dfn.TypeName() == "Gauge") {
649 Gauge *gauge(new Gauge);
650 int index(gauges.size());
651 gauges.push_back(gauge);
652 ReadGauge(*gauge, *dfn.GetProperties());
653 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, GAUGE, index)));
654 } else if (dfn.TypeName() == "Hero") {
655 Hero *hero(new Hero);
656 int index(heroes.size());
657 heroes.push_back(hero);
658 ReadHero(*hero, *dfn.GetProperties());
659 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, HERO, index)));
660 } else if (dfn.TypeName() == "Ikari") {
661 Ikari *ikari(new Ikari);
662 int index(ikaris.size());
663 ikaris.push_back(ikari);
664 ReadIkari(*ikari, *dfn.GetProperties());
665 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, IKARI, index)));
666 } else if (dfn.TypeName() == "Item") {
667 Item *item(new Item);
668 int index(items.size());
669 items.push_back(item);
670 ReadItem(*item, *dfn.GetProperties());
671 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, ITEM, index)));
672 } else if (dfn.TypeName() == "Monster") {
673 Monster *monster(new Monster);
674 int index(monsters.size());
675 monsters.push_back(monster);
676 ReadMonster(*monster, *dfn.GetProperties());
677 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, MONSTER, index)));
678 } else if (dfn.TypeName() == "PartyLayout") {
679 PartyLayout *layout(new PartyLayout);
680 int index(partyLayouts.size());
681 partyLayouts.push_back(layout);
682 ReadPartyLayout(*layout, *dfn.GetProperties());
683 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, PARTY_LAYOUT, index)));
684 } else if (dfn.TypeName() == "SimpleAnimation") {
685 SimpleAnimation *animation(new SimpleAnimation);
686 int index(simpleAnimations.size());
687 simpleAnimations.push_back(animation);
688 ReadSimpleAnimation(*animation, *dfn.GetProperties());
689 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, SIMPLE_ANIMATION, index)));
690 } else if (dfn.TypeName() == "Spell") {
691 Spell *spell(new Spell);
692 int index(spells.size());
693 spells.push_back(spell);
694 ReadSpell(*spell, *dfn.GetProperties());
695 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, SPELL, index)));
696 } else if (dfn.TypeName() == "Sprite") {
697 Sprite *sprite(new Sprite);
698 int index(sprites.size());
699 sprites.push_back(sprite);
700 ReadSprite(*sprite, *dfn.GetProperties());
701 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, SPRITE, index)));
702 } else if (dfn.TypeName() == "TargetingMode") {
703 TargetingMode *mode(new TargetingMode);
704 int index(targetingModes.size());
705 targetingModes.push_back(mode);
706 ReadTargetingMode(*mode, *dfn.GetProperties());
707 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, TARGETING_MODE, index)));
709 throw Error("unhandled object type: " + dfn.TypeName());
714 void Interpreter::ReadComplexAnimation(ComplexAnimation &a, const PropertyList &props) {
715 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
716 if (i->first == "sprite") {
717 a.SetSprite(GetSprite(*i->second));
718 } else if (i->first == "frametime") {
719 a.SetFrameTime(GetNumber(*i->second));
720 } else if (i->first == "repeat") {
721 a.SetRepeat(GetBoolean(*i->second));
722 } else if (i->first == "frames") {
723 const vector<PropertyList *> &values(GetPropertyListArray(*i->second));
724 for (vector<PropertyList *>::const_iterator i(values.begin()), end(values.end()); i != end; ++i) {
725 ComplexAnimation::FrameProp frame;
726 ReadComplexAnimationFrame(frame, **i);
730 throw Error("unknown ComplexAnimation property: " + i->first);
735 void Interpreter::ReadComplexAnimationFrame(ComplexAnimation::FrameProp &f, const PropertyList &props) {
736 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
737 if (i->first == "column") {
738 f.col = GetNumber(*i->second);
739 } else if (i->first == "row") {
740 f.row = GetNumber(*i->second);
741 } else if (i->first == "disposition") {
742 f.disposition = GetVector(*i->second);
744 throw Error("unknown ComplexAnimationFrame property: " + i->first);
749 void Interpreter::ReadFont(Font &f, const PropertyList &props) {
750 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
751 if (i->first == "sprite") {
752 f.SetSprite(GetSprite(*i->second));
753 } else if (i->first == "columnoffset") {
754 f.SetColOffset(GetNumber(*i->second));
755 } else if (i->first == "rowoffset") {
756 f.SetRowOffset(GetNumber(*i->second));
758 throw Error("unknown Font property: " + i->first);
763 void Interpreter::ReadFrame(Frame &f, const PropertyList &props) {
764 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
765 if (i->first == "image") {
766 f.SetSurface(GetImage(*i->second));
767 } else if (i->first == "border") {
768 f.SetBorderSize(GetVector(*i->second));
769 } else if (i->first == "repeat") {
770 f.SetRepeatSize(GetVector(*i->second));
771 } else if (i->first == "offset") {
772 f.SetOffset(GetVector(*i->second));
774 throw Error("unknown Frame property: " + i->first);
779 void Interpreter::ReadGauge(Gauge &g, const PropertyList &props) {
780 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
781 if (i->first == "image") {
782 g.SetSurface(GetImage(*i->second));
783 } else if (i->first == "full") {
784 g.SetFullOffset(GetVector(*i->second));
785 } else if (i->first == "empty") {
786 g.SetEmptyOffset(GetVector(*i->second));
787 } else if (i->first == "height") {
788 g.SetHeight(GetNumber(*i->second));
789 } else if (i->first == "start") {
790 g.SetStartWidth(GetNumber(*i->second));
791 } else if (i->first == "repeat") {
792 g.SetRepeatWidth(GetNumber(*i->second));
793 } else if (i->first == "end") {
794 g.SetEndWidth(GetNumber(*i->second));
796 throw Error("unknown Gauge property: " + i->first);
801 void Interpreter::ReadIkari(Ikari &ikari, const PropertyList &props) {
802 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
803 if (i->first == "name") {
804 ikari.SetName(GetString(*i->second));
805 } else if (i->first == "cost") {
806 ikari.SetCost(GetNumber(*i->second));
807 } else if (i->first == "targets") {
808 ikari.GetTargetingMode() = *GetTargetingMode(*i->second);
809 } else if (i->first == "magical") {
810 if (GetBoolean(*i->second)) {
813 } else if (i->first == "physical") {
814 if (GetBoolean(*i->second)) {
818 throw Error("unknown Ikari property: " + i->first);
823 void Interpreter::ReadItem(Item &item, const PropertyList &props) {
824 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
825 if (i->first == "name") {
826 item.SetName(GetString(*i->second));
827 } else if (i->first == "menuicon") {
828 item.SetMenuIcon(GetSprite(*i->second));
829 } else if (i->first == "battle") {
830 if (GetBoolean(*i->second)) {
831 item.SetUsableInBattle();
833 } else if (i->first == "targets") {
834 item.GetTargetingMode() = *GetTargetingMode(*i->second);
835 } else if (i->first == "ikari") {
836 item.SetIkari(GetIkari(*i->second));
837 } else if (i->first == "attackanimation") {
838 item.SetAttackAnimation(GetAnimation(*i->second));
840 throw Error("unknown Item property: " + i->first);
845 void Interpreter::ReadHero(Hero &h, const PropertyList &props) {
846 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
847 if (i->first == "name") {
848 h.SetName(GetString(*i->second));
849 } else if (i->first == "sprite") {
850 h.SetSprite(GetSprite(*i->second));
851 } else if (i->first == "level") {
852 h.SetLevel(GetNumber(*i->second));
853 } else if (i->first == "maxHealth") {
854 h.SetMaxHealth(GetNumber(*i->second));
855 } else if (i->first == "health") {
856 h.SetHealth(GetNumber(*i->second));
857 } else if (i->first == "maxMana") {
858 h.SetMaxMana(GetNumber(*i->second));
859 } else if (i->first == "mana") {
860 h.SetMana(GetNumber(*i->second));
861 } else if (i->first == "ip") {
862 h.SetIP(GetNumber(*i->second));
863 } else if (i->first == "stats") {
865 ReadStats(stats, *GetPropertyList(*i->second));
867 } else if (i->first == "attackAnimation") {
868 h.SetAttackAnimation(GetAnimation(*i->second));
869 } else if (i->first == "spellAnimation") {
870 h.SetSpellAnimation(GetAnimation(*i->second));
871 } else if (i->first == "meleeAnimation") {
872 h.SetMeleeAnimation(GetAnimation(*i->second));
874 throw Error("unknown Hero property: " + i->first);
879 void Interpreter::ReadMonster(Monster &m, const PropertyList &props) {
880 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
881 if (i->first == "name") {
882 m.SetName(GetString(*i->second));
883 } else if (i->first == "sprite") {
884 m.SetSprite(GetSprite(*i->second));
885 } else if (i->first == "level") {
886 m.SetLevel(GetNumber(*i->second));
887 } else if (i->first == "maxHealth") {
888 m.SetMaxHealth(GetNumber(*i->second));
889 } else if (i->first == "health") {
890 m.SetHealth(GetNumber(*i->second));
891 } else if (i->first == "maxMana") {
892 m.SetMaxMana(GetNumber(*i->second));
893 } else if (i->first == "mana") {
894 m.SetMana(GetNumber(*i->second));
895 } else if (i->first == "stats") {
897 ReadStats(stats, *GetPropertyList(*i->second));
899 } else if (i->first == "attackAnimation") {
900 m.SetAttackAnimation(GetAnimation(*i->second));
901 } else if (i->first == "meleeAnimation") {
902 m.SetMeleeAnimation(GetAnimation(*i->second));
904 throw Error("unknown Monster property: " + i->first);
909 void Interpreter::ReadPartyLayout(PartyLayout &p, const PropertyList &props) {
910 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
911 if (i->first == "positions") {
912 const vector<Value *> &positions(GetValueArray(*i->second));
913 for (vector<Value *>::const_iterator j(positions.begin()), end(positions.end()); j != end; ++j) {
914 p.AddPosition(GetVector(**j));
917 throw Error("unknown PartyLayout property: " + i->first);
922 void Interpreter::ReadSimpleAnimation(SimpleAnimation &a, const PropertyList &props) {
923 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
924 if (i->first == "sprite") {
925 a.SetSprite(GetSprite(*i->second));
926 } else if (i->first == "frametime") {
927 a.SetFrameTime(GetNumber(*i->second));
928 } else if (i->first == "repeat") {
929 a.SetRepeat(GetBoolean(*i->second));
930 } else if (i->first == "framecount") {
931 a.SetNumFrames(GetNumber(*i->second));
932 } else if (i->first == "col") {
933 a.SetCol(GetNumber(*i->second));
934 } else if (i->first == "row") {
935 a.SetRow(GetNumber(*i->second));
937 throw Error("unknown SimpleAnimation property: " + i->first);
942 void Interpreter::ReadSpell(Spell &s, const PropertyList &props) {
943 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
944 if (i->first == "name") {
945 s.SetName(GetString(*i->second));
946 } else if (i->first == "cost") {
947 s.SetCost(GetNumber(*i->second));
948 } else if (i->first == "battle") {
949 if (GetBoolean(*i->second)) {
950 s.SetUsableInBattle();
952 } else if (i->first == "targets") {
953 s.GetTargetingMode() = *GetTargetingMode(*i->second);
955 throw Error("unknown Spell property: " + i->first);
960 void Interpreter::ReadSprite(Sprite &s, const PropertyList &props) {
961 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
962 if (i->first == "image") {
963 s.SetSurface(GetImage(*i->second));
964 } else if (i->first == "size") {
965 s.SetSize(GetVector(*i->second));
966 } else if (i->first == "offset") {
967 s.SetOffset(GetVector(*i->second));
969 throw Error("unknown Sprite property: " + i->first);
974 void Interpreter::ReadStats(Stats &s, const PropertyList &props) {
975 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
976 if (i->first == "atp") {
977 s.SetAttack(GetNumber(*i->second));
978 } else if (i->first == "dfp") {
979 s.SetDefense(GetNumber(*i->second));
980 } else if (i->first == "str") {
981 s.SetStrength(GetNumber(*i->second));
982 } else if (i->first == "agl") {
983 s.SetAgility(GetNumber(*i->second));
984 } else if (i->first == "int") {
985 s.SetIntelligence(GetNumber(*i->second));
986 } else if (i->first == "gut") {
987 s.SetGut(GetNumber(*i->second));
988 } else if (i->first == "mgr") {
989 s.SetMagicResistance(GetNumber(*i->second));
991 throw Error("unknown Stats property: " + i->first);
996 void Interpreter::ReadTargetingMode(TargetingMode &t, const PropertyList &props) {
997 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
998 if (i->first == "ally") {
999 if (GetBoolean(*i->second)) {
1004 } else if (i->first == "enemy") {
1005 if (GetBoolean(*i->second)) {
1010 } else if (i->first == "all") {
1011 if (GetBoolean(*i->second)) {
1014 } else if (i->first == "multiple") {
1015 if (GetBoolean(*i->second)) {
1018 } else if (i->first == "single") {
1019 if (GetBoolean(*i->second)) {
1023 throw Error("unknown TargetingMode property: " + i->first);