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

proximity options #134

Open
wants to merge 1 commit 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
5 changes: 4 additions & 1 deletion l10n/label_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ Acquire\ birch\ bark = 获得白桦树皮
A\ Favor\ for\ %s = 帮忙 %s
Affair\ with\ %s = 邂逅 %s
A\ fish\ bites! = 咬钩了!
Aggro\ players\ in\ proximity\ to\ the\ mouse\ cursor = 攻击目标鼠标指针特别显示
Aggro\ players\ in\ proximity\ to\ the\ mouse\ cursor = 攻击鼠标指针大致范围的玩家
Aggro\ animals\ in\ proximity\ to\ the\ mouse\ cursor = 攻击鼠标指针大致范围的动物
Chase\ small\ games\ in\ proximity\ to\ the\ mouse\ cursor\ (Alt+RMB) = 追逐鼠标指针大致范围的小动物(Alt+右键)
Lift\ corpses\ etc\ in\ proximity\ to\ the\ mouse\ cursor = 举起鼠标指针大致范围的尸体等
Alarm\ on\ battering\ rams\ and\ catapults = 提示冲车和投石机
Alarm\ on\ localized\ resources = 提示勾选资源
Alarm\ on\ new\ private/party\ chat = 提示新的私人信息
Expand Down
3 changes: 3 additions & 0 deletions src/haven/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ public class Config {
public static String font = Utils.getpref("font", "SansSerif");
public static int fontadd = Utils.getprefi("fontadd", 0);
public static boolean proximityaggro = Utils.getprefb("proximityaggro", false);
public static boolean proximityaggroanimal = Utils.getprefb("proximityaggroanimal", false);
public static boolean proximitychase = Utils.getprefb("proximitychase", false);
public static boolean proximitylift = Utils.getprefb("proximitylift", false);
public static boolean pf = false;
public static String playerposfile;
public static byte[] authck = null;
Expand Down
91 changes: 76 additions & 15 deletions src/haven/MapView.java
Original file line number Diff line number Diff line change
Expand Up @@ -1722,6 +1722,50 @@ public static Object[] gobclickargs(ClickInfo inf) {
return (new Object[0]);
}

private interface GobCheck {
boolean check(Gob gob);
}

private class GobCheckAtk implements GobCheck {
public boolean check(Gob gob) {
if (gob == null || gob.type == null) {
return false;
}
Gob.Type type = gob.type;
switch (type) {
case PLAYER:
return Config.proximityaggro && !gob.isFriend();
case MAMMOTH:
case BAT:
case EAGLE:
case MOB:
case BEAR:
case LYNX:
case WILDGOAT:
case TROLL:
case WALRUS:
case TROUGH:
return Config.proximityaggroanimal;
default:
return false;
}
}
}

private class GobCheckLift implements GobCheck {
public boolean check(Gob gob) {
//TODO
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be a huge headache to implement properly. Will need to keep object lists and maintain it... same for GobCheckChase

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it doesn't harm anything if the nearest object is non-liftable. same for GobCheckChase, "chase" a dandelion is somewhat useful. So i think it's ok to todo them. At least we can reword the label and move them out of "combat" options tab.

return true;
}
}

private class GobCheckChase implements GobCheck {
public boolean check(Gob gob) {
//TODO
return true;
}
}

private class Click extends Hittest {
int clickb;

Expand All @@ -1736,6 +1780,21 @@ private Click(Coord c, int b) {
}
}
}


protected Gob proximity(GobCheck check, Coord2d mc) {
Gob target = null;
synchronized (glob.oc) {
for (Gob gob : glob.oc) {
if (!gob.isplayer() && check.check(gob)) {
double dist = gob.rc.dist(mc);
if ((target == null || dist < target.rc.dist(mc)) && dist <= 5 * tilesz.x)
target = gob;
}
}
}
return target;
}

protected void hit(Coord pc, Coord2d mc, ClickInfo inf) {
lastItemactClickArgs = null;
Expand All @@ -1755,21 +1814,23 @@ protected void hit(Coord pc, Coord2d mc, ClickInfo inf) {
}
}

if (Config.proximityaggro && clickb == 1 && curs != null && curs.name.equals("gfx/hud/curs/atk")) {
Gob target = null;
synchronized (glob.oc) {
for (Gob gob : glob.oc) {
if (gob.type == Gob.Type.PLAYER && !gob.isplayer()) {
double dist = gob.rc.dist(mc);
if ((target == null || dist < target.rc.dist(mc)) && dist <= 5 * tilesz.x)
target = gob;
}
}
}
if (target != null) {
wdgmsg("click", target.sc, target.rc.floor(posres), 1, 0, 0, (int) target.id, target.rc.floor(posres), 0, -1);
return;
}
Gob target = null;
if (clickb == 1 && curs != null && curs.name.equals("gfx/hud/curs/atk")
&& (Config.proximityaggro || Config.proximityaggroanimal)) {
target = proximity(new GobCheckAtk(), mc);
}
if (clickb == 1 && curs != null && curs.name.equals("gfx/hud/curs/hand")
&& (Config.proximitylift)) {
target = proximity(new GobCheckLift(), mc);
}
if (clickb == 3 && (modflags & 4) != 0 && curs != null && curs.name.equals("gfx/hud/curs/arw")
&& (Config.proximitylift)) {
target = proximity(new GobCheckChase(), mc);
modflags = modflags & ~4;
}
if (target != null) {
wdgmsg("click", target.sc, target.rc.floor(posres), clickb, modflags, 0, (int) target.id, target.rc.floor(posres), 0, -1);
return;
}

Object[] args = {pc, mc.floor(posres), clickb, modflags};
Expand Down
35 changes: 34 additions & 1 deletion src/haven/OptWnd.java
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,40 @@ public void set(boolean val) {

public void set(boolean val) {
Utils.setprefb("proximityaggro", val);
Config.combshowkeys = val;
Config.proximityaggro = val;
a = val;
}
});
appender.add(new CheckBox("Aggro animals in proximity to the mouse cursor") {
{
a = Config.proximityaggroanimal;
}

public void set(boolean val) {
Utils.setprefb("proximityaggroanimal", val);
Config.proximityaggroanimal = val;
a = val;
}
});
appender.add(new CheckBox("Chase small games in proximity to the mouse cursor (Alt+RMB)") {
{
a = Config.proximitychase;
}

public void set(boolean val) {
Utils.setprefb("proximitychase", val);
Config.proximitychase = val;
a = val;
}
});
appender.add(new CheckBox("Lift corpses etc in proximity to the mouse cursor") {
{
a = Config.proximitylift;
}

public void set(boolean val) {
Utils.setprefb("proximitylift", val);
Config.proximitylift = val;
a = val;
}
});
Expand Down