コード例 #1
0
void DynamicBody::LoadFromJson(const Json::Value &jsonObj, Space *space)
{
	ModelBody::LoadFromJson(jsonObj, space);

	if (!jsonObj.isMember("dynamic_body")) throw SavedGameCorruptException();
	Json::Value dynamicBodyObj = jsonObj["dynamic_body"];

	if (!dynamicBodyObj.isMember("force")) throw SavedGameCorruptException();
	if (!dynamicBodyObj.isMember("torque")) throw SavedGameCorruptException();
	if (!dynamicBodyObj.isMember("vel")) throw SavedGameCorruptException();
	if (!dynamicBodyObj.isMember("ang_vel")) throw SavedGameCorruptException();
	if (!dynamicBodyObj.isMember("mass")) throw SavedGameCorruptException();
	if (!dynamicBodyObj.isMember("mass_radius")) throw SavedGameCorruptException();
	if (!dynamicBodyObj.isMember("ang_inertia")) throw SavedGameCorruptException();
	if (!dynamicBodyObj.isMember("is_moving")) throw SavedGameCorruptException();

	JsonToVector(&m_force, dynamicBodyObj, "force");
	JsonToVector(&m_torque, dynamicBodyObj, "torque");
	JsonToVector(&m_vel, dynamicBodyObj, "vel");
	JsonToVector(&m_angVel, dynamicBodyObj, "ang_vel");
	m_mass = StrToDouble(dynamicBodyObj["mass"].asString());
	m_massRadius = StrToDouble(dynamicBodyObj["mass_radius"].asString());
	m_angInertia = StrToDouble(dynamicBodyObj["ang_inertia"].asString());
	m_isMoving = dynamicBodyObj["is_moving"].asBool();
}
コード例 #2
0
ファイル: DynamicBody.cpp プロジェクト: Philbywhizz/pioneer
void DynamicBody::LoadFromJson(const Json::Value &jsonObj, Space *space)
{
	ModelBody::LoadFromJson(jsonObj, space);

	if (!jsonObj.isMember("dynamic_body")) throw SavedGameCorruptException();
	Json::Value dynamicBodyObj = jsonObj["dynamic_body"];

	if (!dynamicBodyObj.isMember("force")) throw SavedGameCorruptException();
	if (!dynamicBodyObj.isMember("torque")) throw SavedGameCorruptException();
	if (!dynamicBodyObj.isMember("vel")) throw SavedGameCorruptException();
	if (!dynamicBodyObj.isMember("ang_vel")) throw SavedGameCorruptException();
	if (!dynamicBodyObj.isMember("mass")) throw SavedGameCorruptException();
	if (!dynamicBodyObj.isMember("mass_radius")) throw SavedGameCorruptException();
	if (!dynamicBodyObj.isMember("ang_inertia")) throw SavedGameCorruptException();
	if (!dynamicBodyObj.isMember("is_moving")) throw SavedGameCorruptException();

	JsonToVector(&m_force, dynamicBodyObj, "force");
	JsonToVector(&m_torque, dynamicBodyObj, "torque");
	JsonToVector(&m_vel, dynamicBodyObj, "vel");
	JsonToVector(&m_angVel, dynamicBodyObj, "ang_vel");
	m_mass = StrToDouble(dynamicBodyObj["mass"].asString());
	m_massRadius = StrToDouble(dynamicBodyObj["mass_radius"].asString());
	m_angInertia = StrToDouble(dynamicBodyObj["ang_inertia"].asString());
	m_isMoving = dynamicBodyObj["is_moving"].asBool();

	m_aiMessage = AIError::AIERROR_NONE;
	m_decelerating = false;
	for ( int i=0; i < Feature::MAX_FEATURE; i++ ) m_features[i] = false;
}
コード例 #3
0
ファイル: Frame.cpp プロジェクト: Philbywhizz/pioneer
Frame *Frame::FromJson(const Json::Value &jsonObj, Space *space, Frame *parent, double at_time)
{
	Frame *f = new Frame();
	f->m_parent = parent;

	if (!jsonObj.isMember("frame")) throw SavedGameCorruptException();
	Json::Value frameObj = jsonObj["frame"];

	if (!frameObj.isMember("flags")) throw SavedGameCorruptException();
	if (!frameObj.isMember("radius")) throw SavedGameCorruptException();
	if (!frameObj.isMember("label")) throw SavedGameCorruptException();
	if (!frameObj.isMember("pos")) throw SavedGameCorruptException();
	if (!frameObj.isMember("ang_speed")) throw SavedGameCorruptException();
	if (!frameObj.isMember("init_orient")) throw SavedGameCorruptException();
	if (!frameObj.isMember("index_for_system_body")) throw SavedGameCorruptException();
	if (!frameObj.isMember("index_for_astro_body")) throw SavedGameCorruptException();

	f->m_flags = frameObj["flags"].asInt();
	f->m_radius = StrToDouble(frameObj["radius"].asString());
	f->m_label = frameObj["label"].asString();
	JsonToVector(&(f->m_pos), frameObj, "pos");
	f->m_angSpeed = StrToDouble(frameObj["ang_speed"].asString());
	matrix3x3d orient;
	JsonToMatrix(&orient, frameObj, "init_orient");
	f->SetInitialOrient(orient, at_time);
	f->m_sbody = space->GetSystemBodyByIndex(frameObj["index_for_system_body"].asUInt());
	f->m_astroBodyIndex = frameObj["index_for_astro_body"].asUInt();
	f->m_vel = vector3d(0.0); // m_vel is set to zero.

	if (!frameObj.isMember("child_frames")) throw SavedGameCorruptException();
	Json::Value childFrameArray = frameObj["child_frames"];
	if (!childFrameArray.isArray()) throw SavedGameCorruptException();
	for (unsigned int i = 0; i < childFrameArray.size(); ++i) {
		f->m_children.push_back(FromJson(childFrameArray[i], space, f, at_time));
	}
	SfxManager::FromJson(frameObj, f);

	f->ClearMovement();
	return f;
}
コード例 #4
0
ファイル: Body.cpp プロジェクト: Philbywhizz/pioneer
void Body::LoadFromJson(const Json::Value &jsonObj, Space *space)
{
	if (!jsonObj.isMember("body")) throw SavedGameCorruptException();
	Json::Value bodyObj = jsonObj["body"];

	if (!bodyObj.isMember("index_for_frame")) throw SavedGameCorruptException();
	if (!bodyObj.isMember("label")) throw SavedGameCorruptException();
	if (!bodyObj.isMember("dead")) throw SavedGameCorruptException();
	if (!bodyObj.isMember("phys_radius")) throw SavedGameCorruptException();
	if (!bodyObj.isMember("clip_radius")) throw SavedGameCorruptException();

	Properties().LoadFromJson(bodyObj);
	m_frame = space->GetFrameByIndex(bodyObj["index_for_frame"].asUInt());
	m_label = bodyObj["label"].asString();
	Properties().Set("label", m_label);
	m_dead = bodyObj["dead"].asBool();

	JsonToVector(&m_pos, bodyObj, "pos");
	JsonToMatrix(&m_orient, bodyObj, "orient");
	m_physRadius = StrToDouble(bodyObj["phys_radius"].asString());
	m_clipRadius = StrToDouble(bodyObj["clip_radius"].asString());
}
コード例 #5
0
ファイル: SpaceStation.cpp プロジェクト: christiank/pioneer
void SpaceStation::LoadFromJson(const Json::Value &jsonObj, Space *space)
{
	ModelBody::LoadFromJson(jsonObj, space);
	GetModel()->SetLabel(GetLabel());

	if (!jsonObj.isMember("space_station")) throw SavedGameCorruptException();
	Json::Value spaceStationObj = jsonObj["space_station"];

	if (!spaceStationObj.isMember("ship_docking")) throw SavedGameCorruptException();
	if (!spaceStationObj.isMember("ports")) throw SavedGameCorruptException();
	if (!spaceStationObj.isMember("index_for_system_body")) throw SavedGameCorruptException();
	if (!spaceStationObj.isMember("door_animation_step")) throw SavedGameCorruptException();
	if (!spaceStationObj.isMember("door_animation_state")) throw SavedGameCorruptException();

	m_oldAngDisplacement = 0.0;

	Json::Value shipDockingArray = spaceStationObj["ship_docking"];
	if (!shipDockingArray.isArray()) throw SavedGameCorruptException();
	m_shipDocking.reserve(shipDockingArray.size());
	for (Uint32 i = 0; i < shipDockingArray.size(); i++)
	{
		m_shipDocking.push_back(shipDocking_t());
		shipDocking_t &sd = m_shipDocking.back();

		Json::Value shipDockingArrayEl = shipDockingArray[i];
		if (!shipDockingArrayEl.isMember("index_for_body")) throw SavedGameCorruptException();
		if (!shipDockingArrayEl.isMember("stage")) throw SavedGameCorruptException();
		if (!shipDockingArrayEl.isMember("stage_pos")) throw SavedGameCorruptException();
		if (!shipDockingArrayEl.isMember("from_pos")) throw SavedGameCorruptException();
		if (!shipDockingArrayEl.isMember("from_rot")) throw SavedGameCorruptException();

		sd.shipIndex = shipDockingArrayEl["index_for_body"].asInt();
		sd.stage = shipDockingArrayEl["stage"].asInt();
		sd.stagePos = StrToDouble(shipDockingArrayEl["stage_pos"].asString()); // For some reason stagePos was saved as a float in pre-JSON system (saved & loaded as double here).
		JsonToVector(&(sd.fromPos), shipDockingArrayEl, "from_pos");
		JsonToQuaternion(&(sd.fromRot), shipDockingArrayEl, "from_rot");
	}

	// retrieve each of the port details and bay IDs
	Json::Value portArray = spaceStationObj["ports"];
	if (!portArray.isArray()) throw SavedGameCorruptException();
	m_ports.reserve(portArray.size());
	for (Uint32 i = 0; i < portArray.size(); i++)
	{
		m_ports.push_back(SpaceStationType::SPort());
		SpaceStationType::SPort &port = m_ports.back();

		Json::Value portArrayEl = portArray[i];
		if (!portArrayEl.isMember("min_ship_size")) throw SavedGameCorruptException();
		if (!portArrayEl.isMember("max_ship_size")) throw SavedGameCorruptException();
		if (!portArrayEl.isMember("in_use")) throw SavedGameCorruptException();
		if (!portArrayEl.isMember("bays")) throw SavedGameCorruptException();

		port.minShipSize = portArrayEl["min_ship_size"].asInt();
		port.maxShipSize = portArrayEl["max_ship_size"].asInt();
		port.inUse = portArrayEl["in_use"].asBool();

		Json::Value bayArray = portArrayEl["bays"];
		if (!bayArray.isArray()) throw SavedGameCorruptException();
		port.bayIDs.reserve(bayArray.size());
		for (Uint32 j = 0; j < bayArray.size(); j++)
		{
			Json::Value bayArrayEl = bayArray[j];
			if (!bayArrayEl.isMember("bay_id")) throw SavedGameCorruptException();
			if (!bayArrayEl.isMember("name")) throw SavedGameCorruptException();

			port.bayIDs.push_back(std::make_pair(bayArrayEl["bay_id"].asInt(), bayArrayEl["name"].asString()));
		}
	}

	m_sbody = space->GetSystemBodyByIndex(spaceStationObj["index_for_system_body"].asUInt());

	m_doorAnimationStep = StrToDouble(spaceStationObj["door_animation_step"].asString());
	m_doorAnimationState = StrToDouble(spaceStationObj["door_animation_state"].asString());

	InitStation();

	m_navLights->LoadFromJson(spaceStationObj);
}
コード例 #6
0
ファイル: Ship.cpp プロジェクト: tomm/pioneer
void Ship::LoadFromJson(const Json::Value &jsonObj, Space *space)
{
	DynamicBody::LoadFromJson(jsonObj, space);

	if (!jsonObj.isMember("ship")) throw SavedGameCorruptException();
	Json::Value shipObj = jsonObj["ship"];

	if (!shipObj.isMember("ang_thrusters")) throw SavedGameCorruptException();
	if (!shipObj.isMember("thrusters")) throw SavedGameCorruptException();
	if (!shipObj.isMember("wheel_transition")) throw SavedGameCorruptException();
	if (!shipObj.isMember("wheel_state")) throw SavedGameCorruptException();
	if (!shipObj.isMember("launch_lock_timeout")) throw SavedGameCorruptException();
	if (!shipObj.isMember("test_landed")) throw SavedGameCorruptException();
	if (!shipObj.isMember("flight_state")) throw SavedGameCorruptException();
	if (!shipObj.isMember("alert_state")) throw SavedGameCorruptException();
	if (!shipObj.isMember("last_firing_alert")) throw SavedGameCorruptException();
	if (!shipObj.isMember("hyperspace_destination")) throw SavedGameCorruptException();
	if (!shipObj.isMember("hyperspace_countdown")) throw SavedGameCorruptException();
	if (!shipObj.isMember("guns")) throw SavedGameCorruptException();
	if (!shipObj.isMember("ecm_recharge")) throw SavedGameCorruptException();
	if (!shipObj.isMember("ship_type_id")) throw SavedGameCorruptException();
	if (!shipObj.isMember("docked_with_port")) throw SavedGameCorruptException();
	if (!shipObj.isMember("index_for_body_docked_with")) throw SavedGameCorruptException();
	if (!shipObj.isMember("hull_mass_left")) throw SavedGameCorruptException();
	if (!shipObj.isMember("shield_mass_left")) throw SavedGameCorruptException();
	if (!shipObj.isMember("shield_cooldown")) throw SavedGameCorruptException();
	if (!shipObj.isMember("ai_message")) throw SavedGameCorruptException();
	if (!shipObj.isMember("thruster_fuel")) throw SavedGameCorruptException();
	if (!shipObj.isMember("reserve_fuel")) throw SavedGameCorruptException();
	if (!shipObj.isMember("controller_type")) throw SavedGameCorruptException();
	if (!shipObj.isMember("name")) throw SavedGameCorruptException();

	m_skin.LoadFromJson(shipObj);
	m_skin.Apply(GetModel());
	// needs fixups
	JsonToVector(&m_angThrusters, shipObj, "ang_thrusters");
	JsonToVector(&m_thrusters, shipObj, "thrusters");
	m_wheelTransition = shipObj["wheel_transition"].asInt();
	m_wheelState = StrToFloat(shipObj["wheel_state"].asString());
	m_launchLockTimeout = StrToFloat(shipObj["launch_lock_timeout"].asString());
	m_testLanded = shipObj["test_landed"].asBool();
	m_flightState = static_cast<FlightState>(shipObj["flight_state"].asInt());
	m_alertState = static_cast<AlertState>(shipObj["alert_state"].asInt());
	Properties().Set("flightState", EnumStrings::GetString("ShipFlightState", m_flightState));
	Properties().Set("alertStatus", EnumStrings::GetString("ShipAlertStatus", m_alertState));
	m_lastFiringAlert = StrToDouble(shipObj["last_firing_alert"].asString());

	Json::Value hyperspaceDestObj = shipObj["hyperspace_destination"];
	m_hyperspace.dest = SystemPath::FromJson(hyperspaceDestObj);
	m_hyperspace.countdown = StrToFloat(shipObj["hyperspace_countdown"].asString());
	m_hyperspace.duration = 0;

	Json::Value gunArray = shipObj["guns"];
	if (!gunArray.isArray()) throw SavedGameCorruptException();
	assert(ShipType::GUNMOUNT_MAX == gunArray.size());
	for (unsigned int i = 0; i < ShipType::GUNMOUNT_MAX; i++)
	{
		Json::Value gunArrayEl = gunArray[i];
		if (!gunArrayEl.isMember("state")) throw SavedGameCorruptException();
		if (!gunArrayEl.isMember("recharge")) throw SavedGameCorruptException();
		if (!gunArrayEl.isMember("temperature")) throw SavedGameCorruptException();

		m_gun[i].state = gunArrayEl["state"].asUInt();
		m_gun[i].recharge = StrToFloat(gunArrayEl["recharge"].asString());
		m_gun[i].temperature = StrToFloat(gunArrayEl["temperature"].asString());
	}
	m_ecmRecharge = StrToFloat(shipObj["ecm_recharge"].asString());
	SetShipId(shipObj["ship_type_id"].asString()); // XXX handle missing thirdparty ship
	m_dockedWithPort = shipObj["docked_with_port"].asInt();
	m_dockedWithIndex = shipObj["index_for_body_docked_with"].asUInt();
	Init();
	m_stats.hull_mass_left = StrToFloat(shipObj["hull_mass_left"].asString()); // must be after Init()...
	m_stats.shield_mass_left = StrToFloat(shipObj["shield_mass_left"].asString());
	m_shieldCooldown = StrToFloat(shipObj["shield_cooldown"].asString());
	m_curAICmd = 0;
	m_curAICmd = AICommand::LoadFromJson(shipObj);
	m_aiMessage = AIError(shipObj["ai_message"].asInt());
	SetFuel(StrToDouble(shipObj["thruster_fuel"].asString()));
	m_stats.fuel_tank_mass_left = GetShipType()->fuelTankMass * GetFuel();
	m_reserveFuel = StrToDouble(shipObj["reserve_fuel"].asString());

	PropertyMap &p = Properties();
	p.Set("hullMassLeft", m_stats.hull_mass_left);
	p.Set("hullPercent", 100.0f * (m_stats.hull_mass_left / float(m_type->hullMass)));
	p.Set("shieldMassLeft", m_stats.shield_mass_left);
	p.Set("fuelMassLeft", m_stats.fuel_tank_mass_left);
	p.PushLuaTable();
	lua_State *l = Lua::manager->GetLuaState();
	lua_getfield(l, -1, "equipSet");
	m_equipSet = LuaRef(l, -1);
	lua_pop(l, 2);

	UpdateLuaStats();

	m_controller = 0;
	const ShipController::Type ctype = static_cast<ShipController::Type>(shipObj["controller_type"].asInt());
	if (ctype == ShipController::PLAYER)
		SetController(new PlayerShipController());
	else
		SetController(new ShipController());
	m_controller->LoadFromJson(shipObj);

	m_navLights->LoadFromJson(shipObj);

	m_shipName = shipObj["name"].asString();
	Properties().Set("shipName", m_shipName);
}