Skip to content
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

The future belongs to COINS! #5050

Merged
merged 3 commits into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions data/libs/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,15 @@ utils.reverse = function(t)
end
return res
end

--
-- round: Round x to closest multiple of N, but never lower than N
--
-- value = round(unsorted_table, 25)
--
utils.round = function(x, n)
local step = n or 1
x = math.round(x/n)*n
return x < n and n or x
end
return utils
2 changes: 1 addition & 1 deletion data/modules/Assassination/Assassination.lua
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ local makeAdvert = function (station)
local due = Game.time + dist / max_ass_dist * time * 22*60*60*24 + Engine.rand:Number(7*60*60*24, 31*60*60*24)
local danger = Engine.rand:Integer(1,4)
local reward = Engine.rand:Number(2100, 7000) * danger
reward = math.ceil(reward)
reward = utils.round(reward, 500)

-- XXX hull mass is a bad way to determine suitability for role
--local shipdefs = utils.build_array(utils.filter(function (k,def) return def.tag == 'SHIP' and def.hullMass >= (danger * 17) and def.equipSlotCapacity.ATMOSHIELD > 0 end, pairs(ShipDef)))
Expand Down
3 changes: 2 additions & 1 deletion data/modules/BreakdownServicing/BreakdownServicing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ local Format = require 'Format'
local Serializer = require 'Serializer'
local Equipment = require 'Equipment'
local Character = require 'Character'
local utils = require 'utils'

local l = Lang.GetResource("module-breakdownservicing")
local lui = Lang.GetResource("ui-core")
Expand Down Expand Up @@ -107,7 +108,7 @@ local onChat = function (form, ref, option)
})[hyperdrive.l10n_key] or 10)) or 0

-- Now make it bigger (-:
price = price * 10
price = utils.round(price * 10, 5)

-- Replace those tokens into ad's intro text that can change during play
local pricesuggestion = string.interp(ad.price, {
Expand Down
2 changes: 1 addition & 1 deletion data/modules/CargoRun/CargoRun.lua
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ local makeAdvert = function (station)
due = due + Game.time
end
end
reward = math.ceil(reward)
reward = utils.round(reward, 25)

local n = getNumberOfFlavours("INTROTEXT_" .. missiontype)
local introtext
Expand Down
1 change: 1 addition & 0 deletions data/modules/Combat/Combat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ local makeAdvert = function (station)
location = flavour.planets[Engine.rand:Integer(1, #flavour.planets)]
dist = location:DistanceTo(Game.system)
reward = math.ceil(dist * typical_reward * (1 + dedication)^2 * (1 + risk) * (1 + urgency) * Engine.rand:Number(0.8, 1.2))
reward = utils.round(reward, 100)
due = Game.time + typical_travel_time * Engine.rand:Number(0.9, 1.1) + dist * typical_hyperspace_time * (1.5 - urgency) * Engine.rand:Number(0.9, 1.1)

if Engine.rand:Number(1) > 0.5 then
Expand Down
3 changes: 3 additions & 0 deletions data/modules/CrewContracts/CrewContracts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ local Game = require 'Game'
local Character = require 'Character'
local Format = require 'Format'
local Timer = require 'Timer'
local utils = require 'utils'

-- This module allows the player to hire crew members through BB adverts
-- on stations, and handles periodic events such as their wages.
Expand Down Expand Up @@ -180,6 +181,7 @@ local onChat = function (form,ref,option)
+c.sensors
-- Base wage on experience
c.estimatedWage = c.estimatedWage or wageFromScore(c.experience)
c.estimatedWage = utils.round(c.estimatedWage, 1)
end

-- Now look for any persistent characters that are available in this station
Expand All @@ -205,6 +207,7 @@ local onChat = function (form,ref,option)
-- Either base wage on experience, or as a slight increase on their previous wage
-- (which should only happen if this candidate was dismissed with wages owing)
c.estimatedWage = math.max(c.contract and (c.contract.wage + 5) or 0, c.estimatedWage or wageFromScore(c.experience))
c.estimatedWage = utils.round(c.estimatedWage, 1)
end

form:ClearFace()
Expand Down
2 changes: 1 addition & 1 deletion data/modules/DeliverPackage/DeliverPackage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ local makeAdvert = function (station, manualFlavour, nearbystations)
reward = ((dist / max_delivery_dist) * typical_reward * (1+risk) * (1.5+urgency) * Engine.rand:Number(0.8,1.2))
due = Game.time + ((dist / max_delivery_dist) * typical_travel_time * (1.5-urgency) * Engine.rand:Number(0.9,1.1))
end
reward = math.ceil(reward)
reward = utils.round(reward, 5)

local ad = {
station = station,
Expand Down
5 changes: 5 additions & 0 deletions data/modules/DonateToCranks/DonateToCranks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ end
local onCreateBB = function (station)
local n = Engine.rand:Integer(1, #flavours)

-- FOSS is rare, (kind of an easter egg), skip advert
if n == 6 and Engine.rand:Integer(0, 5) > 1 then
return
end

local ad = {
modifier = n == 6 and 1.5 or 1.0, -- donating to FOSS is twice as good
title = flavours[n].title,
Expand Down
1 change: 1 addition & 0 deletions data/modules/SearchRescue/SearchRescue.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,7 @@ local makeAdvert = function (station, manualFlavour, closestplanets)

-- calculate the reward
local reward = calcReward(flavour, pickup_crew, pickup_pass, pickup_comm, deliver_crew, deliver_pass, deliver_comm)
reward = utils.round(reward, 100)

local ad = {
location = location,
Expand Down
3 changes: 2 additions & 1 deletion data/modules/SecondHand/SecondHand.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ local Format = require 'Format'
local Serializer = require 'Serializer'
local Equipment = require 'Equipment'
local Character = require 'Character'
local utils = require 'utils'

local l = Lang.GetResource("module-secondhand")
local l2 = Lang.GetResource("ui-core")
Expand Down Expand Up @@ -135,7 +136,7 @@ local makeAdvert = function (station)
-- buy back price in equipment market is 0.8, so make sure the value is higher
local reduction = Engine.rand:Number(0.8,0.9)

local price = math.ceil(station:GetEquipmentPrice(equipment) * reduction)
local price = utils.round(station:GetEquipmentPrice(equipment) * reduction, 2)

local ad = {
character = character,
Expand Down
2 changes: 1 addition & 1 deletion data/modules/Taxi/Taxi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ local makeAdvert = function (station)
location = nearbysystems[Engine.rand:Integer(1,#nearbysystems)]
local dist = location:DistanceTo(Game.system)
reward = ((dist / max_taxi_dist) * typical_reward * (group / 2) * (1+risk) * (1+3*urgency) * Engine.rand:Number(0.8,1.2))
reward = math.ceil(reward)
reward = utils.round(reward, 50)
due = Game.time + ((dist / max_taxi_dist) * typical_travel_time * (1.5-urgency) * Engine.rand:Number(0.9,1.1))

local ad = {
Expand Down