Skip to content

Commit fda4bc0

Browse files
committed
don't display when mission selected, display wares
1 parent 572faa2 commit fda4bc0

File tree

5 files changed

+94
-6
lines changed

5 files changed

+94
-6
lines changed

mod-town-hall-details/src/pages/aldermans_office.rs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use std::ffi::{CStr, CString};
22

3+
use log::warn;
34
use p3_api::{
45
data::{ddraw_set_constant_color, ui_render_text_at},
56
game_world::GAME_WORLD_PTR,
67
missions::alderman_missions::{AldermanMissionDataPtr, FoundTownPtr},
8+
operations::OPERATIONS_PTR,
79
scheduled_tasks::{scheduled_task::ScheduledTaskData, SCHEDULED_TASKS_PTR},
810
ui::{
911
font::{self, get_normal_font},
@@ -16,13 +18,18 @@ static TASK_RESCHEDULING_IN: &CStr = c"Rescheduling in";
1618
static TASK_RESCHEDULES_REMAINING: &CStr = c"Reschedule Counter";
1719
static TOWN: &CStr = c"Town";
1820
static EFFECTIVE_PRODUCTION: &CStr = c"Effective Production";
21+
static INEFFECTIVE_PRODUCTION: &CStr = c"Ineffective Production";
1922

2023
pub(crate) unsafe fn draw_page(window: UITownHallWindowPtr) {
2124
let next_mission_index = window.get_next_mission_index();
2225
if next_mission_index == 0 {
2326
return;
2427
}
2528

29+
if SCHEDULED_TASKS_PTR.get_merchant_alderman_mission_task_index(OPERATIONS_PTR.get_player_merchant_index()) != -1 {
30+
return;
31+
}
32+
2633
let selected_mission_index = window.get_selected_alderman_mission_index();
2734
if selected_mission_index == 0xff {
2835
return;
@@ -72,6 +79,7 @@ pub(crate) unsafe fn draw_page(window: UITownHallWindowPtr) {
7279

7380
unsafe fn render_aldermans_office_modifications_found_town(window: UITownHallWindowPtr, data: &FoundTownPtr) {
7481
let town = data.get_town();
82+
let effective_raw = data.get_production_effective_raw();
7583
let effective = data.get_production_effective();
7684
let x = window.get_x();
7785
let mut y = window.get_y() + 100;
@@ -88,10 +96,48 @@ unsafe fn render_aldermans_office_modifications_found_town(window: UITownHallWin
8896
font::ddraw_set_text_mode(font::TextMode::AlignRight);
8997
let mut effective_string = String::new();
9098
for facility in effective {
91-
effective_string.push_str(&format!("{facility:?}, "));
99+
match facility {
100+
p3_api::data::enums::FacilityId::Militia => warn!("Unexpected facility {facility:?}"),
101+
p3_api::data::enums::FacilityId::Shipyard => warn!("Unexpected facility {facility:?}"),
102+
p3_api::data::enums::FacilityId::Construction => warn!("Unexpected facility {facility:?}"),
103+
p3_api::data::enums::FacilityId::Weaponsmith => warn!("Unexpected facility {facility:?}"),
104+
p3_api::data::enums::FacilityId::HuntingLodge => effective_string.push_str("Skins, "),
105+
p3_api::data::enums::FacilityId::FishermansHouse => {
106+
if effective_raw & 0x20000 != 0 {
107+
effective_string.push_str("Whale Oil, ")
108+
} else {
109+
effective_string.push_str("Fish, ")
110+
}
111+
}
112+
p3_api::data::enums::FacilityId::Brewery => effective_string.push_str("Beer, "),
113+
p3_api::data::enums::FacilityId::Workshop => effective_string.push_str("Iron Goods, "),
114+
p3_api::data::enums::FacilityId::Apiary => effective_string.push_str("Honey, "),
115+
p3_api::data::enums::FacilityId::GrainFarm => effective_string.push_str("Grain, "),
116+
p3_api::data::enums::FacilityId::CattleFarm => effective_string.push_str("Meat, Leather, "),
117+
p3_api::data::enums::FacilityId::Sawmill => effective_string.push_str("Timber, "),
118+
p3_api::data::enums::FacilityId::WeavingMill => effective_string.push_str("Cloth, "),
119+
p3_api::data::enums::FacilityId::Saltery => effective_string.push_str("Salt, "),
120+
p3_api::data::enums::FacilityId::Ironsmelter => effective_string.push_str("Pig Iron, "),
121+
p3_api::data::enums::FacilityId::SheepFarm => effective_string.push_str("Wool, "),
122+
p3_api::data::enums::FacilityId::Vineyard => effective_string.push_str("Wine, "),
123+
p3_api::data::enums::FacilityId::Pottery => effective_string.push_str("Pottery, "),
124+
p3_api::data::enums::FacilityId::Brickworks => effective_string.push_str("Bricks, "),
125+
p3_api::data::enums::FacilityId::Pitchmaker => effective_string.push_str("Pitch, "),
126+
p3_api::data::enums::FacilityId::HempFarm => effective_string.push_str("Hemp, "),
127+
}
92128
}
93129
effective_string.pop();
94130
effective_string.pop();
95131
let effective_cstring = CString::new(effective_string).unwrap();
96132
ui_render_text_at(x + COL_OFFSETS[1], y, effective_cstring.to_bytes());
133+
y += 20;
134+
135+
font::ddraw_set_text_mode(font::TextMode::AlignLeft);
136+
ui_render_text_at(x + COL_OFFSETS[0], y, INEFFECTIVE_PRODUCTION.to_bytes());
137+
138+
font::ddraw_set_text_mode(font::TextMode::AlignRight);
139+
let mut ineffective_string = String::new();
140+
if effective_raw & 0x20000 != 0 {
141+
ineffective_string.push_str("Fish")
142+
}
97143
}

mod-town-hall-details/src/pages/details.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,22 @@ pub(crate) unsafe fn draw_page(window: UITownHallWindowPtr) {
7979

8080
let mut effective_prods_count = 0;
8181
font::ddraw_set_font(font::get_normal_font());
82+
let mut has_meat_or_leather = false;
8283
for data in &hanse_data {
8384
let ware = WareId::from_usize(data.ware).unwrap();
8485
let ratio = data.get_ratio();
8586
if data.total_consumption < 1024 {
8687
ddraw_set_constant_color(0xFFD3D3D3);
8788
} else if effective_prods_count < 3 {
8889
ddraw_set_constant_color(0xFF7CFC00);
89-
effective_prods_count += 1;
90+
if ware == WareId::Meat || ware == WareId::Leather {
91+
if !has_meat_or_leather {
92+
effective_prods_count += 1;
93+
has_meat_or_leather = true;
94+
}
95+
} else {
96+
effective_prods_count += 1;
97+
}
9098
} else {
9199
ddraw_set_constant_color(0xFF000000);
92100
}

p3-api/src/data/enums.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ pub enum FacilityId {
5454
Brickworks = 0x12,
5555
Pitchmaker = 0x13,
5656
HempFarm = 0x14,
57-
FishermansHouseWhale = 0xff,
5857
}
5958

6059
#[derive(Clone, Copy, Debug, Eq, PartialEq, EnumIter, EnumString, FromPrimitive)]

p3-api/src/operations.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,38 @@ use std::mem::transmute;
22

33
use log::debug;
44

5-
use crate::operation::Operation;
5+
use crate::{data::p3_ptr::P3Pointer, operation::Operation};
66

7+
const OPERATIONS_ADDRESS: u32 = 0x006DF2F0;
8+
pub const OPERATIONS_PTR: OperationsPtr = OperationsPtr::new();
79
const EXECUTE_OPERATION_ADDRESS: u32 = 0x00535760;
8-
//const STATIC_OPERATIONS_ADDRESS: u32 = 0x006DF2F0;
10+
11+
#[derive(Clone, Debug, Copy)]
12+
pub struct OperationsPtr {
13+
pub address: u32,
14+
}
15+
16+
impl Default for OperationsPtr {
17+
fn default() -> Self {
18+
Self::new()
19+
}
20+
}
21+
22+
impl OperationsPtr {
23+
pub const fn new() -> Self {
24+
Self { address: OPERATIONS_ADDRESS }
25+
}
26+
27+
pub unsafe fn get_player_merchant_index(&self) -> i32 {
28+
self.get(0x0924)
29+
}
30+
}
31+
32+
impl P3Pointer for OperationsPtr {
33+
fn get_address(&self) -> u32 {
34+
self.address
35+
}
36+
}
937

1038
pub fn execute_operation(op: &Operation) {
1139
debug!("execute_operation({:?})", op);

p3-api/src/scheduled_tasks/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::mem;
2+
13
use scheduled_task::{ScheduledTaskPtr, SCHEDULED_TASK_SIZE};
24

35
use crate::data::p3_ptr::P3Pointer;
@@ -6,7 +8,7 @@ pub mod scheduled_task;
68
const SCHEDULED_TASKS_ADDRESS: u32 = 0x006DD73C;
79
pub const SCHEDULED_TASKS_PTR: ScheduledTasksPtr = ScheduledTasksPtr::new();
810

9-
#[derive(Clone, Debug)]
11+
#[derive(Clone, Debug, Copy)]
1012
pub struct ScheduledTasksPtr {
1113
pub address: u32,
1214
}
@@ -28,6 +30,11 @@ impl ScheduledTasksPtr {
2830
let base_address: u32 = unsafe { self.get(0x00) };
2931
ScheduledTaskPtr::new(base_address + index as u32 * SCHEDULED_TASK_SIZE)
3032
}
33+
34+
pub unsafe fn get_merchant_alderman_mission_task_index(&self, merchant_index: i32) -> i16 {
35+
let func: extern "thiscall" fn(scheduled_tasks: u32, merchant_index: i32) -> i16 = mem::transmute(0x004EC694);
36+
func(self.address, merchant_index)
37+
}
3138
}
3239

3340
impl P3Pointer for ScheduledTasksPtr {

0 commit comments

Comments
 (0)