share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/global_functions.lua
author Wuzzy <Wuzzy2@mail.ru>
Fri, 21 Dec 2018 23:17:10 +0100
changeset 14522 4e7fbbdca061
parent 12537 66566cfe0a7e
permissions -rw-r--r--
ASA cosmos: Remove unneccary message when hero dies after moon was reached
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11965
72be38f6d0c0 Complete space campaign's spacetrip mission if all main+side missions are completed
Wuzzy <almikes@aol.com>
parents: 11964
diff changeset
     1
local missionsNum = 14
72be38f6d0c0 Complete space campaign's spacetrip mission if all main+side missions are completed
Wuzzy <almikes@aol.com>
parents: 11964
diff changeset
     2
9578
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
     3
function saveCompletedStatus(planetNum)
9636
e1921235fc78 cosmos, after death01 dialogs
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9630
diff changeset
     4
	--        1       2        3        4      5         6        7
e1921235fc78 cosmos, after death01 dialogs
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9630
diff changeset
     5
	-- order: moon01, fruit01, fruit02, ice01, desert01, death01, final
e1921235fc78 cosmos, after death01 dialogs
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9630
diff changeset
     6
	local status = "0000000"
9578
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
     7
	if tonumber(GetCampaignVar("MainMissionsStatus")) then
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
     8
		status = GetCampaignVar("MainMissionsStatus")
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
     9
	end
9718
563a34cd8398 unbreak various parts of campaign variable loading/saving
sheepluva
parents: 9636
diff changeset
    10
11952
63988f36debf Save mission success for A Space Adventure missions
Wuzzy <almikes@aol.com>
parents: 9810
diff changeset
    11
	local planetToLevelMapping = {
63988f36debf Save mission success for A Space Adventure missions
Wuzzy <almikes@aol.com>
parents: 9810
diff changeset
    12
		[1] = 2,
63988f36debf Save mission success for A Space Adventure missions
Wuzzy <almikes@aol.com>
parents: 9810
diff changeset
    13
		[2] = 3,
63988f36debf Save mission success for A Space Adventure missions
Wuzzy <almikes@aol.com>
parents: 9810
diff changeset
    14
		[3] = 8,
63988f36debf Save mission success for A Space Adventure missions
Wuzzy <almikes@aol.com>
parents: 9810
diff changeset
    15
		[4] = 5,
63988f36debf Save mission success for A Space Adventure missions
Wuzzy <almikes@aol.com>
parents: 9810
diff changeset
    16
		[5] = 4,
63988f36debf Save mission success for A Space Adventure missions
Wuzzy <almikes@aol.com>
parents: 9810
diff changeset
    17
		[6] = 9,
63988f36debf Save mission success for A Space Adventure missions
Wuzzy <almikes@aol.com>
parents: 9810
diff changeset
    18
		[7] = 14
63988f36debf Save mission success for A Space Adventure missions
Wuzzy <almikes@aol.com>
parents: 9810
diff changeset
    19
	}
63988f36debf Save mission success for A Space Adventure missions
Wuzzy <almikes@aol.com>
parents: 9810
diff changeset
    20
63988f36debf Save mission success for A Space Adventure missions
Wuzzy <almikes@aol.com>
parents: 9810
diff changeset
    21
	local level = planetToLevelMapping[planetNum]
63988f36debf Save mission success for A Space Adventure missions
Wuzzy <almikes@aol.com>
parents: 9810
diff changeset
    22
	if level ~= nil then
63988f36debf Save mission success for A Space Adventure missions
Wuzzy <almikes@aol.com>
parents: 9810
diff changeset
    23
		SaveCampaignVar("Mission"..level.."Won", "true")
63988f36debf Save mission success for A Space Adventure missions
Wuzzy <almikes@aol.com>
parents: 9810
diff changeset
    24
	end
63988f36debf Save mission success for A Space Adventure missions
Wuzzy <almikes@aol.com>
parents: 9810
diff changeset
    25
9718
563a34cd8398 unbreak various parts of campaign variable loading/saving
sheepluva
parents: 9636
diff changeset
    26
	if planetNum == 1 then
563a34cd8398 unbreak various parts of campaign variable loading/saving
sheepluva
parents: 9636
diff changeset
    27
		status = "1"..status:sub(2)
563a34cd8398 unbreak various parts of campaign variable loading/saving
sheepluva
parents: 9636
diff changeset
    28
	elseif planetNum == status:len() then
9578
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    29
		status = status:sub(1,planetNum-1).."1"
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    30
	else
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    31
		status = status:sub(1,planetNum-1).."1"..status:sub(planetNum+1)
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    32
	end
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    33
	SaveCampaignVar("MainMissionsStatus",status)
11965
72be38f6d0c0 Complete space campaign's spacetrip mission if all main+side missions are completed
Wuzzy <almikes@aol.com>
parents: 11964
diff changeset
    34
72be38f6d0c0 Complete space campaign's spacetrip mission if all main+side missions are completed
Wuzzy <almikes@aol.com>
parents: 11964
diff changeset
    35
	checkAllMissionsCompleted()
72be38f6d0c0 Complete space campaign's spacetrip mission if all main+side missions are completed
Wuzzy <almikes@aol.com>
parents: 11964
diff changeset
    36
end
72be38f6d0c0 Complete space campaign's spacetrip mission if all main+side missions are completed
Wuzzy <almikes@aol.com>
parents: 11964
diff changeset
    37
72be38f6d0c0 Complete space campaign's spacetrip mission if all main+side missions are completed
Wuzzy <almikes@aol.com>
parents: 11964
diff changeset
    38
function checkAllMissionsCompleted()
72be38f6d0c0 Complete space campaign's spacetrip mission if all main+side missions are completed
Wuzzy <almikes@aol.com>
parents: 11964
diff changeset
    39
	local allMissions = true
72be38f6d0c0 Complete space campaign's spacetrip mission if all main+side missions are completed
Wuzzy <almikes@aol.com>
parents: 11964
diff changeset
    40
	for i=2, missionsNum do
72be38f6d0c0 Complete space campaign's spacetrip mission if all main+side missions are completed
Wuzzy <almikes@aol.com>
parents: 11964
diff changeset
    41
		if GetCampaignVar("Mission"..i.."Won") ~= "true" then
72be38f6d0c0 Complete space campaign's spacetrip mission if all main+side missions are completed
Wuzzy <almikes@aol.com>
parents: 11964
diff changeset
    42
			allMissions = false
72be38f6d0c0 Complete space campaign's spacetrip mission if all main+side missions are completed
Wuzzy <almikes@aol.com>
parents: 11964
diff changeset
    43
			break
72be38f6d0c0 Complete space campaign's spacetrip mission if all main+side missions are completed
Wuzzy <almikes@aol.com>
parents: 11964
diff changeset
    44
		end
72be38f6d0c0 Complete space campaign's spacetrip mission if all main+side missions are completed
Wuzzy <almikes@aol.com>
parents: 11964
diff changeset
    45
	end
72be38f6d0c0 Complete space campaign's spacetrip mission if all main+side missions are completed
Wuzzy <almikes@aol.com>
parents: 11964
diff changeset
    46
	if allMissions then
72be38f6d0c0 Complete space campaign's spacetrip mission if all main+side missions are completed
Wuzzy <almikes@aol.com>
parents: 11964
diff changeset
    47
		SaveCampaignVar("Mission1Won", "true")
72be38f6d0c0 Complete space campaign's spacetrip mission if all main+side missions are completed
Wuzzy <almikes@aol.com>
parents: 11964
diff changeset
    48
	end
9578
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    49
end
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    50
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    51
function getCompletedStatus()
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    52
	local allStatus = ""
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    53
	if tonumber(GetCampaignVar("MainMissionsStatus")) then
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    54
		allStatus = GetCampaignVar("MainMissionsStatus")
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    55
	end
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    56
	local status = {
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    57
		moon01 = false,
11964
f3c1679694d3 Draw 2 flowers for fully completed (w/ side missions) planets in space campaign
Wuzzy <almikes@aol.com>
parents: 11952
diff changeset
    58
		moon02 = false,
9578
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    59
		fruit01 = false,
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    60
		fruit02 = false,
11964
f3c1679694d3 Draw 2 flowers for fully completed (w/ side missions) planets in space campaign
Wuzzy <almikes@aol.com>
parents: 11952
diff changeset
    61
		fruit03 = false,
9578
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    62
		ice01 = false,
11964
f3c1679694d3 Draw 2 flowers for fully completed (w/ side missions) planets in space campaign
Wuzzy <almikes@aol.com>
parents: 11952
diff changeset
    63
		ice02 = false,
9578
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    64
		desert01 = false,
11964
f3c1679694d3 Draw 2 flowers for fully completed (w/ side missions) planets in space campaign
Wuzzy <almikes@aol.com>
parents: 11952
diff changeset
    65
		desert02 = false,
f3c1679694d3 Draw 2 flowers for fully completed (w/ side missions) planets in space campaign
Wuzzy <almikes@aol.com>
parents: 11952
diff changeset
    66
		desert03 = false,
9636
e1921235fc78 cosmos, after death01 dialogs
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9630
diff changeset
    67
		death01 = false,
11964
f3c1679694d3 Draw 2 flowers for fully completed (w/ side missions) planets in space campaign
Wuzzy <almikes@aol.com>
parents: 11952
diff changeset
    68
		death02 = false,
9636
e1921235fc78 cosmos, after death01 dialogs
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9630
diff changeset
    69
		final = false
9578
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    70
	}
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    71
	if allStatus ~= "" then
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    72
		if allStatus:sub(1,1) == "1" then
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    73
			status.moon01 = true
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    74
		end
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    75
		if allStatus:sub(2,2) == "1" then
9802
00216d609140 desert01 fixed destructible terrain marks and cosmos marks for completed main missions
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9783
diff changeset
    76
			status.fruit01 = true
9578
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    77
		end
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    78
		if allStatus:sub(3,3) == "1" then
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    79
			status.fruit02 = true
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    80
		end
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    81
		if allStatus:sub(4,4) == "1" then
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    82
			status.ice01 = true
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    83
		end
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    84
		if allStatus:sub(5,5) == "1" then
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    85
			status.desert01 = true
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    86
		end
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    87
		if allStatus:sub(6,6) == "1" then
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    88
			status.death01 = true
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    89
		end
9636
e1921235fc78 cosmos, after death01 dialogs
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9630
diff changeset
    90
		if allStatus:sub(7,7) == "1" then
e1921235fc78 cosmos, after death01 dialogs
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9630
diff changeset
    91
			status.final = true
e1921235fc78 cosmos, after death01 dialogs
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9630
diff changeset
    92
		end
9578
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    93
	end
11964
f3c1679694d3 Draw 2 flowers for fully completed (w/ side missions) planets in space campaign
Wuzzy <almikes@aol.com>
parents: 11952
diff changeset
    94
	-- Bonus missions
f3c1679694d3 Draw 2 flowers for fully completed (w/ side missions) planets in space campaign
Wuzzy <almikes@aol.com>
parents: 11952
diff changeset
    95
	if GetCampaignVar("Mission13Won") == "true" then
f3c1679694d3 Draw 2 flowers for fully completed (w/ side missions) planets in space campaign
Wuzzy <almikes@aol.com>
parents: 11952
diff changeset
    96
		status.moon02 = true
f3c1679694d3 Draw 2 flowers for fully completed (w/ side missions) planets in space campaign
Wuzzy <almikes@aol.com>
parents: 11952
diff changeset
    97
	end
f3c1679694d3 Draw 2 flowers for fully completed (w/ side missions) planets in space campaign
Wuzzy <almikes@aol.com>
parents: 11952
diff changeset
    98
	if GetCampaignVar("Mission6Won") == "true" then
f3c1679694d3 Draw 2 flowers for fully completed (w/ side missions) planets in space campaign
Wuzzy <almikes@aol.com>
parents: 11952
diff changeset
    99
		status.ice02 = true
f3c1679694d3 Draw 2 flowers for fully completed (w/ side missions) planets in space campaign
Wuzzy <almikes@aol.com>
parents: 11952
diff changeset
   100
	end
f3c1679694d3 Draw 2 flowers for fully completed (w/ side missions) planets in space campaign
Wuzzy <almikes@aol.com>
parents: 11952
diff changeset
   101
	if GetCampaignVar("Mission7Won") == "true" then
f3c1679694d3 Draw 2 flowers for fully completed (w/ side missions) planets in space campaign
Wuzzy <almikes@aol.com>
parents: 11952
diff changeset
   102
		status.desert02 = true
f3c1679694d3 Draw 2 flowers for fully completed (w/ side missions) planets in space campaign
Wuzzy <almikes@aol.com>
parents: 11952
diff changeset
   103
	end
f3c1679694d3 Draw 2 flowers for fully completed (w/ side missions) planets in space campaign
Wuzzy <almikes@aol.com>
parents: 11952
diff changeset
   104
	if GetCampaignVar("Mission10Won") == "true" then
f3c1679694d3 Draw 2 flowers for fully completed (w/ side missions) planets in space campaign
Wuzzy <almikes@aol.com>
parents: 11952
diff changeset
   105
		status.fruit03 = true
f3c1679694d3 Draw 2 flowers for fully completed (w/ side missions) planets in space campaign
Wuzzy <almikes@aol.com>
parents: 11952
diff changeset
   106
	end
f3c1679694d3 Draw 2 flowers for fully completed (w/ side missions) planets in space campaign
Wuzzy <almikes@aol.com>
parents: 11952
diff changeset
   107
	if GetCampaignVar("Mission11Won") == "true" then
f3c1679694d3 Draw 2 flowers for fully completed (w/ side missions) planets in space campaign
Wuzzy <almikes@aol.com>
parents: 11952
diff changeset
   108
		status.death02 = true
f3c1679694d3 Draw 2 flowers for fully completed (w/ side missions) planets in space campaign
Wuzzy <almikes@aol.com>
parents: 11952
diff changeset
   109
	end
f3c1679694d3 Draw 2 flowers for fully completed (w/ side missions) planets in space campaign
Wuzzy <almikes@aol.com>
parents: 11952
diff changeset
   110
	if GetCampaignVar("Mission12Won") == "true" then
f3c1679694d3 Draw 2 flowers for fully completed (w/ side missions) planets in space campaign
Wuzzy <almikes@aol.com>
parents: 11952
diff changeset
   111
		status.desert03 = true
f3c1679694d3 Draw 2 flowers for fully completed (w/ side missions) planets in space campaign
Wuzzy <almikes@aol.com>
parents: 11952
diff changeset
   112
	end
9578
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
   113
	return status
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
   114
end
9582
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
   115
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
   116
function initCheckpoint(mission)
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
   117
	local checkPoint = 1
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
   118
	if GetCampaignVar("CurrentMission") ~= mission then
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
   119
		SaveCampaignVar("CurrentMission", mission)
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
   120
		SaveCampaignVar("CurrentMissionCheckpoint", 1)
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
   121
	else
12523
f2a19a6056be ASA: Reset mission checkpoints when going to Spacetrip
Wuzzy <almikes@aol.com>
parents: 11965
diff changeset
   122
		checkPoint = tonumber(GetCampaignVar("CurrentMissionCheckpoint"))
9582
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
   123
	end
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
   124
	return checkPoint
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
   125
end
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
   126
12524
a5ddc6b4abbd ASA: Inform the player about a checkpoint reset
Wuzzy <almikes@aol.com>
parents: 12523
diff changeset
   127
-- Reset mission checkpoint to 1
a5ddc6b4abbd ASA: Inform the player about a checkpoint reset
Wuzzy <almikes@aol.com>
parents: 12523
diff changeset
   128
-- Returns true if the player reached a checkpoint before, false otherwise.
12523
f2a19a6056be ASA: Reset mission checkpoints when going to Spacetrip
Wuzzy <almikes@aol.com>
parents: 11965
diff changeset
   129
function resetCheckpoint(mission)
12524
a5ddc6b4abbd ASA: Inform the player about a checkpoint reset
Wuzzy <almikes@aol.com>
parents: 12523
diff changeset
   130
	local cp = tonumber(GetCampaignVar("CurrentMissionCheckpoint"))
12523
f2a19a6056be ASA: Reset mission checkpoints when going to Spacetrip
Wuzzy <almikes@aol.com>
parents: 11965
diff changeset
   131
	SaveCampaignVar("CurrentMissionCheckpoint", 1)
12524
a5ddc6b4abbd ASA: Inform the player about a checkpoint reset
Wuzzy <almikes@aol.com>
parents: 12523
diff changeset
   132
a5ddc6b4abbd ASA: Inform the player about a checkpoint reset
Wuzzy <almikes@aol.com>
parents: 12523
diff changeset
   133
	return (type(cp) == "number" and cp > 1)
12523
f2a19a6056be ASA: Reset mission checkpoints when going to Spacetrip
Wuzzy <almikes@aol.com>
parents: 11965
diff changeset
   134
end
f2a19a6056be ASA: Reset mission checkpoints when going to Spacetrip
Wuzzy <almikes@aol.com>
parents: 11965
diff changeset
   135
9582
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
   136
function saveCheckpoint(cp)
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
   137
	SaveCampaignVar("CurrentMissionCheckpoint", cp)
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
   138
end
9630
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   139
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   140
-- saves what bonuses are available
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   141
-- times is how many times the bonus will be available, this will be mission specific
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   142
function saveBonus(index, times)
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   143
	--        1         2        3
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   144
	-- order: desert03, fruit03, death02
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   145
	local bonus = "000"
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   146
	if tonumber(GetCampaignVar("SideMissionsBonuses")) then
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   147
		bonus = GetCampaignVar("SideMissionsBonuses")
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   148
	end
9718
563a34cd8398 unbreak various parts of campaign variable loading/saving
sheepluva
parents: 9636
diff changeset
   149
	if index == 1 then
563a34cd8398 unbreak various parts of campaign variable loading/saving
sheepluva
parents: 9636
diff changeset
   150
		bonus = times..bonus:sub(2)
563a34cd8398 unbreak various parts of campaign variable loading/saving
sheepluva
parents: 9636
diff changeset
   151
	elseif index == bonus:len() then
9630
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   152
		bonus = bonus:sub(1,index-1)..times
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   153
	else
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   154
		bonus = bonus:sub(1,index-1)..times..bonus:sub(index+1)
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   155
	end
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   156
	SaveCampaignVar("SideMissionsBonuses",bonus)
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   157
end
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   158
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   159
function getBonus(index)
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   160
	local bonus = 0
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   161
	if tonumber(GetCampaignVar("SideMissionsBonuses")) then
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   162
		bonusString = GetCampaignVar("SideMissionsBonuses")
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   163
		bonus = bonusString:sub(index,index)
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   164
	end
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   165
	return bonus
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   166
end
9782
6c3cad32d4f4 fixed getting device crates with rc plane,end game when device crates destroyed,save/load hero position for checkpoint 5 in desert01
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9718
diff changeset
   167
6c3cad32d4f4 fixed getting device crates with rc plane,end game when device crates destroyed,save/load hero position for checkpoint 5 in desert01
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9718
diff changeset
   168
-- splits number by delimiter
6c3cad32d4f4 fixed getting device crates with rc plane,end game when device crates destroyed,save/load hero position for checkpoint 5 in desert01
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9718
diff changeset
   169
function split(s, delimiter)
6c3cad32d4f4 fixed getting device crates with rc plane,end game when device crates destroyed,save/load hero position for checkpoint 5 in desert01
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9718
diff changeset
   170
	local res = {}
6c3cad32d4f4 fixed getting device crates with rc plane,end game when device crates destroyed,save/load hero position for checkpoint 5 in desert01
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9718
diff changeset
   171
	local first = ""
6c3cad32d4f4 fixed getting device crates with rc plane,end game when device crates destroyed,save/load hero position for checkpoint 5 in desert01
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9718
diff changeset
   172
	for i=1,s:len() do
6c3cad32d4f4 fixed getting device crates with rc plane,end game when device crates destroyed,save/load hero position for checkpoint 5 in desert01
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9718
diff changeset
   173
		if s:sub(1,1) == delimiter then
6c3cad32d4f4 fixed getting device crates with rc plane,end game when device crates destroyed,save/load hero position for checkpoint 5 in desert01
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9718
diff changeset
   174
			table.insert(res, tonumber(first))
6c3cad32d4f4 fixed getting device crates with rc plane,end game when device crates destroyed,save/load hero position for checkpoint 5 in desert01
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9718
diff changeset
   175
			first = ""
6c3cad32d4f4 fixed getting device crates with rc plane,end game when device crates destroyed,save/load hero position for checkpoint 5 in desert01
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9718
diff changeset
   176
		else
6c3cad32d4f4 fixed getting device crates with rc plane,end game when device crates destroyed,save/load hero position for checkpoint 5 in desert01
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9718
diff changeset
   177
			first = first..s:sub(1,1)
6c3cad32d4f4 fixed getting device crates with rc plane,end game when device crates destroyed,save/load hero position for checkpoint 5 in desert01
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9718
diff changeset
   178
		end
6c3cad32d4f4 fixed getting device crates with rc plane,end game when device crates destroyed,save/load hero position for checkpoint 5 in desert01
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9718
diff changeset
   179
		s = s:sub(2)
6c3cad32d4f4 fixed getting device crates with rc plane,end game when device crates destroyed,save/load hero position for checkpoint 5 in desert01
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9718
diff changeset
   180
	end
6c3cad32d4f4 fixed getting device crates with rc plane,end game when device crates destroyed,save/load hero position for checkpoint 5 in desert01
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9718
diff changeset
   181
	if first:len() > 0 then
6c3cad32d4f4 fixed getting device crates with rc plane,end game when device crates destroyed,save/load hero position for checkpoint 5 in desert01
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9718
diff changeset
   182
		table.insert(res, tonumber(first))
6c3cad32d4f4 fixed getting device crates with rc plane,end game when device crates destroyed,save/load hero position for checkpoint 5 in desert01
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9718
diff changeset
   183
	end
6c3cad32d4f4 fixed getting device crates with rc plane,end game when device crates destroyed,save/load hero position for checkpoint 5 in desert01
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9718
diff changeset
   184
	return res
6c3cad32d4f4 fixed getting device crates with rc plane,end game when device crates destroyed,save/load hero position for checkpoint 5 in desert01
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9718
diff changeset
   185
end
12537
66566cfe0a7e ASA, The first stop: Fix team ranking and kills in stats screen (bug 147)
Wuzzy <almikes@aol.com>
parents: 12524
diff changeset
   186
66566cfe0a7e ASA, The first stop: Fix team ranking and kills in stats screen (bug 147)
Wuzzy <almikes@aol.com>
parents: 12524
diff changeset
   187
-- Send team ranking stats. Teams is a list of teams in the desired order.
66566cfe0a7e ASA, The first stop: Fix team ranking and kills in stats screen (bug 147)
Wuzzy <almikes@aol.com>
parents: 12524
diff changeset
   188
-- The default kills counter is used.
66566cfe0a7e ASA, The first stop: Fix team ranking and kills in stats screen (bug 147)
Wuzzy <almikes@aol.com>
parents: 12524
diff changeset
   189
function sendSimpleTeamRankings(teams)
66566cfe0a7e ASA, The first stop: Fix team ranking and kills in stats screen (bug 147)
Wuzzy <almikes@aol.com>
parents: 12524
diff changeset
   190
	for t=1, #teams do
66566cfe0a7e ASA, The first stop: Fix team ranking and kills in stats screen (bug 147)
Wuzzy <almikes@aol.com>
parents: 12524
diff changeset
   191
		local teamname = teams[t]
66566cfe0a7e ASA, The first stop: Fix team ranking and kills in stats screen (bug 147)
Wuzzy <almikes@aol.com>
parents: 12524
diff changeset
   192
		SendStat(siPlayerKills, GetTeamStats(teamname).Kills, teamname)
66566cfe0a7e ASA, The first stop: Fix team ranking and kills in stats screen (bug 147)
Wuzzy <almikes@aol.com>
parents: 12524
diff changeset
   193
	end
66566cfe0a7e ASA, The first stop: Fix team ranking and kills in stats screen (bug 147)
Wuzzy <almikes@aol.com>
parents: 12524
diff changeset
   194
end