本文整理汇总了C++中Ship::InvalidateNewGRFCacheOfChain方法的典型用法代码示例。如果您正苦于以下问题:C++ Ship::InvalidateNewGRFCacheOfChain方法的具体用法?C++ Ship::InvalidateNewGRFCacheOfChain怎么用?C++ Ship::InvalidateNewGRFCacheOfChain使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ship
的用法示例。
在下文中一共展示了Ship::InvalidateNewGRFCacheOfChain方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CmdBuildShip
/**
* Build a ship.
* @param tile tile of the depot where ship is built.
* @param flags type of operation.
* @param e the engine to build.
* @param data unused.
* @param ret[out] the vehicle that has been built.
* @return the cost of this operation or an error.
*/
CommandCost CmdBuildShip(TileIndex tile, DoCommandFlag flags, const Engine *e, uint16 data, Vehicle **ret)
{
tile = GetShipDepotNorthTile(tile);
if (flags & DC_EXEC) {
int x;
int y;
const ShipVehicleInfo *svi = &e->u.ship;
Ship *v = new Ship();
*ret = v;
v->owner = _current_company;
v->tile = tile;
x = TileX(tile) * TILE_SIZE + TILE_SIZE / 2;
y = TileY(tile) * TILE_SIZE + TILE_SIZE / 2;
v->x_pos = x;
v->y_pos = y;
v->z_pos = GetSlopeZ(x, y);
v->UpdateDeltaXY(v->direction);
v->vehstatus = VS_HIDDEN | VS_STOPPED | VS_DEFPAL;
v->spritenum = svi->image_index;
v->cargo_type = e->GetDefaultCargoType();
v->cargo_cap = svi->capacity;
v->last_station_visited = INVALID_STATION;
v->engine_type = e->index;
v->reliability = e->reliability;
v->reliability_spd_dec = e->reliability_spd_dec;
v->max_age = e->GetLifeLengthInDays();
_new_vehicle_id = v->index;
v->state = TRACK_BIT_DEPOT;
v->service_interval = Company::Get(_current_company)->settings.vehicle.servint_ships;
v->date_of_last_service = _date;
v->build_year = _cur_year;
v->cur_image = SPR_IMG_QUERY;
v->random_bits = VehicleRandomBits();
v->UpdateCache();
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
v->InvalidateNewGRFCacheOfChain();
v->cargo_cap = GetVehicleCapacity(v);
v->InvalidateNewGRFCacheOfChain();
VehicleMove(v, false);
}
return CommandCost();
}
示例2: CmdRefitShip
/** Refits a ship to the specified cargo type.
* @param tile unused
* @param flags type of operation
* @param p1 vehicle ID of the ship to refit
* @param p2 various bitstuffed elements
* - p2 = (bit 0-7) - the new cargo type to refit to (p2 & 0xFF)
* - p2 = (bit 8-15) - the new cargo subtype to refit to
* - p2 = (bit 16) - refit only this vehicle (ignored)
* @param text unused
* @return the cost of this operation or an error
*/
CommandCost CmdRefitShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
CargoID new_cid = GB(p2, 0, 8); // gets the cargo number
byte new_subtype = GB(p2, 8, 8);
Ship *v = Ship::GetIfValid(p1);
if (v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR;
if (!v->IsStoppedInDepot()) return_cmd_error(STR_ERROR_SHIP_MUST_BE_STOPPED_IN_DEPOT);
if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_CAN_T_REFIT_DESTROYED_VEHICLE);
/* Check cargo */
if (new_cid >= NUM_CARGO) return CMD_ERROR;
CommandCost cost = RefitVehicle(v, true, new_cid, new_subtype, flags);
if (flags & DC_EXEC) {
v->colourmap = PAL_NONE; // invalidate vehicle colour map
SetWindowDirty(WC_VEHICLE_DETAILS, v->index);
SetWindowDirty(WC_VEHICLE_DEPOT, v->tile);
InvalidateWindowClassesData(WC_SHIPS_LIST, 0);
}
v->InvalidateNewGRFCacheOfChain(); // always invalidate; querycost might have filled it
return cost;
}
示例3: CmdBuildShip
/** Build a ship.
* @param tile tile of depot where ship is built
* @param flags type of operation
* @param p1 ship type being built (engine)
* @param p2 unused
* @param text unused
* @return the cost of this operation or an error
*/
CommandCost CmdBuildShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
UnitID unit_num;
if (!IsEngineBuildable(p1, VEH_SHIP, _current_company)) return_cmd_error(STR_ERROR_SHIP_NOT_AVAILABLE);
const Engine *e = Engine::Get(p1);
CommandCost value(EXPENSES_NEW_VEHICLES, e->GetCost());
/* Engines without valid cargo should not be available */
if (e->GetDefaultCargoType() == CT_INVALID) return CMD_ERROR;
if (flags & DC_QUERY_COST) return value;
/* The ai_new queries the vehicle cost before building the route,
* so we must check against cheaters no sooner than now. --pasky */
if (!IsShipDepotTile(tile)) return CMD_ERROR;
if (!IsTileOwner(tile, _current_company)) return CMD_ERROR;
unit_num = (flags & DC_AUTOREPLACE) ? 0 : GetFreeUnitNumber(VEH_SHIP);
if (!Vehicle::CanAllocateItem() || unit_num > _settings_game.vehicle.max_ships)
return_cmd_error(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME);
if (flags & DC_EXEC) {
int x;
int y;
const ShipVehicleInfo *svi = &e->u.ship;
Ship *v = new Ship();
v->unitnumber = unit_num;
v->owner = _current_company;
v->tile = tile;
x = TileX(tile) * TILE_SIZE + TILE_SIZE / 2;
y = TileY(tile) * TILE_SIZE + TILE_SIZE / 2;
v->x_pos = x;
v->y_pos = y;
v->z_pos = GetSlopeZ(x, y);
v->UpdateDeltaXY(v->direction);
v->vehstatus = VS_HIDDEN | VS_STOPPED | VS_DEFPAL;
v->spritenum = svi->image_index;
v->cargo_type = e->GetDefaultCargoType();
v->cargo_cap = svi->capacity;
v->value = value.GetCost();
v->last_station_visited = INVALID_STATION;
v->max_speed = svi->max_speed;
v->engine_type = p1;
v->reliability = e->reliability;
v->reliability_spd_dec = e->reliability_spd_dec;
v->max_age = e->GetLifeLengthInDays();
_new_vehicle_id = v->index;
v->state = TRACK_BIT_DEPOT;
v->service_interval = Company::Get(_current_company)->settings.vehicle.servint_ships;
v->date_of_last_service = _date;
v->build_year = _cur_year;
v->cur_image = SPR_IMG_QUERY;
v->random_bits = VehicleRandomBits();
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
v->InvalidateNewGRFCacheOfChain();
v->cargo_cap = GetVehicleCapacity(v);
v->InvalidateNewGRFCacheOfChain();
VehicleMove(v, false);
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
InvalidateWindowClassesData(WC_SHIPS_LIST, 0);
SetWindowDirty(WC_COMPANY, v->owner);
if (IsLocalCompany()) {
InvalidateAutoreplaceWindow(v->engine_type, v->group_id); // updates the replace Ship window
}
Company::Get(_current_company)->num_engines[p1]++;
}
return value;
}