src/industry_gui.cpp
branchnoai
changeset 9718 f82a4facea8b
parent 9704 197cb8c6ae17
child 9722 ebf0ece7d8f6
equal deleted inserted replaced
9717:2c27f9be3fb9 9718:f82a4facea8b
   110 				_fund_gui.index[_fund_gui.count] = INVALID_INDUSTRYTYPE;
   110 				_fund_gui.index[_fund_gui.count] = INVALID_INDUSTRYTYPE;
   111 				_fund_gui.count++;
   111 				_fund_gui.count++;
   112 				WP(w, fnd_d).timer_enabled = false;
   112 				WP(w, fnd_d).timer_enabled = false;
   113 			}
   113 			}
   114 
   114 
   115 			/* We'll perform two distinct loops, one for secondary industries, and the other one for
   115 			/* Fill the _fund_gui structure with industries.
   116 			 * primary ones. Each loop will fill the _fund_gui structure. */
   116 			 * The tests performed after the enabled allow to load the industries
       
   117 			 * In the same way they are inserted by grf (if any)
       
   118 			 */
   117 			for (ind = 0; ind < NUM_INDUSTRYTYPES; ind++) {
   119 			for (ind = 0; ind < NUM_INDUSTRYTYPES; ind++) {
   118 				indsp = GetIndustrySpec(ind);
   120 				indsp = GetIndustrySpec(ind);
   119 				if (indsp->enabled && (!indsp->IsRawIndustry() || _game_mode == GM_EDITOR)) {
   121 				if (indsp->enabled){
       
   122 					/* Rule is that editor mode loads all industries.
       
   123 					 * In game mode, all non raw industries are loaded too
       
   124 					 * and raw ones are loaded only when setting allows it */
       
   125 					if (_game_mode != GM_EDITOR && indsp->IsRawIndustry() && _patches.raw_industry_construction == 0) continue;
   120 					_fund_gui.index[_fund_gui.count] = ind;
   126 					_fund_gui.index[_fund_gui.count] = ind;
   121 					_fund_gui.enabled[_fund_gui.count] = (_game_mode == GM_EDITOR) || CheckIfCallBackAllowsAvailability(ind, IACT_USERCREATION);
   127 					_fund_gui.enabled[_fund_gui.count] = (_game_mode == GM_EDITOR) || CheckIfCallBackAllowsAvailability(ind, IACT_USERCREATION);
   122 					_fund_gui.count++;
   128 					_fund_gui.count++;
   123 				}
       
   124 			}
       
   125 
       
   126 			if (_patches.raw_industry_construction != 0 && _game_mode != GM_EDITOR) {
       
   127 				for (ind = 0; ind < NUM_INDUSTRYTYPES; ind++) {
       
   128 					indsp = GetIndustrySpec(ind);
       
   129 					if (indsp->enabled && indsp->IsRawIndustry()) {
       
   130 						_fund_gui.index[_fund_gui.count] = ind;
       
   131 						_fund_gui.enabled[_fund_gui.count] = (_game_mode == GM_EDITOR) || CheckIfCallBackAllowsAvailability(ind, IACT_USERCREATION);
       
   132 						_fund_gui.count++;
       
   133 					}
       
   134 				}
   129 				}
   135 			}
   130 			}
   136 
   131 
   137 			/* first indutry type is selected.
   132 			/* first indutry type is selected.
   138 			 * I'll be damned if there are none available ;) */
   133 			 * I'll be damned if there are none available ;) */
   176 					continue;
   171 					continue;
   177 				}
   172 				}
   178 				const IndustrySpec *indsp = GetIndustrySpec(_fund_gui.index[i + w->vscroll.pos]);
   173 				const IndustrySpec *indsp = GetIndustrySpec(_fund_gui.index[i + w->vscroll.pos]);
   179 
   174 
   180 				/* Draw the name of the industry in white is selected, otherwise, in orange */
   175 				/* Draw the name of the industry in white is selected, otherwise, in orange */
   181 				DrawString(20,     y + offset, indsp->name, selected ? 12 : 6);
   176 				DrawStringTruncated(20, y + offset, indsp->name, selected ? 12 : 6, max_width - 25);
   182 				GfxFillRect(x,     y + 1 + offset,  x + 10, y + 7 + offset, selected ? 15 : 0);
   177 				GfxFillRect(x,     y + 1 + offset,  x + 10, y + 7 + offset, selected ? 15 : 0);
   183 				GfxFillRect(x + 1, y + 2 + offset,  x +  9, y + 6 + offset, indsp->map_colour);
   178 				GfxFillRect(x + 1, y + 2 + offset,  x +  9, y + 6 + offset, indsp->map_colour);
   184 			}
   179 			}
   185 
   180 
   186 			if (WP(w, fnd_d).select == INVALID_INDUSTRYTYPE) {
   181 			if (WP(w, fnd_d).select == INVALID_INDUSTRYTYPE) {
   294 			w->vscroll.cap  += e->we.sizing.diff.y / (int)w->resize.step_height;
   289 			w->vscroll.cap  += e->we.sizing.diff.y / (int)w->resize.step_height;
   295 			w->widget[DYNA_INDU_MATRIX_WIDGET].data = (w->vscroll.cap << 8) + 1;
   290 			w->widget[DYNA_INDU_MATRIX_WIDGET].data = (w->vscroll.cap << 8) + 1;
   296 		} break;
   291 		} break;
   297 
   292 
   298 		case WE_PLACE_OBJ: {
   293 		case WE_PLACE_OBJ: {
       
   294 			bool success = true;
   299 			/* We do not need to protect ourselves against "Random Many Industries" in this mode */
   295 			/* We do not need to protect ourselves against "Random Many Industries" in this mode */
   300 			const IndustrySpec *indsp = GetIndustrySpec(WP(w, fnd_d).select);
   296 			const IndustrySpec *indsp = GetIndustrySpec(WP(w, fnd_d).select);
   301 
   297 
   302 			if (_game_mode == GM_EDITOR) {
   298 			if (_game_mode == GM_EDITOR) {
   303 				/* Show error if no town exists at all */
   299 				/* Show error if no town exists at all */
   308 				}
   304 				}
   309 
   305 
   310 				_current_player = OWNER_NONE;
   306 				_current_player = OWNER_NONE;
   311 				_generating_world = true;
   307 				_generating_world = true;
   312 				_ignore_restrictions = true;
   308 				_ignore_restrictions = true;
   313 				if (!TryBuildIndustry(e->we.place.tile, WP(w, fnd_d).select)) {
   309 				success = TryBuildIndustry(e->we.place.tile, WP(w, fnd_d).select);
       
   310 				if (!success) {
   314 					SetDParam(0, indsp->name);
   311 					SetDParam(0, indsp->name);
   315 					ShowErrorMessage(_error_message, STR_0285_CAN_T_BUILD_HERE, e->we.place.pt.x, e->we.place.pt.y);
   312 					ShowErrorMessage(_error_message, STR_0285_CAN_T_BUILD_HERE, e->we.place.pt.x, e->we.place.pt.y);
   316 				}
   313 				}
   317 
   314 
   318 				_ignore_restrictions = false;
   315 				_ignore_restrictions = false;
   319 				_generating_world = false;
   316 				_generating_world = false;
   320 			} else DoCommandP(e->we.place.tile, WP(w, fnd_d).select, 0, NULL, CMD_BUILD_INDUSTRY | CMD_MSG(STR_4830_CAN_T_CONSTRUCT_THIS_INDUSTRY));
   317 			} else {
   321 
   318 				success = DoCommandP(e->we.place.tile, WP(w, fnd_d).select, 0, NULL, CMD_BUILD_INDUSTRY | CMD_MSG(STR_4830_CAN_T_CONSTRUCT_THIS_INDUSTRY));
   322 			/* Whatever the outcome of the actions, just reset the cursor and the system */
   319 			}
   323 			ResetObjectToPlace();
   320 
       
   321 			/* If an industry has been built, just reset the cursor and the system */
       
   322 			if (success) ResetObjectToPlace();
   324 		} break;
   323 		} break;
   325 
   324 
   326 		case WE_TICK:
   325 		case WE_TICK:
   327 			if (!WP(w, fnd_d).timer_enabled) break;
   326 			if (!WP(w, fnd_d).timer_enabled) break;
   328 			if (--WP(w, fnd_d).callback_timer == 0) {
   327 			if (--WP(w, fnd_d).callback_timer == 0) {
   502 			if (callback_res != CALLBACK_FAILED) {
   501 			if (callback_res != CALLBACK_FAILED) {
   503 				StringID message = GetGRFStringID(ind->grf_prop.grffile->grfid, 0xD000 + callback_res);
   502 				StringID message = GetGRFStringID(ind->grf_prop.grffile->grfid, 0xD000 + callback_res);
   504 				if (message != STR_NULL && message != STR_UNDEFINED) {
   503 				if (message != STR_NULL && message != STR_UNDEFINED) {
   505 					y += 10;
   504 					y += 10;
   506 
   505 
   507 					PrepareTextRefStackUsage();
   506 					PrepareTextRefStackUsage(6);
   508 					DrawString(2, y, message, 0);
   507 					DrawString(2, y, message, 0);
   509 					StopTextRefStackUsage();
   508 					StopTextRefStackUsage();
   510 				}
   509 				}
   511 			}
   510 			}
   512 		}
   511 		}