388 return i->production_rate[pt] == 255; |
388 return i->production_rate[pt] == 255; |
389 } |
389 } |
390 |
390 |
391 static inline bool IsProductionAlterable(const Industry *i) |
391 static inline bool IsProductionAlterable(const Industry *i) |
392 { |
392 { |
393 const IndustrySpec *ind = GetIndustrySpec(i->type); |
|
394 return ((_game_mode == GM_EDITOR || _cheats.setup_prod.value) && |
393 return ((_game_mode == GM_EDITOR || _cheats.setup_prod.value) && |
395 (ind->accepts_cargo[0] == CT_INVALID || ind->accepts_cargo[0] == CT_VALUABLES)); |
394 (i->accepts_cargo[0] == CT_INVALID || i->accepts_cargo[0] == CT_VALUABLES)); |
396 } |
395 } |
397 |
396 |
398 /** Information to store about the industry window */ |
397 /** Information to store about the industry window */ |
399 struct indview_d : public vp_d { |
398 struct indview_d : public vp_d { |
400 byte editbox_line; ///< The line clicked to open the edit box |
399 byte editbox_line; ///< The line clicked to open the edit box |
408 static void IndustryViewWndProc(Window *w, WindowEvent *e) |
407 static void IndustryViewWndProc(Window *w, WindowEvent *e) |
409 { |
408 { |
410 switch (e->event) { |
409 switch (e->event) { |
411 case WE_CREATE: { |
410 case WE_CREATE: { |
412 /* Count the number of lines that we need to resize the GUI with */ |
411 /* Count the number of lines that we need to resize the GUI with */ |
413 const IndustrySpec *ind = GetIndustrySpec(GetIndustry(w->window_number)->type); |
412 const Industry *i = GetIndustry(w->window_number); |
|
413 const IndustrySpec *ind = GetIndustrySpec(i->type); |
414 int lines = -3; |
414 int lines = -3; |
415 |
415 |
416 if (HASBIT(ind->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HASBIT(ind->callback_flags, CBM_IND_PRODUCTION_256_TICKS)) { |
416 if (HASBIT(ind->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HASBIT(ind->callback_flags, CBM_IND_PRODUCTION_256_TICKS)) { |
417 for (uint j = 0; j < 3 && ind->accepts_cargo[j] != CT_INVALID; j++) { |
417 for (uint j = 0; j < lengthof(i->accepts_cargo) && i->accepts_cargo[j] != CT_INVALID; j++) { |
418 if (j == 0) lines++; |
418 if (j == 0) lines++; |
419 lines++; |
419 lines++; |
420 } |
420 } |
421 } else if (ind->accepts_cargo[0] != CT_INVALID) { |
421 } else if (i->accepts_cargo[0] != CT_INVALID) { |
422 lines++; |
422 lines++; |
423 } |
423 } |
424 |
424 |
425 for (uint j = 0; j < 2 && ind->produced_cargo[j] != CT_INVALID; j++) { |
425 for (uint j = 0; j < lengthof(i->produced_cargo) && i->produced_cargo[j] != CT_INVALID; j++) { |
426 if (j == 0) { |
426 if (j == 0) { |
427 if (ind->accepts_cargo[0] != CT_INVALID) lines++; |
427 if (i->accepts_cargo[0] != CT_INVALID) lines++; |
428 lines++; |
428 lines++; |
429 } |
429 } |
430 lines++; |
430 lines++; |
431 } |
431 } |
432 |
432 |
446 |
446 |
447 SetDParam(0, w->window_number); |
447 SetDParam(0, w->window_number); |
448 DrawWindowWidgets(w); |
448 DrawWindowWidgets(w); |
449 |
449 |
450 if (HASBIT(ind->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HASBIT(ind->callback_flags, CBM_IND_PRODUCTION_256_TICKS)) { |
450 if (HASBIT(ind->callback_flags, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HASBIT(ind->callback_flags, CBM_IND_PRODUCTION_256_TICKS)) { |
451 for (uint j = 0; j < 3 && ind->accepts_cargo[j] != CT_INVALID; j++) { |
451 for (uint j = 0; j < lengthof(i->accepts_cargo) && i->accepts_cargo[j] != CT_INVALID; j++) { |
452 if (j == 0) { |
452 if (j == 0) { |
453 DrawString(2, y, STR_INDUSTRY_WINDOW_WAITING_FOR_PROCESSING, 0); |
453 DrawString(2, y, STR_INDUSTRY_WINDOW_WAITING_FOR_PROCESSING, 0); |
454 y += 10; |
454 y += 10; |
455 } |
455 } |
456 SetDParam(0, ind->accepts_cargo[j]); |
456 SetDParam(0, i->accepts_cargo[j]); |
457 SetDParam(1, i->incoming_cargo_waiting[j]); |
457 SetDParam(1, i->incoming_cargo_waiting[j]); |
458 DrawString(4, y, STR_INDUSTRY_WINDOW_WAITING_STOCKPILE_CARGO, 0); |
458 DrawString(4, y, STR_INDUSTRY_WINDOW_WAITING_STOCKPILE_CARGO, 0); |
459 y += 10; |
459 y += 10; |
460 } |
460 } |
461 } else if (ind->accepts_cargo[0] != CT_INVALID) { |
461 } else if (i->accepts_cargo[0] != CT_INVALID) { |
462 StringID str; |
462 StringID str; |
463 |
463 |
464 SetDParam(0, GetCargo(ind->accepts_cargo[0])->name); |
464 SetDParam(0, GetCargo(i->accepts_cargo[0])->name); |
465 str = STR_4827_REQUIRES; |
465 str = STR_4827_REQUIRES; |
466 if (ind->accepts_cargo[1] != CT_INVALID) { |
466 if (i->accepts_cargo[1] != CT_INVALID) { |
467 SetDParam(1, GetCargo(ind->accepts_cargo[1])->name); |
467 SetDParam(1, GetCargo(i->accepts_cargo[1])->name); |
468 str = STR_4828_REQUIRES; |
468 str = STR_4828_REQUIRES; |
469 if (ind->accepts_cargo[2] != CT_INVALID) { |
469 if (i->accepts_cargo[2] != CT_INVALID) { |
470 SetDParam(2, GetCargo(ind->accepts_cargo[2])->name); |
470 SetDParam(2, GetCargo(i->accepts_cargo[2])->name); |
471 str = STR_4829_REQUIRES; |
471 str = STR_4829_REQUIRES; |
472 } |
472 } |
473 } |
473 } |
474 DrawString(2, y, str, 0); |
474 DrawString(2, y, str, 0); |
475 y += 10; |
475 y += 10; |
476 } |
476 } |
477 |
477 |
478 for (uint j = 0; j < 2 && ind->produced_cargo[j] != CT_INVALID; j++) { |
478 for (uint j = 0; j < lengthof(i->produced_cargo) && i->produced_cargo[j] != CT_INVALID; j++) { |
479 if (j == 0) { |
479 if (j == 0) { |
480 if (ind->accepts_cargo[0] != CT_INVALID) y += 10; |
480 if (i->accepts_cargo[0] != CT_INVALID) y += 10; |
481 DrawString(2, y, STR_482A_PRODUCTION_LAST_MONTH, 0); |
481 DrawString(2, y, STR_482A_PRODUCTION_LAST_MONTH, 0); |
482 y += 10; |
482 y += 10; |
483 WP(w, indview_d).production_offset_y = y; |
483 WP(w, indview_d).production_offset_y = y; |
484 } |
484 } |
485 |
485 |
486 SetDParam(0, ind->produced_cargo[j]); |
486 SetDParam(0, i->produced_cargo[j]); |
487 SetDParam(1, i->last_month_production[j]); |
487 SetDParam(1, i->last_month_production[j]); |
488 |
488 |
489 SetDParam(2, i->last_month_pct_transported[j] * 100 >> 8); |
489 SetDParam(2, i->last_month_pct_transported[j] * 100 >> 8); |
490 DrawString(4 + (IsProductionAlterable(i) ? 30 : 0), y, STR_482B_TRANSPORTED, 0); |
490 DrawString(4 + (IsProductionAlterable(i) ? 30 : 0), y, STR_482B_TRANSPORTED, 0); |
491 /* Let's put out those buttons.. */ |
491 /* Let's put out those buttons.. */ |
525 |
525 |
526 /* We should work if needed.. */ |
526 /* We should work if needed.. */ |
527 if (!IsProductionAlterable(i)) return; |
527 if (!IsProductionAlterable(i)) return; |
528 x = e->we.click.pt.x; |
528 x = e->we.click.pt.x; |
529 line = (e->we.click.pt.y - WP(w, indview_d).production_offset_y) / 10; |
529 line = (e->we.click.pt.y - WP(w, indview_d).production_offset_y) / 10; |
530 if (e->we.click.pt.y >= WP(w, indview_d).production_offset_y && IS_INT_INSIDE(line, 0, 2) && |
530 if (e->we.click.pt.y >= WP(w, indview_d).production_offset_y && IS_INT_INSIDE(line, 0, 2) && i->produced_cargo[line] != CT_INVALID) { |
531 GetIndustrySpec(i->type)->produced_cargo[line] != CT_INVALID) { |
|
532 if (IS_INT_INSIDE(x, 5, 25) ) { |
531 if (IS_INT_INSIDE(x, 5, 25) ) { |
533 /* Clicked buttons, decrease or increase production */ |
532 /* Clicked buttons, decrease or increase production */ |
534 if (x < 15) { |
533 if (x < 15) { |
535 if (isProductionMinimum(i, line)) return; |
534 if (isProductionMinimum(i, line)) return; |
536 i->production_rate[line] = max(i->production_rate[line] / 2, 1); |
535 i->production_rate[line] = max(i->production_rate[line] / 2, 1); |
668 case 1: /* Sort by Type */ |
663 case 1: /* Sort by Type */ |
669 r = i->type - j->type; |
664 r = i->type - j->type; |
670 break; |
665 break; |
671 |
666 |
672 case 2: /* Sort by Production */ |
667 case 2: /* Sort by Production */ |
673 if (ind_i->produced_cargo[0] == CT_INVALID) { |
668 if (i->produced_cargo[0] == CT_INVALID) { |
674 r = (ind_j->produced_cargo[0] == CT_INVALID ? 0 : -1); |
669 r = (j->produced_cargo[0] == CT_INVALID ? 0 : -1); |
675 } else { |
670 } else { |
676 if (ind_j->produced_cargo[0] == CT_INVALID) { |
671 if (j->produced_cargo[0] == CT_INVALID) { |
677 r = 1; |
672 r = 1; |
678 } else { |
673 } else { |
679 r = |
674 r = |
680 (i->last_month_production[0] + i->last_month_production[1]) - |
675 (i->last_month_production[0] + i->last_month_production[1]) - |
681 (j->last_month_production[0] + j->last_month_production[1]); |
676 (j->last_month_production[0] + j->last_month_production[1]); |
682 } |
677 } |
683 } |
678 } |
684 break; |
679 break; |
685 |
680 |
686 case 3: /* Sort by transported fraction */ |
681 case 3: /* Sort by transported fraction */ |
687 if (ind_i->produced_cargo[0] == CT_INVALID) { |
682 if (i->produced_cargo[0] == CT_INVALID) { |
688 r = (ind_j->produced_cargo[0] == CT_INVALID ? 0 : -1); |
683 r = (j->produced_cargo[0] == CT_INVALID ? 0 : -1); |
689 } else { |
684 } else { |
690 if (ind_j->produced_cargo[0] == CT_INVALID) { |
685 if (j->produced_cargo[0] == CT_INVALID) { |
691 r = 1; |
686 r = 1; |
692 } else { |
687 } else { |
693 int pi; |
688 int pi; |
694 int pj; |
689 int pj; |
695 |
690 |
696 pi = i->last_month_pct_transported[0] * 100 >> 8; |
691 pi = i->last_month_pct_transported[0] * 100 >> 8; |
697 if (ind_i->produced_cargo[1] != CT_INVALID) { |
692 if (i->produced_cargo[1] != CT_INVALID) { |
698 int p = i->last_month_pct_transported[1] * 100 >> 8; |
693 int p = i->last_month_pct_transported[1] * 100 >> 8; |
699 if (p < pi) pi = p; |
694 if (p < pi) pi = p; |
700 } |
695 } |
701 |
696 |
702 pj = j->last_month_pct_transported[0] * 100 >> 8; |
697 pj = j->last_month_pct_transported[0] * 100 >> 8; |
703 if (ind_j->produced_cargo[1] != CT_INVALID) { |
698 if (j->produced_cargo[1] != CT_INVALID) { |
704 int p = j->last_month_pct_transported[1] * 100 >> 8; |
699 int p = j->last_month_pct_transported[1] * 100 >> 8; |
705 if (p < pj) pj = p; |
700 if (p < pj) pj = p; |
706 } |
701 } |
707 |
702 |
708 r = pi - pj; |
703 r = pi - pj; |
779 p = w->vscroll.pos; |
774 p = w->vscroll.pos; |
780 n = 0; |
775 n = 0; |
781 |
776 |
782 while (p < _num_industry_sort) { |
777 while (p < _num_industry_sort) { |
783 const Industry* i = _industry_sort[p]; |
778 const Industry* i = _industry_sort[p]; |
784 const IndustrySpec *ind = GetIndustrySpec(i->type); |
|
785 |
779 |
786 SetDParam(0, i->index); |
780 SetDParam(0, i->index); |
787 if (ind->produced_cargo[0] != CT_INVALID) { |
781 if (i->produced_cargo[0] != CT_INVALID) { |
788 SetDParam(1, ind->produced_cargo[0]); |
782 SetDParam(1, i->produced_cargo[0]); |
789 SetDParam(2, i->last_month_production[0]); |
783 SetDParam(2, i->last_month_production[0]); |
790 |
784 |
791 if (ind->produced_cargo[1] != CT_INVALID) { |
785 if (i->produced_cargo[1] != CT_INVALID) { |
792 SetDParam(3, ind->produced_cargo[1]); |
786 SetDParam(3, i->produced_cargo[1]); |
793 SetDParam(4, i->last_month_production[1]); |
787 SetDParam(4, i->last_month_production[1]); |
794 SetDParam(5, i->last_month_pct_transported[0] * 100 >> 8); |
788 SetDParam(5, i->last_month_pct_transported[0] * 100 >> 8); |
795 SetDParam(6, i->last_month_pct_transported[1] * 100 >> 8); |
789 SetDParam(6, i->last_month_pct_transported[1] * 100 >> 8); |
796 DrawString(4, 28 + n * 10, STR_INDUSTRYDIR_ITEM_TWO, 0); |
790 DrawString(4, 28 + n * 10, STR_INDUSTRYDIR_ITEM_TWO, 0); |
797 } else { |
791 } else { |