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 Spell *Interpreter::GetSpell(const std::string &name) {
248 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
249 if (i != parsedDefinitions.end()) {
250 if (i->second.type == SPELL) {
251 return spells[i->second.index];
253 throw Error("cannot cast " + i->second.dfn->TypeName() + " to Spell");
256 throw Error("access to undefined Spell " + name);
260 Sprite *Interpreter::GetSprite(const std::string &name) {
261 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
262 if (i != parsedDefinitions.end()) {
263 if (i->second.type == SPRITE) {
264 return sprites[i->second.index];
266 throw Error("cannot cast " + i->second.dfn->TypeName() + " to Sprite");
269 throw Error("access to undefined Sprite " + name);
273 const char *Interpreter::GetString(const std::string &name) const {
274 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
275 if (i != parsedDefinitions.end()) {
276 if (i->second.type == STRING) {
277 return strings[i->second.index];
279 throw Error("cannot cast " + i->second.dfn->TypeName() + " to String");
282 throw Error("access to undefined String " + name);
286 TargetingMode *Interpreter::GetTargetingMode(const std::string &name) {
287 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
288 if (i != parsedDefinitions.end()) {
289 if (i->second.type == TARGETING_MODE) {
290 return targetingModes[i->second.index];
292 throw Error("cannot cast " + i->second.dfn->TypeName() + " to TargetingMode");
295 throw Error("access to undefined TargetingMode " + name);
299 Vector<int> Interpreter::GetVector(const std::string &name) const {
300 map<string, ParsedDefinition>::const_iterator i(parsedDefinitions.find(name));
301 if (i != parsedDefinitions.end()) {
302 if (i->second.type == VECTOR) {
303 return vectors[i->second.index];
305 throw Error("cannot cast " + i->second.dfn->TypeName() + " to Vector");
308 throw Error("access to undefined Vector " + name);
313 void Interpreter::ReadSource() {
314 for (set<string>::const_iterator i(source.Exports().begin()), end(source.Exports().end()); i != end; ++i) {
315 ReadDefinition(source.GetDefinition(*i));
319 void Interpreter::ReadDefinition(const Definition &dfn) {
320 if (parsedDefinitions.find(dfn.Identifier()) != parsedDefinitions.end()) {
323 if (dfn.HasLiteralValue()) {
330 void Interpreter::ReadLiteral(const Definition &dfn) {
331 switch (dfn.GetLiteral()->GetType()) {
332 case Literal::ARRAY_VALUES:
333 valueArrays.push_back(dfn.GetLiteral()->GetValues());
334 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, VALUE_ARRAY, valueArrays.size() - 1)));
336 case Literal::ARRAY_PROPS:
337 propertyListArrays.push_back(dfn.GetLiteral()->GetPropertyLists());
338 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, PROPERTY_LIST_ARRAY, propertyListArrays.size() - 1)));
340 case Literal::BOOLEAN:
341 booleans.push_back(dfn.GetLiteral()->GetBoolean());
342 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, BOOLEAN, booleans.size() - 1)));
345 throw Error("unhandled literal: color");
347 case Literal::NUMBER:
348 numbers.push_back(dfn.GetLiteral()->GetNumber());
349 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, NUMBER, numbers.size() - 1)));
351 case Literal::STRING:
353 char *str(new char[dfn.GetLiteral()->GetString().size() + 1]);
354 std::memcpy(str, dfn.GetLiteral()->GetString().c_str(), dfn.GetLiteral()->GetString().size());
355 str[dfn.GetLiteral()->GetString().size()] = '\0';
356 strings.push_back(str);
358 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, STRING, strings.size() - 1)));
360 case Literal::VECTOR:
361 vectors.push_back(Vector<int>(dfn.GetLiteral()->GetX(), dfn.GetLiteral()->GetY()));
362 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, VECTOR, vectors.size() - 1)));
364 case Literal::OBJECT:
370 Animation *Interpreter::GetAnimation(const Value &v) {
372 if (v.GetLiteral().GetTypeName() == "ComplexAnimation") {
373 ComplexAnimation *a(new ComplexAnimation);
374 ReadComplexAnimation(*a, *v.GetLiteral().GetProperties());
375 complexAnimations.push_back(a);
378 SimpleAnimation *a(new SimpleAnimation);
379 ReadSimpleAnimation(*a, *v.GetLiteral().GetProperties());
380 simpleAnimations.push_back(a);
384 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
385 return GetAnimation(v.GetIdentifier());
389 bool Interpreter::GetBoolean(const Value &v) {
391 return v.GetLiteral().GetBoolean();
393 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
394 return GetBoolean(v.GetIdentifier());
398 Font *Interpreter::GetFont(const Value &v) {
401 ReadFont(*f, *v.GetLiteral().GetProperties());
404 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
405 return GetFont(v.GetIdentifier());
409 Frame *Interpreter::GetFrame(const Value &v) {
412 ReadFrame(*f, *v.GetLiteral().GetProperties());
415 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
416 return GetFrame(v.GetIdentifier());
420 Gauge *Interpreter::GetGauge(const Value &v) {
423 ReadGauge(*g, *v.GetLiteral().GetProperties());
426 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
427 return GetGauge(v.GetIdentifier());
431 Hero *Interpreter::GetHero(const Value &v) {
434 ReadHero(*h, *v.GetLiteral().GetProperties());
437 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
438 return GetHero(v.GetIdentifier());
442 Ikari *Interpreter::GetIkari(const Value &v) {
445 ReadIkari(*i, *v.GetLiteral().GetProperties());
448 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
449 return GetIkari(v.GetIdentifier());
453 SDL_Surface *Interpreter::GetImage(const Value &v) {
454 const char *file(GetString(v));
455 SDL_Surface *image(IMG_Load(file));
456 images.push_back(image);
460 Item *Interpreter::GetItem(const Value &v) {
463 ReadItem(*i, *v.GetLiteral().GetProperties());
466 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
467 return GetItem(v.GetIdentifier());
471 int Interpreter::GetNumber(const Value &v) {
473 return v.GetLiteral().GetNumber();
475 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
476 return GetNumber(v.GetIdentifier());
480 PartyLayout *Interpreter::GetPartyLayout(const Value &v) {
482 PartyLayout *l(new PartyLayout);
483 ReadPartyLayout(*l, *v.GetLiteral().GetProperties());
486 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
487 return GetPartyLayout(v.GetIdentifier());
491 const PropertyList *Interpreter::GetPropertyList(const Value &v) {
493 return v.GetLiteral().GetProperties();
495 throw Error("cannot reference property lists");
499 const vector<PropertyList *> &Interpreter::GetPropertyListArray(const Value &v) {
501 return v.GetLiteral().GetPropertyLists();
503 throw Error("cannot reference property list arrays");
507 Spell *Interpreter::GetSpell(const Value &v) {
510 ReadSpell(*s, *v.GetLiteral().GetProperties());
513 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
514 return GetSpell(v.GetIdentifier());
518 Sprite *Interpreter::GetSprite(const Value &v) {
520 Sprite *s(new Sprite);
521 ReadSprite(*s, *v.GetLiteral().GetProperties());
524 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
525 return GetSprite(v.GetIdentifier());
529 const char *Interpreter::GetString(const Value &v) {
531 return v.GetLiteral().GetString().c_str();
533 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
534 return GetString(v.GetIdentifier());
538 TargetingMode *Interpreter::GetTargetingMode(const Value &v) {
540 TargetingMode *t(new TargetingMode);
541 ReadTargetingMode(*t, *v.GetLiteral().GetProperties());
544 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
545 return GetTargetingMode(v.GetIdentifier());
549 Vector<int> Interpreter::GetVector(const Value &v) {
551 return Vector<int>(v.GetLiteral().GetX(), v.GetLiteral().GetY());
553 ReadDefinition(source.GetDefinition(v.GetIdentifier()));
554 return GetVector(v.GetIdentifier());
558 const vector<Value *> &Interpreter::GetValueArray(const Value &v) {
560 return v.GetLiteral().GetValues();
562 throw Error("cannot reference value arrays");
567 void Interpreter::ReadObject(const Definition &dfn) {
568 if (dfn.TypeName() == "ComplexAnimation") {
569 ComplexAnimation *animation(new ComplexAnimation);
570 int index(complexAnimations.size());
571 complexAnimations.push_back(animation);
572 ReadComplexAnimation(*animation, *dfn.GetProperties());
573 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, COMPLEX_ANIMATION, index)));
574 } else if (dfn.TypeName() == "Font") {
575 Font *font(new Font);
576 int index(fonts.size());
577 fonts.push_back(font);
578 ReadFont(*font, *dfn.GetProperties());
579 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, FONT, index)));
580 } else if (dfn.TypeName() == "Frame") {
581 Frame *frame(new Frame);
582 int index(frames.size());
583 frames.push_back(frame);
584 ReadFrame(*frame, *dfn.GetProperties());
585 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, FRAME, index)));
586 } else if (dfn.TypeName() == "Gauge") {
587 Gauge *gauge(new Gauge);
588 int index(gauges.size());
589 gauges.push_back(gauge);
590 ReadGauge(*gauge, *dfn.GetProperties());
591 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, GAUGE, index)));
592 } else if (dfn.TypeName() == "Hero") {
593 Hero *hero(new Hero);
594 int index(heroes.size());
595 heroes.push_back(hero);
596 ReadHero(*hero, *dfn.GetProperties());
597 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, HERO, index)));
598 } else if (dfn.TypeName() == "Ikari") {
599 Ikari *ikari(new Ikari);
600 int index(ikaris.size());
601 ikaris.push_back(ikari);
602 ReadIkari(*ikari, *dfn.GetProperties());
603 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, IKARI, index)));
604 } else if (dfn.TypeName() == "Item") {
605 Item *item(new Item);
606 int index(items.size());
607 items.push_back(item);
608 ReadItem(*item, *dfn.GetProperties());
609 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, ITEM, index)));
610 } else if (dfn.TypeName() == "Monster") {
611 Monster *monster(new Monster);
612 int index(monsters.size());
613 monsters.push_back(monster);
614 ReadMonster(*monster, *dfn.GetProperties());
615 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, MONSTER, index)));
616 } else if (dfn.TypeName() == "PartyLayout") {
617 PartyLayout *layout(new PartyLayout);
618 int index(partyLayouts.size());
619 partyLayouts.push_back(layout);
620 ReadPartyLayout(*layout, *dfn.GetProperties());
621 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, PARTY_LAYOUT, index)));
622 } else if (dfn.TypeName() == "SimpleAnimation") {
623 SimpleAnimation *animation(new SimpleAnimation);
624 int index(simpleAnimations.size());
625 simpleAnimations.push_back(animation);
626 ReadSimpleAnimation(*animation, *dfn.GetProperties());
627 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, SIMPLE_ANIMATION, index)));
628 } else if (dfn.TypeName() == "Spell") {
629 Spell *spell(new Spell);
630 int index(spells.size());
631 spells.push_back(spell);
632 ReadSpell(*spell, *dfn.GetProperties());
633 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, SPELL, index)));
634 } else if (dfn.TypeName() == "Sprite") {
635 Sprite *sprite(new Sprite);
636 int index(sprites.size());
637 sprites.push_back(sprite);
638 ReadSprite(*sprite, *dfn.GetProperties());
639 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, SPRITE, index)));
640 } else if (dfn.TypeName() == "TargetingMode") {
641 TargetingMode *mode(new TargetingMode);
642 int index(targetingModes.size());
643 targetingModes.push_back(mode);
644 ReadTargetingMode(*mode, *dfn.GetProperties());
645 parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, TARGETING_MODE, index)));
647 throw Error("unhandled object type: " + dfn.TypeName());
652 void Interpreter::ReadComplexAnimation(ComplexAnimation &a, const PropertyList &props) {
653 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
654 if (i->first == "sprite") {
655 a.SetSprite(GetSprite(*i->second));
656 } else if (i->first == "frametime") {
657 a.SetFrameTime(GetNumber(*i->second));
658 } else if (i->first == "repeat") {
659 a.SetRepeat(GetBoolean(*i->second));
660 } else if (i->first == "frames") {
661 const vector<PropertyList *> &values(GetPropertyListArray(*i->second));
662 for (vector<PropertyList *>::const_iterator i(values.begin()), end(values.end()); i != end; ++i) {
663 ComplexAnimation::FrameProp frame;
664 ReadComplexAnimationFrame(frame, **i);
668 throw Error("unknown ComplexAnimation property: " + i->first);
673 void Interpreter::ReadComplexAnimationFrame(ComplexAnimation::FrameProp &f, const PropertyList &props) {
674 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
675 if (i->first == "column") {
676 f.col = GetNumber(*i->second);
677 } else if (i->first == "row") {
678 f.row = GetNumber(*i->second);
679 } else if (i->first == "disposition") {
680 f.disposition = GetVector(*i->second);
682 throw Error("unknown ComplexAnimationFrame property: " + i->first);
687 void Interpreter::ReadFont(Font &f, const PropertyList &props) {
688 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
689 if (i->first == "sprite") {
690 f.SetSprite(GetSprite(*i->second));
691 } else if (i->first == "columnoffset") {
692 f.SetColOffset(GetNumber(*i->second));
693 } else if (i->first == "rowoffset") {
694 f.SetRowOffset(GetNumber(*i->second));
696 throw Error("unknown Font property: " + i->first);
701 void Interpreter::ReadFrame(Frame &f, const PropertyList &props) {
702 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
703 if (i->first == "image") {
704 f.SetSurface(GetImage(*i->second));
705 } else if (i->first == "border") {
706 f.SetBorderSize(GetVector(*i->second));
707 } else if (i->first == "repeat") {
708 f.SetRepeatSize(GetVector(*i->second));
709 } else if (i->first == "offset") {
710 f.SetOffset(GetVector(*i->second));
712 throw Error("unknown Frame property: " + i->first);
717 void Interpreter::ReadGauge(Gauge &g, const PropertyList &props) {
718 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
719 if (i->first == "image") {
720 g.SetSurface(GetImage(*i->second));
721 } else if (i->first == "full") {
722 g.SetFullOffset(GetVector(*i->second));
723 } else if (i->first == "empty") {
724 g.SetEmptyOffset(GetVector(*i->second));
725 } else if (i->first == "height") {
726 g.SetHeight(GetNumber(*i->second));
727 } else if (i->first == "start") {
728 g.SetStartWidth(GetNumber(*i->second));
729 } else if (i->first == "repeat") {
730 g.SetRepeatWidth(GetNumber(*i->second));
731 } else if (i->first == "end") {
732 g.SetEndWidth(GetNumber(*i->second));
734 throw Error("unknown Gauge property: " + i->first);
739 void Interpreter::ReadIkari(Ikari &ikari, const PropertyList &props) {
740 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
741 if (i->first == "name") {
742 ikari.SetName(GetString(*i->second));
743 } else if (i->first == "cost") {
744 ikari.SetCost(GetNumber(*i->second));
745 } else if (i->first == "targets") {
746 ikari.GetTargetingMode() = *GetTargetingMode(*i->second);
747 } else if (i->first == "magical") {
748 if (GetBoolean(*i->second)) {
751 } else if (i->first == "physical") {
752 if (GetBoolean(*i->second)) {
756 throw Error("unknown Ikari property: " + i->first);
761 void Interpreter::ReadItem(Item &item, const PropertyList &props) {
762 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
763 if (i->first == "name") {
764 item.SetName(GetString(*i->second));
765 } else if (i->first == "menuicon") {
766 item.SetMenuIcon(GetSprite(*i->second));
767 } else if (i->first == "battle") {
768 if (GetBoolean(*i->second)) {
769 item.SetUsableInBattle();
771 } else if (i->first == "targets") {
772 item.GetTargetingMode() = *GetTargetingMode(*i->second);
773 } else if (i->first == "ikari") {
774 item.SetIkari(GetIkari(*i->second));
775 } else if (i->first == "attackanimation") {
776 item.SetAttackAnimation(GetAnimation(*i->second));
778 throw Error("unknown Item property: " + i->first);
783 void Interpreter::ReadHero(Hero &h, const PropertyList &props) {
784 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
785 if (i->first == "name") {
786 h.SetName(GetString(*i->second));
787 } else if (i->first == "sprite") {
788 h.SetSprite(GetSprite(*i->second));
789 } else if (i->first == "level") {
790 h.SetLevel(GetNumber(*i->second));
791 } else if (i->first == "maxHealth") {
792 h.SetMaxHealth(GetNumber(*i->second));
793 } else if (i->first == "health") {
794 h.SetHealth(GetNumber(*i->second));
795 } else if (i->first == "maxMana") {
796 h.SetMaxMana(GetNumber(*i->second));
797 } else if (i->first == "mana") {
798 h.SetMana(GetNumber(*i->second));
799 } else if (i->first == "ip") {
800 h.SetIP(GetNumber(*i->second));
801 } else if (i->first == "stats") {
803 ReadStats(stats, *GetPropertyList(*i->second));
805 } else if (i->first == "attackAnimation") {
806 h.SetAttackAnimation(GetAnimation(*i->second));
807 } else if (i->first == "spellAnimation") {
808 h.SetSpellAnimation(GetAnimation(*i->second));
809 } else if (i->first == "meleeAnimation") {
810 h.SetMeleeAnimation(GetAnimation(*i->second));
812 throw Error("unknown Hero property: " + i->first);
817 void Interpreter::ReadMonster(Monster &m, const PropertyList &props) {
818 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
819 if (i->first == "name") {
820 m.SetName(GetString(*i->second));
821 } else if (i->first == "sprite") {
822 m.SetSprite(GetSprite(*i->second));
823 } else if (i->first == "level") {
824 m.SetLevel(GetNumber(*i->second));
825 } else if (i->first == "maxHealth") {
826 m.SetMaxHealth(GetNumber(*i->second));
827 } else if (i->first == "health") {
828 m.SetHealth(GetNumber(*i->second));
829 } else if (i->first == "maxMana") {
830 m.SetMaxMana(GetNumber(*i->second));
831 } else if (i->first == "mana") {
832 m.SetMana(GetNumber(*i->second));
833 } else if (i->first == "stats") {
835 ReadStats(stats, *GetPropertyList(*i->second));
837 } else if (i->first == "attackAnimation") {
838 m.SetAttackAnimation(GetAnimation(*i->second));
839 } else if (i->first == "meleeAnimation") {
840 m.SetMeleeAnimation(GetAnimation(*i->second));
842 throw Error("unknown Monster property: " + i->first);
847 void Interpreter::ReadPartyLayout(PartyLayout &p, const PropertyList &props) {
848 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
849 if (i->first == "positions") {
850 const vector<Value *> &positions(GetValueArray(*i->second));
851 for (vector<Value *>::const_iterator j(positions.begin()), end(positions.end()); j != end; ++j) {
852 p.AddPosition(GetVector(**j));
855 throw Error("unknown PartyLayout property: " + i->first);
860 void Interpreter::ReadSimpleAnimation(SimpleAnimation &a, const PropertyList &props) {
861 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
862 if (i->first == "sprite") {
863 a.SetSprite(GetSprite(*i->second));
864 } else if (i->first == "frametime") {
865 a.SetFrameTime(GetNumber(*i->second));
866 } else if (i->first == "repeat") {
867 a.SetRepeat(GetBoolean(*i->second));
868 } else if (i->first == "framecount") {
869 a.SetNumFrames(GetNumber(*i->second));
870 } else if (i->first == "col") {
871 a.SetCol(GetNumber(*i->second));
872 } else if (i->first == "row") {
873 a.SetRow(GetNumber(*i->second));
875 throw Error("unknown SimpleAnimation property: " + i->first);
880 void Interpreter::ReadSpell(Spell &s, const PropertyList &props) {
881 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
882 if (i->first == "name") {
883 s.SetName(GetString(*i->second));
884 } else if (i->first == "cost") {
885 s.SetCost(GetNumber(*i->second));
886 } else if (i->first == "battle") {
887 if (GetBoolean(*i->second)) {
888 s.SetUsableInBattle();
890 } else if (i->first == "targets") {
891 s.GetTargetingMode() = *GetTargetingMode(*i->second);
893 throw Error("unknown Spell property: " + i->first);
898 void Interpreter::ReadSprite(Sprite &s, const PropertyList &props) {
899 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
900 if (i->first == "image") {
901 s.SetSurface(GetImage(*i->second));
902 } else if (i->first == "size") {
903 s.SetSize(GetVector(*i->second));
904 } else if (i->first == "offset") {
905 s.SetOffset(GetVector(*i->second));
907 throw Error("unknown Sprite property: " + i->first);
912 void Interpreter::ReadStats(Stats &s, const PropertyList &props) {
913 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
914 if (i->first == "atp") {
915 s.SetAttack(GetNumber(*i->second));
916 } else if (i->first == "dfp") {
917 s.SetDefense(GetNumber(*i->second));
918 } else if (i->first == "str") {
919 s.SetStrength(GetNumber(*i->second));
920 } else if (i->first == "agl") {
921 s.SetAgility(GetNumber(*i->second));
922 } else if (i->first == "int") {
923 s.SetIntelligence(GetNumber(*i->second));
924 } else if (i->first == "gut") {
925 s.SetGut(GetNumber(*i->second));
926 } else if (i->first == "mgr") {
927 s.SetMagicResistance(GetNumber(*i->second));
929 throw Error("unknown Stats property: " + i->first);
934 void Interpreter::ReadTargetingMode(TargetingMode &t, const PropertyList &props) {
935 for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) {
936 if (i->first == "ally") {
937 if (GetBoolean(*i->second)) {
942 } else if (i->first == "enemy") {
943 if (GetBoolean(*i->second)) {
948 } else if (i->first == "all") {
949 if (GetBoolean(*i->second)) {
952 } else if (i->first == "multiple") {
953 if (GetBoolean(*i->second)) {
956 } else if (i->first == "single") {
957 if (GetBoolean(*i->second)) {
961 throw Error("unknown TargetingMode property: " + i->first);