Skip to content

Commit c3aaaf8

Browse files
authored
fix: increase TradeBehavior::BUY_THRESHOLD (#549)
1 parent 721f629 commit c3aaaf8

9 files changed

Lines changed: 54 additions & 47 deletions

File tree

Cargo.lock

Lines changed: 32 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ members = [
2323

2424
[workspace.package]
2525
description = "Multiplayer strategy game"
26-
version = "0.7.16"
26+
version = "0.7.17"
2727
edition = "2024"
2828
rust-version = "1.99"
2929
license = "AGPL-3.0-only"

app/src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://schema.tauri.app/config/2.0.0",
33
"productName": "Call of Nil",
4-
"version": "0.7.16",
4+
"version": "0.7.17",
55
"identifier": "tsukilabs.nil",
66
"build": {
77
"beforeDevCommand": "pnpm run -F app dev",

crates/nil-core/src/behavior/impl/trade.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub struct TradeBehavior {
2424
}
2525

2626
impl TradeBehavior {
27-
pub const BUY_THRESHOLD: f64 = 0.1;
27+
pub const BUY_THRESHOLD: f64 = 0.3;
2828
pub const SELL_THRESHOLD: f64 = 0.9;
2929
}
3030

@@ -84,19 +84,26 @@ impl Behavior for TradeBehavior {
8484

8585
let in_vault = vault.get(id).as_u32();
8686

87-
if in_vault > 0 && gold > 0 && amount < capacity * Self::BUY_THRESHOLD {
87+
if in_vault > 0 && gold > 0 && amount < (capacity * Self::BUY_THRESHOLD) {
8888
match id {
8989
ResourceId::Food => push!(BuyResourcesBehavior, Food),
9090
ResourceId::Iron => push!(BuyResourcesBehavior, Iron),
9191
ResourceId::Stone => push!(BuyResourcesBehavior, Stone),
9292
ResourceId::Wood => push!(BuyResourcesBehavior, Wood),
9393
}
94-
} else if amount > capacity * Self::SELL_THRESHOLD {
95-
match id {
96-
ResourceId::Food => push!(SellResourcesBehavior, Food),
97-
ResourceId::Iron => push!(SellResourcesBehavior, Iron),
98-
ResourceId::Stone => push!(SellResourcesBehavior, Stone),
99-
ResourceId::Wood => push!(SellResourcesBehavior, Wood),
94+
} else {
95+
let threshold = capacity * Self::SELL_THRESHOLD;
96+
let surplus = (amount - threshold).floor().max(0.0) as u32;
97+
if surplus > 0
98+
&& in_vault.saturating_add(surplus) < u32::MAX
99+
&& gold.saturating_add(surplus) < u32::MAX
100+
{
101+
match id {
102+
ResourceId::Food => push!(SellResourcesBehavior, Food),
103+
ResourceId::Iron => push!(SellResourcesBehavior, Iron),
104+
ResourceId::Stone => push!(SellResourcesBehavior, Stone),
105+
ResourceId::Wood => push!(SellResourcesBehavior, Wood),
106+
}
100107
}
101108
}
102109
}

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "docs",
3-
"version": "0.7.16",
3+
"version": "0.7.17",
44
"type": "module",
55
"packageManager": "pnpm@11.20.0",
66
"license": "AGPL-3.0-only",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nil",
3-
"version": "0.7.16",
3+
"version": "0.7.17",
44
"type": "module",
55
"packageManager": "pnpm@11.20.0",
66
"license": "AGPL-3.0-only",

packages/bindings/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tsukilabs/nil-bindings",
3-
"version": "0.7.16",
3+
"version": "0.7.17",
44
"description": "TypeScript bindings for Call of Nil",
55
"type": "module",
66
"packageManager": "pnpm@11.20.0",

packages/ffi/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tsukilabs/nil-ffi",
3-
"version": "0.7.16",
3+
"version": "0.7.17",
44
"description": "FFI bindings for Call of Nil",
55
"type": "module",
66
"packageManager": "pnpm@11.20.0",

packages/i18n/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tsukilabs/nil-i18n",
3-
"version": "0.7.16",
3+
"version": "0.7.17",
44
"description": "Internationalization support for Call of Nil",
55
"type": "module",
66
"packageManager": "pnpm@11.20.0",

0 commit comments

Comments
 (0)