1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-07 03:12:36 +01:00

add getModel to ScriptArguments to lookup script models

This commit is contained in:
Daniel Evans 2016-06-20 21:17:41 +01:00
parent f2eaa05759
commit 4ff4515ad7
2 changed files with 23 additions and 0 deletions

View File

@ -108,6 +108,8 @@ public:
return parameters->at(arg);
}
int getModel(unsigned int arg) const;
template <class T>
GameObject* getObject(unsigned int arg) const;

View File

@ -4,6 +4,8 @@
#include <engine/GameWorld.hpp>
#include <objects/CharacterObject.hpp>
#include <ai/PlayerController.hpp>
#include <script/SCMFile.hpp>
#include <engine/GameData.hpp>
GameState* ScriptArguments::getState() const
{
@ -15,6 +17,25 @@ GameWorld* ScriptArguments::getWorld() const
return getVM()->getState()->world;
}
int ScriptArguments::getModel(unsigned int arg) const
{
RW_CHECK(arg < getParameters().size(), "arg out of range");
if (arg >= getParameters().size()) {
return 0;
}
int id = getParameters()[arg].integerValue();
/// @todo verify this behaviour
if (id < 0) {
id = -id;
const auto& model = getVM()->getFile()->getModels()[id];
id = getWorld()->data->findModelObject(model);
}
return id;
}
GameObject* ScriptArguments::getPlayerCharacter(unsigned int player) const
{
auto playerId = parameters->at(player).integerValue();