Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target lock #673

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions rsrc/dialogs/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@
<led name='slow' relative='pos pos-in' anchor='med' top='0' left='15'>Slow</led>
<led name='snail' relative='pos pos-in' anchor='slow' top='0' left='15'>Quite Slow</led>
</group>
<text name='keyshift-head' size='large' relative='pos-in pos' anchor='spd-head' top='30' left='0' width='182' height='17'>When targeting, directional keys should:</text>
<text name='targeting-head' size='large' relative='pos-in pos' anchor='spd-head' top='30' left='0' width='182' height='17'>Targeting mode:</text>
<led name='target-lock' relative='pos-in pos' rel-anchor='prev' top='4' left='15'>Shift screen to show enemies in range</led>
<text name="keyshift-head" relative='neg pos' rel-anchor='prev' top='8' left='3'>Directional keys:</text>
<group name='keyshift-options'>
<led name='target-adjacent' relative='pos-in pos' anchor='keyshift-head' top='4' left='15'>Select adjacent tiles</led>
<led name='target-adjacent' relative='pos pos-in' anchor='keyshift-head' top='0' left='15'>Select adjacent tiles</led>
<led name='screen-shift' relative='pos pos-in' anchor='target-adjacent' top='0' left='15'>Move the screen</led>
</group>
<text name='keyshift-note' relative='pos-in pos' anchor='keyshift-head' top='20' left='15' width='300' height='17'>(Holding Shift while using directional keys will do the opposite.)</text>
<text name='misc-head' size='large' relative='neg pos' anchor='keyshift-note' top='15' left='15' width='182' height='17'>Miscellaneous:</text>
<text name='keyshift-note' relative='pos-in pos-in' anchor='keyshift-head' top='14' left='40' width='300' height='17'>(Holding Shift while using directional keys will do the opposite.)</text>
<text name='misc-head' size='large' relative='pos-in pos' anchor='targeting-head' top='60' left='0' width='182' height='17'>Miscellaneous:</text>
<led name='nosound' relative='pos-in pos' anchor='misc-head' top='6' left='15'>No Sounds</led>
<led name='repeatdesc' relative='pos-in pos' rel-anchor='prev' top='10' left='0'>Show room descriptions more than once</led>
<led name='easier' relative='pos-in pos' rel-anchor='prev' top='10' left='0'>Make game easier (monsters much weaker)</led>
Expand Down
26 changes: 13 additions & 13 deletions src/game/boe.combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1642,10 +1642,10 @@ void load_missile() {
ammo_inv_slot = thrown.slot;
add_string_to_buf("Throw: Select a target.");
add_string_to_buf(" (Hit 's' to cancel.)");
overall_mode = MODE_THROWING;
current_spell_range = 8;
if(thrown->ability == eItemAbil::DISTANCE_MISSILE)
current_spell_range += thrown->abil_strength;
handle_target_mode(MODE_THROWING, current_spell_range);
if(thrown->ability == eItemAbil::EXPLODING_WEAPON)
current_pat = radius2;
else current_pat = single;
Expand All @@ -1658,36 +1658,36 @@ void load_missile() {
} else if(bow && arrow) {
missile_inv_slot = bow.slot;
ammo_inv_slot = arrow.slot;
overall_mode = MODE_FIRING;
add_string_to_buf("Fire: Select a target.");
add_string_to_buf(" (Hit 's' to cancel.)");
current_spell_range = 12;
if(arrow->ability == eItemAbil::DISTANCE_MISSILE)
current_spell_range += arrow->abil_strength;
handle_target_mode(MODE_FIRING, current_spell_range);
add_string_to_buf("Fire: Select a target.");
add_string_to_buf(" (Hit 's' to cancel.)");
if(arrow->ability == eItemAbil::EXPLODING_WEAPON)
current_pat = radius2;
else current_pat = single;
} else if(crossbow && bolts) {
missile_inv_slot = crossbow.slot;
ammo_inv_slot = bolts.slot;
overall_mode = MODE_FIRING;
add_string_to_buf("Fire: Select a target.");
add_string_to_buf(" (Hit 's' to cancel.)");
current_spell_range = 12;
if(bolts->ability == eItemAbil::DISTANCE_MISSILE)
current_spell_range += bolts->abil_strength;
handle_target_mode(MODE_FIRING, current_spell_range);
add_string_to_buf("Fire: Select a target.");
add_string_to_buf(" (Hit 's' to cancel.)");
if(bolts->ability == eItemAbil::EXPLODING_WEAPON)
current_pat = radius2;
else current_pat = single;
} else if(no_ammo) {
missile_inv_slot = no_ammo.slot;
ammo_inv_slot = no_ammo.slot;
overall_mode = MODE_FIRING;
add_string_to_buf("Fire: Select a target.");
add_string_to_buf(" (Hit 's' to cancel.)");
current_spell_range = 12;
if(no_ammo->ability == eItemAbil::DISTANCE_MISSILE)
current_spell_range += no_ammo->abil_strength;
handle_target_mode(MODE_FIRING, current_spell_range);
add_string_to_buf("Fire: Select a target.");
add_string_to_buf(" (Hit 's' to cancel.)");
if(no_ammo->ability == eItemAbil::EXPLODING_WEAPON)
current_pat = radius2;
else current_pat = single;
Expand Down Expand Up @@ -5155,8 +5155,8 @@ void start_spell_targeting(eSpell num, bool freebie, int spell_range, eSpellPat
else if(isMage(num))
add_string_to_buf(" (Hit 'm' to cancel.)");
else add_string_to_buf(" (Hit 'p' to cancel.)");
overall_mode = MODE_SPELL_TARGET;
current_spell_range = num == eSpell::NONE ? spell_range : (*num).range;
handle_target_mode(MODE_SPELL_TARGET, current_spell_range);
current_pat = single;

switch(num) { // Different spells have different messages and diff. target shapes
Expand Down Expand Up @@ -5218,9 +5218,9 @@ void start_fancy_spell_targeting(eSpell num, bool freebie, int spell_range, eSpe
add_string_to_buf(" (Hit 'm' to cancel.)");
else add_string_to_buf(" (Hit 'p' to cancel.)");
add_string_to_buf(" (Hit space to cast.)");
overall_mode = MODE_FANCY_TARGET;
current_pat = single;
current_spell_range = num == eSpell::NONE ? spell_range : (*num).range;
handle_target_mode(MODE_FANCY_TARGET, current_spell_range);
current_pat = single;
short bonus = univ.current_pc().stat_adj(eSkill::INTELLIGENCE);
short level = freebie ? store_item_spell_level : univ.current_pc().level;

Expand Down
6 changes: 5 additions & 1 deletion src/game/boe.dlgutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,8 @@ static bool prefs_event_filter (cDialog& me, std::string id, eKeyMod) {
univ.party.less_wm = dynamic_cast<cLed&>(me["lesswm"]).getState() != led_off;
}
set_pref("ShowStartupSplash", dynamic_cast<cLed&>(me["skipsplash"]).getState() == led_off);
set_pref("TargetLock", dynamic_cast<cLed&>(me["target-lock"]).getState() != led_off);

std::string speed = dynamic_cast<cLedGroup&>(me["speed"]).getSelected();
/* TODO: Should I add these additional preferences from Windows?
party.stuff_done[SDF_NO_TARGET_LINE] = cd_get_led(1099,50);
Expand Down Expand Up @@ -1336,7 +1338,9 @@ void pick_preferences(bool record) {
gameSpeed.setSelected("snail");
break;
}


dynamic_cast<cLed&>(prefsDlog["target-lock"]).setState(get_bool_pref("TargetLock", true) ? led_red : led_off);

cLedGroup& keyshiftOptions = dynamic_cast<cLedGroup&>(prefsDlog["keyshift-options"]);
if(get_bool_pref("DirectionalKeyScrolling", false)){
keyshiftOptions.setSelected("screen-shift");
Expand Down
3 changes: 2 additions & 1 deletion src/game/boe.main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ std::string help_text_rsrc = "help";
std::map<std::string,std::vector<std::string>> feature_flags = {
// Legacy behavior of the T debug action (used by some replays)
// does not change the party's outdoors location
{"debug-enter-town", {"move-outdoors"}}
{"debug-enter-town", {"move-outdoors"}},
{"target-lock", {"V1"}}
};

struct cParseEntrance {
Expand Down
24 changes: 24 additions & 0 deletions src/game/boe.newgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1040,3 +1040,27 @@ short scan_for_response(const char *str) {
return -1;
}

void handle_target_mode(eGameMode target_mode, int range) {
overall_mode = target_mode;
// Lock on to enemies in range:
if(has_feature_flag("target-lock", "V1") && get_bool_pref("TargetLock", true)){
location loc = univ.current_pc().combat_pos;

std::vector<location> enemy_locs_in_range;
for(short i = 0; i < univ.town.monst.size(); i++){
auto& monst = univ.town.monst[i];
if(monst.is_alive()) {
eAttitude att = monst.attitude;
if((att == eAttitude::HOSTILE_A || att == eAttitude::HOSTILE_B)
&& dist(loc, monst.cur_loc) <= range){
enemy_locs_in_range.push_back(monst.cur_loc);
}
}
}
if(!enemy_locs_in_range.empty()){
std::vector<location> dest_candidates = points_containing_most(enemy_locs_in_range);
center = closest_point(dest_candidates, loc);
draw_terrain();
}
}
}
2 changes: 2 additions & 0 deletions src/game/boe.newgraph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "location.hpp"
#include "scenario/item.hpp"
#include "gfx/gfxsheets.hpp"
#include "boe.consts.hpp"

#ifndef BOE_NEWGRAPH_H
#define BOE_NEWGRAPH_H
Expand Down Expand Up @@ -70,6 +71,7 @@ void draw_shop_graphics(bool item_pressed, bool item_help_pressed, rectangle cli
void refresh_shopping();
void click_talk_rect(word_rect_t word);
void place_talk_str(std::string str_to_place,std::string str_to_place2,short color,rectangle c_rect);
void handle_target_mode(eGameMode target_mode, int range);
short scan_for_response(const char *str);
void refresh_talking();
graf_pos calc_item_rect(int num,rectangle& to_rect);
Expand Down
Loading