Skip to content

Commit

Permalink
Versions 1.1.8
Browse files Browse the repository at this point in the history
-Added new AV called WSFW_PowerRequired, this is a resource type so it will be auto-applied to the workbench. This will allow mods to call GetBaseValue(WSFW_PowerRequired) to determine the total power needs in a settlement.
-Fixed a bug where removed workshop objects would not have their stats updated correctly in the pipboy until after you returned to the settlement.
-Improved detection of settlement enter/exit to help the PlayerEnteredSettlement and PlayerExitedSettlement events fire more accurately.
  • Loading branch information
kinggath committed Aug 23, 2019
1 parent 77895aa commit b4ee176
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 28 deletions.
15 changes: 11 additions & 4 deletions Scripts/Source/User/WorkshopFramework/MainQuest.psc
Expand Up @@ -79,7 +79,11 @@ Event OnTimer(Int aiTimerID)
Location kPreviousLoc = PreviousLocation.GetLocation()
Location kNewLoc = LatestLocation.GetLocation()
Bool bEnteringWorkshopLocation = kNewLoc.HasKeyword(LocationTypeWorkshop)
Bool bLeavingWorkshopLocation = kPreviousLoc.HasKeyword(LocationTypeWorkshop)
Bool bLeavingWorkshopLocation = None

if(kPreviousLoc != None)
kPreviousLoc.HasKeyword(LocationTypeWorkshop)
endif

if(bEnteringWorkshopLocation || bLeavingWorkshopLocation)
Var[] kArgs
Expand All @@ -90,7 +94,7 @@ Event OnTimer(Int aiTimerID)
; Check if player is in a different workshop - it can sometimes take a moment before WorkshopParent updates the CurrentWorkshop
currentWorkshop = WorkshopFramework:WSFW_API.GetNearestWorkshop(PlayerRef)

if(bLeavingWorkshopLocation && currentWorkshop && ! PlayerRef.IsWithinBuildableArea(currentWorkshop))
if(bLeavingWorkshopLocation && ! bEnteringWorkshopLocation && currentWorkshop && ! PlayerRef.IsWithinBuildableArea(currentWorkshop))
currentWorkshop = None
endif
endif
Expand Down Expand Up @@ -152,7 +156,7 @@ EndEvent


Event OnMenuOpenCloseEvent(string asMenuName, bool abOpening)
if(asMenuName== "WorkshopMenu")
if(asMenuName == "WorkshopMenu")
if(abOpening)
WorkshopScript currentWorkshop = WorkshopParent.CurrentWorkshop.GetRef() as WorkshopScript
WorkshopScript lastWorkshop = LastWorkshopAlias.GetRef() as WorkshopScript
Expand Down Expand Up @@ -241,7 +245,10 @@ Function HandleLocationChange(Location akNewLoc)
Location lastParentLocation = LatestLocation.GetLocation()

if( ! akNewLoc.IsSameLocation(lastParentLocation) || ! akNewLoc.IsSameLocation(lastParentLocation, LocationTypeSettlement))
PreviousLocation.ForceLocationTo(lastParentLocation) ; 1.1.7
if(lastParentLocation != None)
PreviousLocation.ForceLocationTo(lastParentLocation) ; 1.1.7
endif

LatestLocation.ForceLocationTo(akNewLoc)
StartTimer(1.0, LocationChangeTimerID)
endif
Expand Down
30 changes: 22 additions & 8 deletions Scripts/Source/User/WorkshopFramework/WorkshopResourceManager.psc
Expand Up @@ -478,6 +478,18 @@ EndFunction
Function HandleInstallModChanges()
SetupAllWorkshopProperties() ; 1.0.8 - Confirm any new properties are configured each patch

if(iInstalledVersion < 22) ; 1.1.8 - Update vars for new WSFW_PowerRequired feature
int i = 0
WorkshopScript[] WorkshopsArray = WorkshopParent.Workshops

while(i < WorkshopsArray.Length)
WorkshopScript thisWorkshop = WorkshopsArray[i]
thisWorkshop.FillWSFWVars()

i += 1
endWhile
endif

if(iInstalledVersion < 21) ; 1.1.7 - Update vars for new WSFW_Safety fix
int i = 0
WorkshopScript[] WorkshopsArray = WorkshopParent.Workshops
Expand Down Expand Up @@ -763,17 +775,19 @@ Function ApplyObjectSettlementResources(ObjectReference akObjectRef, WorkshopScr
WorkshopObjectScript asWorkshopObject = akObjectRef as WorkshopObjectScript

Bool bCountResources = true
if(asWorkshopObject)
; For assignable objects, confirm they have a worker
if(asWorkshopObject.RequiresActor() && ! asWorkshopObject.IsActorAssigned())
if( ! abRemoved)
if(asWorkshopObject)
; For assignable objects, confirm they have a worker
if(asWorkshopObject.RequiresActor() && ! asWorkshopObject.IsActorAssigned())
bCountResources = false
endif
endif

if(bCountResources && akObjectRef.HasKeyword(WorkshopCanBePowered) && ! akObjectRef.IsPowered())
; For powered objects, confirm they have power
bCountResources = false
endif
endif

if(bCountResources && akObjectRef.HasKeyword(WorkshopCanBePowered) && ! akObjectRef.IsPowered())
; For powered objects, confirm they have power
bCountResources = false
endif

int i = 0
if(bCountResources)
Expand Down
1 change: 0 additions & 1 deletion Scripts/Source/User/WorkshopObjectScript.psc
Expand Up @@ -118,7 +118,6 @@ bool Property bRadioOn = true auto hidden ; for now only used on temp radio obj
; WSFW New Editor Properties
;


Group WSFWSettings
Keyword Property WorkshopContainerType Auto Const
{ [Optional] If set, this will be linked to the workshop as a special sub-container for redirecting certain resources. See documentation for valid keywords. }
Expand Down
13 changes: 6 additions & 7 deletions Scripts/Source/User/WorkshopParentScript.psc
Expand Up @@ -2105,7 +2105,6 @@ function AssignActorToObjectV2(WorkshopNPCScript assignedActor, WorkshopObjectSc
function.
;-----------------------------------------------------------------------------------------------------------------------------------------
/;

wsTrace(" AssignActorToObject: actor = " + assignedActor + ", object = " + assignedObject + ", resetMode = " + bResetMode)

int workshopID = assignedObject.workshopID
Expand Down Expand Up @@ -2196,7 +2195,6 @@ function AssignActorToObjectV2(WorkshopNPCScript assignedActor, WorkshopObjectSc
endif

elseif assignedObject.HasKeyword (WorkshopWorkObject)

assignedActor.bNewSettler = false

bool bShouldUnassignAllObjects = true
Expand All @@ -2211,7 +2209,7 @@ function AssignActorToObjectV2(WorkshopNPCScript assignedActor, WorkshopObjectSc

;UFO4P 2.0.4 Bug #24311: Multi-resource objects need to be handled separately, even if already assigned: this is to retro-
;actively correct a bug in the vanilla code that could lead to more objects being assigned to an actor than allowed.
if multiResourceValue
if(multiResourceValue)
if assignedObject.HasResourceValue (multiResourceValue)
wsTrace(" Actor already assigned to this resource type")
int resourceIndex = GetResourceIndex (multiResourceValue)
Expand Down Expand Up @@ -2268,9 +2266,10 @@ function AssignActorToObjectV2(WorkshopNPCScript assignedActor, WorkshopObjectSc
UnassignActorFromObjectV2(assignedActor, assignedObject, bResetMode)
bShouldTryToAssignResources = true
endif
;Skip this if the actor doesn't owns anything else than a bed. Now that we have all data we need in handy arrays,
;the IsObjectOwner check is very fast as it won't have to loop through the actor's work objects.
elseif bShouldUnassignAllObjects && IsObjectOwner (workshopRef, assignedActor)

;Skip this if the actor doesn't own anything else than a bed. Now that we have all data we need in handy arrays,
;the IsObjectOwner check is very fast as it won't have to loop through the actor's work objects.
elseif(bShouldUnassignAllObjects && IsObjectOwner(workshopRef, assignedActor))
wsTrace(" Unassigning " + assignedActor + " from previous work object(s)")
;/
; WSFW - Calling our own version of this function. We don't want to change the original function
Expand All @@ -2282,7 +2281,7 @@ function AssignActorToObjectV2(WorkshopNPCScript assignedActor, WorkshopObjectSc
endif

; unassign current owner, if any (and different from new owner)
if previousOwner && previousOwner != assignedActor
if(previousOwner && previousOwner != assignedActor)
wsTrace(" Unassigning previous owner " + previousOwner + " from object " + assignedObject)
; WSFW - This we have to allow because the game engine doesn't support multiple ref owners
;UFO4P 2.0.6 Bug #25439: added a value for the new bool argument bSRsetMode:
Expand Down
56 changes: 48 additions & 8 deletions Scripts/Source/User/WorkshopScript.psc
Expand Up @@ -256,6 +256,7 @@ Group WSFW_AVs

ActorValue Property WSFW_AV_RobotHappinessLevel Auto Hidden
ActorValue Property WSFW_Safety Auto Hidden ; 1.1.7
ActorValue Property WSFW_PowerRequired Auto Hidden ; WSFW 1.1.8
; Replacing calls to WorkshopParent ratings vars
ActorValue Property Happiness Auto Hidden
ActorValue Property BonusHappiness Auto Hidden
Expand All @@ -268,6 +269,7 @@ Group WSFW_AVs
ActorValue Property FoodActual Auto Hidden
ActorValue Property MissingFood Auto Hidden
ActorValue Property Power Auto Hidden
ActorValue Property PowerRequired Auto Hidden ; WSFW 1.1.8
ActorValue Property Water Auto Hidden
ActorValue Property MissingWater Auto Hidden
ActorValue Property Safety Auto Hidden
Expand All @@ -294,6 +296,7 @@ Group WSFW_Added
Keyword Property ObjectTypeWater Auto Hidden
Keyword Property ObjectTypeFood Auto Hidden
Keyword Property WorkshopLinkContainer Auto Hidden
Keyword Property WorkshopCanBePowered Auto Hidden ; WSFW 1.1.8
Faction Property FarmDiscountFaction Auto Hidden
Faction Property PlayerFaction Auto Hidden
{ 1.1.0 }
Expand Down Expand Up @@ -409,6 +412,7 @@ int iFormID_AV_maxAttackStrength = 0x000091DF Const
int iFormID_AV_maxDefenseStrength = 0x000091E1 Const
int iFormID_AV_RobotHappinessLevel = 0x000035D9 Const
int iFormID_WSFW_Safety = 0x0000A9C2 Const
int iFormID_WSFW_PowerRequired = 0x0000B15D Const

; Fallout4.esm
int iFormID_CurrentWorkshopID = 0x0003E0CE Const
Expand All @@ -423,6 +427,7 @@ int iFormID_DamageFood = 0x00127230 Const
int iFormID_FoodActual = 0x00127236 Const
int iFormID_MissingFood = 0x0012723C Const
int iFormID_Power = 0x0000032E Const
int iFormID_PowerRequired = 0x00000330 Const
int iFormID_Water = 0x00000332 Const
int iFormID_MissingWater = 0x0012723D Const
int iFormID_Safety = 0x00000333 Const
Expand All @@ -446,6 +451,7 @@ int iFormID_WorkshopCaravanKeyword = 0x00061C0C Const
int iFormID_ObjectTypeWater = 0x000F4AED Const
int iFormID_ObjectTypeFood = 0x00055ECC Const
int iFormID_WorkshopLinkContainer = 0x0002682F Const
int iFormID_WorkshopCanBePowered = 0X0003037E Const
int iFormID_FarmDiscountFaction = 0x0019FFC4 Const
int iFormID_PlayerFaction = 0x0001C21C Const ; 1.1.0

Expand Down Expand Up @@ -2791,18 +2797,38 @@ bool function RecalculateWorkshopResources(bool bOnlyIfLocationLoaded = true)
RecalculateResources()

; WSFW - 1.1.7 | Unowned workshops do not appear to correctly calculate Safety objects - this is a problem for Nukaworld Vassal settlements
ObjectReference[] SafetyObjects = GetWorkshopResourceObjects(Safety)
Float fSafetyValue = 0.0
if( ! OwnedByPlayer)
ObjectReference[] SafetyObjects = GetWorkshopResourceObjects(Safety)
Float fSafetyValue = 0.0

int i = 0
while(i < SafetyObjects.Length)
if( ! SafetyObjects[i].IsDisabled())
Float fValue = SafetyObjects[i].GetValue(Safety)
fSafetyValue += fValue
endif

i += 1
endWhile

SetValue(WSFW_Safety, fSafetyValue)
endif

; WSFW 1.1.8 - Add up PowerRequired and store on workshop
ObjectReference[] PowerReqObjects = FindAllReferencesWithKeyword(WorkshopCanBePowered, 20000.0)
Float fPowerRequired = 0.0
Keyword WorkshopItemKeyword = WorkshopParent.WorkshopItemKeyword
int i = 0
while(i < SafetyObjects.Length)
Float fValue = SafetyObjects[i].GetValue(Safety)
fSafetyValue += fValue
while(i < PowerReqObjects.Length)
if( ! PowerReqObjects[i].IsDisabled() && PowerReqObjects[i].GetLinkedRef(WorkshopItemKeyword) == Self)
Float fValue = PowerReqObjects[i].GetValue(PowerRequired)
fPowerRequired += fValue
endif

i += 1
endWhile

SetValue(WSFW_Safety, fSafetyValue)
SetValue(WSFW_PowerRequired, fPowerRequired)

return true
else
Expand Down Expand Up @@ -3280,6 +3306,10 @@ Function FillWSFWVars()
WSFW_Safety = Game.GetFormFromFile(iFormID_WSFW_Safety, sWSFW_Plugin) as ActorValue
endif

if( ! WSFW_PowerRequired)
WSFW_PowerRequired = Game.GetFormFromFile(iFormID_WSFW_PowerRequired, sWSFW_Plugin) as ActorValue
endif

;
; Fallout4.esm
;
Expand Down Expand Up @@ -3330,6 +3360,10 @@ Function FillWSFWVars()
if( ! Power)
Power = Game.GetFormFromFile(iFormID_Power, sFO4_Plugin) as ActorValue
endif

if( ! PowerRequired)
PowerRequired = Game.GetFormFromFile(iFormID_PowerRequired, sFO4_Plugin) as ActorValue
endif

if( ! Water)
Water = Game.GetFormFromFile(iFormID_Water, sFO4_Plugin) as ActorValue
Expand Down Expand Up @@ -3422,6 +3456,10 @@ Function FillWSFWVars()
if( ! WorkshopLinkContainer)
WorkshopLinkContainer = Game.GetFormFromFile(iFormID_WorkshopLinkContainer, sFO4_Plugin) as Keyword
endif

if( ! WorkshopCanBePowered)
WorkshopCanBePowered = Game.GetFormFromFile(iFormID_WorkshopCanBePowered, sFO4_Plugin) as Keyword
endif

if( ! FarmDiscountFaction)
FarmDiscountFaction = Game.GetFormFromFile(iFormID_FarmDiscountFaction, sFO4_Plugin) as Faction
Expand Down Expand Up @@ -3487,8 +3525,10 @@ Function RestoreValue(ActorValue akAV, float afAmount)
Parent.RestoreValue(akAV, afAmount)

; Also mod WSFW safety
if(akAV == Safety && WSFW_Safety != None)
Parent.RestoreValue(WSFW_Safety, afAmount)
if(akAV == Safety)
if(WSFW_Safety != None)
Parent.RestoreValue(WSFW_Safety, afAmount)
endif
endif
EndFunction

Expand Down
Binary file modified WorkshopFramework - Main.ba2
Binary file not shown.
Binary file modified WorkshopFramework.esm
Binary file not shown.

0 comments on commit b4ee176

Please sign in to comment.