comparison mm7_3.cpp @ 2193:4842f58715ea

sub_47C3D7_get_fog_related_stuff to sub_47C3D7_get_fog_specular cleanup, IsTerrainSlopeTooHigh restoring commented out min,min/max,max implementation, some small changes in OnMapLoad, sub_4465DF_check_season attempted to pick the best readabilty/maintainability tradeoff
author Grumpy7
date Thu, 30 Jan 2014 22:09:10 +0100
parents 7a517c9a1d5b
children 628a0ad87136
comparison
equal deleted inserted replaced
2188:0ae56373cc35 2193:4842f58715ea
2816 2816
2817 return 0; 2817 return 0;
2818 } 2818 }
2819 2819
2820 //----- (0047C3D7) -------------------------------------------------------- 2820 //----- (0047C3D7) --------------------------------------------------------
2821 int __fastcall sub_47C3D7_get_fog_related_stuff(int a1, int a2, float a3) 2821 int __fastcall sub_47C3D7_get_fog_specular(int a1, int a2, float a3)
2822 { 2822 {
2823 int v3; // ecx@1
2824 double v5; // st7@10 2823 double v5; // st7@10
2825 signed int v7; // ecx@11 2824 signed int v7; // ecx@11
2826 double v8; // st6@12 2825 double v8; // st6@12
2827 double v9; // st7@15 2826 double v9; // st7@15
2828 double v10; // st6@16 2827 double v10; // st6@16
2829 float v11; // ST14_4@17 2828 float v11; // ST14_4@17
2830 double v12; // ST08_8@17 2829 double v12; // ST08_8@17
2831 2830
2832 v3 = pWeather->bNight;
2833 if ( bUnderwater == 1 )
2834 v3 = 0;
2835 if ( pParty->armageddon_timer || !(day_attrib & DAY_ATTRIB_FOG) && !bUnderwater ) 2831 if ( pParty->armageddon_timer || !(day_attrib & DAY_ATTRIB_FOG) && !bUnderwater )
2836 return 0xFF000000; 2832 return 0xFF000000;
2837 if ( v3 ) 2833 if ( a3 == 0.0 )
2834 return (-1 - 216) << 24;
2835 if ( a2 )
2836 return (-1 - 248) << 24;
2837 if (a3 < (double)day_fogrange_1)
2838 return -1 << 24;
2839 if (a3 < (double)day_fogrange_2)
2840 return (-1 - 216) << 24;
2841
2842 if ( pWeather->bNight && !bUnderwater)
2838 { 2843 {
2839 v5 = (double)day_fogrange_1; 2844 v5 = (double)day_fogrange_1;
2840 if ( a3 < v5 ) 2845 v8 = (double)day_fogrange_2;
2841 { 2846 v7 = (signed __int64)((a3 - v5) / (v8 - v5) * 216.0);
2842 v7 = 0;
2843 if ( a3 == 0.0 )
2844 {
2845 v7 = 216;
2846 }
2847 goto LABEL_21;
2848 }
2849 else
2850 {
2851 v8 = (double)day_fogrange_2;
2852 if ( a3 > v8 )
2853 {
2854 v7 = 216;
2855 if ( a3 == 0.0 )
2856 {
2857 v7 = 216;
2858 }
2859 goto LABEL_21;
2860 }
2861 v7 = (signed __int64)((a3 - v5) / (v8 - v5) * 216.0);
2862 }
2863 } 2847 }
2864 else 2848 else
2865 { 2849 {
2866 v9 = (double)day_fogrange_1; 2850 v9 = (double)day_fogrange_1;
2867 if ( a3 < v9 ) 2851 v10 = (double)day_fogrange_2;
2868 { 2852 v11 = (a3 - v9) * 216.0 / (v10 - v9);
2869 v7 = 0; 2853 v7 = bankersRounding(v11);
2870 if ( a3 == 0.0 )
2871 {
2872 v7 = 216;
2873 }
2874 goto LABEL_21;
2875 }
2876 else
2877 {
2878 v10 = (double)day_fogrange_2;
2879 if ( a3 > v10 )
2880 {
2881 v7 = 216;
2882 if ( a3 == 0.0 )
2883 {
2884 v7 = 216;
2885 }
2886 goto LABEL_21;
2887 }
2888 else
2889 {
2890 v11 = (a3 - v9) * 216.0 / (v10 - v9);
2891 v12 = v11 + 6.7553994e15;
2892 v7 = LODWORD(v12);
2893 }
2894 }
2895 } 2854 }
2896 if ( v7 > 216 ) 2855 if ( v7 > 216 )
2897 { 2856 {
2898 v7 = 216; 2857 v7 = 216;
2899 } 2858 }
2900 else 2859 return ( -1 - v7) << 24;
2901 {
2902 if ( a3 == 0.0 )
2903 {
2904 v7 = 216;
2905 }
2906 }
2907 LABEL_21:
2908 if ( a2 )
2909 v7 = 248;
2910 return (-1 - v7) << 24;
2911 } 2860 }
2912 2861
2913 //----- (0047C4FC) -------------------------------------------------------- 2862 //----- (0047C4FC) --------------------------------------------------------
2914 int __fastcall GetActorTintColor(int max_dimm, int min_dimm, float distance, int a4, RenderBillboard *a5) 2863 int __fastcall GetActorTintColor(int max_dimm, int min_dimm, float distance, int a4, RenderBillboard *a5)
2915 { 2864 {
3104 //int v4; // eax@1 3053 //int v4; // eax@1
3105 //int v6; // esi@5 3054 //int v6; // esi@5
3106 //int v7; // ecx@6 3055 //int v7; // ecx@6
3107 //int v8; // edx@6 3056 //int v8; // edx@6
3108 //int v9; // eax@6 3057 //int v9; // eax@6
3109 int y_min; // esi@10 3058 //int y_min; // esi@10
3110 //int v11; // [sp+14h] [bp-8h]@1 3059 //int v11; // [sp+14h] [bp-8h]@1
3111 //int v12; // [sp+18h] [bp-4h]@1 3060 //int v12; // [sp+18h] [bp-4h]@1
3112 3061
3113 //v12 = a1; 3062 //v12 = a1;
3114 //v11 = a2; 3063 //v11 = a2;
3154 /* \ | 3103 /* \ |
3155 \ | 3104 \ |
3156 y3 */ 3105 y3 */
3157 } 3106 }
3158 3107
3159 //int y_min = min(y1, min(y2, y3)),// не верно при подъёме на склон 3108 int y_min = min(y1, min(y2, y3));// не верно при подъёме на склон
3160 //y_max = max(y1, max(y2, y3)); 3109 int y_max = max(y1, max(y2, y3));
3161 //return (y_max - y_min) > 512; 3110 return (y_max - y_min) > 512;
3162
3163 if ( y1 >= y2 )
3164 {
3165 y_min = y2;
3166 if ( y2 < y3 )
3167 {
3168 if ( y1 <= y2 )
3169 {
3170 if ( y2 > y3 )
3171 y3 = y2;
3172 }
3173 else
3174 {
3175 if ( y1 > y3 )
3176 y3 = y1;
3177 }
3178 return y3 - y_min > 512;
3179 }
3180 y_min = y3;
3181 if ( y1 <= y2 )
3182 {
3183 if ( y2 > y3 )
3184 y3 = y2;
3185 }
3186 else
3187 {
3188 if ( y1 > y3 )
3189 y3 = y1;
3190 }
3191 return y3 - y_min > 512;
3192 }
3193 else if ( y1 >= y3 )
3194 y_min = y3;
3195 else
3196 y_min = y1;
3197
3198 if ( y1 <= y2 )
3199 {
3200 if ( y2 > y3 )
3201 y3 = y2;
3202 }
3203 else
3204 {
3205 if ( y1 > y3 )
3206 y3 = y1;
3207 }
3208 return y3 - y_min > 512;
3209 } 3111 }
3210 3112
3211 //----- (0048257A) -------------------------------------------------------- 3113 //----- (0048257A) --------------------------------------------------------
3212 int __fastcall GetTerrainHeightsAroundParty2(int a1, int a2, int *pIsOnWater, int bFloatAboveWater) 3114 int __fastcall GetTerrainHeightsAroundParty2(int a1, int a2, int *pIsOnWater, int bFloatAboveWater)
3213 { 3115 {
3786 3688
3787 //----- (00443FDC) -------------------------------------------------------- 3689 //----- (00443FDC) --------------------------------------------------------
3788 void OnMapLoad() 3690 void OnMapLoad()
3789 { 3691 {
3790 __int16 v4; // cx@9 3692 __int16 v4; // cx@9
3791 __int16 v5; // di@9
3792 int v6; // eax@9 3693 int v6; // eax@9
3793 signed __int64 v8; // qax@26 3694 unsigned __int64 v8; // qax@26
3794 unsigned int v9; // ecx@26 3695 unsigned int v9; // ecx@26
3795 signed __int64 v10; // qax@26 3696 unsigned __int64 v10; // qax@26
3796 signed __int64 v11; // qax@26 3697 unsigned __int64 v11; // qax@26
3797 int v12; // ST50_4@26 3698 unsigned __int64 v13; // qax@26
3798 signed __int64 v13; // qax@26 3699 unsigned __int64 v14; // qax@26
3799 signed __int64 v14; // qax@26
3800 int v15; // ST58_4@26 3700 int v15; // ST58_4@26
3801 signed __int64 v16; // qax@26 3701 unsigned __int64 v16; // qax@26
3802 int hours; // ebx@26 3702 int hours; // ebx@26
3803 unsigned __int64 v18; // [sp+Ch] [bp-44h]@12 3703 unsigned __int64 v18; // [sp+Ch] [bp-44h]@12
3804 signed __int64 seconds; // [sp+14h] [bp-3Ch]@26 3704 unsigned int seconds; // [sp+14h] [bp-3Ch]@26
3805 unsigned __int64 v20; // [sp+1Ch] [bp-34h]@7 3705 unsigned __int64 v20; // [sp+1Ch] [bp-34h]@7
3806 int minutes; // [sp+2Ch] [bp-24h]@26 3706 unsigned int minutes; // [sp+2Ch] [bp-24h]@26
3807 int years; // [sp+34h] [bp-1Ch]@26 3707 unsigned int years; // [sp+34h] [bp-1Ch]@26
3808 int weeks; // [sp+38h] [bp-18h]@26 3708 unsigned int weeks; // [sp+38h] [bp-18h]@26
3809 int v26; // [sp+3Ch] [bp-14h]@15 3709 int v26; // [sp+3Ch] [bp-14h]@15
3810 int days; // [sp+3Ch] [bp-14h]@26 3710 unsigned int days; // [sp+3Ch] [bp-14h]@26
3811 int months; // [sp+40h] [bp-10h]@26 3711 unsigned int months; // [sp+40h] [bp-10h]@26
3812 __int16 v29; // [sp+46h] [bp-Ah]@9 3712 __int16 v29; // [sp+46h] [bp-Ah]@9
3813 __int16 v30; // [sp+48h] [bp-8h]@9 3713 __int16 v30; // [sp+48h] [bp-8h]@9
3814 __int16 v31; // [sp+4Ah] [bp-6h]@9
3815 __int16 v32; // [sp+4Ch] [bp-4h]@9 3714 __int16 v32; // [sp+4Ch] [bp-4h]@9
3816 __int16 v33; // [sp+4Eh] [bp-2h]@9 3715 __int16 v33; // [sp+4Eh] [bp-2h]@9
3817 3716
3818 for (uint i = 0; i < uLevelEVT_NumEvents; ++i) 3717 for (uint i = 0; i < uLevelEVT_NumEvents; ++i)
3819 { 3718 {
3851 if (array_5B5928_timers[dword_5B65C8_timers_count].timer_evt_type == EVENT_Initialize && !(short)v6 ) 3750 if (array_5B5928_timers[dword_5B65C8_timers_count].timer_evt_type == EVENT_Initialize && !(short)v6 )
3852 { 3751 {
3853 if ( v20 ) 3752 if ( v20 )
3854 v18 = pParty->uTimePlayed - v20; 3753 v18 = pParty->uTimePlayed - v20;
3855 else 3754 else
3856 v18 = 0i64; 3755 v18 = 0;
3857 v26 = (signed int)(signed __int64)((double)(signed __int64)v18 * 0.234375) / 60 / 60 / 24; 3756 v26 = (signed int)(signed __int64)((double)(signed __int64)v18 * 0.234375) / 60 / 60 / 24;
3858 3757
3859 if ( v26 / 7 / 4 / 12 ) 3758 if ( v26 / 7 / 4 / 12 != 0 && array_5B5928_timers[dword_5B65C8_timers_count].field_10 ||
3860 { 3759 v26 / 7 / 4 != 0 && array_5B5928_timers[dword_5B65C8_timers_count].field_12 != 0 ||
3861 if ( array_5B5928_timers[dword_5B65C8_timers_count].field_10 )
3862 {
3863 ++dword_5B65C8_timers_count;
3864 array_5B5928_timers[dword_5B65C8_timers_count].next_fire_time = 0;
3865 continue;
3866 }
3867 }
3868 if (v26 / 7 / 4 != 0 && array_5B5928_timers[dword_5B65C8_timers_count].field_12 != 0 ||
3869 v26 / 7 != 0 && array_5B5928_timers[dword_5B65C8_timers_count].field_14 != 0 || 3760 v26 / 7 != 0 && array_5B5928_timers[dword_5B65C8_timers_count].field_14 != 0 ||
3870 v26 != 0 || !v20) 3761 v26 != 0 || !v20)
3871 { 3762 {
3872 ++dword_5B65C8_timers_count; 3763 ++dword_5B65C8_timers_count;
3873 array_5B5928_timers[dword_5B65C8_timers_count].next_fire_time = 0; 3764 array_5B5928_timers[dword_5B65C8_timers_count].next_fire_time = 0;
3874 continue; 3765 continue;
3875 } 3766 }
3876 } 3767 }
3877 else 3768 else
3878 { 3769 {
3879 v8 = (signed __int64)((double)(signed __int64)pParty->uTimePlayed * 0.234375); 3770 v8 = (__int64)((double)pParty->uTimePlayed * 0.234375);
3880 v9 = v8; 3771 seconds = v8 % 60;
3881 v10 = (signed int)v8 / 60; 3772 v10 = v8 / 60;
3882 minutes = v10 % 60; 3773 minutes = v10 % 60;
3883 v11 = (signed int)(v10 / 60); 3774 v11 = v10 / 60;
3884 v12 = v11 % 24; 3775 hours = v11 % 24;
3885 v13 = (signed int)(v11 / 24); 3776 v13 = v11 / 24;
3886 days = v13 % 7; 3777 days = v13 % 7;
3887 v14 = (signed int)(v13 / 7); 3778 v14 = v13 / 7;
3888 v15 = v14 % 4; 3779 weeks = v14 % 4;
3889 v16 = (signed int)(v14 / 4); 3780 v16 = v14 / 4;
3781 months = v16 % 12;
3890 years = v16 / 12; 3782 years = v16 / 12;
3891 3783
3892 unsigned __int64 _1 = (unsigned __int64)((double)pParty->uTimePlayed * 0.234375) >> 32;
3893 __int64 _2 = ((__int64)v9 << 32) | _1;
3894
3895 seconds = _2 % 60;
3896 //v19 = (signed __int64)__PAIR__((unsigned __int64)(signed __int64)((double)(signed __int64)pParty->uTimePlayed * 0.234375) >> 32,
3897 // v9)
3898 // % 60;
3899
3900 hours = v12;
3901 weeks = v15;
3902 months = v16 % 12;
3903 if ( array_5B5928_timers[dword_5B65C8_timers_count].field_10 ) 3784 if ( array_5B5928_timers[dword_5B65C8_timers_count].field_10 )
3904 ++years; 3785 ++years;
3786 else if ( array_5B5928_timers[dword_5B65C8_timers_count].field_12 )
3787 ++months;
3788 else if ( array_5B5928_timers[dword_5B65C8_timers_count].field_14 )
3789 ++weeks;
3905 else 3790 else
3906 { 3791 {
3907 if ( array_5B5928_timers[dword_5B65C8_timers_count].field_12 ) 3792 ++days;
3908 ++months; 3793 minutes = array_5B5928_timers[dword_5B65C8_timers_count].field_18;
3909 else 3794 hours = array_5B5928_timers[dword_5B65C8_timers_count].field_16;
3910 { 3795 seconds = array_5B5928_timers[dword_5B65C8_timers_count].field_1A;
3911 if ( array_5B5928_timers[dword_5B65C8_timers_count].field_14 )
3912 ++weeks;
3913 else
3914 {
3915 ++days;
3916 minutes = array_5B5928_timers[dword_5B65C8_timers_count].field_18;
3917 hours = array_5B5928_timers[dword_5B65C8_timers_count].field_16;
3918 seconds = array_5B5928_timers[dword_5B65C8_timers_count].field_1A;
3919 }
3920 }
3921 } 3796 }
3922 array_5B5928_timers[dword_5B65C8_timers_count].next_fire_time = (signed __int64)((double)((seconds 3797 array_5B5928_timers[dword_5B65C8_timers_count].next_fire_time = (signed __int64)((double)((seconds
3923 + 60 * minutes 3798 + 60 * minutes
3924 + 3600 * hours 3799 + 3600 * hours
3925 + 0x93A80 * weeks 3800 + 86400 * days
3926 + 0x15180 * days 3801 + 604800 * weeks
3927 + 0x24EA00 * (months + 12i64 * years)) << 7) 3802 + 2419200 * months
3803 + 29030400 * years) << 7)
3928 * 0.033333335); 3804 * 0.033333335);
3929 3805
3930 ++dword_5B65C8_timers_count; 3806 ++dword_5B65C8_timers_count;
3931 } 3807 }
3932 } 3808 }
4000 } 3876 }
4001 3877
4002 //----- (004465DF) -------------------------------------------------------- 3878 //----- (004465DF) --------------------------------------------------------
4003 bool sub_4465DF_check_season(int a1) 3879 bool sub_4465DF_check_season(int a1)
4004 { 3880 {
4005 unsigned int v1; // eax@1 3881 unsigned int monthPlusOne; // eax@1
4006 unsigned int v2; // edx@1 3882 unsigned int daysPlusOne; // edx@1
4007 int v3; // ecx@2 3883
4008 int v4; // ecx@3 3884 monthPlusOne = pParty->uCurrentMonth + 1;
4009 char v6; // zf@9 3885 daysPlusOne = pParty->uDaysPlayed + 1;
4010
4011 v1 = pParty->uCurrentMonth + 1;
4012 v2 = pParty->uDaysPlayed + 1;
4013 if ((v1 == (a1 + 1) * 3 && v2 >= 21) || v1 == (a1 + 1) % 4 * 3 + 1 || v1 == (a1 + 1) % 4 * 3 + 2 || (v1 == (a1 + 2) % 4 * 3 && v2 < 21))
4014 return true;
4015 return false;
4016 3886
4017 switch (a1) 3887 switch (a1)
4018 { 3888 {
4019 case 3: 3889 case 3: //winter 12.21 -> 3.20
4020 if (v1 != 12)//12.21 -> 3.20 3890 return (monthPlusOne == 12 && daysPlusOne >= 21 || monthPlusOne == 1 || monthPlusOne == 2 || monthPlusOne == 3 && daysPlusOne <= 20);
4021 {
4022 if ((signed int)v1 >= 1 && (signed int)v1 <= 2)
4023 return true;
4024 v6 = v1 == 3;
4025 if (!v6 || (signed int)v2 >= 21)
4026 return false;
4027 return true;
4028 }
4029 break; 3891 break;
4030 case 2: 3892 case 2:// autumn/fall 9.21 -> 12.20
4031 if (v1 != 9)//9.21 -> 12.20 3893 return (monthPlusOne == 9 && daysPlusOne >= 21 || monthPlusOne == 10 || monthPlusOne == 11 || monthPlusOne == 12 && daysPlusOne <= 20);
4032 {
4033 if ((signed int)v1 >= 10 && (signed int)v1 <= 11)
4034 return true;
4035 v6 = v1 == 12;
4036 if (!v6 || (signed int)v2 >= 21)
4037 return false;
4038 return true;
4039 }
4040 break; 3894 break;
4041 case 1: 3895 case 1://summer 6.21 -> 9.20
4042 if (v1 != 6)//6.21 -> 9.20 3896 return (monthPlusOne == 6 && daysPlusOne >= 21 || monthPlusOne == 7 || monthPlusOne == 8 || monthPlusOne == 9 && daysPlusOne <= 20);
4043 {
4044 if ((signed int)v1 >= 7 && (signed int)v1 <= 8)
4045 return true;
4046 v6 = v1 == 9;
4047 if (!v6 || (signed int)v2 >= 21)
4048 return false;
4049 return true;
4050 }
4051 break; 3897 break;
4052 case 0: 3898 case 0: //spring 3.21 -> 6.20
4053 if (v1 != 3)//3.21 -> 9.20 3899 return (monthPlusOne == 3 && daysPlusOne >= 21 || monthPlusOne == 4 || monthPlusOne == 5 || monthPlusOne == 6 && daysPlusOne <= 20);
4054 {
4055 if ((signed int)v1 >= 4 && (signed int)v1 <= 5)
4056 return true;
4057 v6 = v1 == 6;
4058 if (!v6 || (signed int)v2 >= 21)
4059 return false;
4060 return true;
4061 }
4062 break; 3900 break;
4063 default: 3901 }
4064 return false; 3902 Error("Unknown season");
4065 }
4066 if ( (signed int)v2 >= 21 )
4067 return true;
4068 return false; 3903 return false;
4069 } 3904 }
4070 3905
4071 //----- (0044861E) -------------------------------------------------------- 3906 //----- (0044861E) --------------------------------------------------------
4072 void __fastcall sub_44861E_set_texture(unsigned int uFaceCog, const char *pFilename) 3907 void __fastcall sub_44861E_set_texture(unsigned int uFaceCog, const char *pFilename)