Load sliders from paths.json

This commit is contained in:
Gent 2020-09-25 14:42:31 -04:00
parent b4fb449e69
commit 0ea5712f8c
4 changed files with 43 additions and 15 deletions

View File

@ -40,7 +40,7 @@ void TableData::init() {
std::cerr << "[WARN] Malformed NPCs.json file! Reason:" << err.what() << std::endl;
}
loadPaths(); // load paths
loadPaths(&nextId); // load paths
// load everything else from xdttable
std::cout << "[INFO] Parsing xdt.json..." << std::endl;
@ -223,7 +223,7 @@ int TableData::getItemType(int itemSet) {
/*
* Load paths from paths JSON.
*/
void TableData::loadPaths() {
void TableData::loadPaths(int* nextId) {
try {
std::ifstream inFile(settings::PATHJSON);
nlohmann::json pathData;
@ -238,6 +238,21 @@ void TableData::loadPaths() {
}
std::cout << "[INFO] Loaded " << TransportManager::SkywayPaths.size() << " skyway paths" << std::endl;
// slider circuit
nlohmann::json pathDataSlider = pathData["slider"];
for (nlohmann::json::iterator _sliderPoint = pathDataSlider.begin(); _sliderPoint != pathDataSlider.end(); _sliderPoint++) {
auto sliderPoint = _sliderPoint.value();
if (sliderPoint["stop"]) { // check if this point in the circuit is a stop
// spawn a slider
std::cout << "bus ID was " << *nextId << std::endl;
BaseNPC* slider = new BaseNPC(sliderPoint["iX"], sliderPoint["iY"], sliderPoint["iZ"], 1, (*nextId)++, NPC_BUS);
NPCManager::NPCs[slider->appearanceData.iNPC_ID] = slider;
NPCManager::updateNPCPosition(slider->appearanceData.iNPC_ID, slider->appearanceData.iX, slider->appearanceData.iY, slider->appearanceData.iZ);
// set slider path to a rotation of the circuit
constructPathSlider(pathDataSlider, 0, slider->appearanceData.iNPC_ID);
}
}
// npc paths
nlohmann::json pathDataNPC = pathData["npc"];
for (nlohmann::json::iterator npcPath = pathDataNPC.begin(); npcPath != pathDataNPC.end(); npcPath++) {
@ -272,6 +287,27 @@ void TableData::constructPathSkyway(nlohmann::json::iterator _pathData) {
TransportManager::SkywayPaths[pathData["iRouteID"]] = points;
}
void TableData::constructPathSlider(nlohmann::json points, int rotations, int sliderID) {
std::queue<WarpLocation> route;
std::rotate(points.begin(), points.begin() + rotations, points.end()); // rotate points
nlohmann::json::iterator _point = points.begin(); // iterator
auto point = _point.value();
WarpLocation from = { point["iX"] , point["iY"] , point["iZ"] }; // point A coords
int stopTime = point["stop"] ? SLIDER_STOP_TICKS : 0; // arbitrary stop length
for (_point++; _point != points.end(); _point++) { // loop through all point Bs
point = _point.value();
for (int i = 0; i < stopTime + 1; i++) // repeat point if it's a stop
route.push(from); // add point A to the queue
WarpLocation to = { point["iX"] , point["iY"] , point["iZ"] }; // point B coords
TransportManager::lerp(&route, from, to, SLIDER_SPEED); // lerp from A to B (arbitrary speed)
from = to; // update point A
stopTime = point["stop"] ? SLIDER_STOP_TICKS : 0;
}
std::rotate(points.rbegin(), points.rbegin() + rotations, points.rend()); // undo rotation
TransportManager::NPCQueues[sliderID] = route;
}
void TableData::constructPathNPC(nlohmann::json::iterator _pathData) {
auto pathData = _pathData.value();
// Interpolate

View File

@ -8,7 +8,8 @@ namespace TableData {
void cleanup();
int getItemType(int);
void loadPaths();
void loadPaths(int*);
void constructPathSkyway(nlohmann::json::iterator);
void constructPathSlider(nlohmann::json, int, int);
void constructPathNPC(nlohmann::json::iterator);
}

View File

@ -17,18 +17,6 @@ void TransportManager::init() {
REGISTER_SHARD_PACKET(P_CL2FE_REQ_REGIST_TRANSPORTATION_LOCATION, transportRegisterLocationHandler);
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_WARP_USE_TRANSPORTATION, transportWarpHandler);
BaseNPC* bus = new BaseNPC(220447, 162431, -3650, 1, NPCManager::nextId++, NPC_BUS);
NPCManager::NPCs[bus->appearanceData.iNPC_ID] = bus;
ChunkManager::addNPC(bus->appearanceData.iX, bus->appearanceData.iY, bus->appearanceData.iNPC_ID);
std::queue<WarpLocation> busPoints;
WarpLocation start = { bus->appearanceData.iX, bus->appearanceData.iY, -3650 };
WarpLocation end = { 220441, 188102, -3653 };
busPoints.push(start);
TransportManager::lerp(&busPoints, start, end, 1000);
busPoints.push(end);
TransportManager::lerp(&busPoints, end, start, 1000);
NPCQueues[bus->appearanceData.iNPC_ID] = busPoints;
}
void TransportManager::transportRegisterLocationHandler(CNSocket* sock, CNPacketData* data) {

View File

@ -5,6 +5,9 @@
#include <unordered_map>
const int SLIDER_SPEED = 1200;
const int SLIDER_STOP_TICKS = 8;
struct WarpLocation;
struct TransportRoute {