/** * Increases the tick counter, increases date and possibly calls * procedures that have to be called daily, monthly or yearly. */ void IncreaseDate() { /* increase day, and check if a new day is there? */ _tick_counter++; if (_game_mode == GM_MENU) return; _date_fract++; if (_date_fract < DAY_TICKS) return; _date_fract = 0; /* increase day counter and call various daily loops */ _date++; OnNewDay(); YearMonthDay ymd; /* check if we entered a new month? */ ConvertDateToYMD(_date, &ymd); if (ymd.month == _cur_month) return; /* yes, call various monthly loops */ _cur_month = ymd.month; OnNewMonth(); /* check if we entered a new year? */ if (ymd.year == _cur_year) return; /* yes, call various yearly loops */ _cur_year = ymd.year; OnNewYear(); }
/** * Set the date. * @param date New date * @param fract The number of ticks that have passed on this date. */ void SetDate(Date date, DateFract fract) { assert(fract < DAY_TICKS); YearMonthDay ymd; _date = date; _date_fract = fract; ConvertDateToYMD(date, &ymd); _cur_year = ymd.year; _cur_month = ymd.month; }
/** * Create the new 'set date' window * @param desc the window description * @param window_number number of the window * @param parent the parent window, i.e. if this closes we should close too * @param initial_date the initial date to show * @param min_year the minimum year to show in the year dropdown * @param max_year the maximum year (inclusive) to show in the year dropdown * @param callback the callback to call once a date has been selected */ SetDateWindow(WindowDesc *desc, WindowNumber window_number, Window *parent, Date initial_date, Year min_year, Year max_year, SetDateCallback *callback) : Window(desc), callback(callback), min_year(max(MIN_YEAR, min_year)), max_year(min(MAX_YEAR, max_year)) { assert(this->min_year <= this->max_year); this->parent = parent; this->InitNested(window_number); if (initial_date == 0) initial_date = _date; ConvertDateToYMD(initial_date, &this->date); this->date.year = Clamp(this->date.year, min_year, max_year); }
/** * Handle changing of the current year. * @param p1 Unused. * @param p2 +1 (increase) or -1 (decrease). * @return New year. */ static int32 ClickChangeDateCheat(int32 p1, int32 p2) { YearMonthDay ymd; ConvertDateToYMD(_date, &ymd); p1 = Clamp(p1, MIN_YEAR, MAX_YEAR); if (p1 == _cur_year) return _cur_year; SetDate(ConvertYMDToDate(p1, ymd.month, ymd.day), _date_fract); EnginesMonthlyLoop(); SetWindowDirty(WC_STATUS_BAR, 0); InvalidateWindowClassesData(WC_BUILD_STATION, 0); ResetSignalVariant(); return _cur_year; }
/** Compute the value for #_year_engine_aging_stops. */ void SetYearEngineAgingStops() { /* Determine last engine aging year, default to 2050 as previously. */ _year_engine_aging_stops = 2050; const Engine *e; FOR_ALL_ENGINES(e) { const EngineInfo *ei = &e->info; /* Exclude certain engines */ if (!HasBit(ei->climates, _settings_game.game_creation.landscape)) continue; if (e->type == VEH_TRAIN && e->u.rail.railveh_type == RAILVEH_WAGON) continue; /* Base year ending date on half the model life */ YearMonthDay ymd; ConvertDateToYMD(ei->base_intro + (ei->lifelength * DAYS_IN_LEAP_YEAR) / 2, &ymd); _year_engine_aging_stops = max(_year_engine_aging_stops, ymd.year); } }
virtual void DrawWidget(const Rect &r, int widget) const { if (widget != WID_GL_PANEL) return; YearMonthDay ymd; ConvertDateToYMD(_date, &ymd); int right = r.right - WD_FRAMERECT_RIGHT; int y = r.top + WD_FRAMERECT_TOP; int x = r.left + WD_FRAMERECT_LEFT; int pos = -this->vscroll->GetPosition(); const int cap = this->vscroll->GetCapacity(); /* Draw partial list with global goals */ DrawPartialGoalList(pos, cap, x, y, right, true); /* Draw partial list with company goals */ pos++; DrawPartialGoalList(pos, cap, x, y, right, false); }
/** * Increases the tick counter, increases date and possibly calls * procedures that have to be called daily, monthly or yearly. */ void IncreaseDate() { /* increase day, and check if a new day is there? */ _tick_counter++; if (_game_mode == GM_MENU) return; _date_fract++; if (_date_fract < DAY_TICKS) return; _date_fract = 0; /* increase day counter */ _date++; YearMonthDay ymd; ConvertDateToYMD(_date, &ymd); /* check if we entered a new month? */ bool new_month = ymd.month != _cur_month; /* check if we entered a new year? */ bool new_year = ymd.year != _cur_year; /* update internal variables before calling the daily/monthly/yearly loops */ _cur_month = ymd.month; _cur_year = ymd.year; /* yes, call various daily loops */ OnNewDay(); /* yes, call various monthly loops */ if (new_month) OnNewMonth(); /* yes, call various yearly loops */ if (new_year) OnNewYear(); }
/** * Draw the purchase info details of a vehicle at a given location. * @param left,right,y location where to draw the info * @param engine_number the engine of which to draw the info of * @return y after drawing all the text */ int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number) { const Engine *e = Engine::Get(engine_number); YearMonthDay ymd; ConvertDateToYMD(e->intro_date, &ymd); bool refittable = IsArticulatedVehicleRefittable(engine_number); bool articulated_cargo = false; switch (e->type) { default: NOT_REACHED(); case VEH_TRAIN: if (e->u.rail.railveh_type == RAILVEH_WAGON) { y = DrawRailWagonPurchaseInfo(left, right, y, engine_number, &e->u.rail); } else { y = DrawRailEnginePurchaseInfo(left, right, y, engine_number, &e->u.rail); } articulated_cargo = true; break; case VEH_ROAD: y = DrawRoadVehPurchaseInfo(left, right, y, engine_number); articulated_cargo = true; break; case VEH_SHIP: y = DrawShipPurchaseInfo(left, right, y, engine_number, refittable); break; case VEH_AIRCRAFT: y = DrawAircraftPurchaseInfo(left, right, y, engine_number, refittable); break; } if (articulated_cargo) { /* Cargo type + capacity, or N/A */ int new_y = DrawCargoCapacityInfo(left, right, y, engine_number, refittable); if (new_y == y) { SetDParam(0, CT_INVALID); SetDParam(2, STR_EMPTY); DrawString(left, right, y, STR_PURCHASE_INFO_CAPACITY); y += FONT_HEIGHT_NORMAL; } else { y = new_y; } } /* Draw details that apply to all types except rail wagons. */ if (e->type != VEH_TRAIN || e->u.rail.railveh_type != RAILVEH_WAGON) { /* Design date - Life length */ SetDParam(0, ymd.year); SetDParam(1, e->GetLifeLengthInDays() / DAYS_IN_LEAP_YEAR); DrawString(left, right, y, STR_PURCHASE_INFO_DESIGNED_LIFE); y += FONT_HEIGHT_NORMAL; /* Reliability */ SetDParam(0, ToPercent16(e->reliability)); DrawString(left, right, y, STR_PURCHASE_INFO_RELIABILITY); y += FONT_HEIGHT_NORMAL; } if (refittable) y = ShowRefitOptionsList(left, right, y, engine_number); /* Additional text from NewGRF */ y = ShowAdditionalText(left, right, y, engine_number); return y; }
virtual void DrawWidget(const Rect &r, int widget) const { if (widget != SLW_PANEL) return; YearMonthDay ymd; ConvertDateToYMD(_date, &ymd); int right = r.right - WD_FRAMERECT_RIGHT; int y = r.top + WD_FRAMERECT_TOP; int x = r.left + WD_FRAMERECT_LEFT; int pos = -this->vscroll->GetPosition(); const int cap = this->vscroll->GetCapacity(); /* Section for drawing the offered subisidies */ if (IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_SUBSIDIES_OFFERED_TITLE); pos++; uint num = 0; const Subsidy *s; FOR_ALL_SUBSIDIES(s) { if (!s->IsAwarded()) { if (IsInsideMM(pos, 0, cap)) { /* Displays the two offered towns */ SetupSubsidyDecodeParam(s, true); SetDParam(7, _date - ymd.day + s->remaining * 32); DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_SUBSIDIES_OFFERED_FROM_TO); } pos++; num++; } } if (num == 0) { if (IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_SUBSIDIES_NONE); pos++; } /* Section for drawing the already granted subisidies */ pos++; if (IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_SUBSIDIES_SUBSIDISED_TITLE); pos++; num = 0; FOR_ALL_SUBSIDIES(s) { if (s->IsAwarded()) { if (IsInsideMM(pos, 0, cap)) { SetupSubsidyDecodeParam(s, true); SetDParam(7, s->awarded); SetDParam(8, _date - ymd.day + s->remaining * 32); /* Displays the two connected stations */ DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_SUBSIDIES_SUBSIDISED_FROM_TO); } pos++; num++; } } if (num == 0) { if (IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, STR_SUBSIDIES_NONE); pos++; } }