Start porting the overworld to scripting
This commit is contained in:
76
src/scriptengine/script_challenges.cpp
Normal file
76
src/scriptengine/script_challenges.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2014-2015 SuperTuxKart Team
|
||||
//
|
||||
// This program 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; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program 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 this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "script_track.hpp"
|
||||
|
||||
#include "animations/three_d_animation.hpp"
|
||||
#include "input/device_manager.hpp"
|
||||
#include "input/input_device.hpp"
|
||||
#include "input/input_manager.hpp"
|
||||
#include "modes/world.hpp"
|
||||
#include "states_screens/dialogs/tutorial_message_dialog.hpp"
|
||||
#include "tracks/track.hpp"
|
||||
#include "tracks/track_object.hpp"
|
||||
#include "tracks/track_object_manager.hpp"
|
||||
|
||||
#include <angelscript.h>
|
||||
#include <assert.h>
|
||||
|
||||
/** \cond DOXYGEN_IGNORE */
|
||||
namespace Scripting
|
||||
{
|
||||
/** \endcond */
|
||||
namespace Challenges
|
||||
{
|
||||
/** \addtogroup Scripting
|
||||
* @{
|
||||
*/
|
||||
/** \addtogroup Scripting_Challenges Challenges
|
||||
* @{
|
||||
*/
|
||||
|
||||
int getCompletedChallengesCount()
|
||||
{
|
||||
::Track* track = World::getWorld()->getTrack();
|
||||
return track->getNumOfCompletedChallenges();
|
||||
}
|
||||
|
||||
int getChallengeCount()
|
||||
{
|
||||
::Track* track = World::getWorld()->getTrack();
|
||||
return track->getChallengeList().size();
|
||||
}
|
||||
|
||||
/** @}*/
|
||||
/** @}*/
|
||||
|
||||
void registerScriptFunctions(asIScriptEngine *engine)
|
||||
{
|
||||
int r; // of type asERetCodes
|
||||
|
||||
engine->SetDefaultNamespace("Challenges");
|
||||
|
||||
r = engine->RegisterGlobalFunction("int getCompletedChallengesCount()", asFUNCTION(getCompletedChallengesCount), asCALL_CDECL); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("int getChallengeCount()", asFUNCTION(getChallengeCount), asCALL_CDECL); assert(r >= 0);
|
||||
}
|
||||
|
||||
/** \cond DOXYGEN_IGNORE */
|
||||
}
|
||||
}
|
||||
/** \endcond */
|
||||
|
||||
35
src/scriptengine/script_challenges.hpp
Normal file
35
src/scriptengine/script_challenges.hpp
Normal file
@@ -0,0 +1,35 @@
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2014-2015 SuperTuxKart Team
|
||||
//
|
||||
// This program 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; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program 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 this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#ifndef HEADER_SCRIPT_CHALLENGES_HPP
|
||||
#define HEADER_SCRIPT_CHALLENGES_HPP
|
||||
|
||||
#include <angelscript.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Scripting
|
||||
{
|
||||
namespace Challenges
|
||||
{
|
||||
//script engine functions
|
||||
void registerScriptFunctions(asIScriptEngine *engine);
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "io/file_manager.hpp"
|
||||
#include "karts/kart.hpp"
|
||||
#include "modes/world.hpp"
|
||||
#include "scriptengine/script_challenges.hpp"
|
||||
#include "scriptengine/script_engine.hpp"
|
||||
#include "scriptengine/script_gui.hpp"
|
||||
#include "scriptengine/script_track.hpp"
|
||||
@@ -335,6 +336,7 @@ namespace Scripting
|
||||
RegisterVec3(engine); //register Vec3
|
||||
|
||||
Scripting::Track::registerScriptFunctions(m_engine);
|
||||
Scripting::Challenges::registerScriptFunctions(m_engine);
|
||||
Scripting::Kart::registerScriptFunctions(m_engine);
|
||||
Scripting::Physics::registerScriptFunctions(m_engine);
|
||||
Scripting::Utils::registerScriptFunctions(m_engine);
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "input/input_manager.hpp"
|
||||
#include "modes/world.hpp"
|
||||
#include "states_screens/dialogs/tutorial_message_dialog.hpp"
|
||||
#include "states_screens/dialogs/race_paused_dialog.hpp"
|
||||
#include "tracks/track.hpp"
|
||||
#include "tracks/track_object.hpp"
|
||||
#include "tracks/track_object_manager.hpp"
|
||||
@@ -107,6 +108,11 @@ namespace Scripting
|
||||
{
|
||||
World::getWorld()->scheduleExitRace();
|
||||
}
|
||||
|
||||
void pauseRace()
|
||||
{
|
||||
new RacePausedDialog(0.8f, 0.6f);
|
||||
}
|
||||
}
|
||||
|
||||
/** \cond DOXYGEN_IGNORE */
|
||||
@@ -252,6 +258,7 @@ namespace Scripting
|
||||
asFUNCTION(createTrigger), asCALL_CDECL); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("TrackObject@ getTrackObject(const string &in)", asFUNCTION(getTrackObject), asCALL_CDECL); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("void exitRace()", asFUNCTION(exitRace), asCALL_CDECL); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("void pauseRace()", asFUNCTION(pauseRace), asCALL_CDECL); assert(r >= 0);
|
||||
|
||||
// TrackObject
|
||||
r = engine->RegisterObjectMethod("TrackObject", "void setEnable(bool status)", asMETHOD(TrackObject, setEnable), asCALL_THISCALL); assert(r >= 0);
|
||||
|
||||
@@ -29,8 +29,6 @@ namespace Scripting
|
||||
{
|
||||
//script engine functions
|
||||
void registerScriptFunctions(asIScriptEngine *engine);
|
||||
asIScriptFunction*
|
||||
registerScriptCallbacks(asIScriptEngine *engine , std::string scriptName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
#include "karts/abstract_kart.hpp"
|
||||
#include "modes/world.hpp"
|
||||
#include "scriptengine/script_engine.hpp"
|
||||
#include "states_screens/dialogs/race_paused_dialog.hpp"
|
||||
#include "states_screens/dialogs/tutorial_message_dialog.hpp"
|
||||
#include "tracks/model_definition_loader.hpp"
|
||||
#include "tracks/track.hpp"
|
||||
@@ -914,42 +913,13 @@ void TrackObjectPresentationActionTrigger::onTriggerItemApproached(Item* who)
|
||||
{
|
||||
if (!m_action_active) return;
|
||||
|
||||
// TODO: replace all of these hardcoded actions with scripting
|
||||
|
||||
if (m_action == "garage")
|
||||
{
|
||||
m_action_active = false;
|
||||
|
||||
new RacePausedDialog(0.8f, 0.6f);
|
||||
//dynamic_cast<OverWorld*>(World::getWorld())->scheduleSelectKart();
|
||||
}
|
||||
//action trigger near big doors in the overword to notify players that
|
||||
// they'll open once they finish all the challenges
|
||||
else if (m_action == "big_door")
|
||||
{
|
||||
m_action_active = false;
|
||||
|
||||
Track* m_track = World::getWorld()->getTrack();
|
||||
unsigned int unlocked_challenges = m_track->getNumOfCompletedChallenges();
|
||||
std::vector<OverworldChallenge> m_challenges = m_track->getChallengeList();
|
||||
|
||||
// allow ONE unsolved challenge : the last one
|
||||
if (unlocked_challenges < m_challenges.size() - 1)
|
||||
{
|
||||
new TutorialMessageDialog(
|
||||
_("Complete all challenges to unlock the big door!"), true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Scripting::ScriptEngine* script_engine =
|
||||
World::getWorld()->getScriptEngine();
|
||||
m_action_active = false;
|
||||
int idKart = 0;
|
||||
Camera* camera = Camera::getActiveCamera();
|
||||
if (camera != NULL && camera->getKart() != NULL)
|
||||
idKart = camera->getKart()->getWorldKartId();
|
||||
script_engine->runFunction("void " + m_action + "(int)",
|
||||
[=](asIScriptContext* ctx) { ctx->SetArgDWord(0, idKart); });
|
||||
}
|
||||
Scripting::ScriptEngine* script_engine =
|
||||
World::getWorld()->getScriptEngine();
|
||||
m_action_active = false; // TODO: allow auto re-activating?
|
||||
int idKart = 0;
|
||||
Camera* camera = Camera::getActiveCamera();
|
||||
if (camera != NULL && camera->getKart() != NULL)
|
||||
idKart = camera->getKart()->getWorldKartId();
|
||||
script_engine->runFunction("void " + m_action + "(int)",
|
||||
[=](asIScriptContext* ctx) { ctx->SetArgDWord(0, idKart); });
|
||||
} // onTriggerItemApproached
|
||||
|
||||
Reference in New Issue
Block a user