diff --git a/Moose Development/Moose/Functional/CarrierTrainer.lua b/Moose Development/Moose/Functional/CarrierTrainer.lua index 4d043221e..14f1c40a7 100644 --- a/Moose Development/Moose/Functional/CarrierTrainer.lua +++ b/Moose Development/Moose/Functional/CarrierTrainer.lua @@ -144,7 +144,7 @@ CARRIERTRAINER.MenuF10={} --- Carrier trainer class version. -- @field #string version -CARRIERTRAINER.version="0.0.7" +CARRIERTRAINER.version="0.0.8" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- Constructor @@ -236,6 +236,7 @@ function CARRIERTRAINER:onafterStart(From, Event, To) -- Handle events. self:HandleEvent(EVENTS.Birth) + --self:HandleEvent(EVENTS.Lan) -- Init status check self:__Status(5) @@ -340,14 +341,6 @@ function CARRIERTRAINER:_InitNewRound(playerData) return playerData end ---- Increase score for this approach. --- @param #CARRIERTRAINER self --- @param #CARRIERTRAINER.PlayerData playerData Player data. --- @param #number amount Amount by which the score is increased. -function CARRIERTRAINER:_IncreaseScore(playerData, amount) - playerData.score = playerData.score + amount -end - --- Append text to summary text. -- @param #CARRIERTRAINER self -- @param #CARRIERTRAINER.PlayerData playerData Player data. @@ -429,7 +422,7 @@ function CARRIERTRAINER:_CheckPlayerStatus() self:_Groove(playerData) elseif playerData.step == 9 and unit:IsInZone(self.giantZone) then self:_Trap(playerData) - end + end else -- Unit not alive. --playerDatas[i] = nil @@ -758,22 +751,25 @@ function CARRIERTRAINER:_NewRound(playerData) playerData.step = 1 end ---- Start landing pattern. +--- Start landing pattern, when player enters the start zone. -- @param #CARRIERTRAINER self -- @param #CARRIERTRAINER.PlayerData playerData Player data table. function CARRIERTRAINER:_Start(playerData) - local hint = string.format("Entering the pattern, %s! Aim for 800 feet and 350-400 kts on the upwind.", playerData.callsign) - self:_SendMessageToPlayer(hint, 8, playerData) - playerData.score = 0 - playerData.step = 2 -end + local hint = string.format("Entering the pattern, %s! Aim for 800 feet and 350-400 kts in the break entry.", playerData.callsign) + self:_SendMessageToPlayer(hint, 8, playerData) + + -- TODO: Check for correct player heading! + playerData.score = 0 + playerData.step = 2 +end + --- Upwind leg. -- @param #CARRIERTRAINER self -- @param #CARRIERTRAINER.PlayerData playerData Player data table. -function CARRIERTRAINER:_Upwind(playerData) +function CARRIERTRAINER:_Upwind(playerData) -- Get distances between carrier and player unit (parallel and perpendicular to direction of movement of carrier) local diffX, diffZ = self:_GetDistances(playerData.unit) @@ -787,10 +783,10 @@ function CARRIERTRAINER:_Upwind(playerData) -- Check if we are in front of the boat (diffX > 0). if self:_CheckLimits(diffX, diffZ, self.Upwind) then - -- Get + -- Get altutide. local score, hint=self:_AltitudeCheck(playerData, self.Upwind) - self:_SendMessageToPlayer(hint, 8, playerData) + self:_AddToSummary(playerData, hint) -- Next step. @@ -827,8 +823,7 @@ function CARRIERTRAINER:_Break(playerData, part) -- Check altitude. local score, hint=self:_AltitudeCheck(playerData, self.Upwind) - - self:_SendMessageToPlayer(hint, 8, playerData) + -- Add hint to summary. self:_AddToSummary(playerData, hint) if (part == "early") then @@ -839,7 +834,7 @@ function CARRIERTRAINER:_Break(playerData, part) end end ---- Break. +--- Abeam. -- @param #CARRIERTRAINER self -- @param #CARRIERTRAINER.PlayerData playerData Player data table. function CARRIERTRAINER:_Abeam(playerData) @@ -855,17 +850,23 @@ function CARRIERTRAINER:_Abeam(playerData) -- Check nest step threshold. if self:_CheckLimits(diffX, diffZ, self.Abeam) then + + -- Checks: + -- AoA + -- Altitude + -- Distance to carrier. -- Get AoA. local aoa = playerData.unit:GetAoA() - local aoaFeedback = self:_PrintAoAFeedback(aoa, 8.1, playerData) + self:_AoACheck(aoa, self.Abeam, playerData) - local onSpeedScore = self:_GetOnSpeedScore(aoa) - + -- Check Alitude local score, hint=self:_AltitudeCheck(playerData, self.Abeam) + -- Check distance. local dscore, dhint=self:_DistanceCheck(diffZ, playerData, self.Abeam) + --[[ local fullHint = hint .. ", " .. dhint self:_SendMessageToPlayer( fullHint, 8, playerData ) @@ -873,8 +874,10 @@ function CARRIERTRAINER:_Abeam(playerData) self:_IncreaseScore(playerData, score + dscore + onSpeedScore) self:_PrintScore(score + dscore + onSpeedScore, playerData, true) + ]] - self:_AddToSummary(playerData, fullHint .. " (" .. aoaFeedback .. ")") + + --self:_AddToSummary(playerData, fullHint .. " (" .. aoaFeedback .. ")") -- Proceed to next step. playerData.step = 6 @@ -885,31 +888,34 @@ end -- @param #CARRIERTRAINER self -- @param #CARRIERTRAINER.PlayerData playerData Player data table. function CARRIERTRAINER:_CheckForLongDownwind(playerData) - - local playerPosition = playerData.unit:GetVec3() - local carrierPosition = self.carrier:GetVec3() - - local limit = -1500 -- Get distances between carrier and player unit (parallel and perpendicular to direction of movement of carrier) local diffX, diffZ = self:_GetDistances(playerData.unit) + local limit = -1500 + -- Check we are not too far out w.r.t back of the boat. if diffX < limit then local headingPlayer = playerData.unit:GetHeading() local headingCarrier = self.carrier:GetHeading() - - --TODO: Take carrier heading != 0 into account! - - if (headingPlayer > 170) then + + local cx = self.carrier:GetOrientationX() + local px = playerData.unit:GetOrientationX() + local dp = UTILS.VecDot(cx, px) -- dot > 0 means that we are 90 degrees and about to align + + if dp<-0.98 then local hint = "Too long downwind. Turn final earlier next time." - self:_SendMessageToPlayer( hint, 8, playerData ) + self:_SendMessageToPlayer(hint, 8, playerData) + + self:_AddToSummary(playerData, hint) + local score = -40 self:_IncreaseScore(playerData, score) self:_PrintScore(score, playerData, true) - self:_AddToSummary(playerData, hint) + + -- Long downwind done! playerData.longDownwindDone = true end @@ -975,13 +981,10 @@ function CARRIERTRAINER:_Wake(playerData) local score, hint=self:_AltitudeCheck(playerData, self.Wake) local aoa = playerData.unit:GetAoA() + local score, hint=self:_AoACheck(aoa, self.Wake, playerData) - local aoaFeedback = self:_PrintAoAFeedback(aoa, 8.1, playerData) - local onSpeedScore = self:_GetOnSpeedScore(aoa) - - self:_IncreaseScore(playerData, score + onSpeedScore) - self:_PrintScore(score + onSpeedScore, playerData, true) - self:_AddToSummary(playerData, hint .. " (" .. aoaFeedback .. ")") + -- TODO make summay + --self:_AddToSummary(playerData, hint .. " (" .. aoaFeedback .. ")") playerData.step = 8 end @@ -1007,11 +1010,17 @@ function CARRIERTRAINER:_Groove(playerData) --TODO: if (diffX > -500) then --Reached in close before groove + local hint = "You're too far left and never reached the groove." self:_SendMessageToPlayer( hint, 8, playerData ) + + -- zero score self:_PrintScore(0, playerData, true) self:_AddToSummary(playerData, hint) + + -- Next step. playerData.step = 9 + else local limitDeg = 8.0 @@ -1028,16 +1037,13 @@ function CARRIERTRAINER:_Groove(playerData) -- AoA feed back local aoa = playerData.unit:GetAoA() - local aoaFeedback = self:_PrintAoAFeedback(aoa, 8.1, playerData) - local onSpeedScore = self:_GetOnSpeedScore(aoa) - - self:_IncreaseScore(playerData, score + onSpeedScore) - self:_PrintScore(score + onSpeedScore, playerData, true) - - local fullHint = hint .. " (" .. aoaFeedback .. ")" + local score, hint=self:_AoACheck(aoa, self.Groove,playerData) - self:_AddToSummary(playerData, fullHint) + -- TODO + --local fullHint = hint .. " (" .. aoaFeedback .. ")" + --self:_AddToSummary(playerData, fullHint) + -- Next step. playerData.step = 9 end end @@ -1083,6 +1089,7 @@ function CARRIERTRAINER:_Trap(playerData) local wire = 1 local score = -10 + -- Which wire if(diffX < -14) then wire = 1 score = -15 @@ -1115,14 +1122,14 @@ function CARRIERTRAINER:_Trap(playerData) elseif (diffX > 150) then - local wire = 0 - local hint = "" + local wire = 0 + local hint = "" local score = 0 if (playerData.lowestAltitude < 23) then - hint = "You boltered." + hint = "You boltered." else - hint = "You were waved off." - wire = -1 + hint = "You were waved off." + wire = -1 score = -10 end @@ -1267,14 +1274,10 @@ end --- Evaluate player's altitude at checkpoint. -- @param #CARRIERTRAINER self -- @param #CARRIERTRAINER.PlayerData playerData Player data table. --- @param #CARRIERTRAINER.Checkpoint checkpoint Checkpoint. --- @return #number Score. --- @return #string Message text. -function CARRIERTRAINER:_AltitudeCheck(playerData, checkpoint) +-- @return #number Low score. +-- @return #number Bad score. +function CARRIERTRAINER:_GetGoodBadScore(playerData) - -- Player altitude. - local altitude=playerData.unit:GetAltitude() - local lowscore local badscore if playerData.difficulty==CARRIERTRAINER.Difficulty.EASY then @@ -1288,6 +1291,23 @@ function CARRIERTRAINER:_AltitudeCheck(playerData, checkpoint) badscore=5 end + return lowscore, badscore +end + +--- Evaluate player's altitude at checkpoint. +-- @param #CARRIERTRAINER self +-- @param #CARRIERTRAINER.PlayerData playerData Player data table. +-- @param #CARRIERTRAINER.Checkpoint checkpoint Checkpoint. +-- @return #number Score. +-- @return #string Message text. +function CARRIERTRAINER:_AltitudeCheck(playerData, checkpoint) + + -- Player altitude. + local altitude=playerData.unit:GetAltitude() + + -- Get relative score. + local lowscore, badscore = self:_GetGoodBadScore(playerData) + -- Altitude error +-X% local _error=(altitude-checkpoint.Altitude)/checkpoint.Altitude*100 @@ -1295,31 +1315,30 @@ function CARRIERTRAINER:_AltitudeCheck(playerData, checkpoint) local hint local steptext=self:_StepName(playerData.step) if _error>badscore then - score = 5 - hint = string.format("You're high %s.", steptext) + score = -10 + hint = string.format("You're high %s. ", steptext) elseif _error>lowscore then - score = 7 - hint = string.format("You're slightly high %s.", steptext) + score = -5 + hint = string.format("You're slightly high %s. ", steptext) elseif _errorbadscore then - score = 0 - hint = string.format("too far from the boat (%.1f NM)", dnm) + score = -10 + hint = string.format("too far from the boat (%.1f NM)", dnm) elseif _error>lowscore then - score = 5 - hint = string.format("slightly too far from the boat (%.1f NM)", dnm) + score = -5 + hint = string.format("slightly too far from the boat (%.1f NM)", dnm) elseif _errorbadscore then --Slow - score = 0 + score = -10 + hint = "You're slow." elseif _error>lowscore then --Slightly slow - score = 5 + score = -5 + hint = "You're slightly slow." elseif _error 9.5) then - hint = "You're slow." - elseif(AoA > 9) then - hint = "You're slightly slow." - elseif(AoA > 7.25) then - hint = "You're on speed!" - elseif(AoA > 6.7) then - hint = "You're slightly fast." - else - hint = "You're fast." - end - - local roundedAoA = UTILS.Round(AoA, 2) - - self:_SendMessageToPlayer(hint .. " AOA: " .. roundedAoA .. " (Target: " .. idealAoA .. ")", 8, playerData) - - return hint -end - --- Send message to playe client. -- @param #CARRIERTRAINER self -- @param #string message The message to send.