Commit fa86870bc7137f118ea351c1e5ad23af11fd2682

Authored by dg
1 parent 306620bb

Switching to and from ambushes should be quite faster


git-svn-id: http://svn.net-core.org/repos/t-engine4@5146 51575b47-30f0-44d4-a5cc-537603b46e54
... ... @@ -232,7 +232,7 @@ function _M:newGame()
232 232 -- Generate
233 233 if self.player.__game_difficulty then self:setupDifficulty(self.player.__game_difficulty) end
234 234 self:setupPermadeath(self.player)
235   - self:changeLevel(self.player.starting_level or 1, self.player.starting_zone, nil, self.player.starting_level_force_down)
  235 + self:changeLevel(self.player.starting_level or 1, self.player.starting_zone, {force_down=self.player.starting_level_force_down})
236 236
237 237 print("[PLAYER BIRTH] resolve...")
238 238 self.player:resolve()
... ... @@ -287,7 +287,7 @@ function _M:newGame()
287 287 self.to_re_add_actors = {}
288 288 for act, _ in pairs(self.party.members) do if self.player ~= act then self.to_re_add_actors[act] = true end end
289 289
290   - self:changeLevel(self.player.starting_level or 1, self.player.starting_zone, nil, self.player.starting_level_force_down)
  290 + self:changeLevel(self.player.starting_level or 1, self.player.starting_zone, {force_down=self.player.starting_level_force_down})
291 291 self.player:grantQuest(self.player.starting_quest)
292 292 self.creating_player = false
293 293
... ... @@ -545,7 +545,8 @@ function _M:onLevelLoad(id, fct, data)
545 545 print("Registering on level load", id, fct, data)
546 546 end
547 547
548   -function _M:changeLevel(lev, zone, keep_old_lev, force_down, auto_zone_stair)
  548 +function _M:changeLevel(lev, zone, params)
  549 + params = params or {}
549 550 if not self.player.can_change_level then
550 551 self.logPlayer(self.player, "#LIGHT_RED#You may not change level without your own body!")
551 552 return
... ... @@ -606,32 +607,80 @@ function _M:changeLevel(lev, zone, keep_old_lev, force_down, auto_zone_stair)
606 607 if self._chronoworlds then self._chronoworlds = nil end
607 608
608 609 local left_zone = self.zone
  610 + local old_lev = (self.level and not zone) and self.level.level or -1000
  611 + if params.keep_old_lev then old_lev = self.level.level end
609 612
610   - if self.zone and self.zone.on_leave then
611   - local nl, nz, stop = self.zone.on_leave(lev, old_lev, zone)
612   - if stop then return end
613   - if nl then lev = nl end
614   - if nz then zone = nz end
615   - end
  613 + local force_recreate = false
  614 + local popup = nil
616 615
617   - if self.zone and self.level then self.player:onLeaveLevel(self.zone, self.level) end
  616 + -- We only switch temporarily, keep the old one around
  617 + if params.temporary_zone_shift then
  618 + self:leaveLevel(self.level, lev, old_lev)
618 619
619   - local old_lev = (self.level and not zone) and self.level.level or -1000
620   - if keep_old_lev then old_lev = self.level.level end
621   - if zone then
622   - if self.zone then
623   - self.zone:leaveLevel(false, lev, old_lev)
624   - self.zone:leave()
625   - end
  620 + local oz, ol = self.zone, self.level
626 621 if type(zone) == "string" then
627 622 self.zone = Zone.new(zone)
628 623 else
629 624 self.zone = zone
630 625 end
631 626 if type(self.zone.save_per_level) == "nil" then self.zone.save_per_level = config.settings.tome.save_zone_levels and true or false end
  627 +
  628 + self.zone:getLevel(self, lev, old_lev, true)
  629 + self.visited_zones[self.zone.short_name] = true
  630 +
  631 + self.level.temp_shift_zone = oz
  632 + self.level.temp_shift_level = ol
  633 + -- We switch back
  634 + elseif params.temporary_zone_shift_back then
  635 + popup = Dialog:simpleWaiter("Loading level", "Please wait while loading the level...", nil, 10000)
  636 + core.display.forceRedraw()
  637 +
  638 + local old = self.level
  639 +
  640 + if self.zone and self.zone.on_leave then
  641 + local nl, nz, stop = self.zone.on_leave(lev, old_lev, zone)
  642 + if stop then return end
  643 + if nl then lev = nl end
  644 + if nz then zone = nz end
  645 + end
  646 +
  647 + if self.zone and self.level then self.player:onLeaveLevel(self.zone, self.level) end
  648 + if self.zone then
  649 + self.zone:leaveLevel(false, lev, old_lev)
  650 + self.zone:leave()
  651 + end
  652 +
  653 + self.zone = old.temp_shift_zone
  654 + self.level = old.temp_shift_level
  655 +
  656 + self.visited_zones[self.zone.short_name] = true
  657 + force_recreate = true
  658 + -- We move to a new zone as normal
  659 + elseif not params.temporary_zone_shift then
  660 + if self.zone and self.zone.on_leave then
  661 + local nl, nz, stop = self.zone.on_leave(lev, old_lev, zone)
  662 + if stop then return end
  663 + if nl then lev = nl end
  664 + if nz then zone = nz end
  665 + end
  666 +
  667 + if self.zone and self.level then self.player:onLeaveLevel(self.zone, self.level) end
  668 +
  669 + if zone then
  670 + if self.zone then
  671 + self.zone:leaveLevel(false, lev, old_lev)
  672 + self.zone:leave()
  673 + end
  674 + if type(zone) == "string" then
  675 + self.zone = Zone.new(zone)
  676 + else
  677 + self.zone = zone
  678 + end
  679 + if type(self.zone.save_per_level) == "nil" then self.zone.save_per_level = config.settings.tome.save_zone_levels and true or false end
  680 + end
  681 + self.zone:getLevel(self, lev, old_lev)
  682 + self.visited_zones[self.zone.short_name] = true
632 683 end
633   - local _, is_new = self.zone:getLevel(self, lev, old_lev)
634   - self.visited_zones[self.zone.short_name] = true
635 684
636 685 -- Post process walls
637 686 self.nicer_tiles:postProcessLevelTiles(self.level)
... ... @@ -676,7 +725,7 @@ function _M:changeLevel(lev, zone, keep_old_lev, force_down, auto_zone_stair)
676 725 self.player.last_wilderness = self.zone.short_name
677 726 else
678 727 local x, y = nil, nil
679   - if auto_zone_stair and left_zone then
  728 + if params.auto_zone_stair and left_zone then
680 729 -- Dirty but quick
681 730 local list = {}
682 731 for i = 0, self.level.map.w - 1 do for j = 0, self.level.map.h - 1 do
... ... @@ -690,7 +739,7 @@ function _M:changeLevel(lev, zone, keep_old_lev, force_down, auto_zone_stair)
690 739
691 740 -- Default to stairs
692 741 if not x then
693   - if lev > old_lev and not force_down then x, y = self.level.default_up.x, self.level.default_up.y
  742 + if lev > old_lev and not params.force_down then x, y = self.level.default_up.x, self.level.default_up.y
694 743 else x, y = self.level.default_down.x, self.level.default_down.y
695 744 end
696 745 end
... ... @@ -791,6 +840,7 @@ function _M:changeLevel(lev, zone, keep_old_lev, force_down, auto_zone_stair)
791 840
792 841 self.level.map:redisplay()
793 842 self.level.map:reopen()
  843 + if force_recreate then self.level.map:recreate() end
794 844
795 845 -- Anti stairscum
796 846 if self.level.last_turn and self.level.last_turn < self.turn then
... ... @@ -812,6 +862,8 @@ function _M:changeLevel(lev, zone, keep_old_lev, force_down, auto_zone_stair)
812 862 end
813 863 end
814 864 end
  865 +
  866 + if popup then popup:done() end
815 867 end
816 868
817 869 function _M:getPlayer(main)
... ... @@ -1240,7 +1292,7 @@ function _M:setupCommands()
1240 1292 else
1241 1293 -- Do not unpause, the player is allowed first move on next level
1242 1294 if e.change_level_check and e:change_level_check(self.player) then return end
1243   - self:changeLevel(e.change_zone and e.change_level or self.level.level + e.change_level, e.change_zone, e.keep_old_lev, e.force_down, e.change_zone_auto_stairs)
  1295 + self:changeLevel(e.change_zone and e.change_level or self.level.level + e.change_level, e.change_zone, {keep_old_lev=e.keep_old_lev, force_down=e.force_down, auto_zone_stair=e.change_zone_auto_stairs, temporary_zone_shift_back=e.change_level_shift_back})
1244 1296 end
1245 1297 else
1246 1298 self.log("There is no way out of this level here.")
... ...
... ... @@ -469,6 +469,9 @@ function _M:spawnWorldAmbush(enc, dx, dy)
469 469
470 470 if g.can_encounter == "desert" then gen.floor = "SAND" gen.wall = "PALMTREE" end
471 471
  472 + local terrains = mod.class.Grid:loadList{"/data/general/grids/basic.lua", "/data/general/grids/forest.lua", "/data/general/grids/sand.lua"}
  473 + terrains[gen.up].change_level_shift_back = true
  474 +
472 475 local zone = engine.Zone.new("ambush", {
473 476 name = "Ambush!",
474 477 level_range = {game.player.level, game.player.level},
... ... @@ -476,6 +479,7 @@ function _M:spawnWorldAmbush(enc, dx, dy)
476 479 max_level = 1,
477 480 actor_adjust_level = function(zone, level, e) return zone.base_level + e:getRankLevelAdjust() + level.level-1 + rng.range(-1,2) end,
478 481 width = enc.width or 20, height = enc.height or 20,
  482 + no_worldport = true,
479 483 all_lited = true,
480 484 ambient_music = "last",
481 485 max_material_level = util.bound(math.ceil(game.player.level / 10), 1, 5),
... ... @@ -486,7 +490,7 @@ function _M:spawnWorldAmbush(enc, dx, dy)
486 490 },
487 491
488 492 npc_list = mod.class.NPC:loadList("/data/general/npcs/all.lua", nil, nil, function(e) e.make_escort=nil end),
489   - grid_list = mod.class.Grid:loadList{"/data/general/grids/basic.lua", "/data/general/grids/forest.lua", "/data/general/grids/sand.lua"},
  493 + grid_list = terrains,
490 494 object_list = mod.class.Object:loadList("/data/general/objects/objects.lua"),
491 495 trap_list = {},
492 496 post_process = function(level)
... ... @@ -504,7 +508,7 @@ function _M:spawnWorldAmbush(enc, dx, dy)
504 508 game.player:runStop()
505 509 game.player.energy.value = game.energy_to_act
506 510 game.paused = true
507   - game:changeLevel(1, zone)
  511 + game:changeLevel(1, zone, {temporary_zone_shift=true})
508 512 engine.ui.Dialog:simplePopup("Ambush!", "You have been ambushed!")
509 513
510 514 end)
... ...
... ... @@ -31,7 +31,7 @@ newChat{ id="fool",
31 31 {"...", action = function(npc, player)
32 32 game:onTickEnd(function()
33 33 game.level:removeEntity(npc)
34   - game:changeLevel(2, rng.table{"trollmire","ruins-kor-pul","scintillating-caves","rhaloren-camp","norgos-lair","heart-gloom"})
  34 + game:changeLevel(2, (rng.table{"trollmire","ruins-kor-pul","scintillating-caves","rhaloren-camp","norgos-lair","heart-gloom"}))
35 35
36 36 local a = require("engine.Astar").new(game.level.map, player)
37 37
... ...