File: campaigns.lua

package info (click to toggle)
boswars 2.8-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 96,652 kB
  • sloc: cpp: 57,250; python: 1,715; sh: 25; makefile: 17
file content (160 lines) | stat: -rw-r--r-- 4,763 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
--     ____                _       __               
--    / __ )____  _____   | |     / /___ ___________
--   / __  / __ \/ ___/   | | /| / / __ `/ ___/ ___/
--  / /_/ / /_/ (__  )    | |/ |/ / /_/ / /  (__  ) 
-- /_____/\____/____/     |__/|__/\__,_/_/  /____/  
--                                              
--       A futuristic real-time strategy game.
--          This file is part of Bos Wars.
--
--      campaigns.lua - The main UI lua script.
--
--      (c) Copyright 2006-2010 by François Beerten
--
--      This program is free software; you can redistribute it and/or modify
--      it under the terms of the GNU General Public License as published by
--      the Free Software Foundation; only version 2 of the License.
--
--      This program is distributed in the hope that it will be useful,
--      but WITHOUT ANY WARRANTY; without even the implied warranty of
--      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--      GNU General Public License for more details.
--
--      You should have received a copy of the GNU General Public License
--      along with this program; if not, write to the Free Software
--      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
--      02111-1307, USA.
--


function RunBriefingMenu(objectivestext, briefingtext, briefingsound, background)
  local menu
  local b
  local channel = nil

  if (objectivestext == nil) then
    objectivestext = default_objectives
  end
  SetObjectives(objectivestext)

  local objText = ""
  for i,f in ipairs(objectivestext) do
    objText = objText .. f .. "\n"
  end

  menu = BosMenu(_("Briefing"), background)
  local text = briefingtext .. 
      "\n\n" ..
      _("Objectives:") ..
      "         \n" ..
      objText
  local t= MultiLineLabel(text)
  t:setFont(Fonts["large"])
  t:setAlignment(MultiLineLabel.LEFT)
  t:setVerticalAlignment(MultiLineLabel.CENTER)
  t:setLineWidth(400)
  t:adjustSize()
  t:setHeight(Video.Height * 12 / 20)
  t:setBackgroundColor(dark)
  menu:add(t, Video.Width / 2 - 200, Video.Height / 20 * 3)

  menu:addButton(_("~!Start"), Video.Width / 2 - 100, Video.Height - 100,
    function()
      if (channel ~= nil) then StopChannel(channel) end
      menu:stop()
    end)
  menu:addButton(_("Cancel (~<Esc~>)"), Video.Width / 2 - 100, Video.Height - 65,
    function()
      if (channel ~= nil) then StopChannel(channel) end
      menu:stop(1)
    end)

  if (briefingsound ~= nil) then
    channel = PlaySoundFile(briefingsound, function() channel = nil end)
  end

  return menu:run()
end

function AddCampaignMessage(when, text)
  AddTrigger(
    function() return (GameCycle() >= when) end,
    function() return AddMessage(text) end
  )
end

function AddCampaignFinalAssault(when, text)
  AddTrigger(
    function() return (GameCycle() >= when) end,
    function() 
      AddMessage(text)
      CreateUnit("unit-vault", 1, {60, 8})
      CreateUnit("unit-tank", 1, {59, 12})
      CreateUnit("unit-tank", 1, {61, 12})
      CreateUnit("unit-tank", 1, {59, 14})
      CreateUnit("unit-tank", 1, {60, 14})
      AiForce(9, {"unit-tank", 4, "unit-rtank", 3})
      AiAttackWithForce(9)
    end
  )
end


function CreateMapStep(map, objectivestext, briefingtext, briefingsound, briefingbackground)
  function RunCampaignMap()
    if (RunBriefingMenu(objectivestext, briefingtext, briefingsound, briefingbackground) ~= 0) then
      GameResult = GameQuitToMenu
      return
    end
    Load(map) -- Needed to force the load of the presentation
    RunMap(map, objectivestext) 
  end
  return RunCampaignMap
end


function RunCampaign(campaign)
  Load(campaign)
  currentCampaign = campaign
  if position == nil then
    position = 1
  end
  while position <= table.getn(campaign_steps) do
    campaign_steps[position]()
    if GameResult == GameVictory then
       position = position + 1
    elseif GameResult == GameDefeat then
       position = position
    else
      currentCampaign = nil
      return
    end
  end
  currentCampaign = nil
end


function RunCampaignsMenu(s)
  local menu
  local b

  menu = BosMenu(_("List of Campaigns"))

  ResetMapOptions()
  local lister = CreateFilteringLister("^%a",  ListDirsInDirectory)
  local browser = menu:addBrowser("campaigns/", lister,
                                 Video.Width / 2 - 150, 100, 300, 200)
  function startgamebutton(s)
    DebugPrint("Starting campaign")
    position = nil
    RunCampaign("campaigns/" .. browser:getSelectedItem() .. "/campaign.lua")
    menu:stop()
  end
  menu:addButton(_("Main Menu (~<Esc~>)"), Video.Width / 2 - 250, Video.Height - 100,
                 function() menu:stop() end)
  menu:addButton(_("~!Start"), Video.Width / 2 + 50 ,  Video.Height - 100,
                 startgamebutton)

  menu:run()
end