| 2896 | |
| 2897 | |
| 2898 | int nextModuleToBuild(STRUCTURE const *psStruct, int lastOrderedModule) |
| 2899 | { |
| 2900 | int order = 0; |
| 2901 | UDWORD i = 0; |
| 2902 | |
| 2903 | ASSERT_OR_RETURN(0, psStruct != nullptr && psStruct->pStructureType != nullptr, "Invalid structure pointer"); |
| 2904 | |
| 2905 | int next = psStruct->status == SS_BUILT ? 1 : 0; // If complete, next is one after the current number of modules, otherwise next is the one we're working on. |
| 2906 | int max; |
| 2907 | switch (psStruct->pStructureType->type) |
| 2908 | { |
| 2909 | case REF_POWER_GEN: |
| 2910 | //check room for one more! |
| 2911 | max = std::max<int>(psStruct->capacity + next, lastOrderedModule + 1); |
| 2912 | if (max <= 1) |
| 2913 | { |
| 2914 | i = powerModuleStat; |
| 2915 | order = max; |
| 2916 | } |
| 2917 | break; |
| 2918 | case REF_FACTORY: |
| 2919 | case REF_VTOL_FACTORY: |
| 2920 | //check room for one more! |
| 2921 | max = std::max<int>(psStruct->capacity + next, lastOrderedModule + 1); |
| 2922 | if (max <= NUM_FACTORY_MODULES) |
| 2923 | { |
| 2924 | i = factoryModuleStat; |
| 2925 | order = max; |
| 2926 | } |
| 2927 | break; |
| 2928 | case REF_RESEARCH: |
| 2929 | //check room for one more! |
| 2930 | max = std::max<int>(psStruct->capacity + next, lastOrderedModule + 1); |
| 2931 | if (max <= 1) |
| 2932 | { |
| 2933 | i = researchModuleStat; |
| 2934 | order = max; // Research modules are weird. Build one, get three free. |
| 2935 | } |
| 2936 | break; |
| 2937 | default: |
| 2938 | //no other structures can have modules attached |
| 2939 | break; |
| 2940 | } |
| 2941 | |
| 2942 | if (order) |
| 2943 | { |
| 2944 | // Check availability of Module |
| 2945 | if (!((i < numStructureStats) && |
| 2946 | (apStructTypeLists[psStruct->player][i] == AVAILABLE))) |
| 2947 | { |
| 2948 | order = 0; |
| 2949 | } |
| 2950 | } |
| 2951 | |
| 2952 | return order; |
| 2953 | } |
| 2954 | |
| 2955 | /*Deals with building a module - checking if any droid is currently doing this |
no test coverage detected