Skip to content

Commit

Permalink
LuaSynced: add Spring.GetProjectileTarget(number projectileID) --> nu…
Browse files Browse the repository at this point in the history
…mber targetID, string targetType
  • Loading branch information
rt committed Mar 3, 2013
1 parent c642f0d commit b53e586
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 34 deletions.
10 changes: 5 additions & 5 deletions rts/Lua/LuaSyncedCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2741,7 +2741,7 @@ int LuaSyncedCtrl::SetProjectileSpinAngle(lua_State* L)
return 0;
}

CPieceProjectile* pproj = dynamic_cast<CPieceProjectile*>(proj);
CPieceProjectile* pproj = static_cast<CPieceProjectile*>(proj);
pproj->spinAngle = luaL_optfloat(L, 2, 0.0f);
return 0;
}
Expand All @@ -2753,7 +2753,7 @@ int LuaSyncedCtrl::SetProjectileSpinSpeed(lua_State* L)
return 0;
}

CPieceProjectile* pproj = dynamic_cast<CPieceProjectile*>(proj);
CPieceProjectile* pproj = static_cast<CPieceProjectile*>(proj);
pproj->spinSpeed = luaL_optfloat(L, 2, 0.0f);
return 0;
}
Expand All @@ -2765,7 +2765,7 @@ int LuaSyncedCtrl::SetProjectileSpinVec(lua_State* L)
return 0;
}

CPieceProjectile* pproj = dynamic_cast<CPieceProjectile*>(proj);
CPieceProjectile* pproj = static_cast<CPieceProjectile*>(proj);
pproj->spinVec.x = luaL_optfloat(L, 2, 0.0f);
pproj->spinVec.y = luaL_optfloat(L, 3, 0.0f);
pproj->spinVec.z = luaL_optfloat(L, 4, 0.0f);
Expand All @@ -2783,13 +2783,13 @@ int LuaSyncedCtrl::SetProjectileCEG(lua_State* L)
assert(proj->weapon || proj->piece);

if (proj->weapon) {
CWeaponProjectile* wproj = dynamic_cast<CWeaponProjectile*>(proj);
CWeaponProjectile* wproj = static_cast<CWeaponProjectile*>(proj);
if (wproj != NULL) {
wproj->cegID = gCEG->Load(explGenHandler, luaL_checkstring(L, 2));
}
}
if (proj->piece) {
CPieceProjectile* pproj = dynamic_cast<CPieceProjectile*>(proj);
CPieceProjectile* pproj = static_cast<CPieceProjectile*>(proj);
if (pproj != NULL) {
pproj->cegID = gCEG->Load(explGenHandler, luaL_checkstring(L, 2));
}
Expand Down
85 changes: 56 additions & 29 deletions rts/Lua/LuaSyncedRead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ bool LuaSyncedRead::PushEntries(lua_State* L)
REGISTER_LUA_CFUNC(GetProjectileSpinAngle);
REGISTER_LUA_CFUNC(GetProjectileSpinSpeed);
REGISTER_LUA_CFUNC(GetProjectileSpinVec);
REGISTER_LUA_CFUNC(GetProjectileTarget);
REGISTER_LUA_CFUNC(GetProjectileType);
REGISTER_LUA_CFUNC(GetProjectileName);

Expand Down Expand Up @@ -4406,11 +4407,10 @@ int LuaSyncedRead::GetFeatureCollisionVolumeData(lua_State* L)

int LuaSyncedRead::GetProjectilePosition(lua_State* L)
{
CProjectile* pro = ParseProjectile(L, __FUNCTION__, 1);
const CProjectile* pro = ParseProjectile(L, __FUNCTION__, 1);

if (pro == NULL) {
if (pro == NULL)
return 0;
}

lua_pushnumber(L, pro->pos.x);
lua_pushnumber(L, pro->pos.y);
Expand All @@ -4420,11 +4420,10 @@ int LuaSyncedRead::GetProjectilePosition(lua_State* L)

int LuaSyncedRead::GetProjectileVelocity(lua_State* L)
{
CProjectile* pro = ParseProjectile(L, __FUNCTION__, 1);
const CProjectile* pro = ParseProjectile(L, __FUNCTION__, 1);

if (pro == NULL) {
if (pro == NULL)
return 0;
}

lua_pushnumber(L, pro->speed.x);
lua_pushnumber(L, pro->speed.y);
Expand All @@ -4435,51 +4434,47 @@ int LuaSyncedRead::GetProjectileVelocity(lua_State* L)

int LuaSyncedRead::GetProjectileGravity(lua_State* L)
{
CProjectile* pro = ParseProjectile(L, __FUNCTION__, 1);
const CProjectile* pro = ParseProjectile(L, __FUNCTION__, 1);

if (pro == NULL) {
if (pro == NULL)
return 0;
}

lua_pushnumber(L, pro->mygravity);
return 1;
}

int LuaSyncedRead::GetProjectileSpinAngle(lua_State* L)
{
CProjectile* pro = ParseProjectile(L, __FUNCTION__, 1);
const CProjectile* pro = ParseProjectile(L, __FUNCTION__, 1);

if (pro == NULL || !pro->piece) {
if (pro == NULL || !pro->piece)
return 0;
}

CPieceProjectile* ppro = dynamic_cast<CPieceProjectile*>(pro);
const CPieceProjectile* ppro = static_cast<const CPieceProjectile*>(pro);
lua_pushnumber(L, ppro->spinAngle);
return 1;
}

int LuaSyncedRead::GetProjectileSpinSpeed(lua_State* L)
{
CProjectile* pro = ParseProjectile(L, __FUNCTION__, 1);
const CProjectile* pro = ParseProjectile(L, __FUNCTION__, 1);

if (pro == NULL || !pro->piece) {
if (pro == NULL || !pro->piece)
return 0;
}

CPieceProjectile* ppro = dynamic_cast<CPieceProjectile*>(pro);
const CPieceProjectile* ppro = static_cast<const CPieceProjectile*>(pro);
lua_pushnumber(L, ppro->spinSpeed);
return 1;
}

int LuaSyncedRead::GetProjectileSpinVec(lua_State* L)
{
CProjectile* pro = ParseProjectile(L, __FUNCTION__, 1);
const CProjectile* pro = ParseProjectile(L, __FUNCTION__, 1);

if (pro == NULL || !pro->piece) {
if (pro == NULL || !pro->piece)
return 0;
}

CPieceProjectile* ppro = dynamic_cast<CPieceProjectile*>(pro);
const CPieceProjectile* ppro = static_cast<const CPieceProjectile*>(pro);

lua_pushnumber(L, ppro->spinVec.x);
lua_pushnumber(L, ppro->spinVec.y);
Expand All @@ -4488,13 +4483,46 @@ int LuaSyncedRead::GetProjectileSpinVec(lua_State* L)
}


int LuaSyncedRead::GetProjectileType(lua_State* L)
int LuaSyncedRead::GetProjectileTarget(lua_State* L)
{
CProjectile* pro = ParseProjectile(L, __FUNCTION__, 1);
const CProjectile* pro = ParseProjectile(L, __FUNCTION__, 1);

if (pro == NULL) {
if (pro == NULL || !pro->weapon)
return 0;

const CWeaponProjectile* wpro = static_cast<const CWeaponProjectile*>(pro);
const CWorldObject* wtgt = wpro->target;

if (wtgt == NULL)
return 0;

if (dynamic_cast<const CUnit*>(wtgt) != NULL) {
lua_pushnumber(L, wtgt->id);
lua_pushstring(L, "u");
return 2;
}
if (dynamic_cast<const CFeature*>(wtgt) != NULL) {
lua_pushnumber(L, wtgt->id);
lua_pushstring(L, "f");
return 2;
}
if (dynamic_cast<const CWeaponProjectile*>(wtgt) != NULL) {
lua_pushnumber(L, wtgt->id);
lua_pushstring(L, "p");
return 2;
}

// projectile target cannot be anything else
assert(false);
return 0;
}

int LuaSyncedRead::GetProjectileType(lua_State* L)
{
const CProjectile* pro = ParseProjectile(L, __FUNCTION__, 1);

if (pro == NULL)
return 0;

lua_pushboolean(L, pro->weapon);
lua_pushboolean(L, pro->piece);
Expand All @@ -4503,14 +4531,13 @@ int LuaSyncedRead::GetProjectileType(lua_State* L)

int LuaSyncedRead::GetProjectileName(lua_State* L)
{
CProjectile* pro = ParseProjectile(L, __FUNCTION__, 1);
const CProjectile* pro = ParseProjectile(L, __FUNCTION__, 1);

if (pro == NULL) {
if (pro == NULL)
return 0;
}

if (pro->weapon) {
const CWeaponProjectile* wpro = dynamic_cast<const CWeaponProjectile*>(pro);
const CWeaponProjectile* wpro = static_cast<const CWeaponProjectile*>(pro);

if (wpro != NULL && wpro->weaponDef != NULL) {
// maybe CWeaponProjectile derivatives
Expand All @@ -4520,7 +4547,7 @@ int LuaSyncedRead::GetProjectileName(lua_State* L)
}
}
if (pro->piece) {
const CPieceProjectile* ppro = dynamic_cast<const CPieceProjectile*>(pro);
const CPieceProjectile* ppro = static_cast<const CPieceProjectile*>(pro);

if (ppro != NULL && ppro->omp != NULL) {
lua_pushsstring(L, ppro->omp->name);
Expand Down
1 change: 1 addition & 0 deletions rts/Lua/LuaSyncedRead.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ class LuaSyncedRead {
static int GetProjectileSpinAngle(lua_State* L);
static int GetProjectileSpinSpeed(lua_State* L);
static int GetProjectileSpinVec(lua_State* L);
static int GetProjectileTarget(lua_State* L);
static int GetProjectileType(lua_State* L);
static int GetProjectileName(lua_State* L);

Expand Down

0 comments on commit b53e586

Please sign in to comment.