share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/global_functions.lua
author Periklis Ntanasis <pntanasis@gmail.com>
Tue, 17 Sep 2013 02:04:41 +0300
branchspacecampaign
changeset 9632 9dd1c36d8b54
parent 9630 df942cfac4e6
child 9636 e1921235fc78
permissions -rw-r--r--
final mission map and most logic
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)
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
     2
	--        1       2        3        4      5         6
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
     3
	-- order: moon01, fruit01, fruit02, ice01, desert01, death01
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
     4
	local status = "000000"
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
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
     8
	if i == 1 then
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
     9
		status = "1"..status:sub(planetNum+1)
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    10
	elseif i == status:len() then
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    11
		status = status:sub(1,planetNum-1).."1"
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    12
	else
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    13
		status = status:sub(1,planetNum-1).."1"..status:sub(planetNum+1)
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    14
	end
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    15
	SaveCampaignVar("MainMissionsStatus",status)
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    16
end
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    17
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    18
function getCompletedStatus()
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    19
	local allStatus = ""
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    20
	if tonumber(GetCampaignVar("MainMissionsStatus")) then
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    21
		allStatus = GetCampaignVar("MainMissionsStatus")
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    22
	end
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    23
	local status = {
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    24
		moon01 = false,
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    25
		fruit01 = false,
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    26
		fruit02 = false,
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    27
		ice01 = false,
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    28
		desert01 = false,
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    29
		death01 = false
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    30
	}
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    31
	if allStatus ~= "" then
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    32
		if allStatus:sub(1,1) == "1" then
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    33
			status.moon01 = true
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    34
		end
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    35
		if allStatus:sub(2,2) == "1" then
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    36
			status.fuit01 = true
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    37
		end
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    38
		if allStatus:sub(3,3) == "1" then
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    39
			status.fruit02 = true
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    40
		end
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    41
		if allStatus:sub(4,4) == "1" then
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    42
			status.ice01 = true
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    43
		end
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    44
		if allStatus:sub(5,5) == "1" then
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    45
			status.desert01 = true
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    46
		end
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    47
		if allStatus:sub(6,6) == "1" then
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    48
			status.death01 = true
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
	end
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    51
	return status
16139270448f save main missions' status
Periklis Ntanasis <pntanasis@gmail.com>
parents:
diff changeset
    52
end
9582
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
    53
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
    54
function initCheckpoint(mission)
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
    55
	local checkPoint = 1
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
    56
	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
    57
		SaveCampaignVar("CurrentMission", mission)
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
    58
		SaveCampaignVar("CurrentMissionCheckpoint", 1)
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
    59
	else
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
    60
		checkPoint = tonumber(GetCampaignVar("currentMissionCheckpoint"))
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
    61
	end
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
    62
	return checkPoint
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
    63
end
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
    64
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
    65
function saveCheckpoint(cp)
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
    66
	SaveCampaignVar("CurrentMissionCheckpoint", cp)
bf314b2258b3 less variables used to save the checkpoints - potential breakage xD
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9578
diff changeset
    67
end
9630
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    68
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    69
-- saves what bonuses are available
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    70
-- 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
    71
function saveBonus(index, times)
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    72
	--        1         2        3
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    73
	-- order: desert03, fruit03, death02
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    74
	local bonus = "000"
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    75
	if tonumber(GetCampaignVar("SideMissionsBonuses")) then
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    76
		bonus = GetCampaignVar("SideMissionsBonuses")
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    77
	end
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    78
	if i == 1 then
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    79
		bonus = times..bonus:sub(index+1)
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    80
	elseif i == bonus:len() then
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    81
		bonus = bonus:sub(1,index-1)..times
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    82
	else
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    83
		bonus = bonus:sub(1,index-1)..times..bonus:sub(index+1)
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    84
	end
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    85
	SaveCampaignVar("SideMissionsBonuses",bonus)
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    86
end
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    87
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    88
function getBonus(index)
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    89
	local bonus = 0
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    90
	if tonumber(GetCampaignVar("SideMissionsBonuses")) then
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    91
		bonusString = GetCampaignVar("SideMissionsBonuses")
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    92
		bonus = bonusString:sub(index,index)
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    93
	end
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    94
	return bonus
df942cfac4e6 add bonuses
Periklis Ntanasis <pntanasis@gmail.com>
parents: 9582
diff changeset
    95
end