void veh_interact::move_cursor (int dx, int dy) { mvwputch (w_disp, cy+6, cx+6, cpart >= 0? veh->part_color (cpart) : c_black, special_symbol(cpart >= 0? veh->part_sym (cpart) : ' ')); cx += dx; cy += dy; cpart = part_at (cx, cy); int vdx = -ddx - cy; int vdy = cx - ddy; int vx, vy; veh->coord_translate (vdx, vdy, vx, vy); int vehx = veh->global_x() + vx; int vehy = veh->global_y() + vy; bool obstruct = g->m.move_cost_ter_only (vehx, vehy) == 0; vehicle *oveh = g->m.veh_at (vehx, vehy); if (oveh && oveh != veh) obstruct = true; nc_color col = cpart >= 0? veh->part_color (cpart) : c_black; mvwputch (w_disp, cy+6, cx+6, obstruct? red_background(col) : hilite(col), special_symbol(cpart >= 0? veh->part_sym (cpart) : ' ')); wrefresh (w_disp); werase (w_parts); veh->print_part_desc (w_parts, 0, winw2, cpart, -1); wrefresh (w_parts); can_mount.clear(); has_mats.clear(); if (!obstruct) for (int i = 1; i < num_vparts; i++) { if (veh->can_mount (vdx, vdy, (vpart_id) i)) can_mount.push_back (i); } need_repair.clear(); parts_here.clear(); ptank = -1; if (cpart >= 0) { parts_here = veh->internal_parts(cpart); parts_here.insert (parts_here.begin(), cpart); for (int i = 0; i < parts_here.size(); i++) { int p = parts_here[i]; if (veh->parts[p].hp < veh->part_info(p).durability) need_repair.push_back (i); if (veh->part_flag(p, vpf_fuel_tank) && veh->parts[p].amount < veh->part_info(p).size) ptank = p; } } has_fuel = ptank >= 0? g->pl_refill_vehicle(*veh, ptank, true) : false; werase (w_msg); wrefresh (w_msg); display_mode (' '); }
/** * Draws the list of parts that can be mounted in the selected square. Used * when installing new parts or changing tires. * @param pos The current cursor position in the list. * @param list The list to display parts from. */ void veh_interact::display_list (int pos, std::vector<vpart_info> list) { werase (w_list); int page = pos / page_size; for (int i = page * page_size; i < (page + 1) * page_size && i < list.size(); i++) { int y = i - page * page_size; itype_id itm = list[i].item; bool has_comps = crafting_inv.has_amount(itm, 1); bool has_skill = g->u.skillLevel("mechanics") >= list[i].difficulty; bool is_wheel = list[i].has_flag("WHEEL"); nc_color col = has_comps && (has_skill || is_wheel) ? c_white : c_dkgray; mvwprintz(w_list, y, 3, pos == i ? hilite (col) : col, list[i].name.c_str()); mvwputch (w_list, y, 1, list[i].color, special_symbol(list[i].sym)); } wrefresh (w_list); }
void veh_interact::display_list (int pos) { werase (w_list); int page = pos / page_size; for (int i = page * page_size; i < (page + 1) * page_size && i < can_mount.size(); i++) { int y = i - page * page_size; itype_id itm = vpart_list[can_mount[i]].item; bool has_comps = crafting_inv.has_amount(itm, 1); bool has_skill = g->u.skillLevel("mechanics") >= vpart_list[can_mount[i]].difficulty; nc_color col = has_comps && has_skill? c_white : c_dkgray; mvwprintz(w_list, y, 3, pos == i? hilite (col) : col, vpart_list[can_mount[i]].name); mvwputch (w_list, y, 1, vpart_list[can_mount[i]].color, special_symbol (vpart_list[can_mount[i]].sym)); } wrefresh (w_list); }
void veh_interact::display_veh () { int x1 = 12, y1 = 12, x2 = -12, y2 = -12; for (int ep = 0; ep < veh->external_parts.size(); ep++) { int p = veh->external_parts[ep]; if (veh->parts[p].mount_dx < x1) x1 = veh->parts[p].mount_dx; if (veh->parts[p].mount_dy < y1) y1 = veh->parts[p].mount_dy; if (veh->parts[p].mount_dx > x2) x2 = veh->parts[p].mount_dx; if (veh->parts[p].mount_dy > y2) y2 = veh->parts[p].mount_dy; } ddx = 0; ddy = 0; if (x2 - x1 < 11) { x1--; x2++; } if (y2 - y1 < 11 ) { y1--; y2++; } if (x1 < -5) ddx = -5 - x1; else if (x2 > 6) ddx = 6 - x2; if (y1 < -6) ddy = -6 - y1; else if (y2 > 5) ddy = 5 - y2; for (int ep = 0; ep < veh->external_parts.size(); ep++) { int p = veh->external_parts[ep]; long sym = veh->part_sym (p); nc_color col = veh->part_color (p); int y = -(veh->parts[p].mount_dx + ddx); int x = veh->parts[p].mount_dy + ddy; mvwputch (w_disp, 6+y, 6+x, cx == x && cy == y? hilite(col) : col, special_symbol(sym)); if (cx == x && cy == y) cpart = p; } wrefresh (w_disp); }
/** * Draws the viewport with the vehicle in it on the left side of the window. */ void veh_interact::display_veh () { werase(w_disp); //Iterate over structural parts so we only hit each square once std::vector<int> structural_parts = veh->all_parts_at_location("structure"); for (int i = 0; i < structural_parts.size(); i++) { const int p = structural_parts[i]; long sym = veh->part_sym (p); nc_color col = veh->part_color (p); int y = -(veh->parts[p].mount_dx + ddx); int x = veh->parts[p].mount_dy + ddy; if(x == 0 && y == 0) { col = hilite(col); cpart = p; } mvwputch (w_disp, 6 + y, 6 + x, col, special_symbol(sym)); } wrefresh (w_disp); }
/** * Moves the cursor on the vehicle editing window. * @param dx How far to move the cursor on the x-axis. * @param dy How far to move the cursor on the y-axis. */ void veh_interact::move_cursor (int dx, int dy) { mvwputch (w_disp, cursor_y + 6, cursor_x + 6, cpart >= 0 ? veh->part_color (cpart) : c_black, special_symbol(cpart >= 0 ? veh->part_sym (cpart) : ' ')); cursor_x += dx; cursor_y += dy; cpart = part_at (cursor_x, cursor_y); int vdx = -ddx - cursor_y; int vdy = cursor_x - ddy; int vx, vy; veh->coord_translate (vdx, vdy, vx, vy); int vehx = veh->global_x() + vx; int vehy = veh->global_y() + vy; bool obstruct = g->m.move_cost_ter_furn (vehx, vehy) == 0; vehicle *oveh = g->m.veh_at (vehx, vehy); if (oveh && oveh != veh) { obstruct = true; } nc_color col = cpart >= 0 ? veh->part_color (cpart) : c_black; mvwputch (w_disp, cursor_y + 6, cursor_x + 6, obstruct ? red_background(col) : hilite(col), special_symbol(cpart >= 0 ? veh->part_sym (cpart) : ' ')); wrefresh (w_disp); werase (w_parts); veh->print_part_desc (w_parts, 0, winw2, cpart, -1); wrefresh (w_parts); can_mount.clear(); if (!obstruct) { for (std::map<std::string, vpart_info>::iterator part_type_iterator = vehicle_part_types.begin(); part_type_iterator != vehicle_part_types.end(); ++part_type_iterator) { if (veh->can_mount (vdx, vdy, part_type_iterator->first)) { can_mount.push_back (part_type_iterator->second); } } } need_repair.clear(); parts_here.clear(); ptank = NULL; wheel = NULL; if (cpart >= 0) { //Misleading, internal_parts actually returns all parts at that square parts_here = veh->internal_parts(cpart); parts_here.insert (parts_here.begin(), cpart); for (int i = 0; i < parts_here.size(); i++) { int p = parts_here[i]; if (veh->parts[p].hp < veh->part_info(p).durability) { need_repair.push_back (i); } if (veh->part_flag(p, "FUEL_TANK") && veh->parts[p].amount < veh->part_info(p).size) { ptank = &veh->parts[p]; } if (veh->part_flag(p, "WHEEL") && veh->parts[p].amount < veh->part_info(p).size) { wheel = &veh->parts[p]; } } } has_fuel = ptank != NULL ? g->refill_vehicle_part(*veh, ptank, true) : false; werase (w_msg); wrefresh (w_msg); display_mode (' '); }
/** * Moves the cursor on the vehicle editing window. * @param dx How far to move the cursor on the x-axis. * @param dy How far to move the cursor on the y-axis. */ void veh_interact::move_cursor (int dx, int dy) { mvwputch (w_disp, 6, 6, cpart >= 0 ? veh->part_color (cpart) : c_black, special_symbol(cpart >= 0 ? veh->part_sym (cpart) : ' ')); ddx += dy; ddy -= dx; display_veh(); cpart = part_at (0, 0); int vdx = -ddx; int vdy = -ddy; int vx, vy; veh->coord_translate (vdx, vdy, vx, vy); int vehx = veh->global_x() + vx; int vehy = veh->global_y() + vy; bool obstruct = g->m.move_cost_ter_furn (vehx, vehy) == 0; vehicle *oveh = g->m.veh_at (vehx, vehy); if (oveh && oveh != veh) { obstruct = true; } nc_color col = cpart >= 0 ? veh->part_color (cpart) : c_black; mvwputch (w_disp, 6, 6, obstruct ? red_background(col) : hilite(col), special_symbol(cpart >= 0 ? veh->part_sym (cpart) : ' ')); wrefresh (w_disp); werase (w_parts); veh->print_part_desc (w_parts, 0, parts_w, cpart, -1); wrefresh (w_parts); can_mount.clear(); if (!obstruct) { for (std::map<std::string, vpart_info>::iterator part_type_iterator = vehicle_part_types.begin(); part_type_iterator != vehicle_part_types.end(); ++part_type_iterator) { if (veh->can_mount (vdx, vdy, part_type_iterator->first)) { can_mount.push_back (part_type_iterator->second); } } } //Only build the wheel list once if(wheel_types.empty()) { for (std::map<std::string, vpart_info>::iterator part_type_iterator = vehicle_part_types.begin(); part_type_iterator != vehicle_part_types.end(); ++part_type_iterator) { if (part_type_iterator->second.has_flag("WHEEL")) { wheel_types.push_back (part_type_iterator->second); } } } need_repair.clear(); parts_here.clear(); ptank = NULL; wheel = NULL; if (cpart >= 0) { parts_here = veh->parts_at_relative(veh->parts[cpart].mount_dx, veh->parts[cpart].mount_dy); for (int i = 0; i < parts_here.size(); i++) { int p = parts_here[i]; if (veh->parts[p].hp < veh->part_info(p).durability) { need_repair.push_back (i); } if (veh->part_flag(p, "FUEL_TANK") && veh->parts[p].amount < veh->part_info(p).size) { ptank = &veh->parts[p]; } if (veh->part_flag(p, "WHEEL")) { wheel = &veh->parts[p]; } } } has_fuel = ptank != NULL ? g->refill_vehicle_part(*veh, ptank, true) : false; werase (w_msg); wrefresh (w_msg); display_mode (' '); }
//main function int main() { initialize_Symbol_Table(); remove("a4_1.out"); char input[1000]; token t; int i; //loop for rading lines of source code into input buffer while(gets(input)) { lexemeBegin = 0; while(input[lexemeBegin]!='\0'&&input[lexemeBegin]!='\n' &&input[lexemeBegin]!='\r') //while end of line is not found { while(input[lexemeBegin]==' ' || input[lexemeBegin] == '\t') lexemeBegin++; //checking for keywords and identifiers t = identifier_keyword(input); if(t.tokenID!=NOTOK) { write_token(t); continue; } //checking for integer constants t = integer_constant(input); if(t.tokenID!=NOTOK) { write_token(t); continue; } //checking for floating point number constants t = float_constant(input); if(t.tokenID!=NOTOK) { write_token(t); continue; } //checking for arithmetic operators t = arithmetic_operator(input); if(t.tokenID!=NOTOK) { write_token(t); continue; } //checking for assignment operators t = assignment_operator(input); if(t.tokenID!=NOTOK) { write_token(t); continue; } //checking for relational operators t = relational_operator(input); if(t.tokenID!=NOTOK) { write_token(t); continue; } //checking for special symbols t = special_symbol(input); if(t.tokenID!=NOTOK) { write_token(t); continue; } //checking for comments comment(input); //checking erroneous lexeme error_condition(input); } } }