ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/src/backend/communicator/command_parser/map1a.h
Revision: 1.2
Committed: Mon Oct 25 12:06:57 2010 UTC (16 years ago) by sf-pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +1 -0 lines
Log Message:
be more strict about the protocol

File Contents

# Content
1 /**
2 * S->C: map1a <coord1>[darkness1][face1a][face1b][face1c]<coord2>[darkness2][face2a]...
3 *
4 * This is an update of the map command to support large map sizes.
5 * The old map command supported a maximum map size of 15x15 -
6 * anything larger than that required a new command.
7 *
8 * Given that this larger map now needs 2 bytes for the coordinates -
9 * the same as for the images, trying to optimize one vs the other
10 * does not makes much sense.
11 *
12 * The map1a is an enhancement to the map1 command.
13 *
14 * All data is in standard binary form.
15 */
16 void
17 command_parser::on_map1a (std::istream &args)
18 {
19 while (args.peek () != EOF)
20 {
21 // the coord values are flags + x + y values. The value itself, but
22 // the data represented looks like this:
23 u16 const coord = read_u16 (args);
24
25 // first 6 bits: The x coordinate
26 s16 const coord_x = (coord >> 10) & 63;
27 // next 6 bits: the y coordinate
28 s16 const coord_y = (coord >> 4) & 63;
29 // last 4 bits: MSB - true if we send darkness
30 // MSB-1 - will send floor face
31 // MSB-2 - will send intermediate face
32 // MSB-3 (aka LSB) - will send top face
33 u08 const flags = coord & 15;
34
35 s16 const x = map.x + coord_x;
36 s16 const y = map.y + coord_y;
37
38 auto &cell = map (x, y);
39
40 if (flags)
41 {
42 if (!cell.darkness)
43 cell.darkness = 256;
44
45 if (flags & 8)
46 {
47 if (setup.extmap)
48 {
49 u08 ext;
50
51 do
52 {
53 ext = read_u08 (args);
54 u08 const cmd = ext & 0x7f;
55
56 if (cmd < 4)
57 cell.darkness = 255 - ext * 64 + 1;
58 if (cmd == 5) // health
59 {
60 cell.stat_width = 1;
61 cell.stat_hp = read_u08 (args);
62 }
63 else if (cmd == 6) // monster width
64 {
65 cell.stat_width = read_u08 (args) + 1;
66 }
67 else if (cmd == 0x47)
68 {
69 u08 bytes = read_u08 (args);
70 switch (bytes)
71 {
72 case 1:
73 cell.player = read_u08 (args);
74 break;
75 case 2:
76 cell.player = read_u16 (args);
77 break;
78 case 3:
79 cell.player = read_u24 (args);
80 break;
81 case 4:
82 cell.player = read_u32 (args);
83 break;
84 default:
85 args.ignore (bytes);
86 break;
87 }
88 }
89 else if (cmd == 8) // cell flags
90 cell.flags = read_u08 (args);
91 else if (ext & 0x40) // unknown, multibyte => skip
92 args.ignore (read_u08 (args));
93 }
94 while (ext & 0x80);
95 }
96 else // no extmap
97 cell.darkness = read_u08 (args);
98 }
99
100 for (int z = 0; z < 3; ++z)
101 if (flags & (4 >> z))
102 cell.face[z] = read_u16 (args);
103 }
104 else
105 {
106 // If all the flag values are 0, this then means the space is considered
107 // blocked from view, and should be drawn as black. This conserves
108 // bandwidth for sending blocked spaces, which occur pretty frequently.
109 // Once a space is marked as block, if it re-appears within view, the 3
110 // layers should be marked is blank.
111 cell.clear ();
112 }
113
114 assert (args);
115 }
116 PARSE_END;
117
118 emit map (map);
119 }