This repository has been archived by the owner on Apr 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
vuTools.user.js
2142 lines (1935 loc) · 110 KB
/
vuTools.user.js
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
// ==UserScript==
// @name vuTools
// @version 0.26
// @author Ivan Jelenić (Quirinus)
// @description A userscript to improve various user interface bits of the Visual Utopia browser game.
// @homepage https://github.com/Quirinus/
// @namespace https://github.com/Quirinus/
// @downloadURL https://raw.githubusercontent.com/Quirinus/vuTools/master/vuTools.user.js
// @updateURL https://raw.githubusercontent.com/Quirinus/vuTools/master/vuTools.meta.js
// @supportURL https://github.com/Quirinus/vuTools/issues
// @icon http://visual-utopia.com/favicon.ico
// @match http://visual-utopia.com/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js
// @grant none
// ==/UserScript==
$(document).ready(function ()
{
var url = window.location.href;
/*$(function () {
$('<script>')
.attr('type', 'text/javascript')
.text(' $.fn.ready(function(){var b=$(".nonselectable"),c=$(".selectable");b.on("dragstart, selectstart",function(a){a.preventDefault()});c.on("dragstart, selectstart",function(a){a.stopPropagation()});b.find("*").andSelf().attr("unselectable","on");c.find("*").andSelf().removeAttr("unselectable")});')
.appendTo('head');
});
$(function () {
$('<style>')
.attr('type', 'text/css')
.text('.nonselectable{\
cursor: default;\
border: 0;\
color: inherit;\
background-color: inherit;\
font:inherit;\
pointer-events: none;\
-webkit-touch-callout: none;\
-webkit-user-select: none;\
-khtml-user-drag:none;\
-khtml-user-select: none;\
-moz-user-select: -moz-none;\
-moz-user-select: none;\
-ms-user-select: none;\
-o-user-select: none;\
user-select: none;}\
')
.appendTo('head');
});*/
$(function () {
$('<style>')
.attr('type', 'text/css')
.text('.underdotted { cursor: pointer; border-bottom: 1px dotted white; }')
.appendTo('head');
});
//http://stackoverflow.com/a/2901298
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
$(function () { //a clone for the page, not this script
$('<script>')
.attr('type', 'text/javascript')
.text("function numberWithCommasx(x) { return x.toString().replace(/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g, '$&,'); }; ")
.appendTo('head');
});
$(function () { //a clone for the page, not this script
$('<script>')
.attr('type', 'text/javascript')
.text("function sum_training_gold_cost() \
{ \
var sum = \
parseInt((document.getElementById('t1_total_cost').innerHTML).replace(/[^0-9]+/g, '')) + \
parseInt((document.getElementById('t2_total_cost').innerHTML).replace(/[^0-9]+/g, '')) + \
parseInt((document.getElementById('t3_total_cost').innerHTML).replace(/[^0-9]+/g, '')) + \
parseInt((document.getElementById('t4_total_cost').innerHTML).replace(/[^0-9]+/g, '')) + \
parseInt((document.getElementById('t5_total_cost').innerHTML).replace(/[^0-9]+/g, '')); \
document.getElementById('total_training_costs').innerHTML = numberWithCommasx(sum); \
document.getElementById('total_training_costs2').innerHTML = numberWithCommasx(sum); \
}")
.appendTo('head');
});
$(function () { //a clone for the page, not this script
$('<script>')
.attr('type', 'text/javascript')
.text("function sum_building_gold_cost() \
{ \
var sum = \
parseInt((document.getElementById('b_1_total_cost').innerHTML).replace(/[^0-9]+/g, '')) + \
parseInt((document.getElementById('b_2_total_cost').innerHTML).replace(/[^0-9]+/g, '')) + \
parseInt((document.getElementById('b_3_total_cost').innerHTML).replace(/[^0-9]+/g, '')) + \
parseInt((document.getElementById('b_4_total_cost').innerHTML).replace(/[^0-9]+/g, '')) + \
parseInt((document.getElementById('b_5_total_cost').innerHTML).replace(/[^0-9]+/g, '')); \
parseInt((document.getElementById('b_6_total_cost').innerHTML).replace(/[^0-9]+/g, '')); \
parseInt((document.getElementById('b_7_total_cost').innerHTML).replace(/[^0-9]+/g, '')); \
parseInt((document.getElementById('b_8_total_cost').innerHTML).replace(/[^0-9]+/g, '')); \
parseInt((document.getElementById('b_9_total_cost').innerHTML).replace(/[^0-9]+/g, '')); \
parseInt((document.getElementById('b_wall_total_cost').innerHTML).replace(/[^0-9]+/g, '')); \
document.getElementById('total_building_costs').innerHTML = numberWithCommasx(sum); \
document.getElementById('total_building_costs2').innerHTML = numberWithCommasx(sum); \
}")
.appendTo('head');
});
$(function () { //a clone for the page, not this script
$('<script>')
.attr('type', 'text/javascript')
.text("function addSlaves(slaves, cityID, cityName) { \
amount = prompt('How many slaves do you want to transfer to ' + cityName + ' ?\\n(Use minus to remove slaves)', slaves); \
if(amount) go('addSlaves.asp?cityID=' + cityID + '&amount=' + amount); }")
.appendTo('head');
});
/*function numberWithCommas_unselectable(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, "<span class='nonselectable'>,</span>");
}*/
var text_info = '';
if (url.indexOf('main.asp') != -1)
{
var citynames = $.makeArray($('.citynames'));
var city_len = citynames.length;
var title = '';
var city_name = '';
var city_name_span = '';
var city_ID = -1;
var city_gts = -1;
var city_gates;
var city_race = '';
var city_color;
var ruler_name = '';
var ruler_name_space_pos = -1;
var ruler_name_style = '';
var kd_name = '';
var name_separator_pos1 = -1;
var name_separator_pos2 = -1;
var name_separator_pos3 = -1;
var name_separator_pos4 = -1;
var name_separator_pos5 = -1;
var titles_trim = ['Mr. ', 'Sir ' , 'Lord ', 'Duke ' , 'Prince ', 'Ms. ', 'Lady ', 'Duchess ', 'Princess '];
var titles_len = titles_trim.length;
var kd_own = ['Childrens Playground'];
var kds_friendly = ['The Jester Empire'];
var kds_neutral_nokd = ['', 'The Native People', '*No Kingdom*'];
var kds_neutral = ['Mad and Dangerous', 'The Visual Utopia Empire', 'The Death Dealers', 'Forsaken'];
var kds_enemy = ['The Collective', 'Zeon'];
//var kds_relations = [kd_own, kds_friendly, kds_enemy];
var color_own = '#B679F0'; //plum, lightgray, thistle, #B9F2FF, #B679F0
var color_ownkd = 'chartreuse'; //lime, chartreuse, lightgray
var color_friendly = 'lightgray'; //#9DE0BA, #99FF99, lime
var color_neutral_nokd = 'yellow'; //yellow, darkkhaki
var color_neutral = 'gold'; //yellow, darkkhaki
var color_enemy = '#FF716E'; //crimson, tomato
//var colors_relations = [color_ownkd, color_friendly, color_enemy];
var kd_found = false;
var armies = $.makeArray($('.armyclick'));
var army_len = armies.length;
var army_onclick = '';
var army_name = '';
var army_ID = -1;
var army_ruler_name = '';
var army_ruler_name_short = '';
var army_size = '';
var army_size_img;
var army_race = '';
var army_race_short = '';
var army_kd = '';
var army_troops = -1;
var army_t3 = '';
var army_margin = '';
var army_left = '';
var army_top = '';
var army_name_span = '';
var army_name_width = '';
var army_color = '';
var army_size_index = -1;
var army_race_numbers = ['Human', 'Elf', 'Orc', 'Dwarf', 'Troll', 'Halfling'];
var army_race_fast_units = ['knights', 'riders', 'nazguls', '', '', 'pony riders'];
var army_size_signs = ['o', 'oo', 'ooo', 'I', 'I I', 'I I I', 'x', 'xx', 'xxx', 'xxxx', 'xxxxx', 'xxxxx+']; //▮
var army_size_names = ['scout', 'section', 'platoon', 'company', 'battalion', 'regiment', 'brigade', 'division', 'corps', 'army', 'army group', 'horde'];
var army_size_numbers = ['(1-5)', '(8-12)', '(20-50)', '(100-300)', '(500-1500)', '(2000-4000)', '(around 5000)', '(10,000-20,000)', '(around 50,000)', '(100,000-200,000)', '(around 500,000)', 'of more then one million soldiers']; //around 500,000 --> (200,000-1,000,000)
//var army_size_real_numbers = ['(1-5)', '(8-12)', '(20-50)', '(100-300)', '(500-1500)', '(2000-4000)', '(Around 5000)', '(10,000-20,000)', '(Around 50,000)', '(100,000-200,000)', '(200,000-1,000,000)', 'More then one million soldiers.'];
//here you can access variables under $('script:eq(2)), since they're already loaded
//strArmies
//gives info about users that have visible armies:
//Army ID # Army Name # x # y # Ruler name # r ## KDID # md # as # of Kingdom Name # usrID # a # total troops+1 # m # s
//1537074 #Prep#-1425#1828#Prince Pure The Caring#6##5540#-4#6# of Zeon#90244#0#1954#0#6
//x position = from -2500 to 2500 (4x2500x2500 = world size)
//y position = from -2500 to 2500 (4x2500x2500 = world size)
//r = race
//missing column between two ##? spells? frozen? aotd? losing troops due to something (morale, -gold, -food)? something to do with injured troops? something with xp? dragon?
//md = moving direction (the arrow shows it): 3 north-west, 2 north, 1 north-east, 0 east, -1 south-east, -2 south, -3 south-west, -4 or 4 west
//as = army size (like the army_sizes array above, 0 o, oo, ooo, 3 I, II, III, 6 X, XX, XXX, XXXX , 10 XXXX, XXXXX, XXXXX)
//a = prepping on a town (maybe siege, but don't think so)
//m = tier 3 units only in the army, moves faster
//s = spells/status. frozen = 6. losing troops due to something (morale, -gold, -food)? something to do with injured troops? something with xp? dragon?
var armies_info = strArmies.split('&');
armies_info.pop();
var armies_info_len = armies_info.length;
var army_info = '';
var ai_users = [];
//var ai_userIDs = [];
//var ai_user_kdIDs = [];
var ai_armyIDs = [];
var ai_troops = [];
var ai_t3 = [];
var ai_name = [];
var ai_race = [];
var ai_size = [];
var ai_size_signs = [];
var ai_user_kds = [];
/* //needed for army vision range
var ai_x = [];
var ai_y = [];
var a_los_marker;
var a_fow_square_width;
var army_los_radius_safe_margin;
var army_los_radius;
var army_x;
var army_y;
var army_los_color;
var army_los_show;*/
for (i = 0; i < armies_info_len; i++)
{
army_info = armies_info[i].split('#');
ai_name[i] = army_info[1];
ai_armyIDs[i] = army_info[0];
ai_race[i] = army_race_numbers[parseInt(army_info[5]) - 1]; //from https://static.visual-utopia.com/main.js
ai_users[i] = army_info[4];
//ai_userIDs[i] = army_info[11];
ai_size[i] = army_size_names[parseInt(army_info[9]) - 1];
ai_size_signs[i] = army_size_signs[parseInt(army_info[9]) - 1];
ai_troops[i] = numberWithCommas(parseInt(army_info[13])-1) + ' troops';
if (ai_troops[i] == '1 troops')
ai_troops[i] = '1 soldier';
//ai_t3[i] = (army_info[14] == '0') ? '' : '\nOnly tier 3 troops - movement bonus.';
ai_t3[i] = (army_info[14] == '0') ? '' : '\nOnly ' + army_race_fast_units[parseInt(army_info[5]) - 1] + ' in army - movement bonus.';
if (army_info[10] === '')
{
ai_user_kds[i] = '';
}
else
{
ai_user_kds[i] = army_info[10].substr(4);
}
//ai_user_kdIDs[i] = army_info[7];
/* //needed for army vision range
ai_x[i] = (parseInt(army_info[2]) + 2500).toString(); // since x range from the game is -2500 to 2500, and the click detection is 0 to 5000, I add 2500 to this
ai_y[i] = (parseInt(army_info[3]) + 2500).toString(); // since y range from the game is -2500 to 2500, and the click detection is 0 to 5000, I add 2500 to this
*/
//WORKS: shows army vision range (uncomment the neccesary variable declarations above)
/*a_fow_square_width = 99;
army_los_radius_safe_margin = Math.ceil(a_fow_square_width/2) + 20;
army_los_radius = parseInt(armyLOS) + army_los_radius_safe_margin;
army_x = parseInt(ai_x[i]) - army_los_radius;
army_y = parseInt(ai_y[i]) - army_los_radius;
army_los_color = '';
army_los_show = false;
if (kds_enemy.indexOf(ai_user_kds[i]) !== -1)
{
army_los_show = true;
army_los_color = color_enemy;
}
if (kds_neutral.indexOf(ai_user_kds[i]) !== -1)
{
army_los_show = true;
army_los_color = color_neutral;
}
if (kd_own.indexOf(ai_user_kds[i]) !== -1)
{
army_los_show = true;
army_los_color = color_own;
}
if (army_los_show)
{
a_los_marker = $('<div></div>')
.css('position', 'absolute')
.css('top', army_y)
.css('left', army_x)
.css('width', 2*army_los_radius)
.css('height', 2*army_los_radius)
.css('border', '1px solid ' + army_los_color)
.css('-moz-border-radius', army_los_radius)
.css('-webkit-border-radius', army_los_radius)
.css('pointer-events', 'none')
.css('border-radius', army_los_radius);
$('#hideSpill').append(a_los_marker);
}
army_los_show = false;*/
}
var armyID_check_index = -1;
/*var _oldpop = pop;
function pop() {
_oldpop();//if you need previous function
//extend code here;
alert('gg');
}*/
//alert(pop('armyInfoE.asp?armyID=1537470'));
//hide armies - unfininshed
/*var shift_click_distance = -1;
var shift_click_army_id = -1;
var shift_click_x = -1;
var shift_click_y = -1;
var shift_click_x_old = -1;
var shift_click_y_old = -1;
var armies_hide_index = [];
var armies_hide_id = [];
var armies_hide_len = 0;
var cycle_id = 0;
var cycle_z = 0;
function get_armies_in_distance()
{
armies_hide_index = [];
armies_hide_id = [];
//alert($(armies[3]).attr('onclick').replace("pop('armyInfoE.asp?armyID=", '').replace("')", '').trim() == 1537446);
for (i = 0; i < armies_info_len; i++)
{
shift_click_distance = Math.sqrt(Math.pow(ai_x[i] - shift_click_x,2) + Math.pow(ai_y[i] - shift_click_y,2));
if (shift_click_distance < 150)
{
shift_click_army_id = ai_armyIDs[i];
for (j = 0; j < army_len; j++)
{
if ($(armies[j]).attr('onclick').replace("pop('armyInfoE.asp?armyID=", '').replace("')", '').trim() == shift_click_army_id)
{
armies_hide_index[armies_hide_index.length] = j;
armies_hide_id[armies_hide_id.length] = shift_click_army_id;
}
}
}
}
armies_hide_len = armies_hide_index.length;
}
function cycle_hide_armies()
{
//if (armies_hide_len > 0)
//{
for (i = 0; i < armies_hide_len; i++)
{
if (i === cycle_id)
{
cycle_z = '1';
}
else
{
cycle_z = '0';
}
j = armies_hide_index[i];
$(armies[j]).css('z-index', cycle_z);
$(armies[j]).next().css('z-index', cycle_z);
$('img[style*="top: ' + (parseInt($(armies[j]).css('top'))-6).toString() + 'px; left: ' + (parseInt($(armies[j]).css('left'))-1).toString() + 'px"]').css('z-index', cycle_z);
//alert('img[style*="top: ' + (parseInt($(armies[j]).css('top'))-6).toString() + 'px; left: ' + (parseInt($(armies[j]).css('left'))-1).toString() + 'px"]');
//alert(shift_click_distance + ' ' + ai_size_signs[i] + '\n' + ai_name[i] + ': '+ ai_race[i] + ' ' + ai_size[i] + ' (' + ai_troops[i] + ')\n' + ai_users[i] + ' ' + ai_user_kds[i] + ai_t3[i]);
}
//}
}
function handle_cycle_distance(e)
{
if (e.shiftKey)
{
if ($(this).attr('class') === 'fow')
{
alert('fow');
shift_click_x = e.pageX - $(this).parent().offset().left;
shift_click_y = e.pageY - $(this).parent().offset().top;
if ((shift_click_x !== shift_click_x_old) && (shift_click_y !== shift_click_y_old))
{
get_armies_in_distance(shift_click_x, shift_click_y);
cycle_id = 0;
}
else
{
cycle_id++;
if (cycle_id === armies_hide_len)
cycle_id = 0;
}
cycle_hide_armies();
return;
}
else if ($(this).prop("tagName") === 'IMG')
{
if ($(this).parent().attr('id') === 'karta')
{
alert('#karta > img');
shift_click_x = e.pageX - $(this).parent().offset().left - 2500;
shift_click_y = e.pageY - $(this).parent().offset().top - 2500;
if ((shift_click_x !== shift_click_x_old) && (shift_click_y !== shift_click_y_old))
{
get_armies_in_distance(shift_click_x, shift_click_y);
cycle_id = 0;
}
else
{
cycle_id++;
if (cycle_id === armies_hide_len)
cycle_id = 0;
}
cycle_hide_armies();
return;
}
else if ($(this).parent().attr('id') === 'hideSpill')
{
alert('#hideSpill > img');
shift_click_x = parseInt($(this).css('left')) + e.pageX - $(this).offset().left;
shift_click_y = parseInt($(this).css('top')) + e.pageY - $(this).offset().top;
if ((shift_click_x !== shift_click_x_old) && (shift_click_y !== shift_click_y_old))
{
get_armies_in_distance(shift_click_x, shift_click_y);
cycle_id = 0;
}
else
{
cycle_id++;
if (cycle_id === armies_hide_len)
cycle_id = 0;
}
cycle_hide_armies();
return;
}
}
else if ($(this).prop("tagName") === 'DIV')
{
if ($(this).parent().attr('id') === 'hideSpill')
{
alert('#hideSpill > div');
shift_click_x = parseInt($(this).css('left')) + e.pageX - $(this).offset().left;
shift_click_y = parseInt($(this).css('top')) + e.pageY - $(this).offset().top;
if ((shift_click_x !== shift_click_x_old) && (shift_click_y !== shift_click_y_old))
{
get_armies_in_distance(shift_click_x, shift_click_y);
cycle_id = 0;
}
else
{
cycle_id++;
if (cycle_id === armies_hide_len)
cycle_id = 0;
}
cycle_hide_armies();
return;
}
else if (($(this).parent().prop("tagName") === 'DIV') && ($(this).parent().parent().prop("tagName") === 'BODY') && ($(this).parent().parent().parent().prop("tagName") === 'HTML'))
{
alert('html > body > div > div');
shift_click_x = e.pageX - $(this).offset().left;
shift_click_y = e.pageY - $(this).offset().top;
if ((shift_click_x !== shift_click_x_old) && (shift_click_y !== shift_click_y_old))
{
get_armies_in_distance(shift_click_x, shift_click_y);
cycle_id = 0;
}
else
{
cycle_id++;
if (cycle_id === armies_hide_len)
cycle_id = 0;
}
cycle_hide_armies();
return;
}
}
}
}
$("#hideSpill > img").off('click','#karta > img', handle_cycle_distance).off('click', '#hideSpill > div', handle_cycle_distance).off('click', 'html > body > div > div', handle_cycle_distance).off('click', '.fow', handle_cycle_distance).on('click', handle_cycle_distance);
$("#karta > img").off('click','#hideSpill > img', handle_cycle_distance).off('click', '#hideSpill > div', handle_cycle_distance).off('click', 'html > body > div > div', handle_cycle_distance).off('click', '.fow', handle_cycle_distance).on('click', handle_cycle_distance);
$("#hideSpill > div").off('click','#karta > img', handle_cycle_distance).off('click', '#hideSpill > img', handle_cycle_distance).off('click', 'html > body > div > div', handle_cycle_distance).off('click', '.fow', handle_cycle_distance).on('click', handle_cycle_distance);
$("html > body > div > div").off('click','#karta > img', handle_cycle_distance).off('#hideSpill > img', handle_cycle_distance).off('click', '#hideSpill > div', handle_cycle_distance).off('click', '.fow', handle_cycle_distance).on('click', handle_cycle_distance);
$(".fow").off('click','#karta > img', handle_cycle_distance).off('click', '#hideSpill > img', handle_cycle_distance).off('click', '#hideSpill > div', handle_cycle_distance).off('click', 'html > body > div > div', handle_cycle_distance).on('click', handle_cycle_distance);
*/
//armies
$('div[style*="arrow"]').css('-webkit-filter', 'invert(100%)').css('filter', 'invert(100%)'); //css('z-index', '2'); // and add image map with coordinates from img, rotated for each
$('img[src*="armysize"]').css('-webkit-filter', 'invert(100%)').css('filter', 'invert(100%)').css('z-index', '2');
$('img[src*="reddot"]').css('-webkit-filter', 'invert(100%)').css('filter', 'invert(100%)');
for (i = 0; i < army_len; i++)
{
title = $(armies[i]).attr('title');
army_onclick = $(armies[i]).attr('onclick');
army_ID = army_onclick.replace("pop('armyInfoE.asp?armyID=", '').replace("')", '');
//army_onclick = 'pop2(' + army_ID +');';
//army_onclick = 'if (!e.shiftKey) ' + army_onclick;
//$(armies[i]).attr('onclick', army_onclick);
name_separator_pos1 = title.indexOf(': ');
name_separator_pos2 = title.substring(name_separator_pos1 + ': '.length).indexOf(' ');
name_separator_pos3 = title.substring(name_separator_pos2 + ' '.length).indexOf(' ');
name_separator_pos4 = title.indexOf(' controlled by ');
army_name = title.substring(0, name_separator_pos1);
army_race = title.substring(name_separator_pos1 + ': '.length, name_separator_pos1 + ': '.length + name_separator_pos2);
army_size = title.substring(title.indexOf(army_race) + army_race.length, name_separator_pos4).trim();
army_race_short = '[' + army_race.substr(0,2) + ']';
name_separator_pos5 = title.substring(name_separator_pos4 + ' controlled by '.length).indexOf(' of ');
if (name_separator_pos5 !== -1)
{
armyID_check_index = ai_armyIDs.indexOf(army_ID);
if (armyID_check_index !== -1)
{
army_ruler_name = ai_users[armyID_check_index];
army_kd = ai_user_kds[armyID_check_index];
army_troops = ai_troops[armyID_check_index];
army_t3 = ai_t3[armyID_check_index];
}
else
{
//error,try to do it with the classic method that may fail in complicated cases and give wrong user/kd name cutoffs
army_ruler_name = title.substring(name_separator_pos4 + ' controlled by '.length, name_separator_pos4 + ' controlled by '.length + name_separator_pos5);
army_kd = title.substring(title.indexOf(army_ruler_name) + army_ruler_name.length + ' of '.length);
army_troops = ' ERROR fetching troop number';
army_t3 = '\nERROR fetching tier 3';
}
}
else
{
armyID_check_index = ai_armyIDs.indexOf(army_ID);
if (armyID_check_index !== -1)
{
army_ruler_name = ai_users[armyID_check_index];
army_kd = ''; //army_kd = ai_user_kds[armyID_check_index];
army_troops = ai_troops[armyID_check_index];
army_t3 = ai_t3[armyID_check_index];
}
else
{
//error,try to do it with the classic method that may fail in complicated cases and give wrong user/kd name cutoffs
army_ruler_name = title.substring(name_separator_pos4 + ' controlled by '.length);
army_kd = '';
army_troops = ' ERROR fetching troop number';
army_t3 = '\nERROR fetching tier 3';
}
}
if (army_ruler_name == strRulerName)
{
army_color = color_own;
}
else if (army_kd == kd_own[0])
{
army_color = color_ownkd;
}
else if (kds_friendly.indexOf(army_kd) !== -1)
{
army_color = color_friendly;
}
else if (kds_neutral.indexOf(army_kd) !== -1)
{
army_color = color_neutral;
}
else if (kds_enemy.indexOf(army_kd) !== -1)
{
army_color = color_enemy;
}
else //if (kds_neutral_nokd.indexOf(army_kd) !== -1)
{
army_color = color_neutral_nokd;
}
army_ruler_name_short = army_ruler_name;
for (j = 0; j < titles_len; j++)
{
if (army_ruler_name_short.indexOf(titles_trim[j]) === 0)
{
army_ruler_name_short = army_ruler_name_short.slice(titles_trim[j].length);
break;
}
}
if (army_ruler_name_short.length > 10)
{
ruler_name_space_pos = army_ruler_name_short.indexOf(' ');
if (ruler_name_space_pos !== -1)
army_ruler_name_short = army_ruler_name_short.substring(0, ruler_name_space_pos); //add another layer of indexOf(' ') for a short word
if (army_ruler_name_short.length > 10)
army_ruler_name_short == army_ruler_name_short.substring(0, 9);
}
if ($(armies[i]).hasClass('attackingarmy') || $(armies[i]).hasClass('frozen'))
{
army_margin = '2em';
}
else
{
army_margin = '1em';
}
army_left = parseInt($(armies[i]).css('left')); //.replace('px','') not needed if using parseInt
army_top = parseInt($(armies[i]).css('top'));
//add army race + ruler name, and make it link to the army
army_name_span = $('<a></a>')
.text(army_race_short + army_ruler_name_short)
.css({
'position' : 'absolute',
'text-decoration' : 'none',
'cursor' : 'pointer',
'top' : army_top,
'left' : army_left,
'margin-top' : army_margin,
'color' : army_color,
'font-weight' : 'bold',
'font-size' : '0.8em',
//'z-index' : '10',
'text-align' : 'center',
'text-shadow' : 'black 0px 0px 1px, black 0px 0px 1px, black 0px 0px 1px, black 0px 0px 1px, black 0px 0px 1px',
'-webkit-font-smoothing' : 'antialiased'
})
.attr('title', title)
.attr('onclick', army_onclick);
//make army size signs link to the army as well
army_size_img = $('img[style*="top: ' + (parseInt($(armies[i]).css('top'))-6).toString() + 'px; left: ' + (parseInt($(armies[i]).css('left'))-1).toString() + 'px"]');
army_size_img
.css('cursor', 'pointer')
.attr('title', title)
.attr('onclick', army_onclick)
.addClass('army_size_sign');
$(armies[i]).after(army_name_span);
army_name_width = parseInt(army_name_span.width());
army_name_span.css('left', army_left - Math.floor((army_name_width-$(armies[i]).width())/2)); //$(armies[i]).width() = 18 for normal army (16 + 2x1 border), 22 for attacking army (16 + 2x3), 28 for frozen (16 + 2x6)
//adds army troop numbers and if they're t3 to title
army_size_index = army_size_names.indexOf(army_size);
if (army_size_index !== -1)
{
army_kd = (army_kd !== '') ? 'of ' + army_kd : '';
title = army_name + ': '+ army_race + ' ' + army_size + ' (' + army_troops + ')\n'
+ army_ruler_name + ' ' + army_kd + army_t3;// + army_size_signs[army_size_index] + army_size_numbers[army_size_index]
$(armies[i]).attr('title', title); //add for own armies
army_name_span.attr('title', title); //add for own armies
army_size_img.attr('title', title); //add for own armies
}
else
{
//add for not found armies
alert('wrong army size! ' + army_name + ': '+ army_race + ' ' + army_size + ' (' + army_troops + ')\n'
+ army_ruler_name + ' ' + army_kd + army_t3); //group of armies causes this to pop up
}
}
//city info from strCities:
//cityID # city name # s # grc # x # y # ruler name # r ## kdID # g # of kd name # losgt # usrID # buildings
//s = city pic size
//grc = city pic race
//x = from -2500 to 2500 (4x2500x2500 = world size)
//y = from -2500 to 2500 (4x2500x2500 = world size)
//r = race
//missing column between two ## = spells? arma? fear from orc attack?
//g = gates none or open 0, closed 1
//losgt = extra line of sight from guardtowers, round or ceil(guartower number/2) = losgt;
//strCities
//gives info about users that have visible cities
var cities_info = strCities.split('&');
cities_info.pop();
var cities_info_len = cities_info.length;
var city_info = '';
var ci_users = [];
//var ci_userIDs = [];
var ci_user_kds = [];
//var ci_user_kdIDs = [];
var ci_cityIDs = [];
var ci_city_names = [];
var ci_city_gts = [];
var ci_city_gates = [];
var ci_city_los = [];
var ci_city_x = [];
var ci_city_y = [];
for (i = 0; i < cities_info_len; i++)
{
city_info = cities_info[i].split('#');
ci_cityIDs[i] = city_info[0];
ci_city_names[i] = city_info[1];
ci_users[i] = city_info[6];
//ci_userIDs[i] = city_info[11];
ci_city_gates[i] = city_info[10];
if ((ci_city_gates[i] === '') || (ci_city_gates[i] === '0'))
ci_city_gates[i] = 'Gates: Open or none.';
else if (ci_city_gates[i] === '1')
ci_city_gates[i] = 'Gates: Closed.';
ci_city_gts[i] = numberWithCommas(parseInt(city_info[12])*2);
if (ci_city_gts[i] == '2')
{
ci_city_gts[i] = '1 guardtower.';
}
else if (ci_city_gts[i] == '2,000')
{
ci_city_gts[i] = '2,000 or more guardtowers.';
}
else
{
ci_city_gts[i] = ci_city_gts[i] + ' guardtowers.';
}
//ci_city_los[i] = city_info[12]; //for city vision range
//ci_city_x[i] = (parseInt(city_info[4]) + 2500).toString(); //for city vision range
//ci_city_y[i] = (parseInt(city_info[5]) + 2500).toString(); //for city vision range
/*if (city_info[11] == '') //for city vision range
{
ci_user_kds[i] = '';
}
else
{
ci_user_kds[i] = city_info[11].substr(4);
}*/
//ci_user_kdIDs[i] = city_info[7];
//WORKS: show city vision range circles
/*var los_marker;
var fow_square_width = 99;
var city_los_radius_safe_margin = Math.ceil(fow_square_width/2) + 20;
var city_los_radius = parseInt(ci_city_los[i]) + parseInt(cityLOS) + city_los_radius_safe_margin;
var city_x = parseInt(ci_city_x[i]) - city_los_radius;
var city_y = parseInt(ci_city_y[i]) - city_los_radius;
var city_los_color = '';
var city_los_show = false;
if (kds_enemy.indexOf(ci_user_kds[i]) !== -1)
{
city_los_show = true;
city_los_color = color_enemy;
}
if (kds_neutral.indexOf(ci_user_kds[i]) !== -1)
{
city_los_show = true;
city_los_color = color_neutral;
}
if (kd_own.indexOf(ci_user_kds[i]) !== -1)
{
city_los_show = true;
city_los_color = color_own;
}
if (city_los_show)
{
los_marker = $('<div></div>')
.css('position', 'absolute')
.css('top', city_y)
.css('left', city_x)
.css('width', 2*city_los_radius)
.css('height', 2*city_los_radius)
.css('border', '1px solid ' + city_los_color)
.css('-moz-border-radius', city_los_radius)
.css('-webkit-border-radius', city_los_radius)
.css('pointer-events', 'none')
.css('border-radius', city_los_radius);
$('#hideSpill').append(los_marker);
}
city_los_show = false;*/
}
var cityID_check_index = -1;
//cities
for (i = 0; i < city_len; i++)
{
cityID_check_index = -1;
title = $(citynames[i]).attr('title');
city_name = citynames[i].innerHTML;
city_ID = $(citynames[i]).attr('onclick').replace("pop('cityInfoE.asp?cityID=", '').replace("')", '');
ruler_name = '';
if (title.indexOf('Your city:') === -1)
{
name_separator_pos1 = title.indexOf(' city owned by ');
city_race = title.substring(0, name_separator_pos1);
city_race = '[' + city_race.substr(0,2) + ']';
name_separator_pos2 = title.indexOf(' of ');
name_separator_pos3 = title.indexOf(':');
if (name_separator_pos2 !== -1)
{
cityID_check_index = ci_cityIDs.indexOf(city_ID);
if (cityID_check_index !== -1)
{
ruler_name = ci_users[cityID_check_index];
city_gts = ' ' + ci_city_gts[cityID_check_index];
city_gates = ' ' + ci_city_gates[cityID_check_index];
//kd_name = ci_user_kds[cityID_check_index];
}
else
{
//error,try to do it with the classic method that may fail in complicated cases and give wrong user/kd name cutoffs
ruler_name = title.substring(name_separator_pos1 + ' city owned by '.length, name_separator_pos2);
city_gts = '';
city_gates = '';
//kd_name = title.substring(name_separator_pos2 + ' of '.length, name_separator_pos3);
}
}
else
{
ruler_name = title.substring(name_separator_pos1 + ' city owned by '.length, name_separator_pos3);
city_gts = '';
city_gates = '';
//kd_name = '';
}
}
for (j = 0; j < titles_len; j++)
{
if (ruler_name.indexOf(titles_trim[j]) === 0)
{
ruler_name = ruler_name.slice(titles_trim[j].length);
break;
}
}
if (ruler_name.length > 10)
{
ruler_name_space_pos = ruler_name.indexOf(' ');
if (ruler_name_space_pos !== -1)
ruler_name = ruler_name.substring(0, ruler_name_space_pos);
if (ruler_name.length > 10)
ruler_name = ruler_name.substring(0, 9);
}
//citynames[i].innerHTML = city_race + city_name;
ruler_name_style = $(citynames[i]).attr('style');
$(citynames[i]).css({
'text-shadow' : 'black 0px 0px 1px, black 0px 0px 1px, black 0px 0px 1px, black 0px 0px 1px, black 0px 0px 1px',
'-webkit-font-smoothing' : 'antialiased'
});
title = numberWithCommas(title);
title = title + city_gts + city_gates;
title = title.replace(': ', ':\r');
$(citynames[i]).attr('title', title);
kd_found = false;
if (title.indexOf('Your city:') !== -1)
{
$(citynames[i]).css('color', color_own);
kd_found = true;
}
else
{
if (title.indexOf(kd_own[0]) !== -1)
{
city_color = color_ownkd;
kd_found = true;
}
if (!kd_found)
{
for (j = 0; j < kds_friendly.length ; j++)
{
if (title.indexOf(kds_friendly[j]) !== -1)
{
city_color = color_friendly;
kd_found = true;
break;
}
}
}
if (!kd_found)
{
for (j = 0; j < kds_neutral.length ; j++)
{
if (title.indexOf(kds_neutral[j]) !== -1)
{
city_color = color_neutral;
kd_found = true;
break;
}
}
}
if (!kd_found)
{
for (j = 0; j < kds_enemy.length ; j++)
{
if (title.indexOf(kds_enemy[j]) !== -1)
{
city_color = color_enemy;
kd_found = true;
break;
}
}
}
if (!kd_found)
{
//neutral,unlisted kds, no kds
city_color = color_neutral_nokd;
kd_found = true;
}
$(citynames[i]).css('color', city_color);
city_name_span = $('<span></span>')
.html(city_race + ruler_name)
.addClass('city_ruler_race_name')
.attr('style', ruler_name_style)
.css({
'width' : '100px',
'height' : '20px',
'margin-top' : '3em',
'text-decoration' : 'none',
'cursor' : 'default',
'color' : city_color,
'font-weight' : 'bold',
'font-size' : '0.8em',
'text-align' : 'center',
'text-shadow' : 'black 0px 0px 1px, black 0px 0px 1px, black 0px 0px 1px, black 0px 0px 1px, black 0px 0px 1px',
'-webkit-font-smoothing' : 'antialiased',
'pointer-events': 'none'
})
.attr('title', title);
$(citynames[i]).before(city_name_span);
}
}
//allows map scrolling when clicking on city img, waypoints and army movement arrows
$('#hideSpill > img:not(.armyclick):not(.army_size_sign)').css('pointer-events', 'none'); //important that it's after the code above, because .army_size_sign is added there
$('.wp').css('pointer-events', 'none');
$('div[style*="arrow"]').css('pointer-events', 'none');
}
//menu
//hidden buttons (display: none);, all with special ids
// mslot16 - production
// mslot11-16 - popout
// magic, waypoint
// hoh, mslot18-21 - popout
//click on army/city - popout
//click on the upper menu buttons - popout
//click on the hidden menu buttons - popout
//replies when kd button in the menu is blinking. this fixes is to go to the right post...
if (url.indexOf('&replies=') !== -1)
{
var reply_number = parseInt(url.substring(url.indexOf('&replies=')+'&replies='.length));
var page = Math.ceil((reply_number + 1)/50);
var page_navigation = $("a[href='#top']").parent().parent();
page_navigation = page_navigation.clone();
var current_page = parseInt(page_navigation.find('strong').text());
page_navigation.find('b').remove();
page_navigation.find('strong').remove();
page_navigation.find("a:contains('(next)')").remove();
page_navigation.find("a:contains('(back)')").remove();
var max_page = Math.max(parseInt(page_navigation.find('a:last-child').text()), current_page);
var url_page = url.indexOf('&page=');
if (url_page !== -1)
url_page = parseInt(url.substring(url_page + '&page='.length));
else
url_page = max_page;
var reply_number_mod = reply_number%50;
if ((page === current_page) || (page === url_page))
{
$("#main > table:eq(0) > tbody > tr:eq(" + (reply_number_mod+1).toString() + ")").attr('id','reply_post');
window.location.href = '#reply_post'; //fix it not jumping so the id is at the top of the page, there's a small gap
}
else
{
if (window.location.href.indexOf('&page=') === -1)
{
window.open(window.location.href.replace('&replies=', '&page=' + page + '&replies='), '_self');
}
else
{
window.open(window.location.href.replace(/\&page=[0-9]+/, '&page=' + page), '_self');
}