]> git.localhorst.tv Git - l2e.git/blobdiff - src/main.cpp
new object file format in compiler
[l2e.git] / src / main.cpp
index 31724d5b22acd42f67b0222f8a954234c77981ad..73a9f16fff877eb6ddc013e6cd3b2b4f7e2169ee 100644 (file)
@@ -1,21 +1,25 @@
+#include "keys.h"
 #include "app/Application.h"
 #include "app/Arguments.h"
 #include "app/Input.h"
 #include "battle/BattleState.h"
+#include "battle/Capsule.h"
 #include "battle/Hero.h"
 #include "battle/Monster.h"
 #include "battle/PartyLayout.h"
 #include "battle/Resources.h"
+#include "common/Capsule.h"
 #include "common/GameConfig.h"
 #include "common/GameState.h"
 #include "common/Hero.h"
 #include "common/Ikari.h"
 #include "common/Inventory.h"
 #include "common/Item.h"
+#include "common/LevelUp.h"
 #include "common/Script.h"
 #include "common/Spell.h"
 #include "common/Stats.h"
-#include "geometry/Vector.h"
+#include "graphics/CharSelect.h"
 #include "graphics/ComplexAnimation.h"
 #include "graphics/Font.h"
 #include "graphics/Frame.h"
@@ -25,7 +29,9 @@
 #include "graphics/Sprite.h"
 #include "graphics/Texture.h"
 #include "loader/Caster.h"
+#include "loader/Compiler.h"
 #include "loader/Interpreter.h"
+#include "loader/Loader.h"
 #include "loader/ParsedSource.h"
 #include "loader/Parser.h"
 #include "loader/TypeDescription.h"
@@ -35,6 +41,8 @@
 #include "map/MapState.h"
 #include "map/Tile.h"
 #include "map/Trigger.h"
+#include "math/Fixed.h"
+#include "math/Vector.h"
 #include "menu/Resources.h"
 #include "sdl/InitImage.h"
 #include "sdl/InitScreen.h"
@@ -55,19 +63,23 @@ using app::Input;
 using battle::BattleState;
 using battle::Monster;
 using battle::PartyLayout;
+using common::Capsule;
 using common::GameConfig;
 using common::GameState;
 using common::Hero;
 using common::Spell;
-using geometry::Vector;
 using graphics::Texture;
 using loader::Caster;
+using loader::Compiler;
 using loader::Interpreter;
+using loader::Loader;
 using loader::ParsedSource;
 using loader::Parser;
 using loader::TypeDescription;
 using map::Entity;
 using map::MapState;
+using math::Fixed;
+using math::Vector;
 using sdl::InitImage;
 using sdl::InitScreen;
 using sdl::InitSDL;
@@ -83,7 +95,7 @@ int main(int argc, char **argv) {
        const int width = 512;
        const int height = 448;
 
-       const float walkSpeed = 128.0f;
+       const Fixed<8> walkSpeed = Fixed<8>(1, 8);
 
        bool battle(false);
 
@@ -99,14 +111,17 @@ int main(int argc, char **argv) {
                battle::Monster::CreateTypeDescription();
                battle::PartyLayout::CreateTypeDescription();
 
+               common::Capsule::CreateTypeDescription();
                common::Hero::CreateTypeDescription();
                common::Ikari::CreateTypeDescription();
                common::Item::CreateTypeDescription();
+               common::LevelUp::CreateTypeDescription();
                common::Stats::CreateTypeDescription();
                common::Spell::CreateTypeDescription();
                common::TargetingMode::CreateTypeDescription();
 
                graphics::Animation::CreateTypeDescription();
+               graphics::CharSelect::CreateTypeDescription();
                graphics::ComplexAnimation::CreateTypeDescription();
                graphics::Font::CreateTypeDescription();
                graphics::Frame::CreateTypeDescription();
@@ -129,10 +144,25 @@ int main(int argc, char **argv) {
 
                ParsedSource source;
 
+               Loader ld;
+
                for (vector<char *>::const_iterator i(args.Infiles().begin()), end(args.Infiles().end()); i != end; ++i) {
-                       Parser(*i, source).Parse();
+                       string filePath(*i);
+                       switch (filePath[filePath.size() - 1]) {
+                               case 'o':
+                                       ld.Load(filePath);
+                                       break;
+                               case 's':
+                                       Parser(filePath, source).Parse();
+                                       break;
+                               default:
+                                       throw std::runtime_error("don't know what to do with " + filePath);
+                       }
                }
 
+               Interpreter intp(source);
+               intp.ReadSource();
+
                switch (args.GetRunLevel()) {
                        case Arguments::WRITE:
                        {
@@ -143,6 +173,15 @@ int main(int argc, char **argv) {
                                                source.WriteHeader(outstream);
                                                break;
                                        }
+                                       case 'o': {
+                                               std::fstream outstream(args.OutfilePath(), std::ios_base::out|std::ios_base::trunc);
+                                               outstream.flush();
+                                               outstream.close();
+                                               outstream.open(args.OutfilePath());
+                                               outstream.exceptions(std::ios_base::badbit|std::ios_base::failbit);
+                                               Compiler(intp).Write(outstream);
+                                               break;
+                                       }
                                        default: {
                                                throw std::runtime_error(string("don't know how to write file ") + args.OutfilePath());
                                        }
@@ -165,12 +204,9 @@ int main(int argc, char **argv) {
                                break;
                }
 
-               Interpreter intp(source);
-               intp.ReadSource();
-
                if (intp.PostponedDefinitions().size() > 0) {
                        for (vector<Interpreter::PostponedDefinition>::const_iterator i(intp.PostponedDefinitions().begin()), end(intp.PostponedDefinitions().end()); i != end; ++i) {
-                               std::cerr << "missing definition of " << TypeDescription::Get(i->linkedType).TypeName() << " " << i->identifier << std::endl;
+                               std::cerr << "missing definition of " << TypeDescription::Get(i->type).TypeName() << " " << i->identifier << std::endl;
                        }
                        return 3;
                }
@@ -190,6 +226,13 @@ int main(int argc, char **argv) {
                gameState.party[3] = &gameState.heroes[3];
                gameState.partySize = 4;
 
+               gameState.capsules[1] = *caster.GetCapsule("flash");
+               gameState.capsules[1].UpgradeClass();
+               gameState.capsules[1].UpgradeClass();
+               gameState.capsules[1].UpgradeClass();
+               gameState.capsules[1].UpgradeClass();
+               gameState.capsule = 1;
+
                GameConfig gameConfig;
                gameConfig.state = &gameState;
                gameConfig.heroesLayout = caster.GetPartyLayout("heroesLayout");
@@ -220,7 +263,9 @@ int main(int argc, char **argv) {
                gameState.heroes[0].AddSpell(valorSpell);
                gameState.heroes[1].AddSpell(valorSpell);
 
-               gameState.inventory.Add(caster.GetItem("zirconPlateItem"));
+               gameState.inventory.Add(caster.GetItem("zirconPlateItem"), 32);
+               gameState.inventory.Add(caster.GetItem("holyFruitItem"));
+               gameState.inventory.Add(caster.GetItem("darkFruitItem"));
                gameState.inventory.Add(caster.GetItem("antidoteItem"), 9);
                gameState.inventory.Add(caster.GetItem("powerRingItem"));
                gameState.inventory.Add(caster.GetItem("magicJarItem"), 4);
@@ -263,17 +308,17 @@ int main(int argc, char **argv) {
                gameState.heroes[3].SetEquipment(Hero::EQUIP_RING, caster.GetItem("rocketRingItem"));
                gameState.heroes[3].SetEquipment(Hero::EQUIP_JEWEL, caster.GetItem("krakenRockItem"));
 
-               gameState.heroes[0].MapEntity().Position() = Vector<float>(64, 128);
+               gameState.heroes[0].MapEntity().Position() = Vector<Fixed<8> >(64, 128);
 
-               gameState.heroes[1].MapEntity().Position() = Vector<float>(64, 128);
+               gameState.heroes[1].MapEntity().Position() = Vector<Fixed<8> >(64, 128);
                gameState.heroes[1].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING);
                gameState.heroes[0].MapEntity().AddFollower(&gameState.heroes[1].MapEntity());
 
-               gameState.heroes[2].MapEntity().Position() = Vector<float>(64, 128);
+               gameState.heroes[2].MapEntity().Position() = Vector<Fixed<8> >(64, 128);
                gameState.heroes[2].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING);
                gameState.heroes[1].MapEntity().AddFollower(&gameState.heroes[2].MapEntity());
 
-               gameState.heroes[3].MapEntity().Position() = Vector<float>(64, 128);
+               gameState.heroes[3].MapEntity().Position() = Vector<Fixed<8> >(64, 128);
                gameState.heroes[3].MapEntity().SetFlags(Entity::FLAG_NONBLOCKING);
                gameState.heroes[2].MapEntity().AddFollower(&gameState.heroes[3].MapEntity());
 
@@ -287,6 +332,7 @@ int main(int argc, char **argv) {
                        battleState->AddMonster(monster);
                        battleState->AddMonster(monster);
                        battleState->AddMonster(monster);
+                       battleState->SetCapsule(caster.GetCapsule("flash"));
                        battleState->AddHero(gameState.heroes[0]);
                        battleState->AddHero(gameState.heroes[1]);
                        battleState->AddHero(gameState.heroes[2]);
@@ -302,22 +348,7 @@ int main(int argc, char **argv) {
                }
 
                Application app(screen, state);
-               app.Buttons().MapKey(SDLK_w, Input::PAD_UP);
-               app.Buttons().MapKey(SDLK_d, Input::PAD_RIGHT);
-               app.Buttons().MapKey(SDLK_s, Input::PAD_DOWN);
-               app.Buttons().MapKey(SDLK_a, Input::PAD_LEFT);
-               app.Buttons().MapKey(SDLK_RIGHT, Input::ACTION_A);
-               app.Buttons().MapKey(SDLK_DOWN, Input::ACTION_B);
-               app.Buttons().MapKey(SDLK_UP, Input::ACTION_X);
-               app.Buttons().MapKey(SDLK_LEFT, Input::ACTION_Y);
-               app.Buttons().MapKey(SDLK_RETURN, Input::START);
-               app.Buttons().MapKey(SDLK_SPACE, Input::SELECT);
-               app.Buttons().MapKey(SDLK_RSHIFT, Input::SHOULDER_RIGHT);
-               app.Buttons().MapKey(SDLK_LSHIFT, Input::SHOULDER_LEFT);
-               app.Buttons().MapKey(SDLK_1, Input::DEBUG_1);
-               app.Buttons().MapKey(SDLK_2, Input::DEBUG_2);
-               app.Buttons().MapKey(SDLK_3, Input::DEBUG_3);
-               app.Buttons().MapKey(SDLK_4, Input::DEBUG_4);
+               MapKeys(app.Buttons());
                app.Run();
 
                return 0;