//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){
Vehicle v;
v.setup(mouseX, mouseY);
vehicles.push_back(v);
}
/**
* Check the validity of some of the caches.
* Especially in the sense of desyncs between
* the cached value and what the value would
* be when calculated from the 'base' data.
*/
static void CheckCaches()
{
/* Return here so it is easy to add checks that are run
* always to aid testing of caches. */
if (_debug_desync_level <= 1) return;
/* Check the town caches. */
SmallVector<TownCache, 4> old_town_caches;
Town *t;
FOR_ALL_TOWNS(t) {
MemCpyT(old_town_caches.Append(), &t->cache);
}
extern void RebuildTownCaches();
RebuildTownCaches();
RebuildSubsidisedSourceAndDestinationCache();
uint i = 0;
FOR_ALL_TOWNS(t) {
if (MemCmpT(old_town_caches.Get(i), &t->cache) != 0) {
DEBUG(desync, 2, "town cache mismatch: town %i", (int)t->index);
}
i++;
}
/* Check company infrastructure cache. */
SmallVector<CompanyInfrastructure, 4> old_infrastructure;
Company *c;
FOR_ALL_COMPANIES(c) MemCpyT(old_infrastructure.Append(), &c->infrastructure);
extern void AfterLoadCompanyStats();
AfterLoadCompanyStats();
i = 0;
FOR_ALL_COMPANIES(c) {
if (MemCmpT(old_infrastructure.Get(i), &c->infrastructure) != 0) {
DEBUG(desync, 2, "infrastructure cache mismatch: company %i", (int)c->index);
}
i++;
}
/* Strict checking of the road stop cache entries */
const RoadStop *rs;
FOR_ALL_ROADSTOPS(rs) {
if (IsStandardRoadStopTile(rs->xy)) continue;
assert(rs->GetEntry(DIAGDIR_NE) != rs->GetEntry(DIAGDIR_NW));
rs->GetEntry(DIAGDIR_NE)->CheckIntegrity(rs);
rs->GetEntry(DIAGDIR_NW)->CheckIntegrity(rs);
}
Vehicle *v;
FOR_ALL_VEHICLES(v) {
extern void FillNewGRFVehicleCache(const Vehicle *v);
if (v != v->First() || v->vehstatus & VS_CRASHED || !v->IsPrimaryVehicle()) continue;
uint length = 0;
for (const Vehicle *u = v; u != NULL; u = u->Next()) length++;
NewGRFCache *grf_cache = CallocT<NewGRFCache>(length);
VehicleCache *veh_cache = CallocT<VehicleCache>(length);
GroundVehicleCache *gro_cache = CallocT<GroundVehicleCache>(length);
TrainCache *tra_cache = CallocT<TrainCache>(length);
length = 0;
for (const Vehicle *u = v; u != NULL; u = u->Next()) {
FillNewGRFVehicleCache(u);
grf_cache[length] = u->grf_cache;
veh_cache[length] = u->vcache;
switch (u->type) {
case VEH_TRAIN:
gro_cache[length] = Train::From(u)->gcache;
tra_cache[length] = Train::From(u)->tcache;
break;
case VEH_ROAD:
gro_cache[length] = RoadVehicle::From(u)->gcache;
break;
default:
break;
}
length++;
}
switch (v->type) {
case VEH_TRAIN: Train::From(v)->ConsistChanged(CCF_TRACK); break;
case VEH_ROAD: RoadVehUpdateCache(RoadVehicle::From(v)); break;
case VEH_AIRCRAFT: UpdateAircraftCache(Aircraft::From(v)); break;
case VEH_SHIP: Ship::From(v)->UpdateCache(); break;
default: break;
}
length = 0;
for (const Vehicle *u = v; u != NULL; u = u->Next()) {
FillNewGRFVehicleCache(u);
//.........这里部分代码省略.........
void option4()
{
string inSSN;
string choice;
string test;
string inData;
Person testUpdatePerson;
PersonFile * pPersonFile = new PersonFile;
Person * pPerson = new Person;
VehicleFile * pVehicleFile = new VehicleFile;
Vehicle * pVehicle = new Vehicle;
State * pState = new State;
County * pCounty = new County;
VMake * pVMake = new VMake;
Color * pColor = new Color;
VType * pVType = new VType;
while(true)
{
PrintHeading4();
getline(cin,inSSN);
cin.sync();
if(inSSN[0] == 'q' || inSSN[0] == 'Q') break;
*pPerson = pPersonFile->SearchBySSN(inSSN);
//Ensuring that the Record does not alrady exist
if(pPerson->IsFound() == true || pPerson->IsDeleted())
{
cout << "\n\t\t\tRecord for SSN: " << SSNHyphens(inSSN) << " already exists." << endl;
test = UserWait();
if(test[0] == 'q' || test[0] =='Q')
break;
continue;
}
//This Block only runs if the SSN was not found in the file
//SetFound is run so the Person can be displayed as before they are written out
pPerson->SetFound(true);
pPerson->SetSSN(Trim(inSSN));
while(true)
{
cout << "\n\n\t\tEnter new OLN: ";
getline(cin, inData);
cin.sync();
testUpdatePerson = pPersonFile->SearchByOLN(inData);
//IsDeleted is included because duplicate OLNs cause issues with SearchByOLN
if(testUpdatePerson.IsFound() || testUpdatePerson.IsDeleted())
{
cout << "\n\t\tOLN Already Exists in File. Choose Different OLN." << endl;
UserWait();
system("clear");
continue;
}
break;
}
pPerson->SetOLN(Trim(inData));
cout << "\n\n\t\tEnter new Last Name : ";
getline(cin, inData);
cin.sync();
pPerson->SetLastName(Trim(inData));
cout << "\n\n\t\tEnter new First Name : ";
getline(cin, inData);
cin.sync();
pPerson->SetFirstName(Trim(inData));
cout << "\n\n\t\tEnter new Middle Initial: ";
getline(cin, inData);
cin.sync();
pPerson->SetMI(Trim(inData));
cout << "\n\n\t\tEnter new Street Address: ";
getline(cin, inData);
cin.sync();
pPerson->SetStreet(Trim(inData));
cout << "\n\n\t\tEnter new City : ";
getline(cin, inData);
cin.sync();
pPerson->SetCity(Trim(inData));
system("clear");
cout << "\n\t\tNow Displaying Codes for: State";
pState->DisplayStates();
cout << "\n\n\t\tEnter State Code : ";
getline(cin, inData);
cin.sync();
pPerson->SetStateCode(Trim(inData));
//Only prompts for County if State is Alabama
if(pPerson->GetStateCode() != "02")
{
pPerson->SetCountyCode("00");
}
else
{
//.........这里部分代码省略.........
/**
* Change the company's company-colour
* @param tile unused
* @param flags operation to perform
* @param p1 bitstuffed:
* p1 bits 0-7 scheme to set
* p1 bits 8-9 set in use state or first/second colour
* @param p2 new colour for vehicles, property, etc.
* @param text unused
* @return the cost of this operation or an error
*/
CommandCost CmdSetCompanyColour(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
Colours colour = Extract<Colours, 0, 4>(p2);
LiveryScheme scheme = Extract<LiveryScheme, 0, 8>(p1);
byte state = GB(p1, 8, 2);
if (scheme >= LS_END || state >= 3 || colour == INVALID_COLOUR) return CMD_ERROR;
Company *c = Company::Get(_current_company);
/* Ensure no two companies have the same primary colour */
if (scheme == LS_DEFAULT && state == 0) {
const Company *cc;
FOR_ALL_COMPANIES(cc) {
if (cc != c && cc->colour == colour) return CMD_ERROR;
}
}
if (flags & DC_EXEC) {
switch (state) {
case 0:
c->livery[scheme].colour1 = colour;
/* If setting the first colour of the default scheme, adjust the
* original and cached company colours too. */
if (scheme == LS_DEFAULT) {
_company_colours[_current_company] = colour;
c->colour = colour;
CompanyAdminUpdate(c);
}
break;
case 1:
c->livery[scheme].colour2 = colour;
break;
case 2:
c->livery[scheme].in_use = colour != 0;
/* Now handle setting the default scheme's in_use flag.
* This is different to the other schemes, as it signifies if any
* scheme is active at all. If this flag is not set, then no
* processing of vehicle types occurs at all, and only the default
* colours will be used. */
/* If enabling a scheme, set the default scheme to be in use too */
if (colour != 0) {
c->livery[LS_DEFAULT].in_use = true;
break;
}
/* Else loop through all schemes to see if any are left enabled.
* If not, disable the default scheme too. */
c->livery[LS_DEFAULT].in_use = false;
for (scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
if (c->livery[scheme].in_use) {
c->livery[LS_DEFAULT].in_use = true;
break;
}
}
break;
default:
break;
}
ResetVehicleColourMap();
MarkWholeScreenDirty();
/* All graph related to companies use the company colour. */
InvalidateWindowData(WC_INCOME_GRAPH, 0);
InvalidateWindowData(WC_OPERATING_PROFIT, 0);
InvalidateWindowData(WC_DELIVERED_CARGO, 0);
InvalidateWindowData(WC_PERFORMANCE_HISTORY, 0);
InvalidateWindowData(WC_COMPANY_VALUE, 0);
/* The smallmap owner view also stores the company colours. */
BuildOwnerLegend();
InvalidateWindowData(WC_SMALLMAP, 0, 1);
/* Company colour data is indirectly cached. */
Vehicle *v;
FOR_ALL_VEHICLES(v) {
if (v->owner == _current_company) v->InvalidateNewGRFCache();
}
extern void UpdateObjectColours(const Company *c);
UpdateObjectColours(c);
}
return CommandCost();
}
/**
* Replace a whole vehicle chain
* @param chain vehicle chain to let autoreplace/renew operator on
* @param flags command flags
* @param wagon_removal remove wagons when the resulting chain occupies more tiles than the old did
* @param nothing_to_do is set to 'false' when something was done (only valid when not failed)
* @return cost or error
*/
static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlag flags, bool wagon_removal, bool *nothing_to_do)
{
Vehicle *old_head = *chain;
assert(old_head->IsPrimaryVehicle());
CommandCost cost = CommandCost(EXPENSES_NEW_VEHICLES, 0);
if (old_head->type == VEH_TRAIN) {
/* Store the length of the old vehicle chain, rounded up to whole tiles */
uint16 old_total_length = CeilDiv(Train::From(old_head)->gcache.cached_total_length, TILE_SIZE) * TILE_SIZE;
int num_units = 0; ///< Number of units in the chain
for (Train *w = Train::From(old_head); w != NULL; w = w->GetNextUnit()) num_units++;
Train **old_vehs = CallocT<Train *>(num_units); ///< Will store vehicles of the old chain in their order
Train **new_vehs = CallocT<Train *>(num_units); ///< New vehicles corresponding to old_vehs or NULL if no replacement
Money *new_costs = MallocT<Money>(num_units); ///< Costs for buying and refitting the new vehicles
/* Collect vehicles and build replacements
* Note: The replacement vehicles can only successfully build as long as the old vehicles are still in their chain */
int i;
Train *w;
for (w = Train::From(old_head), i = 0; w != NULL; w = w->GetNextUnit(), i++) {
assert(i < num_units);
old_vehs[i] = w;
CommandCost ret = BuildReplacementVehicle(old_vehs[i], (Vehicle**)&new_vehs[i], true);
cost.AddCost(ret);
if (cost.Failed()) break;
new_costs[i] = ret.GetCost();
if (new_vehs[i] != NULL) *nothing_to_do = false;
}
Train *new_head = (new_vehs[0] != NULL ? new_vehs[0] : old_vehs[0]);
/* Note: When autoreplace has already failed here, old_vehs[] is not completely initialized. But it is also not needed. */
if (cost.Succeeded()) {
/* Separate the head, so we can start constructing the new chain */
Train *second = Train::From(old_head)->GetNextUnit();
if (second != NULL) cost.AddCost(CmdMoveVehicle(second, NULL, DC_EXEC | DC_AUTOREPLACE, true));
assert(Train::From(new_head)->GetNextUnit() == NULL);
/* Append engines to the new chain
* We do this from back to front, so that the head of the temporary vehicle chain does not change all the time.
* That way we also have less trouble when exceeding the unitnumber limit.
* OTOH the vehicle attach callback is more expensive this way :s */
Train *last_engine = NULL; ///< Shall store the last engine unit after this step
if (cost.Succeeded()) {
for (int i = num_units - 1; i > 0; i--) {
Train *append = (new_vehs[i] != NULL ? new_vehs[i] : old_vehs[i]);
if (RailVehInfo(append->engine_type)->railveh_type == RAILVEH_WAGON) continue;
if (new_vehs[i] != NULL) {
/* Move the old engine to a separate row with DC_AUTOREPLACE. Else
* moving the wagon in front may fail later due to unitnumber limit.
* (We have to attach wagons without DC_AUTOREPLACE.) */
CmdMoveVehicle(old_vehs[i], NULL, DC_EXEC | DC_AUTOREPLACE, false);
}
if (last_engine == NULL) last_engine = append;
cost.AddCost(CmdMoveVehicle(append, new_head, DC_EXEC, false));
if (cost.Failed()) break;
}
if (last_engine == NULL) last_engine = new_head;
}
/* When wagon removal is enabled and the new engines without any wagons are already longer than the old, we have to fail */
if (cost.Succeeded() && wagon_removal && new_head->gcache.cached_total_length > old_total_length) cost = CommandCost(STR_ERROR_TRAIN_TOO_LONG_AFTER_REPLACEMENT);
/* Append/insert wagons into the new vehicle chain
* We do this from back to front, so we can stop when wagon removal or maximum train length (i.e. from mammoth-train setting) is triggered.
*/
if (cost.Succeeded()) {
for (int i = num_units - 1; i > 0; i--) {
assert(last_engine != NULL);
Vehicle *append = (new_vehs[i] != NULL ? new_vehs[i] : old_vehs[i]);
if (RailVehInfo(append->engine_type)->railveh_type == RAILVEH_WAGON) {
/* Insert wagon after 'last_engine' */
CommandCost res = CmdMoveVehicle(append, last_engine, DC_EXEC, false);
/* When we allow removal of wagons, either the move failing due
* to the train becoming too long, or the train becoming longer
* would move the vehicle to the empty vehicle chain. */
if (wagon_removal && (res.Failed() ? res.GetErrorMessage() == STR_ERROR_TRAIN_TOO_LONG : new_head->gcache.cached_total_length > old_total_length)) {
CmdMoveVehicle(append, NULL, DC_EXEC | DC_AUTOREPLACE, false);
break;
}
cost.AddCost(res);
//.........这里部分代码省略.........
请发表评论