|
| 1 | +Mission00 = {} |
| 2 | +local Mission00_mt = Class(Mission00, BaseMission) |
| 3 | +function Mission00:new() |
| 4 | + local instance = Mission00:superClass():new(Mission00_mt) |
| 5 | + instance.playerStartX = 161.5 |
| 6 | + instance.playerStartY = 0.1 |
| 7 | + instance.playerStartZ = 111 |
| 8 | + instance.playerRotX = 0 |
| 9 | + instance.playerRotY = Utils.degToRad(180) |
| 10 | + instance.renderTime = true |
| 11 | + instance.isFreePlayMission = true |
| 12 | + instance.vehiclesToSpawn = {} |
| 13 | + instance.foundBottleCount = 0 |
| 14 | + instance.deliveredBottles = 0 |
| 15 | + instance.foundBottles = "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" |
| 16 | + instance.foundInfoTriggers = "00000000000000000000" |
| 17 | + instance.missionMapBottleTriggers = {} |
| 18 | + instance.missionMapGlassContainerTriggers = {} |
| 19 | + instance.disableCombineAI = false |
| 20 | + instance.disableTractorAI = false |
| 21 | + return instance |
| 22 | +end |
| 23 | +function Mission00:delete() |
| 24 | + self.inGameMessage:delete() |
| 25 | + self.inGameIcon:delete() |
| 26 | + delete(self.bottlePickupSound) |
| 27 | + delete(self.bottleDropSound) |
| 28 | + for i = 1, table.getn(self.missionMapBottleTriggers) do |
| 29 | + removeTrigger(self.missionMapBottleTriggers[i]) |
| 30 | + end |
| 31 | + for i = 1, table.getn(self.missionMapGlassContainerTriggers) do |
| 32 | + removeTrigger(self.missionMapGlassContainerTriggers[i]) |
| 33 | + end |
| 34 | + Mission00:superClass().delete(self) |
| 35 | +end |
| 36 | +function Mission00:load() |
| 37 | + g_mission00StartPoint = nil |
| 38 | + self.environment = Environment:new("data/sky/sky_day_night.i3d", true, 8, true, true) |
| 39 | + self.environment.timeScale = g_settingsTimeScale |
| 40 | + self.showWeatherForecast = true |
| 41 | + self:loadMap("map01") |
| 42 | + self.missionMapBottles = self:superClass().loadMissionMap(self, "collectableBottles.i3d") |
| 43 | + self.missionMapGlassContainers = self:superClass().loadMissionMap(self, "glassContainers.i3d") |
| 44 | + local bottleTriggerParentId = getChild(self.missionMapBottles, "CollectableBottles") |
| 45 | + if bottleTriggerParentId ~= 0 then |
| 46 | + local numChildren = getNumOfChildren(bottleTriggerParentId) |
| 47 | + for i = 0, numChildren - 1 do |
| 48 | + local id = getChildAt(bottleTriggerParentId, i) |
| 49 | + id = getChildAt(id, 0) |
| 50 | + addTrigger(id, "bottleTriggerCallback", self) |
| 51 | + self.missionMapBottleTriggers[i + 1] = id |
| 52 | + end |
| 53 | + end |
| 54 | + local glassContainerTriggerParentId = getChild(self.missionMapGlassContainers, "GlassContainers") |
| 55 | + if glassContainerTriggerParentId ~= 0 then |
| 56 | + local numChildren = getNumOfChildren(glassContainerTriggerParentId) |
| 57 | + for i = 0, numChildren - 1 do |
| 58 | + local id = getChildAt(glassContainerTriggerParentId, i) |
| 59 | + id = getChildAt(id, 0) |
| 60 | + addTrigger(id, "glassContainerTriggerCallback", self) |
| 61 | + local x, y, z = getWorldTranslation(id) |
| 62 | + self.missionStats:createMapHotspot(tostring(id), "dataS/missions/hud_pda_spot_gc.png", x + 1024, z + 1024, self.missionStats.pdaMapArrowSize, self.missionStats.pdaMapArrowSize * 1.3333333333333333, false, false, 0) |
| 63 | + self.missionMapGlassContainerTriggers[i + 1] = id |
| 64 | + end |
| 65 | + end |
| 66 | + self.bottlePickupSound = createSample("bottlePickupSound") |
| 67 | + loadSample(self.bottlePickupSound, "data/maps/sounds/bottlePickupSound.wav", false) |
| 68 | + self.bottleDropSound = createSample("bottleDropSound") |
| 69 | + loadSample(self.bottleDropSound, "data/maps/sounds/bottleDropSound.wav", false) |
| 70 | + self.missionMapPalletTrigger = self:superClass().loadMissionMap(self, "mission_stacking/palletMarker.i3d") |
| 71 | + self.inGameMessage = InGameMessage:new() |
| 72 | + self.inGameIcon = InGameIcon:new() |
| 73 | + self.missionMapInfo = self:superClass().loadMissionMap(self, "careerInfoTriggers.i3d") |
| 74 | + local missionMapInfoTriggers = {} |
| 75 | + local infoTriggerParentId = getChild(self.missionMapInfo, "infoTriggers") |
| 76 | + if infoTriggerParentId ~= 0 then |
| 77 | + local numChildren = getNumOfChildren(infoTriggerParentId) |
| 78 | + for i = 0, numChildren - 1 do |
| 79 | + local id = getChildAt(infoTriggerParentId, i) |
| 80 | + id = getChildAt(id, 0) |
| 81 | + missionMapInfoTriggers[i + 1] = id |
| 82 | + end |
| 83 | + end |
| 84 | + self.messages = {} |
| 85 | + local xmlFile = loadXMLFile("messages.xml", "dataS/missions/messages_career" .. g_languageSuffix .. ".xml") |
| 86 | + local eom = false |
| 87 | + local i = 0 |
| 88 | + repeat |
| 89 | + local message = {} |
| 90 | + local baseXMLName = string.format("messages.message(%d)", i) |
| 91 | + message.id = getXMLInt(xmlFile, baseXMLName .. "#id") |
| 92 | + if message.id ~= nil then |
| 93 | + message.title = getXMLString(xmlFile, baseXMLName .. ".title") |
| 94 | + message.content = getXMLString(xmlFile, baseXMLName .. ".content") |
| 95 | + message.duration = getXMLInt(xmlFile, baseXMLName .. ".duration") |
| 96 | + self.messages[message.id] = message |
| 97 | + else |
| 98 | + eom = true |
| 99 | + end |
| 100 | + i = i + 1 |
| 101 | + until eom |
| 102 | + delete(xmlFile) |
| 103 | + self:superClass().loadMissionMap(self, "saucer.i3d") |
| 104 | + self:loadVehicles(g_missionLoaderDesc.vehiclesXML, g_missionLoaderDesc.resetVehicles) |
| 105 | + self.environment.dayTime = g_missionLoaderDesc.stats.dayTime * 1000 * 60 |
| 106 | + if g_missionLoaderDesc.stats.nextRainValid then |
| 107 | + self.environment.timeUntilNextRain = g_missionLoaderDesc.stats.timeUntilNextRain |
| 108 | + self.environment.timeUntilRainAfterNext = g_missionLoaderDesc.stats.timeUntilRainAfterNext |
| 109 | + self.environment.rainTime = g_missionLoaderDesc.stats.rainTime |
| 110 | + self.environment.nextRainDuration = g_missionLoaderDesc.stats.nextRainDuration |
| 111 | + self.environment.nextRainType = g_missionLoaderDesc.stats.nextRainType |
| 112 | + self.environment.rainTypeAfterNext = g_missionLoaderDesc.stats.rainTypeAfterNext |
| 113 | + end |
| 114 | + self.environment.currentDay = g_missionLoaderDesc.stats.currentDay |
| 115 | + self.foundBottleCount = g_missionLoaderDesc.stats.foundBottleCount |
| 116 | + self.deliveredBottles = g_missionLoaderDesc.stats.deliveredBottles |
| 117 | + self.foundBottles = g_missionLoaderDesc.stats.foundBottles |
| 118 | + self.sessionDeliveredBottles = 0 |
| 119 | + for i = 1, string.len(self.foundBottles) do |
| 120 | + if string.sub(self.foundBottles, i, i) == "1" then |
| 121 | + local triggerId = self.missionMapBottleTriggers[i] |
| 122 | + removeTrigger(triggerId) |
| 123 | + local parentId = getParent(triggerId) |
| 124 | + delete(triggerId) |
| 125 | + setVisibility(parentId, false) |
| 126 | + end |
| 127 | + end |
| 128 | + self.reputation = g_missionLoaderDesc.stats.reputation |
| 129 | + self.foundInfoTriggers = g_missionLoaderDesc.stats.foundInfoTriggers |
| 130 | + for i = 1, string.len(self.foundInfoTriggers) do |
| 131 | + if string.sub(self.foundInfoTriggers, i, i) == "1" then |
| 132 | + local triggerId = missionMapInfoTriggers[i] |
| 133 | + removeTrigger(triggerId) |
| 134 | + local parentId = getParent(triggerId) |
| 135 | + setVisibility(parentId, false) |
| 136 | + end |
| 137 | + end |
| 138 | + for i = 1, FruitUtil.NUM_FRUITTYPES do |
| 139 | + FruitUtil.fruitIndexToDesc[i].pricePerLiter = g_missionLoaderDesc.stats.fruitPrices[i] |
| 140 | + FruitUtil.fruitIndexToDesc[i].yesterdaysPrice = g_missionLoaderDesc.stats.yesterdaysFruitPrices[i] |
| 141 | + end |
| 142 | + if g_mission00StartPoint ~= nil then |
| 143 | + local x, y, z = getTranslation(g_mission00StartPoint) |
| 144 | + local dirX, dirY, dirZ = localDirectionToWorld(g_mission00StartPoint, 0, 0, -1) |
| 145 | + self.playerStartX = x |
| 146 | + self.playerStartY = y |
| 147 | + self.playerStartZ = z |
| 148 | + self.playerRotX = 0 |
| 149 | + self.playerRotY = Utils.getYRotationFromDirection(dirX, dirZ) |
| 150 | + self.playerStartIsAbsolute = true |
| 151 | + end |
| 152 | + Mission00:superClass().load(self) |
| 153 | +end |
| 154 | +function Mission00:mouseEvent(posX, posY, isDown, isUp, button) |
| 155 | + Mission00:superClass().mouseEvent(self, posX, posY, isDown, isUp, button) |
| 156 | + self.inGameMessage:mouseEvent(posX, posY, isDown, isUp, button) |
| 157 | + self.inGameIcon:mouseEvent(posX, posY, isDown, isUp, button) |
| 158 | +end |
| 159 | +function Mission00:keyEvent(unicode, sym, modifier, isDown) |
| 160 | + Mission00:superClass().keyEvent(self, unicode, sym, modifier, isDown) |
| 161 | +end |
| 162 | +function Mission00:update(dt) |
| 163 | + if self.firstTimeRun then |
| 164 | + local numToSpawn = table.getn(self.vehiclesToSpawn) |
| 165 | + if 0 < numToSpawn then |
| 166 | + local xmlFile = loadXMLFile("VehiclesXML", g_missionLoaderDesc.vehiclesXML) |
| 167 | + for i = 1, numToSpawn do |
| 168 | + local key = self.vehiclesToSpawn[i].xmlKey |
| 169 | + local filename = getXMLString(xmlFile, key .. "#filename") |
| 170 | + if filename ~= nil then |
| 171 | + local vehicle = self:loadVehicle(filename, 0, 0, 0, 0) |
| 172 | + if vehicle ~= nil then |
| 173 | + local r = vehicle:loadFromAttributesAndNodes(xmlFile, key, true) |
| 174 | + if r ~= BaseMission.VEHICLE_LOAD_OK then |
| 175 | + print("Warning: corrupt savegame, vehicle " .. filename .. " could not be loaded") |
| 176 | + self:removeVehicle(vehicle) |
| 177 | + end |
| 178 | + end |
| 179 | + end |
| 180 | + end |
| 181 | + delete(xmlFile) |
| 182 | + self.vehiclesToSpawn = {} |
| 183 | + self.usedLoadPlaces = {} |
| 184 | + end |
| 185 | + end |
| 186 | + Mission00:superClass().update(self, dt) |
| 187 | + if self.environment.dayTime > 72000000 or self.environment.dayTime < 21600000 then |
| 188 | + self.environment.timeScale = g_settingsTimeScale * 4 |
| 189 | + else |
| 190 | + self.environment.timeScale = g_settingsTimeScale |
| 191 | + end |
| 192 | + self.inGameMessage:update(dt) |
| 193 | + self.inGameIcon:update(dt) |
| 194 | +end |
| 195 | +function Mission00:draw() |
| 196 | + Mission00:superClass().draw(self) |
| 197 | + self.inGameMessage:draw() |
| 198 | + self.inGameIcon:draw() |
| 199 | +end |
| 200 | +function Mission00:loadVehicles(xmlFilename, resetVehicles) |
| 201 | + local xmlFile = loadXMLFile("VehiclesXML", xmlFilename) |
| 202 | + local vehicleI = 0 |
| 203 | + while true do |
| 204 | + local key = string.format("careerVehicles.vehicle(%d)", vehicleI) |
| 205 | + local filename = getXMLString(xmlFile, key .. "#filename") |
| 206 | + if filename == nil then |
| 207 | + break |
| 208 | + end |
| 209 | + local vehicle = self:loadVehicle(filename, 0, 0, 0, 0) |
| 210 | + if vehicle ~= nil then |
| 211 | + local r = vehicle:loadFromAttributesAndNodes(xmlFile, key, resetVehicles) |
| 212 | + if r == BaseMission.VEHICLE_LOAD_ERROR then |
| 213 | + print("Warning: corrupt savegame, vehicle " .. filename .. " could not be loaded") |
| 214 | + self:removeVehicle(vehicle) |
| 215 | + elseif r == BaseMission.VEHICLE_LOAD_DELAYED then |
| 216 | + table.insert(self.vehiclesToSpawn, {xmlKey = key}) |
| 217 | + self:removeVehicle(vehicle) |
| 218 | + end |
| 219 | + end |
| 220 | + vehicleI = vehicleI + 1 |
| 221 | + end |
| 222 | + local i = 0 |
| 223 | + while true do |
| 224 | + local key = string.format("careerVehicles.item(%d)", i) |
| 225 | + local filename = getXMLString(xmlFile, key .. "#filename") |
| 226 | + if filename == nil then |
| 227 | + break |
| 228 | + end |
| 229 | + local rootNode = Utils.loadSharedI3DFile(filename) |
| 230 | + local childIndex = getXMLInt(xmlFile, key .. "#childIndex") |
| 231 | + if childIndex == nil then |
| 232 | + childIndex = 0 |
| 233 | + end |
| 234 | + local node = getChildAt(rootNode, childIndex) |
| 235 | + if node ~= nil and node ~= 0 then |
| 236 | + local x, y, z = Utils.getVectorFromString(getXMLString(xmlFile, key .. "#position")) |
| 237 | + local xRot, yRot, zRot = Utils.getVectorFromString(getXMLString(xmlFile, key .. "#rotation")) |
| 238 | + if x == nil or y == nil or z == nil or xRot == nil or yRot == nil or zRot == nil then |
| 239 | + print("Warning: corrupt savegame, item " .. filename .. " could not be loaded") |
| 240 | + else |
| 241 | + setTranslation(node, x, y, z) |
| 242 | + setRotation(node, xRot, yRot, zRot) |
| 243 | + link(getRootNode(), node) |
| 244 | + self:addItemToSave(filename, node, childIndex) |
| 245 | + end |
| 246 | + delete(rootNode) |
| 247 | + end |
| 248 | + i = i + 1 |
| 249 | + end |
| 250 | + delete(xmlFile) |
| 251 | +end |
| 252 | +function Mission00:saveVehicles(file) |
| 253 | + for k, vehicle in pairs(self.vehiclesToSave) do |
| 254 | + file:write(" <vehicle filename=\"" .. Utils.encodeToHTML(vehicle.configFileName) .. "\"") |
| 255 | + local attributes, nodes = vehicle:getSaveAttributesAndNodes(" ") |
| 256 | + if attributes ~= nil and attributes ~= "" then |
| 257 | + file:write(" " .. attributes) |
| 258 | + end |
| 259 | + if nodes ~= nil and nodes ~= "" then |
| 260 | + file:write(">\n" .. nodes .. [[ |
| 261 | +
|
| 262 | + </vehicle> |
| 263 | +]]) |
| 264 | + else |
| 265 | + file:write("/>\n") |
| 266 | + end |
| 267 | + end |
| 268 | + for k, item in pairs(self.itemsToSave) do |
| 269 | + file:write(" <item filename=\"" .. Utils.encodeToHTML(item.i3dFilename) .. "\"") |
| 270 | + local x, y, z = getTranslation(item.node) |
| 271 | + local xRot, yRot, zRot = getRotation(item.node) |
| 272 | + file:write(" position=\"" .. x .. " " .. y .. " " .. z .. "\" rotation=\"" .. xRot .. " " .. yRot .. " " .. zRot .. "\" childIndex=\"" .. item.childIndex .. "\" />\n") |
| 273 | + end |
| 274 | +end |
| 275 | +function Mission00:bottleTriggerCallback(triggerId, otherId, onEnter, onLeave, onStay) |
| 276 | + if onEnter and self.controlPlayer and otherId == Player.rootNode then |
| 277 | + removeTrigger(triggerId) |
| 278 | + local bottleName = getName(triggerId) |
| 279 | + local bottleNumber = tonumber(string.sub(bottleName, string.len(bottleName) - 2, string.len(bottleName))) |
| 280 | + self.foundBottles = string.sub(self.foundBottles, 1, bottleNumber - 1) .. "1" .. string.sub(self.foundBottles, bottleNumber + 1, string.len(self.foundBottles)) |
| 281 | + local parentId = getParent(triggerId) |
| 282 | + delete(triggerId) |
| 283 | + setVisibility(parentId, false) |
| 284 | + if self.inGameIcon.fileName ~= "dataS/missions/bottle.png" then |
| 285 | + self.inGameIcon:setIcon("dataS/missions/bottle.png") |
| 286 | + end |
| 287 | + self.inGameIcon:setText("+1") |
| 288 | + self.inGameIcon:showIcon(2000) |
| 289 | + if self.bottlePickupSound ~= nil then |
| 290 | + playSample(self.bottlePickupSound, 1, 1, 0) |
| 291 | + end |
| 292 | + self.foundBottleCount = self.foundBottleCount + 1 |
| 293 | + end |
| 294 | +end |
| 295 | +function Mission00:glassContainerTriggerCallback(triggerId, otherId, onEnter, onLeave, onStay) |
| 296 | + if onEnter and self.controlPlayer and otherId == Player.rootNode and self.foundBottleCount > 0 then |
| 297 | + self.missionStats.money = self.missionStats.money + self.foundBottleCount |
| 298 | + self.deliveredBottles = self.deliveredBottles + self.foundBottleCount |
| 299 | + self.sessionDeliveredBottles = self.sessionDeliveredBottles + self.foundBottleCount |
| 300 | + if self.bottleDropSound ~= nil then |
| 301 | + playSample(self.bottleDropSound, 1, 0.5, 0) |
| 302 | + end |
| 303 | + self:increaseReputation(self.foundBottleCount) |
| 304 | + self.foundBottleCount = 0 |
| 305 | + end |
| 306 | +end |
| 307 | +function Mission00:infospotTouched(triggerId) |
| 308 | + local triggerName = getName(triggerId) |
| 309 | + local triggerNumber = tonumber(string.sub(triggerName, string.len(triggerName) - 1)) |
| 310 | + self.foundInfoTriggers = string.sub(self.foundInfoTriggers, 1, triggerNumber - 1) .. "1" .. string.sub(self.foundInfoTriggers, triggerNumber + 1) |
| 311 | + if self.messages[triggerNumber] ~= nil then |
| 312 | + self.inGameMessage:showMessage(self.messages[triggerNumber].title, self.messages[triggerNumber].content, self.messages[triggerNumber].duration, false) |
| 313 | + end |
| 314 | +end |
| 315 | +function Mission00:onCreateStartPoint(id) |
| 316 | + g_mission00StartPoint = id |
| 317 | +end |
0 commit comments