mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-06-22 13:09:38 +01:00
(svn r22571) -Add: [NewGRF] Show town persistent storage in the NewGRF debug GUI.
This commit is contained in:
parent
46d1a06215
commit
8ddb3941f7
@ -163,10 +163,19 @@ public:
|
|||||||
return ro.GetVariable(&ro, var, param, avail);
|
return ro.GetVariable(&ro, var, param, avail);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to decide if the PSA needs a parameter or not.
|
||||||
|
* @return True iff this item has a PSA that requires a parameter.
|
||||||
|
*/
|
||||||
|
virtual bool PSAWithParameter() const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows to know the size of the persistent storage.
|
* Allows to know the size of the persistent storage.
|
||||||
* @param index Index of the item.
|
* @param index Index of the item.
|
||||||
* @param grfid Unused.
|
* @param grfid Parameter for the PSA. Only required for items with parameters.
|
||||||
* @return Size of the persistent storage in indices.
|
* @return Size of the persistent storage in indices.
|
||||||
*/
|
*/
|
||||||
virtual uint GetPSASize(uint index, uint32 grfid) const
|
virtual uint GetPSASize(uint index, uint32 grfid) const
|
||||||
@ -177,7 +186,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Gets the first position of the array containing the persistent storage.
|
* Gets the first position of the array containing the persistent storage.
|
||||||
* @param index Index of the item.
|
* @param index Index of the item.
|
||||||
* @param grfid Unused.
|
* @param grfid Parameter for the PSA. Only required for items with parameters.
|
||||||
* @return Pointer to the first position of the storage array or NULL if not present.
|
* @return Pointer to the first position of the storage array or NULL if not present.
|
||||||
*/
|
*/
|
||||||
virtual int32 *GetPSAFirstPosition(uint index, uint32 grfid) const
|
virtual int32 *GetPSAFirstPosition(uint index, uint32 grfid) const
|
||||||
@ -388,10 +397,14 @@ struct NewGRFInspectWindow : Window {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint psa_size = nih->GetPSASize(index, 0);
|
uint psa_size = nih->GetPSASize(index, this->caller_grfid);
|
||||||
int32 *psa = nih->GetPSAFirstPosition(index, 0);
|
int32 *psa = nih->GetPSAFirstPosition(index, this->caller_grfid);
|
||||||
if (psa_size != 0 && psa != NULL) {
|
if (psa_size != 0 && psa != NULL) {
|
||||||
this->DrawString(r, i++, "Persistent storage:");
|
if (nih->PSAWithParameter()) {
|
||||||
|
this->DrawString(r, i++, "Persistent storage [%08X]:", BSWAP32(this->caller_grfid));
|
||||||
|
} else {
|
||||||
|
this->DrawString(r, i++, "Persistent storage:");
|
||||||
|
}
|
||||||
assert(psa_size % 4 == 0);
|
assert(psa_size % 4 == 0);
|
||||||
for (uint j = 0; j < psa_size; j += 4, psa += 4) {
|
for (uint j = 0; j < psa_size; j += 4, psa += 4) {
|
||||||
this->DrawString(r, i++, " %i: %i %i %i %i", j, psa[0], psa[1], psa[2], psa[3]);
|
this->DrawString(r, i++, " %i: %i %i %i %i", j, psa[0], psa[1], psa[2], psa[3]);
|
||||||
|
@ -158,6 +158,7 @@ void TownStorePSA(Town *t, const GRFFile *caller_grffile, uint pos, int32 value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Create a new storage. */
|
/* Create a new storage. */
|
||||||
|
assert(PersistentStorage::CanAllocateItem());
|
||||||
PersistentStorage *psa = new PersistentStorage(grfid);
|
PersistentStorage *psa = new PersistentStorage(grfid);
|
||||||
psa->StoreValue(pos, value);
|
psa->StoreValue(pos, value);
|
||||||
t->psa_list.push_back(psa);
|
t->psa_list.push_back(psa);
|
||||||
|
@ -443,6 +443,20 @@ class NIHTown : public NIHelper {
|
|||||||
void SetStringParameters(uint index) const { this->SetSimpleStringParameters(STR_TOWN_NAME, index); }
|
void SetStringParameters(uint index) const { this->SetSimpleStringParameters(STR_TOWN_NAME, index); }
|
||||||
uint32 GetGRFID(uint index) const { return 0; }
|
uint32 GetGRFID(uint index) const { return 0; }
|
||||||
uint Resolve(uint index, uint var, uint param, bool *avail) const { return TownGetVariable(var, param, avail, Town::Get(index), NULL); }
|
uint Resolve(uint index, uint var, uint param, bool *avail) const { return TownGetVariable(var, param, avail, Town::Get(index), NULL); }
|
||||||
|
bool PSAWithParameter() const { return true; }
|
||||||
|
uint GetPSASize(uint index, uint32 grfid) const { return cpp_lengthof(PersistentStorage, storage); }
|
||||||
|
|
||||||
|
int32 *GetPSAFirstPosition(uint index, uint32 grfid) const
|
||||||
|
{
|
||||||
|
Town *t = Town::Get(index);
|
||||||
|
|
||||||
|
std::list<PersistentStorage *>::iterator iter;
|
||||||
|
for (iter = t->psa_list.begin(); iter != t->psa_list.end(); iter++) {
|
||||||
|
if ((*iter)->grfid == grfid) return (int32 *)(&(*iter)->storage[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static const NIFeature _nif_town = {
|
static const NIFeature _nif_town = {
|
||||||
|
Loading…
Reference in New Issue
Block a user