summaryrefslogblamecommitdiff
path: root/src/map/status.c
blob: b6e604979c4aef741c92ebb90612a61a35c64334 (plain) (tree)
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
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
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



























































































































































































































































































































































































































































































































































































                                                                                                                      
                                                          






















































                                                                                                      
                                             


                                       
                                                                                                           




















                                                                                                                 
                                          
         
                              

                          
                            

                     



                                                                                                                               


                                  

                                                             










                                                                                                                                                                                          







                                                                                                                      


                                          
                                                              



                                                                                                        
                                                                                                           




                                                                                                        
                              
          
                                                                                                  

                                                                             
                                                                       
                                  
                                                                              




                                                                           

                                     
                 
                                                                              
                                  
                                                                                  
                                  
                                                                                                                                                           









                                                                                                  








                                                                                                                                                       
                                                                                  














                                                                                                                                          
                                            
                  
                                                                                                    











































































































































































































































































































































































































































































































                                                                                                                                                                                       


                                                                                                                                         


                                                                

                                                                



                                            

                                                                        





















                                                                                             

                                                          






                                                           

                                                                                                    


















                                                                                                                                    

                                                                                               





























                                                                   
                                                             







































                                                                                                                  

                                                          

                                                                                                           
                                                                                           

                                                                                                           
                                                                                          

































































































                                                                                                            
                                                              
                              
                                                                        


































                                                                                                     
                                                              




































                                                                                             
                                                                                                                                        










                                                                                                      
                                                               
                                                                                                                  
                                                                                                                
                                                                                  

                                                                             

                                                             
                                                                                                    























                                                                                                                                                                  
                                                                             












































































































                                                                                                                                        
                                               

















































                                                                                                                    


                                                                       


















                                                         










                                                                         
                  


                                                                           




                                                                                                               
                                                 
                                                                 
                                                 


















                                                                 
                                                                                 

                                            
                                                                           





































































                                                                                                                                                          

                                                                                                          











                                                                      
                                  
                             









                                                               
                                  
                                                     
                                  
                                                 
                                                                            
                                                       


                                                                                            
                                                                







                                                    
                                  
                             









                                                               
                                  





                                                                                  






                                                    
                                  
                             









                                                               
                                  

                                                                           






                                                     
                                  
                              









                                                                
                                   
                                                       


                                                                                            
                                                                 
                  

                                                                          






                                                    
                                  
                             









                                                               
                                  


                                                                                  


                                                                                            
                                                                







                                                    
                                  
                             









                                                               
                                  
                                                  







                                                      
                                  
                              













                                                                              
                                          
                                                                                       
                                               
                                                 
                                               
                                                      
                                               






                                                      
                                  
                              

















                                                                                  
                                          




                                                                                                             
                                               

                                                                            





                                                      
                                  
                              












                                                                             






                                                              
                                  
                                  









                                                                        







                                                    
                                  
                             















                                                                       







                                                      
                                  
                              















                                                                                      
                                                                                                  
                                                        
                                    
                                                     
                                               
                                                   
                                               
                                                 









                                                                                                                                             
                                  
                               
                                
 


                                                               






                                                    
                                  
                             
                                
 

                                                   
                                  
                                                   
                                    
                                                     
                                   
                                                                 
                                   








                                                                            
                                              



                                                                                                                 






                                                      
                                  
                              
                                
 

                                                   
                                  
                                                        
                                  
                                                       
                                                                                                 




                                                                              
                                               
                                               
                                               


                                                                            
                                   

                                                           
                                                       
                                                                








                                                       
                                  
                              
                                
 

                                                   
                                  
                                                   
                                    
                                                     
                                   
                                                                 
                                                             

                                                          






                                                        
                                  
                               
                                
 

                                                   
                                  

                                                                               






                                                        







































                                                                                                      
                                                         

                                                                   
                  






                                                                                                        





                                                                






                                                                                            
                                                 






























                                                                                                                                                                                 
                                                 

                                                                   
                  


                                                                                                       





                                                        












                                                                                     





                                                        








                                                                           
































                                                                                                                     
                                                                           

                                                                          
                                                                                                                  
                                                                                            



                                                                                                                                           






























































































































































































































































































































































































































































































































































































































































































































































                                                                                                                                                                          
                                  

                            
                                














                                                                               
                                                                                                                                         







                                                                                     
                                                     


                             

                                                                    
                                   
                                                                
                                   
                                                                                













                                                                                       


                                                                            
                                  
                                                                                
                                  
                                                                              
                                  
                                                                                
                                  
                                                                                
                                  
                                                                                
                                  
                                                         
                                  
                                                        






























































































                                                                                              
                                                                                                   






                                                                                     
                                                              





























































                                                                                                                                                         
                                                                         




                                  
                                                           


                               
                                                    
                            
                                                            

                     



                                                       
                                  












































                                                                                 








                                                                                    





                                                             
















                                                                                                              
                                  



                                                                                                      




                                      




                                                                                               





                                                    
                                                                                                       
                          
                                                                            























                                                                                            
         


                                                                                                           
                                                                                                             
















                                                                                                                                            
                                                  
                                                           
                                                                                



                                                                                                                      
                                                                            


                                                                                           

                                                                                      




                                                                          

                                                                                                                  







                                                                                                                             
                                                                                                                     

                                  


                                                                         






                                                                                                          
                                                                                        






















                                                                                               
                                                                                                          





                                                                                         
                                                                





                                                                          
                                                                
                                                                         
                                                               
                                                                        
                                                                
                                                                         
                                                                  
                                                                           
                                                                   
                                                                            
                                                              
                                                                       
                                                            









                                                                                                     
                                                               
                                                                         
                                                               
                                                                         
                                                               
                                                                         
                                                               

                                                                         
                                                               
                                          
                                       



                                                                                   
                                                               














                                                                              
                                       

                                                                              
                                                                 























                                                                                                
                                       










                                                                                                  
                                                              











                                                                              
                                                                                     
                                                                         
                                                                                   
                                                                         
                                                                   
                                                                            
                                                            
                                                                     
                                                                  
                                                                           
                                                               
                                                                        
                                                                
                                                                         
                                                                                    
                                                                       
                                                                                      
                                                                      
                                                                                   






















































                                                                             
                                                                                                









                                                                       
                                       



                                                                                                           
                                        
























                                                                                   
                                                                                   
                                                                         
                                                                   
                                                                            
                                                            
                                                                     
                                                                  
                                                                           
                                                               
                                                                        
                                                                
                                                                         
                                                             
                                                                      
                                                                                    
                                                                       
                                                                                      
                                                                      
                                                                                   

















                                                                                
                                       



                                                                
                                        






























































































































                                                                                                                      

                                                                                                     









                                                                            



                                                                       











































































































                                                                                                                              
                                       

































                                                                                                                           
                                         





                                                                     

                                                         







                                                                   
                                          























                                                                                             
                                          






































                                                                            
                                                                      


                                                                                                             





                                                                                                                   









                                                                         
                                                                









                                                                                            


                                                                                                            

                                                                                                              


                                                                                                                                                                  














































                                                                                                                       
                                                                                     






































































































































                                                                                                                                           



                                                                                                      



                                             
                                                           
                             
                                                                           





                                      
                                                         


                                                                      
                                                  


                                      
                                                       




                                                              
                                                                                    



                                                              
                                                                     


                                      
                                                    


                                      
                                                     


                                      
                                                      


                                      
                                                     


                                      
                                                           


                                      
                                                     






                                          
                                               
 



                                    
                          
                                          
























                                                                                            
                                  

               


                                                




                                                                                         
                                              




                                                                                          
                                                          
                                                                                                                         


                                                                              

                  



                                   













                                                                  
                                  
                                       

                            


                                
                                            
                                                                                                     






                                                                 
 
                                                                                        

                                                                                
                                                                                

                                           

                                         























































































































                                                                                                              

                                                                                             

                                                                                                
                                                                                                                                                   


                                               
                                                                                                        










                                                                                         
                                                                                                                                     





                                                                                     
                                                                                                      


                                                                                                                      
                                                                                       


                                                                                  
                                                                                
                                                                                       
                                                                               




                                                                                      
                                                                                                                             
                                                                                              

                                                                                                                             
 

                                                                                                                                                     




                                                                      

                                                                   
                                          

                                                                                                                    
                                          

                                                                                                                                            
                                                                                          
                                                                                     
                                                  
                                                                                                                                               


                                                                                               
                                                                                                                                      

                                                                                       
                                                                    













                                                                                                         
                                                                                               

                                                                                 
                                                                                                                                       




                                               



                                                                                                                                       
                                                                   
                                                                                                                                  





                                                                                                             
                                                                                                                               

                                                                                                
                                                                                                                                        



                                        
                                                         













                                                                                                              


                                                                                                      
                                                                                           






                                                                                                
                                                                                         







                                                                     
                                                                               







                                                                               
                                                                    
                                                       


                                                                                                                         




                                                                            
                                                                    


                                                                            
                                                                                                             











                                                                                             
                                      






                                      
                                                            


                                      
                                                                     


                                      
                                                        



                                      
                                                    


                                       
                                                     



                                               
                                                                        


                                       
                                                     


                                                                                 
                                                       


                                      
                                                      


                                      
                                                      


                                      
                                                            


                                      
                                                      






                                                                          
                                        

                                                                             
                                        

                                                                           
                                        

                                                            
                                        


                                                                
                                         

                                                               
                                         

                                                               
                                          


                                                                              
                                           

                                                                     
                                           

                                                    
                                           






















                                                                                                      
                                  







                                                       
                                              

                            
                                                  
 
                                          
                                            
                                                                                              




                                                                 

                                             










                                                             

                                                                                              





                                  
                                                                   



                                                                                



                                                                                                                                                          
                                  

                                                                                                      






                                                                    

                                                                                        


                                                                     
                                                                                    










                                                                        
                                                                                                                                                    

                                                                                                  
                                                  
 

                                                                                    










                                                                                              
                                                                                                                  





                                            
                                                
                                                                    


                                                                                                                                                          




                                                               
                                                                                            

                                                                                   
                                                                                                       



                                  

                                                              
                                                                                                          




                                  


                                                 
                                                  


                                                                                                      

                                  
                                                        
                                                        
                                                                                          










                                                                                 
                                                                                                      







                                                                                                      
                                                                                          
                                 
                                                                      
                                                         
                                                                                   


                                                                  
                                                                                   
                  
                                                                   
                  
                                                                                                            






                                                                                       
                                                                                    
















                                                                               
                                                           










                                                                             
                                                                                                                    





















                                                       

                                                                                                   





                                                    

                                                                



























                                                                                                                           
                                                                                                              




                                                                                                         

                                                                              







                                                                     
                                                                                    









                                                                                                                                                                   

                                                                                                                         
                          
                                                                                                                









                                                                                                                  
                                                                                            













                                                                                                     
                                                                                                               





                                          
                                                       
                                       
                                                                         

                                                 

                                                          








                                                                      
                                                                                 
                                                                     

                                                                   







                                                                          
                                                     
                                    

                                                                  







                                                                             

                                                                          









                                                                         
                                                                                 

                                                                    
                                                                  












                                                                          
                                              










                                                                
                                        






                                           
                                             

                                      

                               







                                                                 




                                                                         


                                     





                                                                                                                                                                               



                              
                                                                                                                         

                                                                                                                           
                                                                                   



                                            




                                                                                                     
                                  

                                                                 
                          


                                                                                             


                              



                                                                                                                                   








                                                      

                                                     










                                                                                                                 
                                            






                                                        

                                                      

                                                           
                                            


                                                    
                                                   
                                                           
                                              
                                                      
                                                  
                                                          
                                                 
                                                         
                                              
                                                      
                                                 
                                                         
                                               
                                                       
                                          
                                                  
                                            
                                                    
                                                 
                                                         
                                                 
                                                         
                                                
                                                        
                                               





































































































































































                                                                                                                                      
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder

#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>

#include "pc.h"
#include "map.h"
#include "pet.h"
#include "mob.h"
#include "clif.h"
#include "guild.h"
#include "skill.h"
#include "itemdb.h"
#include "battle.h"
#include "chrif.h"
#include "status.h"

#include "timer.h"
#include "nullpo.h"
#include "script.h"
#include "showmsg.h"

int SkillStatusChangeTable[]={
	-1,-1,-1,-1,-1,-1,
	SC_PROVOKE,
	SC_WATK_ELEMENT,		//Adds part of your final attack as elemental damage. [Skotlex]
	SC_ENDURE,
	-1,
/* 10- */
	SC_SIGHT,			/* �T�C�g */
	-1,
	SC_SAFETYWALL,		/* �Z�[�t�e�B�[�E�H�[�� */
	-1,-1,-1,
	SC_FREEZE,			/* �t���X�g�_�C�o? */
	SC_STONE,			/* �X�g?���J?�X */
	-1,-1,
/* 20- */
	-1,-1,-1,-1,
	SC_RUWACH,			/* ���A�t */
	-1,//SC_PNEUMA, Pneuma is no longer a status change. It is a cell type.
	-1,-1,-1,
	SC_INCREASEAGI,		/* ���x?�� */
/* 30- */
	SC_DECREASEAGI,		/* ���x���� */
	-1,
	SC_SIGNUMCRUCIS,	/* �V�O�i���N���V�X */
	SC_ANGELUS,			/* �G���W�F���X */
	SC_BLESSING,		/* �u���b�V���O */
	-1,-1,-1,-1,-1,
/* 40- */
	-1,-1,-1,-1,-1,
	SC_CONCENTRATE,		/* �W���͌��� */
	-1,-1,-1,-1,
/* 50- */
	-1,
	SC_HIDING,			/* �n�C�f�B���O */
	-1,-1,-1,-1,-1,-1,-1,-1,
/* 60- */
	SC_TWOHANDQUICKEN,	/* 2HQ */
	SC_AUTOCOUNTER,
	-1,-1,-1,-1,
	SC_IMPOSITIO,		/* �C���|�V�e�B�I�}�k�X */
	SC_SUFFRAGIUM,		/* �T�t���M�E�� */
	SC_ASPERSIO,		/* �A�X�y���V�I */
	SC_BENEDICTIO,		/* ��?�~�� */
/* 70- */
	-1,
	SC_SLOWPOISON,
	-1,
	SC_KYRIE,			/* �L���G�G���C�\�� */
	SC_MAGNIFICAT,		/* �}�O�j�t�B�J?�g */
	SC_GLORIA,			/* �O�����A */
	SC_SILENCE,			/* ���b�N�X�f�B�r?�i */
	-1,
	SC_AETERNA,			/* ���b�N�X�G?�e���i */
	-1,
/* 80- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 90- */
	-1,-1,
	SC_QUAGMIRE,		/* �N�@�O�}�C�A */
	-1,-1,-1,-1,-1,-1,-1,
/* 100- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 110- */
	-1,
	SC_ADRENALINE,		/* �A�h���i�������b�V�� */
	SC_WEAPONPERFECTION,/* �E�F�|���p?�t�F�N�V���� */
	SC_OVERTHRUST,		/* �I?�o?�g���X�g */
	SC_MAXIMIZEPOWER,	/* �}�L�V�}�C�Y�p��? */
	-1,-1,-1,-1,-1,
/* 120- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 130- */
	-1,-1,-1,-1,-1,
	SC_CLOAKING,		/* �N��?�L���O */
	SC_STAN,			/* �\�j�b�N�u��? */
	-1,
	SC_ENCPOISON,		/* �G���`�����g�|�C�Y�� */
	SC_POISONREACT,		/* �|�C�Y�����A�N�g */
/* 140- */
	SC_POISON,			/* �x�m���_�X�g */
	SC_SPLASHER,		/* �x�i���X�v���b�V��? */
	-1,
	SC_TRICKDEAD,		/* ���񂾂ӂ� */
	-1,-1,
	SC_AUTOBERSERK,
	-1,-1,-1,
/* 150- */
	-1,-1,-1,-1,-1,
	SC_LOUD,			/* ���E�h�{�C�X */
	-1,
	SC_ENERGYCOAT,		/* �G�i�W?�R?�g */
	-1,-1,
/* 160- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 200 */
	-1,
	SC_KEEPING,
	-1,
	SC_COMA,
	SC_BARRIER,
	-1,
	SC_STAN,
	SC_HALLUCINATION,
	-1,-1,
/* 210- */
	-1,-1,-1,-1,-1,
	SC_STRIPWEAPON,
	SC_STRIPSHIELD,
	SC_STRIPARMOR,
	SC_STRIPHELM,
	-1,
/* 220- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 230- */
	-1,-1,-1,-1,
	SC_CP_WEAPON,
	SC_CP_SHIELD,
	SC_CP_ARMOR,
	SC_CP_HELM,
	-1,-1,
/* 240- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,
	SC_AUTOGUARD,
/* 250- */
	-1,-1,
	SC_REFLECTSHIELD,
	-1,-1,
	SC_DEVOTION,
	SC_PROVIDENCE,
	SC_DEFENDER,
	SC_SPEARSQUICKEN,
	-1,
/* 260- */
	-1,-1,-1,-1,-1,-1,-1,-1,
	SC_STEELBODY,
	SC_BLADESTOP_WAIT,
/* 270- */
	SC_EXPLOSIONSPIRITS,
	SC_EXTREMITYFIST,
	-1,-1,-1,-1,
	SC_MAGICROD,
	-1,-1,-1,
/* 280- */
	SC_FIREWEAPON,
	SC_WATERWEAPON,
	SC_WINDWEAPON,
	SC_EARTHWEAPON,
	-1,
	SC_VOLCANO,
	SC_DELUGE,
	SC_VIOLENTGALE,
	SC_LANDPROTECTOR,
	-1,
/* 290- */
	-1,-1,-1,-1,
	SC_ORCISH,
	-1,-1,-1,-1,-1,
/* 300- */
	-1,-1,-1,
	SC_COMA,
	-1,-1,
	SC_LULLABY,
	SC_RICHMANKIM,
	SC_ETERNALCHAOS,
	SC_DRUMBATTLE,
/* 310- */
	SC_NIBELUNGEN,
	SC_ROKISWEIL,
	SC_INTOABYSS,
	SC_SIEGFRIED,
	-1,-1,-1,-1,-1,
	SC_WHISTLE,
/* 320- */
	SC_ASSNCROS,
	SC_POEMBRAGI,
	SC_APPLEIDUN,
	-1,-1,
	SC_UGLYDANCE,
	-1,
	SC_HUMMING,
	SC_DONTFORGETME,
	SC_FORTUNE,
/* 330- */
	SC_SERVICE4U,
	-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 340- */
	-1,-1,
	SC_STOP,
	-1,-1,-1,-1,-1,-1,-1,
/* 350- */
	-1,-1,-1,-1,-1,
	SC_AURABLADE,
	SC_PARRYING,
	SC_CONCENTRATION,
	SC_TENSIONRELAX,
	SC_BERSERK,
/* 360- */
	-1,
	SC_ASSUMPTIO,
	SC_BASILICA,
	-1,-1,-1,
	SC_MAGICPOWER,
	-1,
	SC_SACRIFICE,
	SC_GOSPEL,
/* 370- */
	-1,-1,-1,-1,-1,-1,-1,-1,
	SC_EDP,
	-1,
/* 380- */
	SC_TRUESIGHT,
	-1,-1,
	SC_WINDWALK,
	SC_MELTDOWN,
	-1,-1,
	SC_CARTBOOST,
	-1,
	SC_CHASEWALK,
/* 390- */
	SC_REJECTSWORD,
	-1,-1,-1,-1,
	SC_MOONLIT,
	SC_MARIONETTE,
	-1,
	SC_BLEEDING,
	SC_JOINTBEAT,
/* 400 */
	-1,-1,
	SC_MINDBREAKER,
	SC_MEMORIZE,
	SC_FOGWALL,
	SC_SPIDERWEB,
	-1,-1,
	SC_BABY,
	-1,
/* 410- */
	-1,
	SC_RUN,
	SC_READYSTORM,
	-1,
	SC_READYDOWN,
	-1,
	SC_READYTURN,
	-1,
	SC_READYCOUNTER,
	-1,
/* 420- */
	SC_DODGE,
	-1,-1,
	SC_TKDORI,
	-1,-1,-1,-1,
	SC_WARM,
	SC_WARM,
/* 430- */
	SC_WARM,
	SC_SUN_COMFORT,
	SC_MOON_COMFORT,
	SC_STAR_COMFORT,
	-1,-1,-1,-1,-1,-1,
/* 440- */
	-1,-1,-1,-1,
	SC_FUSION,
	MAPID_ALCHEMIST, // Storing the target job rather than simply SC_SPIRIT simplifies code later on.
	-1,
	MAPID_MONK,
	MAPID_STAR_GLADIATOR,
	MAPID_SAGE,
/* 450- */
	MAPID_CRUSADER,
	MAPID_SUPER_NOVICE,
	MAPID_KNIGHT,
	MAPID_WIZARD,
	MAPID_PRIEST,
	MAPID_BARDDANCER,
	MAPID_ROGUE,
	MAPID_ASSASSIN,
	MAPID_BLACKSMITH,
	SC_ADRENALINE2,
/* 460- */
	MAPID_HUNTER,
	MAPID_SOUL_LINKER,
	SC_KAIZEL,
	SC_KAAHI,
	SC_KAUPE,
	SC_KAITE,
	-1,-1,-1,-1,
/* 470- */
	SC_SWOO, // [marquis007]
	SC_SKE,
	SC_SKA, // [marquis007]
	-1,-1,
	SC_PRESERVE,
	-1,-1,-1,-1,
/* 480- */
	-1,-1,
	SC_DOUBLECAST,
	-1,
	SC_GRAVITATION,
	-1,
	SC_MAXOVERTHRUST,
	SC_LONGING,
	SC_HERMODE,
	-1,
/* 490- */
	-1,-1,-1,-1,
	SC_SPIRIT,
	SC_ONEHAND,
	-1,-1,-1,-1,
/* 500- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 510- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 520- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 530- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 540- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 550- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 560- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 570- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 580- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 590- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 600- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 610- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 620- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 630- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 640- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 650- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 660- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 670- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 680- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 690- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 700- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 710- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 720- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 730- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 740- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 750- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 760- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 770- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 780- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 790- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 800- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 810- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 820- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 830- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 840- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 850- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 860- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 870- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 880- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 890- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 900- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 910- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 920- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 930- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 940- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 950- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 960- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 970- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 980- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 990- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 1000- */
	-1,-1,
	SC_SHRINK,
	-1,-1,
	SC_CLOSECONFINE2,
	SC_SIGHTBLASTER,
	-1,-1,-1,
/* 1010- */
	-1,
	SC_WINKCHARM,
	-1,-1,
	SC_COMA,
	-1,-1,-1,-1,-1,
/* 1020- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 1030- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 1040- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 1050- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 1060- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 1070- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 1080- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
/* 1090- */
	-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
};

int StatusIconChangeTable[SC_MAX];

static int max_weight_base[MAX_PC_CLASS];
static int hp_coefficient[MAX_PC_CLASS];
static int hp_coefficient2[MAX_PC_CLASS];
static int hp_sigma_val[MAX_PC_CLASS][MAX_LEVEL];
static int sp_coefficient[MAX_PC_CLASS];
static int aspd_base[MAX_PC_CLASS][20];
#define MAX_REFINE_BONUS 5
static int refinebonus[MAX_REFINE_BONUS][3];	// ���B�{�[�i�X�e�[�u��(refine_db.txt)
int percentrefinery[5][MAX_REFINE+1];	// ���B������(refine_db.txt)
static int atkmods[3][20];	// ����ATK�T�C�Y�C��(size_fix.txt)
static char job_bonus[MAX_PC_CLASS][MAX_LEVEL];

int current_equip_item_index; //Contains inventory index of an equipped item. To pass it into the EQUP_SCRIPT [Lupus]
//we need it for new cards 15 Feb 2005, to check if the combo cards are insrerted into the CURRENT weapon only
//to avoid cards exploits

//Initializes the StatusIconChangeTable variable. May seem somewhat slower than directly defining the array,
//but it is much less prone to errors. [Skotlex]
void initStatusIconChangeTable(void) {
	int i;
	for (i = 0; i < SC_MAX; i++)
		StatusIconChangeTable[i] = SI_BLANK;

	StatusIconChangeTable[SC_PROVOKE] = SI_PROVOKE;
	StatusIconChangeTable[SC_ENDURE] = SI_ENDURE;
	StatusIconChangeTable[SC_TWOHANDQUICKEN] = SI_TWOHANDQUICKEN;
	StatusIconChangeTable[SC_CONCENTRATE] = SI_CONCENTRATE;
	StatusIconChangeTable[SC_HIDING] = SI_HIDING;
	StatusIconChangeTable[SC_CLOAKING] = SI_CLOAKING;
	StatusIconChangeTable[SC_ENCPOISON] = SI_ENCPOISON;
	StatusIconChangeTable[SC_POISONREACT] = SI_POISONREACT;
	StatusIconChangeTable[SC_QUAGMIRE] = SI_QUAGMIRE;
	StatusIconChangeTable[SC_ANGELUS] = SI_ANGELUS;
	StatusIconChangeTable[SC_BLESSING] = SI_BLESSING;
	StatusIconChangeTable[SC_SIGNUMCRUCIS] = SI_SIGNUMCRUCIS;
	StatusIconChangeTable[SC_INCREASEAGI] = SI_INCREASEAGI;
	StatusIconChangeTable[SC_DECREASEAGI] = SI_DECREASEAGI;
	StatusIconChangeTable[SC_SLOWPOISON] = SI_SLOWPOISON;
	StatusIconChangeTable[SC_IMPOSITIO] = SI_IMPOSITIO;
	StatusIconChangeTable[SC_SUFFRAGIUM] = SI_SUFFRAGIUM;
	StatusIconChangeTable[SC_ASPERSIO] = SI_ASPERSIO;
	StatusIconChangeTable[SC_BENEDICTIO] = SI_BENEDICTIO;
	StatusIconChangeTable[SC_KYRIE] = SI_KYRIE;
	StatusIconChangeTable[SC_MAGNIFICAT] = SI_MAGNIFICAT;
	StatusIconChangeTable[SC_GLORIA] = SI_GLORIA;
	StatusIconChangeTable[SC_AETERNA] = SI_AETERNA;
	StatusIconChangeTable[SC_ADRENALINE] = SI_ADRENALINE;
	StatusIconChangeTable[SC_WEAPONPERFECTION]	= SI_WEAPONPERFECTION;
	StatusIconChangeTable[SC_OVERTHRUST] = SI_OVERTHRUST;
	StatusIconChangeTable[SC_MAXIMIZEPOWER] = SI_MAXIMIZEPOWER;
	StatusIconChangeTable[SC_TRICKDEAD] = SI_TRICKDEAD;
	StatusIconChangeTable[SC_LOUD] = SI_LOUD;
	StatusIconChangeTable[SC_ENERGYCOAT] = SI_ENERGYCOAT;
	StatusIconChangeTable[SC_BROKENARMOR] = SI_BROKENARMOR;
	StatusIconChangeTable[SC_BROKENWEAPON] = SI_BROKENWEAPON;
	StatusIconChangeTable[SC_HALLUCINATION] = SI_HALLUCINATION;
	StatusIconChangeTable[SC_WEIGHT50 ] = SI_WEIGHT50;
	StatusIconChangeTable[SC_WEIGHT90] = SI_WEIGHT90;
	StatusIconChangeTable[SC_ASPDPOTION0] = SI_ASPDPOTION;
	StatusIconChangeTable[SC_ASPDPOTION1] = SI_ASPDPOTION;
	StatusIconChangeTable[SC_ASPDPOTION2] = SI_ASPDPOTION;
	StatusIconChangeTable[SC_ASPDPOTION3] = SI_ASPDPOTION;
	StatusIconChangeTable[SC_SPEEDUP0] = SI_SPEEDPOTION;
	StatusIconChangeTable[SC_SPEEDUP1] = SI_SPEEDPOTION;
	StatusIconChangeTable[SC_STRIPWEAPON] = SI_STRIPWEAPON;
	StatusIconChangeTable[SC_STRIPSHIELD] = SI_STRIPSHIELD;
	StatusIconChangeTable[SC_STRIPARMOR] = SI_STRIPARMOR;
	StatusIconChangeTable[SC_STRIPHELM] = SI_STRIPHELM;
	StatusIconChangeTable[SC_CP_WEAPON] = SI_CP_WEAPON;
	StatusIconChangeTable[SC_CP_SHIELD] = SI_CP_SHIELD;
	StatusIconChangeTable[SC_CP_ARMOR] = SI_CP_ARMOR;
	StatusIconChangeTable[SC_CP_HELM] = SI_CP_HELM;
	StatusIconChangeTable[SC_AUTOGUARD] = SI_AUTOGUARD;
	StatusIconChangeTable[SC_REFLECTSHIELD] = SI_REFLECTSHIELD;
	StatusIconChangeTable[SC_PROVIDENCE] = SI_PROVIDENCE;
	StatusIconChangeTable[SC_DEFENDER] = SI_DEFENDER;
	StatusIconChangeTable[SC_AUTOSPELL] = SI_AUTOSPELL;
	StatusIconChangeTable[SC_SPEARSQUICKEN] = SI_SPEARQUICKEN;
	StatusIconChangeTable[SC_EXPLOSIONSPIRITS] = SI_EXPLOSIONSPIRITS;
	StatusIconChangeTable[SC_FURY] = SI_FURY;
	StatusIconChangeTable[SC_FIREWEAPON] = SI_FIREWEAPON;
	StatusIconChangeTable[SC_WATERWEAPON] = SI_WATERWEAPON;
	StatusIconChangeTable[SC_WINDWEAPON] = SI_WINDWEAPON;
	StatusIconChangeTable[SC_EARTHWEAPON] = SI_EARTHWEAPON;
	StatusIconChangeTable[SC_AURABLADE] = SI_AURABLADE;
	StatusIconChangeTable[SC_PARRYING] = SI_PARRYING;
	StatusIconChangeTable[SC_CONCENTRATION] = SI_CONCENTRATION;
	StatusIconChangeTable[SC_TENSIONRELAX] = SI_TENSIONRELAX;
	StatusIconChangeTable[SC_BERSERK] = SI_BERSERK;
	StatusIconChangeTable[SC_ASSUMPTIO] = SI_ASSUMPTIO;
	StatusIconChangeTable[SC_GUILDAURA] = SI_GUILDAURA;
	StatusIconChangeTable[SC_MAGICPOWER] = SI_MAGICPOWER;
	StatusIconChangeTable[SC_EDP] = SI_EDP;
	StatusIconChangeTable[SC_TRUESIGHT] = SI_TRUESIGHT;
	StatusIconChangeTable[SC_WINDWALK] = SI_WINDWALK;
	StatusIconChangeTable[SC_MELTDOWN] = SI_MELTDOWN;
	StatusIconChangeTable[SC_CARTBOOST] = SI_CARTBOOST;
	StatusIconChangeTable[SC_CHASEWALK] = SI_CHASEWALK;
	StatusIconChangeTable[SC_REJECTSWORD] = SI_REJECTSWORD;
	StatusIconChangeTable[SC_MARIONETTE] = SI_MARIONETTE;
	StatusIconChangeTable[SC_MARIONETTE2] = SI_MARIONETTE2;
	StatusIconChangeTable[SC_BLEEDING] = SI_BLEEDING;
	StatusIconChangeTable[SC_MOONLIT] = SI_MOONLIT;
	StatusIconChangeTable[SC_DEVOTION] = SI_DEVOTION;
	StatusIconChangeTable[SC_STEELBODY] = SI_STEELBODY;
	StatusIconChangeTable[SC_SPURT] = SI_SPURT;
	StatusIconChangeTable[SC_SPIRIT] = SI_SPIRIT;
	StatusIconChangeTable[SC_READYSTORM] = SI_READYSTORM;
	StatusIconChangeTable[SC_READYDOWN] = SI_READYDOWN;
	StatusIconChangeTable[SC_READYTURN] = SI_READYTURN;
	StatusIconChangeTable[SC_READYCOUNTER] = SI_READYCOUNTER;
	StatusIconChangeTable[SC_DODGE] = SI_DODGE;
	StatusIconChangeTable[SC_SHADOWWEAPON] = SI_SHADOWWEAPON;
	StatusIconChangeTable[SC_WARM] = SI_WARM;
	StatusIconChangeTable[SC_SUN_COMFORT] = SI_SUN_COMFORT;
	StatusIconChangeTable[SC_MOON_COMFORT] = SI_MOON_COMFORT;
	StatusIconChangeTable[SC_STAR_COMFORT] = SI_STAR_COMFORT;
	StatusIconChangeTable[SC_ADRENALINE2] = SI_ADRENALINE2;
	StatusIconChangeTable[SC_GHOSTWEAPON] = SI_GHOSTWEAPON;
	StatusIconChangeTable[SC_KAITE] = SI_KAITE;
	StatusIconChangeTable[SC_KAIZEL] = SI_KAIZEL;
	StatusIconChangeTable[SC_KAAHI] = SI_KAAHI;
	StatusIconChangeTable[SC_KAUPE] = SI_KAUPE;
	StatusIconChangeTable[SC_ONEHAND] = SI_ONEHAND;
	StatusIconChangeTable[SC_PRESERVE] = SI_PRESERVE;
	StatusIconChangeTable[SC_BATTLEORDERS] = SI_BATTLEORDERS;
	StatusIconChangeTable[SC_DOUBLECAST] = SI_DOUBLECAST;
	StatusIconChangeTable[SC_MAXOVERTHRUST] = SI_MAXOVERTHRUST;
	StatusIconChangeTable[SC_SHRINK] = SI_SHRINK;
	StatusIconChangeTable[SC_SIGHTBLASTER] = SI_SIGHTBLASTER;
	StatusIconChangeTable[SC_WINKCHARM] = SI_WINKCHARM;
	StatusIconChangeTable[SC_CLOSECONFINE] = SI_CLOSECONFINE;
	StatusIconChangeTable[SC_CLOSECONFINE2] = SI_CLOSECONFINE2;
}
/*==========================================
 * ���B�{�[�i�X
 *------------------------------------------
 */
int status_getrefinebonus(int lv,int type)
{
	if (lv >= 0 && lv < 5 && type >= 0 && type < 3)
		return refinebonus[lv][type];
	return 0;
}

/*==========================================
 * Checks whether the src can use the skill on the target,
 * taking into account status/option of both source/target. [Skotlex]
 * flag: 1 to indicate this call is done after the casting (target already selected)
 * src MAY be null to indicate we shouldn't check it, this is a ground-based skill attack.
 * target MAY Be null, in which case the checks are only to see 
 * whether the source can cast or not the skill on the ground.
 *------------------------------------------
 */
int status_check_skilluse(struct block_list *src, struct block_list *target, int skill_num, int flag)
{
	int mode, race, hide_flag;
	struct status_change *sc=NULL, *tsc;

	if (src && status_isdead(src))
		return 0;
	if (target && status_isdead(target) && skill_num != ALL_RESURRECTION && skill_num != PR_REDEMPTIO)
		return 0;
	
	if (skill_num == PA_PRESSURE && flag)
		return 1; //Once Gloria Domini has been casted, there's nothing you can do to stop it. [Skotlex]
	
	mode = src?status_get_mode(src):MD_CANATTACK;
	
	if (!skill_num && !(mode&MD_CANATTACK))
		return 0; //This mode is only needed for melee attacking.
	
	if (((src && map_getcell(src->m,src->x,src->y,CELL_CHKBASILICA)) ||
		(target && target != src && map_getcell(target->m,target->x,target->y,CELL_CHKBASILICA)))
		&& !(mode&MD_BOSS))
	{	//Basilica Check
		if (!skill_num) return 0;
		race = skill_get_inf(skill_num);
		if (race&INF_ATTACK_SKILL)
			return 0;
		if (race&INF_GROUND_SKILL && skill_get_unit_target(skill_num)&BCT_ENEMY)
			return 0;
	}	
	if (src) sc = status_get_sc(src);
	
	if(sc && sc->opt1 >0)
		return 0;
	
	if(sc && sc->count)
	{
		if (
			(sc->data[SC_TRICKDEAD].timer != -1 && skill_num != NV_TRICKDEAD)
			|| (sc->data[SC_AUTOCOUNTER].timer != -1 && skill_num != KN_AUTOCOUNTER)
			|| (sc->data[SC_GOSPEL].timer != -1 && sc->data[SC_GOSPEL].val4 == BCT_SELF && skill_num != PA_GOSPEL)
			|| sc->data[SC_GRAVITATION].timer != -1
		)
			return 0;

		if (sc->data[SC_BLADESTOP].timer != -1) {
			switch (sc->data[SC_BLADESTOP].val1)
			{
				case 1: return 0;
				case 2: if (skill_num != MO_FINGEROFFENSIVE) return 0; break;
				case 3: if (skill_num != MO_FINGEROFFENSIVE && skill_num != MO_INVESTIGATE) return 0; break;
				case 4: if (skill_num != MO_FINGEROFFENSIVE && skill_num != MO_INVESTIGATE && skill_num != MO_CHAINCOMBO) return 0; break;
				case 5: if (skill_num != MO_FINGEROFFENSIVE && skill_num != MO_INVESTIGATE && skill_num != MO_CHAINCOMBO && skill_num!=MO_EXTREMITYFIST) return 0; break;
				default: return 0;
			}
		}
		if (skill_num)
		{	//Skills blocked through status changes...
			if ((sc->data[SC_VOLCANO].timer != -1 && skill_num == WZ_ICEWALL) ||
				(sc->data[SC_ROKISWEIL].timer != -1 && skill_num != BD_ADAPTATION) ||
				(sc->data[SC_MARIONETTE].timer != -1 && skill_num != CG_MARIONETTE) ||
				(sc->data[SC_MARIONETTE2].timer != -1 && skill_num == CG_MARIONETTE) ||
				(sc->data[SC_HERMODE].timer != -1 && skill_get_inf(skill_num) & INF_SUPPORT_SKILL) ||
				sc->data[SC_SILENCE].timer != -1 || sc->data[SC_STEELBODY].timer != -1 ||
				sc->data[SC_BERSERK].timer != -1 || sc->data[SC_SKA].timer != -1 ||
				sc->data[SC_NOCHAT].timer != -1
			)
				return 0;

			if (sc->data[SC_DANCING].timer != -1)
			{
				if (skill_num != BD_ADAPTATION && skill_num != CG_LONGINGFREEDOM
					&& skill_num != BA_MUSICALSTRIKE && skill_num != DC_THROWARROW)
					return 0;
				if (sc->data[SC_DANCING].val1 == CG_HERMODE && skill_num == BD_ADAPTATION)
					return 0;	//Can't amp out of Wand of Hermode :/ [Skotlex]
			}
		}
	}

	if (sc && sc->option)
	{
		if (sc->option&OPTION_HIDE && skill_num != TF_HIDING && skill_num != AS_GRIMTOOTH
			&& skill_num != RG_BACKSTAP && skill_num != RG_RAID)
			return 0;
		if (sc->option&OPTION_CLOAK && skill_num == TF_HIDING)
			return 0;
		if (sc->option&OPTION_CHASEWALK && skill_num != ST_CHASEWALK)
			return 0;
	}
	if (target == NULL || target == src) //No further checking needed.
		return 1;

	tsc = status_get_sc(target);
	if(tsc && tsc->count)
	{	
		if (!(mode & MD_BOSS) && tsc->data[SC_TRICKDEAD].timer != -1)
			return 0;
		if(skill_num == WZ_STORMGUST && tsc->data[SC_FREEZE].timer != -1)
			return 0;
		if(skill_num == PR_LEXAETERNA && (tsc->data[SC_FREEZE].timer != -1 || (tsc->data[SC_STONE].timer != -1 && tsc->data[SC_STONE].val2 == 0)))
			return 0;
	}

	if (src) {
		race = status_get_race(src); 
	} else { //Ground skill, only earth-elemental skills have detecting-hitting capabilities.
		race = 0;
		if(skill_get_pl(skill_num) == 2)
			mode|= MD_DETECTOR;
	}
	hide_flag = flag?OPTION_HIDE:(OPTION_HIDE|OPTION_CLOAK|OPTION_CHASEWALK); //If targetting, cloak+hide protect you, otherwise only hiding does.
		
	switch (target->type)
	{
	case BL_PC:
		{
			struct map_session_data *sd = (struct map_session_data*) target;
			if (pc_isinvisible(sd))
				return 0;
			if ((tsc->option&hide_flag || sd->state.gangsterparadise)
				&& (sd->state.perfect_hiding || !(race == 4 || race == 6 || mode&MD_DETECTOR))
				&& !(mode&MD_BOSS))
				return 0;
		}
		break;
	case BL_PET:
		return 0;
	case BL_ITEM:	//Allow targetting of items to pick'em up (or in the case of mobs, to loot them).
		//TODO: Would be nice if this could be used to judge whether the player can or not pick up the item it targets. [Skotlex]
		if (mode&MD_LOOTER)
			return 1;
		else
			return 0;
	default:
		//Check for chase-walk/hiding/cloaking opponents.
		if (tsc && !(mode&MD_BOSS))
		{
			if (tsc->option&hide_flag && !(race == 4 || race == 6 || mode&MD_DETECTOR))
				return 0;
		}
	}
	return 1;
}

//Skotlex: Calculates the stats of the given pet.
int status_calc_pet(struct map_session_data *sd, int first)
{
	struct pet_data *pd;
	
	nullpo_retr(0, sd);
	if (sd->status.pet_id == 0 || sd->pd == NULL)
		return 1;

	pd = sd->pd;
	
	if (battle_config.pet_lv_rate && pd->status)
	{
		sd->pet.level = sd->status.base_level*battle_config.pet_lv_rate/100;
		if (sd->pet.level < 0)
			sd->pet.level = 1;
		if (pd->status->level != sd->pet.level || first)
		{
			if (!first) //Lv Up animation
				clif_misceffect(&pd->bl, 0);
			pd->status->level = sd->pet.level;
			pd->status->atk1 = (pd->db->atk1*pd->status->level)/pd->db->lv;
			pd->status->atk2 = (pd->db->atk2*pd->status->level)/pd->db->lv;
			pd->status->str = (pd->db->str*pd->status->level)/pd->db->lv;
			pd->status->agi = (pd->db->agi*pd->status->level)/pd->db->lv;
			pd->status->vit = (pd->db->vit*pd->status->level)/pd->db->lv;
			pd->status->int_ = (pd->db->int_*pd->status->level)/pd->db->lv;
			pd->status->dex = (pd->db->dex*pd->status->level)/pd->db->lv;
			pd->status->luk = (pd->db->luk*pd->status->level)/pd->db->lv;
		
			if (pd->status->atk1 > battle_config.pet_max_atk1) pd->status->atk1 = battle_config.pet_max_atk1;
			if (pd->status->atk2 > battle_config.pet_max_atk2) pd->status->atk2 = battle_config.pet_max_atk2;

			if (pd->status->str > battle_config.pet_max_stats) pd->status->str = battle_config.pet_max_stats;
			else if (pd->status->str < 1) pd->status->str = 1;
			if (pd->status->agi > battle_config.pet_max_stats) pd->status->agi = battle_config.pet_max_stats;
			else if (pd->status->agi < 1) pd->status->agi = 1;
			if (pd->status->vit > battle_config.pet_max_stats) pd->status->vit = battle_config.pet_max_stats;
			else if (pd->status->vit < 1) pd->status->vit = 1;
			if (pd->status->int_ > battle_config.pet_max_stats) pd->status->int_ = battle_config.pet_max_stats;
			else if (pd->status->int_ < 1) pd->status->int_ = 1;
			if (pd->status->dex > battle_config.pet_max_stats) pd->status->dex = battle_config.pet_max_stats;
			else if (pd->status->dex < 1) pd->status->dex = 1;
			if (pd->status->luk > battle_config.pet_max_stats) pd->status->luk = battle_config.pet_max_stats;
			else if (pd->status->luk < 1) pd->status->luk = 1;

			if (!first)	//Not done the first time because the pet is not visible yet
				clif_send_petstatus(sd);
		}
	}
	//Support rate modifier (1000 = 100%)
	pd->rate_fix = 1000*(sd->pet.intimate - battle_config.pet_support_min_friendly)/(1000- battle_config.pet_support_min_friendly) +500;
	if(battle_config.pet_support_rate != 100)
		pd->rate_fix = pd->rate_fix*battle_config.pet_support_rate/100;
	return 0;
}	

/*==========================================
 * �p�����[�^�v�Z
 * first==0�̎��A�v�Z�Ώۂ̃p�����[�^���Ăяo���O����
 * �� �������ꍇ������send���邪�A
 * �\���I�ɕω��������p�����[�^�͎��O��send����悤��
 *------------------------------------------
 */

int status_calc_pc(struct map_session_data* sd,int first)
{
	static int calculating = 0; //Check for recursive call preemption. [Skotlex]
	int b_speed,b_max_hp,b_max_sp,b_hp,b_sp,b_weight,b_max_weight,b_paramb[6],b_parame[6],b_hit,b_flee;
	int b_aspd,b_watk,b_def,b_watk2,b_def2,b_flee2,b_critical,b_attackrange,b_matk1,b_matk2,b_mdef,b_mdef2,b_class;
	int b_base_atk;
	struct skill b_skill[MAX_SKILL];
	int i,bl,index;
	int skill,wele,wele_,def_ele,refinedef=0;
	int pele=0,pdef_ele=0;
	int str,dstr,dex;

	nullpo_retr(0, sd);
	if (++calculating > 10) //Too many recursive calls to status_calc_pc!
		return -1;
	
	b_speed = sd->speed;
	b_max_hp = sd->status.max_hp;
	b_max_sp = sd->status.max_sp;
	b_hp = sd->status.hp;
	b_sp = sd->status.sp;
	b_weight = sd->weight;
	b_max_weight = sd->max_weight;
	memcpy(b_paramb,&sd->paramb,sizeof(b_paramb));
	memcpy(b_parame,&sd->paramc,sizeof(b_parame));
	memcpy(b_skill,&sd->status.skill,sizeof(b_skill));
	b_hit = sd->hit;
	b_flee = sd->flee;
	b_aspd = sd->aspd;
	b_watk = sd->right_weapon.watk;
	b_def = sd->def;
	b_watk2 = sd->right_weapon.watk2;
	b_def2 = sd->def2;
	b_flee2 = sd->flee2;
	b_critical = sd->critical;
	b_attackrange = sd->attackrange;
	b_matk1 = sd->matk1;
	b_matk2 = sd->matk2;
	b_mdef = sd->mdef;
	b_mdef2 = sd->mdef2;
	b_class = sd->view_class;
	sd->view_class = sd->status.class_;
	b_base_atk = sd->base_atk;

	pc_calc_skilltree(sd);	// �X�L���c��?�̌v�Z
	
	sd->max_weight = max_weight_base[sd->status.class_]+sd->status.str*300;

	if(first&1) {
		sd->weight=0;
		for(i=0;i<MAX_INVENTORY;i++){
			if(sd->status.inventory[i].nameid==0 || sd->inventory_data[i] == NULL)
				continue;
			sd->weight += sd->inventory_data[i]->weight*sd->status.inventory[i].amount;
		}
		sd->cart_max_weight=battle_config.max_cart_weight;
		sd->cart_weight=0;
		sd->cart_max_num=MAX_CART;
		sd->cart_num=0;
		for(i=0;i<MAX_CART;i++){
			if(sd->status.cart[i].nameid==0)
				continue;
			sd->cart_weight+=itemdb_weight(sd->status.cart[i].nameid)*sd->status.cart[i].amount;
			sd->cart_num++;
		}
	}

	// these are not zeroed. [zzo]

	sd->speed = DEFAULT_WALK_SPEED;
	sd->hprate=battle_config.hp_rate;
	sd->sprate=battle_config.sp_rate;
	sd->castrate=100;
	sd->delayrate=100;
	sd->dsprate=100;
	sd->aspd_rate = 100;
	sd->speed_rate = 100;
	sd->hprecov_rate = 100;
	sd->sprecov_rate = 100;
	sd->atk_rate = sd->matk_rate = 100;
	sd->critical_rate = sd->hit_rate = sd->flee_rate = sd->flee2_rate = 100;
	sd->def_rate = sd->def2_rate = sd->mdef_rate = sd->mdef2_rate = 100;
	sd->speed_add_rate = sd->aspd_add_rate = 100;

	// zeroed arays, order follows the order in map.h.
	// add new arrays to the end of zeroed area in map.h (see comments) and size here. [zzo]
	memset (sd->paramb, 0, sizeof(sd->paramb)
		+ sizeof(sd->parame)
		+ sizeof(sd->subele)
		+ sizeof(sd->subrace)
		+ sizeof(sd->subrace2)
		+ sizeof(sd->subsize)
		+ sizeof(sd->addeff)
		+ sizeof(sd->addeff2)
		+ sizeof(sd->reseff)
		+ sizeof(sd->weapon_coma_ele)
		+ sizeof(sd->weapon_coma_race)
		+ sizeof(sd->weapon_atk)
		+ sizeof(sd->weapon_atk_rate)
		+ sizeof(sd->arrow_addele) 
		+ sizeof(sd->arrow_addrace)
		+ sizeof(sd->arrow_addsize)
		+ sizeof(sd->arrow_addeff)
		+ sizeof(sd->arrow_addeff2)
		+ sizeof(sd->magic_addele)
		+ sizeof(sd->magic_addrace)
		+ sizeof(sd->magic_addsize)
		+ sizeof(sd->critaddrace)
		+ sizeof(sd->expaddrace)
		+ sizeof(sd->itemhealrate)
		+ sizeof(sd->addeff3)
		+ sizeof(sd->addeff3_type)
		+ sizeof(sd->sp_gain_race)
		+ sizeof(sd->unequip_losehp)
		+ sizeof(sd->unequip_losesp)
		);


	memset (&sd->right_weapon.watk, 0, sizeof(sd->right_weapon) - sizeof(sd->right_weapon.atkmods));
	memset (&sd->left_weapon.watk, 0, sizeof(sd->left_weapon) - sizeof(sd->left_weapon.atkmods));

	memset(&sd->special_state,0,sizeof(sd->special_state));

	sd->status.max_hp = 0;
	sd->status.max_sp = 0;

	//zero up structures...
	memset(&sd->autospell,0,sizeof(sd->autospell)
		+ sizeof(sd->autospell2)
		+ sizeof(sd->skillatk)
		+ sizeof(sd->skillblown)
		+ sizeof(sd->add_def)
		+ sizeof(sd->add_mdef)
		+ sizeof(sd->add_dmg)
		+ sizeof(sd->add_mdmg)
		+ sizeof(sd->add_drop)
	);
	
	// vars zeroing. ints, shorts, chars. in that order.
	memset (&sd->hit, 0, sizeof(sd->hit)
		+ sizeof(sd->flee)
		+ sizeof(sd->flee2)
		+ sizeof(sd->critical)
		+ sizeof(sd->aspd)
		+ sizeof(sd->def)
		+ sizeof(sd->mdef)
		+ sizeof(sd->def2)
		+ sizeof(sd->mdef2)
		+ sizeof(sd->def_ele)
		+ sizeof(sd->matk1)
		+ sizeof(sd->matk2)
		+ sizeof(sd->base_atk)
		+ sizeof(sd->arrow_atk)
		+ sizeof(sd->arrow_ele)
		+ sizeof(sd->arrow_cri)
		+ sizeof(sd->arrow_hit)
		+ sizeof(sd->arrow_range)
		+ sizeof(sd->nhealhp)
		+ sizeof(sd->nhealsp)
		+ sizeof(sd->nshealhp)
		+ sizeof(sd->nshealsp)
		+ sizeof(sd->nsshealhp)
		+ sizeof(sd->nsshealsp)
		+ sizeof(sd->critical_def)
		+ sizeof(sd->double_rate)
		+ sizeof(sd->long_attack_atk_rate)
		+ sizeof(sd->near_attack_def_rate)
		+ sizeof(sd->long_attack_def_rate)
		+ sizeof(sd->magic_def_rate)
		+ sizeof(sd->misc_def_rate)
		+ sizeof(sd->ignore_mdef_ele)
		+ sizeof(sd->ignore_mdef_race)
		+ sizeof(sd->perfect_hit)
		+ sizeof(sd->perfect_hit_add)
		+ sizeof(sd->get_zeny_rate)
		+ sizeof(sd->get_zeny_num)
		+ sizeof(sd->double_add_rate)
		+ sizeof(sd->short_weapon_damage_return)
		+ sizeof(sd->long_weapon_damage_return)
		+ sizeof(sd->magic_damage_return)
		+ sizeof(sd->random_attack_increase_add)
		+ sizeof(sd->random_attack_increase_per)
		+ sizeof(sd->break_weapon_rate)
		+ sizeof(sd->break_armor_rate)
		+ sizeof(sd->crit_atk_rate)
		+ sizeof(sd->hp_loss_rate)
		+ sizeof(sd->sp_loss_rate)
		+ sizeof(sd->classchange)
		+ sizeof(sd->setitem_hash)
		+ sizeof(sd->setitem_hash2)
		// shorts
		+ sizeof(sd->attackrange)
		+ sizeof(sd->attackrange_)
		+ sizeof(sd->splash_range)
		+ sizeof(sd->splash_add_range)
		+ sizeof(sd->add_steal_rate)
		+ sizeof(sd->hp_loss_value)
		+ sizeof(sd->sp_loss_value)
		+ sizeof(sd->hp_loss_type)
		+ sizeof(sd->sp_drain_type)
		+ sizeof(sd->hp_gain_value)
		+ sizeof(sd->sp_gain_value)
		+ sizeof(sd->add_drop_count)
		+ sizeof(sd->unbreakable)
		+ sizeof(sd->unbreakable_equip)
		+ sizeof(sd->unstripable_equip)
		+ sizeof(sd->no_regen)
		+ sizeof(sd->add_def_count)
		+ sizeof(sd->add_mdef_count)
		+ sizeof(sd->add_dmg_count)
		+ sizeof(sd->add_mdmg_count)
		);

	if(!sd->state.disguised && sd->disguise) {
		pc_stop_walking(sd,0);
		clif_clearchar(&sd->bl, 0);
		sd->disguise=0;
		clif_changeoption(&sd->bl);
		clif_spawnpc(sd);
	}

	for(i=0;i<10;i++) {
		current_equip_item_index = index = sd->equip_index[i]; //We pass INDEX to current_equip_item_index - for EQUIP_SCRIPT (new cards solution) [Lupus]
		if(index < 0)
			continue;
		if(i == 9 && sd->equip_index[8] == index)
			continue;
		if(i == 5 && sd->equip_index[4] == index)
			continue;
		if(i == 6 && (sd->equip_index[5] == index || sd->equip_index[4] == index))
			continue;

		if(sd->inventory_data[index]) {
			if(sd->inventory_data[index]->type == 4) { // Weapon cards
				if(sd->status.inventory[index].card[0]!=0x00ff && sd->status.inventory[index].card[0]!=0x00fe && sd->status.inventory[index].card[0]!=(short)0xff00) {
					int j;
					for(j=0;j<sd->inventory_data[index]->slot;j++){	// �J?�h
						int c=sd->status.inventory[index].card[j];
						if(c>0){
							if(i == 8 && sd->status.inventory[index].equip == 0x20)
								sd->state.lr_flag = 1;
							run_script(itemdb_equipscript(c),0,sd->bl.id,0);
							sd->state.lr_flag = 0;
							if (!calculating) //Abort, run_script retriggered status_calc_pc. [Skotlex]
								return 1;
						}
					}
				}
			}
			else if(sd->inventory_data[index]->type==5){ // Non-weapon equipment cards
				if(sd->status.inventory[index].card[0]!=0x00ff && sd->status.inventory[index].card[0]!=0x00fe && sd->status.inventory[index].card[0]!=(short)0xff00) {
					int j;
					for(j=0;j<sd->inventory_data[index]->slot;j++){	// �J?�h
						int c=sd->status.inventory[index].card[j];
						if(c>0) {
							run_script(itemdb_equipscript(c),0,sd->bl.id,0);
							if (!calculating) //Abort, run_script retriggered status_calc_pc. [Skotlex]
								return 1;
						}
					}
				}
			}
		}
	}
	wele = sd->right_weapon.atk_ele;
	wele_ = sd->left_weapon.atk_ele;
	def_ele = sd->def_ele;

	if(sd->status.pet_id > 0) { // Pet
		struct pet_data *pd=sd->pd;
		if((pd && battle_config.pet_status_support) && (!battle_config.pet_equip_required || pd->equip > 0)) {
			if(sd->pet.intimate > 0 && pd->state.skillbonus == 1 && pd->bonus) { //Skotlex: Readjusted for pets
				pc_bonus(sd,pd->bonus->type, pd->bonus->val);
			}
			pele = sd->right_weapon.atk_ele;
			pdef_ele = sd->def_ele;
			sd->right_weapon.atk_ele = sd->def_ele = 0;
		}
	}
	memcpy(sd->paramcard,sd->parame,sizeof(sd->paramcard));

	// ?���i�ɂ��X�e?�^�X?���͂�����?�s
	for(i=0;i<10;i++) {
		current_equip_item_index = index = sd->equip_index[i]; //We pass INDEX to current_equip_item_index - for EQUIP_SCRIPT (new cards solution) [Lupus]
		if(index < 0)
			continue;
		if(i == 9 && sd->equip_index[8] == index)
			continue;
		if(i == 5 && sd->equip_index[4] == index)
			continue;
		if(i == 6 && (sd->equip_index[5] == index || sd->equip_index[4] == index))
			continue;
		if(sd->inventory_data[index]) {
			sd->def += sd->inventory_data[index]->def;
			if(sd->inventory_data[index]->type == 4) {
				int r,wlv = sd->inventory_data[index]->wlv;
				if (wlv >= MAX_REFINE_BONUS) 
					wlv = MAX_REFINE_BONUS - 1;
				if(i == 8 && sd->status.inventory[index].equip == 0x20) { // Left-hand weapon
					sd->left_weapon.watk += sd->inventory_data[index]->atk;
					sd->left_weapon.watk2 = (r=sd->status.inventory[index].refine)*	// ��?�U?��
						refinebonus[wlv][0];
					if( (r-=refinebonus[wlv][2])>0 )	// ��?��?�{?�i�X
						sd->left_weapon.overrefine = r*refinebonus[wlv][1];

					if(sd->status.inventory[index].card[0]==0x00ff){	// Forged weapon
						sd->left_weapon.star = (sd->status.inventory[index].card[1]>>8);	// ���̂�����
						if(sd->left_weapon.star >= 15) sd->left_weapon.star = 40; // 3 Star Crumbs now give +40 dmg
						if (pc_istop10fame( MakeDWord(sd->status.inventory[index].card[2],sd->status.inventory[index].card[3]) ,MAPID_BLACKSMITH))
							sd->left_weapon.star += 10;
						wele_= (sd->status.inventory[index].card[1]&0x0f);	// ? ��
					}
					sd->attackrange_ += sd->inventory_data[index]->range;
					sd->state.lr_flag = 1;
					run_script(sd->inventory_data[index]->script,0,sd->bl.id,0);
					sd->state.lr_flag = 0;
					if (!calculating) //Abort, run_script retriggered status_calc_pc. [Skotlex]
						return 1;
				}
				else {	// Right-hand weapon
					sd->right_weapon.watk += sd->inventory_data[index]->atk;
					sd->right_weapon.watk2 += (r=sd->status.inventory[index].refine)*	// ��?�U?��
						refinebonus[wlv][0];
					if( (r-=refinebonus[wlv][2])>0 )	// ��?��?�{?�i�X
						sd->right_weapon.overrefine += r*refinebonus[wlv][1];

					if(sd->status.inventory[index].card[0]==0x00ff){	// Forged weapon
						sd->right_weapon.star += (sd->status.inventory[index].card[1]>>8);	// ���̂�����
						if(sd->right_weapon.star >= 15) sd->right_weapon.star = 40; // 3 Star Crumbs now give +40 dmg
						if (pc_istop10fame( MakeDWord(sd->status.inventory[index].card[2],sd->status.inventory[index].card[3]) ,MAPID_BLACKSMITH))
							sd->right_weapon.star += 10;
						wele = (sd->status.inventory[index].card[1]&0x0f);	// ? ��
					}
					sd->attackrange += sd->inventory_data[index]->range;
					run_script(sd->inventory_data[index]->script,0,sd->bl.id,0);
					if (!calculating) //Abort, run_script retriggered status_calc_pc. [Skotlex]
						return 1;
				}
			}
			else if(sd->inventory_data[index]->type == 5) {
				sd->right_weapon.watk += sd->inventory_data[index]->atk;
				refinedef += sd->status.inventory[index].refine*refinebonus[0][0];
				run_script(sd->inventory_data[index]->script,0,sd->bl.id,0);
				if (!calculating) //Abort, run_script retriggered status_calc_pc. [Skotlex]
					return 1;
			}
		}
	}

	if(sd->equip_index[10] >= 0){ // ��
		index = sd->equip_index[10];
		if(sd->inventory_data[index]){		// Arrows
			sd->state.lr_flag = 2;
			run_script(sd->inventory_data[index]->script,0,sd->bl.id,0);
			sd->state.lr_flag = 0;
			sd->arrow_atk += sd->inventory_data[index]->atk;
		}
	}
	sd->def += (refinedef+50)/100;

	if(sd->attackrange < 1) sd->attackrange = 1;
	if(sd->attackrange_ < 1) sd->attackrange_ = 1;
	if(sd->attackrange < sd->attackrange_)
		sd->attackrange = sd->attackrange_;
	if(sd->status.weapon == 11)
		sd->attackrange += sd->arrow_range;
	if(wele > 0)
		sd->right_weapon.atk_ele = wele;
	if(wele_ > 0)
		sd->left_weapon.atk_ele = wele_;
	if(def_ele > 0)
		sd->def_ele = def_ele;
	if(battle_config.pet_status_support) {
		if(pele > 0 && !sd->right_weapon.atk_ele)
			sd->right_weapon.atk_ele = pele;
		if(pdef_ele > 0 && !sd->def_ele)
			sd->def_ele = pdef_ele;
	}
	sd->double_rate += sd->double_add_rate;
	sd->perfect_hit += sd->perfect_hit_add;
	sd->splash_range += sd->splash_add_range;
	if(sd->aspd_add_rate != 100)	
		sd->aspd_rate += sd->aspd_add_rate-100;
	if(sd->speed_add_rate != 100)	
		sd->speed_rate += sd->speed_add_rate-100;

	// Damage modifiers from weapon type
	sd->right_weapon.atkmods[0] = atkmods[0][sd->weapontype1];
	sd->right_weapon.atkmods[1] = atkmods[1][sd->weapontype1];
	sd->right_weapon.atkmods[2] = atkmods[2][sd->weapontype1];
	sd->left_weapon.atkmods[0] = atkmods[0][sd->weapontype2];
	sd->left_weapon.atkmods[1] = atkmods[1][sd->weapontype2];
	sd->left_weapon.atkmods[2] = atkmods[2][sd->weapontype2];

// ----- STATS CALCULATION -----

	// Job bonuses
	for(i=0;i<(int)sd->status.job_level && i<MAX_LEVEL;i++){
		if(job_bonus[sd->status.class_][i])
			sd->paramb[job_bonus[sd->status.class_][i]-1]++;
	}

	// If a Super Novice has never died and is at least joblv 70, he gets all stats +10
	if((sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE && sd->die_counter == 0 && sd->status.job_level >= 70){
		sd->paramb[0] += 10;
		sd->paramb[1] += 10;
		sd->paramb[2] += 10;
		sd->paramb[3] += 10;
		sd->paramb[4] += 10;
		sd->paramb[5] += 10;
	}

	// Absolute modifiers from passive skills
	if(pc_checkskill(sd,BS_HILTBINDING)>0)
		sd->paramb[0] ++;
	if((skill=pc_checkskill(sd,SA_DRAGONOLOGY))>0)
		sd->paramb[3] += (skill+1)/2; // +1 INT / 2 lv
	if((skill=pc_checkskill(sd,AC_OWL))>0)
		sd->paramb[4] += skill;

	// Improve Concentration adds a percentage of base stat + job bonus + equipment bonus, but not from card bonus nor status change bonus
	if(sd->sc.count && sd->sc.data[SC_CONCENTRATE].timer!=-1 && sd->sc.data[SC_QUAGMIRE].timer == -1){
		sd->paramb[1] += (sd->status.agi+sd->paramb[1]+sd->parame[1]-sd->paramcard[1])*(2+sd->sc.data[SC_CONCENTRATE].val1)/100;
		sd->paramb[4] += (sd->status.dex+sd->paramb[4]+sd->parame[4]-sd->paramcard[4])*(2+sd->sc.data[SC_CONCENTRATE].val1)/100;
	}

	// Absolute modifiers from status changes (only for PC)
	if(sd->sc.count){
		if (sd->sc.data[SC_BATTLEORDERS].timer != -1) {
			sd->paramb[0] += 5;
			sd->paramb[3] += 5;
			sd->paramb[4] += 5;
		}
		if (sd->sc.data[SC_GUILDAURA].timer != -1) {
			int guildflag = sd->sc.data[SC_GUILDAURA].val4;
			for (i = 12; i >= 0; i -= 4) {
				skill = guildflag >> i;
				switch (i) {
					case 12: sd->paramb[0] += skill; break;
					case 8: sd->paramb[2] += skill; break;
					case 4: sd->paramb[1] += skill; break;
					case 0: sd->paramb[4] += skill; break;
				}
				guildflag ^= skill << i;
			}
		}
	}

	// Absolute, then relative modifiers from status changes (shared between PC and NPC)
	sd->paramb[0] = status_calc_str(&sd->bl,sd->paramb[0]);
	sd->paramb[1] = status_calc_agi(&sd->bl,sd->paramb[1]);
	sd->paramb[2] = status_calc_vit(&sd->bl,sd->paramb[2]);
	sd->paramb[3] = status_calc_int(&sd->bl,sd->paramb[3]);
	sd->paramb[4] = status_calc_dex(&sd->bl,sd->paramb[4]);
	sd->paramb[5] = status_calc_luk(&sd->bl,sd->paramb[5]);
	
	// Relative modifiers from status changes (only for PC)
	if(sd->sc.count){
		if(sd->sc.data[SC_MARIONETTE].timer!=-1){
			sd->paramb[0]-= sd->status.str/2;
			sd->paramb[1]-= sd->status.agi/2;
			sd->paramb[2]-= sd->status.vit/2;
			sd->paramb[3]-= sd->status.int_/2;
			sd->paramb[4]-= sd->status.dex/2;
			sd->paramb[5]-= sd->status.luk/2;
		}
		else if(sd->sc.data[SC_MARIONETTE2].timer!=-1){
			struct map_session_data *psd = map_id2sd(sd->sc.data[SC_MARIONETTE2].val3);
			if (psd) {	// if partner is found
				sd->paramb[0] += sd->status.str+psd->status.str/2 > 99 ? 99-sd->status.str : psd->status.str/2;
				sd->paramb[1] += sd->status.agi+psd->status.agi/2 > 99 ? 99-sd->status.agi : psd->status.agi/2;
				sd->paramb[2] += sd->status.vit+psd->status.vit/2 > 99 ? 99-sd->status.vit : psd->status.vit/2;
				sd->paramb[3] += sd->status.int_+psd->status.int_/2 > 99 ? 99-sd->status.int_ : psd->status.int_/2;
				sd->paramb[4] += sd->status.dex+psd->status.dex/2 > 99 ? 99-sd->status.dex : psd->status.dex/2;
				sd->paramb[5] += sd->status.luk+psd->status.luk/2 > 99 ? 99-sd->status.luk : psd->status.luk/2;
			}
		}
	}

	// Calculate total stats
	sd->paramc[0]=sd->status.str+sd->paramb[0]+sd->parame[0];
	sd->paramc[1]=sd->status.agi+sd->paramb[1]+sd->parame[1];
	sd->paramc[2]=sd->status.vit+sd->paramb[2]+sd->parame[2];
	sd->paramc[3]=sd->status.int_+sd->paramb[3]+sd->parame[3];
	sd->paramc[4]=sd->status.dex+sd->paramb[4]+sd->parame[4];
	sd->paramc[5]=sd->status.luk+sd->paramb[5]+sd->parame[5];

	if(sd->sc.count){
		if(sd->sc.data[SC_SPIRIT].timer!=-1 && sd->sc.data[SC_SPIRIT].val2 == SL_HIGH)
	  	{	//Ups any status under 50 to 50.
			if (sd->paramc[0] < 50) {
				sd->paramb[0] += 50-sd->paramc[0];
				sd->paramc[0] = 50;
			}
			if (sd->paramc[1] < 50) {
				sd->paramb[1] += 50-sd->paramc[1];
				sd->paramc[1] = 50;
			}
			if (sd->paramc[2] < 50) {
				sd->paramb[2] += 50-sd->paramc[2];
				sd->paramc[2] = 50;
			}
			if (sd->paramc[3] < 50) {
				sd->paramb[3] += 50-sd->paramc[3];
				sd->paramc[3] = 50;
			}
			if (sd->paramc[4] < 50) {
				sd->paramb[4] += 50-sd->paramc[4];
				sd->paramc[4] = 50;
			}
			if (sd->paramc[5] < 50) {
				sd->paramb[5] += 50-sd->paramc[5];
				sd->paramc[5] = 50;
			}
		}
	}
	for(i=0;i<6;i++)
		if(sd->paramc[i] < 0) sd->paramc[i] = 0;

	if (sd->sc.count && sd->sc.data[SC_CURSE].timer!=-1)
		sd->paramc[5] = 0;

// ------ BASE ATTACK CALCULATION ------

	// Basic Base ATK value
	switch(sd->status.weapon){
		case 11: // Bows
		case 13: // Musical Instruments
		case 14: // Whips
			str = sd->paramc[4];
			dex = sd->paramc[0];
			break;
		default:
			str = sd->paramc[0];
			dex = sd->paramc[4];
			break;
	}
	dstr = str/10;
	sd->base_atk += str + dstr*dstr + dex/5 + sd->paramc[5]/5;

	// Absolute modifiers from passive skills
	if((skill=pc_checkskill(sd,BS_HILTBINDING))>0)
		sd->base_atk += 4;

	// Absolute, then relative modifiers from status changes (shared between PC and NPC)
		sd->base_atk = status_calc_batk(&sd->bl,sd->base_atk);

	if(sd->base_atk < 1)
		sd->base_atk = 1;

// ----- WEAPON ATK CALCULATION -----

	// Absolute, then relative modifiers from status changes (shared between PC and NPC)
	sd->right_weapon.watk = status_calc_watk(&sd->bl,sd->right_weapon.watk);
	if((index= sd->equip_index[8]) >= 0 && sd->inventory_data[index] && sd->inventory_data[index]->type == 4)
		sd->left_weapon.watk = status_calc_watk(&sd->bl,sd->left_weapon.watk);

// ----- WEAPON UPGRADE ATK CALCULATION -----

	// Absolute modifiers from status changes (only for PC)
	if(sd->sc.count){
		if(sd->sc.data[SC_NIBELUNGEN].timer!=-1){
			index = sd->equip_index[9];
			if(index >= 0 && sd->inventory_data[index] && sd->inventory_data[index]->wlv == 4)
				sd->right_weapon.watk2 += sd->sc.data[SC_NIBELUNGEN].val2;
			index = sd->equip_index[8];
			if(index >= 0 && sd->inventory_data[index] && sd->inventory_data[index]->wlv == 4)
				sd->left_weapon.watk2 += sd->sc.data[SC_NIBELUNGEN].val2;
		}
	}

// ----- MATK CALCULATION -----

	// Basic MATK value
	sd->matk1 += sd->paramc[3]+(sd->paramc[3]/5)*(sd->paramc[3]/5);
	sd->matk2 += sd->paramc[3]+(sd->paramc[3]/7)*(sd->paramc[3]/7);
	if(sd->matk1 < sd->matk2) {
		int temp = sd->matk2;
		sd->matk2 = sd->matk1;
		sd->matk1 = temp;
	}

	// Absolute, then relative modifiers from status changes (shared between PC and NPC)
	sd->matk1 = status_calc_matk(&sd->bl,sd->matk1);
	sd->matk2 = status_calc_matk(&sd->bl,sd->matk2);

	// Apply relative modifiers from equipment
	if(sd->matk_rate != 100){
		sd->matk1 = sd->matk1 * sd->matk_rate/100;
		sd->matk2 = sd->matk2 * sd->matk_rate/100;
	}

// ----- CRIT CALCULATION -----

	// Basic Crit value
	sd->critical += (sd->paramc[5]*3)+10;

	// Absolute, then relative modifiers from status changes (shared between PC and NPC)
	sd->critical = status_calc_critical(&sd->bl,sd->critical);

	// Apply relative modifiers from equipment
	if(sd->critical_rate != 100)
		sd->critical = sd->critical * sd->critical_rate/100;

	if(sd->critical < 10) sd->critical = 10;

// ----- HIT CALCULATION -----

	// Basic Hit value
	sd->hit += sd->paramc[4] + sd->status.base_level;

	// Absolute modifiers from passive skills
	if((skill=pc_checkskill(sd,BS_WEAPONRESEARCH))>0)
		sd->hit += skill*2;
	if((skill=pc_checkskill(sd,AC_VULTURE))>0){
		sd->hit += skill;
		if(sd->status.weapon == 11)
			sd->attackrange += skill;
	}

	// Absolute, then relative modifiers from status changes (shared between PC and NPC)
	sd->hit = status_calc_hit(&sd->bl,sd->hit);

	// Apply relative modifiers from equipment
	if(sd->hit_rate != 100)
		sd->hit = sd->hit * sd->hit_rate/100;

	if(sd->hit < 1) sd->hit = 1;

// ----- FLEE CALCULATION -----

	// Basic Flee value
	sd->flee += sd->paramc[1] + sd->status.base_level;

	// Absolute modifiers from passive skills
	if((skill=pc_checkskill(sd,TF_MISS))>0)
		sd->flee += skill*(sd->class_&JOBL_2 && (sd->class_&MAPID_BASEMASK) == MAPID_THIEF? 4 : 3);
	if((skill=pc_checkskill(sd,MO_DODGE))>0)
		sd->flee += (skill*3)>>1;

	// Absolute, then relative modifiers from status changes (shared between PC and NPC)
	sd->flee = status_calc_flee(&sd->bl,sd->flee);

	// Apply relative modifiers from equipment
	if(sd->flee_rate != 100)
		sd->flee = sd->flee * sd->flee_rate/100;

	if(sd->flee < 1) sd->flee = 1;

// ----- PERFECT DODGE CALCULATION -----

	// Basic Perfect Dodge value
	sd->flee2 += sd->paramc[5]+10;

	// Absolute, then relative modifiers from status changes (shared between PC and NPC)
	sd->flee2 = status_calc_flee2(&sd->bl,sd->flee2);

	// Apply relative modifiers from equipment
	if(sd->flee2_rate != 100)
		sd->flee2 = sd->flee2 * sd->flee2_rate/100;

	if(sd->flee2 < 10) sd->flee2 = 10;

// ----- VIT-DEF CALCULATION -----

	// Special fixed values from status changes
	if(sd->sc.count && sd->sc.data[SC_BERSERK].timer!=-1)
		sd->def2 = 0;
	else if(sd->sc.count && sd->sc.data[SC_ETERNALCHAOS].timer!=-1)
		sd->def2 = 0;
	else {
		// Basic VIT-DEF value
		sd->def2 += sd->paramc[2];

		// Absolute, then relative modifiers from status changes (shared between PC and NPC)
		sd->def2 = status_calc_def2(&sd->bl,sd->def2);

		// Apply relative modifiers from equipment
		if(sd->def2_rate != 100)
			sd->def2 = sd->def2 * sd->def2_rate/100;

		if(sd->def2 < 1) sd->def2 = 1;
	}

// ----- EQUIPMENT-DEF CALCULATION -----

	// Absolute, then relative modifiers from status changes (shared between PC and NPC)
	sd->def = status_calc_def(&sd->bl,sd->def);

	// Apply relative modifiers from equipment
	if(sd->def_rate != 100)
		sd->def = sd->def * sd->def_rate/100;

	if(sd->def < 0) sd->def = 0;

	else if (!battle_config.player_defense_type && sd->def > battle_config.max_def)
	{
		sd->def2 += battle_config.over_def_bonus*(sd->def -battle_config.max_def);
		sd->def = battle_config.max_def;
	}

// ----- INT-MDEF CALCULATION -----

	// Special fixed values from status changes
	if(sd->sc.count && sd->sc.data[SC_BERSERK].timer!=-1)
		sd->mdef2 = 0;
	else {
		// Basic INT-MDEF value
		sd->mdef2 += sd->paramc[3];

		// sd->mdef2 = status_calc_mdef2(&sd->bl,sd->mdef2);

		// Apply relative modifiers from equipment
		if(sd->mdef2_rate != 100)
			sd->mdef2 = sd->mdef2 * sd->mdef2_rate/100;

		if(sd->mdef2 < 1) sd->mdef2 = 1;
	}

// ----- EQUIPMENT-MDEF CALCULATION -----

	// Absolute, then relative modifiers from status changes (shared between PC and NPC)
	sd->mdef = status_calc_mdef(&sd->bl,sd->mdef);

	// Apply relative modifiers from equipment
	if(sd->mdef_rate != 100)
		sd->mdef = sd->mdef * sd->mdef_rate/100;

	if(sd->mdef < 0) sd->mdef = 0;

	else if (!battle_config.player_defense_type && sd->mdef > battle_config.max_def)
	{
		sd->mdef2 += battle_config.over_def_bonus*(sd->mdef -battle_config.max_def);
		sd->mdef = battle_config.max_def;
	}
	
// ----- WALKING SPEED CALCULATION -----

	// Relative, then absolute modifiers from status changes (shared between PC and NPC)
	sd->speed = status_calc_speed(&sd->bl,sd->speed);

	// Relative modifiers from passive skills
	if((skill=pc_checkskill(sd,TF_MISS))>0 && (sd->class_&MAPID_UPPERMASK) == MAPID_ASSASSIN && sd->sc.data[SC_CLOAKING].timer==-1)
		sd->speed -= sd->speed * skill/100;
	if(pc_isriding(sd) && pc_checkskill(sd,KN_RIDING)>0)
		sd->speed -= sd->speed * 25/100;
	if(pc_ishiding(sd) && (skill=pc_checkskill(sd,RG_TUNNELDRIVE))>0)
		sd->speed += sd->speed * (100-16*skill)/100;
	if(pc_iscarton(sd) && (skill=pc_checkskill(sd,MC_PUSHCART))>0)
		sd->speed += sd->speed * (100-10*skill)/100;
 	if(sd->skilltimer != -1 && (skill=pc_checkskill(sd,SA_FREECAST))>0) {
		sd->prev_speed = sd->speed; //Store previous speed to correctly restore it. [Skotlex]
		sd->speed += sd->speed * (75-5*skill)/100;
	}
	if(sd->sc.count && sd->sc.data[SC_DANCING].timer!=-1){
			int s_rate = 500-40*pc_checkskill(sd,(sd->status.sex?BA_MUSICALLESSON:DC_DANCINGLESSON));
			if (sd->sc.data[SC_SPIRIT].timer != -1 && sd->sc.data[SC_SPIRIT].val2 == SL_BARDDANCER)
				s_rate -= 40; //TODO: Figure out real bonus rate.
			if (sd->sc.data[SC_LONGING].timer!=-1)
				s_rate -= 20 * sd->sc.data[SC_LONGING].val1;
			sd->speed += sd->speed * s_rate/100;
	}
	if(sd->sc.data[SC_FUSION].timer != -1) //Additional movement speed from SG_FUSION [Komurka]
		sd->speed -= sd->speed * 25/100;

	// Apply relative modifiers from equipment
	if(sd->speed_rate != 100)
		sd->speed = sd->speed*sd->speed_rate/100;

	if(sd->speed < battle_config.max_walk_speed)
		sd->speed = battle_config.max_walk_speed;

// ----- ASPD CALCULATION -----
// Unlike other stats, ASPD rate modifiers from skills/SCs/items/etc are first all added together, then the final modifier is applied

	// Basic ASPD value
	if (sd->status.weapon <= 16)
		sd->aspd += aspd_base[sd->status.class_][sd->status.weapon]-(sd->paramc[1]*4+sd->paramc[4])*aspd_base[sd->status.class_][sd->status.weapon]/1000;
	else
		sd->aspd += (
			(aspd_base[sd->status.class_][sd->weapontype1]-(sd->paramc[1]*4+sd->paramc[4])*aspd_base[sd->status.class_][sd->weapontype1]/1000) +
			(aspd_base[sd->status.class_][sd->weapontype2]-(sd->paramc[1]*4+sd->paramc[4])*aspd_base[sd->status.class_][sd->weapontype2]/1000)
			) *2/3; //From what I read in rodatazone, 2/3 should be more accurate than 0.7 -> 140 / 200; [Skotlex]

	// Relative modifiers from passive skills
	if((skill=pc_checkskill(sd,SA_ADVANCEDBOOK))>0)
		sd->aspd_rate -= (skill/2);
	if((skill = pc_checkskill(sd,SG_DEVIL)) > 0 && !pc_nextjobafter(sd))
		sd->aspd_rate -= (skill*3);

	if(pc_isriding(sd))
		sd->aspd_rate += 50-10*pc_checkskill(sd,KN_CAVALIERMASTERY);

	// Relative modifiers from status changes (shared between PC and NPC)
	sd->aspd_rate = status_calc_aspd_rate(&sd->bl,sd->aspd_rate);

	// Apply all relative modifiers
	if(sd->aspd_rate != 100)
		sd->aspd = sd->aspd*sd->aspd_rate/100;

	if(sd->aspd < battle_config.max_aspd) sd->aspd = battle_config.max_aspd;
	sd->amotion = sd->aspd;

// ----- HP MAX AND REGEN CALCULATION -----

	// Basic MaxHP value
	// here we recycle variable index, and do this calc apart to avoid mixing up the 30% bonus with card bonuses. [Skotlex]
	bl = sd->status.base_level;
	index = (3500 + bl*hp_coefficient2[sd->status.class_] +
		hp_sigma_val[sd->status.class_][(bl > 0)? bl-1:0])/100 *
		(100 + sd->paramc[2])/100 + (sd->parame[2] - sd->paramcard[2]);
	if (sd->class_&JOBL_UPPER)
		index += index * 30/100;
	else if (sd->class_&JOBL_BABY)
		index -= index * 30/100;
	if ((sd->class_&MAPID_UPPERMASK) == MAPID_TAEKWON && sd->status.base_level >= 90 && pc_istop10fame(sd->char_id, MAPID_TAEKWON))
		index *= 3; //Triple max HP for top ranking Taekwons over level 90.
	
	sd->status.max_hp += index;

	if((sd->class_&MAPID_UPPERMASK) == MAPID_SUPER_NOVICE && sd->status.base_level >= 99)
		sd->status.max_hp = sd->status.max_hp + 2000;

	// Absolute modifiers from passive skills
	if((skill=pc_checkskill(sd,CR_TRUST))>0)
		sd->status.max_hp += skill*200;

	// Absolute, then relative modifiers from status changes (shared between PC and NPC)
	sd->status.max_hp = status_calc_maxhp(&sd->bl,sd->status.max_hp);

	// Apply relative modifiers from equipment
	if(sd->hprate!=100)
		sd->status.max_hp = sd->status.max_hp * sd->hprate/100;

	if(sd->status.max_hp > battle_config.max_hp)
		sd->status.max_hp = battle_config.max_hp;
	if(sd->status.hp>sd->status.max_hp)
		sd->status.hp=sd->status.max_hp;
	if(sd->status.max_hp <= 0) sd->status.max_hp = 1;

	// Basic natural HP regeneration value
	sd->nhealhp = 1 + (sd->paramc[2]/5) + (sd->status.max_hp/200);

	// Apply relative modifiers from equipment
	if(sd->hprecov_rate != 100)
		sd->nhealhp = sd->nhealhp*sd->hprecov_rate/100;

	if(sd->nhealhp < 1) sd->nhealhp = 1;
	if(sd->nhealhp > 0x7fff) sd->nhealhp = 0x7fff;

	// Skill-related HP recovery
	if((skill=pc_checkskill(sd,SM_RECOVERY)) > 0)
		sd->nshealhp = skill*5 + (sd->status.max_hp*skill/500);
	// Skill-related HP recovery (only when sit)
	if((skill=pc_checkskill(sd,MO_SPIRITSRECOVERY)) > 0)
		sd->nsshealhp = skill*4 + (sd->status.max_hp*skill/500);
	if((skill=pc_checkskill(sd,TK_HPTIME)) > 0 && sd->state.rest == 1)
		sd->nsshealhp = skill*30 + (sd->status.max_hp*skill/500);

	if(sd->nshealhp > 0x7fff) sd->nshealhp = 0x7fff;
	if(sd->nsshealhp > 0x7fff) sd->nsshealhp = 0x7fff;

// ----- SP MAX AND REGEN CALCULATION -----

	// Basic MaxSP value
	// here we recycle variable index, and do this calc apart to avoid mixing up the 30% bonus with card bonuses. [Skotlex]
	index = ((sp_coefficient[sd->status.class_] * bl) + 1000)/100 * (100 + sd->paramc[3])/100 + (sd->parame[3] - sd->paramcard[3]);
	if (sd->class_&JOBL_UPPER)
		index += index * 30/100;
	else if (sd->class_&JOBL_BABY)
		index -= index * 30/100;
	if ((sd->class_&MAPID_UPPERMASK) == MAPID_TAEKWON && sd->status.base_level >= 90 && pc_istop10fame(sd->char_id, MAPID_TAEKWON))
		index *= 3; //Triple max SP for top ranking Taekwons over level 90.
	
	sd->status.max_sp += index;

	// Absolute modifiers from passive skills
	if((skill=pc_checkskill(sd,SL_KAINA))>0)
		sd->status.max_sp += 30*skill;
	if((skill=pc_checkskill(sd,HP_MEDITATIO))>0)
		sd->status.max_sp += sd->status.max_sp * skill/100;
	if((skill=pc_checkskill(sd,HW_SOULDRAIN))>0)
		sd->status.max_sp += sd->status.max_sp * 2*skill/100;

	// Absolute, then relative modifiers from status changes (shared between PC and NPC)
	sd->status.max_sp = status_calc_maxsp(&sd->bl,sd->status.max_sp);

	// Apply relative modifiers from equipment
	if(sd->sprate!=100)
		sd->status.max_sp = sd->status.max_sp * sd->sprate/100;

	if(sd->status.max_sp > battle_config.max_sp)
		sd->status.max_sp = battle_config.max_sp;
	if(sd->status.sp>sd->status.max_sp)
		sd->status.sp=sd->status.max_sp;
	if(sd->status.max_sp <= 0) sd->status.max_sp = 1;

	if(sd->sc.data[SC_DANCING].timer==-1){
		// Basic natural SP regeneration value
		sd->nhealsp = 1 + (sd->paramc[3]/6) + (sd->status.max_sp/100);
		if(sd->paramc[3] >= 120)
			sd->nhealsp += ((sd->paramc[3]-120)>>1) + 4;

		// Relative modifiers from passive skills
		if((skill=pc_checkskill(sd,HP_MEDITATIO)) > 0)
			sd->nhealsp += sd->nhealsp * 3*skill/100;

		// Apply relative modifiers from equipment
		if(sd->sprecov_rate != 100)
			sd->nhealsp = sd->nhealsp*sd->sprecov_rate/100;

		if(sd->nhealsp < 1) sd->nhealsp = 1;
		if(sd->nhealsp > 0x7fff) sd->nhealsp = 0x7fff;

		// Skill-related SP recovery
		if((skill=pc_checkskill(sd,MG_SRECOVERY)) > 0)
			sd->nshealsp = skill*3 + (sd->status.max_sp*skill/500);
		// Skill-related SP recovery (only when sit)
		if((skill = pc_checkskill(sd,MO_SPIRITSRECOVERY)) > 0)
			sd->nsshealsp = skill*2 + (sd->status.max_sp*skill/500);
		if((skill=pc_checkskill(sd,TK_SPTIME)) > 0 && sd->state.rest == 1) {
			sd->nsshealsp = skill*3 + (sd->status.max_sp*skill/500);
			if ((skill=pc_checkskill(sd,SL_KAINA)) > 0) //Power up Enjoyable Rest
				sd->nsshealsp += (30+10*skill)*sd->nsshealsp/100;
		}
		if(sd->nshealsp > 0x7fff) sd->nshealsp = 0x7fff;
		if(sd->nsshealsp > 0x7fff) sd->nsshealsp = 0x7fff;
	}

// ----- MISC CALCULATIONS -----

	//Even though people insist this is too slow, packet data reports this is the actual real equation.
	sd->dmotion = 800-sd->paramc[1]*4;
	if(sd->dmotion<400)	sd->dmotion = 400;

	// Weight
	if((skill=pc_checkskill(sd,MC_INCCARRY))>0)
		sd->max_weight += 2000*skill;
	if(pc_isriding(sd) && pc_checkskill(sd,KN_RIDING)>0)
		sd->max_weight += 10000;
	if( (skill=pc_checkskill(sd,SG_KNOWLEDGE))>0) //SG skill [Komurka]
		if(sd->bl.m == sd->feel_map[0].m || sd->bl.m == sd->feel_map[1].m || sd->bl.m == sd->feel_map[2].m)
			sd->max_weight += sd->max_weight*skill/10;

	// Skill SP cost
	if((skill=pc_checkskill(sd,HP_MANARECHARGE))>0 )
		sd->dsprate -= 4*skill;

	if(sd->sc.count){
		if(sd->sc.data[SC_SERVICE4U].timer!=-1)
			sd->dsprate -= sd->sc.data[SC_SERVICE4U].val3;
	}

	if(sd->dsprate < 0) sd->dsprate = 0;

	// Anti-element and anti-race
	if((skill=pc_checkskill(sd,CR_TRUST))>0)
		sd->subele[6] += skill*5;
	if((skill=pc_checkskill(sd,BS_SKINTEMPER))>0) {
		sd->subele[0] += skill;
		sd->subele[3] += skill*4;
	}
	if((skill=pc_checkskill(sd,SA_DRAGONOLOGY))>0 ){
		skill = skill*4;
		sd->right_weapon.addrace[9]+=skill;
		sd->left_weapon.addrace[9]+=skill;
		sd->magic_addrace[9]+=skill;
		sd->subrace[9]+=skill;
	}

	if(sd->sc.count){
       	if(sd->sc.data[SC_SIEGFRIED].timer!=-1){
			sd->subele[1] += sd->sc.data[SC_SIEGFRIED].val2;
			sd->subele[2] += sd->sc.data[SC_SIEGFRIED].val2;
			sd->subele[3] += sd->sc.data[SC_SIEGFRIED].val2;
			sd->subele[4] += sd->sc.data[SC_SIEGFRIED].val2;
			sd->subele[5] += sd->sc.data[SC_SIEGFRIED].val2;
			sd->subele[6] += sd->sc.data[SC_SIEGFRIED].val2;
			sd->subele[7] += sd->sc.data[SC_SIEGFRIED].val2;
			sd->subele[8] += sd->sc.data[SC_SIEGFRIED].val2;
			sd->subele[9] += sd->sc.data[SC_SIEGFRIED].val2;
		}
		if(sd->sc.data[SC_PROVIDENCE].timer!=-1){
			sd->subele[6] += sd->sc.data[SC_PROVIDENCE].val2;
			sd->subrace[6] += sd->sc.data[SC_PROVIDENCE].val2;
		}
	}

// ----- CLIENT-SIDE REFRESH -----
	if(first&1) { //Since this is the initial loading, the Falcon and Peco icons must be loaded. [Skotlex]
		if (sd->sc.option&OPTION_FALCON)
			clif_status_load(&sd->bl, SI_FALCON, 1);
		if (sd->sc.option&OPTION_RIDING)
			clif_status_load(&sd->bl, SI_RIDING, 1);
	}
	if(first&4) {
		calculating = 0;
		return 0;
	}
	if(first&3) {
		clif_updatestatus(sd,SP_SPEED);
		clif_updatestatus(sd,SP_MAXHP);
		clif_updatestatus(sd,SP_MAXSP);
		if(first&1) {
			clif_updatestatus(sd,SP_HP);
			clif_updatestatus(sd,SP_SP);
		}
		calculating = 0;
		return 0;
	}

	
	if(sd->sc.data[SC_WEDDING].timer != -1 && sd->view_class != JOB_WEDDING)
		sd->view_class=JOB_WEDDING;
	
	if(sd->sc.data[SC_XMAS].timer != -1 && sd->view_class != JOB_XMAS)
		sd->view_class=JOB_XMAS;

	if(b_class != sd->view_class) {
		clif_changelook(&sd->bl,LOOK_BASE,sd->view_class);
#if PACKETVER < 4
		clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
		clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
#else
		clif_changelook(&sd->bl,LOOK_WEAPON,0);
#endif
	//Restoring cloth dye color after the view class changes. [Skotlex]
	// Added Xmas Suit [Valaris]
	if(battle_config.save_clothcolor && sd->status.clothes_color > 0 &&
		((sd->view_class != JOB_WEDDING && sd->view_class !=JOB_XMAS) || (sd->view_class==JOB_WEDDING && !battle_config.wedding_ignorepalette) ||
			 (sd->view_class==JOB_XMAS && !battle_config.xmas_ignorepalette)))
			clif_changelook(&sd->bl,LOOK_CLOTHES_COLOR,sd->status.clothes_color);
	}

	if( memcmp(b_skill,sd->status.skill,sizeof(sd->status.skill)) || b_attackrange != sd->attackrange)
		clif_skillinfoblock(sd);

	if(b_speed != sd->speed)
		clif_updatestatus(sd,SP_SPEED);
	if(b_weight != sd->weight)
		clif_updatestatus(sd,SP_WEIGHT);
	if(b_max_weight != sd->max_weight) {
		clif_updatestatus(sd,SP_MAXWEIGHT);
		pc_checkweighticon(sd);
	}
	for(i=0;i<6;i++)
		if(b_paramb[i] + b_parame[i] != sd->paramb[i] + sd->parame[i])
			clif_updatestatus(sd,SP_STR+i);
	if(b_hit != sd->hit)
		clif_updatestatus(sd,SP_HIT);
	if(b_flee != sd->flee)
		clif_updatestatus(sd,SP_FLEE1);
	if(b_aspd != sd->aspd)
		clif_updatestatus(sd,SP_ASPD);
	if(b_watk != sd->right_weapon.watk || b_base_atk != sd->base_atk)
		clif_updatestatus(sd,SP_ATK1);
	if(b_def != sd->def)
		clif_updatestatus(sd,SP_DEF1);
	if(b_watk2 != sd->right_weapon.watk2)
		clif_updatestatus(sd,SP_ATK2);
	if(b_def2 != sd->def2)
		clif_updatestatus(sd,SP_DEF2);
	if(b_flee2 != sd->flee2)
		clif_updatestatus(sd,SP_FLEE2);
	if(b_critical != sd->critical)
		clif_updatestatus(sd,SP_CRITICAL);
	if(b_matk1 != sd->matk1)
		clif_updatestatus(sd,SP_MATK1);
	if(b_matk2 != sd->matk2)
		clif_updatestatus(sd,SP_MATK2);
	if(b_mdef != sd->mdef)
		clif_updatestatus(sd,SP_MDEF1);
	if(b_mdef2 != sd->mdef2)
		clif_updatestatus(sd,SP_MDEF2);
	if(b_attackrange != sd->attackrange)
		clif_updatestatus(sd,SP_ATTACKRANGE);
	if(b_max_hp != sd->status.max_hp)
		clif_updatestatus(sd,SP_MAXHP);
	if(b_max_sp != sd->status.max_sp)
		clif_updatestatus(sd,SP_MAXSP);
	if(b_hp != sd->status.hp)
		clif_updatestatus(sd,SP_HP);
	if(b_sp != sd->status.sp)
		clif_updatestatus(sd,SP_SP);

	/* I don't think there's a need for this here. It should be handled in pc_damage and pc_heal. [Skotlex]
	if(sd->status.hp<sd->status.max_hp>>2 && sd->sc.data[SC_AUTOBERSERK].timer!=-1 &&
		(sd->sc.data[SC_PROVOKE].timer==-1 || sd->sc.data[SC_PROVOKE].val2==0) && !pc_isdead(sd))
		status_change_start(&sd->bl,SC_PROVOKE,10,1,0,0,0,0);
	*/
	calculating = 0;
	return 0;
}

/*==========================================
 * Apply shared stat mods from status changes [DracoRPG]
 *------------------------------------------
 */
int status_calc_str(struct block_list *bl, int str)
{
	struct status_change *sc;
	nullpo_retr(str,bl);
	sc= status_get_sc(bl);

	if(sc && sc->count){
		if(sc->data[SC_INCALLSTATUS].timer!=-1)
			str += sc->data[SC_INCALLSTATUS].val1;
		if(sc->data[SC_INCSTR].timer!=-1)
			str += sc->data[SC_INCSTR].val1;
		if(sc->data[SC_STRFOOD].timer!=-1)
			str += sc->data[SC_STRFOOD].val1;
		if(sc->data[SC_LOUD].timer!=-1)
			str += 4;
  		if(sc->data[SC_TRUESIGHT].timer!=-1)
			str += 5;
		if(sc->data[SC_SPURT].timer!=-1)
			str += 10; //Bonus is +!0 regardless of skill level
		if(sc->data[SC_BLESSING].timer != -1){
			int race = status_get_race(bl);
			if(battle_check_undead(race,status_get_elem_type(bl)) || race == 6)
				str >>= 1;
			else str += sc->data[SC_BLESSING].val1;
		}
	}

	return str;
}

int status_calc_agi(struct block_list *bl, int agi)
{
	struct status_change *sc;
	nullpo_retr(agi,bl);
	sc = status_get_sc(bl);

	if(sc && sc->count){
		if(sc->data[SC_INCALLSTATUS].timer!=-1)
			agi += sc->data[SC_INCALLSTATUS].val1;
		if(sc->data[SC_INCAGI].timer!=-1)
			agi += sc->data[SC_INCAGI].val1;
		if(sc->data[SC_AGIFOOD].timer!=-1)
			agi += sc->data[SC_AGIFOOD].val1;
  		if(sc->data[SC_TRUESIGHT].timer!=-1)
			agi += 5;
		if(sc->data[SC_INCREASEAGI].timer!=-1)
			agi += 2 + sc->data[SC_INCREASEAGI].val1;
		if(sc->data[SC_DECREASEAGI].timer!=-1)
			agi -= 2 + sc->data[SC_DECREASEAGI].val1;
		if(sc->data[SC_QUAGMIRE].timer!=-1)
			agi -= sc->data[SC_QUAGMIRE].val1*(bl->type==BL_PC?5:10);
	}

	return agi;
}

int status_calc_vit(struct block_list *bl, int vit)
{
	struct status_change *sc;
	nullpo_retr(vit,bl);
	sc = status_get_sc(bl);

	if(sc && sc->count){
		if(sc->data[SC_INCALLSTATUS].timer!=-1)
			vit += sc->data[SC_INCALLSTATUS].val1;
		if(sc->data[SC_INCVIT].timer!=-1)
			vit += sc->data[SC_INCVIT].val1;
		if(sc->data[SC_VITFOOD].timer!=-1)
			vit += sc->data[SC_VITFOOD].val1;
  		if(sc->data[SC_TRUESIGHT].timer!=-1)
			vit += 5;
		if(sc->data[SC_STRIPARMOR].timer!=-1 && bl->type != BL_PC)
			vit -= vit * 8*sc->data[SC_STRIPARMOR].val1/100;
	}

	return vit;
}

int status_calc_int(struct block_list *bl, int int_)
{
	struct status_change *sc;
	nullpo_retr(int_,bl);
	sc = status_get_sc(bl);

	if(sc && sc->count){
		if(sc->data[SC_INCALLSTATUS].timer!=-1)
			int_ += sc->data[SC_INCALLSTATUS].val1;
		if(sc->data[SC_INCINT].timer!=-1)
			int_ += sc->data[SC_INCINT].val1;
		if(sc->data[SC_INTFOOD].timer!=-1)
			int_ += sc->data[SC_INTFOOD].val1;
  		if(sc->data[SC_TRUESIGHT].timer!=-1)
			int_ += 5;
		if(sc->data[SC_BLESSING].timer != -1){
			int race = status_get_race(bl);
			if(battle_check_undead(race,status_get_elem_type(bl)) || race == 6)
				int_ >>= 1;
			else int_ += sc->data[SC_BLESSING].val1;
		}
		if(sc->data[SC_STRIPHELM].timer!=-1 && bl->type != BL_PC)
			int_ -= int_ * 8*sc->data[SC_STRIPHELM].val1/100;
	}

	return int_;
}

int status_calc_dex(struct block_list *bl, int dex)
{
	struct status_change *sc;
	nullpo_retr(dex,bl);
	sc = status_get_sc(bl);

	if(sc && sc->count){
		if(sc->data[SC_INCALLSTATUS].timer!=-1)
			dex += sc->data[SC_INCALLSTATUS].val1;
		if(sc->data[SC_INCDEX].timer!=-1)
			dex += sc->data[SC_INCDEX].val1;
		if(sc->data[SC_DEXFOOD].timer!=-1)
			dex += sc->data[SC_DEXFOOD].val1;
  		if(sc->data[SC_TRUESIGHT].timer!=-1)
			dex += 5;
		if(sc->data[SC_QUAGMIRE].timer!=-1)
			dex -= sc->data[SC_QUAGMIRE].val1*(bl->type==BL_PC?5:10);
		if(sc->data[SC_BLESSING].timer != -1){
			int race = status_get_race(bl);
			if(battle_check_undead(race,status_get_elem_type(bl)) || race == 6)
				dex >>= 1;
			else dex += sc->data[SC_BLESSING].val1;
		}
	}

	return dex;
}

int status_calc_luk(struct block_list *bl, int luk)
{
	struct status_change *sc;
	nullpo_retr(luk,bl);
	sc = status_get_sc(bl);

	if(sc && sc->count){
		if(sc->data[SC_INCALLSTATUS].timer!=-1)
			luk += sc->data[SC_INCALLSTATUS].val1;
		if(sc->data[SC_INCLUK].timer!=-1)
			luk += sc->data[SC_INCLUK].val1;
		if(sc->data[SC_LUKFOOD].timer!=-1)
			luk += sc->data[SC_LUKFOOD].val1;
  		if(sc->data[SC_TRUESIGHT].timer!=-1)
			luk += 5;
  		if(sc->data[SC_GLORIA].timer!=-1)
			luk += 30;
	}

	return luk;
}

int status_calc_batk(struct block_list *bl, int batk)
{
	struct status_change *sc;
	nullpo_retr(batk,bl);
	sc = status_get_sc(bl);

	if(sc && sc->count){
		if(sc->data[SC_ATKPOTION].timer!=-1)
			batk += sc->data[SC_ATKPOTION].val1;
		if(sc->data[SC_BATKFOOD].timer!=-1)
			batk += sc->data[SC_BATKFOOD].val1;
		if(sc->data[SC_INCATKRATE].timer!=-1)
			batk += batk * sc->data[SC_INCATKRATE].val1/100;
		if(sc->data[SC_PROVOKE].timer!=-1)
			batk += batk * (2+3*sc->data[SC_PROVOKE].val1)/100;
		if(sc->data[SC_CONCENTRATION].timer!=-1)
			batk += batk * 5*sc->data[SC_CONCENTRATION].val1/100;
		if(sc->data[SC_SKE].timer!=-1)
			batk += batk * 3;
		if(sc->data[SC_JOINTBEAT].timer!=-1 && sc->data[SC_JOINTBEAT].val2==4)
  			batk -= batk * 25/100;
		if(sc->data[SC_CURSE].timer!=-1)
  			batk -= batk * 25/100;
		if(sc->data[SC_BLEEDING].timer != -1)
			batk -= batk * 25/100;
	}

	return batk;
}

int status_calc_watk(struct block_list *bl, int watk)
{
	struct status_change *sc;
	nullpo_retr(watk,bl);
	sc = status_get_sc(bl);

	if(sc && sc->count){
		if(sc->data[SC_IMPOSITIO].timer!=-1)
			watk += 5*sc->data[SC_IMPOSITIO].val1;
		if(sc->data[SC_WATKFOOD].timer!=-1)
			watk += sc->data[SC_WATKFOOD].val1;
		if(sc->data[SC_DRUMBATTLE].timer!=-1)
			watk += sc->data[SC_DRUMBATTLE].val2;
		if(sc->data[SC_VOLCANO].timer!=-1 && status_get_elem_type(bl)==3)
			watk += sc->data[SC_VOLCANO].val3;
		if(sc->data[SC_INCATKRATE].timer!=-1)
			watk += watk * sc->data[SC_INCATKRATE].val1/100;
		if(sc->data[SC_PROVOKE].timer!=-1)
			watk += watk * (2+3*sc->data[SC_PROVOKE].val1)/100;
		if(sc->data[SC_CONCENTRATION].timer!=-1)
			watk += watk * 5*sc->data[SC_CONCENTRATION].val1/100;
		if(sc->data[SC_SKE].timer!=-1)
			watk += watk * 3;
		if(sc->data[SC_NIBELUNGEN].timer!=-1 && bl->type != BL_PC && (status_get_element(bl)/10)>=8)
			watk += sc->data[SC_NIBELUNGEN].val2;
		if(sc->data[SC_EXPLOSIONSPIRITS].timer!=-1 && bl->type != BL_PC)
			watk += (1000*sc->data[SC_EXPLOSIONSPIRITS].val1);
		if(sc->data[SC_CURSE].timer!=-1)
			watk -= watk * 25/100;
		if(sc->data[SC_STRIPWEAPON].timer!=-1 && bl->type != BL_PC)
			watk -= watk * 5*sc->data[SC_STRIPWEAPON].val1/100;
	}
	return watk;
}

int status_calc_matk(struct block_list *bl, int matk)
{
	struct status_change *sc;
	nullpo_retr(matk,bl);
	sc = status_get_sc(bl);

	if(sc && sc->count){
		if(sc->data[SC_MATKPOTION].timer!=-1)
			matk += sc->data[SC_MATKPOTION].val1;
		if(sc->data[SC_MATKFOOD].timer!=-1)
			matk += sc->data[SC_MATKFOOD].val1;
		if(sc->data[SC_MAGICPOWER].timer!=-1)
			matk += matk * 5*sc->data[SC_MAGICPOWER].val1/100;
		if(sc->data[SC_MINDBREAKER].timer!=-1)
			matk += matk * 20*sc->data[SC_MINDBREAKER].val1/100;
		if(sc->data[SC_INCMATKRATE].timer!=-1)
			matk += matk * sc->data[SC_INCMATKRATE].val1/100;
	}

	return matk;
}

int status_calc_critical(struct block_list *bl, int critical)
{
	struct status_change *sc;
	nullpo_retr(critical,bl);
	sc = status_get_sc(bl);

	if(sc && sc->count){
		if (sc->data[SC_EXPLOSIONSPIRITS].timer!=-1)
			critical += sc->data[SC_EXPLOSIONSPIRITS].val2;
		if (sc->data[SC_FORTUNE].timer!=-1)
			critical += sc->data[SC_FORTUNE].val2*10;
		if (sc->data[SC_TRUESIGHT].timer!=-1)
			critical += sc->data[SC_TRUESIGHT].val1*10;
		if(sc->data[SC_CLOAKING].timer!=-1)
			critical += critical;
	}

	return critical;
}

int status_calc_hit(struct block_list *bl, int hit)
{
	struct status_change *sc;
	nullpo_retr(hit,bl);
	sc = status_get_sc(bl);

	if(sc && sc->count){
		if(sc->data[SC_INCHIT].timer != -1)
			hit += sc->data[SC_INCHIT].val1;
		if(sc->data[SC_HITFOOD].timer!=-1)
			hit += sc->data[SC_HITFOOD].val1;
		if(sc->data[SC_TRUESIGHT].timer != -1)
			hit += 3*sc->data[SC_TRUESIGHT].val1;
		if(sc->data[SC_HUMMING].timer!=-1)
			hit += sc->data[SC_HUMMING].val2;
		if(sc->data[SC_CONCENTRATION].timer != -1)
			hit += 10*sc->data[SC_CONCENTRATION].val1;
		if(sc->data[SC_INCHITRATE].timer != -1)
			hit += hit * sc->data[SC_INCHITRATE].val1/100;
		if(sc->data[SC_BLIND].timer != -1)
			hit -= hit * 25 / 100;
	}

	return hit;
}

int status_calc_flee(struct block_list *bl, int flee)
{
	struct status_change *sc;
	nullpo_retr(flee,bl);
	sc = status_get_sc(bl);

	if(sc && sc->count){
		if(sc->data[SC_INCFLEE].timer!=-1)
			flee += sc->data[SC_INCFLEE].val1;
		if(sc->data[SC_FLEEFOOD].timer!=-1)
			flee += sc->data[SC_FLEEFOOD].val1;
		if(sc->data[SC_WHISTLE].timer!=-1)
			flee += sc->data[SC_WHISTLE].val2;
		if(sc->data[SC_WINDWALK].timer!=-1)
			flee += flee * sc->data[SC_WINDWALK].val2/100;
		if(sc->data[SC_INCFLEERATE].timer!=-1)
			flee += flee * sc->data[SC_INCFLEERATE].val1/100;
		if(sc->data[SC_VIOLENTGALE].timer!=-1 && status_get_elem_type(bl)==4)
			flee += flee * sc->data[SC_VIOLENTGALE].val3/100;
		if(sc->data[SC_MOON_COMFORT].timer!=-1) //SG skill [Komurka]
			flee += (status_get_lv(bl) + status_get_dex(bl) + status_get_luk(bl))/10;
		if(sc->data[SC_CLOSECONFINE].timer!=-1)
			flee += 10;
		if(sc->data[SC_SPIDERWEB].timer!=-1)
			flee -= flee * 50/100;
		if(sc->data[SC_BERSERK].timer!=-1)
			flee -= flee * 50/100;
		if(sc->data[SC_BLIND].timer!=-1)
			flee -= flee * 25/100;
	}

	if (bl->type == BL_PC && map_flag_gvg(bl->m)) //GVG grounds flee penalty, placed here because it's "like" a status change. [Skotlex]
		flee -= flee * battle_config.gvg_flee_penalty/100;
	return flee;
}

int status_calc_flee2(struct block_list *bl, int flee2)
{
	struct status_change *sc;
	nullpo_retr(flee2,bl);
	sc = status_get_sc(bl);

	if(sc && sc->count){
		if(sc->data[SC_WHISTLE].timer!=-1)
			flee2 += sc->data[SC_WHISTLE].val3*10;
	}

	return flee2;
}

int status_calc_def(struct block_list *bl, int def)
{
	struct status_change *sc;
	nullpo_retr(def,bl);
	sc = status_get_sc(bl);

	if(sc && sc->count){
		if(sc->data[SC_BERSERK].timer!=-1)
			return 0;
		if(sc->data[SC_KEEPING].timer!=-1)
			return 100;
		if(sc->data[SC_STEELBODY].timer!=-1)
			return 90;
		if(sc->data[SC_SKA].timer != -1) // [marquis007]
			return 90;
		if(sc->data[SC_DRUMBATTLE].timer!=-1)
			def += sc->data[SC_DRUMBATTLE].val3;
		if(sc->data[SC_INCDEFRATE].timer!=-1)
			def += def * sc->data[SC_INCDEFRATE].val1/100;
		if(sc->data[SC_SIGNUMCRUCIS].timer!=-1)
			def -= def * sc->data[SC_SIGNUMCRUCIS].val2/100;
		if(sc->data[SC_CONCENTRATION].timer!=-1)
			def -= def * 5*sc->data[SC_CONCENTRATION].val1/100;
		if(sc->data[SC_SKE].timer!=-1)
			def -= def  * 50/100;
		if(sc->data[SC_PROVOKE].timer!=-1 && bl->type != BL_PC) // Provoke doesn't alter player defense.
			def -= def * (5+5*sc->data[SC_PROVOKE].val1)/100;
		if(sc->data[SC_STRIPSHIELD].timer!=-1 && bl->type != BL_PC)
			def -= def * 3*sc->data[SC_STRIPSHIELD].val1/100;
	}

	return def;
}

int status_calc_def2(struct block_list *bl, int def2)
{
	struct status_change *sc;
	nullpo_retr(def2,bl);
	sc = status_get_sc(bl);

	if(sc && sc->count){
		if(sc->data[SC_BERSERK].timer!=-1)
			return 0;
		if(sc->data[SC_ETERNALCHAOS].timer!=-1)
			return 0;
		if(sc->data[SC_SUN_COMFORT].timer!=-1)
			def2 += (status_get_lv(bl) + status_get_dex(bl) + status_get_luk(bl))/2;
		if(sc->data[SC_ANGELUS].timer!=-1)
			def2 += def2 * (10+5*sc->data[SC_ANGELUS].val1)/100;
		if(sc->data[SC_CONCENTRATION].timer!=-1)
			def2 -= def2 * 5*sc->data[SC_CONCENTRATION].val1/100;
		if(sc->data[SC_POISON].timer!=-1)
			def2 -= def2 * 25/100;
		if(sc->data[SC_SKE].timer!=-1)
			def2 -= def2 * 50/100;
		if(sc->data[SC_PROVOKE].timer!=-1)
			def2 -= def2 * (5+5*sc->data[SC_PROVOKE].val1)/100;
		if(sc->data[SC_SKE].timer!=-1)
			def2 /= 2;
		if(sc->data[SC_JOINTBEAT].timer!=-1){
			if(sc->data[SC_JOINTBEAT].val2==3)
				def2 -= def2 * 50/100;
			else if(sc->data[SC_JOINTBEAT].val2==4)
				def2 -= def2 * 25/100;
		}
	}

	return def2;
}

int status_calc_mdef(struct block_list *bl, int mdef)
{
	struct status_change *sc;
	nullpo_retr(mdef,bl);
	sc = status_get_sc(bl);

	if(sc && sc->count){
		if(sc->data[SC_BERSERK].timer!=-1)
			return 0;
		if(sc->data[SC_BARRIER].timer!=-1)
			return 100;
		if(sc->data[SC_STEELBODY].timer!=-1)
			return 90;
		if(sc->data[SC_SKA].timer != -1) // [marquis007]
			return 90; // should it up mdef too?
		if(sc->data[SC_ENDURE].timer!=-1)
			mdef += sc->data[SC_ENDURE].val1;
	}

	return mdef;
}

int status_calc_mdef2(struct block_list *bl, int mdef2)
{
	struct status_change *sc;
	nullpo_retr(mdef2,bl);
	sc = status_get_sc(bl);

	if(sc && sc->count){
		if(sc->data[SC_BERSERK].timer!=-1)
			return 0;
		if(sc->data[SC_MINDBREAKER].timer!=-1)
			mdef2 -= mdef2 * 12*sc->data[SC_MINDBREAKER].val1/100;
	}

	return mdef2;
}

int status_calc_speed(struct block_list *bl, int speed)
{
	struct status_change *sc;
	sc = status_get_sc(bl);

	if(sc && sc->count) {
		if(sc->data[SC_CURSE].timer!=-1)
			speed += 450;
		if(sc->data[SC_SWOO].timer != -1) // [marquis007]
			speed += 450; //Let's use Curse's slow down momentarily (exact value unknown)
		if(sc->data[SC_SPEEDUP1].timer!=-1)
			speed -= speed*50/100;
		else if(sc->data[SC_SPEEDUP0].timer!=-1)
			speed -= speed*25/100;
		else if(sc->data[SC_INCREASEAGI].timer!=-1)
			speed -= speed * 25/100;
		else if(sc->data[SC_CARTBOOST].timer!=-1)
			speed -= speed * 20/100;
		else if(sc->data[SC_BERSERK].timer!=-1)
			speed -= speed * 20/100;
		else if(sc->data[SC_WINDWALK].timer!=-1)
			speed -= speed * 4*sc->data[SC_WINDWALK].val2/100;
		if(sc->data[SC_WEDDING].timer!=-1)
			speed += speed * 50/100;
		if(sc->data[SC_SLOWDOWN].timer!=-1)
			speed += speed * 50/100;
		if(sc->data[SC_DECREASEAGI].timer!=-1)
			speed += speed * 25/100;
		if(sc->data[SC_STEELBODY].timer!=-1)
			speed += speed * 25/100;
		if(sc->data[SC_SKA].timer!=-1)
			speed += speed * 25/100;
		if(sc->data[SC_QUAGMIRE].timer!=-1)
			speed += speed * 50/100;
		if(sc->data[SC_DONTFORGETME].timer!=-1)
			speed += speed * sc->data[SC_DONTFORGETME].val3/100;
		if(sc->data[SC_DEFENDER].timer!=-1)
			speed += speed * (55-5*sc->data[SC_DEFENDER].val1)/100;
		if(sc->data[SC_GOSPEL].timer!=-1 && sc->data[SC_GOSPEL].val4 == BCT_ENEMY)
			speed += speed * 25/100;
		if(sc->data[SC_JOINTBEAT].timer!=-1) {
			if (sc->data[SC_JOINTBEAT].val2 == 0)
				speed += speed * 50/100;
			else if (sc->data[SC_JOINTBEAT].val2 == 2)
				speed += speed * 30/100;
		}
		if(sc->data[SC_CLOAKING].timer!=-1)
			speed = speed * (sc->data[SC_CLOAKING].val3-3*sc->data[SC_CLOAKING].val1) /100;
		if(sc->data[SC_CHASEWALK].timer!=-1)
			speed = speed * sc->data[SC_CHASEWALK].val3/100;
		if(sc->data[SC_RUN].timer!=-1)/*�삯���ɂ�鑬�x�ω�*/
			speed -= speed * 25/100;
	}

	return speed;
}

int status_calc_aspd_rate(struct block_list *bl, int aspd_rate)
{
	struct status_change *sc;
	sc = status_get_sc(bl);

	if(sc && sc->count) {
		int i;
		if(sc->data[SC_QUAGMIRE].timer==-1 && sc->data[SC_DONTFORGETME].timer==-1){
			if(sc->data[SC_TWOHANDQUICKEN].timer!=-1)
				aspd_rate -= 30;
			else if(sc->data[SC_ONEHAND].timer!=-1)
				aspd_rate -= 30;
			else if(sc->data[SC_ADRENALINE2].timer!=-1)
				aspd_rate -= (sc->data[SC_ADRENALINE2].val2 || !battle_config.party_skill_penalty)?30:20;
			else if(sc->data[SC_ADRENALINE].timer!=-1)
				aspd_rate -= (sc->data[SC_ADRENALINE].val2 || !battle_config.party_skill_penalty)?30:20;
			else if(sc->data[SC_SPEARSQUICKEN].timer!=-1)
				aspd_rate -= sc->data[SC_SPEARSQUICKEN].val2;
			else if(sc->data[SC_ASSNCROS].timer!=-1 && (bl->type!=BL_PC || ((struct map_session_data*)bl)->status.weapon != 11))
				aspd_rate -= sc->data[SC_ASSNCROS].val2;
		}
		if(sc->data[SC_BERSERK].timer!=-1)
			aspd_rate -= 30;
		if(sc->data[i=SC_ASPDPOTION3].timer!=-1 || sc->data[i=SC_ASPDPOTION2].timer!=-1 || sc->data[i=SC_ASPDPOTION1].timer!=-1 || sc->data[i=SC_ASPDPOTION0].timer!=-1)
			aspd_rate -= sc->data[i].val2;
		if(sc->data[SC_DONTFORGETME].timer!=-1)
			aspd_rate += sc->data[SC_DONTFORGETME].val2;
		if(sc->data[SC_STEELBODY].timer!=-1)
			aspd_rate += 25;
		if(sc->data[SC_SKA].timer!=-1)
			aspd_rate += 25;
		if(sc->data[SC_DEFENDER].timer != -1)
			aspd_rate += 25 -sc->data[SC_DEFENDER].val1*5;
		if(sc->data[SC_GOSPEL].timer!=-1 && sc->data[SC_GOSPEL].val4 == BCT_ENEMY)
			aspd_rate += 25;
		if(sc->data[SC_GRAVITATION].timer!=-1)
			aspd_rate += sc->data[SC_GRAVITATION].val2;
		if(sc->data[SC_BLEEDING].timer != -1)
			aspd_rate += 25;
		if(sc->data[SC_JOINTBEAT].timer!=-1) {
			if (sc->data[SC_JOINTBEAT].val2 == 1)
				aspd_rate += 25;
			else if (sc->data[SC_JOINTBEAT].val2 == 2)
				aspd_rate += 10;
		}
		if(sc->data[SC_STAR_COMFORT].timer!=-1)
			aspd_rate -= (status_get_lv(bl) + status_get_dex(bl) + status_get_luk(bl))/10;
	}

	return aspd_rate;
}

int status_calc_maxhp(struct block_list *bl, int maxhp)
{
	struct status_change *sc;
	sc = status_get_sc(bl);

	if(sc && sc->count) {
		if(sc->data[SC_INCMHPRATE].timer!=-1)
			maxhp += maxhp * sc->data[SC_INCMHPRATE].val1/100;
		if(sc->data[SC_APPLEIDUN].timer!=-1)
			maxhp += maxhp * sc->data[SC_APPLEIDUN].val2/100;
		if(sc->data[SC_DELUGE].timer!=-1 && status_get_elem_type(bl)==1)
			maxhp += maxhp * deluge_eff[sc->data[SC_DELUGE].val1-1]/100;
		if(sc->data[SC_BERSERK].timer!=-1)
			maxhp += maxhp * 2;
	}

	return maxhp;
}

int status_calc_maxsp(struct block_list *bl, int maxsp)
{
	struct status_change *sc;
	sc = status_get_sc(bl);

	if(sc && sc->count) {
		if(sc->data[SC_INCMSPRATE].timer!=-1)
			maxsp += maxsp * sc->data[SC_INCMSPRATE].val1/100;
		if(sc->data[SC_SERVICE4U].timer!=-1)
			maxsp += maxsp * sc->data[SC_SERVICE4U].val2/100;
	}

	return maxsp;
}

/*==========================================
 * For quick calculating [Celest] Adapted by [Skotlex]
 *------------------------------------------
 */
int status_quick_recalc_speed(struct map_session_data *sd, int skill_num, int skill_lv, char start)
{
	/*	[Skotlex]
	This function individually changes a character's speed upon a skill change and restores it upon it's ending.
	Should only be used on non-inclusive skills to avoid exploits.
	Currently used for freedom of cast
	and when cloaking changes it's val3 (in which case the new val3 value comes in the level.
	*/
	
	int b_speed;
	
	b_speed = sd->speed;
	
	switch (skill_num)
	{
		case SA_FREECAST:
			if (start)
			{
				sd->prev_speed = sd->speed;
				sd->speed = sd->speed*(175 - skill_lv*5)/100;
			}
			else
				sd->speed = sd->prev_speed;
			break;
		case AS_CLOAKING:
			if (start && sd->sc.data[SC_CLOAKING].timer != -1)
			{	//There shouldn't be an "stop" case here.
				//If the previous upgrade was 
				//SPEED_ADD_RATE(3*sd->sc.data[SC_CLOAKING].val1 -sd->sc.data[SC_CLOAKING].val3);
				//Then just changing val3 should be a net difference of....
				if (3*sd->sc.data[SC_CLOAKING].val1 != sd->sc.data[SC_CLOAKING].val3)	//This reverts the previous value.
					sd->speed = sd->speed * 100 /(sd->sc.data[SC_CLOAKING].val3-3*sd->sc.data[SC_CLOAKING].val1);
				sd->sc.data[SC_CLOAKING].val3 = skill_lv;
					sd->speed = sd->speed * (sd->sc.data[SC_CLOAKING].val3-sd->sc.data[SC_CLOAKING].val1*3) /100;
			}
			break;
	}

	if(sd->speed < battle_config.max_walk_speed)
		sd->speed = battle_config.max_walk_speed;

	if(b_speed != sd->speed)
		clif_updatestatus(sd,SP_SPEED);

	return 0;
}

/*==========================================
 * �Ώۂ�Class��Ԃ�(�ėp)
 * �߂�͐�����0�ȏ�
 *------------------------------------------
 */
int status_get_class(struct block_list *bl)
{
	nullpo_retr(0, bl);
	if(bl->type==BL_MOB)
		return ((struct mob_data *)bl)->class_;
	if(bl->type==BL_PC)
		return ((struct map_session_data *)bl)->status.class_;
	if(bl->type==BL_PET)
		return ((struct pet_data *)bl)->class_;
	return 0;
}
/*==========================================
 * �Ώۂ̕�����Ԃ�(�ėp)
 * �߂�͐�����0�ȏ�
 *------------------------------------------
 */
int status_get_dir(struct block_list *bl)
{
	nullpo_retr(0, bl);
	if(bl->type==BL_MOB)
		return ((struct mob_data *)bl)->dir;
	if(bl->type==BL_PC)
		return ((struct map_session_data *)bl)->dir;
	if(bl->type==BL_PET)
		return ((struct pet_data *)bl)->dir;
	return 0;
}
/*==========================================
 * �Ώۂ̃��x����Ԃ�(�ėp)
 * �߂�͐�����0�ȏ�
 *------------------------------------------
 */
int status_get_lv(struct block_list *bl)
{
	nullpo_retr(0, bl);
	if(bl->type==BL_MOB)
		return ((struct mob_data *)bl)->level;
	if(bl->type==BL_PC)
		return ((struct map_session_data *)bl)->status.base_level;
	if(bl->type==BL_PET)
		return ((struct pet_data *)bl)->msd->pet.level;
	return 0;
}

/*==========================================
 * �Ώۂ̎˒���Ԃ�(�ėp)
 * �߂�͐�����0�ȏ�
 *------------------------------------------
 */
int status_get_range(struct block_list *bl)
{
	nullpo_retr(0, bl);
	if(bl->type==BL_MOB)
		return ((struct mob_data *)bl)->db->range;
	if(bl->type==BL_PC)
		return ((struct map_session_data *)bl)->attackrange;
	if(bl->type==BL_PET)
		return ((struct pet_data *)bl)->db->range;
	return 0;
}
/*==========================================
 * �Ώۂ�HP��Ԃ�(�ėp)
 * �߂�͐�����0�ȏ�
 *------------------------------------------
 */
int status_get_hp(struct block_list *bl)
{
	nullpo_retr(1, bl);
	if(bl->type==BL_MOB)
		return ((struct mob_data *)bl)->hp;
	if(bl->type==BL_PC)
		return ((struct map_session_data *)bl)->status.hp;
	return 1;
}
/*==========================================
 * �Ώۂ�MHP��Ԃ�(�ėp)
 * �߂�͐�����0�ȏ�
 *------------------------------------------
 */
int status_get_max_hp(struct block_list *bl)
{
	nullpo_retr(1, bl);

	if(bl->type==BL_PC)
		return ((struct map_session_data *)bl)->status.max_hp;
	else {
		int max_hp = 1;

		if(bl->type == BL_MOB) {
			struct mob_data *md;
			nullpo_retr(1, md = (struct mob_data *)bl);
			max_hp = md->max_hp;

			if(battle_config.mobs_level_up) // mobs leveling up increase [Valaris]
				max_hp += (md->level - md->db->lv) * status_get_vit(bl);

		}
		else if(bl->type == BL_PET) {
			struct pet_data *pd;
			nullpo_retr(1, pd = (struct pet_data*)bl);
			max_hp = pd->db->max_hp;
		}

		max_hp = status_calc_maxhp(bl,max_hp);
		if(max_hp < 1) max_hp = 1;
		return max_hp;
	}
}
/*==========================================
 * �Ώۂ�Str��Ԃ�(�ėp)
 * �߂�͐�����0�ȏ�
 *------------------------------------------
 */
int status_get_str(struct block_list *bl)
{
	int str = 0;
	nullpo_retr(0, bl);

	if (bl->type == BL_PC)
		return ((struct map_session_data *)bl)->paramc[0];
	else {
		if(bl->type == BL_MOB) {
			str = ((struct mob_data *)bl)->db->str;
			if(battle_config.mobs_level_up) // mobs leveling up increase [Valaris]
				str += ((struct mob_data *)bl)->level - ((struct mob_data *)bl)->db->lv;
			if(((struct mob_data*)bl)->special_state.size==1) // change for sized monsters [Valaris]
				str/=2;
			else if(((struct mob_data*)bl)->special_state.size==2)
				str*=2;
		} else if(bl->type == BL_PET){	//<Skotlex> Use pet's stats
			if (battle_config.pet_lv_rate && ((struct pet_data *)bl)->status)
				str = ((struct pet_data *)bl)->status->str;
			else
				str = ((struct pet_data *)bl)->db->str;
		}

		str = status_calc_str(bl,str);
	}
	if(str < 0) str = 0;
	return str;
}
/*==========================================
 * �Ώۂ�Agi��Ԃ�(�ėp)
 * �߂�͐�����0�ȏ�
 *------------------------------------------
 */

int status_get_agi(struct block_list *bl)
{
	int agi=0;
	nullpo_retr(0, bl);

	if(bl->type==BL_PC)
		return ((struct map_session_data *)bl)->paramc[1];
	else {
		if(bl->type == BL_MOB) {
			agi = ((struct mob_data *)bl)->db->agi;
			if(battle_config.mobs_level_up) // increase of mobs leveling up [Valaris]
				agi += ((struct mob_data *)bl)->level - ((struct mob_data *)bl)->db->lv;
			if(((struct mob_data*)bl)->special_state.size==1) // change for sized monsters [Valaris]
				agi/=2;
			else if(((struct mob_data*)bl)->special_state.size==2)
				agi*=2;
		} else if(bl->type == BL_PET) {	//<Skotlex> Use pet's stats
			if (battle_config.pet_lv_rate && ((struct pet_data *)bl)->status)
				agi = ((struct pet_data *)bl)->status->agi;
			else
				agi = ((struct pet_data *)bl)->db->agi;
		}

		agi = status_calc_agi(bl,agi);
	}
	if(agi < 0) agi = 0;
	return agi;
}
/*==========================================
 * �Ώۂ�Vit��Ԃ�(�ėp)
 * �߂�͐�����0�ȏ�
 *------------------------------------------
 */
int status_get_vit(struct block_list *bl)
{
	int vit = 0;
	nullpo_retr(0, bl);

	if(bl->type == BL_PC)
		return ((struct map_session_data *)bl)->paramc[2];
	else {
		if(bl->type == BL_MOB) {
			vit = ((struct mob_data *)bl)->db->vit;
			if(battle_config.mobs_level_up) // increase from mobs leveling up [Valaris]
				vit += ((struct mob_data *)bl)->level - ((struct mob_data *)bl)->db->lv;
			if(((struct mob_data*)bl)->special_state.size==1) // change for sizes monsters [Valaris]
				vit/=2;
			else if(((struct mob_data*)bl)->special_state.size==2)
				vit*=2;
		} else if(bl->type == BL_PET) {	//<Skotlex> Use pet's stats
			if (battle_config.pet_lv_rate && ((struct pet_data *)bl)->status)
				vit = ((struct pet_data *)bl)->status->vit;
			else
				vit = ((struct pet_data *)bl)->db->vit;
		}

		vit = status_calc_vit(bl,vit);
	}
	if(vit < 0) vit = 0;
	return vit;
}
/*==========================================
 * �Ώۂ�Int��Ԃ�(�ėp)
 * �߂�͐�����0�ȏ�
 *------------------------------------------
 */
int status_get_int(struct block_list *bl)
{
	int int_=0;
	nullpo_retr(0, bl);

	if(bl->type == BL_PC)
		return ((struct map_session_data *)bl)->paramc[3];
	else {
		if(bl->type == BL_MOB) {
			int_ = ((struct mob_data *)bl)->db->int_;
			if(battle_config.mobs_level_up) // increase from mobs leveling up [Valaris]
				int_ += ((struct mob_data *)bl)->level - ((struct mob_data *)bl)->db->lv;
			if(((struct mob_data*)bl)->special_state.size==1) // change for sized monsters [Valaris]
				int_/=2;
			else if(((struct mob_data*)bl)->special_state.size==2)
				int_*=2;
		} else if(bl->type == BL_PET) {	//<Skotlex> Use pet's stats
			if (battle_config.pet_lv_rate && ((struct pet_data *)bl)->status)
				int_ = ((struct pet_data *)bl)->status->int_;
			else
				int_ = ((struct pet_data *)bl)->db->int_;
		}

		int_ = status_calc_int(bl,int_);
	}
	if(int_ < 0) int_ = 0;
	return int_;
}
/*==========================================
 * �Ώۂ�Dex��Ԃ�(�ėp)
 * �߂�͐�����0�ȏ�
 *------------------------------------------
 */
int status_get_dex(struct block_list *bl)
{
	int dex = 0;
	nullpo_retr(0, bl);

	if(bl->type==BL_PC)
		return ((struct map_session_data *)bl)->paramc[4];
	else {
		if(bl->type == BL_MOB) {
			dex = ((struct mob_data *)bl)->db->dex;
			if(battle_config.mobs_level_up) // increase from mobs leveling up [Valaris]
				dex += ((struct mob_data *)bl)->level - ((struct mob_data *)bl)->db->lv;
			if(((struct mob_data*)bl)->special_state.size==1) // change for sized monsters [Valaris]
				dex/=2;
			else if(((struct mob_data*)bl)->special_state.size==2)
				dex*=2;
		} else if(bl->type == BL_PET) {	//<Skotlex> Use pet's stats
			if (battle_config.pet_lv_rate && ((struct pet_data *)bl)->status)
				dex = ((struct pet_data *)bl)->status->dex;
			else
				dex = ((struct pet_data *)bl)->db->dex;
		}

		dex = status_calc_dex(bl,dex);
	}
	if(dex < 0) dex = 0;
	return dex;
}
/*==========================================
 * �Ώۂ�Luk��Ԃ�(�ėp)
 * �߂�͐�����0�ȏ�
 *------------------------------------------
 */
int status_get_luk(struct block_list *bl)
{
	int luk = 0;
	nullpo_retr(0, bl);

	if(bl->type == BL_PC)
		return ((struct map_session_data *)bl)->paramc[5];
	else {
		if(bl->type == BL_MOB) {
			luk = ((struct mob_data *)bl)->db->luk;
			if(battle_config.mobs_level_up) // increase from mobs leveling up [Valaris]
				luk += ((struct mob_data *)bl)->level - ((struct mob_data *)bl)->db->lv;
			if(((struct mob_data*)bl)->special_state.size==1) // change for sized monsters [Valaris]
				luk/=2;
			else if(((struct mob_data*)bl)->special_state.size==2)
				luk*=2;
		} else if(bl->type == BL_PET) {	//<Skotlex> Use pet's stats
			if (battle_config.pet_lv_rate && ((struct pet_data *)bl)->status)
				luk = ((struct pet_data *)bl)->status->luk;
			else
				luk = ((struct pet_data *)bl)->db->luk;
		}

		luk = status_calc_luk(bl,luk);
	}
	if(luk < 0) luk = 0;
	return luk;
}

/*==========================================
 * �Ώۂ�Flee��Ԃ�(�ėp)
 * �߂�͐�����1�ȏ�
 *------------------------------------------
 */
int status_get_flee(struct block_list *bl)
{
	int flee = 1;
	nullpo_retr(1, bl);

	if(bl->type == BL_PC)
		return ((struct map_session_data *)bl)->flee;
	
	flee = status_calc_flee(bl,status_get_agi(bl)+status_get_lv(bl));
	if(flee < 1) flee = 1;
	return flee;
}
/*==========================================
 * �Ώۂ�Hit��Ԃ�(�ėp)
 * �߂�͐�����1�ȏ�
 *------------------------------------------
 */
int status_get_hit(struct block_list *bl)
{
	int hit = 1;
	nullpo_retr(1, bl);
	if (bl->type == BL_PC)
		return ((struct map_session_data *)bl)->hit;
	
	hit = status_calc_hit(bl,status_get_dex(bl)+status_get_lv(bl));
	if(hit < 1) hit = 1;
	return hit;
}
/*==========================================
 * �Ώۂ̊��S�����Ԃ�(�ėp)
 * �߂�͐�����1�ȏ�
 *------------------------------------------
 */
int status_get_flee2(struct block_list *bl)
{
	int flee2 = 1;
	nullpo_retr(1, bl);

	if (bl->type == BL_PC) 
		return ((struct map_session_data *)bl)->flee2;

	flee2 = status_calc_flee2(bl,status_get_luk(bl)+10);
	if (flee2 < 1) flee2 = 1;
	return flee2;
}
/*==========================================
 * �Ώۂ̃N���e�B�J����Ԃ�(�ėp)
 * �߂�͐�����1�ȏ�
 *------------------------------------------
 */
int status_get_critical(struct block_list *bl)
{
	int critical = 1;
	nullpo_retr(1, bl);

	if (bl->type == BL_PC)
		return ((struct map_session_data *)bl)->critical;

	critical = status_get_luk(bl)*3+10;
	if(battle_config.enemy_critical_rate != 100)
		critical = critical*battle_config.enemy_critical_rate/100;
	critical = status_calc_critical(bl,critical);
	if (critical < 1) critical = 1;
	return critical;
}
/*==========================================
 * base_atk�̎擾
 * �߂�͐�����1�ȏ�
 *------------------------------------------
 */
int status_get_batk(struct block_list *bl)
{
	int batk = 1;
	nullpo_retr(1, bl);
	
	if(bl->type==BL_PC) {
		batk = ((struct map_session_data *)bl)->base_atk;
		if (((struct map_session_data *)bl)->status.weapon < 16)
			batk += ((struct map_session_data *)bl)->weapon_atk[((struct map_session_data *)bl)->status.weapon];
	} else {
		int str,dstr;
		str = status_get_str(bl); //STR
		dstr = str/10;
		batk = dstr*dstr + str; //base_atk���v�Z����

		if(bl->type == BL_MOB && ((struct mob_data *)bl)->guardian_data)
			batk += batk * 10*((struct mob_data *)bl)->guardian_data->guardup_lv/100; // Strengthen Guardians - custom value +10% ATK / lv

		batk = status_calc_batk(bl,batk);
	}
	if(batk < 1) batk = 1; //base_atk�͍Œ�ł�1
	return batk;
}
/*==========================================
 * �Ώۂ�Atk��Ԃ�(�ėp)
 * �߂�͐�����0�ȏ�
 *------------------------------------------
 */
int status_get_atk(struct block_list *bl)
{
	int atk=0;
	nullpo_retr(0, bl);
	switch (bl->type) {
		case BL_PC:
			return ((struct map_session_data*)bl)->right_weapon.watk;
		case BL_MOB:
			atk = ((struct mob_data*)bl)->db->atk1;
			if(((struct mob_data *)bl)->guardian_data)
				atk += atk * 10*((struct mob_data *)bl)->guardian_data->guardup_lv/100; // Strengthen Guardians - custom value +10% ATK / lv
		break;
		case BL_PET:	//<Skotlex> Use pet's stats
			if (battle_config.pet_lv_rate && ((struct pet_data *)bl)->status)
				atk = ((struct pet_data *)bl)->status->atk1;
			else
				atk = ((struct pet_data*)bl)->db->atk1;
		break;
	}
	// Absolute, then relative modifiers from status changes (shared between PC and NPC)
	atk = status_calc_watk(bl,atk);
	if(atk < 0) atk = 0;
	return atk;
}
/*==========================================
 * �Ώۂ̍���Atk��Ԃ�(�ėp)
 * �߂�͐�����0�ȏ�
 *------------------------------------------
 */
int status_get_atk_(struct block_list *bl)
{
	nullpo_retr(0, bl);
	if(bl->type==BL_PC){
		return ((struct map_session_data*)bl)->left_weapon.watk;
	}
	return 0;
}
/*==========================================
 * �Ώۂ�Atk2��Ԃ�(�ėp)
 * �߂�͐�����0�ȏ�
 *------------------------------------------
 */
int status_get_atk2(struct block_list *bl)
{
	int atk2=0;
	nullpo_retr(0, bl);

	switch (bl->type) {
		case BL_PC:
			return ((struct map_session_data*)bl)->right_weapon.watk2;
		case BL_MOB:
			atk2 = ((struct mob_data*)bl)->db->atk2;
			
			if(((struct mob_data *)bl)->guardian_data)
				atk2 += atk2 * 10*((struct mob_data *)bl)->guardian_data->guardup_lv/100; // Strengthen Guardians - custom value +10% ATK / lv
		break;
		case BL_PET:	//<Skotlex> Use pet's stats
			if (battle_config.pet_lv_rate && ((struct pet_data *)bl)->status)
				atk2 = ((struct pet_data *)bl)->status->atk2;
			else
				atk2 = ((struct pet_data*)bl)->db->atk2;
		break;
	}		  

	// Absolute, then relative modifiers from status changes (shared between PC and NPC)
	atk2 = status_calc_watk(bl,atk2);

	if(atk2 < 0) atk2 = 0;
		return atk2;
}
/*==========================================
 * �Ώۂ̍���Atk2��Ԃ�(�ėp)
 * �߂�͐�����0�ȏ�
 *------------------------------------------
 */
int status_get_atk_2(struct block_list *bl)
{
	nullpo_retr(0, bl);
	if(bl->type==BL_PC)
		return ((struct map_session_data*)bl)->left_weapon.watk2;
	return 0;
}
/*==========================================
 * �Ώۂ�MAtk1��Ԃ�(�ėp)
 * �߂�͐�����0�ȏ�
 *------------------------------------------
 */
int status_get_matk1(struct block_list *bl)
{
	nullpo_retr(0, bl);

	if(bl->type == BL_PC)
		return ((struct map_session_data *)bl)->matk1;
	else {
		int matk = 0;
		int int_ = status_get_int(bl);
		matk = status_calc_matk(bl,int_+(int_/5)*(int_/5));
 		return matk;
	}
}
/*==========================================
 * �Ώۂ�MAtk2��Ԃ�(�ėp)
 * �߂�͐�����0�ȏ�
 *------------------------------------------
 */
int status_get_matk2(struct block_list *bl)
{
	nullpo_retr(0, bl);

	if(bl->type == BL_PC)
		return ((struct map_session_data *)bl)->matk2;
	else {
        int matk = 0;
		int int_ = status_get_int(bl);
		matk = status_calc_matk(bl,int_+(int_/7)*(int_/7));
		return matk;
	}
}
/*==========================================
 * �Ώۂ�Def��Ԃ�(�ėp)
 * �߂�͐�����0�ȏ�
 *------------------------------------------
 */
int status_get_def(struct block_list *bl)
{
	int def=0;
	nullpo_retr(0, bl);

	if(bl->type==BL_PC){
		def = ((struct map_session_data *)bl)->def;
		if(((struct map_session_data *)bl)->skilltimer != -1)
			def -= def * skill_get_castdef(((struct map_session_data *)bl)->skillid)/100;
	} else if(bl->type==BL_MOB) {
		def = ((struct mob_data *)bl)->db->def;
		def -= def * skill_get_castdef(((struct mob_data *)bl)->skillid)/100;
	} else if(bl->type==BL_PET)
		def = ((struct pet_data *)bl)->db->def;

	def = status_calc_def(bl,def);
	if(def < 0) def = 0;

	return def;
}
/*==========================================
 * �Ώۂ�Def2��Ԃ�(�ėp)
 * �߂�͐�����1�ȏ�
 *------------------------------------------
 */
int status_get_def2(struct block_list *bl)
{
	int def2 = 1;
	nullpo_retr(1, bl);
	
	if(bl->type==BL_PC)
		return ((struct map_session_data *)bl)->def2;
	else if(bl->type==BL_MOB)
		def2 = ((struct mob_data *)bl)->db->vit;
	else if(bl->type==BL_PET) {	//<Skotlex> Use pet's stats
		if (battle_config.pet_lv_rate && ((struct pet_data *)bl)->status)
			def2 = ((struct pet_data *)bl)->status->vit;
		else
			def2 = ((struct pet_data *)bl)->db->vit;
	}

	def2 = status_calc_def2(bl,def2);
	if(def2 < 1) def2 = 1;
	
	return def2;
}
/*==========================================
 * �Ώۂ�MDef��Ԃ�(�ėp)
 * �߂�͐�����0�ȏ�
 *------------------------------------------
 */
int status_get_mdef(struct block_list *bl)
{
	int mdef=0;
	nullpo_retr(0, bl);

	if(bl->type==BL_PC)
		return ((struct map_session_data *)bl)->mdef;
	else if(bl->type==BL_MOB)
		mdef = ((struct mob_data *)bl)->db->mdef;
	else if(bl->type==BL_PET)
		mdef = ((struct pet_data *)bl)->db->mdef;

	mdef = status_calc_mdef(bl,mdef);
	if(mdef < 0) mdef = 0;

 	return mdef;
}
/*==========================================
 * �Ώۂ�MDef2��Ԃ�(�ėp)
 * �߂�͐�����0�ȏ�
 *------------------------------------------
 */
int status_get_mdef2(struct block_list *bl)
{
	int mdef2=0;
	nullpo_retr(0, bl);

	if(bl->type == BL_PC)
		return ((struct map_session_data *)bl)->mdef2 + (((struct map_session_data *)bl)->paramc[2]>>1);
	else if(bl->type == BL_MOB)
		mdef2 = ((struct mob_data *)bl)->db->int_ + (((struct mob_data *)bl)->db->vit>>1);
	else if(bl->type == BL_PET) {	//<Skotlex> Use pet's stats
		if (battle_config.pet_lv_rate && ((struct pet_data *)bl)->status)
			mdef2 = ((struct pet_data *)bl)->status->int_ +(((struct pet_data *)bl)->status->vit>>1);
		else
			mdef2 = ((struct pet_data *)bl)->db->int_ + (((struct pet_data *)bl)->db->vit>>1);
	}

	mdef2 = status_calc_mdef2(bl,mdef2);
	if(mdef2 < 0) mdef2 = 0;
	
	return mdef2;
}
/*==========================================
 * �Ώۂ�Speed(�ړ����x)��Ԃ�(�ėp)
 * �߂�͐�����1�ȏ�
 * Speed�͏������ق����ړ����x������
 *------------------------------------------
 */
int status_get_speed(struct block_list *bl)
{
	int speed = 1000;
	nullpo_retr(1000, bl);
	if(bl->type==BL_PC)
		return ((struct map_session_data *)bl)->speed;
	else if(bl->type==BL_MOB) {
		speed = ((struct mob_data *)bl)->speed;
		if(battle_config.mobs_level_up) // increase from mobs leveling up [Valaris]
			speed-=((struct mob_data *)bl)->level - ((struct mob_data *)bl)->db->lv;
	}
	else if(bl->type==BL_PET)
		speed = ((struct pet_data *)bl)->msd->petDB->speed;
	else if(bl->type==BL_NPC)	//Added BL_NPC (Skotlex)
		speed = ((struct npc_data *)bl)->speed;

	speed = status_calc_speed(bl,speed);

	if(speed < 1) speed = 1;
	return speed;
}
/*==========================================
 * �Ώۂ�aDelay(�U�����f�B���C)��Ԃ�(�ėp)
 * aDelay�͏������ق����U�����x������
 *------------------------------------------
 */
int status_get_adelay(struct block_list *bl)
{
	int adelay,aspd_rate;
	nullpo_retr(4000, bl);
	switch (bl->type) {
		case BL_PC:
			return (((struct map_session_data *)bl)->aspd<<1);
		case BL_MOB:
			adelay = ((struct mob_data *)bl)->db->adelay;
			if(((struct mob_data *)bl)->guardian_data)
				aspd_rate = 100 - 10*((struct mob_data *)bl)->guardian_data->guardup_lv; // Strengthen Guardians - custom value +10% ASPD / lv
			else
				aspd_rate = 100;
			break;
		case BL_PET:
			adelay = ((struct pet_data *)bl)->db->adelay;
			aspd_rate = 100;
			break;
		default:
			adelay=4000;
			aspd_rate = 100;
			break;
	}
	aspd_rate = status_calc_aspd_rate(bl,aspd_rate);

	if(aspd_rate != 100)
		adelay = adelay*aspd_rate/100;
	if(adelay < battle_config.monster_max_aspd<<1) adelay = battle_config.monster_max_aspd<<1;
		return adelay;
}
int status_get_amotion(struct block_list *bl)
{
	nullpo_retr(2000, bl);
	if(bl->type==BL_PC)
		return ((struct map_session_data *)bl)->amotion;
	else {
		int amotion=2000,aspd_rate = 100;
		if(bl->type==BL_MOB) {
			amotion = ((struct mob_data *)bl)->db->amotion;

			if(((struct mob_data *)bl)->guardian_data)
				aspd_rate -= aspd_rate * 10*((struct mob_data *)bl)->guardian_data->guardup_lv/100; // Strengthen Guardians - custom value +10% ASPD / lv
		} else if(bl->type==BL_PET)
			amotion = ((struct pet_data *)bl)->db->amotion;

		aspd_rate = status_calc_aspd_rate(bl,aspd_rate);

		if(aspd_rate != 100)
			amotion = amotion*aspd_rate/100;
		if(amotion < battle_config.monster_max_aspd) amotion = battle_config.monster_max_aspd;
		return amotion;
	}
	return 2000;
}
int status_get_dmotion(struct block_list *bl)
{
	int ret;
	struct status_change *sc;

	nullpo_retr(0, bl);
	sc = status_get_sc(bl);
	if(bl->type==BL_MOB){
		ret=((struct mob_data *)bl)->db->dmotion;
		if(battle_config.monster_damage_delay_rate != 100)
			ret = ret*battle_config.monster_damage_delay_rate/100;
	}
	else if(bl->type==BL_PC){
		ret=((struct map_session_data *)bl)->dmotion;
		if(battle_config.pc_damage_delay_rate != 100)
			ret = ret*battle_config.pc_damage_delay_rate/100;
	}
	else if(bl->type==BL_PET)
		ret=((struct pet_data *)bl)->db->dmotion;
	else
		return 2000;

	if(sc && sc->count && (sc->data[SC_ENDURE].timer!=-1 || sc->data[SC_CONCENTRATION].timer!=-1 || sc->data[SC_BERSERK].timer!=-1))
		if (!map_flag_gvg(bl->m)) //Only works on non-gvg grounds. [Skotlex]
			return 0;

	return ret;
}
int status_get_element(struct block_list *bl)
{
	// removed redundant variable ret [zzo]
	struct status_change *sc= status_get_sc(bl);

	nullpo_retr(20, bl);

	if(sc && sc->count) {
		if( sc->data[SC_BENEDICTIO].timer!=-1 )	// ���̍~��
			return 26;
		if( sc->data[SC_FREEZE].timer!=-1 )	// ����
			return 21;
		if( sc->data[SC_STONE].timer!=-1 && sc->data[SC_STONE].val2==0)
			return 22;
	}
	if(bl->type==BL_MOB)	// 10�̈ʁ�Lv*2�A�P�̈ʁ�����
		return ((struct mob_data *)bl)->def_ele;
	if(bl->type==BL_PC)
		return 20+((struct map_session_data *)bl)->def_ele;	// �h�䑮��Lv1
	if(bl->type==BL_PET)
		return ((struct pet_data *)bl)->db->element;

	return 20;
}
//Retrieves the object's element acquired by status changes only.
int status_get_attack_sc_element(struct block_list *bl)
{
	struct status_change *sc =status_get_sc(bl);
	if(sc && sc->count) {
		if( sc->data[SC_WATERWEAPON].timer!=-1)	// �t���X�g�E�F�|��
			return 1;
		if( sc->data[SC_EARTHWEAPON].timer!=-1)	// �T�C�Y�~�b�N�E�F�|��
			return 2;
		if( sc->data[SC_FIREWEAPON].timer!=-1)	// �t���[�������`���[
			return 3;
		if( sc->data[SC_WINDWEAPON].timer!=-1)	// ���C�g�j���O���[�_�[
			return 4;
		if( sc->data[SC_ENCPOISON].timer!=-1)	// �G���`�����g�|�C�Y��
			return 5;
		if( sc->data[SC_ASPERSIO].timer!=-1)		// �A�X�y���V�I
			return 6;
		if( sc->data[SC_SHADOWWEAPON].timer!=-1)
			return 7;
		if( sc->data[SC_GHOSTWEAPON].timer!=-1)
			return 8;
	}
	return 0;
}


int status_get_attack_element(struct block_list *bl)
{
	int ret = status_get_attack_sc_element(bl);

	nullpo_retr(0, bl);
	
	if (ret)	return ret;
	
	if(bl->type==BL_MOB && (struct mob_data *)bl)
		return 0;
	if(bl->type==BL_PC && (struct map_session_data *)bl)
		return ((struct map_session_data *)bl)->right_weapon.atk_ele;
	if(bl->type==BL_PET && (struct pet_data *)bl)
		return 0;

	return 0;
}
int status_get_attack_element2(struct block_list *bl)
{
	nullpo_retr(0, bl);
	if(bl->type==BL_PC) {
		// removed redundant var, speeded up a bit [zzo]
		int ret = status_get_attack_sc_element(bl);

		if(ret) return ret;
		return ((struct map_session_data *)bl)->left_weapon.atk_ele;
	}
	return 0;
}
int status_get_party_id(struct block_list *bl)
{
	nullpo_retr(0, bl);
	if(bl->type==BL_PC)
		return ((struct map_session_data *)bl)->status.party_id;
	if(bl->type==BL_PET)
		return ((struct pet_data *)bl)->msd->status.party_id;
	if(bl->type==BL_MOB){
		struct mob_data *md=(struct mob_data *)bl;
		if( md->master_id>0 )
		{
			struct map_session_data *msd;
			if (md->special_state.ai && (msd = map_id2sd(md->master_id)) != NULL)
				return msd->status.party_id;
			return -md->master_id;
		}
		return 0; //No party.
	}
	if(bl->type==BL_SKILL)
		return ((struct skill_unit *)bl)->group->party_id;
	return 0;
}

int status_get_guild_id(struct block_list *bl)
{
	nullpo_retr(0, bl);
	if(bl->type==BL_PC)
		return ((struct map_session_data *)bl)->status.guild_id;
	if(bl->type==BL_PET)
		return ((struct pet_data *)bl)->msd->status.guild_id;
	if(bl->type==BL_MOB)
	{
		struct map_session_data *msd;
		struct mob_data *md = (struct mob_data *)bl;
		if (md->guardian_data)	//Guardian's guild [Skotlex]
			return md->guardian_data->guild_id;
		if (md->special_state.ai && (msd = map_id2sd(md->master_id)) != NULL)
			return msd->status.guild_id; //Alchemist's mobs [Skotlex]
		return 0; //No guild.
	}
	if(bl->type==BL_SKILL)
		return ((struct skill_unit *)bl)->group->guild_id;
	return 0;
}
int status_get_race(struct block_list *bl)
{
	nullpo_retr(0, bl);
	if(bl->type==BL_MOB)
		return ((struct mob_data *)bl)->db->race;
	if(bl->type==BL_PC)
		return 7;
	if(bl->type==BL_PET)
		return ((struct pet_data *)bl)->db->race;
	return 0;
}
int status_get_size(struct block_list *bl)
{
	nullpo_retr(1, bl);
	switch (bl->type) {
		case BL_MOB:
			if (((struct mob_data *)bl)->sc.data[SC_SWOO].timer != -1) // [marquis007]
				return 0;
			return ((struct mob_data *)bl)->db->size;
		case BL_PET:	
			return ((struct pet_data *)bl)->db->size;
		case BL_PC:
		{
			struct map_session_data *sd = (struct map_session_data *)bl;
			if (sd->sc.data[SC_SWOO].timer != -1)
				return 0;
			if (sd->class_&JOBL_BABY) //[Lupus]
				return (pc_isriding(sd) && battle_config.character_size&2); //Baby Class Peco Rider + enabled option -> size = 1, else 0
			return 1+(pc_isriding(sd) && battle_config.character_size&1);	//Peco Rider + enabled option -> size = 2, else 1
		}
	}
	return 1;
}
int status_get_mode(struct block_list *bl)
{
	nullpo_retr(MD_CANMOVE, bl);
	if(bl->type==BL_MOB)
	{
		if (((struct mob_data *)bl)->mode)
			return ((struct mob_data *)bl)->mode;
		return ((struct mob_data *)bl)->db->mode;
	}
	if(bl->type==BL_PC)
		return (MD_CANMOVE|MD_LOOTER|MD_CANATTACK);
	if(bl->type==BL_PET)
		return ((struct pet_data *)bl)->db->mode;
	if (bl->type==BL_SKILL)
		return (MD_CANATTACK|MD_CANMOVE);	//Default mode for skills: Can attack, can move (think dances).
	//Default universal mode, can move
	return MD_CANMOVE;	// �Ƃ肠���������Ƃ������Ƃ�1
}

int status_get_mexp(struct block_list *bl)
{
	nullpo_retr(0, bl);
	if(bl->type==BL_MOB)
		return ((struct mob_data *)bl)->db->mexp;
	if(bl->type==BL_PET)
		return ((struct pet_data *)bl)->db->mexp;
	return 0;
}
int status_get_race2(struct block_list *bl)
{
	nullpo_retr(0, bl);
	if(bl->type == BL_MOB)
		return ((struct mob_data *)bl)->db->race2;
	if(bl->type==BL_PET)
		return ((struct pet_data *)bl)->db->race2;
	return 0;
}
int status_isdead(struct block_list *bl)
{
	nullpo_retr(0, bl);
	if(bl->type == BL_MOB)
		return ((struct mob_data *)bl)->state.state == MS_DEAD;
	if(bl->type==BL_PC)
		return pc_isdead((struct map_session_data *)bl);
	return 0;
}
int status_isimmune(struct block_list *bl)
{
	struct map_session_data *sd = (struct map_session_data *)bl;
	
	nullpo_retr(0, bl);
	if (bl->type == BL_PC) {
		if (sd->special_state.no_magic_damage)
			return 1;
		if (sd->sc.count && sd->sc.data[SC_HERMODE].timer != -1)
			return 1;
	}	
	return 0;
}

struct status_change *status_get_sc(struct block_list *bl)
{
	nullpo_retr(NULL, bl);
	if(bl->type==BL_MOB)
		return &((struct mob_data*)bl)->sc;
	if(bl->type==BL_PC)
		return &((struct map_session_data*)bl)->sc;
	return NULL;
}

int status_get_sc_def(struct block_list *bl, int type)
{
	int sc_def;
	struct status_change* sc;
	nullpo_retr(0, bl);
	
	switch (type)
	{
	case SP_MDEF1:	// mdef
		sc_def = 100 - (3 + status_get_mdef(bl) + status_get_luk(bl)/3);
		break;
	case SP_MDEF2:	// int
		sc_def = 100 - (3 + status_get_int(bl) + status_get_luk(bl)/3);
		break;
	case SP_DEF1:	// def
		sc_def = 100 - (3 + status_get_def(bl) + status_get_luk(bl)/3);
		break;
	case SP_DEF2:	// vit
		sc_def = 100 - (3 + status_get_vit(bl) + status_get_luk(bl)/3);
		break;
	case SP_LUK:	// luck
		sc_def = 100 - (3 + status_get_luk(bl));
		break;

	case SC_STONE:
	case SC_FREEZE:
		sc_def = 100 - (3 + status_get_mdef(bl) + status_get_luk(bl)/3);
		break;
	case SC_STAN:
	case SC_POISON:
	case SC_SILENCE:
		sc_def = 100 - (3 + status_get_vit(bl) + status_get_luk(bl)/3);
		break;	
	case SC_SLEEP:
	case SC_CONFUSION:
		sc_def = 100 - (3 + status_get_int(bl) + status_get_luk(bl)/3);
		break;
	case SC_BLIND:
		sc_def = 100 - (3 + status_get_int(bl) + status_get_vit(bl)/3);
		break;
	case SC_CURSE:
		sc_def = 100 - (3 + status_get_luk(bl) + status_get_vit(bl)/3);
		break;	

	default:
		sc_def = 100;
		break;
	}

	sc = status_get_sc(bl);
	if (sc && sc->count)
	{
		if (sc->data[SC_SCRESIST].timer != -1)
			sc_def -= sc->data[SC_SCRESIST].val1; //Status resist
		else if (sc->data[SC_SIEGFRIED].timer != -1)
			sc_def -= sc->data[SC_SIEGFRIED].val2; //Status resistance.
	}

	if(bl->type == BL_MOB) {
		struct mob_data *md = (struct mob_data *)bl;
		if (md->class_ == MOBID_EMPERIUM)
			return 0;
		if (sc_def < 50)
			sc_def = 50;
	}
	return (sc_def < 0) ? 0 : sc_def;
}

/*==========================================
 * Starts a status change.
 * type = type, val1~4 depend on the type.
 * Tick is base duration
 * flag:
 * &1: Cannot be avoided (it has to start)
 * &2: Tick should not be reduced (by vit, luk, lv, etc)
 * &4: sc_data loaded, no value has to be altered.
 *------------------------------------------
 */
int status_change_start(struct block_list *bl,int type,int val1,int val2,int val3,int val4,int tick,int flag)
{
	struct map_session_data *sd = NULL;
	struct status_change* sc;
	int opt_flag = 0, calc_flag = 0,updateflag = 0, save_flag = 0, race, mode, elem, undead_flag;
	int scdef = 0;

	nullpo_retr(0, bl);
	sc=status_get_sc(bl);

	if (!sc || status_isdead(bl))
		return 0;
	
	if(type < 0 || type >= SC_MAX) {
		if(battle_config.error_log)
			ShowError("status_change_start: invalid status change (%d)!\n", type);
		return 0;
	}

	race=status_get_race(bl);
	mode=status_get_mode(bl);
	elem=status_get_elem_type(bl);
	undead_flag=battle_check_undead(race,elem);

	if(type == SC_AETERNA && (sc->data[SC_STONE].timer != -1 || sc->data[SC_FREEZE].timer != -1) )
		return 0;
	if(type == SC_OVERTHRUST && sc->data[SC_MAXOVERTHRUST].timer != -1)
		return 0; //Overthrust can't take effect if under Max Overthrust. [Skotlex]
	switch(type){
		case SC_STONE:
		case SC_FREEZE:
			scdef=3+status_get_mdef(bl)+status_get_luk(bl)/3;
			break;
		case SC_STAN:
		case SC_SILENCE:
		case SC_POISON:
		case SC_DPOISON:
			scdef=3+status_get_vit(bl)+status_get_luk(bl)/3;
			break;
		case SC_SLEEP:
		case SC_BLIND:
			scdef=3+status_get_int(bl)+status_get_luk(bl)/3;
			break;
		case SC_CURSE:
			scdef=3+status_get_luk(bl);
			break;
		default:
			scdef=0;
	}
	if(scdef>=100)
		return 0;
	
	if(sd){
		if(type == SC_ADRENALINE && !(skill_get_weapontype(BS_ADRENALINE)&(1<<sd->status.weapon)))
			return 0;
		if(type == SC_ADRENALINE2 && !(skill_get_weapontype(BS_ADRENALINE2)&(1<<sd->status.weapon)))
			return 0;

		if(SC_COMMON_MIN<=type && type<=SC_COMMON_MAX && !(flag&1)){
			if(sd->reseff[type-SC_COMMON_MIN] > 0 && rand()%10000<sd->reseff[type-SC_COMMON_MIN]){
				if(battle_config.battle_log)
					ShowInfo("PC %d skill_sc_start: status change %d blocked by reseff card (AID: %d).\n",type,bl->id);
				return 0;
			}
		}
	}

	if((type==SC_FREEZE || type==SC_STONE) && undead_flag && !(flag&1))
	//I've been informed that undead chars are inmune to stone curse too. [Skotlex]
		return 0;


	if (type==SC_BLESSING && (bl->type==BL_PC || (!undead_flag && race!=6))) {
		if (sc->data[SC_CURSE].timer!=-1)
			status_change_end(bl,SC_CURSE,-1);
		if (sc->data[SC_STONE].timer!=-1 && sc->data[SC_STONE].val2==0)
			status_change_end(bl,SC_STONE,-1);
	}

	if((type == SC_ADRENALINE || type==SC_ADRENALINE2 || type == SC_WEAPONPERFECTION || type == SC_OVERTHRUST) &&
		sc->data[type].timer != -1 && sc->data[type].val2 && !val2)
		return 0;

	if(mode & MD_BOSS && !(flag&1) && ( (type>=SC_COMMON_MIN && type <= SC_COMMON_MAX)
		|| type==SC_QUAGMIRE || type==SC_DECREASEAGI || type==SC_SIGNUMCRUCIS
	  	|| type==SC_PROVOKE || type==SC_ROKISWEIL || type==SC_COMA
		|| (type == SC_BLESSING && (undead_flag || race == 6)))){
		/* �{�X�ɂ�?���Ȃ�(�������J?�h�ɂ��?�ʂ͓K�p�����) */
		return 0;
	}

	if(sc->data[type].timer != -1){	/* ���łɓ����ُ�ɂȂ��Ă���ꍇ�^�C�}���� */
		if(sc->data[type].val1 > val1 && type != SC_COMBO && type != SC_DANCING && type != SC_DEVOTION &&
			type != SC_ASPDPOTION0 && type != SC_ASPDPOTION1 && type != SC_ASPDPOTION2 && type != SC_ASPDPOTION3
			&& type != SC_ATKPOTION && type != SC_MATKPOTION // added atk and matk potions [Valaris]
		)
			return 0;

		if ((type >=SC_STAN && type <= SC_BLIND) || type == SC_DPOISON)
			return 0;/* ?���������ł��Ȃ�?�Ԉُ�ł��鎞��?�Ԉُ���s��Ȃ� */

		if (type == SC_GOSPEL && sc->data[type].val4 == BCT_SELF) //Must not override a casting gospel char.
			return 0;
		
		(sc->count)--;
		delete_timer(sc->data[type].timer, status_change_timer);
		sc->data[type].timer = -1;
	}

	if(type==SC_FREEZE || type==SC_STAN || type==SC_SLEEP || type==SC_STOP || type == SC_CONFUSION ||
		type==SC_CLOSECONFINE || type==SC_CLOSECONFINE2)
		battle_stopwalking(bl,1);

	// �N�A�O�}�C�A/����Y��Ȃ��Œ��͖����ȃX�L��
	if ((sc->data[SC_QUAGMIRE].timer!=-1 || sc->data[SC_DONTFORGETME].timer!=-1) &&
		(type==SC_CONCENTRATE || type==SC_INCREASEAGI ||
		type==SC_TWOHANDQUICKEN || type==SC_SPEARSQUICKEN ||
		type==SC_ADRENALINE || type==SC_ADRENALINE2 ||
		type==SC_TRUESIGHT || type==SC_WINDWALK ||
		type==SC_CARTBOOST || type==SC_ASSNCROS || 
		type==SC_ONEHAND))
	return 0;

	switch(type){	/* �ُ�̎�ނ��Ƃ�?�� */
		case SC_PROVOKE:			/* �v���{�b�N */
			calc_flag = 1;
			if(tick <= 0) tick = 1000;	/* (�I?�g�o?�T?�N) */
			break;
		case SC_ENDURE:				/* �C���f���A */
			if(tick <= 0) tick = 1000 * 60;
			calc_flag = 1; // for updating mdef
			val2 = 7; // [Celest]
			break;
		case SC_AUTOBERSERK:
			{
				if (!(flag&4))
					tick = 60*1000;
				if (bl->type == BL_PC && sd->status.hp<sd->status.max_hp>>2 &&
					(sc->data[SC_PROVOKE].timer==-1 || sc->data[SC_PROVOKE].val2==0))
					status_change_start(bl,SC_PROVOKE,10,1,0,0,0,0);
			}
			break;
		
		case SC_INCREASEAGI:		/* ���x�㏸ */
			calc_flag = 1;
			if(sc->data[SC_DECREASEAGI].timer!=-1 )
				status_change_end(bl,SC_DECREASEAGI,-1);
			break;
		case SC_DECREASEAGI:		/* ���x���� */
			if (bl->type == BL_PC && !(tick&2))	// Celest
				tick>>=1;
			calc_flag = 1;
			if(sc->data[SC_INCREASEAGI].timer!=-1 )
				status_change_end(bl,SC_INCREASEAGI,-1);
			if(sc->data[SC_ADRENALINE].timer!=-1 )
				status_change_end(bl,SC_ADRENALINE,-1);
			if(sc->data[SC_ADRENALINE2].timer!=-1 )
				status_change_end(bl,SC_ADRENALINE2,-1);
			if(sc->data[SC_SPEARSQUICKEN].timer!=-1 )
				status_change_end(bl,SC_SPEARSQUICKEN,-1);
			if(sc->data[SC_TWOHANDQUICKEN].timer!=-1 )
				status_change_end(bl,SC_TWOHANDQUICKEN,-1);
			if(sc->data[SC_CARTBOOST].timer!=-1 )
				status_change_end(bl,SC_CARTBOOST,-1);
			if(sc->data[SC_ONEHAND].timer!=-1 )
				status_change_end(bl,SC_ONEHAND,-1);
			break;
		case SC_SIGNUMCRUCIS:		/* �V�O�i���N���V�X */
			calc_flag = 1;
			val2 = 10 + val1*2;
			if (!(flag&4))
				tick = 600*1000;
			clif_emotion(bl,4);
			break;
		case SC_ONEHAND: //Removes the Aspd potion effect, as reported by Vicious. [Skotlex]
			if(sc->data[SC_ASPDPOTION0].timer!=-1)
				status_change_end(bl,SC_ASPDPOTION0,-1);
			if(sc->data[SC_ASPDPOTION1].timer!=-1)
				status_change_end(bl,SC_ASPDPOTION1,-1);
			if(sc->data[SC_ASPDPOTION2].timer!=-1)
				status_change_end(bl,SC_ASPDPOTION2,-1);
			if(sc->data[SC_ASPDPOTION3].timer!=-1)
				status_change_end(bl,SC_ASPDPOTION3,-1);
		case SC_TWOHANDQUICKEN:		/* 2HQ */
			if(sc->data[SC_DECREASEAGI].timer!=-1)
				return 0;
			sc->opt3 |= 1;
			calc_flag = 1;
			break;
		case SC_ADRENALINE2:
		case SC_ADRENALINE:			/* �A�h���i�������b�V�� */
			if(sc->data[SC_DECREASEAGI].timer!=-1)
				return 0;
			if(bl->type == BL_PC && !(flag&2))
				if(pc_checkskill(sd,BS_HILTBINDING)>0)
					tick += tick / 10;
			calc_flag = 1;
			break;
		case SC_WEAPONPERFECTION:	/* �E�F�|���p?�t�F�N�V���� */
			if(bl->type == BL_PC && !(flag&2))
				if(pc_checkskill(sd,BS_HILTBINDING)>0)
					tick += tick / 10;
			break;
		case SC_OVERTHRUST:			/* �I?�o?�X���X�g */
			if(bl->type == BL_PC && !(flag&2))
				if(pc_checkskill(sd,BS_HILTBINDING)>0)
					tick += tick / 10;
			sc->opt3 |= 2;
			break;
		case SC_MAXOVERTHRUST: //Cancels Normal Overthrust. [Skotlex]
			if (sc->data[SC_OVERTHRUST].timer != -1)
				status_change_end(bl, SC_OVERTHRUST, -1);
			break;
		case SC_MAXIMIZEPOWER:		/* �}�L�V�}�C�Y�p��?(SP��1���鎞��,val2�ɂ�) */
			if (!(flag&4))
			{
				if(bl->type != BL_PC)
					tick = 5000;
				val2 = tick;
			}
			break;
		case SC_ENCPOISON:			/* �G���`�����g�|�C�Y�� */
			calc_flag = 1;
			val2=(((val1 - 1) / 2) + 3)*100;	/* �ŕt?�m�� */
			skill_enchant_elemental_end(bl,SC_ENCPOISON);
			break;
		case SC_EDP:	// [Celest]
			val2 = val1 + 2;			/* �ғŕt?�m��(%) */
			calc_flag = 1;
			break;
		case SC_POISONREACT:	/* �|�C�Y�����A�N�g */
			if (!(flag&4))
				val2=val1/2 + val1%2; // [Celest]
			break;
		case SC_ENERGYCOAT:			/* �G�i�W?�R?�g */
			sc->opt3 |= 4;
			break;
		case SC_MAGICROD:
			val2 = val1*20;
			break;
		case SC_KYRIE:				/* �L���G�G���C�\�� */
			if (!(flag&4))
			{
				val2 = status_get_max_hp(bl) * (val1 * 2 + 10) / 100;/* �ϋv�x */
				val3 = (val1 / 2 + 5);	/* ��? */
			}
// -- moonsoul (added to undo assumptio status if target has it)
			if(sc->data[SC_ASSUMPTIO].timer!=-1 )
				status_change_end(bl,SC_ASSUMPTIO,-1);
			break;
		case SC_MINDBREAKER:
			calc_flag = 1;
			if(tick <= 0) tick = 1000;	/* (�I?�g�o?�T?�N) */
		case SC_TRICKDEAD:			/* ���񂾂ӂ� */
			if (bl->type == BL_PC) {
				pc_stopattack(sd);
			}
			break;
		case SC_QUAGMIRE:			/* �N�@�O�}�C�A */
			calc_flag = 1;
			if(sc->data[SC_CONCENTRATE].timer!=-1 )	/* �W���͌������ */
				status_change_end(bl,SC_CONCENTRATE,-1);
			if(sc->data[SC_INCREASEAGI].timer!=-1 )	/* ���x�㏸���� */
				status_change_end(bl,SC_INCREASEAGI,-1);
			if(sc->data[SC_TWOHANDQUICKEN].timer!=-1 )
				status_change_end(bl,SC_TWOHANDQUICKEN,-1);
			if(sc->data[SC_ONEHAND].timer!=-1 )
				status_change_end(bl,SC_ONEHAND,-1);
			if(sc->data[SC_SPEARSQUICKEN].timer!=-1 )
				status_change_end(bl,SC_SPEARSQUICKEN,-1);
			if(sc->data[SC_ADRENALINE].timer!=-1 )
				status_change_end(bl,SC_ADRENALINE,-1);
			if(sc->data[SC_ADRENALINE2].timer!=-1 )
				status_change_end(bl,SC_ADRENALINE2,-1);
			if(sc->data[SC_TRUESIGHT].timer!=-1 )	/* �g�D��?�T�C�g */
				status_change_end(bl,SC_TRUESIGHT,-1);
			if(sc->data[SC_WINDWALK].timer!=-1 )	/* �E�C���h�E�H?�N */
				status_change_end(bl,SC_WINDWALK,-1);
			if(sc->data[SC_CARTBOOST].timer!=-1 )	/* �J?�g�u?�X�g */
				status_change_end(bl,SC_CARTBOOST,-1);
			break;
		case SC_MAGICPOWER:
			calc_flag = 1;
			val2 = 1;
			break;
		case SC_SACRIFICE:
			if (!(flag&4))
				val2 = 5;
			break;
		case SC_ASPERSIO:			/* �A�X�y���V�I */
			skill_enchant_elemental_end(bl,SC_ASPERSIO);
			break;
		case SC_FIREWEAPON:		/* �t��?�������`��? */
			skill_enchant_elemental_end(bl,SC_FIREWEAPON);
			break;
		case SC_WATERWEAPON:		/* �t���X�g�E�F�|�� */
			skill_enchant_elemental_end(bl,SC_WATERWEAPON);
			break;
		case SC_WINDWEAPON:	/* ���C�g�j���O��?�_? */
			skill_enchant_elemental_end(bl,SC_WINDWEAPON);
			break;
		case SC_EARTHWEAPON:		/* �T�C�Y�~�b�N�E�F�|�� */
			skill_enchant_elemental_end(bl,SC_EARTHWEAPON);
			break;
		case SC_SHADOWWEAPON:
			skill_enchant_elemental_end(bl,SC_SHADOWWEAPON);
			break;
		case SC_GHOSTWEAPON:
			skill_enchant_elemental_end(bl,SC_GHOSTWEAPON);
			break;
		case SC_PROVIDENCE:			/* �v�����B�f���X */
			calc_flag = 1;
			val2=val1*5;
			break;
		case SC_REFLECTSHIELD:
			val2=10+val1*3;
			break;
		case SC_STRIPWEAPON:
			if (val2==0) val2=90;
			break;
		case SC_STRIPSHIELD:
			if (val2==0) val2=85;
			break;

		case SC_AUTOSPELL:			/* �I?�g�X�y�� */
			val4 = 5 + val1*2;
			break;

		case SC_VOLCANO:
			calc_flag = 1;
			val3 = val1*10;
			break;
		case SC_DELUGE:
			calc_flag = 1;
			if (sc->data[SC_FOGWALL].timer != -1 && sc->data[SC_BLIND].timer != -1)
				status_change_end(bl,SC_BLIND,-1);
			break;
		case SC_VIOLENTGALE:
			calc_flag = 1;
			val3 = val1*3;
			break;

		case SC_SPEARSQUICKEN:		/* �X�s�A�N�C�b�P�� */
			calc_flag = 1;
			val2 = 20+val1;
			sc->opt3 |= 1;
			break;

		case SC_BLADESTOP:		/* ���n��� */
			if(val2==2) clif_bladestop((struct block_list *)val3,(struct block_list *)val4,1);
			sc->opt3 |= 32;
			break;

		case SC_LULLABY:			/* �q��S */
		case SC_RICHMANKIM:
		case SC_ROKISWEIL:			/* ���L�̋��� */
		case SC_INTOABYSS:			/* �[���̒��� */
		case SC_POEMBRAGI:			/* �u���M�̎� */
		case SC_UGLYDANCE:			/* ��������ȃ_���X */
			break;
		case SC_ETERNALCHAOS:		/* �G�^?�i���J�I�X */
		case SC_DRUMBATTLE:			/* ?���ۂ̋��� */
		case SC_NIBELUNGEN:			/* �j?�x�����O�̎w�� */
		case SC_SIEGFRIED:			/* �s���g�̃W?�N�t��?�h */
		case SC_WHISTLE:			/* ���J */
		case SC_ASSNCROS:			/* �[�z�̃A�T�V���N���X */
		case SC_APPLEIDUN:			/* �C�h�D���̗ь� */
		case SC_HUMMING:			/* �n�~���O */
		case SC_ATKPOTION: // Valaris
		case SC_MATKPOTION:
		case SC_FORTUNE:			/* �K�^�̃L�X */
		case SC_SERVICE4U:			/* �T?�r�X�t�H?��? */
			calc_flag = 1;
			break;
		case SC_DONTFORGETME:		/* ����Y��Ȃ��� */
			calc_flag = 1;
			if(sc->data[SC_INCREASEAGI].timer!=-1 )	/* ���x�㏸���� */
				status_change_end(bl,SC_INCREASEAGI,-1);
			if(sc->data[SC_TWOHANDQUICKEN].timer!=-1 )
				status_change_end(bl,SC_TWOHANDQUICKEN,-1);
			if(sc->data[SC_ONEHAND].timer!=-1 )
				status_change_end(bl,SC_ONEHAND,-1);
			if(sc->data[SC_SPEARSQUICKEN].timer!=-1 )
				status_change_end(bl,SC_SPEARSQUICKEN,-1);
			if(sc->data[SC_ADRENALINE].timer!=-1 )
				status_change_end(bl,SC_ADRENALINE,-1);
			if(sc->data[SC_ADRENALINE2].timer!=-1 )
				status_change_end(bl,SC_ADRENALINE2,-1);
			if(sc->data[SC_ASSNCROS].timer!=-1 )
				status_change_end(bl,SC_ASSNCROS,-1);
			if(sc->data[SC_TRUESIGHT].timer!=-1 )	/* �g�D��?�T�C�g */
				status_change_end(bl,SC_TRUESIGHT,-1);
			if(sc->data[SC_WINDWALK].timer!=-1 )	/* �E�C���h�E�H?�N */
				status_change_end(bl,SC_WINDWALK,-1);
			if(sc->data[SC_CARTBOOST].timer!=-1 )	/* �J?�g�u?�X�g */
				status_change_end(bl,SC_CARTBOOST,-1);
			break;
		case SC_MOONLIT:
			val2 = bl->id;
			skill_setmapcell(bl,CG_MOONLIT, val1, CELL_SETMOONLIT);
			break;
		case SC_DANCING:			/* �_���X/���t�� */
			calc_flag = 1;
			if (!(flag&4))
			{
				val3= tick / 1000;
				tick = 1000;
			}
			break;

		case SC_EXPLOSIONSPIRITS:	// �����g��
			calc_flag = 1;
			val2 = 75 + 25*val1;
			sc->opt3 |= 8;
			break;
		case SC_STEELBODY:			// ����
		case SC_SKA:
			calc_flag = 1;
			sc->opt3 |= 16;
			break;
		case SC_AUTOCOUNTER:
			val3 = val4 = 0;
			break;

		case SC_ASPDPOTION0:		/* ?���|?�V���� */
		case SC_ASPDPOTION1:
		case SC_ASPDPOTION2:
		case SC_ASPDPOTION3:
			calc_flag = 1;
			if (!(flag&4))
				val2 = 5*(2+type-SC_ASPDPOTION0);
			break;

		case SC_XMAS: // Xmas Suit [Valaris]
		case SC_WEDDING:	//�����p(�����ߏւɂȂ���?���̂�?���Ƃ�)
			{
				struct map_session_data *sd;
				if (bl->type == BL_PC && (sd= (struct map_session_data *)bl))
				{	//Change look.
					if(type==SC_WEDDING)
						sd->view_class = JOB_WEDDING;
					else if(type==SC_XMAS)
						sd->view_class = JOB_XMAS;
					clif_changelook(&sd->bl,LOOK_BASE,sd->view_class);
#if PACKETVER < 4
					clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
					clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
#else
					clif_changelook(&sd->bl,LOOK_WEAPON,0);
#endif
					if(battle_config.save_clothcolor && sd->status.clothes_color > 0 && 
						((type==SC_WEDDING && !battle_config.wedding_ignorepalette) || 
							(type==SC_XMAS && !battle_config.xmas_ignorepalette)))
						clif_changelook(&sd->bl,LOOK_CLOTHES_COLOR,sd->status.clothes_color);
				}
			}
			break;
		case SC_NOCHAT:	//�`���b�g�֎~?��
			{
				if(!battle_config.muting_players)
					return 0;
				
				if (!(flag&4))
					tick = 60000;
				updateflag = SP_MANNER;
				save_flag = 1; // celest
			}
			break;

		/* option1 */
		case SC_STONE:				/* �Ή� */
			if(!(flag&2)) {
				int sc_def = status_get_mdef(bl)*200;
				tick = tick - sc_def;
			}
			if (!(flag&4))
				val3 = tick/1000;
			if(val3 < 1) val3 = 1;
			if (!(flag&4))
				tick = 5000;
			val2 = 1;
			break;
		case SC_SLEEP:				/* ���� */
			if(!(flag&4)) {
				tick = 30000;//�����̓X�e?�^�X�ϐ���?��炸30�b
			}
			break;
		case SC_FREEZE:				/* ���� */
			if(!(flag&2)) {
				int sc_def = 100 - status_get_mdef(bl);
				tick = tick * sc_def / 100;
			}
			break;
		case SC_STAN:				/* �X�^���ival2�Ƀ~���b�Z�b�g�j */
			if(!(flag&2)) {
				int sc_def = status_get_sc_def_vit(bl);
				tick = tick * sc_def / 100;
			}
			break;

			/* option2 */
		case SC_DPOISON:			/* �ғ� */
		{
			int hp = status_get_hp(bl);
			int mhp = status_get_max_hp(bl);

			// MHP?1/4????????
			if (hp > mhp>>2) {
				if(bl->type == BL_PC) {
					int diff = mhp*10/100;
					if (hp - diff < mhp>>2)
						diff = hp - (mhp>>2);
					pc_heal((struct map_session_data *)bl, -diff, 0);
				} else if(bl->type == BL_MOB) {
					struct mob_data *md = (struct mob_data *)bl;
					hp -= mhp*15/100;
					if (hp > mhp>>2)
						md->hp = hp;
					else
						md->hp = mhp>>2;
				}
			}
		}	// fall through
		case SC_POISON:				/* �� */
		{
			int mhp;

			calc_flag = 1;
			if (flag&4)
				break;
			if(!(flag&2)) {
				int sc_def = 100 - (status_get_vit(bl) + status_get_luk(bl)/5);
				tick = tick * sc_def / 100;
			}
			val3 = tick/1000;
			if(val3 < 1) val3 = 1;
			tick = 1000;
			mhp = status_get_max_hp(bl);
			if (bl->type == BL_PC)
				val4 = (type == SC_DPOISON) ? 3 + mhp/50 : 3 + mhp*3/200;
			else
				val4 = (type == SC_DPOISON) ? 3 + mhp/100 : 3 + mhp/200;
		
		}
		break;
		case SC_SILENCE:			/* ��?�i���b�N�X�f�r?�i�j */
			if (sc->data[SC_GOSPEL].timer!=-1) {
				if (sc->data[SC_GOSPEL].val4 == BCT_SELF) { //Clear Gospel [Skotlex]
					status_change_end(bl,SC_GOSPEL,-1);
				}
				break;
			}
			if(!(flag&2)) {
				int sc_def = 100 - status_get_vit(bl);
				tick = tick * sc_def / 100;
			}
			break;
		case SC_CONFUSION:
			if(!(flag&2)) {
				int sc_def = 100 - status_get_vit(bl);
				tick = tick * sc_def / 100;
			}
			clif_emotion(bl,1);
			break;
		case SC_BLIND:				/* ��? */
			calc_flag = 1;
			if(!(flag&4) && tick < 1000)
				tick = 30000;
			if(!(flag&2)) {
				int sc_def = 100 - (status_get_lv(bl)/10 + status_get_int(bl)/15);
				tick = tick*sc_def/100;
				if (tick < 5000) //Minimum 5 secs?
					tick = 5000;
			}
			break;
		case SC_CURSE:
			calc_flag = 1;
			if(!(flag&2)) {
				int sc_def = 100 - status_get_vit(bl);
				tick = tick * sc_def / 100;
			}
			break;

		case SC_BLEEDING:
			if(!(flag&2)) {
				int sc_def = 100 - (status_get_lv(bl)/5 +status_get_vit(bl));
				tick = tick * sc_def / 100;
			}
			if(!(flag&4) && tick < 10000) //Minimum bleed time is 10 secs or this sc does nothing! [Skotlex]
				tick = 10000;
			val4 = tick;
			tick = 10000;
			break;

		/* option */
		case SC_HIDING:		/* �n�C�f�B���O */
			calc_flag = 1;
			if(bl->type == BL_PC && !(flag&4)) {
				val2 = tick / 1000;		/* ��?���� */
				tick = 1000;
			}
			break;
		case SC_CHASEWALK:
		case SC_CLOAKING:		/* �N��?�L���O */
			if (flag&4)
				break;
			if(bl->type != BL_PC)
				tick = 5000*val1;
			calc_flag = 1; // [Celest]
			val2 = tick;
			val3 = type==SC_CLOAKING ? 130-val1*3 : 135-val1*5;
			break;
		case SC_SIGHT:			/* �T�C�g/���A�t */
		case SC_RUWACH:
		case SC_SIGHTBLASTER:
			if (flag&4)
				break;
			val2 = tick/250;
			tick = 10;
			break;

		case SC_WEIGHT50:
		case SC_WEIGHT90:
		case SC_BROKENWEAPON:
		case SC_BROKENARMOR:
		case SC_READYSTORM: // Taekwon stances SCs [Dralnu]
		case SC_READYDOWN:
		case SC_READYCOUNTER:
		case SC_READYTURN:
		case SC_DODGE:
			if (flag&4)
				break;
			tick = 600*1000;
			break;

		case SC_AUTOGUARD:
			if (!flag)
			{
				struct map_session_data *tsd;
				int i,t;
				for(i=val2=0;i<val1;i++) {
					t = 5-(i>>1);
					val2 += (t < 0)? 1:t;
				}
				if (sd)
					for (i = 0; i < 5; i++)
					{	//Pass the status to the other affected chars. [Skotlex]
						if (sd->devotion[i] && (tsd = map_id2sd(sd->devotion[i])))
							status_change_start(&tsd->bl,SC_AUTOGUARD,val1,val2,0,0,tick,1);
					}
			}
			break;

		case SC_DEFENDER:
			calc_flag = 1;
			if (!flag)
			{	
				struct map_session_data *tsd;
				int i;
				val2 = 5 + val1*15;
				if (sd)
					for (i = 0; i < 5; i++)
					{	//See if there are devoted characters, and pass the status to them. [Skotlex]
						if (sd->devotion[i] && (tsd = map_id2sd(sd->devotion[i])))
							status_change_start(&tsd->bl,SC_DEFENDER,val1,val2,0,0,tick,1);
					}
			}
			break;

		case SC_CONCENTRATION:	/* �R���Z���g��?�V���� */
			sc->opt3 |= 1;
			calc_flag = 1;
			break;

		case SC_TENSIONRELAX:	/* �e���V���������b�N�X */
			if (flag&4)
				break;
			if(bl->type == BL_PC) {
				tick = 10000;
			} else return 0;
			break;

		case SC_PARRYING:		/* �p���C���O */
		    val2 = 20 + val1*3;
			break;

		case SC_WINDWALK:		/* �E�C���h�E�H?�N */
			calc_flag = 1;
			val2 = (val1+1)/2; // Flee bonus is 1/1/2/2/3/3/4/4/5/5, movement speed % increase is 4 times that
			break;

		case SC_JOINTBEAT: // Random break [DracoRPG]
			calc_flag = 1;
			val2 = rand()%6;
			if (val2 == 5) status_change_start(bl,SC_BLEEDING,val1,0,0,0,skill_get_time2(type,val1),0);
			break;

		case SC_BERSERK:		/* �o?�T?�N */
			if(sd && !(flag&4)){
				sd->status.hp = sd->status.max_hp * 3;
				sd->status.sp = 0;
				clif_updatestatus(sd,SP_HP);
				clif_updatestatus(sd,SP_SP);
				sd->canregen_tick = gettick() + 300000;
			}
			sc->opt3 |= 128;
			if (!(flag&4))
				tick = 10000;
			calc_flag = 1;
			break;

		case SC_ASSUMPTIO:		/* �A�X���v�e�B�I */
			sc->opt3 |= 2048;
			if(sc->data[SC_KYRIE].timer!=-1)
				status_change_end(bl,SC_KYRIE,-1);
			break;

		case SC_WARM: //SG skills [Komurka]
			if (!(flag&4)) {
				val2 = tick/1000;
				tick = 1000;
			}
			sc->opt3 |= 4096;
			opt_flag = 1;
			break;

		case SC_GOSPEL:
			if (val4 == BCT_SELF) {	// self effect
				if (flag&4)
					break;
				val2 = tick;
				tick = 1000;
				status_change_clear_buffs(bl);
				status_change_clear_debuffs(bl); //Gospel clears both types.
			} else
				calc_flag = 1;
			break;

		case SC_MARIONETTE:		/* �}���I�l�b�g�R���g��?�� */
		case SC_MARIONETTE2:
			if (flag&4)
				break;
			val2 = tick;
			if (!val3)
				return 0;
			tick = 1000;
			calc_flag = 1;
			sc->opt3 |= 1024;
			break;

		case SC_REJECTSWORD:	/* ���W�F�N�g�\?�h */
			val2 = 3; //3��U?�𒵂˕Ԃ�
			break;

		case SC_MEMORIZE:		/* �������C�Y */
			val2 = 5; //��r����1/3�ɂ���
			break;

		case SC_GRAVITATION:
			if (sd) {
				if (val3 == BCT_SELF) {
					sd->canmove_tick += tick;
					sd->canact_tick += tick;
				} else calc_flag = 1;
			}
			break;

		case SC_HERMODE:
			status_change_clear_buffs(bl);
			break;

		case SC_REGENERATION:
			val1 = 2;
		case SC_BATTLEORDERS:
			if (!(flag&4))
				tick = 60000; // 1 minute
			calc_flag = 1;
			break;
		case SC_GUILDAURA:
			calc_flag = 1;
			if (!(flag&4))
				tick = 1000;
			break;

		case SC_DEVOTION:			/* �f�B�{?�V���� */
		{
			struct map_session_data *src;
			if ((src = map_id2sd(val1)) && src->sc.count)
			{	//Try to inherit the status from the Crusader [Skotlex]
			//Ideally, we should calculate the remaining time and use that, but we'll trust that
			//once the Crusader's status changes, it will reflect on the others. 
				if (src->sc.data[SC_AUTOGUARD].timer != -1)
					status_change_start(bl,SC_AUTOGUARD,src->sc.data[SC_AUTOGUARD].val1,0,0,0,
						skill_get_time(CR_AUTOGUARD,src->sc.data[SC_AUTOGUARD].val1),0);
				if (src->sc.data[SC_DEFENDER].timer != -1)
					status_change_start(bl,SC_DEFENDER,src->sc.data[SC_DEFENDER].val1,0,0,0,
						skill_get_time(CR_DEFENDER,src->sc.data[SC_DEFENDER].val1),0);
			}
			break;
		}

		case SC_COMA: //Coma. Sends a char to 1HP/SP
			battle_damage(NULL, bl, status_get_hp(bl)-1, 0);
			if (sd) pc_heal(sd,0,-sd->status.sp+1);
			return 0;

		case SC_CARTBOOST:		/* �J?�g�u?�X�g */
			if(sc->data[SC_DECREASEAGI].timer!=-1 )
			{	//Cancel Decrease Agi, but take no further effect [Skotlex]
				status_change_end(bl,SC_DECREASEAGI,-1);
				return 0;
			}
			calc_flag = 1;
			break;

		case SC_CLOSECONFINE2:
			{
				struct block_list *src = val2?map_id2bl(val2):NULL;
				struct status_change *sc2 = src?status_get_sc(src):NULL;
				if (src && sc2 && sc2->count) {
					if (sc2->data[SC_CLOSECONFINE].timer == -1) //Start lock on caster.
						status_change_start(src,SC_CLOSECONFINE,1,0,0,0,tick+1000,0);
					else { //Increase count of locked enemies and refresh time.
						sc2->data[SC_CLOSECONFINE].val1++;
						delete_timer(sc2->data[SC_CLOSECONFINE].timer, status_change_timer);
						sc2->data[SC_CLOSECONFINE].timer = add_timer(gettick()+tick+1000, status_change_timer, src->id, SC_CLOSECONFINE);
					}
				}
			}
			break;
		case SC_KAITE:
			val2 = 1+val1/5; //Number of bounces: 1 + skilllv/5
			break;
		case SC_KAUPE:
			if (flag&4)
				break; //Do nothing when loading.
			switch (val1) {
				case 3: //33*3 + 1 -> 100%
					val2++;
				case 1:
				case 2: //33, 66%
					val2 += 33*val1;
					val3 = 1; //Dodge 1 attack total.
					break;
				default: //Custom. For high level mob usage, higher level means more blocks. [Skotlex]
					val2 = 100;
					val3 = val1-2;
					break;
			}
			break;
		case SC_COMBO:
			switch (val1) { //Val1 contains the skill id
				case TK_STORMKICK:
					clif_skill_nodamage(bl,bl,TK_READYSTORM,1,1);
					if (sd) sd->attackabletime = gettick()+tick;
					break;
				case TK_DOWNKICK:
					clif_skill_nodamage(bl,bl,TK_READYDOWN,1,1);
					if (sd) sd->attackabletime = gettick()+tick;
					break;
				case TK_TURNKICK:
					clif_skill_nodamage(bl,bl,TK_READYTURN,1,1);
					if (sd) sd->attackabletime = gettick()+tick;
					break;
				case TK_COUNTER:
					clif_skill_nodamage(bl,bl,TK_READYCOUNTER,1,1);
					if (sd) sd->attackabletime = gettick()+tick;
					break;
			}
			break;
		case SC_SWOO: // [marquis007]
			if (!(flag&4) && status_get_mode(bl)&MD_BOSS)
				tick /= 4; //Reduce skill's duration. But for how long?
//			sc->opt3 |= 8192; //We haven't figured out this value yet...
			opt_flag = 1;
			calc_flag = 1;
			break;
		case SC_TKDORI:
			val2 = 11-val1; //Chance to consume: 11-skilllv%
			break;
		case SC_RUN:
			if (!(flag&4))
				val4 = gettick(); //Store time at which you started running.
			calc_flag = 1;
			break;

		case SC_CONCENTRATE:		/* �W���͌��� */
		case SC_BLESSING:			/* �u���b�V���O */
		case SC_ANGELUS:			/* �A���[���X */
		case SC_IMPOSITIO:			/* �C���|�V�e�B�I�}�k�X */
		case SC_GLORIA:				/* �O�����A */
		case SC_LOUD:				/* ���E�h�{�C�X */
		case SC_KEEPING:
		case SC_BARRIER:
		case SC_MELTDOWN:		/* �����g�_�E�� */
		case SC_TRUESIGHT:		/* �g�D��?�T�C�g */
		case SC_SPIDERWEB:		/* �X�p�C�_?�E�F�b�u */
		case SC_SLOWDOWN:
		case SC_SPEEDUP0:
		case SC_SPEEDUP1:
		case SC_INCALLSTATUS:
		case SC_INCHIT:			/* HIT�㏸ */
		case SC_INCHITRATE:		/* HIT%�㏸ */
		case SC_INCFLEE:		/* FLEE�㏸ */
		case SC_INCFLEERATE:		/* FLEE%�㏸ */
		case SC_INCMHPRATE:		/* MHP%�㏸ */
		case SC_INCMSPRATE:		/* MSP%�㏸ */
		case SC_INCATKRATE:		/* ATK%�㏸ */
		case SC_INCMATKRATE:
		case SC_INCDEFRATE:
		case SC_INCSTR:
		case SC_INCAGI:
		case SC_INCVIT:
		case SC_INCINT:
		case SC_INCDEX:
		case SC_INCLUK:
		case SC_STRFOOD:
		case SC_AGIFOOD:
		case SC_VITFOOD:
		case SC_INTFOOD:
		case SC_DEXFOOD:
		case SC_LUKFOOD:
		case SC_FLEEFOOD:
		case SC_HITFOOD:
		case SC_BATKFOOD:
		case SC_WATKFOOD:
		case SC_MATKFOOD:
		case SC_SPURT:
		case SC_SPIRIT:
		case SC_SUN_COMFORT:
		case SC_MOON_COMFORT:
		case SC_STAR_COMFORT:
		case SC_FUSION:
		case SC_SKE:
			calc_flag = 1;
			break;

		case SC_SAFETYWALL:
		case SC_SLOWPOISON: //Slow potion can be activated even if not poisoned.
		case SC_SUFFRAGIUM:			/* �T�t���M�� */
		case SC_BENEDICTIO:			/* ��? */
		case SC_MAGNIFICAT:			/* �}�O�j�t�B�J?�g */
		case SC_AETERNA:			/* �G?�e���i */
  		case SC_STRIPARMOR:
		case SC_STRIPHELM:
		case SC_CP_WEAPON:
		case SC_CP_SHIELD:
		case SC_CP_ARMOR:
		case SC_CP_HELM:
		case SC_EXTREMITYFIST:		/* ���C���e���� */
		case SC_ANKLE:	/* �A���N�� */
		case SC_BLADESTOP_WAIT:		/* ���n���(�҂�) */
		case SC_HALLUCINATION:
		case SC_SPLASHER:		/* �x�i���X�v���b�V��? */
		case SC_FOGWALL:
		case SC_PRESERVE:
		case SC_DOUBLECAST:
		case SC_AURABLADE:		/* �I?���u��?�h */
		case SC_BABY:
		case SC_WATK_ELEMENT:
		case SC_ARMOR_ELEMENT:
		case SC_LONGING:
		case SC_ORCISH:
		case SC_SHRINK:
		case SC_WINKCHARM:
		case SC_SCRESIST:
		case SC_STOP:
		case SC_CLOSECONFINE:
		case SC_SKILLRATE_UP:
		case SC_KAIZEL:
		case SC_KAAHI:
		case SC_INTRAVISION:
		case SC_BASILICA:
			break;

		default:
			if(battle_config.error_log)
				ShowError("UnknownStatusChange [%d]\n", type);
			return 0;
	}

	if (bl->type == BL_PC && (battle_config.display_hallucination || type != SC_HALLUCINATION))
	{
		if (flag&4)
			clif_status_load(bl,StatusIconChangeTable[type],1); //Sending to owner since they aren't in the map yet. [Skotlex]
		clif_status_change(bl,StatusIconChangeTable[type],1);
	}

	/* option��?�X */
	switch(type){
		case SC_STONE:
		case SC_FREEZE:
		case SC_STAN:
		case SC_SLEEP:

			// Cancel cast when get status [LuzZza]
			if (bl->type == BL_PC) {
				struct map_session_data *sd = (struct map_session_data *)bl; //Only Pressure is uninterruptable.
				if (sd->skilltimer != -1 && sd->skillid != PA_PRESSURE) skill_castcancel(bl, 0);
			} else
			if (bl->type == BL_MOB) {
				if (((struct mob_data *)bl)->skilltimer != -1) skill_castcancel(bl, 0);
			}	    		

			battle_stopattack(bl);	/* �U?��~ */
			skill_stop_dancing(bl);	/* ���t/�_���X�̒�? */
			{	/* �����Ɋ|����Ȃ��X�e?�^�X�ُ������ */
				int i;
				for(i = SC_STONE; i <= SC_SLEEP; i++){
					if(sc->data[i].timer != -1){
						(sc->count)--;
						delete_timer(sc->data[i].timer, status_change_timer);
						sc->data[i].timer = -1;
					}
				}
			}
			if(type == SC_STONE)
				sc->opt1 = OPT1_STONEWAIT;
			else
				sc->opt1 = OPT1_STONE + (type - SC_STONE);
			opt_flag = 1;
			break;
		case SC_POISON:
		case SC_CURSE:
		case SC_SILENCE:
		case SC_BLIND:
			sc->opt2 |= 1<<(type-SC_POISON);
			opt_flag = 1;
			break;
		case SC_DPOISON:	// �b��œł̃G�t�F�N�g���g�p
			sc->opt2 |= OPT2_DPOISON;
			opt_flag = 1;
			break;
		case SC_SIGNUMCRUCIS:
			sc->opt2 |= OPT2_SIGNUMCRUCIS;
			opt_flag = 1;
			break;
		case SC_HIDING:
		case SC_CLOAKING:
			battle_stopattack(bl);	/* �U?��~ */
			sc->option |= ((type==SC_HIDING)?OPTION_HIDE:OPTION_CLOAK);
			opt_flag =1 ;
			break;
		case SC_CHASEWALK:
			battle_stopattack(bl);	/* �U?��~ */
			sc->option |= OPTION_CHASEWALK|OPTION_CLOAK;
			opt_flag =1 ;
			break;
		case SC_SIGHT:
			sc->option |= OPTION_SIGHT;
			opt_flag = 1;
			break;
		case SC_RUWACH:
			sc->option |= OPTION_RUWACH;
			opt_flag = 1;
			break;
		case SC_WEDDING:
			sc->option |= OPTION_WEDDING;
			opt_flag = 1;
			break;
		case SC_ORCISH:
			sc->option |= OPTION_ORCISH;
			opt_flag = 1;
			break;
		case SC_SIGHTTRASHER:
			sc->option |= OPTION_SIGHTTRASHER;
			opt_flag = 1;
			break;
		case SC_FUSION:
			sc->option |= OPTION_FLYING;
			opt_flag = 1;
			break;
	}

	if(opt_flag)	/* option��?�X */
		clif_changeoption(bl);

	(sc->count)++;	/* �X�e?�^�X�ُ��? */

	sc->data[type].val1 = val1;
	sc->data[type].val2 = val2;
	sc->data[type].val3 = val3;
	sc->data[type].val4 = val4;
	/* �^�C�}?�ݒ� */
	sc->data[type].timer = add_timer(
		gettick() + tick, status_change_timer, bl->id, type);

	if(bl->type==BL_PC && calc_flag)
		status_calc_pc(sd,0);	/* �X�e?�^�X�Čv�Z */

	if(bl->type==BL_PC && save_flag)
		chrif_save(sd,0); // save the player status

	if(bl->type==BL_PC && updateflag)
		clif_updatestatus(sd,updateflag);	/* �X�e?�^�X���N���C�A���g�ɑ��� */

	if (bl->type==BL_PC && sd->pd)
		pet_sc_check(sd, type); //Skotlex: Pet Status Effect Healing

	if(type==SC_RUN && bl->type==BL_PC)
		pc_run(sd,val1,val2);
	
	return 0;
}
/*==========================================
 * �X�e�[�^�X�ُ�S����
 *------------------------------------------
 */
int status_change_clear(struct block_list *bl,int type)
{
	struct status_change* sc;
	int i;

	nullpo_retr(0, sc = status_get_sc(bl));

	if (sc->count == 0)
		return 0;
	for(i = 0; i < SC_MAX; i++)
	{
		//Type 0: PC killed -> EDP and Meltdown must not be dispelled. [Skotlex]
		// Do not reset Xmas status when killed. [Valaris]
		if(sc->data[i].timer == -1 ||
			(type == 0 && (i == SC_EDP || i == SC_MELTDOWN || i == SC_XMAS)))
			continue;

		status_change_end(bl, i, -1);

		if (type == 1 && sc->data[i].timer != -1)
		{	//If for some reason status_change_end decides to still keep the status when quitting. [Skotlex]
			(sc->count)--;
			delete_timer(sc->data[i].timer, status_change_timer);
			sc->data[i].timer = -1;
		}
	}
	sc->opt1 = 0;
	sc->opt2 = 0;
	sc->opt3 = 0;
	sc->option &= OPTION_MASK;

	if(!type || type&2)
		clif_changeoption(bl);

	return 0;
}

/*==========================================
 * �X�e�[�^�X�ُ�I��
 *------------------------------------------
 */
int status_change_end( struct block_list* bl , int type,int tid )
{
	struct map_session_data *sd;
	struct status_change *sc;
	int opt_flag=0, calc_flag = 0;

	nullpo_retr(0, bl);
	
	sc = status_get_sc(bl);
	if(!sc) {
		if(battle_config.error_log)
			ShowError("status_change_end: BL type %d doesn't has sc data!\n", bl->type);
		return 0;
	}

	if(type < 0 || type >= SC_MAX)
		return 0;

	sd = bl->type==BL_PC?(struct map_session_data *)bl:NULL;

	if (sc->data[type].timer != -1 && (sc->data[type].timer == tid || tid == -1)) {

		if (tid == -1)	// �^�C�}����Ă΂�Ă��Ȃ��Ȃ�^�C�}�폜������
			delete_timer(sc->data[type].timer,status_change_timer);

		/* �Y?�ُ̈�𐳏��?�� */
		sc->data[type].timer=-1;
		(sc->count)--;

		switch(type){	/* �ُ�̎�ނ��Ƃ�?�� */
			case SC_PROVOKE:			/* �v���{�b�N */
			case SC_ENDURE: // celest
			case SC_CONCENTRATE:		/* �W���͌��� */
			case SC_BLESSING:			/* �u���b�V���O */
			case SC_ANGELUS:			/* �A���[���X */
			case SC_INCREASEAGI:		/* ���x�㏸ */
			case SC_DECREASEAGI:		/* ���x���� */
			case SC_SIGNUMCRUCIS:		/* �V�O�i���N���V�X */
			case SC_HIDING:
			case SC_ONEHAND:
			case SC_TWOHANDQUICKEN:		/* 2HQ */
			case SC_ADRENALINE2:
			case SC_ADRENALINE:			/* �A�h���i�������b�V�� */
			case SC_ENCPOISON:			/* �G���`�����g�|�C�Y�� */
			case SC_IMPOSITIO:			/* �C���|�V�e�B�I�}�k�X */
			case SC_GLORIA:				/* �O�����A */
			case SC_LOUD:				/* ���E�h�{�C�X */
			case SC_QUAGMIRE:			/* �N�@�O�}�C�A */
			case SC_PROVIDENCE:			/* �v�����B�f���X */
			case SC_SPEARSQUICKEN:		/* �X�s�A�N�C�b�P�� */
			case SC_VOLCANO:
			case SC_DELUGE:
			case SC_VIOLENTGALE:
			case SC_ETERNALCHAOS:		/* �G�^?�i���J�I�X */
			case SC_DRUMBATTLE:			/* ?���ۂ̋��� */
			case SC_NIBELUNGEN:			/* �j?�x�����O�̎w�� */
			case SC_SIEGFRIED:			/* �s���g�̃W?�N�t��?�h */
			case SC_WHISTLE:			/* ���J */
			case SC_ASSNCROS:			/* �[�z�̃A�T�V���N���X */
			case SC_HUMMING:			/* �n�~���O */
			case SC_DONTFORGETME:		/* ����Y��Ȃ��� */
			case SC_FORTUNE:			/* �K�^�̃L�X */
			case SC_SERVICE4U:			/* �T?�r�X�t�H?��? */
			case SC_EXPLOSIONSPIRITS:	// �����g��
			case SC_STEELBODY:			// ����
			case SC_APPLEIDUN:			/* �C�h�D���̗ь� */
			case SC_BLADESTOP_WAIT:
			case SC_CONCENTRATION:		/* �R���Z���g��?�V���� */
			case SC_ASSUMPTIO:			/* �A�V�����v�e�B�I */
			case SC_WINDWALK:		/* �E�C���h�E�H?�N */
			case SC_TRUESIGHT:		/* �g�D��?�T�C�g */
			case SC_SPIDERWEB:		/* �X�p�C�_?�E�F�b�u */
			case SC_MAGICPOWER:		/* ���@��?�� */
			case SC_CHASEWALK:
			case SC_ATKPOTION:		// [Valaris]
			case SC_MATKPOTION:		// [Valaris]
			case SC_MELTDOWN:		/* �����g�_�E�� */
			case SC_CARTBOOST:
			case SC_MINDBREAKER:		/* �}�C���h�u���[�J�[ */
			case SC_EDP:	// Celest
			case SC_SLOWDOWN:
			case SC_ASPDPOTION0:		/* ?���|?�V���� */
			case SC_ASPDPOTION1:
			case SC_ASPDPOTION2:
			case SC_ASPDPOTION3:
			case SC_SPEEDUP0:
			case SC_SPEEDUP1:
			case SC_INCALLSTATUS:
			case SC_INCHIT:			/* HIT�㏸ */
			case SC_INCHITRATE:		/* HIT%�㏸ */
			case SC_INCFLEE:		/* FLEE�㏸ */
			case SC_INCFLEERATE:		/* FLEE%�㏸ */
			case SC_INCMHPRATE:		/* MHP%�㏸ */
			case SC_INCMSPRATE:		/* MSP%�㏸ */
			case SC_INCATKRATE:		/* ATK%�㏸ */
			case SC_INCMATKRATE:
			case SC_INCDEFRATE:
			case SC_INCSTR:
			case SC_INCAGI:
			case SC_INCVIT:
			case SC_INCINT:
			case SC_INCDEX:
			case SC_INCLUK:
			case SC_STRFOOD:
			case SC_AGIFOOD:
			case SC_VITFOOD:
			case SC_INTFOOD:
			case SC_DEXFOOD:
			case SC_LUKFOOD:
			case SC_FLEEFOOD:
			case SC_HITFOOD:
			case SC_BATKFOOD:
			case SC_WATKFOOD:
			case SC_MATKFOOD:
			case SC_BATTLEORDERS:
			case SC_REGENERATION:
			case SC_GUILDAURA:
			case SC_SPURT:
			case SC_SPIRIT: 
			case SC_SUN_COMFORT:
			case SC_MOON_COMFORT:
			case SC_STAR_COMFORT:
			case SC_FUSION:
			case SC_SKE:
			case SC_SWOO: // [marquis007]
			case SC_SKA: // [marquis007]
				calc_flag = 1;
				break;

			case SC_XMAS: // Xmas Suit [Valaris]
			case SC_WEDDING:	//�����p(�����ߏւɂȂ���?���̂�?���Ƃ�)
			if (sd) {
				//Restore look
				sd->view_class = sd->status.class_;
				clif_changelook(&sd->bl,LOOK_BASE,sd->view_class);
#if PACKETVER < 4
				clif_changelook(&sd->bl,LOOK_WEAPON,sd->status.weapon);
				clif_changelook(&sd->bl,LOOK_SHIELD,sd->status.shield);
#else
				clif_changelook(&sd->bl,LOOK_WEAPON,0);
#endif
				if(battle_config.save_clothcolor && sd->status.clothes_color > 0)
					clif_changelook(&sd->bl,LOOK_CLOTHES_COLOR,sd->status.clothes_color);
			}
			break;
			case SC_RUN://�삯��
				if (sd && sd->walktimer != -1)
						pc_stop_walking(sd,1);
				if (sc->data[type].val1 >= 7 &&
					DIFF_TICK(gettick(), sc->data[type].val4) <= 1000 &&
					(!sd || (sd->weapontype1 == 0 && sd->weapontype2 == 0))
				)
					status_change_start(bl,SC_SPURT,sc->data[type].val1,0,0,0,skill_get_time2(TK_RUN, sc->data[type].val1),0);
				calc_flag = 1;
			break;
			case SC_AUTOBERSERK:
				if (sc->data[SC_PROVOKE].timer != -1 && sc->data[SC_PROVOKE].val2 == 1)
					status_change_end(bl,SC_PROVOKE,-1);
				break;

			case SC_DEFENDER:
				calc_flag = 1;
			case SC_AUTOGUARD:
			if (sd) {
				struct map_session_data *tsd;
				int i;
				for (i = 0; i < 5; i++)
				{	//Clear the status from the others too [Skotlex]
					if (sd->devotion[i] && (tsd = map_id2sd(sd->devotion[i])) && tsd->sc.data[type].timer != -1)
						status_change_end(&tsd->bl,type,-1);
				}
			}
			break;
			case SC_DEVOTION:		/* �f�B�{?�V���� */
				{
					struct map_session_data *md = map_id2sd(sc->data[type].val1);
					//The status could have changed because the Crusader left the game. [Skotlex]
					if (md)
					{
						md->devotion[sc->data[type].val2] = 0;
						clif_devotion(md);
					}
					//Remove AutoGuard and Defender [Skotlex]
					if (sc->data[SC_AUTOGUARD].timer != -1)
						status_change_end(bl,SC_AUTOGUARD,-1);
					if (sc->data[SC_DEFENDER].timer != -1)
						status_change_end(bl,SC_DEFENDER,-1);
				}
				break;
			case SC_BLADESTOP:
				{
					struct status_change *tsc = status_get_sc((struct block_list *)sc->data[type].val4);
					//�Е����؂ꂽ�̂ő���̔��n?�Ԃ��؂�ĂȂ��̂Ȃ����
					if(tsc && tsc->data[SC_BLADESTOP].timer!=-1)
						status_change_end((struct block_list *)sc->data[type].val4,SC_BLADESTOP,-1);

					if(sc->data[type].val2==2)
						clif_bladestop((struct block_list *)sc->data[type].val3,(struct block_list *)sc->data[type].val4,0);
				}
				break;
			case SC_DANCING:
				{
					struct map_session_data *dsd;
					struct status_change *dsc;
					if(sc->data[type].val2)
					{
						skill_delunitgroup((struct skill_unit_group *)sc->data[type].val2);
						sc->data[type].val2 = 0;
					}
					if(sc->data[type].val4 && sc->data[type].val4 != BCT_SELF && (dsd=map_id2sd(sc->data[type].val4))){
						dsc = &dsd->sc;
						//���t�ő��肪����ꍇ�����val4��0�ɂ���
						if(dsc && dsc->data[type].timer!=-1)
						{
							dsc->data[type].val2 = dsc->data[type].val4 = 0; //This will prevent recursive loops. 
							status_change_end(&dsd->bl, type, -1);
						}
					}
					if(sc->data[type].val1 == CG_MOONLIT) //Only dance that doesn't has ground tiles... [Skotlex]
						status_change_end(bl, SC_MOONLIT, -1);
				}
				if (sc->data[SC_LONGING].timer!=-1)
					status_change_end(bl,SC_LONGING,-1);				
				calc_flag = 1;
				break;
			case SC_NOCHAT:	//�`���b�g�֎~?��
				if (sd) {
					if(battle_config.manner_system){
						if (sd->status.manner >= 0) // weeee ^^ [celest]
							sd->status.manner = 0;
						clif_updatestatus(sd,SP_MANNER);
					}
				}
				break;
			case SC_SPLASHER:		/* �x�i���X�v���b�V��? */
				{
					struct block_list *src=map_id2bl(sc->data[type].val3);
					if(src && tid!=-1){
						//�����Ƀ_��?�W����?3*3�Ƀ_��?�W
						skill_castend_damage_id(src, bl,sc->data[type].val2,sc->data[type].val1,gettick(),0 );
					}
				}
				break;
			case SC_CLOSECONFINE2:
				{
					struct block_list *src = sc->data[type].val2?map_id2bl(sc->data[type].val2):NULL;
					struct status_change *sc2 = src?status_get_sc(src):NULL;
					if (src && sc2 && sc2->count) {
						if (sc2->data[SC_CLOSECONFINE].timer != -1) //If status was already ended, do nothing.
						{ //Decrease count
							if (--sc2->data[SC_CLOSECONFINE].val1 <= 0) //No more holds, free him up.
								status_change_end(src, SC_CLOSECONFINE, -1);
						}
					}
				}
				break;
			case SC_CLOSECONFINE:
				if (sc->data[type].val1 > 0) { //Caster has been unlocked... nearby chars need to be unlocked.
					int range = 2*skill_get_range2(bl, RG_CLOSECONFINE, 1);
					map_foreachinarea(status_change_timer_sub, 
						bl->m, bl->x-range, bl->y-range, bl->x+range,bl->y+range,BL_CHAR,bl,sc,type,gettick());
				}
				break;
		/* option1 */
			case SC_FREEZE:
				sc->data[type].val3 = 0;
				break;

		/* option2 */
			case SC_POISON:				/* �� */
			case SC_BLIND:				/* ��? */
			case SC_CURSE:
				calc_flag = 1;
				break;

			case SC_MARIONETTE:		/* �}���I�l�b�g�R���g��?�� */
			case SC_MARIONETTE2:	/// Marionette target
				{
					// check for partner and end their marionette status as well
					int type2 = (type == SC_MARIONETTE) ? SC_MARIONETTE2 : SC_MARIONETTE;
					struct block_list *pbl = map_id2bl(sc->data[type].val3);
					struct status_change* sc2 = pbl?status_get_sc(pbl):NULL;
					if (pbl && sc2 && sc2->count && sc2->data[type2].timer != -1)
							status_change_end(pbl, type2, -1);
					if (type == SC_MARIONETTE)
						clif_marionette(bl, 0); 
					calc_flag = 1;
				}
				break;

			case SC_BERSERK: //val4 indicates if the skill was dispelled. [Skotlex]
				if (sd && sd->status.hp > 100 && !sc->data[type].val4) {
					sd->status.hp = 100;
					clif_updatestatus(sd,SP_HP);
				}
				calc_flag = 1;
				break;
				
			case SC_GRAVITATION:
				if (sd) {
					if (sc->data[type].val3 == BCT_SELF) {
						unsigned int tick = gettick();
						sd->canmove_tick = tick;
						sd->canact_tick = tick;
					} else calc_flag = 1;
				}
				break;
			
			case SC_GOSPEL: //Clear the buffs from other chars.
				if(sc->data[type].val4 != BCT_SELF)
					calc_flag = 1;
				else if (sc->data[type].val3) { //Clear the group.
					struct skill_unit_group *group = (struct skill_unit_group *)sc->data[type].val3;
					sc->data[type].val3 = 0;
					skill_delunitgroup(group);
				}
				break;
			case SC_HERMODE: 
			case SC_BASILICA: //Clear the skill area. [Skotlex]
				if(sc->data[type].val3 == BCT_SELF)
					skill_clear_unitgroup(bl);
				break;
			case SC_MOONLIT: //Clear the unit effect. [Skotlex]
				skill_setmapcell(bl,CG_MOONLIT, sc->data[SC_MOONLIT].val1, CELL_CLRMOONLIT);
				break;
			}


		if (sd && (battle_config.display_hallucination || type != SC_HALLUCINATION))
			clif_status_change(bl,StatusIconChangeTable[type],0);

		switch(type){	/* �����?��Ƃ��Ȃɂ�?�����K�v */
		case SC_STONE:
		case SC_FREEZE:
		case SC_STAN:
		case SC_SLEEP:
			sc->opt1 = 0;
			opt_flag = 1;
			break;

		case SC_POISON:
		case SC_CURSE:
		case SC_SILENCE:
		case SC_BLIND:
			sc->opt2 &= ~(1<<(type-SC_POISON));
			opt_flag = 1;
			break;
		case SC_DPOISON:
			sc->opt2 &= ~OPT2_DPOISON;	// ��?�ԉ���
			opt_flag = 1;
			break;
		case SC_SIGNUMCRUCIS:
			sc->opt2 &= ~OPT2_SIGNUMCRUCIS;
			opt_flag = 1;
			break;

		case SC_HIDING:
			sc->option &= ~OPTION_HIDE;
			opt_flag = 1 ;
			break;
		case SC_CLOAKING:
			sc->option &= ~OPTION_CLOAK;
			calc_flag = 1;	// orn
			opt_flag = 1 ;
			break;
		case SC_CHASEWALK:
			sc->option &= ~(OPTION_CHASEWALK|OPTION_CLOAK);
			opt_flag = 1 ;
			break;
		case SC_SIGHT:
			sc->option &= ~OPTION_SIGHT;
			opt_flag = 1;
			break;
		case SC_WEDDING:	//�����p(�����ߏւɂȂ���?���̂�?���Ƃ�)
			sc->option &= ~OPTION_WEDDING;
			opt_flag = 1;
			break;
		case SC_ORCISH:
			sc->option &= ~OPTION_ORCISH;
			opt_flag = 1;
			break;
		case SC_RUWACH:
			sc->option &= ~OPTION_RUWACH;
			opt_flag = 1;
			break;
		case SC_SIGHTTRASHER:
			sc->option &= ~OPTION_SIGHTTRASHER;
			opt_flag = 1;
			break;
		case SC_FUSION:
			sc->option &= ~OPTION_FLYING;
			opt_flag = 1;
			break;
		//opt3
		case SC_TWOHANDQUICKEN:		/* 2HQ */
		case SC_ONEHAND:		/* 1HQ */
		case SC_SPEARSQUICKEN:		/* �X�s�A�N�C�b�P�� */
		case SC_CONCENTRATION:		/* �R���Z���g��?�V���� */
			sc->opt3 &= ~1;
			break;
		case SC_OVERTHRUST:			/* �I?�o?�X���X�g */
			sc->opt3 &= ~2;
			break;
		case SC_ENERGYCOAT:			/* �G�i�W?�R?�g */
			sc->opt3 &= ~4;
			break;
		case SC_EXPLOSIONSPIRITS:	// �����g��
			sc->opt3 &= ~8;
			break;
		case SC_STEELBODY:			// ����
		case SC_SKA:
			sc->opt3 &= ~16;
			break;
		case SC_BLADESTOP:		/* ���n��� */
			sc->opt3 &= ~32;
			break;
		case SC_BERSERK:		/* �o?�T?�N */
			sc->opt3 &= ~128;
			break;
		case SC_MARIONETTE:		/* �}���I�l�b�g�R���g��?�� */
		case SC_MARIONETTE2:
			sc->opt3 &= ~1024;
			break;
		case SC_ASSUMPTIO:		/* �A�X���v�e�B�I */
			sc->opt3 &= ~2048;
			break;
		case SC_WARM: //SG skills [Komurka]
			sc->opt3 &= ~4096;
			break;
		}

		if(opt_flag)	/* option��?�X��?���� */
			clif_changeoption(bl);

		if (sd && calc_flag)
			status_calc_pc((struct map_session_data *)bl,0);	/* �X�e?�^�X�Čv�Z */
	}

	return 0;
}


/*==========================================
 * �X�e�[�^�X�ُ�I���^�C�}�[
 *------------------------------------------
 */
int status_change_timer(int tid, unsigned int tick, int id, int data)
{
	int type = data;
	struct block_list *bl;
	struct map_session_data *sd=NULL;
	struct status_change *sc;

// security system to prevent forgetting timer removal
	int temp_timerid;

	bl=map_id2bl(id);
#ifndef _WIN32
	nullpo_retr_f(0, bl, "id=%d data=%d",id,data);
#endif
	nullpo_retr(0, sc=status_get_sc(bl));

	if(bl->type==BL_PC)
		sd=(struct map_session_data *)bl;

	if(sc->data[type].timer != tid) {
		if(battle_config.error_log)
			ShowError("status_change_timer %d != %d\n",tid,sc->data[type].timer);
		return 0;
	}

	// security system to prevent forgetting timer removal
	// you shouldn't be that careless inside the switch here
	temp_timerid = sc->data[type].timer;
	sc->data[type].timer = -1;

	switch(type){	/* �����?���ɂȂ�ꍇ */
	case SC_MAXIMIZEPOWER:	/* �}�L�V�}�C�Y�p��? */
	case SC_CLOAKING:
		if(!sd || sd->status.sp > 0)
		{
			if (sd)
			{
				sd->status.sp--;
				clif_updatestatus(sd,SP_SP);
			}
			sc->data[type].timer=add_timer( /* �^�C�}?�Đݒ� */
				sc->data[type].val2+tick, status_change_timer, bl->id, data);
			return 0;
		}
		break;

	case SC_CHASEWALK:
		if(sd){
			int sp = 10+sc->data[SC_CHASEWALK].val1*2;
			if (map_flag_gvg(sd->bl.m)) sp *= 5;
			if (sd->status.sp > sp){
				sd->status.sp -= sp; // update sp cost [Celest]
				clif_updatestatus(sd,SP_SP);
				if ((++sc->data[SC_CHASEWALK].val4) == 1) {
					status_change_start(bl, SC_INCSTR, 1<<(sc->data[SC_CHASEWALK].val1-1), 0, 0, 0,
						(sc->data[SC_SPIRIT].timer != -1 && sc->data[SC_SPIRIT].val2 == SL_ROGUE?10:1) //SL bonus -> x10 duration
						*skill_get_time2(ST_CHASEWALK,sc->data[SC_CHASEWALK].val1), 0);
				}
				sc->data[type].timer = add_timer( /* �^�C�}?�Đݒ� */
					sc->data[type].val2+tick, status_change_timer, bl->id, data);
				return 0;
			}
		}
	break;

	case SC_HIDING:		/* �n�C�f�B���O */
		if(sd){		/* SP�������āA���Ԑ����̊Ԃ͎�? */
			if( sd->status.sp > 0 && (--sc->data[type].val2)>0 ){
				if(sc->data[type].val2 % (sc->data[type].val1+3) ==0 ){
					sd->status.sp--;
					clif_updatestatus(sd,SP_SP);
				}
				sc->data[type].timer=add_timer(	/* �^�C�}?�Đݒ� */
					1000+tick, status_change_timer,
					bl->id, data);
				return 0;
			}
		}
	break;

	case SC_SIGHT:	/* �T�C�g */
	case SC_RUWACH:	/* ���A�t */
	case SC_SIGHTBLASTER:
		{
			int range = skill_get_range2(bl, type==SC_SIGHT?MG_SIGHT:(type==SC_RUWACH?AL_RUWACH:WZ_SIGHTBLASTER), sc->data[type].val1);
			map_foreachinarea( status_change_timer_sub,
				bl->m, bl->x-range, bl->y-range, bl->x+range,bl->y+range,BL_CHAR,
				bl,sc,type,tick);

			if( (--sc->data[type].val2)>0 ){
				sc->data[type].timer=add_timer(	/* �^�C�}?�Đݒ� */
					250+tick, status_change_timer,
					bl->id, data);
				return 0;
			}
		}
		break;

	case SC_SIGNUMCRUCIS:		/* �V�O�i���N���V�X */
		{
			int race = status_get_race(bl);
			if(race == 6 || battle_check_undead(race,status_get_elem_type(bl))) {
				sc->data[type].timer=add_timer(1000*600+tick,status_change_timer, bl->id, data );
				return 0;
			}
		}
		break;

	case SC_WARM: //SG skills [Komurka]
		if( (--sc->data[type].val2)>0){
			map_foreachinarea( status_change_timer_sub,
				bl->m, bl->x-sc->data[type].val4, bl->y-sc->data[type].val4, bl->x+sc->data[type].val4,bl->y+sc->data[type].val4,BL_CHAR,
				bl,sc,type,tick);
			sc->data[type].timer=add_timer(tick+1000, status_change_timer,bl->id, data);
			return 0;
		}
		break;

	case SC_PROVOKE:	/* �v���{�b�N/�I?�g�o?�T?�N */
		if(sc->data[type].val2!=0){	/* �I?�g�o?�T?�N�i�P�b���Ƃ�HP�`�F�b�N�j */
			if(sd && sd->status.hp>sd->status.max_hp>>2)	/* ��~ */
				break;
			sc->data[type].timer=add_timer( 1000+tick,status_change_timer, bl->id, data );
			return 0;
		}
		break;

	case SC_ENDURE:	/* �C���f���A */
		if(sd && sd->special_state.infinite_endure) {
			sc->data[type].timer=add_timer( 1000*60+tick,status_change_timer, bl->id, data );
			return 0;
		}
		break;

	case SC_STONE:
		if(sc->data[type].val2 != 0) {
			sc->data[type].val2 = 0;
			sc->data[type].val4 = 0;
			battle_stopwalking(bl,1);
			sc->opt1 = OPT1_STONE;
			clif_changeoption(bl);
			sc->data[type].timer=add_timer(1000+tick,status_change_timer, bl->id, data );
			return 0;
		}
		else if( (--sc->data[type].val3) > 0) {
			int hp = status_get_max_hp(bl);
			if((++sc->data[type].val4)%5 == 0 && status_get_hp(bl) > hp>>2) {
				hp = hp/100;
				if(hp < 1) hp = 1;
				if(sd)
					pc_heal(sd,-hp,0);
				else if(bl->type == BL_MOB){
					struct mob_data *md;
					if((md=((struct mob_data *)bl)) == NULL)
						break;
					md->hp -= hp;
				}
			}
			sc->data[type].timer=add_timer(1000+tick,status_change_timer, bl->id, data );
			return 0;
		}
		break;

	case SC_POISON:
		if (status_get_hp(bl) <= status_get_max_hp(bl)>>2) //Stop damaging after 25% HP left.
			break;
	case SC_DPOISON:
		if ((--sc->data[type].val3) > 0 && sc->data[SC_SLOWPOISON].timer == -1) {
			if(sd) {
				pc_heal(sd, -sc->data[type].val4, 0);
			} else if (bl->type == BL_MOB) {
				((struct mob_data*)bl)->hp -= sc->data[type].val4;
				if (battle_config.show_mob_hp)
					clif_charnameack (0, bl);
			} else 
				battle_heal(NULL, bl, -sc->data[type].val4, 0, 1);
		}
		if (sc->data[type].val3 > 0 && !status_isdead(bl))
		{
			sc->data[type].timer = add_timer (1000 + tick, status_change_timer, bl->id, data );
			return 0;
		}
		break;

	case SC_TENSIONRELAX:	/* �e���V���������b�N�X */
		if(sd){		/* SP�������āAHP��?�^���łȂ����?? */
			if( sd->status.sp > 12 && sd->status.max_hp > sd->status.hp ){
				sc->data[type].timer=add_timer(	/* �^�C�}?�Đݒ� */
					10000+tick, status_change_timer,
					bl->id, data);
				return 0;
			}
			if(sd->status.max_hp <= sd->status.hp)
			{
				status_change_end(&sd->bl,SC_TENSIONRELAX,-1);
				return 0;
			}
		}
		break;
	case SC_BLEEDING:	// [celest]
		// i hope i haven't interpreted it wrong.. which i might ^^;
		// Source:
		// - 10�����Ȫ�HP�����
		// - ����Ϊުޫ�?����Ѫ��������ƪ�?����Ἢ��ʪ�
		// To-do: bleeding effect increases damage taken?
		if ((sc->data[type].val4 -= 10000) >= 0) {
			int hp = rand()%300 + 400;
			if(sd) {
				pc_heal(sd,-hp,0);
			} else if(bl->type == BL_MOB) {
				struct mob_data *md = (struct mob_data *)bl;
				if (md) md->hp -= hp;
			}
			if (!status_isdead(bl)) {
				// walking and casting effect is lost
				battle_stopwalking (bl, 1);
				skill_castcancel (bl, 0);
				sc->data[type].timer = add_timer(10000 + tick, status_change_timer, bl->id, data );
			}
			return 0;
		}
		break;

	// Status changes that don't have a time limit
	case SC_AETERNA:
	case SC_TRICKDEAD:
	case SC_WEIGHT50:
	case SC_WEIGHT90:
	case SC_MAGICPOWER:
	case SC_REJECTSWORD:
	case SC_MEMORIZE:
	case SC_BROKENWEAPON:
	case SC_BROKENARMOR:
	case SC_SACRIFICE:
	case SC_READYSTORM:
	case SC_READYDOWN:
	case SC_READYTURN:
	case SC_READYCOUNTER:
	case SC_RUN:
	case SC_DODGE:
	case SC_AUTOBERSERK: //continues until triggered off manually. [Skotlex]
		sc->data[type].timer=add_timer( 1000*600+tick,status_change_timer, bl->id, data );
		return 0;

	case SC_DANCING: //�_���X�X�L���̎���SP����
		{
			int s = 0;
			int sp = 1;
			if(sd && (--sc->data[type].val3) > 0) {
				switch(sc->data[type].val1){
				case BD_RICHMANKIM:				/* �j�����h�̉� 3�b��SP1 */
				case BD_DRUMBATTLEFIELD:		/* ?���ۂ̋��� 3�b��SP1 */
				case BD_RINGNIBELUNGEN:			/* �j?�x�����O�̎w�� 3�b��SP1 */
				case BD_SIEGFRIED:				/* �s���g�̃W?�N�t��?�h 3�b��SP1 */
				case BA_DISSONANCE:				/* �s���a�� 3�b��SP1 */
				case BA_ASSASSINCROSS:			/* �[�z�̃A�T�V���N���X 3�b��SP1 */
				case DC_UGLYDANCE:				/* ��������ȃ_���X 3�b��SP1 */
					s=3;
					break;
				case BD_LULLABY:				/* �q��� 4�b��SP1 */
				case BD_ETERNALCHAOS:			/* �i���̍��� 4�b��SP1 */
				case BD_ROKISWEIL:				/* ���L�̋��� 4�b��SP1 */
				case DC_FORTUNEKISS:			/* �K�^�̃L�X 4�b��SP1 */
					s=4;
					break;
				case CG_HERMODE:				// Wand of Hermod
					sp=5;	//Upkeep = 5
				case BD_INTOABYSS:				/* �[���̒��� 5�b��SP1 */
				case BA_WHISTLE:				/* ���J 5�b��SP1 */
				case DC_HUMMING:				/* �n�~���O 5�b��SP1 */
				case BA_POEMBRAGI:				/* �u���M�̎� 5�b��SP1 */
				case DC_SERVICEFORYOU:			/* �T?�r�X�t�H?��? 5�b��SP1 */
					s=5;
					break;
				case BA_APPLEIDUN:				/* �C�h�D���̗ь� 6�b��SP1 */
					s=6;
					break;
				case CG_MOONLIT:				/* ������̐�ɗ�����Ԃт� 10�b��SP1�H */
					sp= 4*sc->data[type].val2; //Moonlit's cost is 4sp*skill_lv [Skotlex]
					//Upkeep is also every 10 secs.
				case DC_DONTFORGETME:			/* ����Y��Ȃ��Łc 10�b��SP1 */
					s=10;
					break;
				}
				if (s && ((sc->data[type].val3 % s) == 0)) {
					if (sc->data[SC_LONGING].timer != -1)
						sp = s;
					if (sp > sd->status.sp)
						sp = sd->status.sp;
					sd->status.sp -= sp;
					clif_updatestatus(sd,SP_SP);
					if (sd->status.sp <= 0)
						break;
				}
				sc->data[type].timer=add_timer(	/* �^�C�}?�Đݒ� */
					1000+tick, status_change_timer,
					bl->id, data);
				return 0;
			}
		}
		break;

	case SC_DEVOTION:
		{	//Check range and timeleft to preserve status [Skotlex]
			//This implementation won't work for mobs because of map_id2sd, but it's a small cost in exchange of the speed of map_id2sd over map_id2sd
			struct map_session_data *md = map_id2sd(sc->data[type].val1);
			if (md && battle_check_range(bl, &md->bl, sc->data[type].val3) && (sc->data[type].val4-=1000)>0)
			{
				sc->data[type].timer = add_timer(1000+tick, status_change_timer, bl->id, data);
				return 0;
			}
		}
		break;
		
	case SC_BERSERK:		/* �o?�T?�N */
		if(sd){		/* HP��100�ȏ�Ȃ�?? */
			if( (sd->status.hp - sd->status.max_hp*5/100) > 100 ){	// 5% every 10 seconds [DracoRPG]
				sd->status.hp -= sd->status.max_hp*5/100;	// changed to max hp [celest]
				clif_updatestatus(sd,SP_HP);
				sc->data[type].timer = add_timer(	/* �^�C�}?�Đݒ� */
					10000+tick, status_change_timer,
					bl->id, data);
				return 0;
			}
			else
				sd->canregen_tick = gettick() + 300000;
		}
		break;
	case SC_NOCHAT:	//�`���b�g�֎~?��
		if(sd && battle_config.manner_system){
			sd->status.manner++;
			clif_updatestatus(sd,SP_MANNER);
			if (sd->status.manner < 0)
			{	//Every 60 seconds your manner goes up by 1 until it gets back to 0.
				sc->data[type].timer=add_timer(60000+tick, status_change_timer, bl->id, data);
				return 0;
			}
		}
		break;

	case SC_SPLASHER:
		if (sc->data[type].val4 % 1000 == 0) {
			char timer[2];
			sprintf (timer, "%d", sc->data[type].val4/1000);
			clif_message(bl, timer);
		}
		if((sc->data[type].val4 -= 500) > 0) {
			sc->data[type].timer = add_timer(
				500 + tick, status_change_timer,
				bl->id, data);
				return 0;
		}
		break;

	case SC_MARIONETTE:		/* �}���I�l�b�g�R���g��?�� */
	case SC_MARIONETTE2:
		{
			struct block_list *pbl = map_id2bl(sc->data[type].val3);
			if (pbl && battle_check_range(bl, pbl, 7) &&
				(sc->data[type].val2 -= 1000)>0) {
				sc->data[type].timer = add_timer(
					1000 + tick, status_change_timer,
					bl->id, data);
					return 0;
			}
		}
		break;

	case SC_GOSPEL:
		if(sc->data[type].val4 == BCT_SELF){
			int hp, sp;
			hp = (sc->data[type].val1 > 5) ? 45 : 30;
			sp = (sc->data[type].val1 > 5) ? 35 : 20;
			if(status_get_hp(bl) - hp > 0 &&
				(sd == NULL || sd->status.sp - sp> 0))
			{
				if (sd)
					pc_heal(sd,-hp,-sp);
				else if (bl->type == BL_MOB)
					mob_heal((struct mob_data *)bl,-hp);
					
				if ((sc->data[type].val2 -= 10000) > 0) {
					sc->data[type].timer = add_timer(
					10000+tick, status_change_timer,
						bl->id, data);
					return 0;
				}
			}
		}
		break;
		
	case SC_GUILDAURA:
		{
			struct block_list *tbl = map_id2bl(sc->data[type].val2);
			
			if (tbl && battle_check_range(bl, tbl, 2)){
				sc->data[type].timer = add_timer(
					1000 + tick, status_change_timer,
					bl->id, data);
					return 0;
			}
		}
		break;
	}

	// default for all non-handled control paths
	// security system to prevent forgetting timer removal

	// if we reach this point we need the timer for the next call, 
	// so restore it to have status_change_end handle a valid timer
	sc->data[type].timer = temp_timerid; 

	return status_change_end( bl,type,tid );
}

/*==========================================
 * �X�e�[�^�X�ُ�^�C�}�[�͈͏���
 *------------------------------------------
 */
int status_change_timer_sub(struct block_list *bl, va_list ap )
{
	struct block_list *src;
	struct status_change *sc, *tsc;
	struct map_session_data* sd=NULL;
	struct map_session_data* tsd=NULL;

	int type;
	unsigned int tick;

	src=va_arg(ap,struct block_list*);
	sc=va_arg(ap,struct status_change*);
	type=va_arg(ap,int);
	tick=va_arg(ap,unsigned int);
	tsc=status_get_sc(bl);
	
	if (status_isdead(bl))
		return 0;
	if (src->type==BL_PC) sd= (struct map_session_data*)src;
	if (bl->type==BL_PC) tsd= (struct map_session_data*)bl;

	switch( type ){
	case SC_SIGHT:	/* �T�C�g */
	case SC_CONCENTRATE:
		if (tsc && tsc->count) {
			if (tsc->data[SC_HIDING].timer != -1)
				status_change_end( bl, SC_HIDING, -1);
			if (tsc->data[SC_CLOAKING].timer != -1)
				status_change_end( bl, SC_CLOAKING, -1);
		}
		break;
	case SC_RUWACH:	/* ���A�t */
		if (tsc && tsc->count && (tsc->data[SC_HIDING].timer != -1 ||	// if the target is using a special hiding, i.e not using normal hiding/cloaking, don't bother
			tsc->data[SC_CLOAKING].timer != -1)) {
			status_change_end( bl, SC_HIDING, -1);
			status_change_end( bl, SC_CLOAKING, -1);
			if(battle_check_target( src, bl, BCT_ENEMY ) > 0)
				skill_attack(BF_MAGIC,src,src,bl,AL_RUWACH,1,tick,0);
		}
		break;
	case SC_SIGHTBLASTER:
		{
			if (sc && sc->count && sc->data[type].val2 > 0 && battle_check_target( src, bl, BCT_ENEMY ) > 0)
			{	//sc_ check prevents a single round of Sight Blaster hitting multiple opponents. [Skotlex]
				skill_attack(BF_MAGIC,src,src,bl,WZ_SIGHTBLASTER,1,tick,0);
				sc->data[type].val2 = 0; //This signals it to end.
			}
		}
		break;
	case SC_WARM: //SG skills [Komurka]
		if(battle_check_target( src,bl, BCT_ENEMY ) > 0) {
			if(sd){
				if(sd->status.sp<2) {
					sd->sc.data[type].val2 = 0; //Makes it end on the next tick.
					break;
				}
				sd->status.sp -= 2;
				clif_updatestatus(sd,SP_SP);	
			}
			skill_attack(BF_WEAPON,src,src,bl,
				sc?sc->data[type].val3:SG_SUN_WARM,sc?sc->data[type].val1:1,
				tick,0);
		}
		break;
	case SC_CLOSECONFINE:
		//Lock char has released the hold on everyone...
		if (tsc && tsc->count && tsc->data[SC_CLOSECONFINE2].timer != -1 && tsc->data[SC_CLOSECONFINE2].val2 == src->id) {
			tsc->data[SC_CLOSECONFINE2].val2 = 0;
			status_change_end(bl, SC_CLOSECONFINE2, -1);
		}
		break;
	}
	return 0;
}

int status_change_clear_buffs (struct block_list *bl)
{
	int i;
	struct status_change *sc= status_get_sc(bl);
	if (!sc || !sc->count)
		return 0;		
	for (i = 20; i < SC_MAX; i++) {
		if(i==SC_HALLUCINATION || i==SC_WEIGHT50 || i==SC_WEIGHT90
			|| i == SC_QUAGMIRE || i == SC_SIGNUMCRUCIS || i == SC_DECREASEAGI 
			|| i == SC_SLOWDOWN || i == SC_ANKLE|| i == SC_BLADESTOP
			|| i == SC_MINDBREAKER || i == SC_WINKCHARM 
			|| i == SC_STOP || i == SC_NOCHAT || i == SC_ORCISH
			|| i == SC_STRIPWEAPON || i == SC_STRIPSHIELD || i == SC_STRIPARMOR || i == SC_STRIPHELM
			|| i == SC_COMBO || i == SC_DANCING || i == SC_GUILDAURA
			)
			continue;
		if(sc->data[i].timer != -1)
			status_change_end(bl,i,-1);
	}
	return 0;
}
int status_change_clear_debuffs (struct block_list *bl)
{
	int i;
	struct status_change *sc = status_get_sc(bl);
	if (!sc || !sc->count)
		return 0;
	for (i = SC_COMMON_MIN; i <= SC_COMMON_MAX; i++) {
		if(sc->data[i].timer != -1)
			status_change_end(bl,i,-1);
	}
	//Other ailments not in the common range.
	if(sc->data[SC_HALLUCINATION].timer != -1)
		status_change_end(bl,SC_HALLUCINATION,-1);
	if(sc->data[SC_QUAGMIRE].timer != -1)
		status_change_end(bl,SC_QUAGMIRE,-1);
	if(sc->data[SC_SIGNUMCRUCIS].timer != -1)
		status_change_end(bl,SC_SIGNUMCRUCIS,-1);
	if(sc->data[SC_DECREASEAGI].timer != -1)
		status_change_end(bl,SC_DECREASEAGI,-1);
	if(sc->data[SC_SLOWDOWN].timer != -1)
		status_change_end(bl,SC_SLOWDOWN,-1);
	if(sc->data[SC_MINDBREAKER].timer != -1)
		status_change_end(bl,SC_MINDBREAKER,-1);
	if(sc->data[SC_WINKCHARM].timer != -1)
		status_change_end(bl,SC_WINKCHARM,-1);
	if(sc->data[SC_STOP].timer != -1)
		status_change_end(bl,SC_STOP,-1);
	if(sc->data[SC_ORCISH].timer != -1)
		status_change_end(bl,SC_ORCISH,-1);
	if(sc->data[SC_STRIPWEAPON].timer != -1)
		status_change_end(bl,SC_STRIPWEAPON,-1);
	if(sc->data[SC_STRIPSHIELD].timer != -1)
		status_change_end(bl,SC_STRIPSHIELD,-1);
	if(sc->data[SC_STRIPARMOR].timer != -1)
		status_change_end(bl,SC_STRIPARMOR,-1);
	if(sc->data[SC_STRIPHELM].timer != -1)
		status_change_end(bl,SC_STRIPHELM,-1);
	return 0;
}

static int status_calc_sigma(void)
{
	int i,j,k;

	for(i=0;i<MAX_PC_CLASS;i++) {
		memset(hp_sigma_val[i],0,sizeof(hp_sigma_val[i]));
		for(k=0,j=2;j<=MAX_LEVEL;j++) {
			k += hp_coefficient[i]*j + 50;
			k -= k%100;
			hp_sigma_val[i][j-1] = k;
		}
	}
	return 0;
}

int status_readdb(void) {
	int i,j;
	FILE *fp;
	char line[1024], path[1024],*p;

	sprintf(path, "%s/job_db1.txt", db_path);
	fp=fopen(path,"r"); // Job-specific values (weight, HP, SP, ASPD)
	if(fp==NULL){
		ShowError("can't read %s\n", path);
		return 1;
	}
	while(fgets(line, sizeof(line)-1, fp)){
		char *split[23];
		if(line[0]=='/' && line[1]=='/')
			continue;
		for(j=0,p=line;j<22 && p;j++){
			split[j]=p;
			p=strchr(p,',');
			if(p) *p++=0;
		}
		if(j<22)
			continue;
       	if(atoi(split[0])>=MAX_PC_CLASS)
		    continue;
		max_weight_base[atoi(split[0])]=atoi(split[1]);
		hp_coefficient[atoi(split[0])]=atoi(split[2]);
		hp_coefficient2[atoi(split[0])]=atoi(split[3]);
		sp_coefficient[atoi(split[0])]=atoi(split[4]);
		for(j=0;j<17;j++)
			aspd_base[atoi(split[0])][j]=atoi(split[j+5]);
	}
	fclose(fp);
	ShowStatus("Done reading '"CL_WHITE"%s"CL_RESET"'.\n","job_db1.txt");

	memset(job_bonus,0,sizeof(job_bonus)); // Job-specific stats bonus
	sprintf(path, "%s/job_db2.txt", db_path);
	fp=fopen(path,"r");
	if(fp==NULL){
		ShowError("can't read %s\n", path);
		return 1;
	}
	while(fgets(line, sizeof(line)-1, fp)){
       	char *split[MAX_LEVEL+1]; //Job Level is limited to MAX_LEVEL, so the bonuses should likewise be limited to it. [Skotlex]
		if(line[0]=='/' && line[1]=='/')
			continue;
		for(j=0,p=line;j<MAX_LEVEL+1 && p;j++){
			split[j]=p;
			p=strchr(p,',');
			if(p) *p++=0;
		}
		if(atoi(split[0])>=MAX_PC_CLASS)
		    continue;
		for(i=1;i<j && split[i];i++)
			job_bonus[atoi(split[0])][i-1]=atoi(split[i]);
	}
	fclose(fp);
	ShowStatus("Done reading '"CL_WHITE"%s"CL_RESET"'.\n",path);

	// �T�C�Y�␳�e?�u��
	for(i=0;i<3;i++)
		for(j=0;j<20;j++)
			atkmods[i][j]=100;
	sprintf(path, "%s/size_fix.txt", db_path);
	fp=fopen(path,"r");
	if(fp==NULL){
		ShowError("can't read %s\n", path);
		return 1;
	}
	i=0;
	while(fgets(line, sizeof(line)-1, fp)){
		char *split[20];
		if(line[0]=='/' && line[1]=='/')
			continue;
		if(atoi(line)<=0)
			continue;
		memset(split,0,sizeof(split));
		for(j=0,p=line;j<20 && p;j++){
			split[j]=p;
			p=strchr(p,',');
			if(p) *p++=0;
		}
		for(j=0;j<20 && split[j];j++)
			atkmods[i][j]=atoi(split[j]);
		i++;
	}
	fclose(fp);
	ShowStatus("Done reading '"CL_WHITE"%s"CL_RESET"'.\n",path);

	// ��?�f?�^�e?�u��
	for(i=0;i<5;i++){
		for(j=0;j<MAX_REFINE; j++)
			percentrefinery[i][j]=100;
		percentrefinery[i][j]=0; //Slot MAX+1 always has 0% success chance [Skotlex]
		refinebonus[i][0]=0;
		refinebonus[i][1]=0;
		refinebonus[i][2]=10;
	}

	sprintf(path, "%s/refine_db.txt", db_path);
	fp=fopen(path,"r");
	if(fp==NULL){
		ShowError("can't read %s\n", path);
		return 1;
	}
	i=0;
	while(fgets(line, sizeof(line)-1, fp)){
		char *split[16];
		if(line[0]=='/' && line[1]=='/')
			continue;
		if(atoi(line)<=0)
			continue;
		memset(split,0,sizeof(split));
		for(j=0,p=line;j<16 && p;j++){
			split[j]=p;
			p=strchr(p,',');
			if(p) *p++=0;
		}
		refinebonus[i][0]=atoi(split[0]);	// ��?�{?�i�X
		refinebonus[i][1]=atoi(split[1]);	// ��?��?�{?�i�X
		refinebonus[i][2]=atoi(split[2]);	// ���S��?���E
		for(j=0;j<MAX_REFINE && split[j];j++)
			percentrefinery[i][j]=atoi(split[j+3]);
		i++;
	}
	fclose(fp); //Lupus. close this file!!!
	ShowStatus("Done reading '"CL_WHITE"%s"CL_RESET"'.\n",path);

	return 0;
}

/*==========================================
 * �X�L���֌W����������
 *------------------------------------------
 */
int do_init_status(void)
{
	if (SC_MAX > MAX_STATUSCHANGE)
	{
		ShowDebug("status.h defines %d status changes, but the MAX_STATUSCHANGE is %d! Fix it.\n", SC_MAX, MAX_STATUSCHANGE);
		exit(1);
	}
	add_timer_func_list(status_change_timer,"status_change_timer");
	initStatusIconChangeTable();
	status_readdb();
	status_calc_sigma();
	return 0;
}