Skip to content

Commit 283bfc1

Browse files
committed
implement singular currency names
1 parent 402a484 commit 283bfc1

File tree

2 files changed

+149
-110
lines changed

2 files changed

+149
-110
lines changed

wotw_seedgen_seed_language/src/compile/function.rs

Lines changed: 142 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use super::{expression::CompileInto, Compile, SnippetCompiler, RESERVED_MEMORY};
1+
use super::{expression::CompileInto, Compile, SnippetCompiler, PRIVATE_MEMORY};
22
use crate::{
33
ast::{self, UberStateType},
44
output::{
55
ArithmeticOperator, Command, CommandBoolean, CommandFloat, CommandInteger, CommandString,
6-
CommandVoid, CommandZone, EqualityComparator, Operation,
6+
CommandVoid, CommandZone, Comparator, EqualityComparator, Operation,
77
},
88
};
99
use arrayvec::ArrayVec;
@@ -1090,8 +1090,13 @@ fn item_message(message: CommandString) -> CommandVoid {
10901090
}
10911091
}
10921092

1093+
fn set_spirit_light_string(value: &str) -> Box<CommandVoid> {
1094+
Box::new(CommandVoid::SetString {
1095+
id: PRIVATE_MEMORY,
1096+
value: value.into(),
1097+
})
1098+
}
10931099
fn spirit_light_string(amount: CommandInteger, rng: &mut Pcg64Mcg, remove: bool) -> CommandString {
1094-
const SPIRIT_LIGHT_STRING_ID: usize = RESERVED_MEMORY + 1;
10951100
CommandString::Multi {
10961101
commands: vec![
10971102
CommandVoid::If {
@@ -1101,12 +1106,7 @@ fn spirit_light_string(amount: CommandInteger, rng: &mut Pcg64Mcg, remove: bool)
11011106
member: 0,
11021107
},
11031108
},
1104-
command: Box::new(CommandVoid::SetString {
1105-
id: SPIRIT_LIGHT_STRING_ID,
1106-
value: (*SPIRIT_LIGHT_NAMES.choose(rng).unwrap())
1107-
.to_string()
1108-
.into(),
1109-
}),
1109+
command: set_random_spirit_light_string(&amount, rng),
11101110
},
11111111
CommandVoid::If {
11121112
condition: CommandBoolean::CompareBoolean {
@@ -1121,10 +1121,7 @@ fn spirit_light_string(amount: CommandInteger, rng: &mut Pcg64Mcg, remove: bool)
11211121
right: false.into(),
11221122
}),
11231123
},
1124-
command: Box::new(CommandVoid::SetString {
1125-
id: SPIRIT_LIGHT_STRING_ID,
1126-
value: "Spirit Light".into(),
1127-
}),
1124+
command: set_spirit_light_string("Spirit Light"),
11281125
},
11291126
],
11301127
last: Box::new(if remove {
@@ -1142,9 +1139,7 @@ fn spirit_light_string(amount: CommandInteger, rng: &mut Pcg64Mcg, remove: bool)
11421139
},
11431140
}),
11441141
right: Box::new(CommandString::Concatenate {
1145-
left: Box::new(CommandString::GetString {
1146-
id: SPIRIT_LIGHT_STRING_ID,
1147-
}),
1142+
left: Box::new(CommandString::GetString { id: PRIVATE_MEMORY }),
11481143
right: Box::new("@".into()),
11491144
}),
11501145
}
@@ -1159,13 +1154,54 @@ fn spirit_light_string(amount: CommandInteger, rng: &mut Pcg64Mcg, remove: bool)
11591154
right: Box::new(" ".into()),
11601155
},
11611156
}),
1162-
right: Box::new(CommandString::GetString {
1163-
id: SPIRIT_LIGHT_STRING_ID,
1164-
}),
1157+
right: Box::new(CommandString::GetString { id: PRIVATE_MEMORY }),
11651158
}
11661159
}),
11671160
}
11681161
}
1162+
fn set_random_spirit_light_string(amount: &CommandInteger, rng: &mut Pcg64Mcg) -> Box<CommandVoid> {
1163+
let name = SPIRIT_LIGHT_NAMES.choose(rng).unwrap();
1164+
let constant_singular = amount.as_constant().map(|amount| matches!(amount, 1 | -1));
1165+
1166+
match constant_singular {
1167+
Some(true) => set_spirit_light_string(name.0),
1168+
Some(false) => set_spirit_light_string(name.1),
1169+
None => Box::new(CommandVoid::Multi {
1170+
commands: vec![
1171+
CommandVoid::SetBoolean {
1172+
id: PRIVATE_MEMORY,
1173+
value: CommandBoolean::CompareInteger {
1174+
operation: Box::new(Operation {
1175+
left: CommandInteger::Arithmetic {
1176+
operation: Box::new(Operation {
1177+
left: amount.clone(),
1178+
operator: ArithmeticOperator::Multiply,
1179+
right: amount.clone(),
1180+
}),
1181+
},
1182+
operator: Comparator::Equal,
1183+
right: 1.into(),
1184+
}),
1185+
},
1186+
},
1187+
CommandVoid::If {
1188+
condition: CommandBoolean::GetBoolean { id: PRIVATE_MEMORY },
1189+
command: set_spirit_light_string(name.0),
1190+
},
1191+
CommandVoid::If {
1192+
condition: CommandBoolean::CompareBoolean {
1193+
operation: Box::new(Operation {
1194+
left: CommandBoolean::GetBoolean { id: PRIVATE_MEMORY },
1195+
operator: EqualityComparator::Equal,
1196+
right: false.into(),
1197+
}),
1198+
},
1199+
command: set_spirit_light_string(name.1),
1200+
},
1201+
],
1202+
}),
1203+
}
1204+
}
11691205
fn resource_string(resource: &str, remove: bool) -> CommandString {
11701206
if remove {
11711207
format!("@Remove {resource}@").into()
@@ -1359,91 +1395,91 @@ where
13591395
Command::Void(CommandVoid::Lookup { index })
13601396
}
13611397

1362-
// TODO update
1363-
const SPIRIT_LIGHT_NAMES: &[&str] = &[
1364-
"Spirit Light",
1365-
"Gallons",
1366-
"Spirit Bucks",
1367-
"Gold",
1368-
"Geo",
1369-
"EXP",
1370-
"Experience",
1371-
"XP",
1372-
"Gil",
1373-
"GP",
1374-
"Dollars",
1375-
"Tokens",
1376-
"Tickets",
1377-
"Pounds Sterling",
1378-
"Brownie Points",
1379-
"Euros",
1380-
"Credits",
1381-
"Bells",
1382-
"Fish",
1383-
"Zenny",
1384-
"Pesos",
1385-
"Exalted Orbs",
1386-
"Hryvnia",
1387-
"Poké",
1388-
"Glod",
1389-
"Dollerydoos",
1390-
"Boonbucks",
1391-
"Pieces of Eight",
1392-
"Shillings",
1393-
"Farthings",
1394-
"Kalganids",
1395-
"Quatloos",
1396-
"Crowns",
1397-
"Solari",
1398-
"Widgets",
1399-
"Ori Money",
1400-
"Money",
1401-
"Cash",
1402-
"Munny",
1403-
"Nuyen",
1404-
"Rings",
1405-
"Rupees",
1406-
"Coins",
1407-
"Echoes",
1408-
"Sovereigns",
1409-
"Points",
1410-
"Drams",
1411-
"Doubloons",
1412-
"Spheres",
1413-
"Silver",
1414-
"Slivers",
1415-
"Rubies",
1416-
"Emeralds",
1417-
"Notes",
1418-
"Yen",
1419-
"Złoty",
1420-
"Likes",
1421-
"Comments",
1422-
"Subs",
1423-
"Bananas",
1424-
"Sapphires",
1425-
"Diamonds",
1426-
"Fun",
1427-
"Minerals",
1428-
"Vespene Gas",
1429-
"Sheep",
1430-
"Brick",
1431-
"Wheat",
1432-
"Wood",
1433-
"Quills",
1434-
"Bits",
1435-
"Bytes",
1436-
"Nuts",
1437-
"Bolts",
1438-
"Souls",
1439-
"Runes",
1440-
"Pons",
1441-
"Boxings",
1442-
"Stonks",
1443-
"Leaves",
1444-
"Marbles",
1445-
"Stamps",
1446-
"Hugs",
1447-
"Nobles",
1448-
"Socks",
1398+
const SPIRIT_LIGHT_NAMES: [(&str, &str); 86] = [
1399+
("Banana", "Bananas"),
1400+
("Bell", "Bells"),
1401+
("Bit", "Bits"),
1402+
("Bolt", "Bolts"),
1403+
("Boonbuck", "Boonbucks"),
1404+
("Boxing", "Boxings"),
1405+
("Brick", "Brick"),
1406+
("Brownie Point", "Brownie Points"),
1407+
("Byte", "Bytes"),
1408+
("Cash", "Cash"),
1409+
("Coin", "Coins"),
1410+
("Comment", "Comments"),
1411+
("Credit", "Credits"),
1412+
("Crown", "Crowns"),
1413+
("Diamond", "Diamonds"),
1414+
("Dollar", "Dollars"),
1415+
("Dollerydoo", "Dollerydoos"),
1416+
("Doubloon", "Doubloons"),
1417+
("Dram", "Drams"),
1418+
("Echoe", "Echoes"),
1419+
("Emerald", "Emeralds"),
1420+
("Euro", "Euros"),
1421+
("Exalted Orb", "Exalted Orbs"),
1422+
("EXP", "EXP"),
1423+
("Experience", "Experience"),
1424+
("Farthing", "Farthings"),
1425+
("Fish", "Fish"),
1426+
("Fun", "Fun"),
1427+
("Gallon", "Gallons"),
1428+
("Geo", "Geo"),
1429+
("Gil", "Gil"),
1430+
("Glod", "Glod"),
1431+
("Gold", "Gold"),
1432+
("GP", "GP"),
1433+
("Hryvnia", "Hryvnia"),
1434+
("Hug", "Hugs"),
1435+
("Kalganid", "Kalganids"),
1436+
("Leaf", "Leaves"),
1437+
("Like", "Likes"),
1438+
("Marble", "Marbles"),
1439+
("Mineral", "Minerals"),
1440+
("Money", "Money"),
1441+
("Munny", "Munny"),
1442+
("Noble", "Nobles"),
1443+
("Note", "Notes"),
1444+
("Nut", "Nuts"),
1445+
("Nuyen", "Nuyen"),
1446+
("Ori", "Ori Money"),
1447+
("Pesos", "Pesos"),
1448+
("Piece of Eight", "Pieces of Eight"),
1449+
("Point", "Points"),
1450+
("Poké", "Poké"),
1451+
("Pon", "Pons"),
1452+
("Pound Sterling", "Pounds Sterling"),
1453+
("Quatloo", "Quatloos"),
1454+
("Quill", "Quills"),
1455+
("Ring", "Rings"),
1456+
("Ruby", "Rubies"),
1457+
("Rune", "Runes"),
1458+
("Rupee", "Rupees"),
1459+
("Sapphire", "Sapphires"),
1460+
("Sheep", "Sheep"),
1461+
("Shilling", "Shillings"),
1462+
("Silver", "Silver"),
1463+
("Sliver", "Slivers"),
1464+
("Smackerooni", "Smackeroonis"),
1465+
("Sock", "Socks"),
1466+
("Solari", "Solari"),
1467+
("Soul", "Souls"),
1468+
("Sovereign", "Sovereigns"),
1469+
("Sphere", "Spheres"),
1470+
("Spirit Buck", "Spirit Bucks"),
1471+
("Spirit", "Spirit Light"),
1472+
("Stamp", "Stamps"),
1473+
("Stonk", "Stonks"),
1474+
("Sub", "Subs"),
1475+
("Ticket", "Tickets"),
1476+
("Token", "Tokens"),
1477+
("Vespine", "Vespine Gas"),
1478+
("Wheat", "Wheat"),
1479+
("Widget", "Widgets"),
1480+
("Wood", "Wood"),
1481+
("XP", "XP"),
1482+
("Yen", "Yen"),
1483+
("Zenny", "Zenny"),
1484+
("Złoty", "Złoty"),
14491485
];

wotw_seedgen_seed_language/src/compile/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ pub struct Compiler<'snippets, 'uberstates> {
4848
/// How many memory slots to reserve for generated calculations
4949
// TODO how much is needed
5050
pub const RESERVED_MEMORY: usize = 10;
51+
/// Memory slot for hardcoded calculations
52+
pub const PRIVATE_MEMORY: usize = RESERVED_MEMORY + 1;
5153

5254
// TODO set -> store?
5355
pub const fn set_boolean(uber_identifier: UberIdentifier, value: CommandBoolean) -> CommandVoid {
@@ -240,10 +242,11 @@ impl<'snippets, 'uberstates> GlobalCompilerData<'snippets, 'uberstates> {
240242
snippet_access,
241243
events: Default::default(),
242244
exported_values: Default::default(),
243-
boolean_ids: IdProvider::new(RESERVED_MEMORY),
244-
integer_ids: IdProvider::new(RESERVED_MEMORY),
245-
float_ids: IdProvider::new(RESERVED_MEMORY),
246-
string_ids: IdProvider::new(RESERVED_MEMORY + 1), // 1 reserved for spirit light strings
245+
// 1 additional reserved for hardcoded calculations
246+
boolean_ids: IdProvider::new(PRIVATE_MEMORY),
247+
integer_ids: IdProvider::new(PRIVATE_MEMORY),
248+
float_ids: IdProvider::new(PRIVATE_MEMORY),
249+
string_ids: IdProvider::new(PRIVATE_MEMORY),
247250
boolean_state_id: 100,
248251
integer_state_id: 0,
249252
float_state_id: 150,

0 commit comments

Comments
 (0)