| 1 |
-- ____ _ __ |
| 2 |
-- / __ )____ _____ | | / /___ ___________ |
| 3 |
-- / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/ |
| 4 |
-- / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ ) |
| 5 |
-- /_____/\____/____/ |__/|__/\__,_/_/ /____/ |
| 6 |
-- |
| 7 |
-- A futuristic real-time strategy game. |
| 8 |
-- This file is part of Bos Wars. |
| 9 |
-- |
| 10 |
-- campaigns.lua - The main UI lua script. |
| 11 |
-- |
| 12 |
-- (c) Copyright 2006-2010 by François Beerten |
| 13 |
-- |
| 14 |
-- This program is free software; you can redistribute it and/or modify |
| 15 |
-- it under the terms of the GNU General Public License as published by |
| 16 |
-- the Free Software Foundation; only version 2 of the License. |
| 17 |
-- |
| 18 |
-- This program is distributed in the hope that it will be useful, |
| 19 |
-- but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 |
-- GNU General Public License for more details. |
| 22 |
-- |
| 23 |
-- You should have received a copy of the GNU General Public License |
| 24 |
-- along with this program; if not, write to the Free Software |
| 25 |
-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 26 |
-- 02111-1307, USA. |
| 27 |
-- |
| 28 |
|
| 29 |
|
| 30 |
function RunBriefingMenu(objectivestext, briefingtext, briefingsound, background) |
| 31 |
local menu |
| 32 |
local b |
| 33 |
local channel = nil |
| 34 |
|
| 35 |
if (objectivestext == nil) then |
| 36 |
objectivestext = default_objectives |
| 37 |
end |
| 38 |
SetObjectives(objectivestext) |
| 39 |
|
| 40 |
local objText = "" |
| 41 |
for i,f in ipairs(objectivestext) do |
| 42 |
objText = objText .. f .. "\n" |
| 43 |
end |
| 44 |
|
| 45 |
menu = BosMenu(_("Briefing"), background) |
| 46 |
local text = briefingtext .. |
| 47 |
"\n\n" .. |
| 48 |
_("Objectives:") .. |
| 49 |
" \n" .. |
| 50 |
objText |
| 51 |
local t= MultiLineLabel(text) |
| 52 |
t:setFont(Fonts["large"]) |
| 53 |
t:setAlignment(MultiLineLabel.LEFT) |
| 54 |
t:setVerticalAlignment(MultiLineLabel.CENTER) |
| 55 |
t:setLineWidth(400) |
| 56 |
t:adjustSize() |
| 57 |
t:setHeight(Video.Height * 12 / 20) |
| 58 |
t:setBackgroundColor(dark) |
| 59 |
menu:add(t, Video.Width / 2 - 200, Video.Height / 20 * 3) |
| 60 |
|
| 61 |
menu:addButton(_("~!Start"), Video.Width / 2 - 100, Video.Height - 100, |
| 62 |
function() |
| 63 |
if (channel ~= nil) then StopChannel(channel) end |
| 64 |
menu:stop() |
| 65 |
end) |
| 66 |
menu:addButton(_("Cancel (~<Esc~>)"), Video.Width / 2 - 100, Video.Height - 65, |
| 67 |
function() |
| 68 |
if (channel ~= nil) then StopChannel(channel) end |
| 69 |
menu:stop(1) |
| 70 |
end) |
| 71 |
|
| 72 |
if (briefingsound ~= nil) then |
| 73 |
channel = PlaySoundFile(briefingsound, function() channel = nil end) |
| 74 |
end |
| 75 |
|
| 76 |
return menu:run() |
| 77 |
end |
| 78 |
|
| 79 |
function AddCampaignMessage(when, text) |
| 80 |
AddTrigger( |
| 81 |
function() return (GameCycle() >= when) end, |
| 82 |
function() return AddMessage(text) end |
| 83 |
) |
| 84 |
end |
| 85 |
|
| 86 |
function AddCampaignFinalAssault(when, text) |
| 87 |
AddTrigger( |
| 88 |
function() return (GameCycle() >= when) end, |
| 89 |
function() |
| 90 |
AddMessage(text) |
| 91 |
CreateUnit("unit-vault", 1, {60, 8}) |
| 92 |
CreateUnit("unit-tank", 1, {59, 12}) |
| 93 |
CreateUnit("unit-tank", 1, {61, 12}) |
| 94 |
CreateUnit("unit-tank", 1, {59, 14}) |
| 95 |
CreateUnit("unit-tank", 1, {60, 14}) |
| 96 |
AiForce(9, {"unit-tank", 4, "unit-rtank", 3}) |
| 97 |
AiAttackWithForce(9) |
| 98 |
end |
| 99 |
) |
| 100 |
end |
| 101 |
|
| 102 |
|
| 103 |
function CreateMapStep(map, objectivestext, briefingtext, briefingsound, briefingbackground) |
| 104 |
function RunCampaignMap() |
| 105 |
if (RunBriefingMenu(objectivestext, briefingtext, briefingsound, briefingbackground) ~= 0) then |
| 106 |
GameResult = GameQuitToMenu |
| 107 |
return |
| 108 |
end |
| 109 |
Load(map) -- Needed to force the load of the presentation |
| 110 |
RunMap(map, objectivestext) |
| 111 |
end |
| 112 |
return RunCampaignMap |
| 113 |
end |
| 114 |
|
| 115 |
|
| 116 |
function RunCampaign(campaign) |
| 117 |
Load(campaign) |
| 118 |
currentCampaign = campaign |
| 119 |
if position == nil then |
| 120 |
position = 1 |
| 121 |
end |
| 122 |
while position <= table.getn(campaign_steps) do |
| 123 |
campaign_steps[position]() |
| 124 |
if GameResult == GameVictory then |
| 125 |
position = position + 1 |
| 126 |
elseif GameResult == GameDefeat then |
| 127 |
position = position |
| 128 |
else |
| 129 |
currentCampaign = nil |
| 130 |
return |
| 131 |
end |
| 132 |
end |
| 133 |
currentCampaign = nil |
| 134 |
end |
| 135 |
|
| 136 |
|
| 137 |
function RunCampaignsMenu(s) |
| 138 |
local menu |
| 139 |
local b |
| 140 |
|
| 141 |
menu = BosMenu(_("List of Campaigns")) |
| 142 |
|
| 143 |
ResetMapOptions() |
| 144 |
local lister = CreateFilteringLister("^%a", ListDirsInDirectory) |
| 145 |
local browser = menu:addBrowser("campaigns/", lister, |
| 146 |
Video.Width / 2 - 150, 100, 300, 200) |
| 147 |
function startgamebutton(s) |
| 148 |
DebugPrint("Starting campaign") |
| 149 |
position = nil |
| 150 |
RunCampaign("campaigns/" .. browser:getSelectedItem() .. "/campaign.lua") |
| 151 |
menu:stop() |
| 152 |
end |
| 153 |
menu:addButton(_("Main Menu (~<Esc~>)"), Video.Width / 2 - 250, Video.Height - 100, |
| 154 |
function() menu:stop() end) |
| 155 |
menu:addButton(_("~!Start"), Video.Width / 2 + 50 , Video.Height - 100, |
| 156 |
startgamebutton) |
| 157 |
|
| 158 |
menu:run() |
| 159 |
end |
| 160 |
|