void playfield::setfield(int mapid, char pid) { active = false; npcs.clear(); mobs.clear(); drops.clear(); portals.clear(); chars.clear(); cache.getmobs()->clear(); mapdata* mdata = cache.getmap(); mdata->load(mapid); app.getimgcache()->setmode(ict_map); nl::nx::view_file("Map"); string strid = to_string(mapid); strid.insert(0, 9 - strid.length(), '0'); node src = nl::nx::nodes["Map"]["Map"]["Map" + to_string(mapid / 100000000)][strid + ".img"]; backgrounds = mapbackgrounds(src["back"]); portals.load(src["portal"], mapid); for (int i = 0; i < 8; i++) { layers[i] = maplayer(src[to_string(i)]); } nl::nx::unview_file("Map"); app.getimgcache()->unlock(); vector2d startpos = portals.getspawnpoint(pid); playerchar.updatefht(); playerchar.setposition(startpos); cam.setposition(startpos); cam.updateview(); active = true; }
void playfield::setfield(int mapid, char pid) { step = GST_TRANSITION; map_objects.clear(); portals.clear(); string oldbgm = map_info.getbgm(); app.getimgcache()->setmode(ict_map); nl::nx::view_file("Map"); string fullname; string strid = to_string(mapid); size_t extend = 9 - strid.length(); for (char i = 0; i < extend; i++) { fullname.append("0"); } node mapdata = nl::nx::nodes["Map"].resolve("Map/Map" + to_string(mapid / 100000000) + "/" + fullname.append(strid) + ".img"); footholds = footholdtree(mapdata["foothold"]); map_info = mapinfo(mapid, mapdata["info"], vector2d(footholds.getwalls()), vector2d(footholds.getborders())); landr = laddersropes(mapdata["ladderRope"]); nl::node portalnodes = mapdata["portal"]; for (nl::node portalnd = portalnodes.begin(); portalnd != portalnodes.end(); portalnd++) { char pid = static_cast<char>(stoi(portalnd.name())); portaltype ptype = static_cast<portaltype>(portalnd.resolve("pt").get_integer()); string pname = portalnd.resolve("pn").get_string(); vector2d ppos = vector2d(static_cast<int>(portalnd.resolve("x").get_integer()), static_cast<int>(portalnd.resolve("y").get_integer())); int targetid = static_cast<int>(portalnd.resolve("tm").get_integer()); string targetpname = portalnd.resolve("tn").get_string(); animation anim; nl::node pnode = nl::nx::nodes["Map"].resolve("MapHelper.img/portal/game"); switch (ptype) { case PT_REGULAR: anim = animation(pnode.resolve("pv")); break; case PT_HIDDEN: case PT_SCRIPTED_HIDDEN: anim = animation(pnode.resolve("ph/default/portalContinue")); break; } portals.addportal(pid, portal(ptype, pname, targetid, targetid == mapid, targetpname, anim, ppos)); } nl::nx::view_file("Back"); backgrounds = mapbackgrounds(mapdata.resolve("back"), map_info.getwalls(), map_info.getborders()); nl::nx::unview_file("Back"); nl::nx::view_file("Tile"); nl::nx::view_file("Obj"); for (int i = 0; i < 8; i++) { maplayers[i] = maplayer(mapdata.resolve(to_string(i))); } nl::nx::unview_file("Tile"); nl::nx::unview_file("Obj"); nl::nx::unview_file("Map"); app.getimgcache()->unlock(); vector2d startpos = portals.getspawnpoint(pid); playerchar.setfh(&footholds); playerchar.setposition(startpos); view.setposition(startpos); view.setbounds(map_info.getwalls(), map_info.getborders()); string path = map_info.getbgm(); if (path != oldbgm) { bgm.Cleanup(); wstring stemp = wstring(path.begin(), path.end()); bgm.Load(stemp.c_str()); bgm.SetVolume((100 * config.getbgmvolume()) - 10000); bgm.Play(); } step = GST_GAME; }