#plugin Make Hospitable (Ctrl+H) #author Dan Williamson Monday, April 09, 2007 at 9:35 PM #desc Generate System Contents in a system until there is a Hospitable planet in the system. #menuhotkey Ctrl+H cancelled = False sector = GetCurrentSector() NumberOfAttempts = 0 ScanSystems RefreshScene Sub ScanSystems sector.RenderMessageBig = "Making this system habitable. Hit [ESC] to cancel and [P] to pause processing..." RefreshScene ProcessSystem() If (cancelled) Then Exit Sub sector.UpdateVisibleCount End Sub Sub ProcessSystem() CheckIfCancelled If (cancelled) Then Exit Sub CheckIfPaused aSystem = EditingBody() If not aSystem.Loaded Then sector.DynaLoad aSystem End If ' This flag is set to 1 if the system contains a white dwarf ' It indicates that no planets are to be found in the system. noplanets = 0 ' If the system is of Type Multiple If aSystem.TypeID = BODY_TYPE_MULT Then ' Only create child bodies for each substar individually. ' Check for the presence of a White Dwarf in the system For currentStar = 1 to aSystem.ChildrenCount() thisStar = aSystem.getChild(currentStar-1) If thisStar.TypeID = BODY_TYPE_WHITEDWARF Then noplanets = 1 End If Next ' If there is no White Dwarf, then we can go ahead and generate the system contents for ' each star individually If noplanets = 0 Then For currentStar = 1 to aSystem.ChildrenCount() thisStar = aSystem.getChild(currentStar-1) If thisStar.TypeID = BODY_TYPE_STAR Then RegenerateSystem thisStar End If Next End If End If ' If the system is of Type Star (not White Dwarf), we can go ahead and generate a full system. If aSystem.TypeID = BODY_TYPE_STAR Then RegenerateSystem aSystem End If If (cancelled) Then Exit Sub If (aSystem.ChildrenCount() = 0) Then Exit Sub 'if system is populated, change the label color if aSystem.ChildPopulation > 0 then aSystem.LabelColor = rgb( 128, 255, 0) end if If (cancelled) Then Exit Sub 'do this so that astro can keep track of things like populations & political affiliations more efficiently If (sector.Modified = True) Then aSystem.UpdateRootBody End If End Sub Sub RegenerateSystem( aSystem ) ' save name temp = aSystem.Name habitable = False Do aSystem.ClearFields RandomSystem aSystem, true 'use built-in astro generator, w/ populations. aSystem.Name = temp 'restore name in case it gets cancelled. ' Don't need to remove space stations as they are not considered hospitable. ' Check for habitability If aSystem.GetMaxChildHabitability() > HAB_HABITABLE Then habitable = True End If 'check for a cancel CheckIfCancelled If (cancelled) Then Exit Sub CheckIfPaused Loop While Not (habitable) End Sub Sub CheckIfCancelled If (cancelled = False) Then cancelled = (GetKey() = 27) End If End Sub sub CheckIfPaused If ((GetKey() = 80) Or (GetKey() = 112)) Then sector.RenderMessageBig = "Processing paused. Hit [P] to continue processing." RefreshScene KeyPressed = GetKey() Do While (KeyPressed <> 80) And (KeyPressed <> 112) Pause 500 KeyPressed = GetKey() Loop sector.RenderMessageBig = "Making this system habitable. Hit [ESC] to cancel and [P] to pause processing..." RefreshScene End If End Sub