/** ** Create a missile on the map ** ** @param l Lua state. ** */ static int CclCreateMissile(lua_State *l) { LuaCheckArgs(l, 6); const std::string name = LuaToString(l, 1); const MissileType *mtype = MissileTypeByIdent(name); if (!mtype) { LuaError(l, "Bad missile"); } PixelPos startpos, endpos; if (!lua_istable(l, 2) || lua_rawlen(l, 2) != 2) { LuaError(l, "incorrect argument !!"); } lua_rawgeti(l, 2, 1); startpos.x = LuaToNumber(l, -1); lua_pop(l, 1); lua_rawgeti(l, 2, 2); startpos.y = LuaToNumber(l, -1); lua_pop(l, 1); if (!lua_istable(l, 3) || lua_rawlen(l, 3) != 2) { LuaError(l, "incorrect argument !!"); } lua_rawgeti(l, 3, 1); endpos.x = LuaToNumber(l, -1); lua_pop(l, 1); lua_rawgeti(l, 3, 2); endpos.y = LuaToNumber(l, -1); lua_pop(l, 1); const int sourceUnitId = LuaToNumber(l, 4); const int destUnitId = LuaToNumber(l, 5); const bool dealDamage = LuaToBoolean(l, 6); CUnit *sourceUnit = sourceUnitId != -1 ? &UnitManager.GetSlotUnit(sourceUnitId) : NULL; CUnit *destUnit = destUnitId != -1 ? &UnitManager.GetSlotUnit(destUnitId) : NULL; if (sourceUnit != NULL) { startpos += sourceUnit->GetMapPixelPosTopLeft(); } if (destUnit != NULL) { endpos += destUnit->GetMapPixelPosTopLeft(); } Missile *missile = MakeMissile(*mtype, startpos, endpos); if (!missile) { return 0; } if (dealDamage) { missile->SourceUnit = sourceUnit; } missile->TargetUnit = destUnit; return 0; }
/** ** Create a missile on the map ** ** @param l Lua state. ** */ static int CclCreateMissile(lua_State *l) { const int arg = lua_gettop(l); if (arg < 6 || arg > 7) { LuaError(l, "incorrect argument"); } const std::string name = LuaToString(l, 1); const MissileType *mtype = MissileTypeByIdent(name); if (!mtype) { LuaError(l, "Bad missile"); } PixelPos startpos, endpos; CclGetPos(l, &startpos.x, &startpos.y, 2); CclGetPos(l, &endpos.x, &endpos.y, 3); const int sourceUnitId = LuaToNumber(l, 4); const int destUnitId = LuaToNumber(l, 5); const bool dealDamage = LuaToBoolean(l, 6); const bool mapRelative = arg == 7 ? LuaToBoolean(l, 7) : false; CUnit *sourceUnit = sourceUnitId != -1 ? &UnitManager.GetSlotUnit(sourceUnitId) : nullptr; CUnit *destUnit = destUnitId != -1 ? &UnitManager.GetSlotUnit(destUnitId) : nullptr; if (mapRelative == false) { if (sourceUnit != nullptr) { startpos += sourceUnit->GetMapPixelPosTopLeft(); } if (destUnit != nullptr) { endpos += destUnit->GetMapPixelPosTopLeft(); } } //Wyrmgus start // Missile *missile = MakeMissile(*mtype, startpos, endpos); Missile *missile = MakeMissile(*mtype, startpos, endpos, 0); //Wyrmgus end if (!missile) { return 0; } if (dealDamage) { missile->SourceUnit = sourceUnit; } missile->TargetUnit = destUnit; return 0; }