From ff10f3ca53a80b2f0c29f16805f1557a06b5d938 Mon Sep 17 00:00:00 2001 From: Marrub Date: Mon, 4 Mar 2019 09:00:03 -0500 Subject: [PATCH] better terminal group handling --- MarathonData.md | 7 ++-- source/marathon/trm.rs | 74 +++++++++++++++++++++++++----------------- tests/data/term.out | 49 +++++++++------------------- 3 files changed, 64 insertions(+), 66 deletions(-) diff --git a/MarathonData.md b/MarathonData.md index 22a1c4d..c505b65 100644 --- a/MarathonData.md +++ b/MarathonData.md @@ -337,7 +337,8 @@ Example: #SOUND sound_number ``` -`#SOUND` plays the specified sound from the Sounds file or from the Scenario. +`#SOUND` plays the specified sound from the Sounds file or from the scenario +and then goes to the next level. Example: @@ -1914,7 +1915,7 @@ Used to determine how the engine loads map data. | Name | Value | Permutation | | ---- | ----- | ----------- | -| `Logon` | `0` | None | +| `Logon` | `0` | Pict ID | | `Unfinished` | `1` | None | | `Success` | `2` | None | | `Failure` | `3` | None | @@ -1927,7 +1928,7 @@ Used to determine how the engine loads map data. | `Movie` | `10` | Movie ID | | `Track` | `11` | Track ID | | `Pict` | `12` | Pict ID | -| `Logoff` | `13` | None | +| `Logoff` | `13` | Pict ID | | `Camera` | `14` | Object ID | | `Static` | `15` | 1/30 secs | | `Tag` | `16` | Tag number | diff --git a/source/marathon/trm.rs b/source/marathon/trm.rs index 79e1a64..d02c49b 100644 --- a/source/marathon/trm.rs +++ b/source/marathon/trm.rs @@ -10,7 +10,7 @@ pub fn read_group(b: &[u8], text: &[u8]) -> ResultS 12, BE in b => flags = u16[0]; ttype = u16[2]; - pdata = i16[4]; + pdata = u16[4]; start = u16[6] usize; size = u16[8] usize; lines = u16[10]; @@ -18,9 +18,28 @@ pub fn read_group(b: &[u8], text: &[u8]) -> ResultS let text = mac_roman_cstr(&text[start..start + size])?; let flags = flag_ok!(GroupFlags, flags)?; - let ttype = GroupType::from_repr(ttype)?; + let ttype = match ttype { + 0 => GroupType::Logon(pdata), + 1 => GroupType::Unfinished, + 2 => GroupType::Success, + 3 => GroupType::Failure, + 4 => GroupType::Info, + 5 => GroupType::End, + 6 => GroupType::TeleInter(pdata), + 7 => GroupType::TeleIntra(pdata), + 8 => GroupType::Checkpoint(pdata), + 9 => GroupType::Sound(pdata), + 10 => GroupType::Movie(pdata), + 11 => GroupType::Track(pdata), + 12 => GroupType::Pict(pdata), + 13 => GroupType::Logoff(pdata), + 14 => GroupType::Camera(pdata), + 15 => GroupType::Static(pdata), + 16 => GroupType::Tag(pdata), + n => return Err(ReprError::new(n).into()), + }; - Ok(Group{flags, ttype, pdata, lines, text}) + Ok(Group{flags, ttype, lines, text}) } /// Reads a `Face`. @@ -103,11 +122,33 @@ pub struct Group { pub flags: GroupFlags, pub ttype: GroupType, - pub pdata: i16, pub lines: u16, pub text: String, } +/// The command of a `Group`. +#[derive(Debug, PartialEq, serde::Serialize)] +pub enum GroupType +{ + Logon(u16), + Unfinished, + Success, + Failure, + Info, + End, + TeleInter(u16), + TeleIntra(u16), + Checkpoint(u16), + Sound(u16), + Movie(u16), + Track(u16), + Pict(u16), + Logoff(u16), + Camera(u16), + Static(u16), + Tag(u16), +} + bitflags! { /// Flags for `Group`. #[derive(serde::Serialize)] @@ -118,29 +159,4 @@ bitflags! { } } -c_enum! { - /// The command of a `Group`. - #[derive(Debug, PartialEq, serde::Serialize)] - pub enum GroupType: u16 - { - 0 => Logon, - 1 => Unfinished, - 2 => Success, - 3 => Failure, - 4 => Info, - 5 => End, - 6 => TeleInter, - 7 => TeleIntra, - 8 => Checkpoint, - 9 => Sound, - 10 => Movie, - 11 => Track, - 12 => Pict, - 13 => Logoff, - 14 => Camera, - 15 => Static, - 16 => Tag, - } -} - // EOF diff --git a/tests/data/term.out b/tests/data/term.out index fe3e0ab..57681ad 100644 --- a/tests/data/term.out +++ b/tests/data/term.out @@ -5,42 +5,36 @@ vec![ trm::Group { flags: trm::GroupFlags::empty(), ttype: trm::GroupType::Unfinished, - pdata: 0, lines: 0, text: "".to_string() }, trm::Group { flags: trm::GroupFlags::empty(), - ttype: trm::GroupType::Logon, - pdata: 1600, + ttype: trm::GroupType::Logon(1600), lines: 1, text: "\n".to_string() }, trm::Group { flags: trm::GroupFlags::empty(), - ttype: trm::GroupType::Pict, - pdata: 10011, + ttype: trm::GroupType::Pict(10011), lines: 22, text: "~text interface terminal malfunction error ~2992dud\n\nThings have gone terribly awry. Until now, I thought myself immortal, but now I know that is not true. There are things that can destroy me with the ease that I slaughtered the Pfhor naval garrison and the Western Arm of their Battle Group Seven. But in their final gasp they used a weapon that I thought they had retired, even Tycho tried to keep them from using it.\n\nNow I fear what that weapon has unleashed will destroy us. I once boasted to be able to count the atoms in a cloud, to understand them all, predict them, and so did I predict you, but this new chaos is entirely terrible, mindless, obeying rules that I don\'t comprehend. And it is hungry.\n\n".to_string() }, trm::Group { flags: trm::GroupFlags::empty(), - ttype: trm::GroupType::Pict, - pdata: 10005, + ttype: trm::GroupType::Pict(10005), lines: 21, text: "~text interface terminal malfunction error ~2992dud\n\nIt\'s too bad, perhaps if I could have delayed the Pfhor from using their weapon, I could have sent you to explore the ruins of Lh\'owon, perhaps what you found would give us the answers that we now need so desparately: how to stop this chaos, the purpose of the station on which you\'re currently standing, and why the chaos hasn\'t come here yet.\n\nBut with each moment the chaos grows, I am doomed to die here, after so many triumphs. I have detected one ship nearby, which I can only guess is being commanded by Tycho. The Pfhor have entered the station, and if you can find a way onto their ship, you may be able to escape. To escape. To escape.\n\n".to_string() }, trm::Group { flags: trm::GroupFlags::empty(), - ttype: trm::GroupType::Pict, - pdata: 10006, + ttype: trm::GroupType::Pict(10006), lines: 21, text: "~text interface terminal malfunction error ~2992dud\n\nIt\'s too bad, perhaps if I could have delayed the Pfhor from using their weapon, I could have sent you to explore the ruins of Lh\'owon, perhaps what you found would give us the answers that we now need so desparately: how to stop this chaos, the purpose of the station on which you\'re currently standing, and why the chaos hasn\'t come here yet.\n\nBut with each moment the chaos grows, I am doomed to die here, after so many triumphs. I have detected one ship nearby, which I can only guess is being commanded by Tycho. The Pfhor have entered the station, and if you can find a way onto their ship, you may be able to escape. To escape. To escape.\n\n".to_string() }, trm::Group { flags: trm::GroupFlags::empty(), - ttype: trm::GroupType::Logoff, - pdata: 1600, + ttype: trm::GroupType::Logoff(1600), lines: 1, text: "\n".to_string() } @@ -53,28 +47,24 @@ vec![ trm::Group { flags: trm::GroupFlags::empty(), ttype: trm::GroupType::Unfinished, - pdata: 253, lines: 0, text: "".to_string() }, trm::Group { flags: trm::GroupFlags::empty(), - ttype: trm::GroupType::Logon, - pdata: 1610, + ttype: trm::GroupType::Logon(1610), lines: 1, text: "\n".to_string() }, trm::Group { flags: trm::GroupFlags::empty(), - ttype: trm::GroupType::Pict, - pdata: 10008, + ttype: trm::GroupType::Pict(10008), lines: 14, text: "\n\n\nspurious interrupt\nunauthorized access\ninformation contained\n\n
\ninformation retrieval aspect 30-f\n\n~eibat weapo` 3941\nsiklicar 21`perie1ces\nclwaa\n\n".to_string() }, trm::Group { flags: trm::GroupFlags::empty(), - ttype: trm::GroupType::Logoff, - pdata: 1610, + ttype: trm::GroupType::Logoff(1610), lines: 1, text: "\n".to_string() } @@ -87,35 +77,30 @@ vec![ trm::Group { flags: trm::GroupFlags::empty(), ttype: trm::GroupType::Unfinished, - pdata: 253, lines: 0, text: "".to_string() }, trm::Group { flags: trm::GroupFlags::empty(), - ttype: trm::GroupType::Logon, - pdata: 1619, + ttype: trm::GroupType::Logon(1619), lines: 1, text: "".to_string() }, trm::Group { flags: trm::GroupFlags::empty(), - ttype: trm::GroupType::Pict, - pdata: 10007, + ttype: trm::GroupType::Pict(10007), lines: 16, text: "\n\n\nthousands are sailing\nthe same self\t\tthe only self\n\nself willed the peril of a thousand fates\n\na line of infinite ends\t\tfinite finishing\nthe one remains oblique and pure\n\narching to the single point of consciousness\n\nfind yourself\nstarting back\n".to_string() }, trm::Group { flags: trm::GroupFlags::empty(), - ttype: trm::GroupType::Logoff, - pdata: 1619, + ttype: trm::GroupType::Logoff(1619), lines: 1, text: "".to_string() }, trm::Group { flags: trm::GroupFlags::empty(), - ttype: trm::GroupType::TeleInter, - pdata: 1, + ttype: trm::GroupType::TeleInter(1), lines: 1, text: "".to_string() } @@ -134,28 +119,24 @@ vec![ trm::Group { flags: trm::GroupFlags::empty(), ttype: trm::GroupType::Unfinished, - pdata: 0, lines: 0, text: "".to_string() }, trm::Group { flags: trm::GroupFlags::empty(), - ttype: trm::GroupType::Logon, - pdata: 1619, + ttype: trm::GroupType::Logon(1619), lines: 1, text: "".to_string() }, trm::Group { flags: trm::GroupFlags::empty(), - ttype: trm::GroupType::Pict, - pdata: 10007, + ttype: trm::GroupType::Pict(10007), lines: 84, text: "534954210001000034EE724C6175020000000016\n000000001E48617473204F666620746F20456967\n6874204E696E657465656E2E736974946AAA0000\n0000000000000000000000000000000000000000\n00000000FFFFFFFF53495444534954210100AE1A\nCAD4AE1ACAD40000000000003468000000000000\n34680000CAF90000000000004A21534954210001\n00003468724C617502000000001600000D0D1A48\n617473204F666620746F204569676874204E696E\n657465656E0001537E94897D0000000000000000\n000000000000000000000000000000000000FFFF\nFFFF7363653232362EB00100AE1AA710AE1ACAC4\n0000087A0000738C0000057100002E7177DCF747\n000000000000EFB60B005D796C65E775CA8EB023\n47B984114E5646B8114E5847B8E498849F479E93\nE347FBB5EC08CB8F30B24A23C7098B3CCBC31B2D\nC2093D4EB81EDE2897F09530326087377E86279C\n3C7BF192A31CCFC988BFD7D993A747669C1C2313\n4638E164CA927072FC24CF8F1CA79EFC0566A33C\n2F3D0302A02F3BC28D3C2748648403AF029F2380\n95318331965FC5D8227C99FD62F78617DE1918ED\n6EC311B368530FEB69375AA82C5BBDE3E0F0D1E2\n5ECE8BC343C5DE23CEC07071CF91417BD8B60737\n984CFF8E1EB2BBBB376DF816BA3E622FCFCBF867\nBE5EFD7981B1A3A7A0FA3DAD4BF36516D4BEC4DA\nD8BC5A8D6A79F00A6B79A051D916AA871D7F88CA\nB550178D9602E760B7F656A37A1EA1CC05D4968B\nFA92BD9CBD3C775FCD6EB0E566B38335535C772C\n7C5B483D065BF2E01E1DF71E61F53CE46C03D782\n7D0BD3B7FB1B6CCB186BCE0D33B66EBD7061EB56\n6676754D4E7675B14CA170FD7AA1A0592727B52D\n8C9D3E8D1DC61E3BA6DD626CDF3E1D55C6D6AFC7\nBE9831B031B6249F1F1FC7A53D9FBF74097BC7DA\nB5E3E31B37B2A55D5DE3E36082E207D3F26A6E5F\n7785162791F485EF70EEA6BC5D702E70EAAF5A9C\nD7852983F8477AFE2AAD4824485C7000FBAE552A\nF5F6F6CFF2BCE3F2332072DC599E8A8CE74BF50B\n6DFE8DCC64CC4F85E13A759E87206765BF55DADD\nE086CB1B22C7CFF4734780516B7D63A565F5BEEE\nC9F857DA3C45AB7C40AC534F5B1677B8F0A4544A\nCAC86BA8BB6424718366556724DCF727AC7269DB\n9A0B57AF5E11DEEFF4DC1F944D7CB75CEA4D4BF9\n4FAC7E47F3C63F532101BBEF9E7FEBFC9713BB4A\n80C5093D798D96D4606319167881FA9E96A8C817\nE270A9F48113FE454FDCA045896F5B5C48F51DE5\n93C83F6B95B78BF03AADBC05915120643C818374\nB917DCA4A5B7B42D5FC16E15DFA2A76628839400\n6746524E53A62665FCC3DC1A4E5353B1B84EEBC0\n51B3ACBE9B9419EEB7635CA7AC72052453963508\n12C1BC3A59292D4BA4904122EC3EA29AF0827BD4\n069B284A258B53481076384B591548DF8B6F6A43\n8413C4B78981A02326AA0A518107C20B536A438E\n02901E32404F2912149CDC1F92CEB3C4AAE2FB64\nAA44A594F347A9CA4F860D3482F48240A9C80BEE\n5247E272217C8E8C925233C492BA326A32A54EE4\n0BCD61EF97440B1A77995507C664AAC2818C5C22\n83D0E7FBEF50CE75C22A17C09830AC8E8008EF1E\n99AE13DCD7668AF00EA2E387C10CE5A41825DF1B\nADD336734CC4B364F8DE0C3543D3771DE8483CAF\nE679506A26521BE78B789A0C11CE472F441EE3DA\n3465234908629D4A06C9FBD494334801B232709B\nB2BE47910F01C6949AA5B6314A22A450ABD1C954\n3AC74604658BC67C71B2A21444EC324F5AA3B364\n9E295590B9B1FEC191F2765871B6B473AA54AEC0\n8A2A4768D9899433F860564B7D9052E5BC729BCC\nDAE13E6839B3DDB62B2E1FA8D3818E1AAA432176\n2AB2079087D5480252C703A2041F643751A2DC1F\nD6ECDE4A83323E0A2745E452758F3223659D1778\n3EFA37B52591EB8EDEA7BCF47C118E090FED78D0\nA4C44F79DEE64E00FF7D81B60852CAD704BA5404\n88BFC8A0BE3D585673454366E74A20BC49CC6FF0\n9C00A1A4A82EDB43D48737D7F60E0CCDF91201A5\n5A1D622C58825E4182337050071011C751C94821\nC94910016AA8F8FA5C13E5E228503034554D6A9F\nE24E8522FDD210A10E3DEAA5011715083ACFE9C6\n10217AA136E25CA3FCA748915D215A760E084D37\n7F2E802781D35AFD090751297CA1DBDC918A6A3E\nDAE51A757C464CA602C522FF243CB2F0CA393EFF\nD27A9CC3C08349FCF4145971B9D17A3EE2F8F1C2\nEB10A7FFF6C73FF806E3FEFD53C0287F38D1A91F\n9B6BD83E66BCB6735B19042B766EDBBB07986773\n65EDDBFC3C5368368B2C7760EE8800E21DFB933E\nAD280D8DBCF9B65DDC32A2FF317875C8191AFC1F\n000E00EB37EAB4CECBEBECBC0CCF06793DBD2EB3\n".to_string() }, trm::Group { flags: trm::GroupFlags::empty(), - ttype: trm::GroupType::Logoff, - pdata: 1619, + ttype: trm::GroupType::Logoff(1619), lines: 1, text: "".to_string() }