コード例 #1
0
void CDestructibleModel::DoExplosion(char* pTargetName)
{
	CWeapons weapons;
	weapons.Init(m_hObject);
	weapons.ObtainWeapon(m_nExplosionWeaponId);
	weapons.ChangeWeapon(m_nExplosionWeaponId);

	CWeapon* pWeapon = weapons.GetCurWeapon();
	if (!pWeapon) return;

	weapons.SetAmmo(pWeapon->GetAmmoId());

	pWeapon->SetDamageFactor(m_fDamageFactor);

	LTRotation rRot;
	g_pLTServer->GetObjectRotation(m_hObject, &rRot);

	LTVector vF, vPos;
	g_pLTServer->GetObjectPos(m_hObject, &vPos);
	vF = rRot.Forward();

	// Just blow up in place if we're not supposed to fire along
	// forward vector and we don't have a target...

	if (!m_bFireAlongForward)
	{
		pWeapon->SetLifetime(0.0f);
		VEC_SET(vF, 0.0f, -1.0f, 0.0f);  // Fire down
	}

	// See if we have a target...If so, point at it.

	if (pTargetName)
	{
		ObjArray <HOBJECT, MAX_OBJECT_ARRAY_SIZE> objArray;
		g_pLTServer->FindNamedObjects(pTargetName, objArray);

		if (objArray.NumObjects())
		{
			LTVector vObjPos;
			g_pLTServer->GetObjectPos(objArray.GetObject(0), &vObjPos);
			vF = vObjPos - vPos;
			vF.Normalize();

			rRot = LTRotation(vF, LTVector(0.0f, 1.0f, 0.0f));
			g_pLTServer->SetObjectRotation(m_hObject, &rRot);
		}
	}

	WeaponFireInfo weaponFireInfo;
	weaponFireInfo.hFiredFrom	= m_hObject;
	weaponFireInfo.vPath		= vF;
	weaponFireInfo.vFirePos	= vPos;
	weaponFireInfo.vFlashPos	= vPos;

	pWeapon->Fire(weaponFireInfo);
}
コード例 #2
0
/*EntityName sirve para leer dentro del componente la informacion correcta segun el xml*/
Component * CEntityFactory::NewComponent(const String& name, CEntity * entity, const String& entityName){
	if (name == "render"){
		CRender * render = new CRender(entity);
		render->Init(m_entitiesInfo, entityName);
		return render;
	}
	else if (name == "stats"){
		CStats * stats = new CStats(entity);
		stats->Init(m_entitiesInfo, entityName);
		return stats;
	}
	else if (name == "collision"){
		CColisionComponent * collision = new CColisionComponent(entity);
		collision->Init();
		return collision;
	}
	else if (name == "controller"){
		CController * controller = new CController(entity);
		controller->Init(m_entitiesInfo, entityName);
		return controller;
	}
	else if (name == "ia"){
		CEnemyIA * ia = new CEnemyIA(entity);
		ia->Init();
		return ia;
	}
	else if (name == "weapons"){
		CWeapons * weapons = new CWeapons(entity);
		weapons->Init(m_entitiesInfo, entityName);
		return weapons;
	}
	else if (name == "iafighters"){
		CIAFighters * ia = new CIAFighters(entity);
		ia->Init();
		return ia;
	}
	else if (name == "traction"){
		CTraction * traction = new CTraction(entity);
		return traction;
	}
	else if (name == "weapon1movement"){
		CWeapon1Movement * weapon = new CWeapon1Movement(entity);
		return weapon;
	}
	else{
		return nullptr;
	}
}