| 1162 | } |
| 1163 | |
| 1164 | pub fn manager_viewer_message(&self) -> String { |
| 1165 | let earth_map = &self.world.planet_maps[&Earth]; |
| 1166 | let earth_units = &self.world.planet_states.get(&Earth); |
| 1167 | let mars_map = &self.world.planet_maps[&Mars]; |
| 1168 | let mars_units = &self.world.planet_states.get(&Mars); |
| 1169 | let eh = earth_map.height; |
| 1170 | let ew = earth_map.width; |
| 1171 | let mh = mars_map.height; |
| 1172 | let mw = mars_map.width; |
| 1173 | |
| 1174 | let mut message = ManagerViewMessage { |
| 1175 | earth_width: ew as u32, |
| 1176 | earth_height: eh as u32, |
| 1177 | mars_width: mw as u32, |
| 1178 | mars_height: mh as u32, |
| 1179 | earth: vec![0; 2*ew*eh], |
| 1180 | mars: vec![0; 2*mw*mh], |
| 1181 | // backcompat |
| 1182 | width: ew as u32, |
| 1183 | height: eh as u32, |
| 1184 | }; |
| 1185 | |
| 1186 | for x in 0..ew { |
| 1187 | for y in 0..eh { |
| 1188 | let loc = MapLocation::new(Earth, x as i32, y as i32); |
| 1189 | if let Some(id) = earth_units.and_then(|eu| eu.units_by_loc.get(&loc)) { |
| 1190 | let unit = &earth_units.unwrap().units[&id]; |
| 1191 | let unit_int = match unit.unit_type() { |
| 1192 | Worker => 1, |
| 1193 | Knight => 2, |
| 1194 | Ranger => 3, |
| 1195 | Mage => 4, |
| 1196 | Healer => 5, |
| 1197 | Factory => 6, |
| 1198 | Rocket => 7, |
| 1199 | }; |
| 1200 | let team_int = match unit.team() { |
| 1201 | Red => 0, |
| 1202 | Blue => 1, |
| 1203 | }; |
| 1204 | message.earth[(x+y*ew)*2] = unit_int; |
| 1205 | message.earth[(x+y*ew)*2+1] = team_int; |
| 1206 | } else if !earth_map.is_passable_terrain[y as usize][x as usize] { |
| 1207 | message.earth[(x+y*ew)*2] = 8; |
| 1208 | message.earth[(x+y*ew)*2+1] = 3; |
| 1209 | } else { |
| 1210 | message.earth[(x+y*ew)*2] = 0; |
| 1211 | message.earth[(x+y*ew)*2+1] = 3; |
| 1212 | } |
| 1213 | } |
| 1214 | } |
| 1215 | for x in 0..mw { |
| 1216 | for y in 0..mh { |
| 1217 | let loc = MapLocation::new(Mars, x as i32, y as i32); |
| 1218 | if let Some(id) = mars_units.and_then(|mu| mu.units_by_loc.get(&loc)) { |
| 1219 | let unit = &mars_units.unwrap().units[&id]; |
| 1220 | let unit_int = match unit.unit_type() { |
| 1221 | Worker => 1, |