Skip to content

Commit

Permalink
News Event: don't accumulate price/stock/demand on each visit
Browse files Browse the repository at this point in the history
  • Loading branch information
impaktor committed Jul 9, 2024
1 parent 1a25b04 commit 92f954d
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions data/modules/NewsEventCommodity/NewsEventCommodity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ end
local Comms = require 'Comms'
local debugView = require 'pigui.views.debug'
local ui = require 'pigui'
local Economy = require 'Economy'
local Engine = require 'Engine'
local Lang = require 'Lang'
local Game = require 'Game'
Expand Down Expand Up @@ -351,26 +352,23 @@ local onShipDocked = function (ship, station)
Comms.Message(greeting)
end

local price = station:GetCommodityPrice(cargo_item)
local stock = station:GetCommodityStock(cargo_item)
local demand = station:GetCommodityDemand(cargo_item)
local price = Economy.GetMarketPrice(cargo_item.price, 0)
local targetStock, targetDemand = Economy.GetStationFlowParams(station, cargo_item)
local stock, demand = Economy.GetCommodityStockFromFlow(cargo_item, targetStock, targetDemand)

-- How close to finish? number between [0, 1]
-- How close to finish? 1.0 at start -> 0 at end of event
local progress = (n.expires - Game.time) / (n.expires - n.date)
print("progress", progress)

local newPrice, newStock, newDemand
if n.multiplier > 0 then
newPrice = n.multiplier * price -- increase price
newStock = 0 -- remove all stock

newDemand = demand * (1 + progress*n.multiplier)

newPrice = n.multiplier * price -- increase price
newStock = 0 -- remove all stock
newDemand = demand * (1 + progress*n.multiplier) -- demand
elseif n.multiplier < 0 then
newPrice = math.ceil(price / (1 + math.abs(n.multiplier))) -- dump price
newStock = math.ceil(math.abs(n.multiplier * stock)) -- spam stock
newDemand = 0 -- station does not buy it
else
error("multiplier should probably not be 0.")
newStock = math.ceil(math.abs(n.multiplier * stock)) -- spam stock
newDemand = 0 -- station does not buy it
end
-- print("--- NewsEvent: cargo:", cargo_item:GetName(), "price:", newPrice, "stock:", newStock)
station:SetCommodityPrice(cargo_item, newPrice)
Expand Down

0 comments on commit 92f954d

Please sign in to comment.