void add_edge(vertex* vertices, int id1, int id2, double weight, int* countEdges, double* totalWeights, int* success) { bool valid; vertex* v1; vertex* v2; edge* currEdge; int printf_result = 0; *success = SUCCESS; valid = TRUE; /* no edges between the same vertex */ if (id1 == id2) { printf_result = printf("Error: edge must be between two different vertices\n"); valid = FALSE; } if (valid == TRUE && printf_result >= 0) { v1 = &(vertices[id1]); v2 = &(vertices[id2]); /* check to see if vertex already exists */ if (v1->degree < v2->degree) { currEdge = v1->edges; } else { currEdge = v2->edges; } while (currEdge != NULL && printf_result >= 0) { if ((currEdge->vertexID == v1->id) || (currEdge->vertexID == v2->id)) { printf_result = printf("Error: edge is in the graph\n"); valid = FALSE; } currEdge = currEdge->next; } } if (printf_result >= 0) { if (valid == TRUE) { add_one_edge(v1, v2, weight, success); if (*success) { add_one_edge(v2, v1, weight, success); if (*success) { /* count edge */ *countEdges = *countEdges + 1; *totalWeights = *totalWeights + weight; v1->degree++; v2->degree++; } } } } else { perror(ERROR_PRINTF); *success = FAILURE; } }
void add_segment_edges(automap *am, segment *seg) { int is_grate, no_fade; ubyte color; int sn; int segnum = seg-Segments; int hidden_flag; int ttype,trigger_num; for (sn=0;sn<MAX_SIDES_PER_SEGMENT;sn++) { int vertex_list[4]; hidden_flag = 0; is_grate = 0; no_fade = 0; color = 255; if (seg->children[sn] == -1) { color = am->wall_normal_color; } switch( Segment2s[segnum].special ) { case SEGMENT_IS_FUELCEN: color = BM_XRGB( 29, 27, 13 ); break; case SEGMENT_IS_CONTROLCEN: if (Control_center_present) color = BM_XRGB( 29, 0, 0 ); break; case SEGMENT_IS_ROBOTMAKER: color = BM_XRGB( 29, 0, 31 ); break; } if (seg->sides[sn].wall_num > -1) { trigger_num = Walls[seg->sides[sn].wall_num].trigger; ttype = Triggers[trigger_num].type; if (ttype==TT_SECRET_EXIT) { color = BM_XRGB( 29, 0, 31 ); no_fade=1; goto Here; } switch( Walls[seg->sides[sn].wall_num].type ) { case WALL_DOOR: if (Walls[seg->sides[sn].wall_num].keys == KEY_BLUE) { no_fade = 1; color = am->wall_door_blue; } else if (Walls[seg->sides[sn].wall_num].keys == KEY_GOLD) { no_fade = 1; color = am->wall_door_gold; } else if (Walls[seg->sides[sn].wall_num].keys == KEY_RED) { no_fade = 1; color = am->wall_door_red; } else if (!(WallAnims[Walls[seg->sides[sn].wall_num].clip_num].flags & WCF_HIDDEN)) { int connected_seg = seg->children[sn]; if (connected_seg != -1) { int connected_side = find_connect_side(seg, &Segments[connected_seg]); int keytype = Walls[Segments[connected_seg].sides[connected_side].wall_num].keys; if ((keytype != KEY_BLUE) && (keytype != KEY_GOLD) && (keytype != KEY_RED)) color = am->wall_door_color; else { switch (Walls[Segments[connected_seg].sides[connected_side].wall_num].keys) { case KEY_BLUE: color = am->wall_door_blue; no_fade = 1; break; case KEY_GOLD: color = am->wall_door_gold; no_fade = 1; break; case KEY_RED: color = am->wall_door_red; no_fade = 1; break; default: Error("Inconsistent data. Supposed to be a colored wall, but not blue, gold or red.\n"); } } } } else { color = am->wall_normal_color; hidden_flag = 1; } break; case WALL_CLOSED: // Make grates draw properly if (WALL_IS_DOORWAY(seg,sn) & WID_RENDPAST_FLAG) is_grate = 1; else hidden_flag = 1; color = am->wall_normal_color; break; case WALL_BLASTABLE: // Hostage doors color = am->wall_door_color; break; } } if (segnum==Player_init[Player_num].segnum) color = BM_XRGB(31,0,31); if ( color != 255 ) { // If they have a map powerup, draw unvisited areas in dark blue. if (Players[Player_num].flags & PLAYER_FLAGS_MAP_ALL && (!Automap_visited[segnum])) color = am->wall_revealed_color; Here: get_side_verts(vertex_list,segnum,sn); add_one_edge( am, vertex_list[0], vertex_list[1], color, sn, segnum, hidden_flag, 0, no_fade ); add_one_edge( am, vertex_list[1], vertex_list[2], color, sn, segnum, hidden_flag, 0, no_fade ); add_one_edge( am, vertex_list[2], vertex_list[3], color, sn, segnum, hidden_flag, 0, no_fade ); add_one_edge( am, vertex_list[3], vertex_list[0], color, sn, segnum, hidden_flag, 0, no_fade ); if ( is_grate ) { add_one_edge( am, vertex_list[0], vertex_list[2], color, sn, segnum, hidden_flag, 1, no_fade ); add_one_edge( am, vertex_list[1], vertex_list[3], color, sn, segnum, hidden_flag, 1, no_fade ); } } } }
void add_segment_edges(segment *seg) { int is_grate, no_fade; ubyte color; int sn; int segnum = seg-Segments; int hidden_flag; for (sn=0;sn<MAX_SIDES_PER_SEGMENT;sn++) { short vertex_list[4]; hidden_flag = 0; is_grate = 0; no_fade = 0; color = 255; if (seg->children[sn] == -1) { color = WALL_NORMAL_COLOR; } switch( seg->special ) { case SEGMENT_IS_FUELCEN: color = BM_XRGB( 29, 27, 13 ); break; case SEGMENT_IS_CONTROLCEN: color = BM_XRGB( 29, 0, 0 ); break; case SEGMENT_IS_ROBOTMAKER: color = BM_XRGB( 29, 0, 31 ); break; } if (seg->sides[sn].wall_num > -1) { switch( Walls[seg->sides[sn].wall_num].type ) { case WALL_DOOR: if (Walls[seg->sides[sn].wall_num].keys == KEY_BLUE) { no_fade = 1; color = WALL_DOOR_BLUE; //mprintf((0, "Seg %i, side %i has BLUE wall\n", segnum, sn)); } else if (Walls[seg->sides[sn].wall_num].keys == KEY_GOLD) { no_fade = 1; color = WALL_DOOR_GOLD; //mprintf((0, "Seg %i, side %i has GOLD wall\n", segnum, sn)); } else if (Walls[seg->sides[sn].wall_num].keys == KEY_RED) { no_fade = 1; color = WALL_DOOR_RED; //mprintf((0, "Seg %i, side %i has RED wall\n", segnum, sn)); } else if (!(WallAnims[Walls[seg->sides[sn].wall_num].clip_num].flags & WCF_HIDDEN)) { int connected_seg = seg->children[sn]; if (connected_seg != -1) { int connected_side = find_connect_side(seg, &Segments[connected_seg]); int keytype = Walls[Segments[connected_seg].sides[connected_side].wall_num].keys; if ((keytype != KEY_BLUE) && (keytype != KEY_GOLD) && (keytype != KEY_RED)) color = WALL_DOOR_COLOR; else { switch (Walls[Segments[connected_seg].sides[connected_side].wall_num].keys) { case KEY_BLUE: color = WALL_DOOR_BLUE; no_fade = 1; break; case KEY_GOLD: color = WALL_DOOR_GOLD; no_fade = 1; break; case KEY_RED: color = WALL_DOOR_RED; no_fade = 1; break; default: Error("Inconsistent data. Supposed to be a colored wall, but not blue, gold or red.\n"); } //mprintf((0, "Seg %i, side %i has a colored door on the other side.\n", segnum, sn)); } } } else { color = WALL_NORMAL_COLOR; hidden_flag = 1; //mprintf((0, "Wall at seg:side %i:%i is hidden.\n", seg-Segments, sn)); } break; case WALL_CLOSED: // Make grates draw properly color = WALL_NORMAL_COLOR; is_grate = 1; break; case WALL_BLASTABLE: // Hostage doors color = WALL_DOOR_COLOR; break; } } if (segnum==Player_init[Player_num].segnum) color = BM_XRGB(31,0,31); if ( color != 255 ) { // If they have a map powerup, draw unvisited areas in dark blue. if (Players[Player_num].flags & PLAYER_FLAGS_MAP_ALL && (!Automap_visited[segnum])) color = BM_XRGB( 0, 0, 25 ); get_side_verts(vertex_list,segnum,sn); add_one_edge( vertex_list[0], vertex_list[1], color, (ubyte) sn, (short) segnum, (int) hidden_flag, 0, (int) no_fade ); add_one_edge( vertex_list[1], vertex_list[2], color, (ubyte) sn, (short) segnum, hidden_flag, 0, no_fade ); add_one_edge( vertex_list[2], vertex_list[3], color, (ubyte) sn, (short) segnum, hidden_flag, 0, no_fade ); add_one_edge( vertex_list[3], vertex_list[0], color, (ubyte) sn, (short) segnum, hidden_flag, 0, no_fade ); if ( is_grate ) { add_one_edge( vertex_list[0], vertex_list[2], color, (ubyte) sn, (short) segnum, hidden_flag, 1, no_fade ); add_one_edge( vertex_list[1], vertex_list[3], color, (ubyte) sn, (short) segnum, hidden_flag, 1, no_fade ); } } } }