Ejemplo n.º 1
0
int ant::InternalLuaScriptExports::createActor( const char* actorArchetype, LuaPlus::LuaObject luaPosition, LuaPlus::LuaObject luaRotation )
{
	if (!luaPosition.IsTable())
	{
		GCC_ERROR("Invalid object passed to createActor(); type = " + std::string(luaPosition.TypeName()));
		return INVALID_ACTOR_ID;
	}

	if (!luaRotation.IsNumber())
	{
		GCC_ERROR("Invalid object passed to createActor(); type = " + std::string(luaRotation.TypeName()));
		return INVALID_ACTOR_ID;
	}

	sf::Vector2f pos(luaPosition["x"].GetFloat(), luaPosition["y"].GetFloat());
	ant::Real rot = luaRotation.GetFloat();

	TiXmlElement *overloads = NULL;
	ActorStrongPtr actor = ant::ISFMLApp::getApp()->getGameLogic()->createActor(actorArchetype, overloads, &pos, &rot);

	if (actor)
	{
		shared_ptr<EvtData_New_Actor> pNewActorEvent(GCC_NEW EvtData_New_Actor(actor->getId()));
		IEventManager::instance()->queueEvent(pNewActorEvent);
		return actor->getId();
	}

	return INVALID_ACTOR_ID;
}
Ejemplo n.º 2
0
bool EvtData_StartJump::buildEventFromScript(void)
{
	if (m_eventData.IsTable())
	{
		// ID
		LuaPlus::LuaObject temp = m_eventData.GetByName("actorId");
		if (temp.IsInteger())
		{
			m_id = temp.GetInteger();
		}
		else
		{
			GCC_ERROR("Invalid id sent to EvtData_StartJump; type = " + std::string(temp.TypeName()));
			return false;
		}

		// acceleration
		temp = m_eventData.GetByName("acceleration");
		if (temp.IsNumber())
			m_acceleration = temp.GetFloat();
		else
			m_acceleration = 5.0f;  // something reasonable

		return true;
	}

	return false;
}
// apply force to an object from lua
void LuaInternalScriptExports::ApplyForce(LuaPlus::LuaObject normalDirectionLua, float force, int gameObjectId)
{
	if (normalDirectionLua.IsTable())
	{
		Vec3 normalDir(normalDirectionLua["x"].GetFloat(), normalDirectionLua["y"].GetFloat(), normalDirectionLua["z"].GetFloat());
		g_pApp->m_pGame->GetGamePhysics()->ApplyForce(normalDir, force, gameObjectId);
		return;
	}
	CB_ERROR("Invalid object passed to ApplyForce(). Type = " + std::string(normalDirectionLua.TypeName()));
}
Ejemplo n.º 4
0
void InternalScriptExports::ApplyTorque(LuaPlus::LuaObject axisLua, float force, int actorId)
{
    if (axisLua.IsTable())
    {
        Vec3 axis(axisLua["x"].GetFloat(), axisLua["y"].GetFloat(), axisLua["z"].GetFloat());
		g_pApp->m_pGame->VGetGamePhysics()->VApplyTorque(axis, force, actorId);
		return;
    }
    GCC_ERROR("Invalid object passed to ApplyTorque(); type = " + std::string(axisLua.TypeName()));
}
Ejemplo n.º 5
0
void ant::InternalLuaScriptExports::lualog( LuaPlus::LuaObject text )
{
	if (text.IsConvertibleToString())
	{
		GCC_LOG("Lua",text.ToString());
	}
	else
	{
		GCC_LOG("Lua","<" + std::string(text.TypeName()) + ">");
	}
}
// write to the log from lua script
void LuaInternalScriptExports::LuaLog(LuaPlus::LuaObject text)
{
	if (text.IsConvertibleToString())
	{
		CB_LOG("Lua", text.ToString());
	}
	else
	{
		CB_LOG("Lua", "<" + std::string(text.TypeName()) + ">");
	}
}
// get the y rotation in radians from a lua vec3
float LuaInternalScriptExports::GetYRotationFromVector(LuaPlus::LuaObject vec3)
{
	// make sure vec3 is a table
	if (vec3.IsTable())
	{
		Vec3 lookAt(vec3["x"].GetFloat(), vec3["y"].GetFloat(), vec3["z"].GetFloat());
		// use the GetYRotationFromVector from math.h
		return ::GetYRotationFromVector(lookAt);
	}

	CB_ERROR("Invalid object passed to GetYRotationFromVector(); type = " + std::string(vec3.TypeName()));
	return 0;
}
// create a game object from lua
int LuaInternalScriptExports::CreateGameObject(const char* objectArchetype, LuaPlus::LuaObject luaPosition, LuaPlus::LuaObject luaYawPitchRoll)
{
	// lua position must be a table
	if (!luaPosition.IsTable())
	{
		CB_ERROR("Invalid object passed to CreateGameObject(). Type = " + std::string(luaPosition.TypeName()));
		return INVALID_GAMEOBJECT_ID;
	}
	// lua yawPitchRoll must be a table
	if (!luaYawPitchRoll.IsTable())
	{
		CB_ERROR("Invalid object passed to CreateGameObject(). Type = " + std::string(luaYawPitchRoll.TypeName()));
		return INVALID_GAMEOBJECT_ID;
	}

	Vec3 position(luaPosition["x"].GetFloat(), luaPosition["y"].GetFloat(), luaPosition["z"].GetFloat());
	Vec3 yawPitchRoll(luaYawPitchRoll["x"].GetFloat(), luaYawPitchRoll["y"].GetFloat(), luaYawPitchRoll["z"].GetFloat());
	// build the transform for the object
	Mat4x4 transform;
	transform.BuildYawPitchRoll(yawPitchRoll.x, yawPitchRoll.y, yawPitchRoll.z);
	transform.SetPosition(position);

	// create the object
	TiXmlElement* overloads = nullptr;
	StrongGameObjectPtr pObject = g_pApp->m_pGame->CreateGameObject(objectArchetype, overloads, &transform);

	// fire the new object created event
	if (pObject)
	{
		shared_ptr<Event_NewGameObject> pNewObjectEvent(CB_NEW Event_NewGameObject(pObject->GetId()));
		IEventManager::Get()->QueueEvent(pNewObjectEvent);
		return pObject->GetId();
	}

	return INVALID_GAMEOBJECT_ID;
}
Ejemplo n.º 9
0
bool EvtData_EndAccelerating::buildEventFromScript(void)
{
	if (m_eventData.IsTable())
	{
		// ID
		LuaPlus::LuaObject temp = m_eventData.GetByName("id");
		if (temp.IsInteger())
		{
			m_id = temp.GetInteger();
		}
		else
		{
			GCC_ERROR("Invalid id sent to EvtData_EndAccelerating; type = " + std::string(temp.TypeName()));
			return false;
		}

		return true;
	}

	return false;
}
Ejemplo n.º 10
0
float InternalScriptExports::GetYRotationFromVector(LuaPlus::LuaObject vec3)
{
    if (vec3.IsTable())
    {
        Vec3 lookAt(vec3["x"].GetFloat(), vec3["y"].GetFloat(), vec3["z"].GetFloat());
        return ::GetYRotationFromVector(lookAt);
    }

    GCC_ERROR("Invalid object passed to GetYRotationFromVector(); type = " + std::string(vec3.TypeName()));
    return 0;
}
Ejemplo n.º 11
-4
int InternalScriptExports::CreateActor(const char* actorArchetype, LuaPlus::LuaObject luaPosition, LuaPlus::LuaObject luaYawPitchRoll)
{

    if (!luaPosition.IsTable())
    {
	    GCC_ERROR("Invalid object passed to CreateActor(); type = " + std::string(luaPosition.TypeName()));
		return INVALID_ACTOR_ID;
	}

    if (!luaYawPitchRoll.IsTable())
    {
	    GCC_ERROR("Invalid object passed to CreateActor(); type = " + std::string(luaYawPitchRoll.TypeName()));
		return INVALID_ACTOR_ID;
	}

	Vec3 pos(luaPosition["x"].GetFloat(), luaPosition["y"].GetFloat(), luaPosition["z"].GetFloat());
	Vec3 ypr(luaYawPitchRoll["x"].GetFloat(), luaYawPitchRoll["y"].GetFloat(), luaYawPitchRoll["z"].GetFloat());

	Mat4x4 initialTransform;
	initialTransform.BuildYawPitchRoll(ypr.x, ypr.y, ypr.z);
	initialTransform.SetPosition(pos);

	TiXmlElement *overloads = NULL;
	StrongActorPtr pActor = g_pApp->m_pGame->VCreateActor(actorArchetype, overloads, &initialTransform);

	if (pActor)
	{
		shared_ptr<EvtData_New_Actor> pNewActorEvent(GCC_NEW EvtData_New_Actor(pActor->GetId()));
		IEventManager::Get()->VQueueEvent(pNewActorEvent);
		return pActor->GetId();
	}

	return INVALID_ACTOR_ID;
}