-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv150.cpp
More file actions
1765 lines (1676 loc) · 63 KB
/
v150.cpp
File metadata and controls
1765 lines (1676 loc) · 63 KB
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
#define _ALLOW_KEYWORD_MACROS
#if(!defined(_DEBUG)&&!defined(Adler))
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable"
#pragma warning(push,1)
#include <cstring>
#endif
#ifndef NOMINMAX
#define NOMINMAX
#endif
#define private public
#define protected public
#include "MyStrategy.h"
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
using std::vector;
using std::string;
//#undef Adler
#ifdef Adler
#include <Windows.h>
#include <fstream>
inline string IToS(const int&val){char c[16];_itoa_s(val,c,10);return string(c);}
inline string FToS(const double&val){char c[64];if(abs(val)>1e9){_snprintf_s(c,32,32,"%e",val);}else{sprintf_s(c,"%f",val);}return string(c);}
inline string FToS2(const double&val){char c[64];if(abs(val)>1e9){_snprintf_s(c,32,32,"%e",val);}else{sprintf_s(c,"%.2f",val);}return string(c);}
static bool IsKeyDown(int vKey){int i=GetAsyncKeyState(vKey);return i<0;}
#define KB_CODE(){auto mwta=game.getWizardMaxTurnAngle();if(IsKeyDown('Q'))move.setTurn(-mwta);if(IsKeyDown('E'))move.setTurn(+mwta);if(IsKeyDown('W'))move.setSpeed(+100);if(IsKeyDown('S'))move.setSpeed(-100);if(IsKeyDown('D'))move.setStrafeSpeed(+100);if(IsKeyDown('A'))move.setStrafeSpeed(-100);}
static bool file_put_contents(const string&FN,const string&mem)
{
using namespace std;
fstream f;
f.open(FN.c_str(),ios::out|ios::binary);
if(!f)return false;
if(!mem.empty())f.write(&mem[0],mem.size());
f.close();
return true;
};
#else
void KB_CODE(){}
static bool file_put_contents(const string&FN,const string&mem){return true;}
#endif
#define QapAssert(COND)if(!(COND))__debugbreak();
#define PRO_FUNCGEN_GETP_BY_FIELD(rettype,getp,arr,field_type,field)\
rettype*getp(field_type value)\
{\
rettype*p=nullptr;\
for(int i=0;i<arr.size();i++){\
auto&ex=arr[i];\
if(ex.field!=value)continue;\
QapAssert(!p);\
p=&ex;\
}\
return p;\
}
#define PRO_FUNCGEN_ADD_UNIQUE_OBJ_BY_FIELD_V2(rettype,adduni,arr,field_type,field)\
rettype*adduni(field_type value)\
{\
rettype*p=nullptr;\
for(int i=0;i<arr.size();i++){\
auto&ex=arr[i];\
if(ex.field!=value)continue;\
QapAssert(!p);\
p=&ex;\
}\
if(!p){p=&qap_add_back(arr);p->field=value;}\
return p;\
}
template<typename TYPE,size_t COUNT>inline size_t lenof(TYPE(&)[COUNT]){return COUNT;}
template<class TYPE,class FUNC>
int qap_minval_id_for_vec(vector<TYPE>&arr,FUNC func){
if(arr.empty())return -1;
int id=0;auto val=func(arr[0],0);
for(int i=1;i<arr.size();i++){
auto&ex=arr[i];
auto tmp=func(ex,i);
if(tmp>=val)continue;
val=tmp;id=i;
}
return id;
}
template<class TYPE,class FUNC>
int qap_minval_id_for_vec(const vector<TYPE>&arr,FUNC func){
if(arr.empty())return -1;
int id=0;auto val=func(arr[0],0);
for(int i=1;i<arr.size();i++){
auto&ex=arr[i];
auto tmp=func(ex,i);
if(tmp>=val)continue;
val=tmp;id=i;
}
return id;
}
template<class TYPE>int qap_includes(const vector<TYPE>&arr,const TYPE&value){for(int i=0;i<arr.size();i++){if(arr[i]==value)return true;}return false;}
#define QAP_MINVAL_ID_OF_VEC(arr,code)qap_minval_id_for_vec(arr,[&](decltype(arr[0])&ex,int i){return code;})
template<class TYPE,class FUNC>void qap_foreach(vector<TYPE>&arr,FUNC func){for(int i=0;i<arr.size();i++)func(arr[i],i);}
template<class TYPE,class FUNC>void qap_foreach(const vector<TYPE>&arr,FUNC func){for(int i=0;i<arr.size();i++)func(arr[i],i);}
#define QAP_FOREACH(arr,code)qap_foreach(arr,[&](decltype(arr[0])&ex,int i){code;})
template<class TYPE,class FUNC>void clean_if(vector<TYPE>&Arr,FUNC&Pred){int last=0;for(int i=0;i<Arr.size();i++){auto&ex=Arr[i];if(Pred(ex))continue;if(last!=i){auto&ax=Arr[last];ax=std::move(ex);}last++;}if(last==Arr.size())return;Arr.resize(last);}
template<class TYPE,class FUNC>void clean_if(vector<TYPE>&Arr,const FUNC&Pred){int last=0;for(int i=0;i<Arr.size();i++){auto&ex=Arr[i];if(Pred(ex))continue;if(last!=i){auto&ax=Arr[last];ax=std::move(ex);}last++;}if(last==Arr.size())return;Arr.resize(last);}
template<class TYPE,class FUNC>void clean_if(vector<TYPE>&Arr,FUNC&&Pred){int last=0;for(int i=0;i<Arr.size();i++){auto&ex=Arr[i];if(Pred(ex))continue;if(last!=i){auto&ax=Arr[last];ax=std::move(ex);}last++;}if(last==Arr.size())return;Arr.resize(last);}
template<class TYPE>static TYPE&qap_add_back(vector<TYPE>&arr){arr.resize(arr.size()+1);return arr.back();}
template<typename TYPE>TYPE Sign(TYPE value){return (value>0)?TYPE(+1):TYPE(value<0?-1:0);}
typedef double real;const real Pi=3.14159265;const real Pi2=Pi*2;const real PiD2=Pi/2;const real PiD4=Pi/4;
template<class TYPE>inline TYPE Clamp(const TYPE&v,const TYPE&a,const TYPE&b){return std::max(a,std::min(v, b));}
template<typename TYPE>inline TYPE Lerp(const TYPE&A,const TYPE&B,const real&v){return A+(B-A)*v;}
class vec2d{
public:
real x;real y;
vec2d():x(0.0),y(0.0) {}
vec2d(const real&x,const real&y):x(x),y(y) {}
vec2d(const vec2d&v):x(v.x),y(v.y) {}
public:
vec2d&operator=(const vec2d&v){x=v.x;y=v.y;return *this;}
vec2d operator+()const{return *this;}
vec2d operator-()const{return vec2d(-x,-y);}
vec2d&operator+=(const vec2d&v){x+=v.x;y +=v.y;return *this;}
vec2d&operator-=(const vec2d&v){x-=v.x; y-=v.y;return *this;}
vec2d&operator*=(const real&f){x*=f;y*=f;return *this;}
vec2d&operator/=(const real&f){x/=f;y/=f;return *this;}
public:
vec2d Rot(const vec2d&OX)const{real M=OX.Mag();return vec2d(((x*+OX.x)+(y*OX.y))/M,((x*-OX.y)+(y*OX.x))/M);}
vec2d UnRot(const vec2d&OX)const{real M=OX.Mag();if(M==0.0f){return vec2d(0,0);};return vec2d(((x*OX.x)+(y*-OX.y))/M,((x*OX.y)+(y*+OX.x))/M);}
vec2d Ort()const{return vec2d(-y,x);}
vec2d Norm()const{if((x==0)&&(y==0)){return vec2d(0,0);}return vec2d(x/this->Mag(),y/this->Mag());}
vec2d SetMag(const real&val)const{return this->Norm().Mul(vec2d(val,val));}
vec2d Mul(const vec2d&v)const{return vec2d(x*v.x,y*v.y);}
vec2d Div(const vec2d&v)const{return vec2d(v.x!=0?x/v.x:x,v.y!=0?y/v.y:y);}
real GetAng()const{return atan2(y,x);}
real Mag()const{return sqrt(x*x+y*y);}
real SqrMag()const{return x*x+y*y;}
public:
real dist_to(const vec2d&p)const{return hypot(p.x-x,p.y-y);}
real sqr_dist_to(const vec2d&p)const{return vec2d(p.x-x,p.y-y).SqrMag();}
bool dist_to_point_less_that_r(const vec2d&p,real r)const{return vec2d(p.x-x,p.y-y).SqrMag()<r*r;}
public:
static vec2d min(const vec2d&a,const vec2d&b){return vec2d(std::min(a.x,b.x),std::min(a.y,b.y));}
static vec2d max(const vec2d&a,const vec2d&b){return vec2d(std::max(a.x,b.x),std::max(a.y,b.y));}
static void comin(vec2d&a,const vec2d&b){a=min(a,b);}
static void comax(vec2d&a,const vec2d&b){a=max(a,b);}
static vec2d sign(const vec2d&p){return vec2d(Sign(p.x),Sign(p.y));}
public:
inline static real dot(const vec2d&a,const vec2d&b){return a.x*b.x+a.y*b.y;}
inline static real cross(const vec2d&a,const vec2d&b){return a.x*b.y-a.y*b.x;}
};
vec2d operator+(const vec2d&u,const vec2d&v){return vec2d(u.x+v.x,u.y+v.y);}
vec2d operator-(const vec2d&u,const vec2d&v){return vec2d(u.x-v.x,u.y-v.y);}
vec2d operator*(const vec2d&u,const real&v){return vec2d(u.x*v,u.y*v);}
vec2d operator*(const real&u,const vec2d&v){return vec2d(u*v.x,u*v.y);}
bool operator==(const vec2d&u,const vec2d&v){return (u.x==v.x)&&(u.y==v.y);}
bool operator!=(const vec2d&u,const vec2d&v){return !(u==v);}
inline vec2d Vec2dEx(const real&ang,const real&mag){return vec2d(cos(ang)*mag,sin(ang)*mag);}
template<class TYPE>
struct t_looped_buffer{
vector<TYPE> frames;
int n;
int ptr;
public:
t_looped_buffer(){n=8;ptr=0;}
void add(const TYPE&value)
{
QapAssert(n>0);
if(frames.size()!=n)frames.resize(n);
ptr=ptr%n;
frames[ptr]=value;
ptr++;
ptr=ptr%n;
}
void init(const TYPE&value){frames.resize(n,value);}
TYPE&get_average(){
TYPE sum;for(int i=0;i<frames.size();i++){sum+=frames[i];}
return sum*(1.0/frames.size());
}
};
using namespace model;
const Game*pgame=nullptr;
vec2d our_base_pos(000,4000);
vec2d real_our_base_pos(000,3600);
vec2d enemy_base_pos(-1,-1);
vec2d real_enemy_base_pos(-1,-1);
vec2d get_pos(const Unit&u){return vec2d(u.getX(),u.getY());}
real sqr(real x){return x*x;}
bool almost_equal(real a,real b,real eps=0.05){return abs(a-b)<eps;}
real get_selfdmgbon_mmmmm(const Wizard&ref){
auto&arr=ref.skills;
real k=0;
for(int i=0;i<arr.size();i++){
auto&ex=arr[i];
if(ex==SKILL_MAGICAL_DAMAGE_BONUS_PASSIVE_1)k=1;
if(ex==SKILL_MAGICAL_DAMAGE_BONUS_AURA_1)k=2;
if(ex==SKILL_MAGICAL_DAMAGE_BONUS_PASSIVE_2)k=3;
if(ex==SKILL_MAGICAL_DAMAGE_BONUS_AURA_2)k=4;
}
return k*pgame->magicalDamageBonusPerSkillLevel;
}
real get_selfdmgbon_staff(const Wizard&ref){
auto&arr=ref.skills;
real k=0;
for(int i=0;i<arr.size();i++){
auto&ex=arr[i];
if(ex==SKILL_STAFF_DAMAGE_BONUS_PASSIVE_1)k=1;
if(ex==SKILL_STAFF_DAMAGE_BONUS_AURA_1)k=2;
if(ex==SKILL_STAFF_DAMAGE_BONUS_PASSIVE_2)k=3;
if(ex==SKILL_STAFF_DAMAGE_BONUS_AURA_2)k=4;
}
return k*pgame->staffDamageBonusPerSkillLevel;
}
real get_mmmmm_dmg(const Wizard&ref){
return pgame->magicMissileDirectDamage+get_selfdmgbon_mmmmm(ref);
}
real get_staff_dmg(const Wizard&ref){
return pgame->staffDamage+get_selfdmgbon_staff(ref);
}
static bool is_hastened(const Wizard&ref){
auto&arr=ref.getStatuses();for(int i=0;i<arr.size();i++){auto&ex=arr[i];if(ex.getType()==STATUS_HASTENED)return true;}return false;
}
static const Status*get_hastened(const Wizard&ref){
auto&arr=ref.getStatuses();for(int i=0;i<arr.size();i++){auto&ex=arr[i];if(ex.getType()==STATUS_HASTENED)return &ex;}return nullptr;
}
static real get_rotfactor(const Wizard&ref){return (is_hastened(ref)?1.0+pgame->getHastenedRotationBonusFactor():1.0);}
int get_passive_movbon_factor(const Wizard&ref){
auto&arr=ref.skills;
int k=0;
for(int i=0;i<arr.size();i++){
auto&ex=arr[i];
if(ex==SKILL_MOVEMENT_BONUS_FACTOR_PASSIVE_1)k=1;
if(ex==SKILL_MOVEMENT_BONUS_FACTOR_PASSIVE_2)k=2;
}
return k;
}
int get_aura_movbon_factor(const Wizard&ref){
auto&arr=ref.skills;
int k=0;
for(int i=0;i<arr.size();i++){
auto&ex=arr[i];
if(ex==SKILL_MOVEMENT_BONUS_FACTOR_AURA_1)k=1;
if(ex==SKILL_MOVEMENT_BONUS_FACTOR_AURA_2)k=2;
}
return k;
}
int get_passive_mdmgbon(const Wizard&ref){
auto&arr=ref.skills;
int k=0;
for(int i=0;i<arr.size();i++){
auto&ex=arr[i];
if(ex==SKILL_MAGICAL_DAMAGE_BONUS_PASSIVE_1)k=1;
if(ex==SKILL_MAGICAL_DAMAGE_BONUS_PASSIVE_2)k=2;
}
return k;
}
int get_aura_mdmgbon(const Wizard&ref){
auto&arr=ref.skills;
int k=0;
for(int i=0;i<arr.size();i++){
auto&ex=arr[i];
if(ex==SKILL_MAGICAL_DAMAGE_BONUS_AURA_1)k=1;
if(ex==SKILL_MAGICAL_DAMAGE_BONUS_AURA_2)k=2;
}
return k;
}
int get_passive_staffdmgbon(const Wizard&ref){
auto&arr=ref.skills;
int k=0;
for(int i=0;i<arr.size();i++){
auto&ex=arr[i];
if(ex==SKILL_STAFF_DAMAGE_BONUS_PASSIVE_1)k=1;
if(ex==SKILL_STAFF_DAMAGE_BONUS_PASSIVE_2)k=2;
}
return k;
}
int get_aura_staffdmgbon(const Wizard&ref){
auto&arr=ref.skills;
int k=0;
for(int i=0;i<arr.size();i++){
auto&ex=arr[i];
if(ex==SKILL_STAFF_DAMAGE_BONUS_AURA_1)k=1;
if(ex==SKILL_STAFF_DAMAGE_BONUS_AURA_2)k=2;
}
return k;
}
template<class TYPE>
int update_df(const vector<TYPE>&arr,vec2d&df,int&n,const Wizard&self)
{
auto sp=get_pos(self);auto sr=self.getRadius();
real gap=4*4+1;real hgap=gap/4;
int tn=0;
for(int i=0;i<arr.size();i++){
auto&ex=arr[i];
if(self.getId()==ex.getId())continue;
bool neutral=ex.getFaction()==FACTION_NEUTRAL;
bool other=ex.getFaction()==FACTION_OTHER;
bool enemy_active=ex.getLife()!=ex.getMaxLife();
//if(neutral&&enemy_active)continue;
//if(ex.getFaction()!=self.getFaction()&&!other)continue;
if(other||(neutral&&!enemy_active))gap=hgap;
auto ep=get_pos(ex);auto er=ex.getRadius();
auto r=sr+er+gap;
auto dist=ep.dist_to(sp);
if(dist<r){
//df=df+(sp-ep).SetMag(1.0-sqr((dist-sr-er)/gap));n++;
df+=(sp-ep).Norm();n++;tn++;
}
}
return tn;
}
real get_attsec(const Building&u){return Pi2;}
real get_attsec(const Wizard&ref){return pgame->getStaffSector();}
real get_attsec(const Minion&ref){return ref.getType()==MINION_ORC_WOODCUTTER?pgame->getOrcWoodcutterAttackSector():pgame->getFetishBlowdartAttackSector();}
real get_attrange(const Minion&ref){return ref.getType()==MINION_ORC_WOODCUTTER?pgame->getOrcWoodcutterAttackRange():pgame->getFetishBlowdartAttackRange();}
real get_attrange(const Wizard&ref){return ref.getCastRange();}
real get_attrange(const Building&ref){return ref.getAttackRange();}
struct t_tow{
//int id;
vec2d pos;
int hp;
real attrange;
real r;
real dmg;
int cdt;
int rcdt;
Faction faction;
BuildingType type;
operator bool()const{return hp>0;}
};
static std::vector<t_tow> enemy_tows;
vec2d get_pos(const t_tow&u){return u.pos;}
real get_r(const CircularUnit&u){return u.getRadius();}
real get_r(const t_tow&u){return u.r;}
real get_ang(const CircularUnit&u){return u.getAngle();}
real get_ang(const t_tow&u){return 0;}
real get_attsec(const t_tow&u){return Pi2;}
real get_attrange(const t_tow&ref){return ref.attrange;}
int get_rcdt(const Wizard&e){return std::max(e.getRemainingCooldownTicksByAction()[ACTION_MAGIC_MISSILE],e.getRemainingActionCooldownTicks());}
template<class TYPE>int get_rcdt(const TYPE&e){return e.getRemainingActionCooldownTicks();}
int get_rcdt(const t_tow&e){return e.rcdt;}
struct t_shot_config{
#define LIST(F)\
F( -25,hp ,100.0)\
F(+100,attrange ,500.0)\
F( -10,rcdt ,60.0)\
F(+100,dmg ,12.0)\
F( +1,dist ,500.0)\
F( -10,self_turn_ticks,30.0)\
F(-1e3,self_rcdt ,30.0)\
F( +25,our_weapon_dmg ,12.0)\
// LIST
#define F(koef,var,base)real var;
LIST(F);
#undef F
t_shot_config(){
#define F(koef,var,base)this->var=real(koef)/base;
LIST(F);
#undef F
}
};
static const t_shot_config shot_conf;
int mmrad=0;
int mmdmg=0;
struct t_shot_state{
int dist;
int ang;
real spd;
t_shot_state(){dist=-1;ang=-1;spd=-1;}
bool operator!=(const t_shot_state&ref)const{return dist!=ref.dist||ang!=ref.ang||spd!=ref.spd;}
};
struct t_shot{
int wizid;
vec2d ep;
real er;
int hp;
real dmg;
real dist;
real self_turn_ticks;
real attrange;
int rcdt;
bool ready;
real profit;
ActionType action;
int self_rcdt;
t_shot_state target_cast_state;
real our_weapon_dmg;
void update_profit(const vec2d&sp,real sr){
auto&conf=shot_conf;
#define F(var)var*conf.var
profit=(
F(hp)+F(attrange)+F(rcdt)+F(dmg)+F(dist)+F(self_turn_ticks)+F(self_rcdt)+F(our_weapon_dmg)
);
if(hp<=mmdmg*2)if(attrange>=499)profit+=F(attrange);
auto base_dist=ep.dist_to(real_our_base_pos);
auto danger_dist=attrange+pgame->factionBaseRadius+mmrad;
if(base_dist<danger_dist){
profit+=25.0*(danger_dist-base_dist)/danger_dist;
}
#undef F
}
};
struct t_wizard_acc_stat{
typedef t_shot_state t_state;
struct t_rec{
t_state state;
int shots;
int hits;
t_rec(){shots=0;hits=0;}
operator bool(){return shots<1||real(hits)/shots>0.45;}
void add(bool hit){shots++;if(hit)hits++;}
};
int id;
t_rec total;
vector<t_rec> arr;
void add_event(bool hit,t_state state){
auto&rec=*dist2info(state);
rec.add(hit);
total.add(hit);
}
PRO_FUNCGEN_ADD_UNIQUE_OBJ_BY_FIELD_V2(t_rec,dist2info,arr,t_state,state);
};
vector<t_wizard_acc_stat> wizards_acc;
t_wizard_acc_stat final_wizacc;
PRO_FUNCGEN_ADD_UNIQUE_OBJ_BY_FIELD_V2(t_wizard_acc_stat,id2wizacc,wizards_acc,int,id);
struct t_magic_missle_target{
int selfid;
int wizid;
t_shot_state target_cast_state;
real beg_dist;
real hp;
real curhp;
int tick;
vec2d beg;
vec2d end;
void reset(){wizid=-1;hp=-1;tick=-1;curhp=-1;}
t_magic_missle_target(){reset();}
};
vector<t_magic_missle_target> mm_targets;
PRO_FUNCGEN_ADD_UNIQUE_OBJ_BY_FIELD_V2(t_magic_missle_target,selfid2mmtarget,mm_targets,int,selfid);
struct t_lane{
vector<t_tow*> arr;
vec2d get_pos()const{
for(int i=0;i<arr.size();i++)if(arr[i]->hp)return arr[i]->pos;
return real_enemy_base_pos+(real_enemy_base_pos-real_our_base_pos).SetMag(pgame->factionBaseRadius*0.5);
}
bool unlocked()const{
for(int i=0;i<arr.size();i++)if(arr[i]->hp)return false;
return true;
}
};
struct t_main_tower_info{
t_lane top;
t_lane mid;
t_lane low;
const t_lane&operator[](size_t id)const{return (&top)[id%3];}
t_lane&operator[](size_t id){return (&top)[id%3];}
bool unlocked()const{
auto&arr=*this;
for(int i=0;i<3;i++)if(arr[i].unlocked())return true;
return false;
}
};
t_main_tower_info enemy_main_tower;
struct t_unit{
int id;
vec2d pos;
real ang;
bool neutral;
bool agro;
t_looped_buffer<vec2d> loop_pos;
t_looped_buffer<real> loop_ang;
void load(const LivingUnit&ex){
id=ex.getId();
pos=get_pos(ex);
ang=get_ang(ex);
neutral=ex.getFaction()==FACTION_NEUTRAL;
agro=false;
if(loop_pos.frames.empty())loop_pos.init(pos);
loop_pos.add(pos);
if(loop_ang.frames.empty())loop_ang.init(ang);
loop_ang.add(ang);
}
template<class TYPE>
void update(const TYPE&ex){
if(!neutral){load(ex);return;}
if(get_pos(ex).dist_to(pos)>0.1)agro=true;
if(abs(get_ang(ex)-ang)>0.1)agro=true;
if(get_rcdt(ex))agro=true;
if(ex.getLife()!=ex.getMaxLife())agro=true;
}
};
vector<t_unit> units;
PRO_FUNCGEN_GETP_BY_FIELD(t_unit,id2unit,units,int,id);
template<class TYPE>
void load_units(const vector<TYPE>&arr){
for(int i=0;i<arr.size();i++){
auto&ex=arr[i];
auto*p=id2unit(ex.getId());
if(!p){p=&qap_add_back(units);p->load(ex);continue;}
p->update(ex);
}
}
struct t_tree{
int tick;
vec2d pos;
real r;
int hp;
t_tree(){tick=-1;hp=-1;r=0;}
void load(const Tree&ex,int t){
tick=t;
pos=get_pos(ex);
r=ex.getRadius();
hp=ex.getLife();
}
};
vector<t_tree> id2tree;
vector<int> trees;
void update_forest(const vector<Tree>&arr,int tick){
for(int i=0;i<arr.size();i++){
auto&ex=arr[i];
auto id=ex.getId();
if(id>=id2tree.size())id2tree.resize(id+1);
id2tree[id].load(ex,tick);
}
}
bool is_passive_and_neutral(const t_tow&ex){return false;}
bool is_passive_and_neutral(const Building&ex){return false;}
bool is_passive_and_neutral(const Wizard&ex){return false;}
bool is_passive_and_neutral(const Minion&ex){
auto*p=id2unit(ex.getId());
QapAssert(p);
return p->neutral&&!p->agro;
}
int g_low_hp_ewiz_id=-1;
struct MeWorld:public World
{
real get_movfactor(const Wizard&ref)const{
return (is_hastened(ref)?1.0+pgame->hastenedMovementBonusFactor:1.0)+get_selfmovbon(ref);
}
real get_movfactor_with_timelimit(const Wizard&ref,int TL=16)const{
if(auto*p=get_hastened(ref))if(p->getRemainingDurationTicks()<TL)return 1+get_selfmovbon(ref);return get_movfactor(ref);
}
vec2d movedir2input(const Game&game,const Wizard&self,const vec2d&dir)const{
auto rf=get_rotfactor(self);auto mf=get_movfactor(self);
auto sk=game.getWizardStrafeSpeed();
auto fk=game.getWizardForwardSpeed();
auto bk=game.getWizardBackwardSpeed();
QapAssert(almost_equal(sk,bk,1e-4));
auto m=vec2d(fk,sk);
auto out=dir.x<=0?dir.SetMag(sk):dir.Div(m).Norm().Mul(m)*mf;
return out;
}
void set_move(const Game&game,const Wizard&self,Move&move,const vec2d&dir)const{
auto out=movedir2input(game,self,dir);
move.setStrafeSpeed(out.y);
move.setSpeed(out.x);
}
real get_selfmovbon(const Wizard&ref)const{
real k=get_passive_movbon_factor(ref)+get_aura_movbon_factor_in_point(get_pos(ref),ref.faction);
return k*pgame->movementBonusFactorPerSkillLevel;
}
int get_aura_movbon_factor_in_point(const vec2d&p,const Faction&faction)const{
auto&arr=wizards;int k=0;
QAP_FOREACH(arr,if(ex.faction==faction)if(get_pos(ex).dist_to_point_less_that_r(p,pgame->auraSkillRange))k=std::max(k,get_aura_movbon_factor(ex)););
return k;
}
real get_selfmdmgbon(const Wizard&ref)const{
real k=get_passive_mdmgbon(ref)+get_aura_mdmgbon_in_point(get_pos(ref),ref.faction);
return k*pgame->magicalDamageBonusPerSkillLevel;
}
int get_aura_mdmgbon_in_point(const vec2d&p,const Faction&faction)const{
auto&arr=wizards;int k=0;
QAP_FOREACH(arr,if(ex.faction==faction)if(get_pos(ex).dist_to_point_less_that_r(p,pgame->auraSkillRange))k=std::max(k,get_aura_mdmgbon(ex)););
return k;
}
real get_selfstaffdmgbon(const Wizard&ref)const{
real k=get_passive_staffdmgbon(ref)+get_aura_staffdmgbon_in_point(get_pos(ref),ref.faction);
return k*pgame->staffDamageBonusPerSkillLevel;
}
int get_aura_staffdmgbon_in_point(const vec2d&p,const Faction&faction)const{
auto&arr=wizards;int k=0;
QAP_FOREACH(arr,if(ex.faction==faction)if(get_pos(ex).dist_to_point_less_that_r(p,pgame->auraSkillRange))k=std::max(k,get_aura_staffdmgbon(ex)););
return k;
}
template<class TYPE>
bool is_visible_ex(const vec2d&p,const vector<TYPE>&arr,const Faction&frac){
for(int i=0;i<arr.size();i++){
auto&ex=arr[i];
if(ex.getFaction()!=frac)continue;
bool ok=get_pos(ex).dist_to_point_less_that_r(p,ex.getVisionRange());
if(ok)return true;
}
return false;
}
bool is_visible(const vec2d&p,const Wizard&self){
auto our_frac=self.getFaction();
if(is_visible_ex(p,getMinions(),our_frac))return true;
if(is_visible_ex(p,getWizards(),our_frac))return true;
if(is_visible_ex(p,getBuildings(),our_frac))return true;
return false;
}
const Building*get_tow_at_pos(const vec2d&pos){
auto&arr=getBuildings();
for(int i=0;i<arr.size();i++){auto&ex=arr[i];if(get_pos(ex).dist_to(pos)<1)return &ex;};
return nullptr;
}
t_tow&get_etow_at_pos(const vec2d&pos){
auto&arr=enemy_tows;
for(int i=0;i<arr.size();i++){auto&ex=arr[i];if(ex.pos.dist_to(pos)<1)return ex;};
return *(t_tow*)nullptr;
}
void update(t_tow&tow,const Wizard&self){
if(!tow.hp)return;
if(!is_visible(tow.pos,self))return;
auto*p=get_tow_at_pos(tow.pos);
if(p)tow.pos=get_pos(*p);
tow.hp=p?p->getLife():0;
tow.rcdt=p?p->getRemainingActionCooldownTicks():0;
}
// for wizrd std::max(e.getRemainingCooldownTicksByAction()[ACTION_MAGIC_MISSILE],e.getRemainingActionCooldownTicks())
template<class TYPE>int get_maxcdt(const TYPE&e){return e.getCooldownTicks();}
int get_maxcdt(const Wizard&e){return pgame->getMagicMissileCooldownTicks();}
int get_maxcdt(const t_tow&e){return e.cdt;}
// without other enviroment objects. just for r1.
struct t_input{
vec2d dpos;
real dang;
};
struct t_wiz{
vec2d pos;
real hp;
real ang;
real angspd;
real attsec;
real attrange;
real bulletspd;
real rotf;
real movf;
real fspd;
real sspd;
real bspd;
int mm_rcdt;
int sf_rcdt;
void load(const MeWorld&world,const Wizard&ref){
pos=get_pos(ref);
hp=get_hp(ref);
ang=get_ang(ref);
angspd=get_angspd(ref);
attsec=get_attsec(ref);
attrange=get_attrange(ref);
bulletspd=get_maxbulletspd(ref);
rotf=get_rotfactor(ref);
movf=world.get_movfactor(ref);
sspd=pgame->getWizardStrafeSpeed();
fspd=pgame->getWizardForwardSpeed();
bspd=pgame->getWizardBackwardSpeed();
auto min_rcdt=ref.getRemainingActionCooldownTicks();
mm_rcdt=std::max(min_rcdt,ref.getRemainingCooldownTicksByAction()[ACTION_MAGIC_MISSILE]);
sf_rcdt=std::max(min_rcdt,ref.getRemainingCooldownTicksByAction()[ACTION_STAFF]);
}
vec2d clamp_movespeedinput(real speed,real strafe){
return vec2d(Clamp(speed,fspd*movf,bspd*movf),Clamp(strafe,-sspd*movf,+sspd*movf));
}
vec2d movedir2input(const vec2d&dir){
QapAssert(almost_equal(sspd,bspd,1e-4));
auto m=vec2d(fspd,bspd);
auto out=dir.x<=0?dir.SetMag(sspd):dir.Div(m).Norm().Mul(m)*movf;
return out;
}
void sim_step(const t_input&ref){
auto dpos=clamp_movespeedinput(ref.dpos.x,ref.dpos.y).UnRot(Vec2dEx(ang,1));
pos+=dpos;
ang+=Clamp(ref.dang,-angspd*rotf,+angspd*rotf);
mm_rcdt=std::max(0,mm_rcdt-1);
sf_rcdt=std::max(0,sf_rcdt-1);
}
t_input get_input_to_dir(vec2d dir){
auto movdir=dir.Rot(Vec2dEx(ang,1));
t_input inp;
inp.dang=movdir.GetAng();
inp.dpos=movedir2input(movdir);
return inp;
}
};
int cur_entrypoint()
{
return 0;
}
real get_fly_ticks_v2(vec2d pos,const vec2d&v,int wizr,const vector<t_wiz>&sarr,int offset,real ecr)
{
int n=2;real inv_n=1.0/n;auto sv=v*inv_n;auto beg_pos=pos;int subiter=0;int maxsubiter=ecr*n/v.Mag();
for(int iter=0;;iter++)
{
auto&wiz=sarr[offset+iter];
for(int i=0;i<n;i++){
if(pos.dist_to_point_less_that_r(wiz.pos,mmrad*2+wizr))return subiter*inv_n;
if(subiter>=maxsubiter)return -subiter*inv_n;
pos+=sv;
subiter++;
}
}
return -0.1234567;
}
bool sim_based_go_back(const Wizard&self,const Wizard&enemy,const vec2d&dir)
{
vector<t_wiz> sarr;
t_wiz s;s.load(*this,self);
t_wiz e;e.load(*this,enemy);
if(!s.pos.dist_to_point_less_that_r(e.pos,self.getVisionRange()*1.25))return false;
int limit=30+60+12*2;
for(int t=0;t<limit+16;t++)
{
auto sinp=s.get_input_to_dir(t?-dir:+dir);
sarr.push_back(s);
s.sim_step(sinp);
}
auto ecr=enemy.getCastRange();auto hss=pgame->getStaffSector()*0.5;auto wizr=self.getRadius();
for(int t=0;t<limit;t++)
{
auto einp=e.get_input_to_dir(sarr[t].pos-e.pos);
//auto sinp=s.get_input_to_dir(t?-dir:dir);
if(!e.mm_rcdt)
{
auto ang=fabs((s.pos-e.pos).Rot(Vec2dEx(e.ang,1)).GetAng());
if(ang<hss)
{
int mid_rays=64;
for(int i=0;i<=mid_rays+1;i++)
{
real k=i*hss*2/(mid_rays+1);
vec2d bullet_v=Vec2dEx(e.ang-hss+k,e.bulletspd);
//auto ft=get_fly_ticks(e.pos,bullet_v,s,wizr,-dir,ecr);
auto ft=get_fly_ticks_v2(e.pos,bullet_v,wizr,sarr,t,ecr);
bool hit=ft>=0;
if(!hit)
{
int gg=1;
continue;
}
int gg=1;
return true;
}
//auto bullet_fly_ticks=real_to_int_up(dist/get_maxbulletspd(self));
//if(e.pos.dist_to(s.pos)<ecr+wizr+mmrad)
}
int gg=1;
}
e.sim_step(einp);
//s.sim_step(sinp);
}
return false;
}
struct t_go_back_result{
bool go_back;
bool go_fast;
bool go_panic;
void add(const t_go_back_result&ref){
go_back=go_back||ref.go_back;
go_fast=go_fast||ref.go_fast;
go_panic=go_panic||ref.go_panic;
}
};
t_go_back_result need_go_back(const Wizard&self,real shp,real smf,const vec2d&sp,real sr,const vec2d&dir,const Wizard&e)
{
t_go_back_result out={false,false,false};
if(e.getId()==g_low_hp_ewiz_id&&get_hp(e)<shp-mmdmg*3){
return out;
}
if(shp>=self.maxLife*0.5)return need_go_back<Wizard>(self,shp,smf,sp,sr,dir,e);
out.go_back=sim_based_go_back(self,e,dir);
if(out.go_back){
int gg=1;
}
out.go_fast=out.go_back;
auto ehp=get_hp(e);
if(out.go_back)if(shp-mmdmg*2>=ehp){
out.go_fast=false;
}
return out;
}
struct t_wizwall{
vec2d center;
int n;
int hp;
int tn;
int thp;
real get_avr_thp(){return !tn?0:real(thp)/tn;}
};
bool inside_wizwall(const Wizard&self,t_wizwall&wall){
return wall.center.dist_to_point_less_that_r(get_pos(self),pgame->wizardCastRange);
}
t_wizwall get_wizwall(const Unit&ref){QapAssert(false);t_wizwall tmp={get_pos(ref)};return tmp;}
t_wizwall get_wizwall(const t_tow&ref){QapAssert(false);t_wizwall tmp={get_pos(ref)};return tmp;}
template<class TYPE>
t_go_back_result need_go_back(const Wizard&self,real shp,real smf,const vec2d&sp,real sr,const vec2d&dir,const TYPE&e){
bool go_back=false;bool go_fast=false;bool go_panic=false;
real wiz_buff=3.1;
auto final_mode=pgame->rawMessagesEnabled;
const real self_bspd=pgame->getWizardBackwardSpeed()*smf;
const real self_fspd=pgame->getWizardForwardSpeed()*smf;
const real bot_spd=3;
auto bulletrad=get_bulletrad(e);
auto ehp=get_hp(e);
auto ep=get_pos(e);
auto ang=get_ang(e);
auto angspd=get_angspd(e);
auto attsec=get_attsec(e);
auto bulletspd=get_maxbulletspd(e);
auto maxspd=get_maxspd(e);
auto is_ewiz=maxspd>bot_spd;
if(is_ewiz&&final_mode)
{
if(shp>ehp||(shp==self.maxLife&&shp==ehp))if(shp>64)wiz_buff=-25;
auto wall=get_wizwall(self);
auto ewall=get_wizwall(e);
if(shp>24)if(wall.n>=2||(wall.tn>ewall.tn&&wall.thp>=ewall.thp+64))if(wall.get_avr_thp()>ewall.get_avr_thp()+24)wiz_buff=-64;
}
/*
if(!almost_equal(self_bspd,maxspd)&&self_bspd<maxspd){
go_panic=!almost_equal(self_fspd,maxspd)&&self_fspd<maxspd;
if(go_panic)if(sp.dist_to(ep)>get_attrange(e)+sr*8+bulletrad)go_panic=false;
if(almost_equal(self_fspd,maxspd)||go_panic){
//+6.1940176041876 in 30 frames; from bspd to fspd
wiz_buff+=+6.1940176041876+self_fspd;
go_fast=true;
}
}
*/
if(go_panic)wiz_buff*=2;
auto spd=get_spd(e);
int dodge_ticks=std::max(0,real_to_int_up((sp.dist_to(ep)-sr-bulletrad)/real(bulletspd))-1);
auto turn_ticks=get_min_turn_ticks(sp,ep,ang,attsec,angspd);
auto safe_ticks=std::max(0,std::max(turn_ticks,get_rcdt(e)));
auto safe_dist=safe_ticks*std::max(0.0,self_bspd-maxspd);
bool look_like_tower=almost_equal(spd.SqrMag(),0)&&almost_equal(3,maxspd)&&bulletrad>0;
if(look_like_tower){
safe_dist=safe_ticks*self_bspd;//wiz_buff=0;
}
//bool is_fetish=almost_equal(spd.SqrMag(),0)&&almost_equal(self_spd,maxspd)&&bulletrad>0;
//bool is_orcwod=almost_equal(spd.SqrMag(),0)&&almost_equal(self_spd,maxspd)&&!bulletrad;
//if(is_fetish)safe_dist=safe_ticks*self_spd;
//if(is_orcwod)safe_dist=safe_ticks*self_spd;
//if(almost_equal(self_spd,maxspd)&&!bulletrad)safe_ticks=0;
//bool turn_ticks_based_answer=;
//bool cdt_based_answer=(sp-dir.SetMag(get_rcdt(e)*2.9)).dist_to(ep)<=get_attrange(e)+sr+4.1;
go_back=(sp-dir.SetMag(self_bspd*dodge_ticks+safe_dist)).dist_to(ep)<=get_attrange(e)+sr+bulletrad+wiz_buff;
/*
if(is_ewiz)if(go_panic)if(shp+mmdmg*3>=ehp){go_panic=false;go_back=false;}
if(is_ewiz)if(go_panic)if(shp/ehp>3){go_panic=false;go_back=false;}
*/
t_go_back_result out={go_back,go_back?go_fast:false,go_panic};
return out;
}
bool is_vulnerable(const CircularUnit&u){return true;}
bool is_vulnerable(const t_tow&u){
if(u.hp<=0)return false;
//auto&tow=get_etow_at_pos(get_pos(u));
for(int i=0;i<3;i++){
auto&ex=enemy_main_tower[i];
if(ex.arr[1]==&u)return ex.arr[0]->hp<=0;
}
return u.type==BUILDING_FACTION_BASE?enemy_main_tower.unlocked():true;
}
bool is_ebase(const CircularUnit&u){return false;}
bool is_ebase(const t_tow&u){return u.type==BUILDING_FACTION_BASE;}
static int get_hp(const LivingUnit&u){return u.getLife();}
static int get_hp(const t_tow&u){return u.hp;}
static real get_angspd(const t_tow&u){return Pi2;}
static real get_angspd(const Building&u){return Pi2;}
static real get_angspd(const Minion&ref){return pgame->getMinionMaxTurnAngle();}
static real get_angspd(const Wizard&ref){return get_rotfactor(ref)*pgame->getWizardMaxTurnAngle();}
static real get_maxbulletspd(const Wizard&ref){return pgame->getMagicMissileSpeed();}
static real get_maxbulletspd(const t_tow&ref){return 4000;}
static real get_maxbulletspd(const Building&ref){return 4000;}
static real get_maxbulletspd(const Minion&ref){return ref.getType()==MINION_ORC_WOODCUTTER?4000:pgame->getDartSpeed();}
real get_maxspd(const Wizard&ref){return get_movfactor(ref)*pgame->getWizardForwardSpeed();}
static real get_maxspd(const t_tow&ref){return 0;}
static real get_maxspd(const Building&ref){return 0;}
static real get_maxspd(const Minion&ref){return pgame->getMinionSpeed();}
static bool has_staff(const Wizard&){return true;}
static bool has_mm(const Wizard&){return true;}
static bool has_fireball(const Wizard&ref){return qap_includes(ref.skills,SKILL_FIREBALL);}
static bool has_frostbolt(const Wizard&ref){return qap_includes(ref.skills,SKILL_FROST_BOLT);}
enum t_weapon_type{ew_dart,ew_mm,ew_fi,ew_fr,ew_st};
struct t_weapon_info{
real r;
real spd;
real dmg;
real mindmg;
int rcdt;
int mcost;
//t_weapon_type type;
};
static real get_mana_regspd(const Wizard&ref){
return pgame->wizardBaseManaRegeneration+pgame->wizardManaRegenerationGrowthPerLevel*ref.level;;
}
static int mp_based_rcdt(const Wizard&ref,int mpcost){
auto mrspd=get_mana_regspd(ref);
auto mrcdt=real_to_int_up(std::max(0.0,(mpcost-ref.mana)/mrspd));
return mrcdt;
}
vector<t_weapon_info> get_weapons(const Wizard&ref){
auto self_rcdt_act=ref.getRemainingActionCooldownTicks();
vector<t_weapon_info> out;
if(has_staff(ref))
{
auto self_rcdt_staff=std::max(self_rcdt_act,ref.getRemainingCooldownTicksByAction()[ACTION_STAFF]);
auto&b=qap_add_back(out);
b.mcost=0;
b.r=0;
b.spd=4000;
b.dmg=pgame->staffDamage+get_selfstaffdmgbon(ref);
auto mrcdt=mp_based_rcdt(ref,b.mcost);
b.rcdt=std::max(self_rcdt_act,std::max(mrcdt,self_rcdt_staff));
}
if(has_mm(ref))
{
auto self_rcdt_mm=std::max(self_rcdt_act,ref.getRemainingCooldownTicksByAction()[ACTION_MAGIC_MISSILE]);
auto&b=qap_add_back(out);
b.mcost=pgame->magicMissileManacost;
b.r=pgame->magicMissileRadius;
b.spd=pgame->magicMissileSpeed;
b.dmg=pgame->magicMissileDirectDamage+get_selfmdmgbon(ref);
auto mrcdt=mp_based_rcdt(ref,b.mcost);
b.rcdt=std::max(self_rcdt_act,std::max(mrcdt,self_rcdt_mm));
}
if(has_fireball(ref))
{
auto self_rcdt_fi=std::max(self_rcdt_act,ref.getRemainingCooldownTicksByAction()[ACTION_FIREBALL]);
auto&b=qap_add_back(out);
b.mcost=pgame->fireballManacost;
b.r=pgame->fireballRadius;
b.spd=pgame->fireballSpeed;
b.dmg=pgame->fireballExplosionMaxDamage;
auto mrcdt=mp_based_rcdt(ref,b.mcost);