void check_color(void) { if (global_color != current_color) { fprintf(output_file, "\\psset{linecolor=%s}\n", color_string(global_color)); current_color = global_color; } if (local_color != current_color) { linecolor = color_string(local_color); nargs++; } }
void glyph::load_data_text(std::istream &datastream, std::string owner_name) { std::string fgtmp, bgtmp; char tmpch; datastream >> tmpch >> fgtmp >> bgtmp; symbol = tmpch; fg = color_string(fgtmp); if (fg == c_null) { debugmsg("Loaded bad color '%s' (%s)", fgtmp.c_str(), owner_name.c_str()); } bg = color_string(bgtmp); if (bg == c_null) { debugmsg("Loaded bad color '%s' (%s)", fgtmp.c_str(), owner_name.c_str()); } }
void print(int s) { /* Print the contents of the stack for the user. */ char buf[FILEPATH_MAX]; int i, stack_size; soc_w(s, CMD_SIZE); soc_r(s, buf, MSG_MAX); stack_size = atoi(buf); printf("%d file%s in stack\n", stack_size, PLURALS(stack_size)); for( i = 0; i < stack_size; i++ ) { soc_w(s, CMD_PICK); if( !read_status_okay(s) ) { soc_r(s, buf, FILEPATH_MAX); printf("received error `%s'\n", buf); exit(EXIT_FAILURE); } sprintf(buf, "%d", i); soc_w(s, buf); if( !read_status_okay(s) ) { soc_r(s, buf, FILEPATH_MAX); printf("error: `%s'\n", buf); exit(EXIT_FAILURE); } soc_r(s, buf, FILEPATH_MAX); char *filecolr = color_string(COLR_PATH, buf); printf("%d: %s\n", i+1, filecolr); free(filecolr); } }
static void drv_drawEllipse(double xcf, double ycf, double xrf, double yrf, mg_color_t color, double weight) { fprintf(fout, "<ellipse cx=\"%fin\" cy=\"%fin\" rx=\"%fin\" ry=\"%fin\" stroke=\"%s\" opacity=\"%s\" fill=\"none\" stroke-width=\"%fin\"/>\n", xcf, ycf, xrf, yrf, color_string(color), alpha_string(color), weight); }
static void drv_drawFilledEllipse(double xcf, double ycf, double xrf, double yrf, mg_color_t color) { fprintf(fout, "<ellipse cx=\"%fin\" cy=\"%fin\" rx=\"%fin\" ry=\"%fin\" fill=\"%s\" opacity=\"%s\"/>\n", xcf, ycf, xrf, yrf, color_string(color), alpha_string(color)); }
void put_font(void) { if (local_color != current_fontcolor) { fprintf(output_file, "\\%s", color_string(local_color)); if (!local_font) putc(' ', output_file); } if (local_font) fprintf(output_file, "\\%s ", local_font_desc); }
/* * returns a QString with a preset color * Colors are in 24-bit hex RGB format (#000000 - #FFFFFF) * Keep this current with preset_colors table in tables.c. */ QString color_string(QString msg, byte color_num) { // Paranoia if (color_num >= MAX_COLORS) color_num = TERM_WHITE; QColor msg_color = defined_colors[color_num]; return (color_string(msg, msg_color)); }
int save_game(char * path, settings * game_settings) { FILE * fp; mxml_node_t * tree; mxml_node_t * game_node; mxml_node_t * board_node; cord c; char row_name[6] = "row_x"; char row[9] = { 0 }; fp = fopen(path, "w"); if (fp == NULL) return FALSE; tree = mxmlNewXML("1.0"); game_node = mxmlNewElement(tree, "game"); mxmlNewInteger(mxmlNewElement(game_node, "game_mode"), game_settings->mode); mxmlNewOpaque(mxmlNewElement(game_node, "user_color"), color_string(game_settings->color)); mxmlNewOpaque(mxmlNewElement(game_node, "next_turn"), color_string(game_settings->next)); if (game_settings->minimax_depth == BEST_DIFFICULTY) mxmlNewOpaque(mxmlNewElement(game_node, "user_color"), "best"); else mxmlNewInteger(mxmlNewElement(game_node, "difficulty"), game_settings->minimax_depth); board_node = mxmlNewElement(game_node, "board"); for (int y = 8; y > 0; y--) { for (int x = 0; x < 8; x++) { c.x = x; c.y = y - 1; row[x] = (board_piece(game_settings->board, c) == EMPTY) ? '_' : board_piece(game_settings->board, c); } row_name[4] = '0' + y; mxmlNewOpaque(mxmlNewElement(board_node, row_name), row); } mxmlSaveFile(tree, fp, MXML_NO_CALLBACK); fclose(fp); mxmlDelete(tree); return TRUE; }
void check_hatch(double a) { hatched = 1; hatchangle = a; nargs++; if (global_color != current_hatchcolor) { fprintf(output_file, "\\psset{hatchcolor=%s}\n", color_string(global_color)); current_hatchcolor = global_color; } if (local_color != current_hatchcolor) { hatchcolor = color_string(local_color); nargs++; } if (global_size != current_hatchsep) { fprintf(output_file, "\\psset{hatchsep=%gpt}\n", HATCHSEP*global_size); current_hatchsep = global_size; } if (local_size != current_hatchsep) { hatchsep = HATCHSEP*local_size; nargs++; } }
void check_font(void) { if (global_color != current_fontcolor || (global_font && default_font)) { fprintf(output_file, "\\bgroup"); if (global_color != current_fontcolor) { fprintf(output_file, "\\%s", color_string(global_color)); current_fontcolor = global_color; } if (global_font && default_font) { fprintf(output_file, "\\%s", global_font_desc); default_font = 0; } putc('\n', output_file); } }
static void drv_drawText(struct mg_font* fnt, double xf, double yf, const unsigned char* utf8str, mg_color_t color) { mg_rectf_t t; if (!fnt || !utf8str) return; drv_getTextSize(fnt, utf8str, &t); yf += t.h; fprintf(fout, "<text x=\"%fin\" y=\"%fin\" font-size=\"%f\" font-family=\"%s\" fill=\"%s\" dominant-baseline=\"text-after-edge\" opacity=\"%s\">\n", xf, yf, fnt->size*96.0, fnt->name, color_string(color), alpha_string(color)); fprintf(fout, "%s</text>", utf8str); }
static void drv_drawFilledRect(const mg_rectf_t* r, mg_color_t color) { if (!r) { mg_rectf_t t; t.x = t.y = 0; t.w = width; t.h = height; drv_drawFilledRect(&t, color); } else { fprintf(fout, "<rect x=\"%fin\" y=\"%fin\" width=\"%fin\" height=\"%fin\" stroke=\"none\" fill=\"%s\" opacity=\"%s\"/>\n", r->x, r->y, r->w, r->h, color_string(color), alpha_string(color)); } }
void push(int s, char *file) { /* Instruct daemon to push <file> onto the stack. Terminate on error. */ char buf[FILEPATH_MAX], *fullpath, *prefix="push:"; int okay; soc_w(s, CMD_PUSH); okay = read_status_okay(s); if( !okay ) { if( soc_r(s, buf, FILEPATH_MAX) <= 0 ) { fprintf(stderr, "%s quitting for read error\n", prefix); exit(EXIT_FAILURE); } printf("Could not push; received error: `%s'\n", buf); exit(EXIT_FAILURE); } fullpath = abs_path(file); if( fullpath == NULL ) { fprintf(stderr, "%s: file `%s' does not exist\n", program_name, file); exit(EXIT_FAILURE); } soc_w(s, fullpath); okay = read_status_okay(s); if( soc_r(s, buf, FILEPATH_MAX) <= 0 ) { fprintf(stderr, "%s quitting for read error\n", prefix); exit(EXIT_FAILURE); } if( !okay ) { printf("received error `%s' (stack state debatable)\n", buf); } else { if( strcmp(buf, fullpath) != 0 ) { fprintf(stderr, "%s error: path sent not the same as path pushed\n", prefix); exit(EXIT_FAILURE); } char *fullpathcolr = color_string(COLR_PATH, fullpath); printf("Pushed `%s'\n", fullpathcolr); free(fullpathcolr); } free(fullpath); }
/* * Describe fake ego item "lore" */ QString desc_ego_fake(int ego_num, QString object_string, bool display) { /* Hack: dereference the join */ QString xtra[10] = { "sustains", "higher resistances", "abilities", "immunities", "stat increases", "slays", "*slays*", "elemental brands", "elemental resists", "native abilities"}; ego_item_type *e_ptr = &e_info[ego_num]; object_type dummy; object_type *o_ptr = &dummy; /* List ego flags */ int k_idx = find_first_ego_match(ego_num); if (!k_idx) return ("No match"); make_object_fake(o_ptr, k_idx, ego_num, TRUE); o_ptr->xtra2 = 0; o_ptr->update_object_flags(); QString output = color_string(QString("<big><b>%1 %2</b></big><br>") .arg(object_string) .arg(e_ptr->e_name), TERM_BLUE); if (e_ptr->e_text.length()) { output.append(QString("<br>%1<br>") .arg(e_ptr->e_text)); } output.append(object_info_out(o_ptr, FALSE, FALSE)); if (e_ptr->xtra) { output.append(QString("<br>It provides one or more random %1.<br>") .arg(xtra[e_ptr->xtra - 1])); } if (e_ptr->e_flags3 & (TR3_PERMA_CURSE)) output.append("It is permanently cursed."); else if (e_ptr->e_flags3 & (TR3_HEAVY_CURSE)) output.append("It is heavily cursed."); if (e_ptr->e_flags3 & (TR3_LIGHT_CURSE)) output.append("It is cursed."); /* Finally, display it */ if (display) display_info_window(DISPLAY_INFO_OBJECT, o_ptr->k_idx, output); return(output); }
TargetCommandList::TargetCommandList(void): NPPDialog() { central = new QWidget; QPointer<QVBoxLayout> main_layout = new QVBoxLayout; central->setLayout(main_layout); main_layout->setSpacing(10); this->setClient(central); // IMPORTANT: it must be called AFTER setting the layout QPointer<QLabel> targeting_prompt = new QLabel(color_string(QString("<h2>Targeting Commands</h2>"), TERM_BLUE)); main_layout->addWidget(targeting_prompt, Qt::AlignCenter); QPointer<QHBoxLayout> top_across = new QHBoxLayout; main_layout->addLayout(top_across); QPointer<QVBoxLayout> vlay_key_dirs = new QVBoxLayout; add_dir_targeting(vlay_key_dirs, TRUE); top_across->addLayout(vlay_key_dirs); top_across->addStretch(1); QPointer<QVBoxLayout> vlay_pad_dirs = new QVBoxLayout; add_dir_targeting(vlay_pad_dirs, FALSE); top_across->addLayout(vlay_pad_dirs); top_across->addStretch(1); QPointer<QGridLayout> glay_target_commands = new QGridLayout; add_targeting_commands(glay_target_commands); main_layout->addLayout(glay_target_commands); QDialogButtonBox buttons; buttons.setStandardButtons(QDialogButtonBox::Ok); connect(&buttons, SIGNAL(accepted()), this, SLOT(close())); main_layout->addWidget(&buttons); main_layout->addStretch(1); setWindowTitle(tr("Targeting Command List")); this->clientSizeUpdated(); this->exec(); }
WizardModeDialog::WizardModeDialog(void) { int row = 0; // Paranoia if (!p_ptr->playing) return; if (!p_ptr->is_wizard) { QString prompt = color_string(QString ("<b><big>You are about to use 'Wizard Mode' commands.</big></b><br><br>"), TERM_RED); prompt.append("Wizard Mode contains many powerful 'cheat' commands. "); prompt.append("Your savefile will be marked as a wizard mode character and will not be scored.<br><br>"); prompt.append("Really use Wizard Mode?"); if (!get_check(prompt)) return; p_ptr->is_wizard = TRUE; } main_prompt = new QLabel(QString("<b><big>Please select a command</big></b><br>")); main_prompt->setAlignment(Qt::AlignCenter); QPointer<QVBoxLayout> vlay = new QVBoxLayout; vlay->addWidget(main_prompt); // Add the player related commands QPointer<QGridLayout> wizard_layout = new QGridLayout; player_section = new QLabel("<b>Player commands</b>"); player_section->setAlignment(Qt::AlignCenter); wizard_layout->addWidget(player_section, row, 1); row++; // Add the "cure all" button QPointer<QPushButton> heal_button = new QPushButton("Heal Player"); heal_button->setToolTip("Completely heal and restore the player."); connect(heal_button, SIGNAL(clicked()), this, SLOT(wiz_cure_all())); wizard_layout->addWidget(heal_button, row, 0); // Add the "know all" button QPointer<QPushButton> know_button = new QPushButton("Know All"); know_button->setToolTip("Know everything about every feature, object, and monster in the game."); connect(know_button, SIGNAL(clicked()), this, SLOT(wiz_know_all())); wizard_layout->addWidget(know_button, row, 1); // Add the "jump" button QPointer<QPushButton> jump_button = new QPushButton("Jump To New Level"); jump_button->setToolTip("Allow the player to instantly jump to any level in the dungeon."); connect(jump_button, SIGNAL(clicked()), this, SLOT(wiz_jump())); wizard_layout->addWidget(jump_button, row, 2); row++; // Add the "teleport_to_target" button QPointer<QPushButton> teleport_target_button = new QPushButton("Teleport To Targeted Spot"); teleport_target_button->setToolTip("Teleports the player to a specified spot on the dungeon level."); connect(teleport_target_button, SIGNAL(clicked()), this, SLOT(wiz_teleport_to_target())); wizard_layout->addWidget(teleport_target_button, row, 0); // Add the "phase door" button QPointer<QPushButton> phase_door = new QPushButton("Phase Door"); phase_door->setToolTip("Teleports the player to a random spot up to 10 squares away."); connect(phase_door, SIGNAL(clicked()), this, SLOT(wiz_phase_door())); wizard_layout->addWidget(phase_door, row, 1); // Add the "teleport" button QPointer<QPushButton> teleport = new QPushButton("Teleport"); teleport->setToolTip("Teleports the player to a random spot up to 100 squares away."); connect(teleport, SIGNAL(clicked()), this, SLOT(wiz_teleport())); wizard_layout->addWidget(teleport, row, 2); row++; // Add the "edit character" button QPointer<QPushButton> edit_character = new QPushButton("Edit Character"); edit_character->setToolTip("Edit character statistics, experience, gold, and fame."); connect(edit_character, SIGNAL(clicked()), this, SLOT(wiz_edit_character())); wizard_layout->addWidget(edit_character, row, 0); // Add the "know all" button QPointer<QPushButton> spoil_button = new QPushButton("Print Spoilers"); spoil_button->setToolTip("Print out Spoilers for all Monsters, objects, artifacts, and terrain."); connect(spoil_button, SIGNAL(clicked()), this, SLOT(wiz_print_spoilers())); wizard_layout->addWidget(spoil_button, row, 1); row++; // Add the dungeon commands dungeon_section = new QLabel("<b>Dungeon commands</b>"); dungeon_section->setAlignment(Qt::AlignCenter); wizard_layout->addWidget(dungeon_section, row, 1); row++; // Add the "summon" button QPointer<QPushButton> summon_button = new QPushButton("Summon Monster"); summon_button->setToolTip("Summon one random monster."); connect(summon_button, SIGNAL(clicked()), this, SLOT(wiz_summon())); wizard_layout->addWidget(summon_button, row, 0); // Add the "banish" button QPointer<QPushButton> banish_button = new QPushButton("Banish Monsters"); banish_button->setToolTip("Erase all monsters within 30 squares of player, except for uniques and quest monsters."); connect(banish_button, SIGNAL(clicked()), this, SLOT(wiz_banish())); wizard_layout->addWidget(banish_button, row, 1); // Add the "detect all monsters" button QPointer<QPushButton> display_mon_button = new QPushButton("Detect All Monsters"); display_mon_button->setToolTip("Detect all monsters on the level."); connect(display_mon_button, SIGNAL(clicked()), this, SLOT(wiz_detect_all_monsters())); wizard_layout->addWidget(display_mon_button, row, 2); row++; // Add the "detection" button QPointer<QPushButton> detection = new QPushButton("Detection"); detection->setToolTip("Cast the 'Detection' spell"); connect(detection, SIGNAL(clicked()), this, SLOT(wiz_detection())); wizard_layout->addWidget(detection, row, 0); // Add the "magic mapping" button QPointer<QPushButton> magic_mapping = new QPushButton("Magic Mapping"); magic_mapping->setToolTip("Cast the 'Magic Mapping' spell."); connect(magic_mapping, SIGNAL(clicked()), this, SLOT(wiz_magic_mapping())); wizard_layout->addWidget(magic_mapping, row, 1); // Add the "light dungeon" button QPointer<QPushButton> dungeon_light = new QPushButton("Light Dungeon"); dungeon_light->setToolTip("Illuminate the entire dungeon level."); connect(dungeon_light, SIGNAL(clicked()), this, SLOT(wiz_level_light())); wizard_layout->addWidget(dungeon_light, row, 2); row++; // Add the "redraw dungeon" button QPointer<QPushButton> redraw_dungeon = new QPushButton("Redraw Dungeon"); redraw_dungeon->setToolTip("Redraw a new dungeon level at the current depth."); connect(redraw_dungeon, SIGNAL(clicked()), this, SLOT(wiz_redraw_dungeon())); wizard_layout->addWidget(redraw_dungeon, row, 0); // Add the "make monster" button QPointer<QPushButton> make_monster = new QPushButton("Make Monster"); make_monster->setToolTip("Attempt to make a monster of a specified monster race."); connect(make_monster, SIGNAL(clicked()), this, SLOT(wiz_create_monster())); wizard_layout->addWidget(make_monster, row, 1); // Add the "make feature" button QPointer<QPushButton> make_feature = new QPushButton("Make Feature"); make_feature->setToolTip("Attempt to make a specified feature type."); connect(make_feature, SIGNAL(clicked()), this, SLOT(wiz_create_feature())); wizard_layout->addWidget(make_feature, row, 2); row++; // Add the object commands object_section = new QLabel("<b>Object commands</b>"); object_section->setAlignment(Qt::AlignCenter); wizard_layout->addWidget(object_section, row, 1); row++; // Add the "mass create items" button QPointer<QPushButton> mass_create_items_button = new QPushButton("Create 25 Random Items"); mass_create_items_button->setToolTip("Drop 25 randomly generated objects around the player."); connect(mass_create_items_button , SIGNAL(clicked()), this, SLOT(wiz_mass_create_items())); wizard_layout->addWidget(mass_create_items_button, row, 0); // Add the "create 1 random good item" button QPointer<QPushButton> create_good_item = new QPushButton("Create 1 Random Good Item"); create_good_item->setToolTip("Drop one randomly created guaranteed good item by the player."); connect(create_good_item , SIGNAL(clicked()), this, SLOT(wiz_create_good_item())); wizard_layout->addWidget(create_good_item, row, 1); // Add the "create 1 random great item" button QPointer<QPushButton> create_great_item = new QPushButton("Create 1 Random Great Item"); create_great_item->setToolTip("Drop one randomly created guaranteed great item by the player."); connect(create_great_item , SIGNAL(clicked()), this, SLOT(wiz_create_great_item())); wizard_layout->addWidget(create_great_item, row, 2); row++; // Add the "mass identify" button QPointer<QPushButton> mass_identify = new QPushButton("Mass Identify"); mass_identify->setToolTip("Identify all objects the player has, as well as all objects within 5 squares."); connect(mass_identify, SIGNAL(clicked()), this, SLOT(wiz_mass_identify_items())); wizard_layout->addWidget(mass_identify, row, 0); // Add the "winner's kit" button QPointer<QPushButton> winners_kit = new QPushButton("Winner's kit"); winners_kit->setToolTip("Create a set of artifacts suitable for winning the game."); connect(winners_kit, SIGNAL(clicked()), this, SLOT(wiz_winners_kit())); wizard_layout->addWidget(winners_kit, row, 1); // Add the "edit object" button QPointer<QPushButton> edit_object = new QPushButton("Edit Object"); edit_object->setToolTip("Edit a non-artifact object."); connect(edit_object, SIGNAL(clicked()), this, SLOT(wiz_edit_object())); wizard_layout->addWidget(edit_object, row, 2); row++; // Add the "make artifact" button QPointer<QPushButton> create_artifact = new QPushButton("Create artifact"); create_artifact->setToolTip("Create an artifact."); connect(create_artifact, SIGNAL(clicked()), this, SLOT(wiz_create_artifact())); wizard_layout->addWidget(create_artifact, row, 0); // Add the "make objecct" button QPointer<QPushButton> create_object = new QPushButton("Create object"); create_object->setToolTip("Create a normal object."); connect(create_object, SIGNAL(clicked()), this, SLOT(wiz_create_object())); wizard_layout->addWidget(create_object, row, 1); vlay->addLayout(wizard_layout); buttons = new QDialogButtonBox(QDialogButtonBox::Cancel); connect(buttons, SIGNAL(rejected()), this, SLOT(close())); vlay->addStretch(); vlay->addWidget(buttons); setLayout(vlay); setWindowTitle(tr("Wizard Mode Menu")); this->exec(); }
static void help_frame(struct world *mzx_world, char *help, int pos) { // Displays one frame of the help. Simply prints each line. POS is the // position of the center line. int t1, t2; int first = 12; int scroll_base_color = mzx_world->scroll_base_color; int scroll_arrow_color = mzx_world->scroll_arrow_color; unsigned int next_pos; // Work backwards to line do { if(help[pos - 1] == 1) break; // Can't. pos--; // Go to start of this line. do { pos--; } while((help[pos] != '\n') && (help[pos] != 1)); pos++; //Back a line! first--; } while(first > 6); //First holds first line pos (6-12) to draw if(first > 6) { for(t1 = 6; t1 < first; t1++) fill_line(64, 8, t1, 32, scroll_base_color); } // Display from First to either 18 or end of help for(t1 = first; t1 < 19; t1++) { // Fill... fill_line(64, 8, t1, 32, scroll_base_color); // Find NEXT line NOW - Actually get end of this one. next_pos = pos; while(help[next_pos] != '\n') next_pos++; // Temp. make a 0 help[next_pos] = 0; // Write- What TYPE is it? if(help[pos] != 255) //Normal color_string(help + pos, 8, t1, scroll_base_color); else { pos++; switch(help[pos]) { case '$': // Centered. :) pos++; t2 = strlencolor(help + pos); color_string(help + pos, 40 - (t2 >> 1), t1, scroll_base_color); break; case '>': case '<': // Option- Jump to AFTER dest. label/fill pos += help[pos + 1] + 3; // Now show, two spaces over color_string(help + pos, 10, t1, scroll_base_color); // Add arrow draw_char('\x10', scroll_arrow_color, 8, t1); break; case ':': // Label- Jump to mesg and show pos += help[pos + 1] + 3; color_string(help + pos, 8, t1, scroll_base_color); break; } } // Now fix EOS to be a \n help[next_pos] = '\n'; // Next line... next_pos++; pos = next_pos; if(help[pos] == 0) break; } if(t1 < 19) { for(t1 += 1; t1 < 19; t1++) fill_line(64, 8, t1, 32, scroll_base_color); } update_screen(); }
/* * Request a "movement" direction (1,2,3,4,6,7,8,9) from the user. * * Return TRUE if a direction was chosen, otherwise return FALSE. * * This function should be used for all "repeatable" commands, such as * run, walk, open, close, bash, disarm, spike, tunnel, etc, as well * as all commands which must reference a grid adjacent to the player, * and which may not reference the grid under the player. * * Directions "5" and "0" are illegal and will not be accepted. * * This function tracks and uses the "global direction", and uses * that as the "desired direction", if it is set. */ bool get_rep_dir(int *dp) { int dir = 0; /* Initialize */ (*dp) = 0; if (!dir) { ui_update_message_label(color_string("Please select a direction.", TERM_L_RED)); ui_targeting_show(MODE_TARGETING_DIRECTION); } /* Get a direction */ while (!dir) { UserInput input = ui_get_input(); if (input.mode == INPUT_MODE_KEY) { if ((input.key == Qt::Key_Escape) || (input.key == Qt::Key_X)) dir = DIR_TARGET; else if (input.key == Qt::Key_Question) { do_cmd_list_targeting_commands(); continue; } else dir = target_dir(input); } // Do nothing else if (input.mode == INPUT_MODE_MOUSE_WHEEL) { continue; } /* Check mouse coordinates */ else if ((input.mode == INPUT_MODE_MOUSE_SINGLE_CLICK) || (input.mode == INPUT_MODE_MOUSE_DOUBLE_CLICK)) { /* Calculate approximate angle */ dir = ui_get_dir_from_slope(p_ptr->py, p_ptr->px, input.y, input.x); } } ui_targeting_hide(); if (!dir) color_message("Illegal direction", TERM_ORANGE); ui_clear_message_label(); if (dir == DIR_TARGET) return false; /* Save desired direction */ p_ptr->player_args.direction = dir; /* Save direction */ (*dp) = dir; /* Success */ return (TRUE); }
/* * Handle "target" and "look". * * Note that this code can be called from "get_aim_dir()". * * Currently, when "flag" is true, that is, when * "interesting" grids are being used, and a directional key is used, we * only scroll by a single panel, in the direction requested, and check * for any interesting grids on that panel. The "correct" solution would * actually involve scanning a larger set of grids, including ones in * panels which are adjacent to the one currently scanned, but this is * overkill for this function. XXX XXX * * Hack -- targeting/observing an "outer border grid" may induce * problems, so this is not currently allowed. * * The player can use the direction keys to move among "interesting" * grids in a heuristic manner, or the "space", "+", and "-" keys to * move through the "interesting" grids in a sequential manner, or * can enter "location" mode, and use the direction keys to move one * grid at a time in any direction. The "t" (set target) command will * only target a monster (as opposed to a location) if the monster is * target_able and the "interesting" mode is being used. * * The current grid is described using the "look" method above, and * a new command may be entered at any time, but note that if the * "TARGET_LOOK" bit flag is set (or if we are in "location" mode, * where "space" has no obvious meaning) then "space" will scan * through the description of the current grid until done, instead * of immediately jumping to the next "interesting" grid. This * allows the "target" command to retain its old semantics. * * The "*", "+", and "-" keys may always be used to jump immediately * to the next (or previous) interesting grid, in the proper mode. * * The "return" key may always be used to scan through a complete * grid description (forever). * * This command will cancel any old target, even if used from * inside the "look" command. * * 'mode' is one of TARGET_LOOK or TARGET_KILL. * 'x' and 'y' are the initial position of the target to be highlighted, * or -1 if no location is specified. * Returns TRUE if a target has been successfully set, FALSE otherwise. */ bool target_set_interactive(int mode, int x, int y) { int py = p_ptr->py; int px = p_ptr->px; int i, d, target_count; bool done = FALSE; bool interactive = TRUE; u16b path_n; u16b path_g[PATH_SIZE]; u16b path_gx[PATH_SIZE]; /* Cancel target */ target_set_monster(0, FALSE); /* All grids are selectable */ if (mode & (TARGET_GRID)) { /* Disable other modes */ mode &= ~(TARGET_LOOK | TARGET_KILL | TARGET_TRAP); /* Disable interesting grids */ interactive = FALSE; } /* Prepare the "temp" array */ target_set_interactive_prepare(mode); /* If we haven't been given an initial location, start on the player. */ if ((x == -1 || y == -1) && target_grids.size()) { x = p_ptr->px; y = p_ptr->py; ui_targeting_show(MODE_TARGETING_INTERACTIVE); ui_update_message_label(color_string("Interactive Target Mode", TERM_L_RED)); } /* * If we /have/ been given an initial location, make sure we * honour it by going into "free targeting" mode. */ else { if (x == -1 || y == -1) { x = p_ptr->px; y = p_ptr->py; } interactive = FALSE; ui_targeting_show(MODE_TARGETING_MANUAL); ui_update_message_label(color_string("Manual Target Mode", TERM_L_RED)); } /* Start near the player */ target_count = 0; /* Interact */ while (!done) { /* Interesting grids */ if (interactive && target_grids.size()) { bool path_drawn = FALSE; int yy, xx; y = target_grids[target_count].y; x = target_grids[target_count].x; /* Dummy pointers to send to project_path */ yy = y; xx = x; /* Adjust panel if needed */ ui_ensure(y, x); /* Find the path. */ path_n = project_path(path_g, path_gx, MAX_RANGE, py, px, &yy, &xx, PROJECT_THRU); /* Draw the path in "target" mode. If there is one */ if ((mode & (TARGET_KILL)) && (dungeon_info[y][x].projectable())) { path_drawn = ui_draw_path(path_n, path_g, y, x); } ui_show_cursor(y, x); /* Describe and Prompt */ describe_grid_brief(y, x); UserInput input = ui_get_input(); /* Remove the path */ if (path_drawn) ui_destroy_path(); ui_show_cursor(-1, -1); /* Assume no "direction" */ d = 0; // Use the mouse wheel to go through targets if (input.mode == INPUT_MODE_MOUSE_WHEEL) { if (input.key == Qt::Key_Plus) { if (++target_count == target_grids.size()) target_count = 0; } else if (input.key == Qt::Key_Minus) { if (target_count-- == 0) target_count = target_grids.size() - 1; } continue; } // double-click - automatically target if appropriate if (input.mode == INPUT_MODE_MOUSE_DOUBLE_CLICK) { if (!set_selected_target(mode, y, x)) { target_set_location(y, x); } done = TRUE; continue; } /* * If we click, move the target location to the click and * switch to "free targeting" mode by unsetting 'flag'. * This means we get some info about wherever we've picked. */ if (input.mode == INPUT_MODE_MOUSE_SINGLE_CLICK) { // If clicking twice on the same square, accept if (input.x == x && input.y == y) { if (set_selected_target(mode, y, x)) done = TRUE; continue; } x = input.x; y = input.y; ui_update_message_label(color_string("Interactive Target Mode", TERM_L_RED)); ui_targeting_show(MODE_TARGETING_MANUAL); interactive = FALSE; continue; } /* Analyze */ switch (input.key) { case Qt::Key_Escape: case Qt::Key_X: { done = TRUE; break; } case Qt::Key_C: case Qt::Key_Comma: { /* Set to closest target */ if (target_set_closest(TARGET_KILL)) done = TRUE; break; } case Qt::Key_Space: case Qt::Key_Plus: { if (++target_count == target_grids.size()) target_count = 0; break; } case Qt::Key_Minus: { if (target_count-- == 0) target_count = target_grids.size() - 1; break; } case Qt::Key_Exclam: case Qt::Key_L: { GridDialog(y, x); break; } case Qt::Key_Asterisk: case Qt::Key_M: { ui_update_message_label(color_string("Manual Target Mode", TERM_L_RED)); ui_targeting_show(MODE_TARGETING_MANUAL); interactive = FALSE; break; } case Qt::Key_Question: { do_cmd_list_targeting_commands(); break; } case Qt::Key_H: case Qt::Key_5: case Qt::Key_Period: case Qt::Key_Clear: { if (set_selected_target(mode, y, x)) done = TRUE; break; } default: { /* Extract direction */ d = target_dir(input); /* Oops */ if (!d) message("Illegal command for target mode!"); break; } } /* Hack -- move around */ if (d) { int old_y = target_grids[target_count].y; int old_x = target_grids[target_count].x; /* Find a new monster */ i = target_pick(old_y, old_x, ddy[d], ddx[d]); /* Scroll to find interesting grid */ if (i < 0) { QRect vis = visible_dungeon(); int old_wy = vis.y(); int old_wx = vis.x(); /* Change if legal */ if (ui_change_panel(d)) { /* Recalculate interesting grids */ target_set_interactive_prepare(mode); /* Find a new monster */ i = target_pick(old_y, old_x, ddy[d], ddx[d]); /* Restore panel if needed */ if ((i < 0) && ui_modify_panel(old_wy, old_wx)) { /* Recalculate interesting grids */ target_set_interactive_prepare(mode); } } } /* Use interesting grid if found */ if (i >= 0) target_count = i; } } /* Arbitrary grids */ else { bool path_drawn = FALSE; /* Dummy pointers to send to project_path */ int yy = y; int xx = x; /* Find the path. */ path_n = project_path(path_g, path_gx, MAX_RANGE, py, px, &yy, &xx, PROJECT_THRU); /* Draw the path in "target" mode. If there is one */ if ((mode & (TARGET_KILL)) && (dungeon_info[y][x].projectable())) { /* Save target info */ path_drawn = ui_draw_path(path_n, path_g, y, x); } describe_grid_brief(y, x); ui_show_cursor(y, x); UserInput input = ui_get_input(); /* Remove the path */ if (path_drawn) ui_destroy_path(); ui_show_cursor(y, x); /* Assume no direction */ d = 0; if (input.mode == INPUT_MODE_MOUSE_WHEEL) continue; // double-click - automatically target if appropriate if (input.mode == INPUT_MODE_MOUSE_DOUBLE_CLICK) { if (set_selected_target(mode, y, x)) done = TRUE; else { message(QString("Illegal target!")); } break; } if (input.mode == INPUT_MODE_MOUSE_SINGLE_CLICK) { /* We only target if we click somewhere where the cursor is already (i.e. a double-click without a time limit) */ if (input.x == x && input.y == y) { target_set_location(y, x); done = TRUE; } else { /* Just move the cursor for now - another click will target. */ x = input.x; y = input.y; } continue; } /* Analyze the keypress */ switch (input.key) { case Qt::Key_Escape: case Qt::Key_X: { done = TRUE; continue; } case Qt::Key_Asterisk: case Qt::Key_M: { if (((mode & (TARGET_GRID)) != TARGET_GRID) && target_grids.size()) { ui_update_message_label(color_string("Interactive Target Mode", TERM_L_RED)); ui_targeting_show(MODE_TARGETING_INTERACTIVE); interactive = TRUE; } break; } case Qt::Key_copyright: case Qt::Key_C: case Qt::Key_Comma: { /* Set to closest target */ if (target_set_closest(TARGET_KILL)) done = TRUE; break; } case Qt::Key_Exclam: case Qt::Key_L: { GridDialog(y, x); break; } case Qt::Key_Ampersand: case Qt::Key_P: { /* Recenter around player */ ui_center(py, px); y = py; x = px; break; } case Qt::Key_H: case Qt::Key_5: case Qt::Key_Period: case Qt::Key_Clear: { target_set_location(y, x); done = TRUE; break; } case Qt::Key_Question: { do_cmd_list_targeting_commands(); break; } default: { /* Extract a direction */ d = target_dir(input); /* Oops */ if (!d) message("Illegal command for target mode!"); break; } } /* Handle "direction" */ if (d) { int dungeon_hgt = p_ptr->cur_map_hgt; int dungeon_wid = p_ptr->cur_map_wid; /* Move */ x += ddx[d]; y += ddy[d]; /* Slide into legality */ if (x >= dungeon_wid - 1) x--; else if (x <= 0) x++; /* Slide into legality */ if (y >= dungeon_hgt - 1) y--; else if (y <= 0) y++; /* Adjust panel if needed */ if (ui_adjust_panel(y, x)) { /* Recalculate interesting grids */ target_set_interactive_prepare(mode); } } } } /* Forget */ target_grids.clear(); ui_targeting_hide(); /* Recenter around player */ ui_ensure(py, px); /* Failure to set target */ if (!p_ptr->target_set) return (FALSE); /* Success */ return (TRUE); }
static void drv_drawLine(double x0f, double y0f, double x1f, double y1f, mg_color_t color, double weightf) { fprintf(fout, "<line x1=\"%fin\" y1=\"%fin\" x2=\"%fin\" y2=\"%fin\" stroke=\"%s\" stroke-width=\"%fin\" opacity=\"%s\"/>\n", x0f, y0f, x1f, y1f, color_string(color), weightf, alpha_string(color)); }
/* * Get an "aiming direction" (1,2,3,4,6,7,8,9 or 5) from the user. * * Return TRUE if a direction was chosen, otherwise return FALSE. * * The direction "5" is special, and means "use current target". Also DIR_TARGET * * This function tracks and uses the "global direction", and uses * that as the "desired direction", if it is set. * * Note that "Force Target", if set, will pre-empt user interaction, * if there is a usable target already set. * * Currently this function applies confusion directly. */ bool get_aim_dir(int *dp, bool target_trap) { /* Global direction */ int dir = 0; int old_dir; bool done = FALSE; int mode = TARGET_QUIET; if (target_trap) mode |= TARGET_TRAP; else mode |= TARGET_KILL; if (*dp == DIR_CLOSEST) { if (target_set_closest(mode)) { return(TRUE); } } /* Initialize */ (*dp) = 0; /* Hack -- auto-target if requested */ if (use_old_target && target_okay() && !dir) dir = DIR_TARGET; else ui_update_message_label(color_string("Please select a target.", TERM_L_RED)); ui_targeting_show(MODE_TARGETING_AIMING); /* Ask until satisfied */ while (!dir && !done) { ui_show_cursor(p_ptr->py, p_ptr->px); /* Get a command (or Cancel) */ UserInput input = ui_get_input(); // Paranoia if (input.mode == INPUT_MODE_NONE) break; if ((input.key == Qt::Key_Escape) || (input.key == Qt::Key_X)) { break; } // Do nothing if (input.mode == INPUT_MODE_MOUSE_WHEEL) { continue; } // Skip interactive mode and directly choose target. if (input.mode == INPUT_MODE_MOUSE_DOUBLE_CLICK) { if (set_selected_target(mode, input.y, input.x)) dir = DIR_TARGET; else if (set_selected_target(TARGET_GRID, input.y, input.x)) dir = DIR_TARGET; continue; } if (input.mode == INPUT_MODE_MOUSE_SINGLE_CLICK) { /* Calculate approximate angle */ if (target_set_interactive(mode, input.x, input.y)) dir = DIR_TARGET; else done = TRUE; continue; } /* Analyze */ switch (input.key) { case Qt::Key_M: case Qt::Key_Asterisk: { /* Set new target, use target if legal */ int mode = TARGET_KILL; if (target_trap) mode |= TARGET_TRAP; if (target_set_interactive(mode, -1, -1)) dir = DIR_TARGET; else done = TRUE; continue; } case Qt::Key_C: case Qt::Key_Comma: { /* Set to closest target */ if (target_set_closest(TARGET_KILL)) { dir = DIR_CLOSEST; continue; } break; } case Qt::Key_Question: { do_cmd_list_targeting_commands(); continue; } case Qt::Key_H: case Qt::Key_5: case Qt::Key_Period: case Qt::Key_Clear: { /* Use current target, if set and legal */ if (target_okay()) dir = DIR_TARGET; break; } default: { /* Possible direction */ dir = target_dir(input); break; } } /* Error */ if (!dir) color_message("Illegal aim direction!", TERM_ORANGE); } ui_targeting_hide(); ui_show_cursor(-1, -1); ui_clear_message_label(); /* No direction */ if (!dir) return (FALSE); /* Save the direction */ old_dir = dir; /* Check for confusion */ if (p_ptr->timed[TMD_CONFUSED]) { /* Random direction */ dir = ddd[randint0(8)]; } /* Notice confusion */ if (old_dir != dir) { /* Warn the user */ message(QString("You are confused.")); } /* Save direction */ (*dp) = dir; /* A "valid" direction was entered */ return (TRUE); }