Skip to content

Commit

Permalink
Phoneme codec for cit names
Browse files Browse the repository at this point in the history
  • Loading branch information
inodentry committed Apr 28, 2024
1 parent 5c3787d commit 3a85db6
Show file tree
Hide file tree
Showing 10 changed files with 581 additions and 36 deletions.
7 changes: 5 additions & 2 deletions bin/mw_datatool/src/cmd/gen_map.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::io::BufWriter;

use mw_common::{game::{MapGenTileData, TileKind}, grid::*};
use mw_common::{game::{MapGenTileData, TileKind}, grid::*, phoneme::Ph};

use crate::prelude::*;
use crate::{CommonArgs, GenMapArgs};
Expand Down Expand Up @@ -28,7 +28,10 @@ pub fn main(common: &CommonArgs, args: &GenMapArgs) -> AnyResult<()> {
.start_is()?;
let is = b_is
.with_map_lz4compressed(&map, true, &mut scratch)?
.with_cits([Pos(12, 17), Pos(7, 3)])?
.with_cits([
(Pos(12, 17), [Ph::A, Ph::B, Ph::E, Ph::Z].as_slice()),
(Pos(7, 3), [Ph::I, Ph::D, Ph::A].as_slice()),
])?
.with_named_players(["iyes", "georgie", "gr.NET"])?
.finish()?;
let b_file = b_file.with_is(is)?;
Expand Down
9 changes: 9 additions & 0 deletions bin/mw_datatool/src/cmd/info.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use mw_common::phoneme::{lang, render_str};
use mw_dataformat::read::MwFileReader;

use crate::prelude::*;
Expand Down Expand Up @@ -55,5 +56,13 @@ pub fn main(common: &CommonArgs, args: &InfoArgs) -> AnyResult<()> {
eprintln!("{}: {:?}", i, name);
}

eprintln!();
eprintln!("Cits:");
let cit_pos = isr.read_cits_pos()?.to_owned();
let iter_cit_names = isr.read_cits_names()?;
for (i, (pos, name)) in cit_pos.iter().cloned().zip(iter_cit_names).enumerate() {
eprintln!("{}: Y:{},X:{} {:?}", i, pos.y(), pos.x(), render_str::<lang::EN>(name));
}

Ok(())
}
2 changes: 1 addition & 1 deletion bin/mw_datatool/src/cmd/map_ascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn main(common: &CommonArgs, _args: &MapAsciiArgs) -> AnyResult<()> {

let (_, mut isr) = mfr.read_is()?;
let map: MapDataTopo<MapGenTileData> = isr.read_map_dyntopo(Some(&mut scratch), false)?;
let cits = isr.read_cits()?;
let cits = isr.read_cits_pos()?;

fn f_tile_ascii(cits: &[Pos], pos: Pos, kind: TileKind) -> u8 {
if cits.iter().position(|p| *p == pos).is_some() {
Expand Down
5 changes: 3 additions & 2 deletions bin/mw_datatool/src/cmd/reencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ fn reencode<R: Read + Seek, W: Write + Seek>(reader: R, writer: W, args: &Reenco
}
};

let cits = isr.read_cits()?;
let b_is = b_is.with_cits(cits.iter().cloned())?;
let cit_pos = isr.read_cits_pos()?.to_owned();
let iter_cit_names = isr.read_cits_names()?;
let b_is = b_is.with_cits(cit_pos.iter().cloned().zip(iter_cit_names))?;

let b_is = if args.anonymize || isr.is_anonymized() {
b_is.with_anonymous_players(isr.n_players())?
Expand Down
18 changes: 14 additions & 4 deletions doc/src/tech/dataformat-player.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ It begins with a header:
- `u8`: map size (radius)
- `u8`: number of players
- `u8`: number of cities/regions
- `u16`: length of the whole Initialization Sequence / offset at which Messages will start
- `u16`: length of player names data (0 for an anonymized stream)
- `u32`: length of compressed map data in bytes
- `u16`: length of the Rules data
- `u16`: length of the Cits names data
- `u16`: length of the player names data (0 for an anonymized stream)
- `u16`: (reserved)

The `flags` field is encoded as follows:

Expand Down Expand Up @@ -108,9 +110,17 @@ Hex example:
After the map data, regions are encoded the same way: one byte per tile, in
concentric ring order. The byte is the city/region ID for that tile.

### City Locations
### City Info

Then follows the list of city coordinates.
First, locations for each city on the map:
- `(u8, u8)`: (y, x) location

Then, names for each city on the map:
- `u8`: length in bytes
- …: phonemes

The name uses a special Phoneme encoding (undocumented, see source code),
which can be rendered/localized based on client language.

### Player Names

Expand Down
1 change: 1 addition & 0 deletions lib/mw_common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ pub mod algo;
pub mod driver;
pub mod grid;
pub mod plid;
pub mod phoneme;
pub mod game;
Loading

0 comments on commit 3a85db6

Please sign in to comment.