--
-- when we die
--

function node_heaven_ctor (self, DeathType)

   self.name = "Heaven"
   self.death_type = DeathType
end

node_heaven = class (node, node_heaven_ctor)

function node_heaven:action (Action)

   local T = ""

   if (not Action) then

      local KM = math.floor (cur_play.distance_m / 1000)
      local Special = cur_play.special
      local Deaths = cur_play.deaths
      local Money = cur_play.money
      local Passed = cur_play.passed

      local Bonus = 0
      function AddScore (Why, Points)

         T = T .. Why .. " (+" .. tostring (Points) .. ")//"
         Bonus = Bonus + Points
      end

      local FinalT

      if (4 == self.death_type) then

         T = "Congratulations.//"

         FinalT = "Your pilgrimidge was completed.//"

         AddScore ("Your lost spirit has found it's way to the star-mother", 2500)

      elseif (3 == self.death_type) then

         T = "Game Over.//"
            .. "Your heart turned to stone, because that is what you wanted."

         FinalT = "This is what it comes to, then. Blood and live; your holy piligrimidge, ended at last. And so, so close to home.//"

         AddScore ("Your heart found it's rest, but you denied it", 2000)

      else

         local DeathDescs = {

            "You died in a car crash. ",
            "You ran out of gasoline, and starved to death beside the highway. ",
         }

         T =  "Game Over.//"
            .. DeathDescs[self.death_type]
            .. "You travelled " .. tostring (KM) .. " KM.//"
            .. "You passed " .. tostring (Passed) .. " cars.//"
            .. "Your mood when you died was " .. cur_play.last_mood .. ". "
            .. "Driving helped to take the edge off things, not that it matters now.//"

         FinalT = "This is what it comes to, then. Gasoline and death; your illicit journey, ended in the womb. And so, so far from home.//"

         if (Money > 0) then

            AddScore ("Highway patrol found $" .. tostring (Money) .. " in your wallet, but no ID.", Money)
         end

         if (Deaths > 0) then

            AddScore ("You more or less held it together, even after seeing " .. tostring (Deaths) .. " highway fatalities", Deaths * 50)
         end
      end

      if (Special > 0) then

         AddScore ("You collected " .. tostring (Special) .. " ?'s", Special * Special * 5)
      end

      if (KM >= 1000) then

         AddScore ("You forgot about her", 2500)

      elseif (KM > 100) then

         AddScore ("For a moment, you almost forgot about her", 500)

      end

      T = T .. "**//"

      T = T .. FinalT
         .. "Base: " .. cur_play.score .. "pts//"
         .. "Bonuses: " .. Bonus .. "pts//"
         .. "Final: " .. cur_play.score + Bonus .. "pts//"
         .. "Urrp! Thanks for playing!"

   elseif ("quit" == Action) then

      game_quit ()
      return "Thank you for playing."

   elseif ("restart" == Action) then

      new_game ()
      return "Restarting."
   end

   return T
end

function node_heaven:menu ()

   M = {

      { "restart", "Play Again" },
      { "quit", "Quit" }
   }

   return "Do you want to play again?", M
end
