Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --+------------------+-----------------+
- --| EXPANSION MOD | 03.07.2019 |
- --+------------------------------------+
- --| Author: Nocalora | Version |
- --+------------------+ 0.6.2X |
- --| Module | RC19 |
- --+------------------+-----------------+
- --| Gameplay Element Core |
- --+------------------------------------+
- -- Object-Oriented-Programming approach
- -- Create a new Capture Point
- --
- -- cp1 = CP_CreateCapturePoint(
- -- 1 {Vector3(-100, 0, -100), Vector3(100, 0, -100), Vector3(100, 0, 100), Vector3(-100, 0, 100)},
- -- 2 CP_Config,
- -- 3 {PLAYER_TEAM});
- --
- --ToDo:
- -- - Add AttachOnCaptureEvent(function, args) + sub-point variant
- -- - Add AttachOnLoseEvent(function, args) + sub-point variant
- --
- -- END GOAL: Optimize and make as few calculations as possible.
- --
- function CP_CreateCapturePoint(sName, tPositions, tConfig, tSides, fOnCapture)
- LOG("[CP]: Creating new Capture Point: "..sName);
- --This Object
- local self = {};
- -- Sets --
- self.Name = sName; -- Name of the Capture Point
- self.Positions = tPositions; -- Positions of the Capture Points (Vector3 Table)
- self.Config = tConfig; -- Configuration of this Capture Point set
- self.Sides = tSides; -- Sides which can interact with this Capture Point set
- self.OnCapture = fOnCapture; -- Function to exec on Capture Event (complete CP)
- self.Amount = getn(tPositions); -- Amount of Positions in a Control Point
- self.Points = {}; -- Data involving the ownership of the Points
- self.PointsConnection = {}; -- The Connection NavPoint and associated Lines | [1] is reserved for central NavPoint for the control point
- --self.Points[].Lines = {}; -- Lines associated with the Point
- --self.Points[].NavPoints = {}; -- NavPoints associated with the Point | [5] is reserved for the central NavPoint for the sub-point
- --self.Points[].Ships = {}; -- Ships inside the Point
- --self.Points[].ShipsIDs = {}; -- Associated IDs and their Ships
- --self.Points[].Ownership = {TEAM, GROUP};-- Owning Faction
- --self.Points[].OwnershipVal= VALUE; -- Ownership Percentage
- self.FullOwnership = FALSE; -- If all points are owned by one side
- self.FullOwnershipSide = nil; -- Full Ownership Side
- self.DoUpdates = TRUE; -- If autoexec should remain active
- -- Gets --
- -- Get Positions of the Capture Points
- function self:GetPositions() return self.Positions; end;
- function self:GetConfig() return self.Config; end;
- function self:GetSides() return self.Sides; end;
- function self:GetOnCapture() return self.OnCapture(); end;
- function self:GetOnLoose() return self.OnLoose(); end;
- function self:GetAmount() return self.Amount; end;
- function self:GetPoints() return self.Points; end;
- function self:HasFullownership() return self.FullOwnership; end;
- function self:GetFullownershipSide() return self.FullOwnershipSide; end;
- -- Create the Capture "Points" --
- local tThisPoint, iThisX , iThusY, iThisZ;
- LOG("[CP]: Creating Points for Capture Point");
- for i = 1, self.Amount, 1 do
- LOG("[CP]: Creating Points... ["..i.."/"..self.Amount.."]");
- tThisPoint = self.Positions[i];
- iThisX = tThisPoint.x;
- iThisY = tThisPoint.y;
- iThisZ = tThisPoint.z;
- -- Save the points in the class.
- self.Points[i] = tThisPoint;
- LOG("[CP]: at: "..iThisX.." ".. iThisY.." "..iThisZ);
- -- Prepare the Tables
- self.Points[i].NavPoints = {};
- self.Points[i].Lines = {};
- self.Points[i].Connection = {};
- self.Points[i].Ships = {};
- self.Points[i].ShipsIDs = {};
- self.Points[i].Ownership = {};
- self.Points[i].Ownership.Team = nil;
- self.Points[i].Ownership.Group = nil;
- self.Points[i].OwnershipVal = 0;
- self.Points[i].FortifyVal = 0;
- self.Points[i].FortifyStage = 0;
- self.Points[i].FortifyRebuiltVal = 0;
- self.Points[i].FortifyFlight = nil;
- end;
- --DrawPoints(string sOwnerColor)
- function self:DrawPoints(sOwnerColor)
- LOG("[CP]: DrawPoints()");
- local vec3Pos, np1, np2, np3, np4, npm, npl1, npl2, npl3, npl4;
- for i = 1, self.Amount, 1 do
- local NavPoints, Lines = {}, {};
- vec3Pos = self.Positions[i];
- np1 = CreateNavPoint(" Point: "..i, Vector3(vec3Pos.x + 100, 0, vec3Pos.z), "nav_void.dds");
- np2 = CreateNavPoint(" ", Vector3(vec3Pos.x, 0, vec3Pos.z + 100), "nav_void.dds");
- np3 = CreateNavPoint(" ", Vector3(vec3Pos.x - 100, 0, vec3Pos.z), "nav_void.dds");
- np4 = CreateNavPoint(" ", Vector3(vec3Pos.x, 0, vec3Pos.z - 100), "nav_void.dds");
- npm = CreateNavPoint(" ", Vector3(vec3Pos.x, 0, vec3Pos.z), "nav_void.dds");
- --CreateLine(npSrc, npDest, vec3RGB, iLineWidth, bAnimated, iAnimSpeed, iArrowMode
- -- iArrowMode | 0 = No Arrow, 1 = Arrow at Dest, 2 = Arrow at Source, 3 = Arrow at Src AND Dest
- npl1 = CreateLine(np1, np2, self.Config["tColors"][sOwnerColor], .2, TRUE, .2, 0);
- npl2 = CreateLine(np2, np3, self.Config["tColors"][sOwnerColor], .2, TRUE, .2, 0);
- npl3 = CreateLine(np3, np4, self.Config["tColors"][sOwnerColor], .2, TRUE, .2, 0);
- npl4 = CreateLine(np4, np1, self.Config["tColors"][sOwnerColor], .2, TRUE, .2, 0);
- tinsert(NavPoints, np1);
- tinsert(NavPoints, np2);
- tinsert(NavPoints, np3);
- tinsert(NavPoints, np4);
- tinsert(NavPoints, npm);
- tinsert(Lines, npl1);
- tinsert(Lines, npl2);
- tinsert(Lines, npl3);
- tinsert(Lines, npl4);
- LOG("[CP]: DrawPoints(): Adding NavPoints and Lines for Point: ["..i.."/"..self.Amount.."]");
- self.Points[i].NavPoints = NavPoints;
- self.Points[i].Lines = Lines;
- end;
- end;
- --DeletePoint(int iPositionIndex)
- function self:DeletePoint(iPositionIndex)
- for j = 1, 5, 1 do
- if (self.Points[iPositionIndex].Lines[j]) then self.Points[iPositionIndex].Lines[j]:Delete(); end;
- if (self.Points[iPositionIndex].NavPoints[j]) then self.Points[iPositionIndex].NavPoints[j]:Delete(); end;
- end;
- end;
- --DrawPointConnections(RGB sOwnerColor)
- function self:DrawPointConnections(sOwnerColor)
- LOG("[CP]: DrawPointConnections()");
- local vec3Center, npc, npcl = Vector3(0, 0, 0);
- for i = 1, self.Amount, 1 do
- vec3Center.x = vec3Center.x + self.Positions[i].x;
- vec3Center.z = vec3Center.z + self.Positions[i].z;
- end;
- vec3Center.x = (vec3Center.x / self.Amount);
- vec3Center.z = (vec3Center.z / self.Amount);
- npc = CreateNavPoint(self.sName, Vector3(vec3Center.x, 0, vec3Center.z), "nav_void.dds");
- self.PointsConnection[1] = npc;
- for i = 1, self.Amount, 1 do
- npcl = CreateLine(npc, self.Points[i].NavPoints[5], self.Config["tColors"][sOwnerColor], .2, TRUE, .2, 0);
- self.PointsConnection[1 + i] = npcl;
- end;
- end;
- --DrawPointConnection(RGB sOwnerColor, int iPositionIndex)
- function self:DrawPointConnection(sOwnerColor, iPositionIndex)
- LOG("[CP]: DrawPointConnection() for Point: "..iPositionIndex.." with sOwnerColor: "..sOwnerColor);
- local npcp_mid = self.PointsConnection[1];
- local npsubpoint_mid = self.Points[iPositionIndex].NavPoints[5];
- local rgbcolor = self.Config["tColors"][sOwnerColor];
- local linecenterline = CreateLine(npcp_mid, npsubpoint_mid, rgbcolor, .2, TRUE, .2, 0);
- self.PointsConnection[1 + iPositionIndex] = linecenterline;
- end;
- --RedrawPointConnection(RGB sOwnerColor, int iPositionIndex)
- function self:RedrawPointConnection(sOwnerColor, iPositionIndex)
- LOG("[CP]: RedrawPointConnection() for Point: "..iPositionIndex.." with sOwnerColor: "..sOwnerColor);
- self.PointsConnection[1 + iPositionIndex]:Delete(); -- Delete old Connection Point
- self:DrawPointConnection(sOwnerColor, iPositionIndex); -- Create new Connection Point
- end;
- --DeletePointConnections(int iPositionIndex)
- function self:DeletePointConnections(tself, iPositionIndex)
- tself.PointsConnection[1]:Delete(); -- Delete NavPoint
- for j = 1, tself.Amount, 1 do
- tself.PointsConnection[1 + j]:Delete(); -- Delete Line
- end;
- end;
- --RedrawPoint(RGB sOwnerColor, int iPositionIndex): Redraws a specific Point
- function self:RedrawPoint(sOwnerColor, iPositionIndex)
- -- Delete old Point
- LOG("[CP]: RedrawPoint(): Removing Lines and NavPoints for Point: ["..iPositionIndex.."/"..self.Amount.."]");
- self:DeletePoint(iPositionIndex);
- -- Create new Point
- self:DrawPoint(sOwnerColor, iPositionIndex);
- end;
- --DrawPoint(RGB OwnerColor, int iPositionIndex): Draws a specific Point
- function self:DrawPoint(sOwnerColor, iPositionIndex)
- LOG("[CP]: DrawPoint(): for "..iPositionIndex.." with sOwner: "..sOwnerColor);
- local NavPoints, Lines = {}, {};
- vec3Pos = self.Positions[iPositionIndex];
- np1 = CreateNavPoint(" Point: "..iPositionIndex, Vector3(vec3Pos.x + 100, 0, vec3Pos.z), "nav_void.dds");
- np2 = CreateNavPoint(" ", Vector3(vec3Pos.x, 0, vec3Pos.z + 100), "nav_void.dds");
- np3 = CreateNavPoint(" ", Vector3(vec3Pos.x - 100, 0, vec3Pos.z), "nav_void.dds");
- np4 = CreateNavPoint(" ", Vector3(vec3Pos.x, 0, vec3Pos.z - 100), "nav_void.dds");
- npm = CreateNavPoint(" ", Vector3(vec3Pos.x, 0, vec3Pos.z), "nav_void.dds");
- --CreateLine(npSrc, npDest, vec3RGB, iLineWidth, bAnimated, iAnimSpeed, iArrowMode
- -- iArrowMode | 0 = No Arrow, 1 = Arrow at Dest, 2 = Arrow at Source, 3 = Arrow at Src AND Dest
- npl1 = CreateLine(np1, np2, self.Config["tColors"][sOwnerColor], .2, TRUE, .2, 0);
- npl2 = CreateLine(np2, np3, self.Config["tColors"][sOwnerColor], .2, TRUE, .2, 0);
- npl3 = CreateLine(np3, np4, self.Config["tColors"][sOwnerColor], .2, TRUE, .2, 0);
- npl4 = CreateLine(np4, np1, self.Config["tColors"][sOwnerColor], .2, TRUE, .2, 0);
- tinsert(NavPoints, np1);
- tinsert(NavPoints, np2);
- tinsert(NavPoints, np3);
- tinsert(NavPoints, np4);
- tinsert(NavPoints, npm);
- tinsert(Lines, npl1);
- tinsert(Lines, npl2);
- tinsert(Lines, npl3);
- tinsert(Lines, npl4);
- LOG("[CP]: DrawPoint(): Adding NavPoints and Lines for Point: ["..iPositionIndex.."/"..self.Amount.."]");
- self.Points[iPositionIndex].NavPoints = NavPoints;
- self.Points[iPositionIndex].Lines = Lines;
- end;
- --HasShipsInsidePoint(int iPositionIndex)
- function self:HasShipsInsidePoint(iPositionIndex)
- LOG("[CP]: HasShipsInsidePoint() of "..iPositionIndex);
- if (getn(self.Points[iPositionIndex].Ships) >= 1) then
- LOG("[CP]: HasShipsInsidePoint() of "..iPositionIndex.." returns TRUE");
- for i = 1, getn(self.Points[iPositionIndex].Ships), 1 do
- LOG("[CP]: "..self.Points[iPositionIndex].Ships[i]:GetName());
- end;
- return TRUE;
- end;
- LOG("[CP]: HasShipsInsidePoint() of "..iPositionIndex.." returns FALSE");
- return FALSE;
- end;
- --GetFirstSideOfPoint(int iPositionIndex)
- function self:GetFirstSideOfPoint(iPositionIndex)
- return self.Points[iPositionIndex].Ships[1]:GetPilot():GetSide();
- end;
- --GetFirstGroupOfPoint(int iPositionIndex)
- function self:GetFirstGroupOfPoint(iPositionIndex)
- return self.Points[iPositionIndex].Ships[1]:GetPilot():GetGroup();
- end;
- --HasMultipleSidesInPoint(int iPositionIndex) (Will return either a TRUE or FALSE depending if the Point only consists of one claiming Side or multiple)
- function self:HasMultipleSidesInPoint(iPositionIndex)
- LOG("[CP]: HasMultipleSidesInPoint() of "..iPositionIndex);
- local latestSide, curSide = nil, nil;
- for i = 1, getn(self.Points[iPositionIndex].Ships), 1 do
- curSide = self.Points[iPositionIndex].Ships[i]:GetPilot():GetSide();
- if (latestSide == nil) then
- latestSide = curSide;
- break;
- end;
- if (latestSide ~= curSide) then
- LOG("[CP]: HasMultipleSidesInPoint() of "..iPositionIndex.." returns TRUE");
- return TRUE;
- end;
- end;
- LOG("[CP]: HasMultipleSidesInPoint() of "..iPositionIndex.." returns FALSE");
- return FALSE;
- end;
- --UpdateOwnership(int iPositionIndex)
- --Cases:
- -- - One Side inside Point : Point "Ownership" percentage goes up for that faction.
- -- - Two sides inside Point : Point "Ownership" percentage halts.
- -- - No side inside Point : Point "Ownership" percentage goes down.
- function self:UpdatePointOwnership(iPositionIndex)
- LOG("[CP]: UpdatePointOwnership()");
- -- Check if the sub-point even has ships in it
- if (self:HasShipsInsidePoint(iPositionIndex) == TRUE) then
- if (self:HasMultipleSidesInPoint(iPositionIndex) == TRUE) then -- Multiple sides (HALT PERCENTAGE)
- -- Do nothing
- LOG("[CP]: UpdatePointOwnership(): Do Nothing in "..iPositionIndex);
- else -- Only one side inside sub-point (INCREASE PERCENTAGE)
- if (self.Points[iPositionIndex].Ownership.Team == self:GetFirstSideOfPoint(iPositionIndex)) then -- The ownership matches with the current residing side. (INCREASE PERCENTAGE)
- self:IncreasePointOwnership(iPositionIndex);
- else -- The ownership doesnt match with the current residing. (DECREASE PERCENTAGE)
- self:DecreasePointOwnership(iPositionIndex);
- if (self.Points[iPositionIndex].OwnershipVal == 0) then -- Percentage is 0, update side ownership with new owner
- self.Points[iPositionIndex].Ownership.Team = self:GetFirstSideOfPoint(iPositionIndex);
- self.Points[iPositionIndex].Ownership.Group = self:GetFirstGroupOfPoint(iPositionIndex);
- self:UpdateColors(iPositionIndex); -- Update the Colors
- end;
- end;
- end;
- else -- No sides inside sub-point (LOWER PERCENTAGE)
- if (self.Points[iPositionIndex].OwnershipVal == 100) then -- Ownership Percentage is 100, do not decrease.
- elseif (self.Points[iPositionIndex].OwnershipVal == 0) then -- Ownership Percentage is zero
- else
- self:DecreasePointOwnership(iPositionIndex);
- if (self.Points[iPositionIndex].OwnershipVal == 0) then -- Ownership Percentage just reachd zero
- self.Points[iPositionIndex].Ownership.Team = "Unowned";
- self:UpdateColors(iPositionIndex);
- end;
- end;
- end;
- end;
- --Event: On Complete Control of Capture Point
- function self:EventOnCompleteControl()
- LOG("[CP]: EventOnCompleteControl()");
- if (self.FullOwnership == TRUE) then
- LOG("[CP]: EventOnCompleteControl(): Complete ownership from a side | Executing OnCapture, passing Side as Arg");
- ExecFunc(self.OnCapture, {0, self.FullOwnershipSide});
- end;
- end;
- --IncreasePointOwnership(int iPositionIndex)
- function self:IncreasePointOwnership(iPositionIndex)
- if (self.Points[iPositionIndex].OwnershipVal < 100) then
- local iIncrement = (self.Config["iCaptureSpeedperUnit"] * getn(self.Points[iPositionIndex].Ships));
- if (getn(self.Points[iPositionIndex].Ships) == 0) then iIncrement = self.Config["iCaptureSpeedperUnit"]; end;
- self.Points[iPositionIndex].OwnershipVal = self.Points[iPositionIndex].OwnershipVal + iIncrement;
- LOG("[CP]: IncreasePointOwnership(): Increasing % | Residing Side Matches | in "..iPositionIndex.." | current "..self.Points[iPositionIndex].OwnershipVal);
- if (self.Points[iPositionIndex].Ownership.Team == PLAYER_TEAM) then OutputToScreenLog(self.Points[iPositionIndex].OwnershipVal.."% Captured", 1); end;
- else -- percentage is 100
- LOG("[CP]: IncreasePointOwnership(): Increasing % | % = 100 | Residing Side Matches | in "..iPositionIndex);
- end;
- end;
- --DecreasePointOwnership(int iPositionIndex)
- function self:DecreasePointOwnership(iPositionIndex)
- if (self.Points[iPositionIndex].OwnershipVal >= 1) then
- local iDecrement = (self.Config["iCaptureSpeedperUnit"] * getn(self.Points[iPositionIndex].Ships));
- if (getn(self.Points[iPositionIndex].Ships) == 0) then iDecrement = self.Config["iCaptureSpeedperUnit"]; end;
- self.Points[iPositionIndex].OwnershipVal = self.Points[iPositionIndex].OwnershipVal - iDecrement;
- LOG("[CP]: DecreasePointOwnership(): Lowering % | in "..iPositionIndex.." | current "..self.Points[iPositionIndex].OwnershipVal);
- else -- percentage is 0
- LOG("[CP]: DecreasePointOwnership(): Lowering % | % = 0 | in "..iPositionIndex);
- end;
- end;
- --UpdateColors(int iPositionIndex) (Refreshes the Colors according to ownership of individual Capture sub-point)
- function self:UpdateColors(iPositionIndex)
- LOG("[CP]: UpdateColors() with position: "..iPositionIndex);
- local sideOwner = self.Points[iPositionIndex].Ownership.Team;
- if (sideOwner == "Unowned") then
- self:RedrawPoint("Unowned", iPositionIndex);
- self:RedrawPointConnection("Unowned", iPositionIndex);
- elseif (sideOwner == PLAYER_TEAM) then
- self:RedrawPoint("Player", iPositionIndex);
- self:RedrawPointConnection("Player", iPositionIndex);
- elseif (GetTeamRelation(sideOwner, PLAYER_TEAM) == RELATION_FRIEND) then
- self:RedrawPoint("Allied", iPositionIndex);
- self:RedrawPointConnection("Allied", iPositionIndex);
- elseif (GetTeamRelation(sideOwner, PLAYER_TEAM) == RELATION_WAR) then
- self:RedrawPoint("War", iPositionIndex);
- self:RedrawPointConnection("War", iPositionIndex);
- elseif (GetTeamRelation(sideOwner, PLAYER_TEAM) == RELATION_NEUTRAL) then
- self:RedrawPoint("Neutral", iPositionIndex);
- self:RedrawPointConnection("Neutral", iPositionIndex);
- end;
- end;
- --Update()
- function self:Update(tself)
- LOG("[CP]: Update(): ");
- -- Check for full Ownership
- local sideP1Owner, bSameOwner = tself.Points[1].Ownership.Team, TRUE;
- for i = 1, tself.Amount, 1 do -- go through each Capture Point sub-point.
- tself:UpdatePointOwnership(i);
- tself:EventOnCompleteControl(i);
- if ((tself.Points[i].Ownership.Team == sideP1Owner) and (sideP1Owner ~= nil)) then --same owner and or one is Unowned
- else --different owner
- LOG("[CP]: UpdatePointOwnership(): different owners in "..i);
- bSameOwner = FALSE;
- end;
- end;
- if (bSameOwner == TRUE) then
- tself.FullOwnership = TRUE;
- end;
- end;
- --Add/Remove Flight: ID Approach
- function self:AddFlightToPoint(iPositionIndex, flight)
- LOG("[CP]: AddFlightToPoint added flight of Leader: "..flight:GetLeader():GetShip():GetName().." id: "..flight.id);
- local flightPilots = flight:GetPilotCount();
- for i = 1, flightPilots, 1 do
- self:AddShipToPoint(iPositionIndex, flight:GetPilotByNumber(i):GetShip());
- end;
- end;
- function self:RemoveFlightFromPoint(iPositionIndex, flight)
- LOG("[CP]: RemoveFlightFromPoint removed flight of Leader: "..flight:GetLeader():GetShip():GetName().." id: "..flight.id);
- local flightPilots = flight:GetPilotCount();
- for i = 1, flightPilots, 1 do
- self:RemoveShipFromPoint(iPositionIndex, flight:GetPilotByNumber(i):GetShip());
- end;
- end;
- --Add/Remove Ship: ID Approach
- --AddShipToPoint(int iPositionIndex, ship shipCarcass)
- function self:AddShipToPoint(iPositionIndex, shipCarcass)
- LOG("[CP]: AddShipToPoint added ship: "..shipCarcass:GetName().." id: "..shipCarcass.id);
- tinsert(self.Points[iPositionIndex].Ships, shipCarcass);
- self.Points[iPositionIndex].ShipsIDs[tostring(shipCarcass.id)] = getn(self.Points[iPositionIndex].Ships); -- The id now can be used to get the index of the ship.
- LOG("[CP]: Added Index: "..getn(self.Points[iPositionIndex].Ships)..", ID: "..shipCarcass.id);
- end;
- --RemoveShipFromPoint(int iPositionIndex, ship shipCarcass)
- function self:RemoveShipFromPoint(iPositionIndex, shipCarcass)
- LOG("[CP]: RemoveShipFromPoint removed ship: "..shipCarcass:GetName().." id: "..shipCarcass.id);
- local shipIndex = self.Points[iPositionIndex].ShipsIDs[tostring(shipCarcass.id)];
- if (shipIndex) then
- LOG("[CP]: Removed Index: "..shipIndex.."/"..getn(self.Points[iPositionIndex].Ships)..", ID: "..shipCarcass.id);
- tremove(self.Points[iPositionIndex].Ships, shipIndex);
- tremove(self.Points[iPositionIndex].ShipsIDs, shipCarcass.id);
- else
- LOG("[CP]: Error while: Removing Index: ?/"..getn(self.Points[iPositionIndex].Ships)..", ID: "..shipCarcass.id);
- end;
- end;
- --OnShipEnter Event (Receives the Position Index of the Point)
- function self:EventOnSideEnter(tself, iPositionIndex)
- LOG("[CP]: Event: OnShipEnter() fired on PositionIndex "..iPositionIndex);
- local TriggerContext = GetTriggerContext();
- local triggeringPilot = TriggerContext:GetPilot();
- local triggeringShip = triggeringPilot:GetShip();
- local triggeringPointVec = tself.Positions[iPositionIndex];
- if (tself:IsShipInside(iPositionIndex, triggeringShip) == FALSE) then
- tself:AddFlightToPoint(iPositionIndex, triggeringPilot:GetFlight());
- TU_CreateOnLeaveShipTrigger(triggeringPointVec, 100, triggeringShip, tself.EventOnSideLeave, {0, tself, iPositionIndex}); -- Attach OnLeave event for entered Ship
- end;
- end;
- --OnShipLeave Event (Receives the Position Index of the Point)
- function self:EventOnSideLeave(tself, iPositionIndex)
- LOG("[CP]: Event: OnShipLeave() fired on PositionIndex "..iPositionIndex);
- local TriggerContext = GetTriggerContext();
- local triggeringTargetObj = TriggerContext:GetTargetObject();
- local triggeringPilot = triggeringTargetObj:GetPilot();
- local triggeringShip = triggeringPilot:GetShip();
- tself:RemoveFlightFromPoint(iPositionIndex, triggeringPilot:GetFlight());
- TU_CreateOnEnterTrigger(tself.Positions[iPositionIndex], 100, tself.Sides, tself.EventOnSideEnter, {0, tself, iPositionIndex}); -- ReAttach OnEnter event for side
- end;
- --IsShipInside(int iPositionIndex, ship shipCarcass) (Returns wether a ship is inside the sub-point or not)
- function self:IsShipInside(iPositionIndex, shipCarcass)
- local shipCurship;
- for i = 1, getn(self.Points[iPositionIndex].Ships), 1 do
- shipCurship = self.Points[iPositionIndex].Ships[i];
- if (shipCarcass.id == shipCurship.id) then
- return TRUE;
- end;
- end;
- return FALSE;
- end;
- --ToggleCaptureable(bool isCaptureable)
- function self:ToggleCaptureable(bCapturable)
- LOG("[CP]: ToggleCaptureable()");
- if (bCapturable == TRUE) then
- local vec3Pos;
- for i = 1, self.Amount, 1 do
- vec3Pos = self.Positions[i];
- LOG("[CP]: Created Trigger for Position ["..i.."/"..self.Amount.."]");
- -- Create OnEnter Trigger to make Capture possible
- TU_CreateOnEnterTrigger(vec3Pos, 100, self.Sides, self.EventOnSideEnter, {0, self, i});
- end;
- end;
- end;
- -- self:UpdateCondition()
- function self:UpdateCondition()
- return TRUE;
- end;
- --Delete()
- function self:Delete()
- for i = 1, self.Amount, 1 do
- self:DeletePointConnections(self, i);
- self:DeletePoint(i);
- self.Points[i].Lines = nil;
- self.Points[i].NavPoints = nil;
- self.Points[i].Ships = nil;
- self.Points[i].ShipsIDs = nil;
- self.Points[i].Ownership = nil;
- self.Points[i].OwnershipVal = nil;
- end;
- self.Name = nil;
- self.Positions = nil;
- self.Config = nil;
- self.Sides = nil;
- self.OnCapture = nil;
- self.Amount = nil;
- self.Points = nil;
- self.PointsConnection = nil;
- self.FullOwnership = nil;
- self.FullOwnershipSide = nil;
- self.DoUpdates = nil;
- self = nil;
- end;
- -- Draw the Points
- self:DrawPoints("Unowned");
- self:ToggleCaptureable(TRUE);
- self:DrawPointConnections("Unowned", TRUE);
- -- Activate the Update Function
- ExecEvery(self.Config["iUpdateTime"], self.Update, {0, self},
- function()
- if (%self.Name == nil) then
- return FALSE;
- else
- return %self:UpdateCondition();
- end;
- end);
- LOG("[CP]: Returning Capture Point");
- return self;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement