/
MapView.java
2265 lines (2095 loc) · 58.5 KB
/
MapView.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* This file is part of the Haven & Hearth game client.
* Copyright (C) 2009 Fredrik Tolf <fredrik@dolda2000.com>, and
* Björn Johannessen <johannessen.bjorn@gmail.com>
*
* Redistribution and/or modification of this file is subject to the
* terms of the GNU Lesser General Public License, version 3, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* Other parts of this source tree adhere to other copying
* rights. Please see the file `COPYING' in the root directory of the
* source tree for details.
*
* A copy the GNU Lesser General Public License is distributed along
* with the source tree of which this file is a part in the file
* `doc/LPGL-3'. If it is missing for any reason, please see the Free
* Software Foundation's website at <http://www.fsf.org/>, or write
* to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*/
package haven;
import static haven.MCache.cmaps;
import static haven.MCache.tileSize;
import haven.INIFile.Pair;
import haven.MCache.Grid;
import haven.MCache.Overlay;
import haven.Resource.Tile;
import haven.Coord;
import java.awt.Color;
import java.awt.event.KeyEvent;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.TreeMap;
import union.APXUtils;
import union.KerriUtils;
import union.JSBotUtils;
public class MapView extends Widget implements DTarget, Console.Directory {
static Color[] olc = new Color[31];
static Map<String, Class<? extends Camera>> camtypes = new HashMap<String, Class<? extends Camera>>();
public Coord mc = new Coord(0, 0), mousepos = new Coord(0, 0), pmousepos = new Coord(0, 0), mouseAtTile = new Coord(0, 0);
Camera cam;
Sprite.Part[] clickable = {};
List<Sprite.Part> obscured = Collections.emptyList();
private int[] visol = new int[31];
private long olftimer = 0;
private int olflash = 0;
Grabber grab = null;
ILM mask;
final MCache map;
public final Glob glob;
Collection<Gob> plob = null;
boolean plontile;
int plrad = 0;
int playergob = -1;
public Profile prof = new Profile(300);
private Profile.Frame curf;
Coord plfpos = null;
long lastmove = 0;
Sprite.Part obscpart = null;
Gob obscgob = null;
static Text.Foundry polownertf = new Text.Foundry("serif", 20);
public Text polownert = null;
public String polowner = null;
public Coord moveto = null;
long polchtm = 0;
int si = 4;
double _scale = 1;
double scales[] = { 0.5, 0.66, 0.8, 0.9, 1, 1.25, 1.5, 1.75, 2 };
Map<String, Integer> radiuses;
int beast_check_delay = 0;
public boolean player_moving = false;
public boolean objectSelecting = false; //used for JS selectObject
public boolean waitForSelect = false; //used for JS selectObject
public Gob objectUnderMouse = null; //current object under mouse (hover)
public Coord myLastCoord; //my last coord
//private ArrayList<Integer> ignoredObjects = new ArrayList<Integer>();
private static int dup(int paramInt)
{
return paramInt << 4 | paramInt;
}
private static Color int16toc(int paramInt) {
return new Color(dup((paramInt & 0xF000) >> 12), dup((paramInt & 0xF00) >> 8),
dup((paramInt & 0xF0) >> 4), dup((paramInt & 0xF) >> 0));
}
public double getScale() {
return Config.zoom ? _scale : 1;
}
public void setScale(double value) {
_scale = value;
// mask.dispose();
// mask = new ILM(MainFrame.getScreenSize().div(_scale), glob.oc);
}
public static final Comparator<Sprite.Part> clickcmp = new Comparator<Sprite.Part>() {
public int compare(Sprite.Part a, Sprite.Part b) {
return (-Sprite.partidcmp.compare(a, b));
}
};
static {
Widget.addtype("mapview", new WidgetFactory() {
public Widget create(Coord c, Widget parent, Object[] args) {
Coord sz = MainFrame.getInnerSize();
Coord mc = (Coord) args[1];
int pgob = -1;
if (args.length > 2) {
pgob = (Integer) args[2];
JSBotUtils.playerID = pgob;
}
return (new MapView(c, sz, parent, mc, pgob));
}
});
olc[0] = new Color(255, 0, 128);
olc[1] = new Color(0, 0, 255);
olc[2] = new Color(255, 0, 0);
olc[3] = new Color(128, 0, 255);
olc[16] = new Color(0, 255, 0);
olc[17] = new Color(255, 255, 0);
}
public interface Grabber {
void mmousedown(Coord mc, int button);
void mmouseup(Coord mc, int button);
void mmousemove(Coord mc);
}
@SuppressWarnings("serial")
public static class GrabberException extends RuntimeException {
}
public static class Camera {
public void setpos(MapView mv, Gob player, Coord sz) {
}
public boolean click(MapView mv, Coord sc, Coord mc, int button) {
return (false);
}
public void move(MapView mv, Coord sc, Coord mc) {
}
public boolean release(MapView mv, Coord sc, Coord mc, int button) {
return (false);
}
public void moved(MapView mv) {
}
public static void borderize(MapView mv, Gob player, Coord sz,
Coord border) {
if (Config.noborders) {
return;
}
Coord mc = mv.mc;
Coord oc = m2s(mc).inv();
int bt = -((sz.y / 2) - border.y);
int bb = (sz.y / 2) - border.y;
int bl = -((sz.x / 2) - border.x);
int br = (sz.x / 2) - border.x;
Coord sc = m2s(player.position()).add(oc);
if (sc.x < bl)
mc = mc.add(s2m(new Coord(sc.x - bl, 0)));
if (sc.x > br)
mc = mc.add(s2m(new Coord(sc.x - br, 0)));
if (sc.y < bt)
mc = mc.add(s2m(new Coord(0, sc.y - bt)));
if (sc.y > bb)
mc = mc.add(s2m(new Coord(0, sc.y - bb)));
mv.mc = mc;
}
public void reset() {
}
}
private static abstract class DragCam extends Camera {
Coord o, mo;
boolean dragging = false;
boolean needreset = false;
public boolean click(MapView mv, Coord sc, Coord mc, int button) {
if (button == 2) {
mv.ui.grabmouse(mv);
o = sc;
mo = null;
dragging = true;
return (true);
}
return (false);
}
public void move(MapView mv, Coord sc, Coord mc) {
if (dragging) {
Coord off = sc.add(o.inv());
if ((mo == null) && (off.dist(Coord.z) > 5))
mo = mv.mc;
if (mo != null) {
mv.mc = mo.add(s2m(off).inv());
moved(mv);
}
}
}
public void reset() {
needreset = true;
}
public boolean release(MapView mv, Coord sc, Coord mc, int button) {
if ((button == 2) && dragging) {
mv.ui.grabmouse(null);
dragging = false;
if (mo == null) {
mv.mc = mc;
moved(mv);
}
return (true);
}
return (false);
}
}
static class OrigCam extends Camera {
public final Coord border = new Coord(250, 150);
public void setpos(MapView mv, Gob player, Coord sz) {
borderize(mv, player, sz, border);
}
public boolean click(MapView mv, Coord sc, Coord mc, int button) {
if (button == 1)
mv.mc = mc;
return (false);
}
}
static {
camtypes.put("orig", OrigCam.class);
}
static class OrigCam2 extends DragCam {
public final Coord border = new Coord(250, 125);
private final double v;
private Coord tgt = null;
private long lmv;
public OrigCam2(double v) {
this.v = Math.log(v) / 0.02; /* 1 / 50 FPS = 0.02 s */
}
public OrigCam2() {
this(0.9);
}
public OrigCam2(String... args) {
this((args.length < 1) ? 0.9 : Double.parseDouble(args[0]));
}
public void setpos(MapView mv, Gob player, Coord sz) {
if (needreset) {
needreset = false;
mv.mc = player.position();
}
if (tgt != null) {
if (mv.mc.dist(tgt) < 10) {
tgt = null;
} else {
long now = System.currentTimeMillis();
double dt = (now - lmv) / 1000.0;
lmv = now;
mv.mc = tgt.add(mv.mc.add(tgt.inv()).mul(Math.exp(v * dt)));
}
}
borderize(mv, player, sz, border);
}
public boolean click(MapView mv, Coord sc, Coord mc, int button) {
if ((button == 1) && (mv.ui.root.cursor == RootWidget.defcurs)) {
tgt = mc;
lmv = System.currentTimeMillis();
}
return (super.click(mv, sc, mc, button));
}
public void moved(MapView mv) {
tgt = null;
}
public void reset() {
super.reset();
tgt = null;
}
}
static {
camtypes.put("clicktgt", OrigCam2.class);
}
static class WrapCam extends Camera {
public final Coord region = new Coord(200, 150);
public void setpos(MapView mv, Gob player, Coord sz) {
Coord sc = m2s(player.position().add(mv.mc.inv()));
if (sc.x < -region.x)
mv.mc = mv.mc.add(s2m(new Coord(-region.x * 2, 0)));
if (sc.x > region.x)
mv.mc = mv.mc.add(s2m(new Coord(region.x * 2, 0)));
if (sc.y < -region.y)
mv.mc = mv.mc.add(s2m(new Coord(0, -region.y * 2)));
if (sc.y > region.y)
mv.mc = mv.mc.add(s2m(new Coord(0, region.y * 2)));
}
}
static {
camtypes.put("kingsquest", WrapCam.class);
}
static class BorderCam extends DragCam {
public final Coord border = new Coord(250, 150);
public void setpos(MapView mv, Gob player, Coord sz) {
if (needreset) {
needreset = false;
mv.mc = player.position();
}
borderize(mv, player, sz, border);
}
}
static {
camtypes.put("border", BorderCam.class);
}
static class PredictCam extends DragCam {
private double xa = 0, ya = 0;
private boolean reset = true;
private final double speed = 0.15, rspeed = 0.15;
private double sincemove = 0;
private long last = System.currentTimeMillis();
public void setpos(MapView mv, Gob player, Coord sz) {
long now = System.currentTimeMillis();
double dt = ((double) (now - last)) / 1000.0;
last = now;
if (needreset) {
needreset = false;
mv.mc = player.position();
}
Coord mc = mv.mc.add(s2m(sz.add(mv.sz.inv()).div(2)));
Coord sc = m2s(player.position()).add(m2s(mc).inv());
if (reset) {
xa = (double) sc.x / (double) sz.x;
ya = (double) sc.y / (double) sz.y;
if (xa < -0.25)
xa = -0.25;
if (xa > 0.25)
xa = 0.25;
if (ya < -0.15)
ya = -0.15;
if (ya > 0.25)
ya = 0.25;
reset = false;
}
Coord vsz = sz.div(16);
Coord vc = new Coord((int) (sz.x * xa), (int) (sz.y * ya));
boolean moved = false;
if (sc.x < vc.x - vsz.x) {
if (xa < 0.25)
xa += speed * dt;
moved = true;
mc = mc.add(s2m(new Coord(sc.x - (vc.x - vsz.x) - 4, 0)));
}
if (sc.x > vc.x + vsz.x) {
if (xa > -0.25)
xa -= speed * dt;
moved = true;
mc = mc.add(s2m(new Coord(sc.x - (vc.x + vsz.x) + 4, 0)));
}
if (sc.y < vc.y - vsz.y) {
if (ya < 0.25)
ya += speed * dt;
moved = true;
mc = mc.add(s2m(new Coord(0, sc.y - (vc.y - vsz.y) - 2)));
}
if (sc.y > vc.y + vsz.y) {
if (ya > -0.15)
ya -= speed * dt;
moved = true;
mc = mc.add(s2m(new Coord(0, sc.y - (vc.y + vsz.y) + 2)));
}
if (!moved) {
sincemove += dt;
if (sincemove > 1) {
if (xa < -0.1)
xa += rspeed * dt;
if (xa > 0.1)
xa -= rspeed * dt;
if (ya < -0.1)
ya += rspeed * dt;
if (ya > 0.1)
ya -= rspeed * dt;
}
} else {
sincemove = 0;
}
mv.mc = mc.add(s2m(mv.sz.add(sz.inv()).div(2)));
}
public void moved(MapView mv) {
reset = true;
}
public void reset() {
reset = true;
xa = ya = 0;
super.reset();
}
}
static {
camtypes.put("predict", PredictCam.class);
}
static class FixedCam extends DragCam {
public final Coord border = new Coord(250, 150);
private Coord off = Coord.z;
private boolean setoff = false;
public void setpos(MapView mv, Gob player, Coord sz) {
if (setoff) {
borderize(mv, player, sz, border);
off = mv.mc.add(player.position().inv());
setoff = false;
}
mv.mc = player.position().add(off);
}
public void moved(MapView mv) {
setoff = true;
}
public void reset() {
off = Coord.z;
}
}
static {
camtypes.put("fixed", FixedCam.class);
}
static class CakeCam extends Camera {
private Coord border = new Coord(250, 150);
private Coord size, center, diff;
public void setpos(MapView mv, Gob player, Coord sz) {
if (size == null || !size.equals(sz)) {
size = new Coord(sz);
center = size.div(2);
diff = center.sub(border);
}
if (player != null && mv.pmousepos != null)
mv.mc = player.position().sub(
s2m(center.sub(mv.pmousepos).mul(diff).div(center)));
}
}
static {
camtypes.put("cake", CakeCam.class);
}
static class FixedCakeCam extends DragCam {
public final Coord border = new Coord(250, 150);
private Coord size, center, diff;
private boolean setoff = false;
private Coord off = Coord.z;
private Coord tgt = null;
private Coord cur = off;
private double vel = 0.2;
public FixedCakeCam(double vel) {
this.vel = Math.min(1.0, Math.max(0.1, vel));
}
public FixedCakeCam(String... args) {
this(args.length < 1 ? 0.2 : Double.parseDouble(args[0]));
}
public void setpos(MapView mv, Gob player, Coord sz) {
if (setoff) {
borderize(mv, player, sz, border);
off = mv.mc.add(player.position().inv());
setoff = false;
}
if (mv.pmousepos != null
&& (mv.pmousepos.x == 0 || mv.pmousepos.x == sz.x - 1
|| mv.pmousepos.y == 0 || mv.pmousepos.y == sz.y - 1)) {
if (size == null || !size.equals(sz)) {
size = new Coord(sz);
center = size.div(2);
diff = center.sub(border);
}
if (player != null && mv.pmousepos != null)
tgt = player
.position()
.sub(s2m(center.sub(mv.pmousepos).mul(diff)
.div(center))).sub(player.position());
} else {
tgt = off;
}
cur = cur.add(tgt.sub(cur).mul(vel));
mv.mc = player.position().add(cur);
}
public void moved(MapView mv) {
setoff = true;
}
public void reset() {
off = new Coord();
}
}
static {
camtypes.put("fixedcake", FixedCakeCam.class);
}
@SuppressWarnings("serial")
private class Loading extends Exception {
}
private static Camera makecam(Class<? extends Camera> ct, String... args)
throws ClassNotFoundException {
try {
try {
Constructor<? extends Camera> cons = ct
.getConstructor(String[].class);
return (cons.newInstance(new Object[] { args }));
} catch (IllegalAccessException e) {
} catch (NoSuchMethodException e) {
}
try {
return (ct.newInstance());
} catch (IllegalAccessException e) {
}
} catch (InstantiationException e) {
throw (new Error(e));
} catch (InvocationTargetException e) {
if (e.getCause() instanceof RuntimeException)
throw ((RuntimeException) e.getCause());
throw (new RuntimeException(e));
}
throw (new ClassNotFoundException(
"No valid constructor found for camera " + ct.getName()));
}
private static Camera restorecam() {
Class<? extends Camera> ct = camtypes.get(Utils.getpref("defcam",
"border"));
if (ct == null)
return (new BorderCam());
String[] args = (String[]) Utils.deserialize(Utils.getprefb("camargs",
null));
if (args == null)
args = new String[0];
try {
return (makecam(ct, args));
} catch (ClassNotFoundException e) {
return (new BorderCam());
}
}
public MapView(Coord c, Coord sz, Widget parent, Coord mc, int playergob) {
super(c, sz, parent);
isui = false;
this.mc = mc;
this.playergob = playergob;
this.cam = restorecam();
setcanfocus(true);
glob = ui.sess.glob;
map = glob.map;
mask = new ILM(MainFrame.getScreenSize(), glob.oc);
radiuses = new HashMap<String, Integer>();
radiuses.put("gfx/terobjs/mining/minesupport", 100);
radiuses.put("gfx/terobjs/bhive", 150);
}
public void resetcam() {
if (cam != null) {
cam.reset();
}
}
// kerri
public int getTileFix(Coord tileCoord) {
int r = map.gettilen(tileCoord);
return r;
}
public static Coord m2s(Coord c) {
return (new Coord((c.x * 2) - (c.y * 2), c.x + c.y));
}
public static Coord s2m(Coord c) {
return (new Coord((c.x / 4) + (c.y / 2), (c.y / 2) - (c.x / 4)));
}
static Coord viewoffset(Coord sz, Coord vc) {
return (m2s(vc).inv().add(sz.div(2)));
}
public void grab(Grabber grab) {
this.grab = grab;
}
public void release(Grabber grab) {
if (this.grab == grab)
this.grab = null;
}
private Gob gobatpos(Coord c) {
for (Sprite.Part d : obscured) {
Gob gob = (Gob) d.owner;
if (gob == null)
continue;
if (d.checkhit(c.add(gob.sc.inv())))
return (gob);
}
for (Sprite.Part d : clickable) {
Gob gob = (Gob) d.owner;
if (gob == null)
continue;
if (d.checkhit(c.add(gob.sc.inv())))
return (gob);
}
return (null);
}
public boolean mousedown(Coord c, int button) {
setfocus(this);
Coord c0 = c;
c = new Coord((int) (c.x / getScale()), (int) (c.y / getScale()));
Gob hit = gobatpos(c);
// PF
if (path != null && button != 3) {
path.clear();
path_moving = false;
path_step = 0;
path_interact_object = null;
}
//Kerri
if(objectSelecting)
{
objectUnderMouse = hit;
objectSelecting = false;
return true;
}
Coord mc = s2m(c.add(viewoffset(sz, this.mc).inv()));
if (grab != null) {
try {
grab.mmousedown(mc, button);
return true;
} catch (GrabberException e) {
}
}
if ((cam != null) && cam.click(this, c, mc, button)) {
/* Nothing */
} else if (plob != null) {
Gob gob = null;
for (Gob g : plob)
gob = g;
wdgmsg("place", gob.rc, button, ui.modflags());
} else {
//Kerri
if (button == 1 && ui.modctrl && ui.modmeta) {
KerriUtils.addOL(hit);
}
//Kerri
if(button == 1 && ui.modctrl && ui.modshift) {
if(hit != null)
hit.setDrawOlay(!hit.getDrawOlay());
}
// PF
if (button == 3 && ui.modctrl && ui.modshift) {
if (hit == null)
path_interact_object = null;
else
path_interact_object = hit;
path = APXUtils._pf_find_path(mc, path_interact_object != null ? path_interact_object.id : 0);
update_pf_moving();
return true;
}
if (hit == null) {
if (button == 1 && ui.modshift) {
glob.oc.enqueue(mc);
glob.oc.checkqueue();
} else {
glob.oc.movequeue.clear();
if (Config.assign_to_tile) {
mc = tilify(mc);
}
wdgmsg("click", c0, mc, button, ui.modflags());
}
} else {
//Kerri: option
if (ui.modmeta && Config.objectBlink)
ui.chat.getawnd().wdgmsg("msg", "@$[" + hit.id + "]");
if (Config.assign_to_tile) {
mc = tilify(mc);
}
wdgmsg("click", c0, mc, button, ui.modflags(), hit.id,
hit.position());
}
}
return (true);
}
public boolean mouseup(Coord c, int button) {
c = new Coord((int) (c.x / getScale()), (int) (c.y / getScale()));
Coord mc = s2m(c.add(viewoffset(sz, this.mc).inv()));
if (grab != null) {
try {
grab.mmouseup(mc, button);
return (true);
} catch (GrabberException e) {
}
}
if ((cam != null) && cam.release(this, c, mc, button)) {
return (true);
} else {
return (true);
}
}
public void mousemove(Coord c) {
c = new Coord((int) (c.x / getScale()), (int) (c.y / getScale()));
this.pmousepos = c;
Coord mc = s2m(c.add(viewoffset(sz, this.mc).inv()));
this.mousepos = mc;
mouseAtTile = tilify(mousepos); //Kerri
Collection<Gob> plob = this.plob;
if (cam != null)
cam.move(this, c, mc);
if (grab != null) {
try {
grab.mmousemove(mc);
return;
} catch (GrabberException e) {
}
}
if (plob != null) {
Gob gob = null;
for (Gob g : plob)
gob = g;
boolean plontile = this.plontile ^ ui.modshift;
gob.move(plontile ? tilify(mc) : mc);
}
//Kerri
if(pmousepos != null)
objectUnderMouse = gobatpos(c);
else
objectUnderMouse = null;
if(objectUnderMouse == null) {
tip = null;
tips = null;
} else if(objectUnderMouse != null && ui.modshift){
String s;
s = "Res found on gob " + objectUnderMouse.id;
String names[] = objectUnderMouse.resnames();
if(names.length > 0){
for(String name : names){
if(name.contains("gfx/borka")){
name = name.replace("gfx/borka/","");
if(name.contains("/"))
name = name.substring(0,name.indexOf("/"));
if(name.equals("body") || name.startsWith("hair") || s.contains(name))
continue;
}
s += "\n"+name;
}
}
if(tip == null || !tips.equals(s)){
tips = s;
tip = null;
tooltip(null,false);
}
}
}
String tips;
Text tip = null;
public Object tooltip(Coord c,boolean again){
if(tip != null)
return(tip);
if(tips != null && !tips.equals("")){
tip = RichText.render(tips,200);
}
return(tip);
}
public boolean mousewheel(Coord c, int amount) {
if (!Config.zoom)
return false;
si = Math.min(8, Math.max(0, si - amount));
setScale(scales[si]);
return (true);
}
public void move(Coord mc) {
this.mc = mc;
}
public static Coord tilify(Coord c) {
c = c.div(tileSize);
c = c.mul(tileSize);
c = c.add(tileSize.div(2));
return (c);
}
public static Coord tilefy_ns(Coord c) {
c = c.div(tileSize);
c = c.mul(tileSize);
return (c);
}
private void unflashol() {
for (int i = 0; i < visol.length; i++) {
if ((olflash & (1 << i)) != 0)
visol[i]--;
}
olflash = 0;
olftimer = 0;
}
public void uimsg(String msg, Object... args) {
if (msg == "move") {
move((Coord) args[0]);
if (cam != null)
cam.moved(this);
} else if (msg == "flashol") {
unflashol();
olflash = (Integer) args[0];
for (int i = 0; i < visol.length; i++) {
if ((olflash & (1 << i)) != 0)
visol[i]++;
}
olftimer = System.currentTimeMillis() + (Integer) args[1];
} else if (msg == "place") {
Collection<Gob> plob = this.plob;
if (plob != null) {
this.plob = null;
glob.oc.lrem(plob);
}
plob = new LinkedList<Gob>();
plontile = (Integer) args[2] != 0;
Gob gob = new Gob(glob, plontile ? tilify(mousepos) : mousepos);
Resource res = Resource.load((String) args[0], (Integer) args[1]);
gob.setattr(new ResDrawable(gob, res));
plob.add(gob);
glob.oc.ladd(plob);
if (args.length > 3) {
plrad = (Integer) args[3];
radiuses.put(res.name, plrad);
if (res.name.equals("gfx/terobjs/bhive"))
radiuses.put("gfx/terobjs/bhived", plrad);
}
this.plob = plob;
} else if (msg == "unplace") {
if (plob != null)
glob.oc.lrem(plob);
plob = null;
plrad = 0;
} else if (msg == "polowner") {
String o = ((String) args[0]).intern();
if (o != polowner) {
if (o.length() == 0) {
if (this.polowner != null)
this.polownert = polownertf.render("Leaving "
+ this.polowner);
this.polowner = null;
} else {
this.polowner = o;
this.polownert = polownertf.render("Entering " + o);
}
this.polchtm = System.currentTimeMillis();
}
} else {
super.uimsg(msg, args);
}
}
public void enol(int... overlays) {
for (int ol : overlays)
visol[ol]++;
}
public void disol(int... overlays) {
for (int ol : overlays)
visol[ol]--;
}
@SuppressWarnings("unused")
public int gettilen(Coord tc) {
int r = map.gettilen(tc);
return (r);
}
private Tile getground(Coord tc) throws Loading {
Tile r = map.getground(tc);
if (r == null)
throw (new Loading());
return (r);
}
private Tile[] gettrans(Coord tc) throws Loading {
Tile[] r = map.gettrans(tc);
if (r == null)
throw (new Loading());
return (r);
}
private int getol(Coord tc) throws Loading {
int ol = map.getol(tc);
if (ol == -1)
throw (new Loading());
return (ol);
}
private void drawtile(GOut g, Coord tc, Coord sc) {
Tile t;
try {
t = getground(tc);
// t = gettile(tc).ground.pick(0);
g.image(t.tex(), sc);
// g.setColor(FlowerMenu.pink);
// Utils.drawtext(g, Integer.toString(t.i), sc);
if (Config.tileAA) {
for (Tile tt : gettrans(tc)) {
g.image(tt.tex(), sc);
}
}
} catch (Loading e) {
}
}
// JSBot
public void map_move(int obj_id, Coord offset) {
Coord oc, sc;
int btn = 1;
int modflags = 0;
Gob gob;
synchronized (glob.oc) {
gob = glob.oc.getgob(obj_id);
}
if (gob == null)
return;
sc = new Coord((int) Math.round(Math.random() * 200 + sz.x / 2 - 100),
(int) Math.round(Math.random() * 200 + sz.y / 2 - 100));
oc = gob.position();
oc = oc.add(offset);
wdgmsg("click", sc, oc, btn, modflags, obj_id, oc);
}
public void map_move_step(int x, int y) {
Gob pgob;
int btn = 1;
int modflags = 0;
synchronized (glob.oc) {
pgob = glob.oc.getgob(playergob);
}