]> git.localhorst.tv Git - l2e.git/blobdiff - src/main.cpp
started an interpreter for parsed sources
[l2e.git] / src / main.cpp
index cf6e78bbf6c9596235b82ecc5d18001881c68bb6..7a8b425d1a8bea52ddb3f302556f8c1ca5923d3e 100644 (file)
@@ -17,7 +17,6 @@
 #include "common/Inventory.h"
 #include "common/Item.h"
 #include "common/Spell.h"
-#include "geometry/Point.h"
 #include "geometry/Vector.h"
 #include "graphics/ComplexAnimation.h"
 #include "graphics/Font.h"
 #include "graphics/Menu.h"
 #include "graphics/SimpleAnimation.h"
 #include "graphics/Sprite.h"
+#include "loader/Interpreter.h"
+#include "loader/ParsedSource.h"
+#include "loader/Parser.h"
 #include "sdl/InitImage.h"
 #include "sdl/InitScreen.h"
 #include "sdl/InitSDL.h"
 
+#include <cstdlib>
+#include <ctime>
 #include <exception>
 #include <iostream>
 #include <SDL.h>
@@ -46,7 +50,6 @@ using common::Ikari;
 using common::Inventory;
 using common::Item;
 using common::Spell;
-using geometry::Point;
 using geometry::Vector;
 using graphics::ComplexAnimation;
 using graphics::Font;
@@ -55,6 +58,9 @@ using graphics::Gauge;
 using graphics::Menu;
 using graphics::SimpleAnimation;
 using graphics::Sprite;
+using loader::Interpreter;
+using loader::ParsedSource;
+using loader::Parser;
 using sdl::InitImage;
 using sdl::InitScreen;
 using sdl::InitSDL;
@@ -70,7 +76,18 @@ int main(int argc, char **argv) {
 
        const int framerate = 33;
 
+//     std::srand(std::time(0));
+
        try {
+               ParsedSource source;
+               Parser parser("test-data/test.l2s", source);
+               parser.Parse();
+               cout << source;
+               Interpreter intp(source);
+               intp.ReadSource();
+
+               return 0;
+
                InitSDL sdl;
                InitImage image(IMG_INIT_PNG);
                InitScreen screen(width, height);
@@ -78,15 +95,15 @@ int main(int argc, char **argv) {
                // temporary test data
                SDL_Surface *bg(IMG_Load("test-data/battle-bg.png"));
                PartyLayout monstersLayout;
-               monstersLayout.AddPosition(Point<Uint8>(88, 88));
-               monstersLayout.AddPosition(Point<Uint8>(128, 88));
-               monstersLayout.AddPosition(Point<Uint8>(168, 88));
-               monstersLayout.AddPosition(Point<Uint8>(208, 88));
+               monstersLayout.AddPosition(Vector<Uint8>(88, 88));
+               monstersLayout.AddPosition(Vector<Uint8>(128, 88));
+               monstersLayout.AddPosition(Vector<Uint8>(168, 88));
+               monstersLayout.AddPosition(Vector<Uint8>(208, 88));
                PartyLayout heroesLayout;
-               heroesLayout.AddPosition(Point<Uint8>(48, 136));
-               heroesLayout.AddPosition(Point<Uint8>(128, 136));
-               heroesLayout.AddPosition(Point<Uint8>(80, 152));
-               heroesLayout.AddPosition(Point<Uint8>(160, 152));
+               heroesLayout.AddPosition(Vector<Uint8>(48, 136));
+               heroesLayout.AddPosition(Vector<Uint8>(128, 136));
+               heroesLayout.AddPosition(Vector<Uint8>(80, 152));
+               heroesLayout.AddPosition(Vector<Uint8>(160, 152));
 
                SDL_Surface *monsterImg(IMG_Load("test-data/monster.png"));
                Sprite monsterSprite(monsterImg, 64, 64);
@@ -121,8 +138,7 @@ int main(int argc, char **argv) {
                maxim.SetIP(0);
                maxim.SetStats(Stats(28, 22, 28, 17, 14, 100, 10));
                ComplexAnimation maximAttackAnimation(&maximSprite, framerate);
-               // TODO: cross check double frames; could be related to differences in framerates
-               maximAttackAnimation.AddFrames(1, 0, Vector<int>(0,  0), 7); // TODO: maybe this could also be a pause before the battle animation
+               maximAttackAnimation.AddFrames(1, 0, Vector<int>(0,  0), 7);
                maximAttackAnimation.AddFrames(1, 0, Vector<int>(4, -1), 2);
                maximAttackAnimation.AddFrames(2, 0, Vector<int>(4, -2), 2);
                maximAttackAnimation.AddFrames(2, 0, Vector<int>(6, -2), 2);
@@ -131,7 +147,7 @@ int main(int argc, char **argv) {
                maximAttackAnimation.AddFrames(2, 1, Vector<int>(0,  0), 1);
                maximAttackAnimation.AddFrames(2, 2, Vector<int>(0,  0), 2);
                maximAttackAnimation.AddFrames(2, 2, Vector<int>(2,  0), 1);
-               maximAttackAnimation.AddFrames(1, 0, Vector<int>(0,  0), 7); // TODO: maybe this could also be a pause between two animations
+               maximAttackAnimation.AddFrames(1, 0, Vector<int>(0,  0), 7);
                maxim.SetAttackAnimation(&maximAttackAnimation);
                ComplexAnimation maximSpellAnimation(&maximSprite, 5 * framerate);
                maximSpellAnimation.AddFrames(3, 0, Vector<int>(), 2);
@@ -481,6 +497,7 @@ int main(int argc, char **argv) {
                Item zircoSword;
                zircoSword.SetName("Zirco sword");
                zircoSword.SetMenuIcon(&swordIcon);
+               zircoSword.GetTargetingMode().TargetSingleEnemy();
                Ikari firestorm;
                firestorm.SetName("Firestorm");
                firestorm.SetCost(224);
@@ -505,7 +522,7 @@ int main(int argc, char **argv) {
                Ikari lightGuard;
                lightGuard.SetName("Light guard");
                lightGuard.SetCost(128);
-               lightGuard.GetTargetingMode().TargetAllAllies(); // FIXME: actually only targets self
+               lightGuard.GetTargetingMode().TargetAllAllies(); // actually only targets self
                lightGuard.SetMagical();
                holyShield.SetIkari(&lightGuard);
                maxim.SetShield(&holyShield);
@@ -515,7 +532,7 @@ int main(int argc, char **argv) {
                Ikari boomerang;
                boomerang.SetName("Boomerang");
                boomerang.SetCost(164);
-               boomerang.GetTargetingMode().TargetAllAllies(); // FIXME: actually only targets self
+               boomerang.GetTargetingMode().TargetAllAllies(); // actually only targets self
                boomerang.SetMagical();
                legendHelm.SetIkari(&boomerang);
                maxim.SetHelmet(&legendHelm);
@@ -543,6 +560,7 @@ int main(int argc, char **argv) {
                Item zircoWhip;
                zircoWhip.SetName("Zirco whip");
                zircoWhip.SetMenuIcon(&rodIcon);
+               zircoWhip.GetTargetingMode().TargetSingleEnemy();
                Ikari thundershriek;
                thundershriek.SetName("Thundershriek");
                thundershriek.SetCost(224);
@@ -604,6 +622,7 @@ int main(int argc, char **argv) {
                Item zircoAx;
                zircoAx.SetName("Zirco ax");
                zircoAx.SetMenuIcon(&axIcon);
+               zircoAx.GetTargetingMode().TargetSingleEnemy();
                Ikari torrent;
                torrent.SetName("Torrent");
                torrent.SetCost(224);
@@ -618,7 +637,7 @@ int main(int argc, char **argv) {
                Ikari ironBarrier;
                ironBarrier.SetName("Iron barrier");
                ironBarrier.SetCost(255);
-               ironBarrier.GetTargetingMode().TargetAllAllies(); // FIXME: actually only targets self
+               ironBarrier.GetTargetingMode().TargetAllAllies(); // actually only targets self
                ironBarrier.SetMagical();
                megaShield.SetIkari(&ironBarrier);
                guy.SetShield(&megaShield);
@@ -648,6 +667,7 @@ int main(int argc, char **argv) {
                Item lizardBlow;
                lizardBlow.SetName("Lizard blow");
                lizardBlow.SetMenuIcon(&swordIcon);
+               lizardBlow.GetTargetingMode().TargetSingleEnemy();
                Ikari dragonRush;
                dragonRush.SetName("Dragon rush");
                dragonRush.SetCost(164);
@@ -719,6 +739,9 @@ int main(int argc, char **argv) {
                app.Run();
 
                return 0;
+       } catch (Parser::Error &e) {
+               cerr << "parsing exception in file " << e.File() << " on line " << e.Line() << ": " << e.what() << endl;
+               return 1;
        } catch (exception &e) {
                cerr << "exception in main(): " << e.what() << endl;
                return 1;