(svn r23618) -Add: ScriptGame::Pause, ScriptGame::Unpause, and ScriptGame::GetLandscape (GameScript only)
parent
37954d5098
commit
3a799f1145
@ -0,0 +1,36 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */
|
||||
|
||||
#include "../script_game.hpp"
|
||||
#include "../template/template_game.hpp.sq"
|
||||
|
||||
|
||||
template <> const char *GetClassName<ScriptGame, ST_GS>() { return "GSGame"; }
|
||||
|
||||
void SQGSGame_Register(Squirrel *engine)
|
||||
{
|
||||
DefSQClass<ScriptGame, ST_GS> SQGSGame("GSGame");
|
||||
SQGSGame.PreRegister(engine);
|
||||
SQGSGame.AddConstructor<void (ScriptGame::*)(), 1>(engine, "x");
|
||||
|
||||
SQGSGame.DefSQConst(engine, ScriptGame::LT_TEMPERATE, "LT_TEMPERATE");
|
||||
SQGSGame.DefSQConst(engine, ScriptGame::LT_ARCTIC, "LT_ARCTIC");
|
||||
SQGSGame.DefSQConst(engine, ScriptGame::LT_TROPIC, "LT_TROPIC");
|
||||
SQGSGame.DefSQConst(engine, ScriptGame::LT_TOYLAND, "LT_TOYLAND");
|
||||
|
||||
SQGSGame.DefSQStaticMethod(engine, &ScriptGame::Pause, "Pause", 1, ".");
|
||||
SQGSGame.DefSQStaticMethod(engine, &ScriptGame::Unpause, "Unpause", 1, ".");
|
||||
SQGSGame.DefSQStaticMethod(engine, &ScriptGame::IsPaused, "IsPaused", 1, ".");
|
||||
SQGSGame.DefSQStaticMethod(engine, &ScriptGame::GetLandscape, "GetLandscape", 1, ".");
|
||||
SQGSGame.DefSQStaticMethod(engine, &ScriptGame::IsMultiplayer, "IsMultiplayer", 1, ".");
|
||||
|
||||
SQGSGame.PostRegister(engine);
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file script_game.cpp Implementation of ScriptGame. */
|
||||
|
||||
#include "../../stdafx.h"
|
||||
#include "script_game.hpp"
|
||||
#include "../../command_type.h"
|
||||
#include "../../settings_type.h"
|
||||
#include "../../openttd.h"
|
||||
#include "../../network/network.h"
|
||||
|
||||
/* static */ bool ScriptGame::Pause()
|
||||
{
|
||||
return ScriptObject::DoCommand(0, PM_PAUSED_GAME_SCRIPT, 1, CMD_PAUSE);
|
||||
}
|
||||
|
||||
/* static */ bool ScriptGame::Unpause()
|
||||
{
|
||||
return ScriptObject::DoCommand(0, PM_PAUSED_GAME_SCRIPT, 0, CMD_PAUSE);
|
||||
}
|
||||
|
||||
/* static */ bool ScriptGame::IsPaused()
|
||||
{
|
||||
return !!_pause_mode;
|
||||
}
|
||||
|
||||
/* static */ ScriptGame::LandscapeType ScriptGame::GetLandscape()
|
||||
{
|
||||
return (ScriptGame::LandscapeType)_settings_game.game_creation.landscape;
|
||||
}
|
||||
|
||||
/* static */ bool ScriptGame::IsMultiplayer()
|
||||
{
|
||||
#ifdef ENABLE_NETWORK
|
||||
return _network_server;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file script_game.hpp Everything to manipulate the current running game. */
|
||||
|
||||
#ifndef SCRIPT_GAME_HPP
|
||||
#define SCRIPT_GAME_HPP
|
||||
|
||||
#include "script_object.hpp"
|
||||
#include "../../landscape_type.h"
|
||||
|
||||
/**
|
||||
* Class that handles some game related functions.
|
||||
* @api game
|
||||
*/
|
||||
class ScriptGame : public ScriptObject {
|
||||
public:
|
||||
/**
|
||||
* Type of landscapes known in the game.
|
||||
*/
|
||||
enum LandscapeType {
|
||||
/* Note: these values represent part of the in-game LandscapeType enum */
|
||||
LT_TEMPERATE = ::LT_TEMPERATE, ///< Temperate climiate.
|
||||
LT_ARCTIC = ::LT_ARCTIC, ///< Arctic climate.
|
||||
LT_TROPIC = ::LT_TROPIC, ///< Tropic climate.
|
||||
LT_TOYLAND = ::LT_TOYLAND, ///< Toyland climate.
|
||||
};
|
||||
|
||||
/**
|
||||
* Pause the server.
|
||||
* @return True if the action succeeded.
|
||||
*/
|
||||
static bool Pause();
|
||||
|
||||
/**
|
||||
* Unpause the server.
|
||||
* @return True if the action succeeded.
|
||||
*/
|
||||
static bool Unpause();
|
||||
|
||||
/**
|
||||
* Check if the game is paused.
|
||||
* @return True if and only if the game is paused (by which-ever means).
|
||||
* @note That a game is paused, doesn't always means you can unpause it. If
|
||||
* the game has been manually paused, or because of the pause_on_join in
|
||||
* Multiplayer for example, you cannot unpause the game.
|
||||
*/
|
||||
static bool IsPaused();
|
||||
|
||||
/**
|
||||
* Get the current landscape.
|
||||
*/
|
||||
static LandscapeType GetLandscape();
|
||||
|
||||
/**
|
||||
* Is this a multiplayer game?
|
||||
* @return True if this is a server in a multiplayer game.
|
||||
*/
|
||||
static bool IsMultiplayer();
|
||||
};
|
||||
|
||||
#endif /* SCRIPT_GAME_HPP */
|
@ -0,0 +1,25 @@
|
||||
/* $Id$ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */
|
||||
|
||||
#include "../script_game.hpp"
|
||||
|
||||
namespace SQConvert {
|
||||
/* Allow enums to be used as Squirrel parameters */
|
||||
template <> inline ScriptGame::LandscapeType GetParam(ForceType<ScriptGame::LandscapeType>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptGame::LandscapeType)tmp; }
|
||||
template <> inline int Return<ScriptGame::LandscapeType>(HSQUIRRELVM vm, ScriptGame::LandscapeType res) { sq_pushinteger(vm, (int32)res); return 1; }
|
||||
|
||||
/* Allow ScriptGame to be used as Squirrel parameter */
|
||||
template <> inline ScriptGame *GetParam(ForceType<ScriptGame *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptGame *)instance; }
|
||||
template <> inline ScriptGame &GetParam(ForceType<ScriptGame &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptGame *)instance; }
|
||||
template <> inline const ScriptGame *GetParam(ForceType<const ScriptGame *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptGame *)instance; }
|
||||
template <> inline const ScriptGame &GetParam(ForceType<const ScriptGame &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptGame *)instance; }
|
||||
template <> inline int Return<ScriptGame *>(HSQUIRRELVM vm, ScriptGame *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "Game", res, NULL, DefSQDestructorCallback<ScriptGame>, true); return 1; }
|
||||
} // namespace SQConvert
|
Loading…
Reference in New Issue