Jump to content

this is a biggie, Where are the buildings kept in ksp and how can they be edited/replased


Recommended Posts

I experimented with this in 0.90 but had to prioritize my time a bit so nothing ever came of it. It still works in 1.0. I'm just going to barf it up in hopes it'll be useful


[KSPAddon(KSPAddon.Startup.MainMenu, true)]
public class Test_ChangeSpaceCenterBuildingsExternal : MonoBehaviour
{

private void Start()
{
Log.Debug("Testing building external changes");

var facility =
FlightGlobals.Bodies.Where(cb => cb.isHomeWorld)
.SelectMany(cb => cb.gameObject.GetComponentsInChildren<Upgradeables.UpgradeableFacility>(true))
.FirstOrDefault(f => f.id == "SpaceCenter/VehicleAssemblyBuilding");

if (facility.IsNull()) throw new InvalidOperationException("facility");



Log.Normal("UpgradeableFacility:");
facility.gameObject.PrintComponents();


var model = GameDatabase.Instance.databaseModel.Find(
go => go.name == "BuildYourOwnSpaceCenter/structures/TestCube/TestCube");

if (model == null) Log.Error("failed to find model!");
model.AddComponent<TestScale>();
model.AddComponent<CrashObjectName>().objectName = "That ugly box";
model.SetLayerRecursive(15);
model.SetActive(true);


model.transform.parent = facility.GetUpgradeLevels()[0].facilityPrefab.transform;
model.transform.localPosition = Vector3.zero;

DontDestroyOnLoad(model);


var uft = facility.gameObject.AddComponent<UpgradeableFacilityTweakable>();
uft.ImpersonateFacility(facility);
uft.SetPrefab(0, model);

Destroy(facility);
}
}
class UpgradeableFacilityTweakable : UpgradeableFacility
{
public void ImpersonateFacility(UpgradeableFacility target)
{
upgradeLevels = target.GetUpgradeLevels();
facilityTransform = target.GetFacilityTransform();

setup = false;
preCompiledId = true;
id = target.id;
facilityLevel = target.FacilityLevel;

SetupLevels();

for (int i = 0; i < upgradeLevels.Length; ++i)
upgradeLevels[i].levelCost = 1000f * i;

}


public void SetPrefab(int level, GameObject prefab)
{
upgradeLevels[level].facilityPrefab = prefab;
setup = false;
SetupLevels();
}
}

Those are the main pieces. The interiors are simpler (you can just swap the model right out). Not a complete solution (the structure can't be destroyed -- haven't investigated that yet) but should jumpstart anyone willing to make the effort

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...