-
-
Notifications
You must be signed in to change notification settings - Fork 362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CrewContracts - onUpdateBB #5596
base: master
Are you sure you want to change the base?
Changes from 1 commit
8be9f44
a6674bf
c234adc
d847abe
c1300d1
05dd512
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -379,6 +379,24 @@ local isEnabled = function (ref) | |||||
return numCrewmenAvailable > 0 | ||||||
end | ||||||
|
||||||
local newCrew = function() | ||||||
local hopefulCrew = Character.New() | ||||||
-- Roll new stats, with a 1/3 chance that they're utterly inexperienced | ||||||
hopefulCrew:RollNew(Engine.rand:Integer(0, 2) > 0) | ||||||
-- Make them a title if they're good at anything | ||||||
local maxScore = math.max(hopefulCrew.engineering, | ||||||
hopefulCrew.piloting, | ||||||
hopefulCrew.navigation, | ||||||
hopefulCrew.sensors) | ||||||
if maxScore > 45 then | ||||||
if hopefulCrew.engineering == maxScore then hopefulCrew.title = lui.SHIPS_ENGINEER end | ||||||
if hopefulCrew.piloting == maxScore then hopefulCrew.title = lui.PILOT end | ||||||
if hopefulCrew.navigation == maxScore then hopefulCrew.title = lui.NAVIGATOR end | ||||||
if hopefulCrew.sensors == maxScore then hopefulCrew.title = lui.SENSORS_AND_DEFENCE end | ||||||
end | ||||||
return hopefulCrew | ||||||
end | ||||||
|
||||||
local onCreateBB = function (station) | ||||||
-- Create non-persistent Characters as available crew | ||||||
nonPersistentCharactersForCrew[station] = {} | ||||||
|
@@ -393,26 +411,38 @@ local onCreateBB = function (station) | |||||
|
||||||
-- Number is based on population, nicked from Assassinations.lua and tweaked | ||||||
for i = 1, Engine.rand:Integer(0, math.ceil(Game.system.population) * 2 + 1) do | ||||||
local hopefulCrew = Character.New() | ||||||
-- Roll new stats, with a 1/3 chance that they're utterly inexperienced | ||||||
hopefulCrew:RollNew(Engine.rand:Integer(0, 2) > 0) | ||||||
-- Make them a title if they're good at anything | ||||||
local maxScore = math.max(hopefulCrew.engineering, | ||||||
hopefulCrew.piloting, | ||||||
hopefulCrew.navigation, | ||||||
hopefulCrew.sensors) | ||||||
if maxScore > 45 then | ||||||
if hopefulCrew.engineering == maxScore then hopefulCrew.title = lui.SHIPS_ENGINEER end | ||||||
if hopefulCrew.piloting == maxScore then hopefulCrew.title = lui.PILOT end | ||||||
if hopefulCrew.navigation == maxScore then hopefulCrew.title = lui.NAVIGATOR end | ||||||
if hopefulCrew.sensors == maxScore then hopefulCrew.title = lui.SENSORS_AND_DEFENCE end | ||||||
end | ||||||
table.insert(nonPersistentCharactersForCrew[station],hopefulCrew) | ||||||
table.insert(nonPersistentCharactersForCrew[station],newCrew()) | ||||||
end | ||||||
end | ||||||
|
||||||
Event.Register("onCreateBB", onCreateBB) | ||||||
|
||||||
local onUpdateBB = function (station) | ||||||
-- If no crew available (ad is greyed out), reseed the table after a while | ||||||
if #nonPersistentCharactersForCrew[station] < 1 and Engine.rand:Integer(0, 10) == 0 then -- Not much crew around | ||||||
table.insert(nonPersistentCharactersForCrew[station],newCrew()) | ||||||
print("Reseeding crew candidates") | ||||||
else | ||||||
-- 1 in 30 to be removed and then maybe someone new inserted | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you mean 1 in 101? or I do not understand correctly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, old comment, numbers have changed. |
||||||
for k,v in pairs(nonPersistentCharactersForCrew[station]) do | ||||||
if #nonPersistentCharactersForCrew[station] > 0 then | ||||||
if Engine.rand:Integer(0, 100) == 0 then | ||||||
table.remove(nonPersistentCharactersForCrew[station],k) | ||||||
print("Removing crew candidate. #nonPersistentCharactersForCrew: " .. #nonPersistentCharactersForCrew[station]) | ||||||
end | ||||||
end | ||||||
end | ||||||
for k,v in pairs(nonPersistentCharactersForCrew[station]) do | ||||||
if #nonPersistentCharactersForCrew[station] < math.ceil(Game.system.population) * 2 + 1 then | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it would be nice to see an explanation of this criterion, looks like something empirical? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's from this equation a bit higher up on the page. pioneer/data/modules/CrewContracts/CrewContracts.lua Lines 394 to 395 in 0f417f2
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, maybe then we should put it in a small separate function, with a descriptive name? |
||||||
if Engine.rand:Integer(0, 100) == 0 then | ||||||
table.insert(nonPersistentCharactersForCrew[station],k,newCrew()) | ||||||
print("Adding crew candidate. #nonPersistentCharactersForCrew: " .. #nonPersistentCharactersForCrew[station]) | ||||||
end | ||||||
end | ||||||
end | ||||||
end | ||||||
end | ||||||
Event.Register("onUpdateBB", onUpdateBB) | ||||||
|
||||||
-- Wipe temporary crew out when hyperspacing | ||||||
Event.Register("onEnterSystem", function(ship) | ||||||
if ship:IsPlayer() then | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
10 times out of 11 this branch will fire, even if the array is empty, although now it will not cause an effect, it looks suspicious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there are no applicants, array is empty AND a random number equates to 0.
That's one in 11, not 10 times out of 11. The function reseeds the table when it goes to zero and let's it stay at zero for a randomly determined time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was talking about the "else" branch, yes, I said incorrectly, if the array is empty, the else branch will fire 10 times out of 11.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I go it. Yes, that looks a bit wonky.