share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/global_functions.lua
author Wuzzy <almikes@aol.com>
Wed, 04 May 2016 05:23:58 +0200
changeset 11956 221b38978401
parent 11952 63988f36debf
child 11964 f3c1679694d3
permissions -rw-r--r--
Seperate campaign victories from campaign mission victories
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9578
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
     1
function saveCompletedStatus(planetNum)
9636
e1921235fc78 cosmos, after death01 dialogs
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9630
diff changeset
     2
	--        1       2        3        4      5         6        7
e1921235fc78 cosmos, after death01 dialogs
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9630
diff changeset
     3
	-- order: moon01, fruit01, fruit02, ice01, desert01, death01, final
e1921235fc78 cosmos, after death01 dialogs
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9630
diff changeset
     4
	local status = "0000000"
9578
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
     5
	if tonumber(GetCampaignVar("MainMissionsStatus")) then
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
     6
		status = GetCampaignVar("MainMissionsStatus")
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
     7
	end
9718
563a34cd8398 unbreak various parts of campaign variable loading/saving
sheepluva
parents: 9636
diff changeset
     8
11952
63988f36debf Save mission success for A Space Adventure missions
Wuzzy <almikes@aol.com>
parents: 9810
diff changeset
     9
	local planetToLevelMapping = {
63988f36debf Save mission success for A Space Adventure missions
Wuzzy <almikes@aol.com>
parents: 9810
diff changeset
    10
		[1] = 2,
63988f36debf Save mission success for A Space Adventure missions
Wuzzy <almikes@aol.com>
parents: 9810
diff changeset
    11
		[2] = 3,
63988f36debf Save mission success for A Space Adventure missions
Wuzzy <almikes@aol.com>
parents: 9810
diff changeset
    12
		[3] = 8,
63988f36debf Save mission success for A Space Adventure missions
Wuzzy <almikes@aol.com>
parents: 9810
diff changeset
    13
		[4] = 5,
63988f36debf Save mission success for A Space Adventure missions
Wuzzy <almikes@aol.com>
parents: 9810
diff changeset
    14
		[5] = 4,
63988f36debf Save mission success for A Space Adventure missions
Wuzzy <almikes@aol.com>
parents: 9810
diff changeset
    15
		[6] = 9,
63988f36debf Save mission success for A Space Adventure missions
Wuzzy <almikes@aol.com>
parents: 9810
diff changeset
    16
		[7] = 14
63988f36debf Save mission success for A Space Adventure missions
Wuzzy <almikes@aol.com>
parents: 9810
diff changeset
    17
	}
63988f36debf Save mission success for A Space Adventure missions
Wuzzy <almikes@aol.com>
parents: 9810
diff changeset
    18
63988f36debf Save mission success for A Space Adventure missions
Wuzzy <almikes@aol.com>
parents: 9810
diff changeset
    19
	local level = planetToLevelMapping[planetNum]
63988f36debf Save mission success for A Space Adventure missions
Wuzzy <almikes@aol.com>
parents: 9810
diff changeset
    20
	if level ~= nil then
63988f36debf Save mission success for A Space Adventure missions
Wuzzy <almikes@aol.com>
parents: 9810
diff changeset
    21
		SaveCampaignVar("Mission"..level.."Won", "true")
63988f36debf Save mission success for A Space Adventure missions
Wuzzy <almikes@aol.com>
parents: 9810
diff changeset
    22
	end
63988f36debf Save mission success for A Space Adventure missions
Wuzzy <almikes@aol.com>
parents: 9810
diff changeset
    23
9718
563a34cd8398 unbreak various parts of campaign variable loading/saving
sheepluva
parents: 9636
diff changeset
    24
	if planetNum == 1 then
563a34cd8398 unbreak various parts of campaign variable loading/saving
sheepluva
parents: 9636
diff changeset
    25
		status = "1"..status:sub(2)
563a34cd8398 unbreak various parts of campaign variable loading/saving
sheepluva
parents: 9636
diff changeset
    26
	elseif planetNum == status:len() then
9578
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    27
		status = status:sub(1,planetNum-1).."1"
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    28
	else
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    29
		status = status:sub(1,planetNum-1).."1"..status:sub(planetNum+1)
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    30
	end
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    31
	SaveCampaignVar("MainMissionsStatus",status)
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
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    34
function getCompletedStatus()
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    35
	local allStatus = ""
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    36
	if tonumber(GetCampaignVar("MainMissionsStatus")) then
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    37
		allStatus = GetCampaignVar("MainMissionsStatus")
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    38
	end
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    39
	local status = {
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    40
		moon01 = false,
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    41
		fruit01 = false,
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    42
		fruit02 = false,
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    43
		ice01 = false,
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    44
		desert01 = false,
9636
e1921235fc78 cosmos, after death01 dialogs
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9630
diff changeset
    45
		death01 = false,
e1921235fc78 cosmos, after death01 dialogs
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9630
diff changeset
    46
		final = false
9578
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    47
	}
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    48
	if allStatus ~= "" then
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    49
		if allStatus:sub(1,1) == "1" then
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    50
			status.moon01 = true
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    51
		end
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    52
		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
    53
			status.fruit01 = true
9578
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    54
		end
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    55
		if allStatus:sub(3,3) == "1" then
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    56
			status.fruit02 = true
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    57
		end
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    58
		if allStatus:sub(4,4) == "1" then
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    59
			status.ice01 = true
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    60
		end
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    61
		if allStatus:sub(5,5) == "1" then
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    62
			status.desert01 = true
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    63
		end
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    64
		if allStatus:sub(6,6) == "1" then
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    65
			status.death01 = true
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    66
		end
9636
e1921235fc78 cosmos, after death01 dialogs
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9630
diff changeset
    67
		if allStatus:sub(7,7) == "1" then
e1921235fc78 cosmos, after death01 dialogs
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9630
diff changeset
    68
			status.final = true
e1921235fc78 cosmos, after death01 dialogs
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9630
diff changeset
    69
		end
9578
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    70
	end
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    71
	return status
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    72
end
9582
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
    73
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
    74
function initCheckpoint(mission)
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
    75
	local checkPoint = 1
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
    76
	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
    77
		SaveCampaignVar("CurrentMission", mission)
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
    78
		SaveCampaignVar("CurrentMissionCheckpoint", 1)
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
    79
		SaveCampaignVar("HogsPosition", "")
9582
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
    80
	else
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
    81
		checkPoint = tonumber(GetCampaignVar("currentMissionCheckpoint"))
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
    82
	end
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
    83
	return checkPoint
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
    84
end
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
    85
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
    86
function saveCheckpoint(cp)
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
    87
	SaveCampaignVar("CurrentMissionCheckpoint", cp)
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
    88
end
9630
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    89
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    90
-- saves what bonuses are available
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    91
-- 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
    92
function saveBonus(index, times)
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    93
	--        1         2        3
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    94
	-- order: desert03, fruit03, death02
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    95
	local bonus = "000"
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    96
	if tonumber(GetCampaignVar("SideMissionsBonuses")) then
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    97
		bonus = GetCampaignVar("SideMissionsBonuses")
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    98
	end
9718
563a34cd8398 unbreak various parts of campaign variable loading/saving
sheepluva
parents: 9636
diff changeset
    99
	if index == 1 then
563a34cd8398 unbreak various parts of campaign variable loading/saving
sheepluva
parents: 9636
diff changeset
   100
		bonus = times..bonus:sub(2)
563a34cd8398 unbreak various parts of campaign variable loading/saving
sheepluva
parents: 9636
diff changeset
   101
	elseif index == bonus:len() then
9630
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   102
		bonus = bonus:sub(1,index-1)..times
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   103
	else
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   104
		bonus = bonus:sub(1,index-1)..times..bonus:sub(index+1)
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   105
	end
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   106
	SaveCampaignVar("SideMissionsBonuses",bonus)
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   107
end
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   108
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   109
function getBonus(index)
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   110
	local bonus = 0
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   111
	if tonumber(GetCampaignVar("SideMissionsBonuses")) then
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   112
		bonusString = GetCampaignVar("SideMissionsBonuses")
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   113
		bonus = bonusString:sub(index,index)
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   114
	end
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   115
	return bonus
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
   116
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
   117
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
   118
-- 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
   119
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
   120
	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
   121
	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
   122
	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
   123
		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
   124
			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
   125
			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
   126
		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
   127
			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
   128
		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
   129
		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
   130
	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
   131
	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
   132
		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
   133
	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
   134
	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
   135
end