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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
enum EWetnessLevel
{
	DRY,
	DAMP,
	WET,
	SOAKING,
	DRENCHED
}

enum SurfaceAnimationBone
{
	LeftFrontLimb = 0,
	RightFrontLimb,
	LeftBackLimb,
	RightBackLimb
}

enum PlantType
{
	TREE_HARD		= 1000,
	TREE_SOFT		= 1001,
	BUSH_HARD		= 1002,	
	BUSH_SOFT		= 1003,
}

enum WeightUpdateType
{
	FULL = 0,
	ADD,
	REMOVE,
	RECURSIVE_ADD,
	RECURSIVE_REMOVE
}

enum EItemManipulationContext
{
	UPDATE, //generic operation
	ATTACHING,
	DETACHING,
}

//! icon visibility, meant to be used in a bitmask
enum EInventoryIconVisibility
{
	ALWAYS = 0,
	HIDE_VICINITY = 1,
	//further values yet unused, but nice to have anyway
	HIDE_PLAYER_CONTAINER = 2,
	HIDE_HANDS_SLOT = 4
}

//!EXCLUSIVITY values, restrict attachment combinations
enum EAttExclusions
{
	OCCUPANCY_INVALID = -1,
	//Legacy relations
	LEGACY_EYEWEAR_HEADGEAR,
	LEGACY_EYEWEAR_MASK,
	LEGACY_HEADSTRAP_HEADGEAR,
	LEGACY_HEADSTRAP_MASK,
	LEGACY_HEADGEAR_MASK,
	LEGACY_HEADGEAR_EYEWEWEAR,
	LEGACY_HEADGEAR_HEADSTRAP,
	LEGACY_MASK_HEADGEAR,
	LEGACY_MASK_EYEWEWEAR,
	LEGACY_MASK_HEADSTRAP,
	//
	EXCLUSION_HEADGEAR_HELMET_0, //full helmet
	//EXCLUSION_HEADGEAR_HELMET_0_A, //example of another 'vector' of potential conflict, like between helmet and eyewear..otherwise the other non-helmet entities would collide through the 'EXCLUSION_HEADSTRAP_0' value.
	EXCLUSION_HEADSTRAP_0,
	EXCLUSION_MASK_0,
	EXCLUSION_MASK_1,
	EXCLUSION_MASK_2, //Mostly Gasmasks
	EXCLUSION_MASK_3, //bandana mask special behavior
	EXCLUSION_GLASSES_REGULAR_0,
	EXCLUSION_GLASSES_TIGHT_0,
	//values to solve the edge-cases with shaving action
	SHAVING_MASK_ATT_0,
	SHAVING_HEADGEAR_ATT_0,
	SHAVING_EYEWEAR_ATT_0,
}

class DebugSpawnParams
{
	Man m_Player;

	static DebugSpawnParams WithPlayer(Man player)
	{
		DebugSpawnParams params = new DebugSpawnParams();
		params.m_Player = player;
		return params;
	}
};

class TSelectableActionInfoArrayEx extends array<ref Param> {}
typedef Param3<int, int, string> TSelectableActionInfo;
typedef Param4<int, int, string, int> TSelectableActionInfoWithColor;

class EntityAI extends Entity
{
	bool 								m_DeathSyncSent;
	bool 								m_KilledByHeadshot;
	bool 								m_PreparedToDelete = false;
	bool 								m_RefresherViable = false;
	bool								m_WeightDirty = 1;
	private ref map<int,ref set<int>>	m_AttachmentExclusionSlotMap; //own masks for different slots <slot,mask>. Kept on instance to better respond to various state changes
	private ref set<int>				m_AttachmentExclusionMaskGlobal; //additional mask values and simple item values. Independent of slot-specific behavior!
	private ref set<int> 				m_AttachmentExclusionMaskChildren; //additional mask values and simple item values
	
	ref DestructionEffectBase			m_DestructionBehaviourObj;
	
	ref KillerData 						m_KillerData;
	private ref HiddenSelectionsData	m_HiddenSelectionsData;
	
	const int DEAD_REPLACE_DELAY		= 2000;
	const int DELETE_CHECK_DELAY		= 100;
	
	ref array<EntityAI> 			m_AttachmentsWithCargo;
	ref array<EntityAI> 			m_AttachmentsWithAttachments;
	ref InventoryLocation 			m_OldLocation;
	
	protected ref DamageZoneMap 	m_DamageZoneMap;
	private ref map<int, string> 	m_DamageDisplayNameMap = new map<int, string>; //values are localization keys as strings, use 'Widget.TranslateString' method to get the localized one
	
	float							m_Weight;
	float							m_WeightEx;
	float 							m_ConfigWeight = ConfigGetInt("weight");
	protected bool 					m_CanDisplayWeight;
	private float 					m_LastUpdatedTime;
	protected float					m_ElapsedSinceLastUpdate;
	
	protected UTemperatureSource m_UniversalTemperatureSource;
	
	bool m_PendingDelete = false;
	bool m_Initialized = false;
	bool m_TransportHitRegistered = false;
	vector m_TransportHitVelocity;
	
	//Called on item attached to this item (EntityAI item, string slot, EntityAI parent)
	protected ref ScriptInvoker		m_OnItemAttached;
	//Called on item detached from this item (EntityAI item, string slot, EntityAI parent)
	protected ref ScriptInvoker		m_OnItemDetached;
	//Called when an item is added to the cargo of this item (EntityAI item, EntityAI parent)
	protected ref ScriptInvoker		m_OnItemAddedIntoCargo;
	//Called when an item is removed from the cargo of this item (EntityAI item, EntityAI parent)
	protected ref ScriptInvoker		m_OnItemRemovedFromCargo;
	//Called when an item is moved around in the cargo of this item (EntityAI item, EntityAI parent)
	protected ref ScriptInvoker		m_OnItemMovedInCargo;
	//Called when an item is flipped around in cargo (bool flip)
	protected ref ScriptInvoker		m_OnItemFlipped;
	//Called when an items view index is changed 
	protected ref ScriptInvoker		m_OnViewIndexChanged;
	//Called when an location in this item is reserved (EntityAI item) - cargo
	protected ref ScriptInvoker		m_OnSetLock;
	//Called when this item is unreserved (EntityAI item) - cargo
	protected ref ScriptInvoker		m_OnReleaseLock;
	//Called when an location in this item is reserved (EntityAI item) - attachment
	protected ref ScriptInvoker		m_OnAttachmentSetLock;
	//Called when this item is unreserved (EntityAI item) - attachment
	protected ref ScriptInvoker		m_OnAttachmentReleaseLock;	
	//Called when this entity is hit
	protected ref ScriptInvoker		m_OnHitByInvoker;	
	//Called when this entity is killed
	protected ref ScriptInvoker		m_OnKilledInvoker;
	
	void EntityAI()
	{
		// Set up the Energy Manager
		string type = GetType();
		string param_access_energy_sys = "CfgVehicles " + type + " EnergyManager ";
		bool is_electic_device = GetGame().ConfigIsExisting(param_access_energy_sys);

		if (is_electic_device) // TO DO: Check if this instance is a hologram (advanced placement). If Yes, then do not create Energy Manager component.
		{
			CreateComponent(COMP_TYPE_ENERGY_MANAGER);
			RegisterNetSyncVariableBool("m_EM.m_IsSwichedOn");
			RegisterNetSyncVariableBool("m_EM.m_CanWork");
			RegisterNetSyncVariableBool("m_EM.m_IsPlugged");
			RegisterNetSyncVariableInt("m_EM.m_EnergySourceNetworkIDLow");
			RegisterNetSyncVariableInt("m_EM.m_EnergySourceNetworkIDHigh");
			RegisterNetSyncVariableFloat("m_EM.m_Energy");
		}
		
		// Item preview index
		RegisterNetSyncVariableInt( "m_ViewIndex", 0, 99 );
		// Refresher signalization
		RegisterNetSyncVariableBool("m_RefresherViable");
		
		m_AttachmentsWithCargo			= new array<EntityAI>();
		m_AttachmentsWithAttachments	= new array<EntityAI>();
		m_LastUpdatedTime = 0.0;
		m_ElapsedSinceLastUpdate = 0.0;
		
		m_CanDisplayWeight = ConfigGetBool("displayWeight");
		
		InitDamageZoneMapping();
		InitDamageZoneDisplayNameMapping();
		
		m_HiddenSelectionsData = new HiddenSelectionsData( GetType() );
		
		GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(DeferredInit,34);
	}
	
	void ~EntityAI()
	{
		
	}
	
	void DeferredInit()
	{
		m_Initialized = true;
	}
	
	bool IsInitialized()
	{
		return m_Initialized;
	}
	
	//! should the item's icon be hidden in any part of the inventory?
	int GetHideIconMask()
	{
		return EInventoryIconVisibility.ALWAYS;
	}

	private ref ComponentsBank m_ComponentsBank;
	ComponentEnergyManager m_EM; // This reference is necesarry due to synchronization, since it's impossible to synchronize values from a component :(

	//! CreateComponent
	Component CreateComponent(int comp_type, string extended_class_name="")
	{
		return GetComponent(comp_type, extended_class_name);
	}

	//! GetComponent
	Component GetComponent(int comp_type, string extended_class_name="")
	{
		if ( m_ComponentsBank == NULL )
			m_ComponentsBank = new ComponentsBank(this);
		
		return m_ComponentsBank.GetComponent(comp_type, extended_class_name);
	}

	//! DeleteComponent
	bool DeleteComponent(int comp_type)
	{
		return m_ComponentsBank.DeleteComponent(comp_type);
	}
	
	string GetDestructionBehaviour()
	{
		return "";
	}
	
	bool IsDestructionBehaviour()
	{
		return false;
	}
	
	//! IsComponentExist
	bool HasComponent(int comp_type)
	{
		if ( m_ComponentsBank )
			return m_ComponentsBank.IsComponentAlreadyExist(comp_type);
		
		return false;
	}
	
	//! Calculates if the max lifetime is higher than refresher frequency (i.e. gets kept alive by refresher) 
	void MaxLifetimeRefreshCalc()
	{
		if ( (!GetGame().IsMultiplayer() || GetGame().IsServer()) && GetEconomyProfile() )
		{
			float lifetime = GetEconomyProfile().GetLifetime();
			int frequency = GetCEApi().GetCEGlobalInt("FlagRefreshFrequency");
			if ( frequency <= 0 )
			{
				frequency = GameConstants.REFRESHER_FREQUENCY_DEFAULT;
			}
			
			if ( frequency <= lifetime )
			{
				m_RefresherViable = true;
				SetSynchDirty();
			}
		}
	}
	
	bool IsRefresherSignalingViable()
	{
		if (IsRuined())
		{
			return false;
		}
		return m_RefresherViable;
	}
	
	#ifdef DEVELOPER
	override void SetDebugItem()
	{
		super.SetDebugItem();
		_item = this;
	}
	#endif
	
	
	//! Initializes script-side map of damage zones and their components (named selections in models)
	void InitDamageZoneMapping()
	{
		m_DamageZoneMap = new DamageZoneMap;
		DamageSystem.GetDamageZoneMap(this,m_DamageZoneMap);
	}
	
	//! Initialize map of damage zone display names for more optimized retrieval
	void InitDamageZoneDisplayNameMapping()
	{	
		string path_base;
		string path;
		string component_name;
		
		if ( IsWeapon() )
		{
			path_base = CFG_WEAPONSPATH;
		}
		else if ( IsMagazine() )
		{
			path_base = CFG_MAGAZINESPATH;
		}
		else
		{
			path_base = CFG_VEHICLESPATH;
		}
		
		path_base = string.Format( "%1 %2 DamageSystem DamageZones", path_base, GetType() );
		
		if ( !GetGame().ConfigIsExisting(path_base) )
		{
			component_name = GetDisplayName();
			GetGame().FormatRawConfigStringKeys(component_name);
			m_DamageDisplayNameMap.Insert( "".Hash(), component_name );
		}
		else
		{
			TStringArray zone_names = new TStringArray;
			GetDamageZones( zone_names );
			
			for ( int i = 0; i < zone_names.Count(); i++ )
			{
				path = string.Format( "%1 %2 displayName", path_base, zone_names[i] );
				
				if (GetGame().ConfigIsExisting(path) && GetGame().ConfigGetTextRaw(path,component_name))
				{
					GetGame().FormatRawConfigStringKeys(component_name);
					m_DamageDisplayNameMap.Insert( zone_names[i].Hash(), component_name );
				}
			}
		}
	}
	
	protected float ConvertNonlethalDamage(float damage, DamageType damageType)
	{
		return 0.0;
	}
	
	//! DEPRECATED - for legacy purposes
	float ConvertNonlethalDamage(float damage)
	{
		return 0.0;
	}
	
	DamageZoneMap GetEntityDamageZoneMap()
	{
		return m_DamageZoneMap;
	}
	
	map<int, string> GetEntityDamageDisplayNameMap()
	{
		return m_DamageDisplayNameMap;
	}
	
	//! 'displayWeight' in item config
	bool CanDisplayWeight()
	{
		return m_CanDisplayWeight;
	}

	//! Log
	void Log(string msg, string fnc_name = "n/a")
	{
		Debug.Log(msg, "Object", "n/a", fnc_name, this.GetType());
	}

	//! LogWarning
	void LogWarning(string msg, string fnc_name = "n/a")
	{
		Debug.LogWarning(msg, "Object", "n/a", fnc_name, this.GetType());
	}

	//! LogError
	void LogError(string msg, string fnc_name = "n/a")
	{
		Debug.LogError(msg, "Object", "n/a", fnc_name, this.GetType());
	}

	///@{ Skinning
	bool IsSkinned()
	{
		return GetCompBS() && GetCompBS().IsSkinned();
	}

	void SetAsSkinned()
	{
		if (GetCompBS())
			GetCompBS().SetAsSkinned();
	}

	bool CanBeSkinnedWith(EntityAI tool)
	{
		if ( !IsSkinned()  &&  tool )
			if ( !IsAlive() )
				return true;
		return false;
	}
	///@} Skinning

	// ITEM TO ITEM FIRE DISTRIBUTION
	//! Override this method to return TRUE when this item has or can provide fire. Evaluated on server and client.
	bool HasFlammableMaterial()
	{
		return false;
	}
	
	//! Override this method so it checks whenever this item can be ignited right now or not. Evaluated on Server and Client.
	bool CanBeIgnitedBy(EntityAI igniter = NULL)
	{
		return false;
	}
	
	//! Override this method and check if the given item can be ignited right now by this one. Evaluated on Server and Client.
	bool CanIgniteItem(EntityAI ignite_target = NULL)
	{
		return false;
	}
	
	//! Override this method and make it so it returns whenever this item is on fire right now or not. Evaluated on Server and Client.
	bool IsIgnited()
	{
		if (m_EM)
			return m_EM.IsWorking();
		return false;
	}
	
	// Change return value to true if last detached item cause disassemble of item - different handlig some inventory operations
	bool DisassembleOnLastDetach()
	{
		return false;
	}
	
	bool IsBasebuildingKit()
	{
		return false;
	}
	
	//! Should return false if you want to disable hologram rotation
	bool PlacementCanBeRotated()
	{
		return true;
	}
	
	//! Executed on Server when this item ignites some target item
	void OnIgnitedTarget( EntityAI target_item)
	{
		
	}
	
	//! Executed on Server when some item ignited this one
	void OnIgnitedThis( EntityAI fire_source)
	{
		
	}
	
	//! Executed on Server when this item failed to ignite target item
	void OnIgnitedTargetFailed( EntityAI target_item)
	{
		
	}
	
	//! Executed on Server when some item failed to ignite this one
	void OnIgnitedThisFailed( EntityAI fire_source)
	{
		
	}
	
	//! Final evaluation just before the target item is actually ignited. Evaluated on Server.
	bool IsTargetIgnitionSuccessful(EntityAI item_target)
	{
		return true;
	}
	
	//! Final evaluation just before this item is actually ignited from fire source. Evaluated on Server.
	bool IsThisIgnitionSuccessful(EntityAI item_source = NULL)
	{
		return true;
	}
	// End of fire distribution ^
	
	// ADVANCED PLACEMENT EVENTS
	void OnPlacementStarted(Man player);		
	void OnHologramBeingPlaced(Man player);
	void OnPlacementComplete(Man player, vector position = "0 0 0", vector orientation = "0 0 0");
	void OnPlacementCancelled(Man player);
	
	bool CanBePlaced(Man player, vector position)
	{
		return true;
	}

	//! Method which returns message why object can't be placed at given position
	string CanBePlacedFailMessage( Man player, vector position )
	{
		return "";
	}
	
	//! Do the roof check when placing this?
	bool DoPlacingHeightCheck()
	{
		return false;
	}
	
	//! used as script-side override of distance for specific height checks
	float HeightCheckOverride()
	{
		return 0.0;
	}
	
	//! used as script-side override of start pos for specific height checks
	float HeightStartCheckOverride()
	{
		return 0.0;
	}
	
	//! is this container empty or not, checks both cargo and attachments
	bool IsEmpty()
	{
		return (!HasAnyCargo() && GetInventory().AttachmentCount() == 0);
	}
	
	bool CanBeSplit()
	{
		return false;
	}

	//! is this container empty or not, checks only cargo
	bool HasAnyCargo()
	{
		CargoBase cargo = GetInventory().GetCargo();
		
		if(!cargo) return false;//this is not a cargo container
		
		if( cargo.GetItemCount() > 0 )
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	array<EntityAI> GetAttachmentsWithCargo()
	{
		return m_AttachmentsWithCargo;
	}
	
	array<EntityAI> GetAttachmentsWithAttachments()
	{
		return m_AttachmentsWithAttachments;
	}

	int GetAgents() { return 0; }
	void RemoveAgent(int agent_id);
	void RemoveAllAgents();
	void RemoveAllAgentsExcept(int agent_to_keep);
	void InsertAgent(int agent, float count = 1);

	override bool IsEntityAI() { return true; }
	
	bool IsInventoryVisible()
	{
		return !( GetParent() || GetHierarchyParent() );
	}
	
	bool IsPlayer()
	{
		return false;
	}
	
	bool IsAnimal()
	{
		return false;
	}
	
	bool IsZombie()
	{
		return false;
	}
	
	bool IsZombieMilitary()
	{
		return false;
	}
	
	bool IsIgnoredByConstruction()
	{
		return IsDamageDestroyed();
	}
	
	bool CanBeTargetedByAI(EntityAI ai)
	{
		if (ai && ai.IsBeingBackstabbed())
		{
			return false;
		}
		
		if ( !dBodyIsActive( this ) && !IsMan() )
			return false;
		return !IsDamageDestroyed();
	}
	
	bool CanBeBackstabbed()
	{
		return false;
	}
	
	/**@brief Delete this object in next frame
	 * @return \p void
	 *
	 * @code
	 *			ItemBase item = GetGame().GetPlayer().CreateInInventory("GrenadeRGD5");
	 *			item.Delete();
	 * @endcode
	**/
	override void Delete()
	{
		m_PendingDelete = true;
		super.Delete();
	}
	
	void DeleteOnClient()
	{
		GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Call(GetGame().ObjectDeleteOnClient, this);
	}
	
	// delete synchronized between server and client
	void DeleteSafe()
	{
		if (GetHierarchyRootPlayer() == null)
		{
			Delete();
		}
		else
		{
			if (GetGame().IsServer() && GetGame().IsMultiplayer())
				GetHierarchyRootPlayer().JunctureDeleteItem(this);
			else
				GetHierarchyRootPlayer().AddItemToDelete(this);
		}
	}
	
	//legacy, wrong name, use 'DeleteSafe()' instead
	void DeleteSave()
	{		
		DeleteSafe();
	}
	
	bool IsSetForDeletion()
	{
		return IsPreparedToDelete() || m_PendingDelete || ToDelete() || IsPendingDeletion();
	}
	
	override bool CanBeActionTarget()
	{
		if (super.CanBeActionTarget())
		{
			return !IsSetForDeletion();
		}
		else
		{
			return false;
		}
	}
	
	void SetPrepareToDelete()
	{
		m_PreparedToDelete = true;
	}
	
	bool IsPreparedToDelete()
	{
		return m_PreparedToDelete;
	}
	
	
	void CheckForDestroy()
	{
		if (IsPrepareToDelete())
		{
			GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(TryDelete, DELETE_CHECK_DELAY, false);
		}
	}
	
	bool IsPrepareToDelete()
	{
		return false;
	}
	
	bool TryDelete()
	{
		if (!IsPrepareToDelete())
		{
			Debug.Log("TryDelete - not ready for deletion");
			return false;
		}

		if (GetGame().HasInventoryJunctureItem(this))
		{
			Debug.Log("TryDelete - deferred call");
			GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(TryDelete, DELETE_CHECK_DELAY, false);
			return false;
		}

		OnBeforeTryDelete();
		Debug.Log("TryDelete - OnBeforeTryDelete end");
		DeleteSafe();
		Debug.Log("TryDelete - DeleteSafe end");

		return true;
	}
	
	void OnBeforeTryDelete();
	
	//! Returns root of current hierarchy (for example: if this entity is in Backpack on gnd, returns Backpack)
	proto native EntityAI GetHierarchyRoot();

	//! Returns root of current hierarchy cast to Man
	proto native Man GetHierarchyRootPlayer();
	
	//! Returns direct parent of current entity
	proto native EntityAI GetHierarchyParent();

	//! Get economy item profile (if assigned, otherwise null)
	proto native CEItemProfile GetEconomyProfile();

	// !returns the number of levels bellow the hierarchy root this entity is at
	int GetHierarchyLevel(int lvl = 0)
	{
		if (!GetHierarchyParent())
			return lvl;

		return GetHierarchyParent().GetHierarchyLevel(lvl+1);
	}
	
	void OnInventoryInit()
	{
		InitAttachmentExclusionValues();
	}
	
	//! Called upon object creation
	void EEInit()
	{
		if (GetInventory())
		{
			GetInventory().EEInit();
			m_AttachmentsWithCargo.Clear();
			m_AttachmentsWithAttachments.Clear();
			for ( int i = 0; i < GetInventory().AttachmentCount(); i++ )
			{
				EntityAI attachment = GetInventory().GetAttachmentFromIndex( i );
				if ( attachment )
				{
					if ( attachment.GetInventory().GetCargo() )
					{
						m_AttachmentsWithCargo.Insert( attachment );
					}
					
					if ( attachment.GetInventory().GetAttachmentSlotsCount() > 0 )
					{
						m_AttachmentsWithAttachments.Insert( attachment );
					}
				}
			}
		}
		
		MaxLifetimeRefreshCalc();
	}
	
	//! Called right before object deleting
	void EEDelete(EntityAI parent)
	{
		m_PendingDelete = true;
		GetInventory().EEDelete(parent);
		
		if (m_EM)
			m_EM.OnDeviceDestroyed();
	}
	
	override void OnExplosionEffects(Object source, Object directHit, int componentIndex, string surface, vector pos, vector surfNormal, float energyFactor, float explosionFactor, bool isWater, string ammoType) 
	{
		super.OnExplosionEffects(source, directHit, componentIndex, surface, pos, surfNormal, energyFactor, explosionFactor, isWater, ammoType);
		#ifndef SERVER
		g_Game.GetWorld().AddEnvShootingSource(pos, 1.0);
		#endif
		if (m_DestructionBehaviourObj && m_DestructionBehaviourObj.HasExplosionDamage())
		{
			m_DestructionBehaviourObj.OnExplosionEffects(source, directHit, componentIndex, surface, pos, surfNormal, energyFactor, explosionFactor, isWater, ammoType);
		}
	}
	
	
	void OnItemLocationChanged(EntityAI old_owner, EntityAI new_owner) { }
	
	void OnItemAttachmentSlotChanged (notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc) {}
	
	void EEItemLocationChanged (notnull InventoryLocation oldLoc, notnull InventoryLocation newLoc)
	{
		EntityAI old_owner = oldLoc.GetParent();
		EntityAI new_owner = newLoc.GetParent();
		OnItemLocationChanged(old_owner, new_owner);
		
		if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT && newLoc.GetType() == InventoryLocationType.ATTACHMENT)
		{
			OnItemAttachmentSlotChanged(oldLoc,newLoc);
		}
		
		if (oldLoc.GetType() == InventoryLocationType.ATTACHMENT)
		{
			if (old_owner)
				OnWasDetached(old_owner, oldLoc.GetSlot());
			else
				Error("EntityAI::EEItemLocationChanged - detached, but old_owner is null");
		}
		
		if (newLoc.GetType() == InventoryLocationType.ATTACHMENT)
		{
			if (new_owner)
				OnWasAttached(newLoc.GetParent(), newLoc.GetSlot());
			else
				Error("EntityAI::EEItemLocationChanged - attached, but new_owner is null");
		}
	}

	//! Called from 'IEntity.AddChild'
	void EEParentedTo(EntityAI parent)
	{
	}

	//! Called from 'IEntity.RemoveChild' or 'IEntity.AddChild' when hierarchy changes
	void EEParentedFrom(EntityAI parent)
	{
	}
	
	void EEInventoryIn (Man newParentMan, EntityAI diz, EntityAI newParent)
	{
	}
	void EEInventoryOut (Man oldParentMan, EntityAI diz, EntityAI newParent)
	{
		m_LastUpdatedTime = 0.0;
		
		if (GetInventory() && newParent == null)
		{
			GetInventory().ResetFlipCargo();
		}
	}

	void EEAmmoChanged()
	{
		SetWeightDirty();
	}

	void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
	{
		// Notify potential parent that this item was ruined
		EntityAI parent = GetHierarchyParent();
		
		if (newLevel == GameConstants.STATE_RUINED)
		{
			if (parent)
			{
				parent.OnAttachmentRuined(this);
			}
			if (!zone)
			{
				OnDamageDestroyed(oldLevel);
			}
			AttemptDestructionBehaviour(oldLevel,newLevel, zone);
		}
	}
	
	//! Called when the health gets to the min value, 'oldLevel' is previous health level, 'oldLevel' -1 means this entity was just spawned
	void OnDamageDestroyed(int oldLevel);
	
	void AttemptDestructionBehaviour(int oldLevel, int newLevel, string zone) 
	{
		if (IsDestructionBehaviour() && GetDestructionBehaviour())
		{
			typename destType = GetDestructionBehaviour().ToType();
			
			if (destType)
			{
				if (!m_DestructionBehaviourObj)
				{
					m_DestructionBehaviourObj = DestructionEffectBase.Cast(destType.Spawn());
				}
				
				if (m_DestructionBehaviourObj)
				{
					m_DestructionBehaviourObj.OnHealthLevelChanged(this, oldLevel, newLevel, zone);
				}
			}
			else
			{
				ErrorEx("Incorrect destruction behaviour type, make sure the class returned in 'GetDestructionBehaviour()' is a valid type inheriting from 'DestructionEffectBase'");
			}
		}
	}
	
	
	void SetTakeable(bool pState);
	
	//! called on server when the entity is killed
	void EEKilled(Object killer)
	{
		if (m_OnKilledInvoker)
			m_OnKilledInvoker.Invoke(this, killer);
		//analytics
		GetGame().GetAnalyticsServer().OnEntityKilled( killer, this );
		
		if( ReplaceOnDeath() )
			GetGame().GetCallQueue( CALL_CATEGORY_SYSTEM ).CallLater( DeathUpdate, DEAD_REPLACE_DELAY, false);
	}
	
	bool ReplaceOnDeath()
	{
		return false;
	}
	
	string GetDeadItemName()
	{
		return "";
	}
	
	bool KeepHealthOnReplace()
	{
		return false;
	}
	
	void DeathUpdate()
	{
		EntityAI dead_entity = EntityAI.Cast( GetGame().CreateObjectEx( GetDeadItemName(), GetPosition(), ECE_OBJECT_SWAP, RF_ORIGINAL ) );
		dead_entity.SetOrientation(GetOrientation());
		if ( KeepHealthOnReplace() )
			dead_entity.SetHealth(GetHealth());
		this.Delete();
	}
	
	//! Called when some attachment of this parent is ruined. Called on server and client side.
	void OnAttachmentRuined(EntityAI attachment)
	{
		// ...
	}
	
	void EEHitBy(TotalDamageResult damageResult, int damageType, EntityAI source, int component, string dmgZone, string ammo, vector modelPos, float speedCoef)
	{
		if (m_OnHitByInvoker)
			m_OnHitByInvoker.Invoke(this, damageResult, damageType, source, component, dmgZone, ammo, modelPos, speedCoef);
		#ifdef DEVELOPER
		//Print("EEHitBy: " + this + "; damageResult:"+ damageResult.GetDamage("","") +"; damageType: "+ damageType +"; source: "+ source +"; component: "+ component +"; dmgZone: "+ dmgZone +"; ammo: "+ ammo +"; modelPos: "+ modelPos);
		#endif
	}
	
	// called only on the client who caused the hit
	void EEHitByRemote(int damageType, EntityAI source, int component, string dmgZone, string ammo, vector modelPos)
	{
		
	}
	
	// !Called on PARENT when a child is attached to it.
	void EEItemAttached(EntityAI item, string slot_name)
	{
		int slotId = InventorySlots.GetSlotIdFromString(slot_name);
		PropagateExclusionValueRecursive(item.GetAttachmentExclusionMaskAll(slotId),slotId); //Performed from parent to avoid event order issues on swap
		SetWeightDirty();

		if ( m_ComponentsBank != NULL )
		{
			for ( int comp_key = 0; comp_key < COMP_TYPE_COUNT; ++comp_key )
			{
				if ( m_ComponentsBank.IsComponentAlreadyExist(comp_key) )
				{
					m_ComponentsBank.GetComponent(comp_key).Event_OnItemAttached(item, slot_name);
				}
			}
		}		
		
		// Energy Manager
		if ( m_EM && item.GetCompEM())
			m_EM.OnAttachmentAdded(item);
		
		if ( item.GetInventory().GetCargo() )
			m_AttachmentsWithCargo.Insert( item );
		
		if ( item.GetInventory().GetAttachmentSlotsCount() > 0 )
			m_AttachmentsWithAttachments.Insert( item );
		
		if ( m_OnItemAttached )
			m_OnItemAttached.Invoke( item, slot_name, this );
	}
	
	void SwitchItemSelectionTexture(EntityAI item, string slot_name);
	void SwitchItemSelectionTextureEx(EItemManipulationContext context, Param par = null);
	
	// !Called on PARENT when a child is detached from it.
	void EEItemDetached(EntityAI item, string slot_name)
	{
		int slotId = InventorySlots.GetSlotIdFromString(slot_name);
		ClearExclusionValueRecursive(item.GetAttachmentExclusionMaskAll(slotId),slotId); //Performed from parent to avoid event order issues on swap
		SetWeightDirty();
		
		if ( m_ComponentsBank != NULL )
		{
			for ( int comp_key = 0; comp_key < COMP_TYPE_COUNT; ++comp_key )
			{
				if ( m_ComponentsBank.IsComponentAlreadyExist(comp_key) )
				{
					m_ComponentsBank.GetComponent(comp_key).Event_OnItemDetached(item, slot_name);
				}
			}
		}
		
		// Energy Manager
		if (m_EM && item.GetCompEM())
			m_EM.OnAttachmentRemoved(item);
		
		if ( m_AttachmentsWithCargo.Find( item ) > -1 )
			m_AttachmentsWithCargo.RemoveItem( item );
		
		if ( m_AttachmentsWithAttachments.Find( item ) > -1 )
			m_AttachmentsWithAttachments.RemoveItem( item );
		
				
		if ( m_OnItemDetached )
			m_OnItemDetached.Invoke( item, slot_name, this );
	}

	void EECargoIn(EntityAI item)
	{
		SetWeightDirty();
		
		if( m_OnItemAddedIntoCargo )
			m_OnItemAddedIntoCargo.Invoke( item, this );
			
		item.OnMovedInsideCargo(this);
	}

	void EECargoOut(EntityAI item)
	{
		SetWeightDirty();
		
		if( m_OnItemRemovedFromCargo )
			m_OnItemRemovedFromCargo.Invoke( item, this );
			
		item.OnRemovedFromCargo(this);
	}

	void EECargoMove(EntityAI item)
	{
		if( m_OnItemMovedInCargo )
			m_OnItemMovedInCargo.Invoke( item, this );
		item.OnMovedWithinCargo(this);
	}
	
	ScriptInvoker GetOnItemAttached()
	{
		if( !m_OnItemAttached )
			m_OnItemAttached = new ScriptInvoker;
		return m_OnItemAttached;
	}
	
	ScriptInvoker GetOnItemDetached()
	{
		if( !m_OnItemDetached )
			m_OnItemDetached = new ScriptInvoker;
		return m_OnItemDetached;
	}
	
	ScriptInvoker GetOnItemAddedIntoCargo()
	{
		if( !m_OnItemAddedIntoCargo )
			m_OnItemAddedIntoCargo = new ScriptInvoker;
		return m_OnItemAddedIntoCargo;
	}
	
	ScriptInvoker GetOnItemRemovedFromCargo()
	{
		if( !m_OnItemRemovedFromCargo )
			m_OnItemRemovedFromCargo = new ScriptInvoker;
		return m_OnItemRemovedFromCargo;
	}
	
	ScriptInvoker GetOnItemMovedInCargo()
	{
		if( !m_OnItemMovedInCargo )
			m_OnItemMovedInCargo = new ScriptInvoker;
		return m_OnItemMovedInCargo;
	}
	
	ScriptInvoker GetOnItemFlipped()
	{
		if( !m_OnItemFlipped )
			m_OnItemFlipped = new ScriptInvoker;
		return m_OnItemFlipped;
	}
	
	ScriptInvoker GetOnViewIndexChanged()
	{
		if( !m_OnViewIndexChanged )
			m_OnViewIndexChanged = new ScriptInvoker;
		return m_OnViewIndexChanged;
	}
	
	ScriptInvoker GetOnSetLock()
	{
		if( !m_OnSetLock )
			m_OnSetLock = new ScriptInvoker;
		return m_OnSetLock;
	}
	
	ScriptInvoker GetOnReleaseLock()
	{
		if( !m_OnReleaseLock )
			m_OnReleaseLock = new ScriptInvoker;
		return m_OnReleaseLock;
	}
	
	ScriptInvoker GetOnAttachmentSetLock()
	{
		if( !m_OnAttachmentSetLock )
			m_OnAttachmentSetLock = new ScriptInvoker;
		return m_OnAttachmentSetLock;
	}
	
	ScriptInvoker GetOnAttachmentReleaseLock()
	{
		if( !m_OnAttachmentReleaseLock )
			m_OnAttachmentReleaseLock = new ScriptInvoker;
		return m_OnAttachmentReleaseLock;
	}
	
	ScriptInvoker GetOnHitByInvoker()
	{
		if ( !m_OnHitByInvoker )
			m_OnHitByInvoker = new ScriptInvoker;
		return m_OnHitByInvoker;
	}
	
	ScriptInvoker GetOnKilledInvoker()
	{
		if ( !m_OnKilledInvoker )
			m_OnKilledInvoker = new ScriptInvoker;
		return m_OnKilledInvoker;
	}
	
	
	//! Called when this item enters cargo of some container
	void OnMovedInsideCargo(EntityAI container)
	{
		if (m_EM)
			m_EM.HandleMoveInsideCargo(container);
	}
	
	//! Called when this item exits cargo of some container
	void OnRemovedFromCargo(EntityAI container)
	{
		
	}
	
	//! Called when this item moves within cargo of some container
	void OnMovedWithinCargo(EntityAI container)
	{
	
	}
	
	//! Called when entity is part of "connected system" and being restored after load
	void EEOnAfterLoad()
	{
		// ENERGY MANAGER
		// Restore connections between devices which were connected before server restart
		if ( m_EM && m_EM.GetRestorePlugState() )
		{
			int b1 = m_EM.GetEnergySourceStorageIDb1();
			int b2 = m_EM.GetEnergySourceStorageIDb2();
			int b3 = m_EM.GetEnergySourceStorageIDb3();
			int b4 = m_EM.GetEnergySourceStorageIDb4();

			// get pointer to EntityAI based on this ID
			EntityAI potential_energy_source = GetGame().GetEntityByPersitentID(b1, b2, b3, b4); // This function is available only in this event!
			
			// IMPORTANT!
			// Object IDs acquired here become INVALID when electric devices are transfered to another server while in plugged state (like Flashlight plugged into its attachment 9V battery)
			// To avoid issues, these items must be excluded from this system of restoring plug state so they don't unintentionally plug to incorrect devices through these invalid IDs.
			// Therefore their plug state is being restored withing the EEItemAttached() event while being excluded by the following 'if' conditions...
			
			bool is_attachment = false;
			
			if (potential_energy_source)
				is_attachment = GetInventory().HasAttachment(potential_energy_source);
			
			if ( !is_attachment	&&	potential_energy_source )
				is_attachment = potential_energy_source.GetInventory().HasAttachment(this);
			
			if ( potential_energy_source && potential_energy_source.GetCompEM() /*&& potential_energy_source.HasEnergyManager()*/ && !is_attachment )
				m_EM.PlugThisInto(potential_energy_source); // restore connection
		}
	}
	
	//! Called when entity is being created as new by CE/ Debug
	void EEOnCECreate()
	{
	}

	//! Called when entity is being loaded from DB or Storage (after all children loaded)
	void AfterStoreLoad()
	{
	}
	
	//! Called when an item fails to get loaded into the inventory of an entity and gets dropped
	void OnBinLoadItemsDropped()
	{
		if (GetHierarchyRootPlayer())
			GetHierarchyRootPlayer().SetProcessUIWarning(true);
	}
	
	//! Sets all animation values to 1, making them INVISIBLE if they are configured in models.cfg in such way. These selections must also be defined in the entity's config class in 'AnimationSources'. 
	void HideAllSelections()
	{
		string cfg_path = "cfgVehicles " + GetType() + " AnimationSources";
		
		if ( GetGame().ConfigIsExisting(cfg_path) )
		{
			int	selections = GetGame().ConfigGetChildrenCount(cfg_path);
			
			for (int i = 0; i < selections; i++)
			{
				string selection_name;
				GetGame().ConfigGetChildName(cfg_path, i, selection_name);
				HideSelection(selection_name);
			}
		}
	}
	
	//! Sets all animation values to 0, making them VISIBLE if they are configured in models.cfg in such way. These selections must also be defined in the entity's config class in 'AnimationSources'. 
	void ShowAllSelections()
	{
		string cfg_path = "cfgVehicles " + GetType() + " AnimationSources";
		
		if ( GetGame().ConfigIsExisting(cfg_path) )
		{
			int	selections = GetGame().ConfigGetChildrenCount(cfg_path);
			
			for (int i = 0; i < selections; i++)
			{
				string selection_name;
				GetGame().ConfigGetChildName(cfg_path, i, selection_name);
				ShowSelection(selection_name);
			}
		}
	}
	
	/**@fn		CanReceiveAttachment
	 * @brief calls this->CanReceiveAttachment(attachment)
	 * @return	true if action allowed
	 *
	 * @note: return scriptConditionExecute(this, attachment, "CanReceiveAttachment");
	 **/
	bool CanReceiveAttachment (EntityAI attachment, int slotId)
	{
		//generic occupancy check
		EntityAI currentAtt = GetInventory().FindAttachment(slotId);
		bool hasInternalConflict = attachment.HasInternalExclusionConflicts(slotId);
		if (currentAtt) //probably a swap or same-type swap
		{
			set<int> diff = attachment.GetAttachmentExclusionMaskAll(slotId);
			diff.RemoveItems(currentAtt.GetAttachmentExclusionMaskAll(slotId));
			if (diff.Count() == 0)
			{
				return !hasInternalConflict;
			}
			else
			{
				return !hasInternalConflict && !IsExclusionFlagPresentRecursive(diff,slotId);
			}
		}
		return !hasInternalConflict && !IsExclusionFlagPresentRecursive(attachment.GetAttachmentExclusionMaskAll(slotId),slotId);
	}
	
	/**@fn		CanLoadAsAttachment
	 * @brief	calls this->CanLoadAsAttachment(attachment), is called on server start when loading in the storage
	 * @return	true if action allowed
	 *
	 * @note: return scriptConditionExecute(this, attachment, "CanLoadAsAttachment");
	 **/
	bool CanLoadAttachment(EntityAI attachment)
	{
		return true;
	}

	/**@fn		CanPutAsAttachment
	 * @brief	calls this->CanPutAsAttachment(parent)
	 * @param[in] parent	\p	target entity this is trying to attach to
	 * @return	true if action allowed
	 *
	 * @note: engine code is scriptConditionExecute(this, parent, "CanPutAsAttachment")
	 **/
	bool CanPutAsAttachment (EntityAI parent)
	{
		return !IsHologram();
	}

	//If return true, item can be attached even from parent to this. Item will be switched during proccess. (only hands)
	bool CanSwitchDuringAttach(EntityAI parent)
	{
		return false;
	}
	/**@fn		CanReleaseAttachment
	 * @brief calls this->CanReleaseAttachment(attachment)
	 * @return	true if action allowed
	 *
	 * @note: return scriptConditionExecute(this, attachment, "CanReleaseAttachment");
	 **/
	bool CanReleaseAttachment (EntityAI attachment)
	{
		if( attachment && attachment.GetInventory() && GetInventory() )
		{
			InventoryLocation il = new InventoryLocation();
			attachment.GetInventory().GetCurrentInventoryLocation( il );
			if( il.IsValid() )
			{
				int slot = il.GetSlot();
				return !GetInventory().GetSlotLock( slot );
			}
		}
		return true;
	}
	/**@fn		CanDetachAttachment
	 * @brief	calls this->CanDetachAttachment(parent)
	 * @return	true if action allowed
	 *
	 * @note: return scriptConditionExecute(this, parent, "CanDetachAttachment");
	 **/
	bool CanDetachAttachment (EntityAI parent)
	{
		return true;
	}
	
	bool CanBeFSwaped()
	{
		return true;
	}
	
	bool CanCombineAttachment(notnull EntityAI e, int slot, bool stack_max_limit = false)
	{
		EntityAI att = GetInventory().FindAttachment(slot);
		if(att)
			return att.CanBeCombined(e, true, stack_max_limit);
		return false;
	}	
	
	bool CanBeCombined(EntityAI other_item, bool reservation_check = true, bool stack_max_limit = false )
	{
		return false;
	}
	
	void CombineItemsClient(EntityAI entity2, bool use_stack_max = false )
	{}
	
	/**@fn		CanReceiveItemIntoCargo
	 * @brief	calls this->CanReceiveItemIntoCargo(item)
	 * @return	true if action allowed
	 *
	 * @note: return scriptConditionExecute(this, item, "CanReceiveItemIntoCargo");
	 **/
	bool CanReceiveItemIntoCargo(EntityAI item)
	{
		if (GetInventory() && GetInventory().GetCargo())
			return GetInventory().GetCargo().CanReceiveItemIntoCargo(item));
		
		return true;
	}
	
	/**@fn		CanLoadItemIntoCargo
	 * @brief	calls this->CanLoadItemIntoCargo(item), is called on server start when loading in the storage
	 * @return	true if action allowed
	 *
	 * @note: return scriptConditionExecute(this, item, "CanLoadItemIntoCargo");
	 **/
	bool CanLoadItemIntoCargo(EntityAI item)
	{
		return true;
	}
	
	/**@fn		CanPutInCargo
	 * @brief	calls this->CanPutInCargo(parent)
	 * @return	true if action allowed
	 *
	 * @note: return scriptConditionExecute(this, parent, "CanPutInCargo");
	 **/
	bool CanPutInCargo (EntityAI parent)
	{
		return !IsHologram();
	}

	/**@fn		CanSwapItemInCargo
	 * @brief	calls this->CanSwapItemInCargo(child_entity, new_entity)
	 * @return	true if action allowed
	 *
	 * @note: return ScriptConditionExecute(GetOwner(), child_entity, "CanSwapItemInCargo", new_entity);
	 **/
	bool CanSwapItemInCargo (EntityAI child_entity, EntityAI new_entity)
	{
		if (GetInventory() && GetInventory().GetCargo())
			return GetInventory().GetCargo().CanSwapItemInCargo(child_entity, new_entity));
		
		return true;
	}

	/**@fn		CanReleaseCargo
	 * @brief	calls this->CanReleaseCargo(cargo)
	 * @return	true if action allowed
	 *
	 * @note: return scriptConditionExecute(this, cargo, "CanReleaseCargo");
	 **/
	bool CanReleaseCargo (EntityAI cargo)
	{
		return true;
	}

	/**@fn		CanRemoveFromCargo
	 * @brief	calls this->CanRemoveFromCargo(parent)
	 * @return	true if action allowed
	 *
	 * @note: return scriptConditionExecute(this, parent, "CanRemoveFromCargo");
	 **/
	bool CanRemoveFromCargo (EntityAI parent)
	{
		return true;
	}
	
	/**@fn		CanReceiveItemIntoInventory
	 * @brief calls this->CanReceiveItemIntoInventory(item)
	 * @return	true if action allowed
	 *
	 * @note: return scriptConditionExecute(this, , "CanReceiveItemIntoInventory");
	 **/
	/*bool CanReceiveItemIntoInventory (EntityAI entity_ai)
	{
		return true;
	}*/

	/**@fn		CanPutInInventory
	 * @brief calls this->CanPutInInventory(parent)
	 * @return	true if action allowed
	 *
	 * @note: return scriptConditionExecute(this, parent, "ConditionIntoInventory");
	 **/
	/*bool CanPutInInventory (EntityAI parent)
	{
		return true;
	}*/

	/**@fn		CanReceiveItemIntoHands
	 * @brief	calls this->CanReceiveItemIntoHands(item_to_hands)
	 * @return	true if action allowed
	 *
	 * @note: scriptConditionExecute(this, item_to_hands, "CanReceiveItemIntoHands");
	 **/
	bool CanReceiveItemIntoHands (EntityAI item_to_hands)
	{
		return true;
	}
	
	bool IsBeingPlaced()
	{
		return false;
	}
	
	override bool IsHologram()
	{
		return false;
	}
	
	bool CanSaveItemInHands (EntityAI item_in_hands)
	{
		return true;
	}

	/**@fn		CanPutIntoHands
	 * @brief calls this->CanPutIntoHands(parent)
	 * @return	true if action allowed
	 *
	 * @note: return scriptConditionExecute(this, parent, "CanPutIntoHands");
	 **/
	bool CanPutIntoHands (EntityAI parent)
	{
		return !IsHologram();
	}

	/**@fn		CanReleaseFromHands
	 * @brief calls this->CanReleaseFromHands(handheld)
	 * @return	true if action allowed
	 *
	 * @note: scriptConditionExecute(this, handheld, "CanReleaseFromHands");
	 **/
	bool CanReleaseFromHands (EntityAI handheld)
	{
		return true;
	}

	/**@fn		CanRemoveFromHands
	 * @brief	calls this->CanRemoveFromHands(parent)
	 * @return	true if action allowed
	 *
	 * @note: return scriptConditionExecute(this, parent, "CanRemoveFromHands");
	 **/
	bool CanRemoveFromHands (EntityAI parent)
	{
		return true;
	}

	/**@fn		CanDisplayAttachmentSlot
	 * @param	slot_name->name of the attachment slot that will or won't be displayed
	 * @return	true if attachment icon can be displayed in UI (inventory)
	 **/	
	bool CanDisplayAttachmentSlot( string slot_name )
	{
		Debug.LogWarning("Obsolete function - use CanDisplayAttachmentSlot with slot id parameter");
		return InventorySlots.GetShowForSlotId(InventorySlots.GetSlotIdFromString(slot_name));
	}
	
	/**@fn		CanDisplayAttachmentSlot
	 * @param	slot_id->id of the attachment slot that will or won't be displayed
	 * @return	true if attachment icon can be displayed in UI (inventory)
	 **/	
	bool CanDisplayAttachmentSlot( int slot_id )
	{
		return InventorySlots.GetShowForSlotId(slot_id);
	}
	
	/**@fn		CanDisplayAnyAttachmentSlot
	 * @return	true if any attachment slot can be shown
	 **/	
	bool CanDisplayAnyAttachmentSlot()
	{
		int count = GetInventory().GetAttachmentSlotsCount();
		int slotID;
		for (int i = 0; i < count; i++)
		{
			slotID = GetInventory().GetAttachmentSlotId(i);
			if (CanDisplayAttachmentSlot(slotID))
			{
				return true;
			}
		}
		
		return false;
	}

	/**@fn		CanDisplayAttachmentCategory
	 * @param	category_name->name of the attachment category that will or won't be displayed
	 * @return	true if attachment icon can be displayed in UI (inventory)
	 **/		
	bool CanDisplayAttachmentCategory( string category_name )
	{
		return true;
	}
	
	/**@fn		CanDisplayCargo
	 * @return	true if cargo can be displayed in UI (inventory)
	 **/		
	bool CanDisplayCargo()
	{
		return GetInventory().GetCargo() != null;
	}
	
	/**@fn		CanAssignToQuickbar
	 * @return	true if item can be assigned to quickbar safely
	 **/		
	bool CanAssignToQuickbar()
	{
		return true;
	}
	
	/**@fn		CanAssignAttachmentsToQuickbar
	 * @return	true if attached item can be assigned to quickbar safely
	 **/
	bool CanAssignAttachmentsToQuickbar()
	{
		return true;
	}
	
	/**@fn		IgnoreOutOfReachCondition
	 * @return	if true, attachment condition for out of reach (inventory) will be ignored
	 **/		
	bool IgnoreOutOfReachCondition()
	{
		return GetHierarchyRootPlayer() == GetGame().GetPlayer();
	}	

	// !Called on CHILD when it's attached to parent.
	void OnWasAttached( EntityAI parent, int slot_id );
	
	// !Called on CHILD when it's detached from parent.
	void OnWasDetached( EntityAI parent, int slot_id )
	{
		if (!IsFlagSet(EntityFlags.VISIBLE))
		{
			SetInvisible(false);
			OnInvisibleSet(false);
			SetInvisibleRecursive(false,parent);
		}
	}
	
	void OnCargoChanged() { }
	
	bool IsTakeable()
	{
		return false;
	}
	
	proto native GameInventory GetInventory();
	proto native void CreateAndInitInventory();
	proto native void DestroyInventory();
		
	int GetSlotsCountCorrect()
	{
		if (GetInventory())
			return GetInventory().GetAttachmentSlotsCount();
		else
			return -1;
	}

	EntityAI FindAttachmentBySlotName(string slot_name)
	{
		if ( GetGame() )
		{
			int slot_id = InventorySlots.GetSlotIdFromString(slot_name);
			if (slot_id != InventorySlots.INVALID)
				return GetInventory().FindAttachment(slot_id); 
		}
		return null;
	}

	/**@fn		IsLockedInSlot
	 * @return	true if entity is locked in attachment slot
	 **/	
	bool IsLockedInSlot()
	{
		EntityAI parent = GetHierarchyParent();
		if ( parent )
		{
			InventoryLocation inventory_location = new InventoryLocation();
			GetInventory().GetCurrentInventoryLocation( inventory_location );
			
			return parent.GetInventory().GetSlotLock( inventory_location.GetSlot() );
		}
		
		return false;
	}
	
	/**
	\brief Put item anywhere into this entity (as attachment or into cargo, recursively)
	*/
	bool PredictiveTakeEntityToInventory (FindInventoryLocationType flags, notnull EntityAI item)
	{
		if ( GetGame().IsMultiplayer() )
			return GetInventory().TakeEntityToInventory(InventoryMode.JUNCTURE, flags, item);
		else
			return GetInventory().TakeEntityToInventory(InventoryMode.PREDICTIVE, flags, item);
	}
	bool LocalTakeEntityToInventory (FindInventoryLocationType flags, notnull EntityAI item)
	{
		return GetInventory().TakeEntityToInventory(InventoryMode.LOCAL, flags, item);
	}
	bool ServerTakeEntityToInventory (FindInventoryLocationType flags, notnull EntityAI item)
	{
		return GetInventory().TakeEntityToInventory(InventoryMode.SERVER, flags, item);
	}
	bool PredictiveTakeEntityToTargetInventory (notnull EntityAI target, FindInventoryLocationType flags, notnull EntityAI item)
	{
		if ( GetGame().IsMultiplayer() )
			return GetInventory().TakeEntityToTargetInventory(InventoryMode.JUNCTURE, target, flags, item);
		else
			return GetInventory().TakeEntityToTargetInventory(InventoryMode.PREDICTIVE, target, flags, item);
	}
	bool LocalTakeEntityToTargetInventory (notnull EntityAI target, FindInventoryLocationType flags, notnull EntityAI item)
	{
		return GetInventory().TakeEntityToTargetInventory(InventoryMode.LOCAL, target, flags, item);
	}
	bool ServerTakeEntityToTargetInventory (notnull EntityAI target, FindInventoryLocationType flags, notnull EntityAI item)
	{
		return GetInventory().TakeEntityToTargetInventory(InventoryMode.SERVER, target, flags, item);
	}
	/**
	\brief Put item into into cargo
	*/
	bool PredictiveTakeEntityToCargo (notnull EntityAI item)
	{
		if ( GetGame().IsMultiplayer() )
			return GetInventory().TakeEntityToCargo(InventoryMode.JUNCTURE, item);
		else
			return GetInventory().TakeEntityToCargo(InventoryMode.PREDICTIVE, item);
	}
	bool LocalTakeEntityToCargo (notnull EntityAI item)
	{
		return GetInventory().TakeEntityToCargo(InventoryMode.LOCAL, item);
	}
	bool ServerTakeEntityToCargo (notnull EntityAI item)
	{
		return GetInventory().TakeEntityToCargo(InventoryMode.SERVER, item);
	}

	bool PredictiveTakeEntityToTargetCargo (notnull EntityAI target, notnull EntityAI item)
	{
		if ( GetGame().IsMultiplayer() )
			return GetInventory().TakeEntityToTargetCargo(InventoryMode.JUNCTURE, target, item);
		else
			return GetInventory().TakeEntityToTargetCargo(InventoryMode.PREDICTIVE, target, item);
	}
	bool LocalTakeEntityToTargetCargo (notnull EntityAI target, notnull EntityAI item)
	{
		return GetInventory().TakeEntityToTargetCargo(InventoryMode.LOCAL, target, item);
	}
	bool ServerTakeEntityToTargetCargo (notnull EntityAI target, notnull EntityAI item)
	{
		return GetInventory().TakeEntityToTargetCargo(InventoryMode.SERVER, target, item);
	}
	/**
	\brief Put item into into cargo on specific cargo location
	*/
	bool PredictiveTakeEntityToCargoEx (notnull EntityAI item, int idx, int row, int col)
	{
		if ( GetGame().IsMultiplayer() )
			return GetInventory().TakeEntityToCargoEx(InventoryMode.JUNCTURE, item, idx, row, col);
		else
			return GetInventory().TakeEntityToCargoEx(InventoryMode.PREDICTIVE, item, idx, row, col);
	}
	bool LocalTakeEntityToCargoEx (notnull EntityAI item, int idx, int row, int col)
	{
		return GetInventory().TakeEntityToCargoEx(InventoryMode.LOCAL, item, idx, row, col);
	}

	bool PredictiveTakeEntityToTargetCargoEx (notnull CargoBase cargo, notnull EntityAI item, int row, int col)
	{
		if ( GetGame().IsMultiplayer() )
			return GetInventory().TakeEntityToTargetCargoEx(InventoryMode.JUNCTURE, cargo, item, row, col);
		else
			return GetInventory().TakeEntityToTargetCargoEx(InventoryMode.PREDICTIVE, cargo, item, row, col);
	}
	bool LocalTakeEntityToTargetCargoEx (notnull CargoBase cargo, notnull EntityAI item, int row, int col)
	{
		return GetInventory().TakeEntityToTargetCargoEx(InventoryMode.LOCAL, cargo, item, row, col);
	}
	bool ServerTakeEntityToTargetCargoEx (notnull CargoBase cargo, notnull EntityAI item, int row, int col)
	{
		return GetInventory().TakeEntityToTargetCargoEx(InventoryMode.SERVER, cargo, item, row, col);
	}
	/**
	\brief Returns if item can be added as attachment on specific slot. Note that slot index IS NOT slot ID! Slot ID is defined in DZ/data/config.cpp
	*/
	bool PredictiveTakeEntityAsAttachmentEx (notnull EntityAI item, int slot)
	{
		if ( GetGame().IsMultiplayer() )
			return GetInventory().TakeEntityAsAttachmentEx(InventoryMode.JUNCTURE, item, slot);
		else
			return GetInventory().TakeEntityAsAttachmentEx(InventoryMode.PREDICTIVE, item, slot);
	}
	bool LocalTakeEntityAsAttachmentEx (notnull EntityAI item, int slot)
	{
		return GetInventory().TakeEntityAsAttachmentEx(InventoryMode.LOCAL, item, slot);
	}
	bool ServerTakeEntityAsAttachmentEx (notnull EntityAI item, int slot)
	{
		return GetInventory().TakeEntityAsAttachmentEx(InventoryMode.SERVER, item, slot);
	}

	bool PredictiveTakeEntityToTargetAttachmentEx (notnull EntityAI target, notnull EntityAI item, int slot)
	{
		if ( GetGame().IsMultiplayer() )
			return GetInventory().TakeEntityAsTargetAttachmentEx(InventoryMode.JUNCTURE, target, item, slot);
		else
			return GetInventory().TakeEntityAsTargetAttachmentEx(InventoryMode.PREDICTIVE, target, item, slot);
	}
	bool LocalTakeEntityToTargetAttachmentEx (notnull EntityAI target, notnull EntityAI item, int slot)
	{
		return GetInventory().TakeEntityAsTargetAttachmentEx(InventoryMode.LOCAL, target, item, slot);
	}
	bool ServerTakeEntityToTargetAttachmentEx (notnull EntityAI target, notnull EntityAI item, int slot)
	{
		return GetInventory().TakeEntityAsTargetAttachmentEx(InventoryMode.SERVER, target, item, slot);
	}

	bool PredictiveTakeEntityToTargetAttachment (notnull EntityAI target, notnull EntityAI item)
	{
		if ( GetGame().IsMultiplayer() )
			return GetInventory().TakeEntityAsTargetAttachment(InventoryMode.JUNCTURE, target, item);
		else
			return GetInventory().TakeEntityAsTargetAttachment(InventoryMode.PREDICTIVE, target, item);
	}
	bool LocalTakeEntityToTargetAttachment (notnull EntityAI target, notnull EntityAI item)
	{
		return GetInventory().TakeEntityAsTargetAttachment(InventoryMode.LOCAL, target, item);
	}
	bool ServerTakeEntityToTargetAttachment (notnull EntityAI target, notnull EntityAI item)
	{
		return GetInventory().TakeEntityAsTargetAttachment(InventoryMode.SERVER, target, item);
	}

	bool PredictiveTakeToDst (notnull InventoryLocation src, notnull InventoryLocation dst)
	{
		if ( GetGame().IsMultiplayer() )
			return GetInventory().TakeToDst(InventoryMode.JUNCTURE, src, dst);
		else
			return GetInventory().TakeToDst(InventoryMode.PREDICTIVE, src, dst);
	}
	bool LocalTakeToDst (notnull InventoryLocation src, notnull InventoryLocation dst)
	{
		return GetInventory().TakeToDst(InventoryMode.LOCAL, src, dst);
	}
	bool ServerTakeToDst (notnull InventoryLocation src, notnull InventoryLocation dst)
	{
		return GetInventory().TakeToDst(InventoryMode.SERVER, src, dst);
	}

	/**
	\brief Put item into as attachment
	*/
	bool PredictiveTakeEntityAsAttachment(notnull EntityAI item)
	{
		if (GetGame().IsMultiplayer())
			return GetInventory().TakeEntityAsAttachment(InventoryMode.JUNCTURE, item);
		else
			return GetInventory().TakeEntityAsAttachment(InventoryMode.PREDICTIVE, item);
	}
	bool LocalTakeEntityAsAttachment (notnull EntityAI item)
	{
		return GetInventory().TakeEntityAsAttachment(InventoryMode.LOCAL, item);
	}
	bool ServerTakeEntityAsAttachment (notnull EntityAI item)
	{
		return GetInventory().TakeEntityAsAttachment(InventoryMode.SERVER, item);
	}

	bool PredictiveDropEntity(notnull EntityAI item)
	{
		return false;
	}
	
	bool LocalDropEntity(notnull EntityAI item)
	{
		return false;
	}
	
	bool ServerDropEntity(notnull EntityAI item)
	{
		return false;
	}

	/**
	\brief Get attached entity by type
	*/
	EntityAI GetAttachmentByType(typename type)
	{
		for ( int i = 0; i < GetInventory().AttachmentCount(); i++ )
		{
			EntityAI attachment = GetInventory().GetAttachmentFromIndex( i );
			if ( attachment && attachment.IsInherited( type ) )
				return attachment;
		}
		return NULL;
	}

	/**
	\brief Get attached entity by config type name
	*/
	EntityAI GetAttachmentByConfigTypeName(string type)
	{
		for ( int i = 0; i < GetInventory().AttachmentCount(); i++ )
		{
			EntityAI attachment = GetInventory().GetAttachmentFromIndex ( i );
			if ( attachment.IsKindOf ( type ) )
				return attachment;
			}
		return NULL;
	}
	/**
	\brief Returns if item can be dropped out from this entity
	*/
	bool CanDropEntity(notnull EntityAI item)
	{
		return true;
	}

	EntityAI SpawnInInventoryOrGroundPos(string object_name, GameInventory inv, vector pos)
	{
		if (inv)
		{
			EntityAI res = inv.CreateInInventory(object_name);
			if (res)
			{
				return res;
			}
		}

		return SpawnEntityOnGroundPos(object_name, pos);
	}

	/**
	 **/
	EntityAI SpawnEntityOnGroundPos(string object_name, vector pos)
	{
		InventoryLocation il = new InventoryLocation();
		vector mat[4];
		Math3D.MatrixIdentity4(mat);
		mat[3] = pos;
		il.SetGround(NULL, mat);
		return SpawnEntity(object_name, il,ECE_PLACE_ON_SURFACE,RF_DEFAULT);
	}
	/**
	 **/
	EntityAI SpawnEntityOnGround(string object_name, vector mat[4])
	{
		InventoryLocation il = new InventoryLocation();
		il.SetGround(NULL, mat);
		return SpawnEntity(object_name, il,ECE_PLACE_ON_SURFACE,RF_DEFAULT);
	}
	
	//----------------------------------------------------------------

	bool CanSwapEntities(EntityAI otherItem, InventoryLocation otherDestination, InventoryLocation destination)
	{
		return true;
	}
	
	// Forward declarations to allow lower modules to access properties that are modified from higher modules
	// These are mainly used within the ItemBase
	void SetWet(float value, bool allow_client = false);
	void AddWet(float value);
	void SetWetMax();

	float GetWet()
	{
		return 0;
	}
	
	float GetWetMax()
	{
		return 0;
	}

	float GetWetMin()
	{
		return 0;
	}
	
	float GetWetInit()
	{
		return 0;
	}
	
	bool HasWetness()
	{
		return GetWetMax() - GetWetMin() != 0;
	}
	
	void OnWetChanged(float newVal, float oldVal);

	void OnWetLevelChanged(EWetnessLevel newLevel, EWetnessLevel oldLevel);
	// ! Returns current wet level of the entity
	EWetnessLevel GetWetLevel();
	
	// ! Calculates wet level from a given wetness, to get level of an entity, use 'GetWetLevel()' instead
	static EWetnessLevel GetWetLevelInternal(float wetness)
	{
		if (wetness < GameConstants.STATE_DAMP)
		{
			return EWetnessLevel.DRY;
		}
		else if (wetness < GameConstants.STATE_WET)
		{
			return EWetnessLevel.DAMP;
		}
		else if (wetness < GameConstants.STATE_SOAKING_WET)
		{
			return EWetnessLevel.WET;
		}
		else if (wetness < GameConstants.STATE_DRENCHED)
		{
			return EWetnessLevel.SOAKING;
		}
		return EWetnessLevel.DRENCHED;
	}
	//----------------------------------------------------------------
	
	float GetQuantity()
	{
		return 0;
	}
	
	int GetQuantityMax()
	{
		return 0;
	}
	
	void SetQuantityToMinimum();
	
	int GetTargetQuantityMax(int attSlotID = -1)
	{
		return 0;
	}
	
	int GetQuickBarBonus()
	{
		return 0;
	}

	//----------------------------------------------------------------

	void SetTemperature(float value, bool allow_client = false) {};
	void AddTemperature(float value) {};
	void SetTemperatureMax() {};

	float GetTemperature()
	{
		return 0;
	}
	
	float GetTemperatureInit()
	{
		return 0;
	}
	
	float GetTemperatureMin()
	{
		return 0;
	}

	float GetTemperatureMax()
	{
		return 0;
	}
	
	//----------------------------------------------------------------
		
	HiddenSelectionsData GetHiddenSelectionsData()
	{
		return m_HiddenSelectionsData;
	}
	
	//! Returns index of the string found in cfg array 'hiddenSelections'. If it's not found then it returns -1.
	int GetHiddenSelectionIndex( string selection )
	{
		if (m_HiddenSelectionsData)
			return m_HiddenSelectionsData.GetHiddenSelectionIndex( selection );

		return -1;
	}
	
	//! Returns the hiddenSelectionsTextures array from the object's config
	override TStringArray GetHiddenSelections()
	{
		if (m_HiddenSelectionsData)
			return m_HiddenSelectionsData.m_HiddenSelections;
		else
			return super.GetHiddenSelections();
	}
	
	//! Returns the hiddenSelectionsTextures array from the object's config
	override TStringArray GetHiddenSelectionsTextures()
	{
		if (m_HiddenSelectionsData)
			return m_HiddenSelectionsData.m_HiddenSelectionsTextures;
		else
			return super.GetHiddenSelectionsTextures();
	}
	
	//! Returns the hiddenSelectionsMaterials array from the object's config
	override TStringArray GetHiddenSelectionsMaterials()
	{
		if (m_HiddenSelectionsData)
			return m_HiddenSelectionsData.m_HiddenSelectionsMaterials;
		else
			return super.GetHiddenSelectionsMaterials();
	}
	
	/**
	 * @fn		EntityPlaceOnSurfacePointWithRotation
	 * @brief	applies correct rotation according to WRUtils::EntityPlacementRotation(type->GetRotationFlags())
	 *
	 * @param[out]	trans	\p		the transform to apply the correct rotation on
	 * @param[in]	pos		\p		position to check
	 * @param[in]	dx		\p		up vector x to align to
	 * @param[in]	dz		\p		up vector z to align to
	 * @param[in]	fAngle	\p		angle to position
	 * @param[in]	align	\p		align to surface
	 **/	
	proto native void PlaceOnSurfaceRotated(out vector trans[4], vector pos, float dx = 0, float dz = 0, float fAngle = 0, bool align = false);

	/**
	 * @fn		RegisterNetSyncVariableBool
	 * @brief	registers bool variable synchronized over network
	 *
	 * @param[in]	variableName	\p		which variable should be synchronized
	 **/	
	proto native void RegisterNetSyncVariableBool(string variableName);
	
	/**
	 * @fn		RegisterNetSyncVariableBoolSignal
	 * @brief	when bool variable is true, it's sent to clients and become false again
	 *
	 * @param[in]	variableName	\p		which variable should be synchronized
	 **/	
	proto native void RegisterNetSyncVariableBoolSignal(string variableName);

	/**
	 * @fn		RegisterNetSyncVariableInt
	 * @brief	registers int variable synchronized over network
	 *
	 * @param[in]	variableName	\p		which variable should be synchronized
	 * @param[in]	minValue		\p		minimal value used for quantization (when minValue == maxValue, no quatization is done)
	 * @param[in]	maxValue		\p		maximal value used for quantization (when minValue == maxValue, no quatization is done)
	 **/	
	proto native void RegisterNetSyncVariableInt(string variableName, int minValue = 0, int maxValue = 0);
	
	/**
	 * @fn		RegisterNetSyncVariableFloat
	 * @brief	registers float variable synchronized over network
	 *
	 * @param[in]	variableName	\p		which variable should be synchronized
	 * @param[in]	minValue		\p		minimal value used for quantization (when minValue == maxValue, no quatization is done)
	 * @param[in]	maxValue		\p		maximal value used for quantization (when minValue == maxValue, no quatization is done)
	 * @param[in]	precision		\p		precision in number of digits after decimal point
	 **/	
	proto native void RegisterNetSyncVariableFloat(string variableName, float minValue = 0, float maxValue = 0, int precision = 1);
	
	/**
	 * @fn		RegisterNetSyncVariableObject
	 * @brief	registers object variable synchronized over network, only synchronizes if network id is assigned. Doesn't handle object despawn on client
	 *
	 * @param[in]	variableName	\p		which variable should be synchronized
	 **/	
	proto native void RegisterNetSyncVariableObject(string variableName);
	
	proto native void UpdateNetSyncVariableInt(string variableName, float minValue = 0, float maxValue = 0);
	proto native void UpdateNetSyncVariableFloat(string variableName, float minValue = 0, float maxValue = 0, int precision = 1);

	proto native void SwitchLight(bool isOn);

	//! Simple hidden selection state; 0 == hidden
	proto native void SetSimpleHiddenSelectionState(int index, bool state);
	proto native bool IsSimpleHiddenSelectionVisible(int index);
	
	//! Change texture in hiddenSelections
	proto native void SetObjectTexture(int index, string texture_name);
	proto native owned string GetObjectTexture(int index);
	//! Change material in hiddenSelections
	proto native void SetObjectMaterial(int index, string mat_name);
	proto native owned string GetObjectMaterial(int index);
		
	proto native bool	IsPilotLight();
	proto native void SetPilotLight(bool isOn);

	/**
	\brief Engine calls this function to collect data from entity to store for persistence (on server side).
	@code
	void OnStoreSave(ParamsWriteContext ctx)
	{
		// dont forget to propagate this call trough class hierarchy!
		super.OnStoreSave(ctx);

		// write any data (using params) you want to store
		int   a = 5;
		float b = 6.0;

		ctx.Write(a);
		ctx.Write(b);
	}
	@endcode
	*/
	void OnStoreSave(ParamsWriteContext ctx)
	{
		// Saving of energy related states
		if ( m_EM )
		{		
			// Save energy amount
			ctx.Write( m_EM.GetEnergy() );
			
			// Save passive/active state
			ctx.Write( m_EM.IsPassive() );
			
			// Save ON/OFF state
			ctx.Write( m_EM.IsSwitchedOn() );
			
			// Save plugged/unplugged state
			ctx.Write( m_EM.IsPlugged() );
			
			// ENERGY SOURCE
			// Save energy source IDs
			EntityAI energy_source = m_EM.GetEnergySource();
			int b1 = 0;
			int b2 = 0;
			int b3 = 0;
			int b4 = 0;

			if (energy_source)
			{
				energy_source.GetPersistentID(b1, b2, b3, b4);
			}

			ctx.Write( b1 ); // Save energy source block 1
			ctx.Write( b2 ); // Save energy source block 2
			ctx.Write( b3 ); // Save energy source block 3
			ctx.Write( b4 ); // Save energy source block 4
		}
	}
	
	/**
	\brief Called when data is loaded from persistence (on server side).
	@code

	void OnStoreLoad(ParamsReadContext ctx, int version)
	{
		// dont forget to propagate this call trough class hierarchy!
		if ( !super.OnStoreLoad(ctx, version) )
			return false;

		// read data loaded from game database (format and order of reading must be the same as writing!)
		int a;
		if ( !ctx.Read(a) )
			return false;

		float b;
		if ( !ctx.Read(b) )
			return false;

		return true;
	}
	@endcode
	*/
	
	bool OnStoreLoad (ParamsReadContext ctx, int version)
	{
		// Restoring of energy related states
		
		if ( m_EM )
		{
			// Load energy amount
			float f_energy = 0;
			if ( !ctx.Read( f_energy ) )
				f_energy = 0;
			m_EM.SetEnergy(f_energy);
			
			// Load passive/active state
			bool b_is_passive = false;
			if ( !ctx.Read( b_is_passive ) )
				return false;
			m_EM.SetPassiveState(b_is_passive);
			
			// Load ON/OFF state
			bool b_is_on = false;
			if ( !ctx.Read( b_is_on ) )
			{
				m_EM.SwitchOn();
				return false;
			}
			
			// Load plugged/unplugged state
			bool b_is_plugged = false;
			if ( !ctx.Read( b_is_plugged ) )
				return false;
			
			// ENERGY SOURCE
			if ( version <= 103 )
			{
				// Load energy source ID low
				int i_energy_source_ID_low = 0; // Even 0 can be valid ID!
				if ( !ctx.Read( i_energy_source_ID_low ) )
					return false;
				
				// Load energy source ID high
				int i_energy_source_ID_high = 0; // Even 0 can be valid ID!
				if ( !ctx.Read( i_energy_source_ID_high ) )
					return false;
			}
			else
			{
				int b1 = 0;
				int b2 = 0;
				int b3 = 0;
				int b4 = 0;

				if ( !ctx.Read(b1) ) return false;
				if ( !ctx.Read(b2) ) return false;
				if ( !ctx.Read(b3) ) return false;
				if ( !ctx.Read(b4) ) return false;

				if ( b_is_plugged )
				{
					// Because function GetEntityByPersitentID() cannot be called here, ID values must be stored and used later.
					m_EM.StoreEnergySourceIDs( b1, b2, b3, b4 );
					m_EM.RestorePlugState(true);
				}
			}

			if (b_is_on)
			{
				m_EM.SwitchOn();
			}
		}
		return true;
	}

	//! Sets object synchronization dirty flag, which signalize that object wants to be synchronized (take effect only in MP on server side)
	proto native void SetSynchDirty();

	/**
	\brief Called on clients after receiving synchronization data from server.
	*/
	void OnVariablesSynchronized()
	{
		if ( m_EM )
		{
			if ( GetGame().IsMultiplayer() )
			{
				bool is_on = m_EM.IsSwitchedOn();
				
				if (is_on != m_EM.GetPreviousSwitchState())
				{
					if (is_on)
						m_EM.SwitchOn();
					else
						m_EM.SwitchOff();
				}
				
				int id_low = m_EM.GetEnergySourceNetworkIDLow();
				int id_High = m_EM.GetEnergySourceNetworkIDHigh();
				
				EntityAI energy_source = EntityAI.Cast( GetGame().GetObjectByNetworkId(id_low, id_High) );
				
				if (energy_source)
				{
					ComponentEnergyManager esem = energy_source.GetCompEM();
					
					if ( !esem )
					{
						string object = energy_source.GetType();
						Error("Synchronization error! Object " + object + " has no instance of the Energy Manager component!");
					}
					
					m_EM.PlugThisInto(energy_source);
					
				}
				else
				{
					m_EM.UnplugThis();
				}
				
				m_EM.DeviceUpdate();
				m_EM.StartUpdates();
			}
		}
	}

	proto native void SetAITargetCallbacks(AbstractAITargetCallbacks callbacks);

	override void EOnFrame(IEntity other, float timeSlice)
	{
		if ( m_ComponentsBank != NULL )
		{
			for ( int comp_key = 0; comp_key < COMP_TYPE_COUNT; ++comp_key )
			{
				if ( m_ComponentsBank.IsComponentAlreadyExist(comp_key) )
				{
					m_ComponentsBank.GetComponent(comp_key).Event_OnFrame(other, timeSlice);
				}
			}
		}
	}
	
	string GetDebugText()
	{
		string text = string.Empty;

		text += "Weight: " + GetWeightEx() + "\n";
		text += "Disabled: " + GetIsSimulationDisabled() + "\n";
		#ifdef SERVER
		if (GetEconomyProfile())
			text += "CE Lifetime default: " + (int)GetEconomyProfile().GetLifetime() + "\n";
		text += "CE Lifetime remaining: " + (int)GetLifetime() + "\n";
		#endif
		
		ComponentEnergyManager compEM = GetCompEM();
		if (compEM)
		{
			text += "Energy Source: " + Object.GetDebugName(compEM.GetEnergySource()) + "\n";
			text += "Switched On: " + compEM.IsSwitchedOn() + "\n";
			text += "Is Working: " + compEM.IsWorking() + "\n";
		}

		return text;
	}
	
	
	void GetDebugButtonNames(out string button1, out string button2, out string button3, out string button4){}//DEPRICATED, USE GetDebugActions / OnAction
	void OnDebugButtonPressClient(int button_index){}//DEPRICATED, USE GetDebugActions / OnAction
	void OnDebugButtonPressServer(int button_index){}//DEPRICATED, USE GetDebugActions / OnAction
	
	
	Shape DebugBBoxDraw()
	{
		return GetComponent(COMP_TYPE_ETITY_DEBUG).DebugBBoxDraw();
	}

	void DebugBBoxSetColor(int color)
	{
		GetComponent(COMP_TYPE_ETITY_DEBUG).DebugBBoxSetColor(color);
	}

	void DebugBBoxDelete()
	{
		GetComponent(COMP_TYPE_ETITY_DEBUG).DebugBBoxDelete();
	}

	Shape DebugDirectionDraw(float distance = 1)
	{
		return GetComponent(COMP_TYPE_ETITY_DEBUG).DebugDirectionDraw(distance);
	}

	void DebugDirectionSetColor(int color)
	{
		GetComponent(COMP_TYPE_ETITY_DEBUG).DebugDirectionSetColor(color);
	}

	void DebugDirectionDelete()
	{
		GetComponent(COMP_TYPE_ETITY_DEBUG).DebugDirectionDelete();
	}

	//! Hides selection of the given name. Must be configed in config.cpp and models.cfg
	void HideSelection( string selection_name )
	{
		if ( !ToDelete() )
		{
			SetAnimationPhase ( selection_name, 1 ); // 1 = hide, 0 = unhide!
		}
	}

	//! Shows selection of the given name. Must be configed in config.hpp and models.cfg
	void ShowSelection( string selection_name )
	{
		if ( !ToDelete() )
		{
			SetAnimationPhase ( selection_name, 0 ); // 1 = hide, 0 = unhide!
		}
	}

	//! Returns blocks of bits of persistence id of this entity.
	//! This id stays the same even after server restart.
	proto void GetPersistentID( out int b1, out int b2, out int b3, out int b4 );

	//! Set (override) remaining economy lifetime (seconds)
	proto native void SetLifetime( float fLifeTime );
	//! Get remaining economy lifetime (seconds)
	proto native float GetLifetime();
	//! Reset economy lifetime to default (seconds)
	proto native void IncreaseLifetime();

	//! Set (override) max economy lifetime per entity instance (seconds)
	proto native void SetLifetimeMax( float fLifeTime );
	//! Get max economy lifetime per instance - default is from DB (seconds)
	proto native float GetLifetimeMax();

	//! Reset economy lifetime to default across entity hierarchy all the way to the topmost entity
	void IncreaseLifetimeUp()
	{
		IncreaseLifetime();
		if (GetHierarchyParent())
			GetHierarchyParent().IncreaseLifetimeUp();
	}	


	// BODY STAGING
	//! Use this to access Body Staging component on dead character. Returns NULL if the given object lacks such component.
	ComponentBodyStaging GetCompBS()
	{
		if ( HasComponent(COMP_TYPE_BODY_STAGING) )
			return ComponentBodyStaging.Cast( GetComponent(COMP_TYPE_BODY_STAGING) );
		return NULL;
	}

	///@{ energy manager
	//! ENERGY MANAGER:Documentation: Confluence >> Camping & Squatting >> Electricity >> Energy Manager functionalities
	//! Use this to access Energy Manager component on your device. Returns NULL if the given object lacks such component.
	ComponentEnergyManager GetCompEM()
	{
		if (m_EM)
			return m_EM;
		
		if ( HasComponent(COMP_TYPE_ENERGY_MANAGER) )
			return ComponentEnergyManager.Cast( GetComponent(COMP_TYPE_ENERGY_MANAGER) );
		return NULL;
	}

	//! If this item has class EnergyManager in its config then it returns true. Otherwise returns false.
	bool HasEnergyManager()
	{
		return HasComponent(COMP_TYPE_ENERGY_MANAGER);
	}

	// ------ Public Events for Energy manager component. Overwrite these and put your own functionality into them. ------

	//! Energy manager event: Called only once when this device starts doing its work
	void OnWorkStart() {}

	//! Energy manager event: Called every device update if its supposed to do some work. The update can be every second or at random, depending on its manipulation.
	void OnWork( float consumed_energy ) {}

	//! Energy manager event: Called when the device stops working (was switched OFF or ran out of energy)
	void OnWorkStop() {}

	//! Energy manager event: Called when the device is switched on
	void OnSwitchOn() {}

	//! Energy manager event: Called when the device is switched OFF
	void OnSwitchOff() {}

	//! Energy manager event: Called when this device is plugged into some energy source
	void OnIsPlugged(EntityAI source_device) {}

	//! Energy manager event: Called when this device is UNPLUGGED from the energy source
	void OnIsUnplugged( EntityAI last_energy_source ) {}

	//! Energy manager event: When something is plugged into this device
	void OnOwnSocketTaken( EntityAI device ) {}

	//! Energy manager event: When something is UNPLUGGED from this device
	void OnOwnSocketReleased( EntityAI device ) {}

	//! Energy manager event: Object's initialization. Energy Manager is fully initialized by this point.
	void OnInitEnergy() {}

	//! Energy manager event: Called when energy was consumed on this device. ALWAYS CALL super.OnEnergyConsumed() !!!
	void OnEnergyConsumed() {}

	//! Energy manager event: Called when energy was added on this device. ALWAYS CALL super.OnEnergyAdded() !!!
	void OnEnergyAdded() {}
	///@} energy manager
	
	override void OnRPC(PlayerIdentity sender, int rpc_type, ParamsReadContext ctx)
	{
		super.OnRPC(sender, rpc_type, ctx);

		if ( GetGame().IsClient() )
		{
			switch (rpc_type)
			{
				// BODY STAGING - server => client synchronization of skinned state.
				case ERPCs.RPC_BS_SKINNED_STATE:
				{
					Param1<bool> p_skinned_state= new Param1<bool>(false);
					if (ctx.Read(p_skinned_state))
					{
						float state = p_skinned_state.param1;
						if (state && GetCompBS())
							GetCompBS().SetAsSkinnedClient();
					}
					break;
				}
				
				case ERPCs.RPC_EXPLODE_EVENT:
				{
					OnExplodeClient();					
					break;
				}
			}
		}
	}

	#ifdef DIAG_DEVELOPER
	void FixEntity()
	{
		if (!(GetGame().IsServer()))
			return;
		SetFullHealth();
		
		if (GetInventory())
		{
			int i = 0;
			int AttachmentsCount = GetInventory().AttachmentCount();
			if (AttachmentsCount > 0)
			{
				for (i = 0; i < AttachmentsCount; i++)
				{
					GetInventory().GetAttachmentFromIndex(i).FixEntity();
				}
			}
		
			CargoBase cargo = GetInventory().GetCargo();
			if (cargo)
			{
				int cargoCount = cargo.GetItemCount();
				for (i = 0; i < cargoCount; i++)
				{
					cargo.GetItem(i).FixEntity();
				}
			}
		}
	}
	#endif

	float GetWetWeightModifier()
	{
		return CfgGameplayHandler.GetWetnessWeightModifiers()[GetWetLevel()];
	}

	float GetConfigWeightModified()
	{
		return m_ConfigWeight * GetWetWeightModifier();	
	}

	#ifdef DEVELOPER
	string GetConfigWeightModifiedDebugText()
	{
		if (WeightDebug.m_VerbosityFlags & WeightDebugType.RECALC_FORCED)
		{
			return "(" + m_ConfigWeight + "(config weight) * " + GetWetWeightModifier() + "(Wetness Modifier))";
		}
		return string.Empty;
	}
	#endif
	

	//Obsolete, use GetWeightEx()
	int GetWeight()
	{
		return GetWeightEx();
	}

	void ClearWeightDirty()
	{
		//Print("ent:" + this + " - ClearWeightDirty");
		m_WeightDirty = 0;
	}

	void SetWeightDirty()
	{
		#ifdef DEVELOPER
		if (WeightDebug.m_VerbosityFlags & WeightDebugType.SET_DIRTY_FLAG)
		{
			Print("---------------------------------------");
			Print("ent:" + this + " - SetWeightDirty");
			if (WeightDebug.m_VerbosityFlags & WeightDebugType.DUMP_STACK)
			{
				DumpStack();
			}
			Print("---------------------------------------");
		}
		#endif
		m_WeightDirty = 1;
		if (GetHierarchyParent())
		{
			GetHierarchyParent().SetWeightDirty();
		}
	}
	// returns weight of all cargo and attachments
	float GetInventoryAndCargoWeight(bool forceRecalc = false)
	{
		float totalWeight;
		if (GetInventory())
		{
			int i = 0;
			int AttachmentsCount = GetInventory().AttachmentCount();
			if (AttachmentsCount > 0)
			{
				for (i = 0; i < AttachmentsCount; i++)
				{
					totalWeight += GetInventory().GetAttachmentFromIndex(i).GetWeightEx(forceRecalc);
				}
			}
		
			CargoBase cargo = GetInventory().GetCargo();
			if (cargo)
			{
				int cargoCount = cargo.GetItemCount();
				for (i = 0; i < cargoCount; i++)
				{
					totalWeight += cargo.GetItem(i).GetWeightEx(forceRecalc);
				}
			}
		}
		return totalWeight;	
	}
	//! returns weight of the entity in a way that's specific to the entity type and is internal to the weight system calculation, to obtain entity's weight, use the 'GetWeightEx' method instead
	protected float GetWeightSpecialized(bool forceRecalc = false)
	{
		return GetInventoryAndCargoWeight(forceRecalc);
	}

	//! returns overall weight of the entity, 'forceRecalc = true' is meant to be used only when debugging, using it in gameplay code is higly inadvisable as it bypasses the weight caching and has adverse effect on performance
	//this method is not meant to be overriden, to adjust weight calculation for specific item type, override 'GetWeightSpecialized(bool forceRecalc = false)' instead
	float GetWeightEx(bool forceRecalc = false)
	{
		if (m_WeightDirty || forceRecalc)//recalculate
		{
			m_WeightEx = GetWeightSpecialized(forceRecalc);
			ClearWeightDirty();
		
			#ifdef DEVELOPER
			if (WeightDebug.m_VerbosityFlags & WeightDebugType.RECALC_FORCED)
			{
				WeightDebug.GetWeightDebug(this).SetWeight(m_WeightEx);
			}
			if (WeightDebug.m_VerbosityFlags & WeightDebugType.RECALC_DIRTY)
			{
				Print("ent:" + this + " - Dirty Recalc");
				if (WeightDebug.m_VerbosityFlags & WeightDebugType.DUMP_STACK)
				{
					DumpStack();
				}
			}
			#endif
		}

		return m_WeightEx;
	}
	
	void UpdateWeight(WeightUpdateType updateType = WeightUpdateType.FULL, float weightAdjustment = 0);
	
	float GetSingleInventoryItemWeightEx(){}

	void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
	{
		//fix entity
		outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.FIX_ENTITY, "Fix Entity", FadeColors.LIGHT_GREY));
	
		//weight
		outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.GET_TOTAL_WEIGHT, "Print Weight", FadeColors.LIGHT_GREY));
		outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.GET_TOTAL_WEIGHT_RECALC, "Print Weight Verbose", FadeColors.LIGHT_GREY));
		outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.GET_PLAYER_WEIGHT, "Print Player Weight", FadeColors.LIGHT_GREY));
		outputList.Insert(new TSelectableActionInfoWithColor(SAT_DEBUG_ACTION, EActions.GET_PLAYER_WEIGHT_RECALC, "Print Player Weight Verbose", FadeColors.LIGHT_GREY));
	}
	bool OnAction(int action_id, Man player, ParamsReadContext ctx)
	{
		if (action_id == EActions.FIX_ENTITY)
		{
			#ifdef DIAG_DEVELOPER
			FixEntity();
			#endif
		}
		else if (action_id == EActions.GET_TOTAL_WEIGHT) //Prints total weight of item + its contents
		{
			WeightDebug.ClearWeightDebug();
			#ifndef SERVER
			Debug.Log("======================== "+  GetType() +" =================================");
			#endif
			Debug.Log("Weight:" + GetWeightEx().ToString());
			Debug.Log("Weight excluding cargo and attachments:" + GetSingleInventoryItemWeightEx());
			Debug.Log("----------------------------------------------------------------------------------------------");
		}
		else if (action_id == EActions.GET_TOTAL_WEIGHT_RECALC) //Prints total weight of item + its contents
		{
			WeightDebug.ClearWeightDebug();
			WeightDebug.SetVerbosityFlags(WeightDebugType.RECALC_FORCED);
			#ifndef SERVER
			Debug.Log("======================== "+  GetType() +" RECALC ===========================");
			#endif
			Debug.Log("Weight:" + GetWeightEx(true).ToString());
			Debug.Log("Weight excluding cargo and attachments:" + GetSingleInventoryItemWeightEx());
			WeightDebug.PrintAll(this);
			Debug.Log("----------------------------------------------------------------------------------------------");
			WeightDebug.SetVerbosityFlags(0);
		}
		else if (action_id == EActions.GET_PLAYER_WEIGHT) //Prints total weight of item + its contents
		{
			WeightDebug.ClearWeightDebug();
			#ifndef SERVER
			Debug.Log("======================== PLAYER: "+player+" ===========================");
			#endif
			Debug.Log("New overall weight Player:"+player.GetWeightEx().ToString());

			Debug.Log("----------------------------------------------------------------------------------------------");
		}
		else if (action_id == EActions.GET_PLAYER_WEIGHT_RECALC) //Prints total weight of item + its contents
		{
			WeightDebug.ClearWeightDebug();
			WeightDebug.SetVerbosityFlags(WeightDebugType.RECALC_FORCED);
			#ifndef SERVER
			Debug.Log("======================== PLAYER RECALC: "+player+" ===========================");
			#endif
			Debug.Log("New overall weight Player:"+player.GetWeightEx(true).ToString());
			WeightDebug.PrintAll(player);
			Debug.Log("----------------------------------------------------------------------------------------------");
			WeightDebug.SetVerbosityFlags(0);
		}
		return false;
	}

	///@{ view index
	//! Item view index is used to setup which camera will be used in item view widget in inventory.
	//! With this index you can setup various camera angles for different item states (e.g. fireplace, weapons).
	int m_ViewIndex = 0;
	
	//! Sets item preview index
	void SetViewIndex( int index )
	{
		m_ViewIndex = index;
		
		if( GetGame().IsServer() ) 
		{
			SetSynchDirty();
		}
	}
	
	//! Returns item preview index !!!! IF OVERRIDING with more dynamic events call GetOnViewIndexChanged() in constructor on client !!!!
	int GetViewIndex()
	{
		if ( MemoryPointExists( "invView2" ) )
		{
			#ifdef PLATFORM_WINDOWS
			InventoryLocation il = new InventoryLocation();
			GetInventory().GetCurrentInventoryLocation( il );
			InventoryLocationType type = il.GetType();
			switch ( type )
			{
				case InventoryLocationType.CARGO:
				{
					return 0;
				}
				case InventoryLocationType.ATTACHMENT:
				{
					return 1;
				}
				case InventoryLocationType.HANDS:
				{
					return 0;
				}
				case InventoryLocationType.GROUND:
				{
					return 1;
				}
				case InventoryLocationType.PROXYCARGO:
				{
					return 0;
				}
				default:
				{
					return 0;
				}
			}			
			#endif
			
			#ifdef PLATFORM_CONSOLE
			return 1;
			#endif
		}
		return 0;
	}
	///@} view index
	
	//! Returns hit component for the Entity (overriden for each Type - PlayerBase, DayZInfected, DayZAnimal, etc.)
	string GetHitComponentForAI()
	{
		Debug.LogError("EntityAI: HitComponentForAI not set properly for that entity (" + GetType() + ")");
		//! returns Global so it is obvious you need to configure that properly on entity
		return "";
	}

	//! returns default hit component for the Entity (overriden for each Type - PlayerBase, DayZInfected, DayZAnimal, etc.)
	string GetDefaultHitComponent()
	{
		Debug.LogError("EntityAI: DefaultHitComponent not set properly for that entity (" + GetType() + ")");
		//! returns Global so it is obvious you need to configure that properly on entity
		return "";
	}
	
	//! returns default hit position component name for the Entity (overriden by type if needed - used mainly as support for impact particles)
	string GetDefaultHitPositionComponent()
	{
		Debug.LogError("EntityAI: DefaultHitPositionComponent not set for that entity (" + GetType() + ")");
		return "";
	}
	
	array<string> GetSuitableFinisherHitComponents()
	{
		Debug.LogError("EntityAI: SuitableFinisherHitComponents not set for that entity (" + GetType() + ")");
		return null;
	}
	
	vector GetDefaultHitPosition()
	{
		Debug.LogError("EntityAI: DefaultHitPosition not set for that entity (" + GetType() + ")");
		return vector.Zero;
	}
	
	//! value is related to EMeleeTargetType
	int GetMeleeTargetType()
	{
		return EMeleeTargetType.ALIGNABLE;
	}
	
	//! returns sound type of attachment (used for clothing and weapons on DayZPlayerImplement, paired with Anim*Type enum from DayZAnimEvents)
	string GetAttachmentSoundType()
	{
		return "None";
	}
	
	//! returns item behaviour of item (more in ItemBase)
	bool IsHeavyBehaviour()
	{
		return false;
	}
	
	//! returns item behaviour of item (more in ItemBase)
	bool IsOneHandedBehaviour()
	{
		return false;
	}
	
	//! returns item behaviour of item (more in ItemBase)
	bool IsTwoHandedBehaviour()
	{
		return false;
	}
	
	string ChangeIntoOnAttach(string slot) {}
	string ChangeIntoOnDetach() {}
	
	/**
	\brief Central economy calls this function whenever going over all the entities 
	@code
	void OnCEUpdate()
	{
		// dont forget to propagate this call trough class hierarchy! - always at the start of the function
		super.OnCEUpdate();
	
		// use m_ElapsedSinceLastUpdate for time-related purposes
	}
	@endcode
	*/
	void OnCEUpdate()
	{
		float currentTime = GetGame().GetTickTime();
		if (m_LastUpdatedTime == 0)
			m_LastUpdatedTime = currentTime;
		
		m_ElapsedSinceLastUpdate = currentTime - m_LastUpdatedTime; 
		m_LastUpdatedTime = currentTime;
	}

	void OnDebugSpawnEx(DebugSpawnParams params)
	{
		OnDebugSpawn();
	}
	
	void OnDebugSpawn() 
	{
		array<string> slots = new array<string>;
		ConfigGetTextArray("Attachments", slots);
		
		array<string> mags = new array<string>;
		ConfigGetTextArray("magazines", mags);
		
		//-------
		
		TStringArray all_paths = new TStringArray;
		
		all_paths.Insert(CFG_VEHICLESPATH);
		all_paths.Insert(CFG_MAGAZINESPATH);
		all_paths.Insert(CFG_WEAPONSPATH);
		
		string config_path;
		string child_name;
		int scope;
		string path;
		int consumable_count;
		
		for (int i = 0; i < all_paths.Count(); i++)
		{
			config_path = all_paths.Get(i);
			int children_count = GetGame().ConfigGetChildrenCount(config_path);
			
			for (int x = 0; x < children_count; x++)
			{
				GetGame().ConfigGetChildName(config_path, x, child_name);
				path = config_path + " " + child_name;
				scope = GetGame().ConfigGetInt( config_path + " " + child_name + " scope" );
				bool should_check = 1;
				if ( config_path == "CfgVehicles" && scope == 0)
				{
					should_check = 0;
				}
				
				if ( should_check )
				{
					string inv_slot;
					GetGame().ConfigGetText( config_path + " " + child_name + " inventorySlot",inv_slot );
					for (int z = 0; z < slots.Count(); z++)
					{
						if (slots.Get(z) == inv_slot)
						{
							this.GetInventory().CreateInInventory( child_name );
							continue;
							//Print("matching attachment: " + child_name + " for inv. slot name:" +inv_slot);
						}
					}
				}
			}
		}
	};
	
	override EntityAI ProcessMeleeItemDamage(int mode = 0)
	{
		if (GetGame().IsServer())
			AddHealth("","Health",-MELEE_ITEM_DAMAGE);
		return this;
	}

	//! Returns liquid throughput coeficient
	float GetLiquidThroughputCoef()
	{
		return LIQUID_THROUGHPUT_DEFAULT;
	}
	
	string GetInvulnerabilityTypeString()
	{
		return "";
	}
	
	void ProcessInvulnerabilityCheck(string servercfg_param)
	{
		if ( GetGame() && GetGame().IsMultiplayer() && GetGame().IsServer() )
		{
			int invulnerability;
			switch (servercfg_param)
			{
				case "disableContainerDamage":
					invulnerability = CfgGameplayHandler.GetDisableContainerDamage();
				break;
				
				case "disableBaseDamage":
					invulnerability = CfgGameplayHandler.GetDisableBaseDamage();
				break;
			}
				
			if (invulnerability > 0)
			{
				SetAllowDamage(false);
			}
		}
	}

	void SetBayonetAttached(bool pState, int slot_idx = -1) {};
	bool HasBayonetAttached() {};
	int GetBayonetAttachmentIdx() {};
	
	void SetButtstockAttached(bool pState, int slot_idx = -1) {};
	bool HasButtstockAttached() {};
	int GetButtstockAttachmentIdx() {};
	
	void SetInvisibleRecursive(bool invisible, EntityAI parent = null, array<int> attachments = null)
	{
		array<int> childrenAtt = new array<int>;
		array<int> attachmentsArray = new array<int>;
		if (attachments)
			attachmentsArray.Copy(attachments);
		else
		{
			for (int i = 0; i < GetInventory().GetAttachmentSlotsCount(); i++)
			{
				attachmentsArray.Insert(GetInventory().GetAttachmentSlotId(i));
			}
		}
		
		EntityAI item;
		
		foreach( int slot : attachmentsArray )
		{
			if( parent )
				item = parent.GetInventory().FindAttachment(slot);
			else
				item = this;//GetInventory().FindAttachment(slot);
			
			if( item )
			{
				if( item.GetInventory().AttachmentCount() > 0 )
				{
					for(i = 0; i < item.GetInventory().GetAttachmentSlotsCount(); i++)
					{
						childrenAtt.Insert(item.GetInventory().GetAttachmentSlotId(i));
					}
					
					SetInvisibleRecursive(invisible,item,childrenAtt);
				}
				
				item.SetInvisible(invisible);
				item.OnInvisibleSet(invisible);
			}
		}
	}
	
	void SoundHardTreeFallingPlay()
	{
		EffectSound sound =	SEffectManager.PlaySound( "hardTreeFall_SoundSet", GetPosition() );
		sound.SetAutodestroy( true );
	}
		
	void SoundSoftTreeFallingPlay()
	{
		EffectSound sound =	SEffectManager.PlaySound( "softTreeFall_SoundSet", GetPosition() );
		sound.SetAutodestroy( true );
	}
		
	void SoundHardBushFallingPlay()
	{
		EffectSound sound =	SEffectManager.PlaySound( "hardBushFall_SoundSet", GetPosition() );
		sound.SetAutodestroy( true );
	}
		
	void SoundSoftBushFallingPlay()
	{
		EffectSound sound =	SEffectManager.PlaySound( "softBushFall_SoundSet", GetPosition() );
		sound.SetAutodestroy( true );
	}
	
	void RegisterTransportHit(Transport transport)
	{
		if (!m_TransportHitRegistered)
		{	
			m_TransportHitRegistered = true; 
			m_TransportHitVelocity = GetVelocity(transport);
			Car car;
			float damage;
			vector impulse;
			
			// a different attempt to solve hits from "standing" car to the players
			if (Car.CastTo(car, transport))
			{
				if (car.GetSpeedometerAbsolute() > 2 )
				{
					damage = m_TransportHitVelocity.Length();
					ProcessDirectDamage(DT_CUSTOM, transport, "", "TransportHit", "0 0 0", damage);
				}
				else
				{
					m_TransportHitRegistered = false;
				}

				// compute impulse and apply only if the body dies
				if (IsDamageDestroyed() && car.GetSpeedometerAbsolute() > 3)
				{
					impulse = 40 * m_TransportHitVelocity;
					impulse[1] = 40 * 1.5;
					dBodyApplyImpulse(this, impulse);
				}
			}			
			else //old solution just in case if somebody use it
			{
				// avoid damage because of small movements
				if (m_TransportHitVelocity.Length() > 0.1)
				{
					damage = m_TransportHitVelocity.Length();
					ProcessDirectDamage(DT_CUSTOM, transport, "", "TransportHit", "0 0 0", damage);
				}
				else
				{
					m_TransportHitRegistered = false;
				}
				
				// compute impulse and apply only if the body dies
				if (IsDamageDestroyed() && m_TransportHitVelocity.Length() > 0.3)
				{
					impulse = 40 * m_TransportHitVelocity;
					impulse[1] = 40 * 1.5;
					dBodyApplyImpulse(this, impulse);
				}
			}
		}
	}
	
	bool GetInventoryHandAnimation(notnull InventoryLocation loc, out int value)
	{
		value = -1;
		return false;
	}
	
	bool TranslateSlotFromSelection(string selection_name, out int slot_id)
	{
		return false;
	}
	
	//! Universal Temperature Sources Helpers
	bool IsUniversalTemperatureSource()
	{
		return GetUniversalTemperatureSource() != null && GetUniversalTemperatureSource().IsActive();
	}
	
	UTemperatureSource GetUniversalTemperatureSource()
	{
		return m_UniversalTemperatureSource;
	}
	
	void SetUniversalTemperatureSource(UTemperatureSource uts)
	{
		m_UniversalTemperatureSource = uts;
	}
	
	vector GetUniversalTemperatureSourcePosition()
	{
		return GetPosition();
	}

	//! Remotely controlled devices helpers
	RemotelyActivatedItemBehaviour GetRemotelyActivatedItemBehaviour();

	void PairRemote(notnull EntityAI trigger);

	void UnpairRemote();

	EntityAI GetPairDevice();

	void SetPersistentPairID(int id)
	{
		RemotelyActivatedItemBehaviour raib = GetRemotelyActivatedItemBehaviour();
		if (raib)
		{
			raib.SetPersistentPairID(id);
		}
	}

	//! Turnable Valve behaviour
	bool HasTurnableValveBehavior();
	bool IsValveTurnable(int pValveIndex);
	int GetTurnableValveIndex(int pComponentIndex);
	void ExecuteActionsConnectedToValve(int pValveIndex);

//////////////////////////////////
// attachment exclusion section //
//////////////////////////////////
	private void InitAttachmentExclusionValues()
	{
		m_AttachmentExclusionSlotMap = new map<int,ref set<int>>();
		m_AttachmentExclusionMaskGlobal = new set<int>;
		m_AttachmentExclusionMaskChildren = new set<int>();
	
		int count = GetInventory().GetSlotIdCount();
		//no sense in performing inits for something that cannot be attached anywhere (hand/lefthand and some other 'special' slots are the reason for creating 'new' sets above)
		if (count == 0)
			return;
		
		InitInherentSlotExclusionMap();
		InitGlobalExclusionValues();
		InitLegacyConfigExclusionValues();
	}
	
	//! map stored on instance to better respond to various state changes
	private void InitInherentSlotExclusionMap()
	{
		int count = GetInventory().GetSlotIdCount();
		//starting with the INVALID slot, so it is always in the map of attachable items
		SetAttachmentExclusionMaskSlot(InventorySlots.INVALID,GetAttachmentExclusionInitSlotValue(InventorySlots.INVALID));
		
		int slotId;
		for (int i = 0; i < count; i++) 
		{
			slotId = GetInventory().GetSlotId(i);
			SetAttachmentExclusionMaskSlot(slotId,GetAttachmentExclusionInitSlotValue(slotId));
		}
	}
	
	//! override this to modify slot behavior for specific items, or just set 'm_AttachmentExclusionMaskGlobal' value for simple items
	protected set<int> GetAttachmentExclusionInitSlotValue(int slotId)
	{
		set<int> dflt = new set<int>;
		return dflt;
	}
	
	//Initiated last, and only for items that do not have others defined already
	protected void InitLegacyConfigExclusionValues()
	{
		bool performLegacyInit = InitLegacyExclusionCheck();
		
		//adding implicit slot info AFTER the check is performed
		InitLegacySlotExclusionValuesImplicit();
		
		if (performLegacyInit)
			InitLegacySlotExclusionValuesDerived();
	}

	//returns 'false' if the script initialization 
	protected bool InitLegacyExclusionCheck()
	{
		//first check the globals
		if (m_AttachmentExclusionMaskGlobal.Count() > 0)
			return false;
		
		//now the map
		int count = m_AttachmentExclusionSlotMap.Count();
		if (count > 1) //more than InventorySlots.INVALID
		{
			for (int i = 0; i < count; i++)
			{
				int countSet = m_AttachmentExclusionSlotMap.GetElement(i).Count();
				if (countSet > 0) //SOMETHING is defined
				{
					return false;
				}
			}
		}
		
		return true;
	}

	/**@fn		InitLegacySlotExclusionValuesImplicit
	 * @brief	adding base one-directional relations between headgear, masks, eyewear, and headstraps (exception)
	 *
	 * @note: 'InitLegacyConfigExclusionValues' adds them the other way if the item does not have any script-side exclusions AND has some legacy config parameter.
	**/
	protected void InitLegacySlotExclusionValuesImplicit()
	{
		int slotId;
		int slotCount = GetInventory().GetSlotIdCount();
		for (int i = 0; i < slotCount; i++) 
		{
			slotId = GetInventory().GetSlotId(i);
			set<int> tmp;
			switch (slotId)
			{
				case InventorySlots.HEADGEAR:
				{
					tmp = new set<int>;
					tmp.Copy(GetAttachmentExclusionInitSlotValue(slotId));
					tmp.Insert(EAttExclusions.LEGACY_HEADGEAR_MASK);
					tmp.Insert(EAttExclusions.LEGACY_HEADGEAR_HEADSTRAP);
					tmp.Insert(EAttExclusions.LEGACY_HEADGEAR_EYEWEWEAR);
					SetAttachmentExclusionMaskSlot(slotId,tmp);
					break;
				}
				
				case InventorySlots.MASK:
				{
					tmp = new set<int>;
					tmp.Copy(GetAttachmentExclusionInitSlotValue(slotId));
					tmp.Insert(EAttExclusions.LEGACY_MASK_HEADGEAR);
					tmp.Insert(EAttExclusions.LEGACY_MASK_HEADSTRAP);
					tmp.Insert(EAttExclusions.LEGACY_MASK_EYEWEWEAR);
					SetAttachmentExclusionMaskSlot(slotId,tmp);
					break;
				}
				
				case InventorySlots.EYEWEAR:
				{
					tmp = new set<int>;
					tmp.Copy(GetAttachmentExclusionInitSlotValue(slotId));
					if (ConfigGetBool("isStrap"))
					{
						tmp.Insert(EAttExclusions.LEGACY_HEADSTRAP_HEADGEAR);
						tmp.Insert(EAttExclusions.LEGACY_HEADSTRAP_MASK);
					}
					else
					{
						tmp.Insert(EAttExclusions.LEGACY_EYEWEAR_HEADGEAR);
						tmp.Insert(EAttExclusions.LEGACY_EYEWEAR_MASK);
					}
					SetAttachmentExclusionMaskSlot(slotId,tmp);
					break;
				}
			}
		}
	}
	
	protected void InitLegacySlotExclusionValuesDerived()
	{
		int slotId;
		int slotCount = GetInventory().GetSlotIdCount();
		for (int i = 0; i < slotCount; i++) 
		{
			slotId = GetInventory().GetSlotId(i);
			set<int> tmp;
			switch (slotId)
			{
				case InventorySlots.HEADGEAR:
				{
					tmp = new set<int>;
					tmp.Copy(GetAttachmentExclusionMaskSlot(slotId));
					if (ConfigGetBool("noNVStrap"))
					{
						tmp.Insert(EAttExclusions.LEGACY_HEADSTRAP_HEADGEAR);
					}
					if (ConfigGetBool("noMask"))
					{
						tmp.Insert(EAttExclusions.LEGACY_MASK_HEADGEAR);
					}
					if (ConfigGetBool("noEyewear"))
					{
						tmp.Insert(EAttExclusions.LEGACY_EYEWEAR_HEADGEAR);
					}
					SetAttachmentExclusionMaskSlot(slotId,tmp);
					break;
				}
				
				case InventorySlots.MASK:
				{
					tmp = new set<int>;
					tmp.Copy(GetAttachmentExclusionMaskSlot(slotId));
					if (ConfigGetBool("noNVStrap"))
					{
						tmp.Insert(EAttExclusions.LEGACY_HEADSTRAP_MASK);
					}
					if (ConfigGetBool("noHelmet"))
					{
						tmp.Insert(EAttExclusions.LEGACY_HEADGEAR_MASK);
					}
					if (ConfigGetBool("noEyewear"))
					{
						tmp.Insert(EAttExclusions.LEGACY_EYEWEAR_MASK);
					}
					SetAttachmentExclusionMaskSlot(slotId,tmp);
					break;
				}
				
				case InventorySlots.EYEWEAR:
				{
					tmp = new set<int>;
					tmp.Copy(GetAttachmentExclusionMaskSlot(slotId));
					if (ConfigGetBool("isStrap"))
					{
						if (ConfigGetBool("noHelmet"))
						{
							tmp.Insert(EAttExclusions.LEGACY_HEADGEAR_HEADSTRAP);
						}
						if (ConfigGetBool("noMask"))
						{
							tmp.Insert(EAttExclusions.LEGACY_MASK_HEADSTRAP);
						}
					}
					else
					{
						if (ConfigGetBool("noHelmet"))
						{
							tmp.Insert(EAttExclusions.LEGACY_HEADGEAR_EYEWEWEAR);
						}
						if (ConfigGetBool("noMask"))
						{
							tmp.Insert(EAttExclusions.LEGACY_MASK_EYEWEWEAR);
						}
					}
					SetAttachmentExclusionMaskSlot(slotId,tmp);
					break;
				}
			}
		}
	}

	//! override to init part of the mask, independent of slot-specific behavior
	protected void InitGlobalExclusionValues();
	
	//! to help with item staging exclusions
	protected void AddSingleExclusionValueGlobal(EAttExclusions value)
	{
		if (m_AttachmentExclusionMaskGlobal.Find(value) == -1)
			m_AttachmentExclusionMaskGlobal.Insert(value);
	}
	
	//! to help with item staging exclusions
	protected void ClearSingleExclusionValueGlobal(EAttExclusions value)
	{
		int idx = m_AttachmentExclusionMaskGlobal.Find(value);
		if (idx != -1)
			m_AttachmentExclusionMaskGlobal.Remove(idx);
	}
	
	protected void SetAttachmentExclusionMaskGlobal(set<int> values)
	{
		m_AttachmentExclusionMaskGlobal.Clear();
		m_AttachmentExclusionMaskGlobal.Copy(values);
	}
	
	//! sets values for specific slot
	protected void SetAttachmentExclusionMaskSlot(int slotId, set<int> values)
	{
		if (m_AttachmentExclusionSlotMap)
		{
			m_AttachmentExclusionSlotMap.Set(slotId,values);
		}
		else
			ErrorEx("m_AttachmentExclusionSlotMap not available! Fill the 'inventorySlot[]' in the " + this + " config file.");
	}
	
	private void PropagateExclusionValueRecursive(set<int> values, int slotId)
	{
		if (values && values.Count() != 0)
		{
			set<int> passThis;
			InventoryLocation lcn = new InventoryLocation();
			GetInventory().GetCurrentInventoryLocation(lcn);
			if (CheckExclusionAccessPropagation(lcn.GetSlot(), slotId, values, passThis))
			{
				m_AttachmentExclusionMaskChildren.InsertSet(passThis);
				EntityAI parent = GetHierarchyParent();
				if (parent)
					parent.PropagateExclusionValueRecursive(passThis,lcn.GetSlot());
			}
		}
	}
	
	private void ClearExclusionValueRecursive(set<int> values, int slotId)
	{
		if (values && values.Count() != 0)
		{
			set<int> passThis;
			InventoryLocation lcn = new InventoryLocation();
			GetInventory().GetCurrentInventoryLocation(lcn);
			if (CheckExclusionAccessPropagation(lcn.GetSlot(), slotId, values, passThis))
			{
				int count = passThis.Count();
				for (int i = 0; i < count; i++)
				{
					m_AttachmentExclusionMaskChildren.RemoveItem(passThis[i]);
				}
				EntityAI parent = GetHierarchyParent();
				if (parent)
					parent.ClearExclusionValueRecursive(passThis,lcn.GetSlot());
			}
		}
	}
	
	//! Slot-specific, children (attachments), and additional (state etc.) masks combined
	set<int> GetAttachmentExclusionMaskAll(int slotId)
	{
		set<int> values = new set<int>();
		set<int> slotValues = GetAttachmentExclusionMaskSlot(slotId);
		if (slotValues)
			values.InsertSet(slotValues);
		values.InsertSet(m_AttachmentExclusionMaskGlobal);
		values.InsertSet(m_AttachmentExclusionMaskChildren);
		
		return values;
	}
	
	//! Specific slot behavior
	set<int> GetAttachmentExclusionMaskSlot(int slotId)
	{
		return m_AttachmentExclusionSlotMap.Get(slotId);
	}
	
	//! Global mask value, independent of slot-specific behavior!
	set<int> GetAttachmentExclusionMaskGlobal()
	{
		return m_AttachmentExclusionMaskGlobal;
	}
	
	//! Mask value coming from the item's attachments
	set<int> GetAttachmentExclusionMaskChildren()
	{
		return m_AttachmentExclusionMaskChildren;
	}
	
	//! checks if any attachment or item state would interfere with this being attached into a different slot (Headgear -> Mask)
	private bool HasInternalExclusionConflicts(int targetSlot)
	{
		set<int> targetSlotValues = GetAttachmentExclusionMaskSlot(targetSlot);
		if (targetSlotValues) //can be null, if so, no conflict
		{
			set<int> additionalValues = new set<int>(); //NOT slot values
			additionalValues.InsertSet(GetAttachmentExclusionMaskGlobal());
			additionalValues.InsertSet(GetAttachmentExclusionMaskChildren());
			
			int countTarget = targetSlotValues.Count();
			for (int i = 0; i < countTarget; i++)
			{
				if (additionalValues.Find(targetSlotValues[i]) != -1)
				{
					return true;
				}
			}
		}
		return false;
	}
	
	//! checks 'this' if the incoming flag is present for the current state (slot behavior and others)
	protected bool IsExclusionFlagPresent(set<int> values)
	{
		int slotId;
		string slotName;
		GetInventory().GetCurrentAttachmentSlotInfo(slotId,slotName); //if currently attached, treat it accordingly
		
		set<int> currentSlotValuesAll = GetAttachmentExclusionMaskAll(slotId);
		int count = values.Count();
		for (int i = 0; i < count; i++)
		{
			if (currentSlotValuesAll.Find(values[i]) != -1)
				return true;
		}
		return false;
	}
	
	//! Gets flag from what is effectively an owner
	protected bool IsExclusionFlagPresentRecursive(set<int> values, int targetSlot)
	{
		if (values && values.Count() != 0)
		{
			InventoryLocation lcn = new InventoryLocation();
			GetInventory().GetCurrentInventoryLocation(lcn);
			EntityAI parent = GetHierarchyParent();
			set<int> passThis;
			if (CheckExclusionAccessCondition(lcn.GetSlot(),targetSlot, values, passThis))
			{
				if (parent && parent != this) //we reached root if false
				{
					return parent.IsExclusionFlagPresentRecursive(passThis,lcn.GetSlot());
				}
			}
			return IsExclusionFlagPresent(passThis);
		}
		
		return false;
	}
	
	//!
	protected bool CheckExclusionAccessCondition(int occupiedSlot, int targetSlot, set<int> value, inout set<int> adjustedValue)
	{
		bool occupiedException = occupiedSlot == InventorySlots.HANDS || occupiedSlot == InventorySlots.SHOULDER || occupiedSlot == InventorySlots.MELEE || occupiedSlot == InventorySlots.LEFTHAND;
		bool targetException = targetSlot == InventorySlots.HANDS || targetSlot == InventorySlots.SHOULDER || targetSlot == InventorySlots.MELEE || targetSlot == InventorySlots.LEFTHAND;
		
		if (occupiedException)
		{
			adjustedValue = value;
			return false;
		}
		
		if (targetException)
		{
			adjustedValue = null;
			return false;
		}
		
		AdjustExclusionAccessCondition(occupiedSlot,targetSlot,value,adjustedValue);
		return adjustedValue.Count() != 0;
	}
	
	//!if we want to filter 
	protected void AdjustExclusionAccessCondition(int occupiedSlot, int testedSlot, set<int> value, inout set<int> adjustedValue)
	{
		adjustedValue = value;
	}

	//! special propagation contition
	protected bool CheckExclusionAccessPropagation(int occupiedSlot, int targetSlot, set<int> value, inout set<int> adjustedValue)
	{
		bool occupiedException = occupiedSlot == InventorySlots.HANDS || occupiedSlot == InventorySlots.SHOULDER || occupiedSlot == InventorySlots.MELEE || occupiedSlot == InventorySlots.LEFTHAND;
		bool targetException = targetSlot == InventorySlots.HANDS || targetSlot == InventorySlots.SHOULDER || targetSlot == InventorySlots.MELEE || targetSlot == InventorySlots.LEFTHAND || targetSlot == InventorySlots.INVALID;
		
		if (targetException)
		{
			adjustedValue = null;
			return false;
		}
		
		AdjustExclusionAccessPropagation(occupiedSlot,targetSlot,value,adjustedValue);
		return adjustedValue.Count() != 0;
	}
	
	//!if we want to filter propagation specifically; DO NOT override unless you know what you are doing.
	protected void AdjustExclusionAccessPropagation(int occupiedSlot, int testedSlot, set<int> value, inout set<int> adjustedValue)
	{
		AdjustExclusionAccessCondition(occupiedSlot,testedSlot,value,adjustedValue);
	}

	bool IsManagingArrows()
	{
		return false;
	}

	ArrowManagerBase GetArrowManager()
	{
		return null;
	}

	void SetFromProjectile(ProjectileStoppedInfo info)
	{
	}

	void ClearInventory();
};

#ifdef DEVELOPER
void SetDebugDeveloper_item(Object entity)//without a setter,the place where the setting happens is near impossible to find as way too many hits for "_item" exist
{
	if (entity)
		entity.SetDebugItem();

}
Object _item;//watched item goes here(LCTRL+RMB->Watch)
#endif