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;
39 using graphics::Frame;
40 using graphics::Gauge;
41 using graphics::ComplexAnimation;
42 using graphics::SimpleAnimation;
43 using graphics::Sprite;
44 using geometry::Vector;
53 Interpreter::~Interpreter() {
54 for (vector<ComplexAnimation *>::const_iterator i(complexAnimations.begin()), end(complexAnimations.end()); i != end; ++i) {
57 for (vector<Font *>::const_iterator i(fonts.begin()), end(fonts.end()); i != end; ++i) {
60 for (vector<Frame *>::const_iterator i(frames.begin()), end(frames.end()); i != end; ++i) {
63 for (vector<Gauge *>::const_iterator i(gauges.begin()), end(gauges.end()); i != end; ++i) {
66 for (vector<Hero *>::const_iterator i(heroes.begin()), end(heroes.end()); i != end; ++i) {
69 for (vector<Ikari *>::const_iterator i(ikaris.begin()), end(ikaris.end()); i != end; ++i) {
72 for (vector<SDL_Surface *>::const_iterator i(images.begin()), end(images.end()); i != end; ++i) {
75 for (vector<Item *>::const_iterator i(items.begin()), end(items.end()); i != end; ++i) {
78 for (vector<Monster *>::const_iterator i(monsters.begin()), end(monsters.end()); i != end; ++i) {
81 for (vector<PartyLayout *>::const_iterator i(partyLayouts.begin()), end(partyLayouts.end()); i != end; ++i) {
84 for (vector<SimpleAnimation *>::const_iterator i(simpleAnimations.begin()), end(simpleAnimations.end()); i != end; ++i) {
87 for (vector<Spell *>::const_iterator i(spells.begin()), end(spells.end()); i != end; ++i) {
90 for (vector<Sprite *>::const_iterator i(sprites.begin()), end(sprites.end()); i != end; ++i) {
93 for (vector<const char *>::const_iterator i(strings.begin()), end(strings.end()); i != end; ++i) {
96 for (vector<TargetingMode *>::const_iterator i(targetingModes.begin()), end(targetingModes.end()); i != end; ++i) {
102 Animation *Interpreter::GetAnimation(const std::string &name) {
103 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
104 if (i != parsedDefinitions.end()) {
105 if (i->second.type == COMPLEX_ANIMATION) {
106 return complexAnimations[i->second.index];
107 } else if (i->second.type == SIMPLE_ANIMATION) {
108 return simpleAnimations[i->second.index];
110 throw Error("cannot cast " + i->second.dfn->TypeName() + " to Animation");
113 throw Error("access to undefined Animation " + name);
117 bool Interpreter::GetBoolean(const std::string &name) const {
118 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
119 if (i != parsedDefinitions.end()) {
120 if (i->second.type == BOOLEAN) {
121 return booleans[i->second.index];
123 throw Error("cannot cast " + i->second.dfn->TypeName() + " to Boolean");
126 throw Error("access to undefined Boolean " + name);
130 Font *Interpreter::GetFont(const std::string &name) {
131 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
132 if (i != parsedDefinitions.end()) {
133 if (i->second.type == FONT) {
134 return fonts[i->second.index];
136 throw Error("cannot cast " + i->second.dfn->TypeName() + " to Font");
139 throw Error("access to undefined Font " + name);
143 Frame *Interpreter::GetFrame(const std::string &name) {
144 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
145 if (i != parsedDefinitions.end()) {
146 if (i->second.type == FRAME) {
147 return frames[i->second.index];
149 throw Error("cannot cast " + i->second.dfn->TypeName() + " to Frame");
152 throw Error("access to undefined Frame " + name);
156 Gauge *Interpreter::GetGauge(const std::string &name) {
157 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
158 if (i != parsedDefinitions.end()) {
159 if (i->second.type == GAUGE) {
160 return gauges[i->second.index];
162 throw Error("cannot cast " + i->second.dfn->TypeName() + " to Gauge");
165 throw Error("access to undefined Gauge " + name);
169 Hero *Interpreter::GetHero(const std::string &name) {
170 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
171 if (i != parsedDefinitions.end()) {
172 if (i->second.type == HERO) {
173 return heroes[i->second.index];
175 throw Error("cannot cast " + i->second.dfn->TypeName() + " to Hero");
178 throw Error("access to undefined Hero " + name);
182 Ikari *Interpreter::GetIkari(const std::string &name) {
183 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
184 if (i != parsedDefinitions.end()) {
185 if (i->second.type == IKARI) {
186 return ikaris[i->second.index];
188 throw Error("cannot cast " + i->second.dfn->TypeName() + " to Ikari");
191 throw Error("access to undefined Ikari " + name);
195 Item *Interpreter::GetItem(const std::string &name) {
196 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
197 if (i != parsedDefinitions.end()) {
198 if (i->second.type == ITEM) {
199 return items[i->second.index];
201 throw Error("cannot cast " + i->second.dfn->TypeName() + " to Item");
204 throw Error("access to undefined Item " + name);
208 Monster *Interpreter::GetMonster(const std::string &name) {
209 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
210 if (i != parsedDefinitions.end()) {
211 if (i->second.type == MONSTER) {
212 return monsters[i->second.index];
214 throw Error("cannot cast " + i->second.dfn->TypeName() + " to Monster");
217 throw Error("access to undefined Monster " + name);
221 int Interpreter::GetNumber(const std::string &name) const {
222 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
223 if (i != parsedDefinitions.end()) {
224 if (i->second.type == NUMBER) {
225 return numbers[i->second.index];
227 throw Error("cannot cast " + i->second.dfn->TypeName() + " to Number");
230 throw Error("access to undefined Number " + name);
234 PartyLayout *Interpreter::GetPartyLayout(const std::string &name) {
235 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
236 if (i != parsedDefinitions.end()) {
237 if (i->second.type == PARTY_LAYOUT) {
238 return partyLayouts[i->second.index];
240 throw Error("cannot cast " + i->second.dfn->TypeName() + " to PartyLayout");
243 throw Error("access to undefined PartyLayout " + name);
247 const char *Interpreter::GetPath(const std::string &name) const {
248 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
249 if (i != parsedDefinitions.end()) {
250 if (i->second.type == PATH) {
251 return strings[i->second.index];
253 throw Error("cannot cast " + i->second.dfn->TypeName() + " to Path");
256 throw Error("access to undefined Path " + name);
260 Spell *Interpreter::GetSpell(const std::string &name) {
261 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
262 if (i != parsedDefinitions.end()) {
263 if (i->second.type == SPELL) {
264 return spells[i->second.index];
266 throw Error("cannot cast " + i->second.dfn->TypeName() + " to Spell");
269 throw Error("access to undefined Spell " + name);
273 Sprite *Interpreter::GetSprite(const std::string &name) {
274 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
275 if (i != parsedDefinitions.end()) {
276 if (i->second.type == SPRITE) {
277 return sprites[i->second.index];
279 throw Error("cannot cast " + i->second.dfn->TypeName() + " to Sprite");
282 throw Error("access to undefined Sprite " + name);
286 const char *Interpreter::GetString(const std::string &name) const {
287 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
288 if (i != parsedDefinitions.end()) {
289 // TODO: enable path to string casting some time
290 if (i->second.type == STRING /* || i->second.type == PATH */) {
291 return strings[i->second.index];
293 throw Error("cannot cast " + i->second.dfn->TypeName() + " to String");
296 throw Error("access to undefined String " + name);
300 TargetingMode *Interpreter::GetTargetingMode(const std::string &name) {
301 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
302 if (i != parsedDefinitions.end()) {
303 if (i->second.type == TARGETING_MODE) {
304 return targetingModes[i->second.index];
306 throw Error("cannot cast " + i->second.dfn->TypeName() + " to TargetingMode");
309 throw Error("access to undefined TargetingMode " + name);
313 Vector<int> Interpreter::GetVector(const std::string &name) const {
314 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
315 if (i != parsedDefinitions.end()) {
316 if (i->second.type == VECTOR) {
317 return vectors[i->second.index];
319 throw Error("cannot cast " + i->second.dfn->TypeName() + " to Vector");
322 throw Error("access to undefined Vector " + name);
327 void Interpreter::ReadSource() {
328 for (set<string>::const_iterator i(source.Exports().begin()), end(source.Exports().end()); i != end; ++i) {
329 ReadDefinition(source.GetDefinition(*i));
333 void Interpreter::ReadDefinition(const Definition &dfn) {
334 if (parsedDefinitions.find(dfn.Identifier()) != parsedDefinitions.end()) {
337 if (dfn.HasLiteralValue()) {
344 void Interpreter::ReadLiteral(const Definition &dfn) {
345 switch (dfn.GetLiteral()->GetType()) {
346 case Literal::ARRAY_VALUES:
347 valueArrays.push_back(dfn.GetLiteral()->GetValues());
348 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, VALUE_ARRAY, valueArrays.size() - 1)));
350 case Literal::ARRAY_PROPS:
351 propertyListArrays.push_back(dfn.GetLiteral()->GetPropertyLists());
352 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, PROPERTY_LIST_ARRAY, propertyListArrays.size() - 1)));
354 case Literal::BOOLEAN:
355 booleans.push_back(dfn.GetLiteral()->GetBoolean());
356 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, BOOLEAN, booleans.size() - 1)));
359 throw Error("unhandled literal: color");
361 case Literal::NUMBER:
362 numbers.push_back(dfn.GetLiteral()->GetNumber());
363 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, NUMBER, numbers.size() - 1)));
367 char *str(new char[dfn.GetLiteral()->GetString().size() + 1]);
368 std::memcpy(str, dfn.GetLiteral()->GetString().c_str(), dfn.GetLiteral()->GetString().size());
369 str[dfn.GetLiteral()->GetString().size()] = '\0';
370 strings.push_back(str);
372 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, PATH, strings.size() - 1)));
374 case Literal::STRING:
376 char *str(new char[dfn.GetLiteral()->GetString().size() + 1]);
377 std::memcpy(str, dfn.GetLiteral()->GetString().c_str(), dfn.GetLiteral()->GetString().size());
378 str[dfn.GetLiteral()->GetString().size()] = '\0';
379 strings.push_back(str);
381 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, STRING, strings.size() - 1)));
383 case Literal::VECTOR:
384 vectors.push_back(Vector<int>(dfn.GetLiteral()->GetX(), dfn.GetLiteral()->GetY()));
385 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, VECTOR, vectors.size() - 1)));
387 case Literal::OBJECT:
393 Animation *Interpreter::GetAnimation(const Value &v) {
395 if (v.GetLiteral().GetTypeName() == "ComplexAnimation") {
396 ComplexAnimation *a(new ComplexAnimation);
397 ReadComplexAnimation(*a, *v.GetLiteral().GetProperties());
398 complexAnimations.push_back(a);
401 SimpleAnimation *a(new SimpleAnimation);
402 ReadSimpleAnimation(*a, *v.GetLiteral().GetProperties());
403 simpleAnimations.push_back(a);
407 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
408 return GetAnimation(v.GetIdentifier());
412 bool Interpreter::GetBoolean(const Value &v) {
414 return v.GetLiteral().GetBoolean();
416 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
417 return GetBoolean(v.GetIdentifier());
421 Font *Interpreter::GetFont(const Value &v) {
424 ReadFont(*f, *v.GetLiteral().GetProperties());
427 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
428 return GetFont(v.GetIdentifier());
432 Frame *Interpreter::GetFrame(const Value &v) {
435 ReadFrame(*f, *v.GetLiteral().GetProperties());
438 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
439 return GetFrame(v.GetIdentifier());
443 Gauge *Interpreter::GetGauge(const Value &v) {
446 ReadGauge(*g, *v.GetLiteral().GetProperties());
449 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
450 return GetGauge(v.GetIdentifier());
454 Hero *Interpreter::GetHero(const Value &v) {
457 ReadHero(*h, *v.GetLiteral().GetProperties());
460 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
461 return GetHero(v.GetIdentifier());
465 Ikari *Interpreter::GetIkari(const Value &v) {
468 ReadIkari(*i, *v.GetLiteral().GetProperties());
471 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
472 return GetIkari(v.GetIdentifier());
476 SDL_Surface *Interpreter::GetImage(const Value &v) {
477 string path(GetPath(v));
478 map<string, SDL_Surface *>::const_iterator i(imageCache.find(path));
479 if (i == imageCache.end()) {
480 SDL_Surface *image(IMG_Load(path.c_str()));
481 images.push_back(image);
482 imageCache.insert(make_pair(path, image));
489 Item *Interpreter::GetItem(const Value &v) {
492 ReadItem(*i, *v.GetLiteral().GetProperties());
495 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
496 return GetItem(v.GetIdentifier());
500 int Interpreter::GetNumber(const Value &v) {
502 return v.GetLiteral().GetNumber();
504 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
505 return GetNumber(v.GetIdentifier());
509 PartyLayout *Interpreter::GetPartyLayout(const Value &v) {
511 PartyLayout *l(new PartyLayout);
512 ReadPartyLayout(*l, *v.GetLiteral().GetProperties());
515 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
516 return GetPartyLayout(v.GetIdentifier());
520 const char *Interpreter::GetPath(const Value &v) {
522 return v.GetLiteral().GetString().c_str();
524 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
525 return GetPath(v.GetIdentifier());
529 const PropertyList *Interpreter::GetPropertyList(const Value &v) {
531 return v.GetLiteral().GetProperties();
533 throw Error("cannot reference property lists");
537 const vector<PropertyList *> &Interpreter::GetPropertyListArray(const Value &v) {
539 return v.GetLiteral().GetPropertyLists();
541 throw Error("cannot reference property list arrays");
545 Spell *Interpreter::GetSpell(const Value &v) {
548 ReadSpell(*s, *v.GetLiteral().GetProperties());
551 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
552 return GetSpell(v.GetIdentifier());
556 Sprite *Interpreter::GetSprite(const Value &v) {
558 Sprite *s(new Sprite);
559 ReadSprite(*s, *v.GetLiteral().GetProperties());
562 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
563 return GetSprite(v.GetIdentifier());
567 const char *Interpreter::GetString(const Value &v) {
569 return v.GetLiteral().GetString().c_str();
571 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
572 return GetString(v.GetIdentifier());
576 TargetingMode *Interpreter::GetTargetingMode(const Value &v) {
578 TargetingMode *t(new TargetingMode);
579 ReadTargetingMode(*t, *v.GetLiteral().GetProperties());
582 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
583 return GetTargetingMode(v.GetIdentifier());
587 Vector<int> Interpreter::GetVector(const Value &v) {
589 return Vector<int>(v.GetLiteral().GetX(), v.GetLiteral().GetY());
591 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
592 return GetVector(v.GetIdentifier());
596 const vector<Value *> &Interpreter::GetValueArray(const Value &v) {
598 return v.GetLiteral().GetValues();
600 throw Error("cannot reference value arrays");
605 void Interpreter::ReadObject(const Definition &dfn) {
606 if (dfn.TypeName() == "ComplexAnimation") {
607 ComplexAnimation *animation(new ComplexAnimation);
608 int index(complexAnimations.size());
609 complexAnimations.push_back(animation);
610 ReadComplexAnimation(*animation, *dfn.GetProperties());
611 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, COMPLEX_ANIMATION, index)));
612 } else if (dfn.TypeName() == "Font") {
613 Font *font(new Font);
614 int index(fonts.size());
615 fonts.push_back(font);
616 ReadFont(*font, *dfn.GetProperties());
617 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, FONT, index)));
618 } else if (dfn.TypeName() == "Frame") {
619 Frame *frame(new Frame);
620 int index(frames.size());
621 frames.push_back(frame);
622 ReadFrame(*frame, *dfn.GetProperties());
623 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, FRAME, index)));
624 } else if (dfn.TypeName() == "Gauge") {
625 Gauge *gauge(new Gauge);
626 int index(gauges.size());
627 gauges.push_back(gauge);
628 ReadGauge(*gauge, *dfn.GetProperties());
629 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, GAUGE, index)));
630 } else if (dfn.TypeName() == "Hero") {
631 Hero *hero(new Hero);
632 int index(heroes.size());
633 heroes.push_back(hero);
634 ReadHero(*hero, *dfn.GetProperties());
635 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, HERO, index)));
636 } else if (dfn.TypeName() == "Ikari") {
637 Ikari *ikari(new Ikari);
638 int index(ikaris.size());
639 ikaris.push_back(ikari);
640 ReadIkari(*ikari, *dfn.GetProperties());
641 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, IKARI, index)));
642 } else if (dfn.TypeName() == "Item") {
643 Item *item(new Item);
644 int index(items.size());
645 items.push_back(item);
646 ReadItem(*item, *dfn.GetProperties());
647 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, ITEM, index)));
648 } else if (dfn.TypeName() == "Monster") {
649 Monster *monster(new Monster);
650 int index(monsters.size());
651 monsters.push_back(monster);
652 ReadMonster(*monster, *dfn.GetProperties());
653 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, MONSTER, index)));
654 } else if (dfn.TypeName() == "PartyLayout") {
655 PartyLayout *layout(new PartyLayout);
656 int index(partyLayouts.size());
657 partyLayouts.push_back(layout);
658 ReadPartyLayout(*layout, *dfn.GetProperties());
659 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, PARTY_LAYOUT, index)));
660 } else if (dfn.TypeName() == "SimpleAnimation") {
661 SimpleAnimation *animation(new SimpleAnimation);
662 int index(simpleAnimations.size());
663 simpleAnimations.push_back(animation);
664 ReadSimpleAnimation(*animation, *dfn.GetProperties());
665 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, SIMPLE_ANIMATION, index)));
666 } else if (dfn.TypeName() == "Spell") {
667 Spell *spell(new Spell);
668 int index(spells.size());
669 spells.push_back(spell);
670 ReadSpell(*spell, *dfn.GetProperties());
671 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, SPELL, index)));
672 } else if (dfn.TypeName() == "Sprite") {
673 Sprite *sprite(new Sprite);
674 int index(sprites.size());
675 sprites.push_back(sprite);
676 ReadSprite(*sprite, *dfn.GetProperties());
677 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, SPRITE, index)));
678 } else if (dfn.TypeName() == "TargetingMode") {
679 TargetingMode *mode(new TargetingMode);
680 int index(targetingModes.size());
681 targetingModes.push_back(mode);
682 ReadTargetingMode(*mode, *dfn.GetProperties());
683 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, TARGETING_MODE, index)));
685 throw Error("unhandled object type: " + dfn.TypeName());
690 void Interpreter::ReadComplexAnimation(ComplexAnimation &a, const PropertyList &props) {
691 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
692 if (i->first == "sprite") {
693 a.SetSprite(GetSprite(*i->second));
694 } else if (i->first == "frametime") {
695 a.SetFrameTime(GetNumber(*i->second));
696 } else if (i->first == "repeat") {
697 a.SetRepeat(GetBoolean(*i->second));
698 } else if (i->first == "frames") {
699 const vector<PropertyList *> &values(GetPropertyListArray(*i->second));
700 for (vector<PropertyList *>::const_iterator i(values.begin()), end(values.end()); i != end; ++i) {
701 ComplexAnimation::FrameProp frame;
702 ReadComplexAnimationFrame(frame, **i);
706 throw Error("unknown ComplexAnimation property: " + i->first);
711 void Interpreter::ReadComplexAnimationFrame(ComplexAnimation::FrameProp &f, const PropertyList &props) {
712 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
713 if (i->first == "column") {
714 f.col = GetNumber(*i->second);
715 } else if (i->first == "row") {
716 f.row = GetNumber(*i->second);
717 } else if (i->first == "disposition") {
718 f.disposition = GetVector(*i->second);
720 throw Error("unknown ComplexAnimationFrame property: " + i->first);
725 void Interpreter::ReadFont(Font &f, const PropertyList &props) {
726 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
727 if (i->first == "sprite") {
728 f.SetSprite(GetSprite(*i->second));
729 } else if (i->first == "columnoffset") {
730 f.SetColOffset(GetNumber(*i->second));
731 } else if (i->first == "rowoffset") {
732 f.SetRowOffset(GetNumber(*i->second));
734 throw Error("unknown Font property: " + i->first);
739 void Interpreter::ReadFrame(Frame &f, const PropertyList &props) {
740 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
741 if (i->first == "image") {
742 f.SetSurface(GetImage(*i->second));
743 } else if (i->first == "border") {
744 f.SetBorderSize(GetVector(*i->second));
745 } else if (i->first == "repeat") {
746 f.SetRepeatSize(GetVector(*i->second));
747 } else if (i->first == "offset") {
748 f.SetOffset(GetVector(*i->second));
750 throw Error("unknown Frame property: " + i->first);
755 void Interpreter::ReadGauge(Gauge &g, const PropertyList &props) {
756 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
757 if (i->first == "image") {
758 g.SetSurface(GetImage(*i->second));
759 } else if (i->first == "full") {
760 g.SetFullOffset(GetVector(*i->second));
761 } else if (i->first == "empty") {
762 g.SetEmptyOffset(GetVector(*i->second));
763 } else if (i->first == "height") {
764 g.SetHeight(GetNumber(*i->second));
765 } else if (i->first == "start") {
766 g.SetStartWidth(GetNumber(*i->second));
767 } else if (i->first == "repeat") {
768 g.SetRepeatWidth(GetNumber(*i->second));
769 } else if (i->first == "end") {
770 g.SetEndWidth(GetNumber(*i->second));
772 throw Error("unknown Gauge property: " + i->first);
777 void Interpreter::ReadIkari(Ikari &ikari, const PropertyList &props) {
778 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
779 if (i->first == "name") {
780 ikari.SetName(GetString(*i->second));
781 } else if (i->first == "cost") {
782 ikari.SetCost(GetNumber(*i->second));
783 } else if (i->first == "targets") {
784 ikari.GetTargetingMode() = *GetTargetingMode(*i->second);
785 } else if (i->first == "magical") {
786 if (GetBoolean(*i->second)) {
789 } else if (i->first == "physical") {
790 if (GetBoolean(*i->second)) {
794 throw Error("unknown Ikari property: " + i->first);
799 void Interpreter::ReadItem(Item &item, const PropertyList &props) {
800 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
801 if (i->first == "name") {
802 item.SetName(GetString(*i->second));
803 } else if (i->first == "menuicon") {
804 item.SetMenuIcon(GetSprite(*i->second));
805 } else if (i->first == "battle") {
806 if (GetBoolean(*i->second)) {
807 item.SetUsableInBattle();
809 } else if (i->first == "targets") {
810 item.GetTargetingMode() = *GetTargetingMode(*i->second);
811 } else if (i->first == "ikari") {
812 item.SetIkari(GetIkari(*i->second));
813 } else if (i->first == "attackanimation") {
814 item.SetAttackAnimation(GetAnimation(*i->second));
816 throw Error("unknown Item property: " + i->first);
821 void Interpreter::ReadHero(Hero &h, const PropertyList &props) {
822 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
823 if (i->first == "name") {
824 h.SetName(GetString(*i->second));
825 } else if (i->first == "sprite") {
826 h.SetSprite(GetSprite(*i->second));
827 } else if (i->first == "level") {
828 h.SetLevel(GetNumber(*i->second));
829 } else if (i->first == "maxHealth") {
830 h.SetMaxHealth(GetNumber(*i->second));
831 } else if (i->first == "health") {
832 h.SetHealth(GetNumber(*i->second));
833 } else if (i->first == "maxMana") {
834 h.SetMaxMana(GetNumber(*i->second));
835 } else if (i->first == "mana") {
836 h.SetMana(GetNumber(*i->second));
837 } else if (i->first == "ip") {
838 h.SetIP(GetNumber(*i->second));
839 } else if (i->first == "stats") {
841 ReadStats(stats, *GetPropertyList(*i->second));
843 } else if (i->first == "attackAnimation") {
844 h.SetAttackAnimation(GetAnimation(*i->second));
845 } else if (i->first == "spellAnimation") {
846 h.SetSpellAnimation(GetAnimation(*i->second));
847 } else if (i->first == "meleeAnimation") {
848 h.SetMeleeAnimation(GetAnimation(*i->second));
850 throw Error("unknown Hero property: " + i->first);
855 void Interpreter::ReadMonster(Monster &m, const PropertyList &props) {
856 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
857 if (i->first == "name") {
858 m.SetName(GetString(*i->second));
859 } else if (i->first == "sprite") {
860 m.SetSprite(GetSprite(*i->second));
861 } else if (i->first == "level") {
862 m.SetLevel(GetNumber(*i->second));
863 } else if (i->first == "maxHealth") {
864 m.SetMaxHealth(GetNumber(*i->second));
865 } else if (i->first == "health") {
866 m.SetHealth(GetNumber(*i->second));
867 } else if (i->first == "maxMana") {
868 m.SetMaxMana(GetNumber(*i->second));
869 } else if (i->first == "mana") {
870 m.SetMana(GetNumber(*i->second));
871 } else if (i->first == "stats") {
873 ReadStats(stats, *GetPropertyList(*i->second));
875 } else if (i->first == "attackAnimation") {
876 m.SetAttackAnimation(GetAnimation(*i->second));
877 } else if (i->first == "meleeAnimation") {
878 m.SetMeleeAnimation(GetAnimation(*i->second));
880 throw Error("unknown Monster property: " + i->first);
885 void Interpreter::ReadPartyLayout(PartyLayout &p, const PropertyList &props) {
886 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
887 if (i->first == "positions") {
888 const vector<Value *> &positions(GetValueArray(*i->second));
889 for (vector<Value *>::const_iterator j(positions.begin()), end(positions.end()); j != end; ++j) {
890 p.AddPosition(GetVector(**j));
893 throw Error("unknown PartyLayout property: " + i->first);
898 void Interpreter::ReadSimpleAnimation(SimpleAnimation &a, const PropertyList &props) {
899 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
900 if (i->first == "sprite") {
901 a.SetSprite(GetSprite(*i->second));
902 } else if (i->first == "frametime") {
903 a.SetFrameTime(GetNumber(*i->second));
904 } else if (i->first == "repeat") {
905 a.SetRepeat(GetBoolean(*i->second));
906 } else if (i->first == "framecount") {
907 a.SetNumFrames(GetNumber(*i->second));
908 } else if (i->first == "col") {
909 a.SetCol(GetNumber(*i->second));
910 } else if (i->first == "row") {
911 a.SetRow(GetNumber(*i->second));
913 throw Error("unknown SimpleAnimation property: " + i->first);
918 void Interpreter::ReadSpell(Spell &s, const PropertyList &props) {
919 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
920 if (i->first == "name") {
921 s.SetName(GetString(*i->second));
922 } else if (i->first == "cost") {
923 s.SetCost(GetNumber(*i->second));
924 } else if (i->first == "battle") {
925 if (GetBoolean(*i->second)) {
926 s.SetUsableInBattle();
928 } else if (i->first == "targets") {
929 s.GetTargetingMode() = *GetTargetingMode(*i->second);
931 throw Error("unknown Spell property: " + i->first);
936 void Interpreter::ReadSprite(Sprite &s, const PropertyList &props) {
937 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
938 if (i->first == "image") {
939 s.SetSurface(GetImage(*i->second));
940 } else if (i->first == "size") {
941 s.SetSize(GetVector(*i->second));
942 } else if (i->first == "offset") {
943 s.SetOffset(GetVector(*i->second));
945 throw Error("unknown Sprite property: " + i->first);
950 void Interpreter::ReadStats(Stats &s, const PropertyList &props) {
951 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
952 if (i->first == "atp") {
953 s.SetAttack(GetNumber(*i->second));
954 } else if (i->first == "dfp") {
955 s.SetDefense(GetNumber(*i->second));
956 } else if (i->first == "str") {
957 s.SetStrength(GetNumber(*i->second));
958 } else if (i->first == "agl") {
959 s.SetAgility(GetNumber(*i->second));
960 } else if (i->first == "int") {
961 s.SetIntelligence(GetNumber(*i->second));
962 } else if (i->first == "gut") {
963 s.SetGut(GetNumber(*i->second));
964 } else if (i->first == "mgr") {
965 s.SetMagicResistance(GetNumber(*i->second));
967 throw Error("unknown Stats property: " + i->first);
972 void Interpreter::ReadTargetingMode(TargetingMode &t, const PropertyList &props) {
973 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
974 if (i->first == "ally") {
975 if (GetBoolean(*i->second)) {
980 } else if (i->first == "enemy") {
981 if (GetBoolean(*i->second)) {
986 } else if (i->first == "all") {
987 if (GetBoolean(*i->second)) {
990 } else if (i->first == "multiple") {
991 if (GetBoolean(*i->second)) {
994 } else if (i->first == "single") {
995 if (GetBoolean(*i->second)) {
999 throw Error("unknown TargetingMode property: " + i->first);