this works on Windows and DOS, but I'm unsure.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@723 c06c8d41-db1a-0410-9941-cceddc491573
YHSVOROKPYS33Y4RYZRVZTE3G5LXOFX52HEDNLV6HIXOJYNOKH3QC
RLL3KTSFFND4BVYIEJ4XVK74DPF5E3K77M6SOYQPURIKLU77HE5QC
AJJ6D6JRV6ZAZOAUHYUM2IQG42V6PBALOD4KEMNKSVVAOJXAUCPQC
QLBBUQ6AI5GVLD3QLINQTPO3XO6FYMQCVY5U2S7JRBBHRM5NHFGQC
3WRAJZ5ZLOSIZHFBUH5552QC4F3GAK7AXF6VIQFVN6VY7PUO6HPQC
JW2KRJHES33W7UTWZ6NDO4TLMK4EFU4HKZXBWR2UJOMPCCOTR4CQC
K2CS6TCX2NDVL2ASEHGP4J4K4IJ6FP3ANNKTSIWVG43HPYSBX6ZQC
RPOZZWKG5GLPHVZZ7ZKMKS64ZMV2LDCQSARBJFJ6FZOTOKCQO7FAC
SDLKLUNFGVKDS55DDJZCBAVIB7NL3RRYPTACAY65SCUQKV6APFSAC
ODNAIEJW732NG7USKQKCIP4R4DAEYXXJQX6LY7TIN32NKE75454QC
VIFRP3HZEONFR6PQRYZYM3YUEJOQ7T4F5CZY4MN4YJMB23FMU7XAC
#if defined(WIN32CONSOLE) || defined(DOS)
// Translate shifted numpad to shifted vi keys. Yes,
// this is horribly hacky.
{
static int win_keypad[] = { 'B', 'J', 'N',
'H', '5', 'L',
'Y', 'K', 'U' };
if (getty >= '1' && getty <= '9')
getty = win_keypad[ getty - '1' ];
}
#endif
getty = unmangle_direction_keys(getchm(KC_LEVELMAP), KC_LEVELMAP);
int unmangle_direction_keys(int keyin, int km)
{
const KeymapContext keymap = static_cast<KeymapContext>(km);
#ifdef UNIX
// Kludging running and opening as two character sequences
// for Unix systems. This is an easy way out... all the
// player has to do is find a termcap and numlock setting
// that will get curses the numbers from the keypad. This
// will hopefully be easy.
/* can we say yuck? -- haranp */
if (keyin == '*')
{
keyin = getchm(keymap);
// return control-key
keyin = CONTROL(toupper(numpad2vi(keyin)));
}
else if (keyin == '/')
{
keyin = getchm(keymap);
// return shift-key
keyin = toupper(numpad2vi(keyin));
}
#else
// Old DOS keypad support
if (keyin == 0)
{
/* FIXME haranp - hackiness */
const char DOSidiocy[10] = { "OPQKSMGHI" };
const char DOSunidiocy[10] = { "bjnh.lyku" };
const int DOScontrolidiocy[9] = {
117, 145, 118, 115, 76, 116, 119, 141, 132
};
keyin = getchm(keymap);
for (int j = 0; j < 9; ++j ) {
if (keyin == DOSidiocy[j]) {
keyin = DOSunidiocy[j];
break;
}
if (keyin == DOScontrolidiocy[j]) {
keyin = CONTROL(toupper(DOSunidiocy[j]));
break;
}
}
}
#endif
return (keyin);
}
keyin = getchm(KC_TARGETING); // grrr.
if (keyin == '*')
{
targChosen = true;
dir = 0;
}
else
{
if (strchr(DOSidiocy, keyin) == NULL)
return;
dirChosen = true;
dir = (int)(strchr(DOSidiocy, keyin) - DOSidiocy);
}
dir_chosen = true;
dir = (int)(strchr(dirchars, keyin) - dirchars) / 2;
}
else if (strchr( dirchars, tolower(keyin) ) != NULL)
{
dir_chosen = true;
dir = (int)(strchr(dirchars, keyin) - dirchars) / 2;
switch (keyin)
{
case CONTROL('F'):
mode = (mode + 1) % TARG_NUM_MODES;
snprintf( info, INFO_SIZE, "Targeting mode is now: %s",
(mode == TARG_ANY) ? "any" :
(mode == TARG_ENEMY) ? "enemies"
: "friends" );
mpr( info );
targChosen = true;
dir = 0;
break;
case '-':
targChosen = true;
dir = -1;
break;
case '*':
targChosen = true;
dir = 0;
break;
case CONTROL('F'):
mode = (mode + 1) % TARG_NUM_MODES;
snprintf( info, INFO_SIZE, "Targeting mode is now: %s",
(mode == TARG_ANY) ? "any" :
(mode == TARG_ENEMY) ? "enemies"
: "friends" );
mpr( info );
targ_chosen = true;
dir = 0;
break;
case '-':
targ_chosen = true;
dir = -1;
break;
case '*':
targ_chosen = true;
dir = 0;
break;
case ';':
targ_chosen = true;
dir = -3;
break;
case ';':
targChosen = true;
dir = -3;
break;
case '\'':
targChosen = true;
dir = -2;
break;
case '\'':
targ_chosen = true;
dir = -2;
break;
// get the extended key
keyin = getchm(KC_TARGETING);
// look for CR - change to '5' to indicate selection
if (keyin == 13)
keyin = 'S';
if (strchr(DOSidiocy, keyin) == NULL)
break;
dirChosen = true;
dir = (int)(strchr(DOSidiocy, keyin) - DOSidiocy);
dir_chosen = true;
dir = (int)(strchr(dirchars, keyin) - dirchars) / 2;
}
else if (strchr(dirchars, tolower(keyin)) != NULL)
{
dir_chosen = true;
dir = (int)(strchr(dirchars, tolower(keyin)) - dirchars) / 2;
shifted_direction = true;
case 'C':
targChosen = true;
mx = you.x_pos + cx - VIEW_CX;
my = you.y_pos + cy - VIEW_CY;
if (!in_bounds(mx, my))
break;
if (mgrd[mx][my] != NON_MONSTER)
{
mprf("%s won't like that.",
ptr_monam(&menv[mgrd[mx][my]], DESC_CAP_THE));
break;
}
create_spec_monster_name(mx, my);
viewwindow(true, false);
break;
case 'C':
targ_chosen = true;
mx = you.x_pos + cx - VIEW_CX;
my = you.y_pos + cy - VIEW_CY;
if (!in_bounds(mx, my))
break;
if (mgrd[mx][my] != NON_MONSTER)
{
mprf("%s won't like that.",
ptr_monam(&menv[mgrd[mx][my]], DESC_CAP_THE));
break;
}
create_spec_monster_name(mx, my);
viewwindow(true, false);
break;
case 'D':
targChosen = true;
mx = you.x_pos + cx - VIEW_CX;
my = you.y_pos + cy - VIEW_CY;
if (!in_bounds(mx, my))
break;
mid = mgrd[mx][my];
case 'D':
targ_chosen = true;
mx = you.x_pos + cx - VIEW_CX;
my = you.y_pos + cy - VIEW_CY;
if (!in_bounds(mx, my))
break;
mid = mgrd[mx][my];
case 'F':
targChosen = true;
mx = you.x_pos + cx - VIEW_CX;
my = you.y_pos + cy - VIEW_CY;
if (!in_bounds(mx, my))
break;
mid = mgrd[mx][my];
case 'F':
targ_chosen = true;
mx = you.x_pos + cx - VIEW_CX;
my = you.y_pos + cy - VIEW_CY;
if (!in_bounds(mx, my))
break;
mid = mgrd[mx][my];
mprf("Changing attitude of %s\n",
ptr_monam(&menv[mid], DESC_PLAIN));
menv[mid].attitude =
menv[mid].attitude == ATT_HOSTILE?
ATT_FRIENDLY
: ATT_HOSTILE;
mprf("Changing attitude of %s\n",
ptr_monam(&menv[mid], DESC_PLAIN));
menv[mid].attitude =
menv[mid].attitude == ATT_HOSTILE?
ATT_FRIENDLY
: ATT_HOSTILE;
describe_monsters( menv[ mid ].type, mid );
redraw_screen();
mesclr( true );
// describe the cell again.
describe_cell(view2gridX(cx), view2gridY(cy));
break;
describe_monsters( menv[ mid ].type, mid );
redraw_screen();
mesclr( true );
// describe the cell again.
describe_cell(view2gridX(cx), view2gridY(cy));
break;
snprintf( info, INFO_SIZE, "Targeting mode is now: %s",
(mode == TARG_ANY) ? "any" :
(mode == TARG_ENEMY) ? "enemies"
: "friends" );
snprintf( info, INFO_SIZE, "Targeting mode is now: %s",
(mode == TARG_ANY) ? "any" :
(mode == TARG_ENEMY) ? "enemies"
: "friends" );
case '^':
case '\t':
case '\\':
case '_':
case '<':
case '>':
{
if (find_square( cx, cy, objfind_pos, 1,
find_feature, keyin, true,
Options.target_los_first
? LOS_FLIPVH : LOS_ANY))
{
newcx = objfind_pos[0];
newcy = objfind_pos[1];
}
else
flush_input_buffer( FLUSH_ON_FAILURE );
targChosen = true;
break;
}
case ';':
case '/':
case '\'':
case '*':
{
dir = keyin == ';' || keyin == '/'? -1 : 1;
if (find_square( cx, cy, objfind_pos, dir,
find_object, 0, true,
Options.target_los_first
? (dir == 1? LOS_FLIPVH : LOS_FLIPHV)
: LOS_ANY))
case '^':
case '\t':
case '\\':
case '_':
case '<':
case '>':
{
if (find_square( cx, cy, objfind_pos, 1,
find_feature, keyin, true,
Options.target_los_first
? LOS_FLIPVH : LOS_ANY))
{
newcx = objfind_pos[0];
newcy = objfind_pos[1];
}
else
flush_input_buffer( FLUSH_ON_FAILURE );
targ_chosen = true;
break;
}
case ';':
case '/':
case '\'':
case '*':
{
dir = keyin == ';' || keyin == '/'? -1 : 1;
if (find_square( cx, cy, objfind_pos, dir,
find_object, 0, true,
Options.target_los_first
? (dir == 1? LOS_FLIPVH : LOS_FLIPHV)
: LOS_ANY))
{
newcx = objfind_pos[0];
newcy = objfind_pos[1];
}
else
flush_input_buffer( FLUSH_ON_FAILURE );
targChosen = true;
break;
}
{
newcx = objfind_pos[0];
newcy = objfind_pos[1];
}
else
flush_input_buffer( FLUSH_ON_FAILURE );
targ_chosen = true;
break;
}
case '-':
case '+':
case '=':
{
dir = keyin == '-'? -1 : 1;
if (find_square( cx, cy, monsfind_pos, dir,
find_monster, mode, Options.target_wrap ))
{
newcx = monsfind_pos[0];
newcy = monsfind_pos[1];
}
else
flush_input_buffer( FLUSH_ON_FAILURE );
targChosen = true;
break;
}
case '-':
case '+':
case '=':
{
dir = keyin == '-'? -1 : 1;
if (find_square( cx, cy, monsfind_pos, dir,
find_monster, mode, Options.target_wrap ))
{
newcx = monsfind_pos[0];
newcy = monsfind_pos[1];
}
else
flush_input_buffer( FLUSH_ON_FAILURE );
targ_chosen = true;
break;
}
case '?':
targChosen = true;
mx = you.x_pos + cx - VIEW_CX;
my = you.y_pos + cy - VIEW_CY;
if (!in_bounds(mx, my))
break;
mid = mgrd[mx][my];
case '?':
targ_chosen = true;
mx = you.x_pos + cx - VIEW_CX;
my = you.y_pos + cy - VIEW_CY;
if (!in_bounds(mx, my))
break;
mid = mgrd[mx][my];
describe_monsters( menv[ mid ].type, mid );
redraw_screen();
mesclr( true );
// describe the cell again.
describe_cell(view2gridX(cx), view2gridY(cy));
break;
describe_monsters( menv[ mid ].type, mid );
redraw_screen();
mesclr( true );
// describe the cell again.
describe_cell(view2gridX(cx), view2gridY(cy));
break;
case '\r':
case '\n':
case '.':
case '5':
case 'X':
// If we're in look-around mode, and the cursor is on
// the character and there's a valid travel target
// within the viewport, jump to that target.
if (justLooking && cx == VIEW_CX && cy == VIEW_CY)
case '\r':
case '\n':
case '.':
case '5':
case 'X':
// If we're in look-around mode, and the cursor is on
// the character and there's a valid travel target
// within the viewport, jump to that target.
if (justLooking && cx == VIEW_CX && cy == VIEW_CY)
{
if (you.travel_x > 0 && you.travel_y > 0)
{
int nx = grid2viewX(you.travel_x);
int ny = grid2viewY(you.travel_y);
if (in_viewport_bounds(nx, ny))
if (you.travel_x > 0 && you.travel_y > 0)
{
int nx = grid2viewX(you.travel_x);
int ny = grid2viewY(you.travel_y);
if (in_viewport_bounds(nx, ny))
{
newcx = nx;
newcy = ny;
targChosen = true;
}
}
newcx = nx;
newcy = ny;
targ_chosen = true;
else
{
dirChosen = true;
dir = keyin == 'X'? -1 : 4;
}
break;
}
}
else
{
dir_chosen = true;
dir = keyin == 'X'? -1 : 4;
}
break;
keyin = getch_with_command_macros();
#ifdef UNIX
// Kludging running and opening as two character sequences
// for Unix systems. This is an easy way out... all the
// player has to do is find a termcap and numlock setting
// that will get curses the numbers from the keypad. This
// will hopefully be easy.
/* can we say yuck? -- haranp */
if (keyin == '*')
{
keyin = getch();
// return control-key
keyin = CONTROL(toupper(numpad2vi(keyin)));
}
else if (keyin == '/')
{
keyin = getch();
// return shift-key
keyin = toupper(numpad2vi(keyin));
}
#else
// Old DOS keypad support
if (keyin == 0)
{
/* FIXME haranp - hackiness */
const char DOSidiocy[10] = { "OPQKSMGHI" };
const char DOSunidiocy[10] = { "bjnh.lyku" };
const int DOScontrolidiocy[9] = {
117, 145, 118, 115, 76, 116, 119, 141, 132
};
keyin = getch();
for (int j = 0; j < 9; ++j ) {
if (keyin == DOSidiocy[j]) {
keyin = DOSunidiocy[j];
break;
}
if (keyin == DOScontrolidiocy[j]) {
keyin = CONTROL(toupper(DOSunidiocy[j]));
break;
}
}
}
#endif
keyin = unmangle_direction_keys(getch_with_command_macros());