Scenario Editing

From MegaGlest
Revision as of 09:00, 9 July 2009 by Hailstone3 (talk) (Useful Links:)
Jump to: navigation, search

In newer Glests (3.2.0 beta and newer) lua scripting gives us a new possibility. Scripted Scenarios!

The game includes 2 tutorial scenarios and one scripted normal scenario(storming) now. These demo scenarios show a bit what's possible now. Have a look at them if you want to learn it.

Useful Links:


Coordinate System:

The origin {0,0} is at the top left of the screen (needs double checking). The largest x value is the first number in the map size (eg 128 x 128) and goes from 0 on the left to the maximum x at the right. The largest y value is the second number in the map size (eg 128 x 128) and goes from 0 on the top to the maximum y at the bottom. When ever there is a parameter requiring positions of type Vec2i you can use the format {x,y} (where x and y are number values within the map size) to select a position on the map.

The available functions

As there is no list of the possible commands now, here a copy of some things from script_manager.h (from the glest sourcecode) which should contain/show all possible Glest lua-commands.


Message Box Functions

bool getMessageBoxEnabled() const {return !messageQueue.empty();}

GraphicMessageBox* getMessageBox() {return &messageBox;}

string getDisplayText() const {return displayText;}

bool getGameOver() const {return gameOver;}

const PlayerModifiers *getPlayerModifiers(int factionIndex) const {return &playerModifiers[factionIndex];}



Events

void onMessageBoxOk();

void onResourceHarvested();

void onUnitCreated(const Unit* unit);

void onUnitDied(const Unit* unit);


private:


string wrapString(const string &str, int wrapCount);



Wrappers, Commands

void showMessage(const string &text, const string &header);

void clearDisplayText();

void setDisplayText(const string &text);

void setCameraPosition(const Vec2i &pos);

void createUnit(const string &unitName, int factionIndex, Vec2i pos);

void giveResource(const string &resourceName, int factionIndex, int amount);

void givePositionCommand(int unitId, const string &producedName, const Vec2i &pos);

void giveProductionCommand(int unitId, const string &producedName);

void giveUpgradeCommand(int unitId, const string &upgradeName);

void disableAi(int factionIndex);

void setPlayerAsWinner(int factionIndex);

void endGame();



Wrappers, Queries

Vec2i getStartLocation(int factionIndex);

Vec2i getUnitPosition(int unitId);

int getUnitFaction(int unitId);

int getResourceAmount(const string &resourceName, int factionIndex);

const string &getLastCreatedUnitName();

int getLastCreatedUnitId();

const string &getLastDeadUnitName();

int getLastDeadUnitId();

int getUnitCount(int factionIndex);

int getUnitCountOfType(int factionIndex, const string &typeName);



Callbacks, Commands

static int showMessage(LuaHandle* luaHandle);

static int setDisplayText(LuaHandle* luaHandle);

static int clearDisplayText(LuaHandle* luaHandle);

static int setCameraPosition(LuaHandle* luaHandle);

static int createUnit(LuaHandle* luaHandle);

static int giveResource(LuaHandle* luaHandle);

static int givePositionCommand(LuaHandle* luaHandle);

static int giveProductionCommand(LuaHandle* luaHandle);

static int giveUpgradeCommand(LuaHandle* luaHandle);

static int disableAi(LuaHandle* luaHandle);

static int setPlayerAsWinner(LuaHandle* luaHandle);

static int endGame(LuaHandle* luaHandle);



Callbacks, Queries

static int getStartLocation(LuaHandle* luaHandle);

static int getUnitPosition(LuaHandle* luaHandle);

static int getUnitFaction(LuaHandle* luaHandle);

static int getResourceAmount(LuaHandle* luaHandle);

static int getLastCreatedUnitName(LuaHandle* luaHandle);

static int getLastCreatedUnitId(LuaHandle* luaHandle);

static int getLastDeadUnitName(LuaHandle* luaHandle);

static int getLastDeadUnitId(LuaHandle* luaHandle);

static int getUnitCount(LuaHandle* luaHandle);

static int getUnitCountOfType(LuaHandle* luaHandle);