Here is an interesting math problem…
I periodically create spheres ABOVE, BELOW, LEFT, RIGHT of all player’s Mothership to use for various reasons in the game. Calculating the ABOVE and BELOW is relatively easy. Just adding to Y value in 3d space. Though since some functions are XYZ and others XZY it can be a tiny confusing but not the math problem I am having here.
Calculating LEFT and RIGHT of the player’s Mothership, in relation to the center of the map… that is another thing entirely. It would be right or left depending on the ship’s location from center of the map.
Before I jump into my math books… has anybody else already done this?
My current code:
g_SphereRan = 0
-----If NMY ships in range do orders
----@param AllySob The Ally ship.
----@param range The range from Ally Ship.
--function SobGroup_ProxOrders(AllySob, range)
--
-- local tmpowner = SobGroup_OwnedBy(AllySob)
-- local playerIndex = 0;
-- while (playerIndex < playerCount) do
-- print("print checking player "..playerIndex)
-- print("print agaisnt "..tmpowner)
-- if (AreAllied(playerIndex, tmpowner) == 0) then
-- print("print NOT ALLY i think")
-- SobGroup_CreateIfNotExist ( "Player_Ships"..playerIndex.."Near" )
-- SobGroup_Clear("Player_Ships"..playerIndex.."Near")
-- SobGroup_FillProximitySobGroup("Player_Ships"..playerIndex.."Near", "Player_Ships"..playerIndex, AllySob, range)
-- local count = SobGroup_Count ("Player_Ships"..playerIndex.."Near")
-- print("print count of nmyships "..count)
-- if (count > 0)then
-- --Set up differant IF for each type of ship to have a new Order sent to.
-- --familylist.lua to find types of ships to include.
-- if SobGroup_AreAnyFromTheseAttackFamilies(AllySob, "Carrier, shipyard")==0 then
-- print("print we have carrier in ths group")
-- if SobGroup_AreAnyFromTheseAttackFamilies("Player_Ships"..playerIndex.."Near", "BattleCruiser, Capturer, Destroyer")==1 then
-- if ( SobGroup_Count(AllySob) > 0 and SobGroup_Count("SobMShipPlayer"..tmpowner) > 0 ) then
-- Tactics(AllySob, "Run")
-- print("print we have DD or BC or Capture in ths group")
-- SobGroup_MoveToSobGroup(AllySob, "SobMShipPlayer"..tmpowner) --WFB ??? Like to alternate way to escape
-- end
-- end
-- end
-- if SobGroup_AreAnyFromTheseAttackFamilies(AllySob, "Frigate, Fighter, Corvette")==1 then
-- if SobGroup_AreAnyFromTheseAttackFamilies("Player_Ships"..playerIndex.."Near", "Frigate, Capturer, SmallCapitalShip, BigCapitalShip")==1 then
--
-- end
-- end
-- end
-- end
-- playerIndex = playerIndex+1
-- end
--end
---Create Sphere (above, below, left, right) around players to use with AI.
function AddSphereEarlyRule()
local playerIndex = 0;
while (playerIndex < playerCount) do
if g_SphereRan == 1 then
Volume_Delete("EarlyPlayer"..playerIndex.."MSVolume")
Volume_Delete("EarlyPlayer"..playerIndex.."MSVolumeRIGHT")
Volume_Delete("EarlyPlayer"..playerIndex.."MSVolumeLEFT")
Volume_Delete("EarlyPlayer"..playerIndex.."MSVolumeABOVE")
Volume_Delete("EarlyPlayer"..playerIndex.."MSVolumeBELOW")
g_SphereRan = 1 --Dont run first time
end
if (SobGroup_Empty("SobMShipPlayer"..playerIndex) ~= 1) then
local sobHumanMS_position = SobGroup_GetPosition("SobMShipPlayer"..playerIndex) --X. Y, Z
--print("print sobMS_position = {"..sobHumanMS_position[1]..", "..sobHumanMS_position[2]..", "..sobHumanMS_position[3].."},")
local RIGHT = sobHumanMS_position[1] - 9500
--Testing
local tempprint = sobHumanMS_position[1]
print("COORDS "..tempprint)
local tempprint = sobHumanMS_position[2]
print("COORDS "..tempprint)
local tempprint = sobHumanMS_position[3]
print("COORDS "..tempprint)
local tempprint = g_mapCoords[1]
print("COORDS "..tempprint)
local tempprint = g_mapCoords[2]
print("COORDS "..tempprint)
local tempprint = g_mapCoords[3]
print("COORDS "..tempprint)
local LEFT = sobHumanMS_position[1] + 9500 --Left Sphere of player
local ABOVE = sobHumanMS_position[2] + 9500
local BELOW = sobHumanMS_position[2] - 9500
local FORWARD = sobHumanMS_position[3] + 7500
local BACK = sobHumanMS_position[3] - 7500
Volume_AddSphere("EarlyPlayer"..playerIndex.."MSVolume", sobHumanMS_position, 3000 ) --X, Z, Y Ex. EarlyPlayer1MSVoume
--Volume_AddSphere("EarlyPlayer"..playerIndex.."MSVolumeRIGHT", {RIGHT, sobHumanMS_position[2], BACK}, 10 ) --X, Z, Y RIGHT of
--Volume_AddSphere("EarlyPlayer"..playerIndex.."MSVolumeLEFT", {LEFT, sobHumanMS_position[2], sobHumanMS_position[3]}, 10 ) --X, Z, Y LEFT of
Volume_AddSphere("EarlyPlayer"..playerIndex.."MSVolumeABOVE", {sobHumanMS_position[1], sobHumanMS_position[3], ABOVE}, 1000 ) --X, Z, Y ABOVE
Volume_AddSphere("EarlyPlayer"..playerIndex.."MSVolumeBELOW", {sobHumanMS_position[1], sobHumanMS_position[3], BELOW}, 10 ) --Z, Z, Y BELOW
end
playerIndex = playerIndex+1
end
end
On a side note there were some other items I was researching…
- plotting bezier curve. (specifically the point in 3d space of the top of the curve.)
- plotting straight line and will a Volume intersect.
- distance between SOB Groups (game has this)
- distance between SOBGroup and Volume. (can be solved from 3.
Distance, as found in existing game lua.
function SobGroup_GetDistanceToSobGroup(sg_Group1, sg_Group2)
if SobGroup_Empty(sg_Group1) == 0 and SobGroup_Empty(sg_Group2) == 0 then
local t_position1 = SobGroup_GetPosition(sg_Group1)
local t_position2 = SobGroup_GetPosition(sg_Group2)
local li_distance = floor(sqrt((t_position1[1] - t_position2[1])*(t_position1[1] - t_position2[1]) + (t_position1[2] - t_position2[2])*(t_position1[2] - t_position2[2]) + (t_position1[3] - t_position2[3])*(t_position1[3] - t_position2[3])))
return li_distance
else
return nil
end
end