Rebalanced economy somewhat

This commit is contained in:
Joshua Barretto 2021-04-18 14:08:48 +01:00
parent 1892ec571d
commit b72e454148
6 changed files with 54 additions and 33 deletions

View File

@ -22,24 +22,24 @@ loot_tables: [
(2.0, "common.loot_tables.armor.twigsleaves"),
(0.5, "common.loot_tables.armor.plate"),
(0.25, "common.loot_tables.armor.steel"),
(0.125, "common.loot_tables.armor.cultist"),
(0.075, "common.loot_tables.armor.cultist"),
// Materials
(7.5, "common.loot_tables.materials.common"),
(5.0, "common.loot_tables.materials.underground"),
// Food
(0.5, "common.loot_tables.food.farm_ingredients"),
(0.25, "common.loot_tables.food.wild_ingredients"),
(0.1, "common.loot_tables.food.prepared"),
(0.5, "common.loot_tables.food.wild_ingredients"),
(0.2, "common.loot_tables.food.prepared"),
// TODO: Change consumables when they are split up later
(1.0, "common.loot_tables.consumables"),
],
],
// this is the amount of that good the most common item represents
// so basically this table balances the goods against each other (higher=less valuable)
good_scaling: [
(Potions, 0.001), // common.items.consumable.potion_minor
(Potions, 0.025), // common.items.consumable.potion_minor
(Food, 2.0), // common.items.food.mushroom
(Coin, 10.0), // common.items.utility.coins
(Armor, 0.2), // common.items.armor.misc.pants.worker_blue
(Tools, 0.1), // common.items.weapons.staff.starter_staff
(Ingredients, 1.0), // common.items.crafting_ing.leather_scraps
(Coin, 25.0), // common.items.utility.coins
(Armor, 0.1), // common.items.armor.misc.pants.worker_blue
(Tools, 0.15), // common.items.weapons.staff.starter_staff
(Ingredients, 0.25), // common.items.crafting_ing.leather_scraps
])

View File

@ -1,7 +1,6 @@
[
(1.0, Item("common.items.food.apple")),
(1.0, Item("common.items.food.carrot")),
(1.0, Item("common.items.food.cheese")),
(1.0, Item("common.items.food.lettuce")),
(1.0, Item("common.items.food.tomato")),
]
]

View File

@ -1,9 +1,9 @@
[
(0.2, Item("common.items.food.apple_mushroom_curry")),
(0.4, Item("common.items.food.apple_mushroom_curry")),
(1.0, Item("common.items.food.apple_stick")),
(2.0, Item("common.items.food.cheese")),
(1.0, Item("common.items.food.mushroom_stick")),
(1.0, Item("common.items.food.plainsalad")),
(1.0, Item("common.items.food.sunflower_icetea")),
(1.0, Item("common.items.food.cheese")),
(1.1, Item("common.items.food.mushroom_stick")),
(1.2, Item("common.items.food.plainsalad")),
(0.5, Item("common.items.food.sunflower_icetea")),
(1.0, Item("common.items.food.tomatosalad")),
]
]

View File

@ -1,6 +1,6 @@
[
(1.0, Item("common.items.food.apple")),
(1.0, Item("common.items.food.cheese")),
(0.3, Item("common.items.food.cheese")),
(1.0, Item("common.items.food.coconut")),
(1.0, Item("common.items.food.mushroom")),
]
(1.5, Item("common.items.food.mushroom")),
]

View File

@ -1095,8 +1095,7 @@ mod tests {
.iter()
.map(|(good, a)| ResourcesSetup {
good,
amount: (*a as f32)
* i.economy.natural_resources.average_yield_per_chunk[good],
amount: *a * i.economy.natural_resources.average_yield_per_chunk[good],
})
.collect();
let neighbors = i
@ -1159,8 +1158,7 @@ mod tests {
//let c = sim::SimChunk::new();
//settlement.economy.add_chunk(ch, distance_squared)
// bypass the API for now
settlement.economy.natural_resources.chunks_per_resource[g.good] =
g.amount as u32;
settlement.economy.natural_resources.chunks_per_resource[g.good] = g.amount;
settlement.economy.natural_resources.average_yield_per_chunk[g.good] = 1.0;
}
index.sites.insert(settlement);

View File

@ -29,7 +29,7 @@ pub struct Labor(u8, PhantomData<Profession>);
#[derive(Debug)]
pub struct AreaResources {
pub resource_sum: MapVec<Good, f32>,
pub resource_chunks: MapVec<Good, u32>,
pub resource_chunks: MapVec<Good, f32>,
pub chunks: u32,
}
@ -49,7 +49,7 @@ pub struct NaturalResources {
pub per_area: Vec<AreaResources>,
// computation simplifying cached values
pub chunks_per_resource: MapVec<Good, u32>,
pub chunks_per_resource: MapVec<Good, f32>,
pub average_yield_per_chunk: MapVec<Good, f32>,
}
@ -221,9 +221,9 @@ impl Economy {
.iter()
.map(|a| a.resource_chunks[g])
.sum();
if chunks != 0 {
if chunks > 0.001 {
self.natural_resources.chunks_per_resource[g] = chunks;
self.natural_resources.average_yield_per_chunk[g] = amount / (chunks as f32);
self.natural_resources.average_yield_per_chunk[g] = amount / chunks;
}
}
}
@ -273,14 +273,14 @@ impl Economy {
pub fn replenish(&mut self, _time: f32) {
for (good, &ch) in self.natural_resources.chunks_per_resource.iter() {
let per_year = self.natural_resources.average_yield_per_chunk[good] * (ch as f32);
let per_year = self.natural_resources.average_yield_per_chunk[good] * ch;
self.stocks[good] = self.stocks[good].max(per_year);
}
// info!("resources {:?}", self.stocks);
}
pub fn add_chunk(&mut self, ch: &SimChunk, distance_squared: i64) {
let biome = ch.get_biome();
// let biome = ch.get_biome();
// we don't scale by pi, although that would be correct
let distance_bin = (distance_squared >> 16).min(64) as usize;
if self.natural_resources.per_area.len() <= distance_bin {
@ -289,9 +289,33 @@ impl Economy {
.resize_with(distance_bin + 1, Default::default);
}
self.natural_resources.per_area[distance_bin].chunks += 1;
self.natural_resources.per_area[distance_bin].resource_sum[Terrain(biome)] += 1.0;
self.natural_resources.per_area[distance_bin].resource_chunks[Terrain(biome)] += 1;
// TODO: Scale resources by rockiness or tree_density?
// self.natural_resources.per_area[distance_bin].resource_sum[Terrain(biome)] +=
// 1.0; self.natural_resources.per_area[distance_bin].
// resource_chunks[Terrain(biome)] += 1.0; TODO: Scale resources by
// rockiness or tree_density?
let mut add_biome = |biome, amount| {
self.natural_resources.per_area[distance_bin].resource_sum[Terrain(biome)] += amount;
self.natural_resources.per_area[distance_bin].resource_chunks[Terrain(biome)] += amount;
};
if ch.river.is_ocean() {
add_biome(BiomeKind::Ocean, 1.0);
} else if ch.river.is_lake() {
add_biome(BiomeKind::Lake, 1.0);
} else {
add_biome(BiomeKind::Forest, 0.5 + ch.tree_density);
add_biome(BiomeKind::Grassland, 0.5 + ch.humidity);
add_biome(BiomeKind::Jungle, 0.5 + ch.humidity * (ch.temp * 0.5 + 0.5));
add_biome(
BiomeKind::Mountain,
0.5 + ch.rockiness + (ch.alt / 4000.0).max(0.0),
);
add_biome(
BiomeKind::Desert,
0.5 + (1.0 - ch.humidity) * (ch.temp * 0.5 + 0.5),
);
add_biome(BiomeKind::Snowland, 0.5 + (-ch.temp).max(0.0));
}
}
pub fn add_neighbor(&mut self, id: Id<Site>, distance: usize) {