1 #ifndef _OVERHEAD_MAP_CLASS_ 2 #define _OVERHEAD_MAP_CLASS_ 3 /* 4 5 Copyright (C) 1991-2001 and beyond by Bungie Studios, Inc. 6 and the "Aleph One" developers. 7 8 This program is free software; you can redistribute it and/or modify 9 it under the terms of the GNU General Public License as published by 10 the Free Software Foundation; either version 3 of the License, or 11 (at your option) any later version. 12 13 This program is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 This license is contained in the file "COPYING", 19 which is included with this source code; it is available online at 20 http://www.gnu.org/licenses/gpl.html 21 22 Overhead-Map Base Class and Data, 23 by Loren Petrich, 24 August 3, 2000 25 26 The definitions had been moved out of overhead_map.c and overhead_map_macintosh.c 27 28 Dec 17, 2000 (Loren Petrich): 29 Added font abstraction 30 */ 31 32 #include "cseries.h" 33 #include "world.h" 34 #include "map.h" 35 #include "monsters.h" 36 #include "overhead_map.h" 37 #include "shape_descriptors.h" 38 #include "shell.h" 39 #include "FontHandler.h" 40 41 42 /* ---------- constants */ 43 44 enum /* polygon colors */ 45 { 46 _polygon_color, 47 _polygon_platform_color, 48 _polygon_water_color, 49 _polygon_lava_color, 50 _polygon_sewage_color, 51 _polygon_jjaro_color, // LP addition 52 _polygon_goo_color, // LP: PfhorSlime moved down here 53 _polygon_hill_color, 54 _polygon_minor_ouch_color, // LP, AlexJS: these two added for M1 compatibility 55 _polygon_major_ouch_color, 56 _polygon_teleporter_color, 57 NUMBER_OF_POLYGON_COLORS, 58 // For backwards compatibility: all those before the "ouch" colors 59 NUMBER_OF_OLD_POLYGON_COLORS = _polygon_hill_color + 1 60 }; 61 62 enum /* line colors */ 63 { 64 _solid_line_color, 65 _elevation_line_color, 66 _control_panel_line_color, 67 NUMBER_OF_LINE_DEFINITIONS 68 }; 69 70 // LP change: Items and monsters were interchanged to get the aliens 71 // closer to the civilians 72 73 enum /* thing colors */ 74 { 75 _civilian_thing, 76 _monster_thing, 77 _item_thing, 78 _projectile_thing, 79 _checkpoint_thing, 80 NUMBER_OF_THINGS 81 }; 82 83 enum 84 { 85 _rectangle_thing, 86 _circle_thing 87 }; 88 89 90 // Data constituents 91 92 // Note: all the colors were changed from RGBColor to rgb_color, 93 // which has the same members (3 unsigned shorts), but which is intended to be more portable. 94 95 struct line_definition 96 { 97 rgb_color color; 98 short pen_sizes[OVERHEAD_MAP_MAXIMUM_SCALE-OVERHEAD_MAP_MINIMUM_SCALE+1]; 99 }; 100 101 struct thing_definition 102 { 103 rgb_color color; 104 short shape; 105 short radii[OVERHEAD_MAP_MAXIMUM_SCALE-OVERHEAD_MAP_MINIMUM_SCALE+1]; 106 }; 107 108 struct entity_definition 109 { 110 short front, rear, rear_theta; 111 }; 112 113 const int NUMBER_OF_ANNOTATION_SIZES = OVERHEAD_MAP_MAXIMUM_SCALE-OVERHEAD_MAP_MINIMUM_SCALE+1; 114 struct annotation_definition 115 { 116 rgb_color color; 117 FontSpecifier Fonts[NUMBER_OF_ANNOTATION_SIZES]; 118 }; 119 120 // For some reason, only one annotation color was ever implemented 121 const int NUMBER_OF_ANNOTATION_DEFINITIONS = 1; 122 123 // Collection of the data used to do the map name 124 struct map_name_definition 125 { 126 rgb_color color; 127 FontSpecifier Font; 128 short offset_down; // from top of screen 129 }; 130 131 // The configuration-data structure itself 132 // Note: there is only one definition of the player-entity shape 133 // instead of one for 134 135 struct OvhdMap_CfgDataStruct 136 { 137 rgb_color polygon_colors[NUMBER_OF_POLYGON_COLORS]; 138 line_definition line_definitions[NUMBER_OF_LINE_DEFINITIONS]; 139 thing_definition thing_definitions[NUMBER_OF_THINGS]; 140 short monster_displays[NUMBER_OF_MONSTER_TYPES]; 141 short dead_monster_displays[NUMBER_OF_COLLECTIONS]; 142 entity_definition player_entity; 143 annotation_definition annotation_definitions[NUMBER_OF_ANNOTATION_DEFINITIONS]; 144 map_name_definition map_name_data; 145 rgb_color path_color; 146 147 // Which of these to show 148 bool ShowAliens; 149 bool ShowItems; 150 bool ShowProjectiles; 151 bool ShowPaths; 152 }; 153 154 155 // Now for the overhead-map-renderer class; 156 // this is to be subclassed for whatever renderers one wants to use. 157 158 class OverheadMapClass 159 { 160 // Auxiliary routines: 161 // The cost function for the checkpoint automap must be static 162 // so it can be called properly 163 void transform_endpoints_for_overhead_map(overhead_map_data &Control); 164 void generate_false_automap(short polygon_index); 165 static int32 false_automap_cost_proc(short source_polygon_index, short line_index, short destination_polygon_index, void *caller_data); 166 void replace_real_automap(void); 167 168 // For the false automap 169 byte *saved_automap_lines, *saved_automap_polygons; 170 171 protected: 172 173 // Text justification 174 enum 175 { 176 _justify_left, 177 _justify_center 178 }; 179 180 // For special overall things begin_overall()181 virtual void begin_overall() {} end_overall()182 virtual void end_overall() {} 183 begin_polygons()184 virtual void begin_polygons() {} draw_polygon(short vertex_count,short * vertices,rgb_color & color)185 virtual void draw_polygon( 186 short vertex_count, 187 short *vertices, 188 rgb_color& color) {} end_polygons()189 virtual void end_polygons() {} 190 begin_lines()191 virtual void begin_lines() {} draw_line(short * vertices,rgb_color & color,short pen_size)192 virtual void draw_line( 193 short *vertices, 194 rgb_color& color, 195 short pen_size) {} end_lines()196 virtual void end_lines() {} 197 begin_things()198 virtual void begin_things() {} draw_thing(world_point2d & center,rgb_color & color,short shape,short radius)199 virtual void draw_thing( 200 world_point2d& center, 201 rgb_color& color, 202 short shape, 203 short radius) {} end_things()204 virtual void end_things() {} 205 draw_player(world_point2d & center,angle facing,rgb_color & color,short shrink,short front,short rear,short rear_theta)206 virtual void draw_player( 207 world_point2d& center, 208 angle facing, 209 rgb_color& color, 210 short shrink, 211 short front, 212 short rear, 213 short rear_theta) {} 214 draw_text(world_point2d & location,rgb_color & color,char * text,FontSpecifier & FontData,short justify)215 virtual void draw_text( 216 world_point2d& location, 217 rgb_color& color, 218 char *text, 219 FontSpecifier& FontData, 220 short justify) {} 221 set_path_drawing(rgb_color & color)222 virtual void set_path_drawing(rgb_color& color) {} draw_path(short step,world_point2d & location)223 virtual void draw_path( 224 short step, // 0: first point 225 world_point2d& location) {} finish_path()226 virtual void finish_path() {} 227 228 // Get vertex with the appropriate transformation: GetVertex(short index)229 static world_point2d& GetVertex(short index) {return get_endpoint_data(index)->transformed;} 230 231 // Get pointer to first vertex GetFirstVertex()232 static world_point2d *GetFirstVertex() {return &GetVertex(0);} 233 234 // Get the vertex stride, for the convenience of OpenGL GetVertexStride()235 static int GetVertexStride() {return sizeof(endpoint_data);} 236 237 private: 238 // Auxiliary functions to be done inline; 239 // these are overloads of the corresponding graphics-API-specific virtual functions 240 // defined earlier. draw_polygon(short vertex_count,short * vertices,short color,short scale)241 void draw_polygon( 242 short vertex_count, 243 short *vertices, 244 short color, 245 short scale) 246 { 247 (void)(scale); 248 if (!(color>=0&&color<NUMBER_OF_POLYGON_COLORS)) return; 249 draw_polygon(vertex_count, vertices, ConfigPtr->polygon_colors[color]); 250 } draw_line(short line_index,short color,short scale)251 void draw_line( 252 short line_index, 253 short color, 254 short scale) 255 { 256 if (!(color>=0&&color<NUMBER_OF_LINE_DEFINITIONS)) return; 257 line_definition& LineDef = ConfigPtr->line_definitions[color]; 258 draw_line(get_line_data(line_index)->endpoint_indexes, 259 LineDef.color, LineDef.pen_sizes[scale-OVERHEAD_MAP_MINIMUM_SCALE]); 260 } draw_thing(world_point2d * center,angle facing,short color,short scale)261 void draw_thing( 262 world_point2d *center, 263 angle facing, 264 short color, 265 short scale) 266 { 267 if (!(color>=0&&color<NUMBER_OF_THINGS)) return; 268 thing_definition& ThingDef = ConfigPtr->thing_definitions[color]; 269 draw_thing(*center, ThingDef.color, ThingDef.shape, 270 ThingDef.radii[scale-OVERHEAD_MAP_MINIMUM_SCALE]); 271 } draw_player(world_point2d * center,angle facing,short color,short scale)272 void draw_player( 273 world_point2d *center, 274 angle facing, 275 short color, 276 short scale) 277 { 278 rgb_color PlayerColor; 279 _get_player_color(color, (RGBColor*)&PlayerColor); 280 281 // Changed to use only one entity shape 282 entity_definition& EntityDef = ConfigPtr->player_entity; 283 draw_player(*center, facing, PlayerColor, 284 OVERHEAD_MAP_MAXIMUM_SCALE-scale, 285 EntityDef.front, EntityDef.rear, EntityDef.rear_theta); 286 } draw_annotation(world_point2d * location,short color,char * text,short scale)287 void draw_annotation( 288 world_point2d *location, 289 short color, 290 char *text, 291 short scale) 292 { 293 if (!(color>=0&&color<NUMBER_OF_ANNOTATION_DEFINITIONS)) return; 294 if (!(scale>=OVERHEAD_MAP_MINIMUM_SCALE&&scale<=OVERHEAD_MAP_MAXIMUM_SCALE)) return; 295 annotation_definition& NoteDef = ConfigPtr->annotation_definitions[color]; 296 draw_text(*location,NoteDef.color, text, 297 NoteDef.Fonts[scale-OVERHEAD_MAP_MINIMUM_SCALE],_justify_left); 298 } draw_map_name(overhead_map_data & Control,char * name)299 void draw_map_name( 300 overhead_map_data &Control, 301 char *name) 302 { 303 map_name_definition& map_name_data = ConfigPtr->map_name_data; 304 world_point2d location; 305 location.x = Control.left + Control.half_width; 306 location.y = Control.top + map_name_data.offset_down; 307 draw_text(location, map_name_data.color, name, 308 map_name_data.Font, _justify_center); 309 } 310 set_path_drawing()311 void set_path_drawing() 312 { 313 set_path_drawing(ConfigPtr->path_color); 314 } 315 316 public: 317 // Pointer to configuration data 318 OvhdMap_CfgDataStruct *ConfigPtr; 319 320 // Needs both the configuration data for displaying the map 321 void Render(overhead_map_data& Control); 322 323 // Constructor (idiot-proofer) OverheadMapClass()324 OverheadMapClass(): ConfigPtr(NULL) {} 325 326 // Destructor ~OverheadMapClass()327 virtual ~OverheadMapClass() {} 328 }; 329 330 331 #endif 332