Initial whitespace, formatting, file headers and NULL usage fixes.

This commit is contained in:
Jonathan G Rennison
2016-02-14 02:30:03 +00:00
parent 6be2efc084
commit a31e7ac87d
23 changed files with 712 additions and 588 deletions

View File

@@ -1,3 +1,14 @@
/* $Id$ */
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file tbtr_template_vehicle.cpp Template-based train replacement: template vehicle. */
#include "stdafx.h"
#include "company_func.h"
#include "train.h"
@@ -24,7 +35,6 @@
#include "table/train_cmd.h"
#include "tbtr_template_vehicle.h"
// since doing stuff with sprites
@@ -32,6 +42,8 @@
#include "newgrf_engine.h"
#include "newgrf_cargo.h"
#include "safeguards.h"
TemplatePool _template_pool("TemplatePool");
INSTANTIATE_POOL_METHODS(Template)
@@ -74,24 +86,28 @@ void TemplateVehicle::SetFirst(TemplateVehicle *v) { this->first = v; }
TemplateVehicle* TemplateVehicle::GetNextUnit() const
{
TemplateVehicle *tv = this->Next();
while ( tv && HasBit(tv->subtype, GVSF_ARTICULATED_PART) ) tv = tv->Next();
if ( tv && HasBit(tv->subtype, GVSF_MULTIHEADED) && !HasBit(tv->subtype, GVSF_ENGINE) ) tv = tv->Next();
while (tv && HasBit(tv->subtype, GVSF_ARTICULATED_PART)) {
tv = tv->Next();
}
if (tv && HasBit(tv->subtype, GVSF_MULTIHEADED) && !HasBit(tv->subtype, GVSF_ENGINE)) tv = tv->Next();
return tv;
}
TemplateVehicle* TemplateVehicle::GetPrevUnit()
{
TemplateVehicle *tv = this->Prev();
while ( tv && HasBit(tv->subtype, GVSF_ARTICULATED_PART|GVSF_ENGINE) ) tv = tv->Prev();
if ( tv && HasBit(tv->subtype, GVSF_MULTIHEADED|GVSF_ENGINE) ) tv = tv->Prev();
while (tv && HasBit(tv->subtype, GVSF_ARTICULATED_PART|GVSF_ENGINE)) {
tv = tv->Prev();
}
if (tv && HasBit(tv->subtype, GVSF_MULTIHEADED|GVSF_ENGINE)) tv = tv->Prev();
return tv;
}
/** setting */
void appendTemplateVehicle(TemplateVehicle *orig, TemplateVehicle *newv)
{
if ( !orig ) return;
while ( orig->Next() ) orig=orig->Next();
if (!orig) return;
while (orig->Next()) orig = orig->Next();
orig->SetNext(newv);
newv->SetPrev(orig);
newv->SetFirst(orig->First());
@@ -99,7 +115,7 @@ void appendTemplateVehicle(TemplateVehicle *orig, TemplateVehicle *newv)
void insertTemplateVehicle(TemplateVehicle *orig, TemplateVehicle *newv, TemplateVehicle *insert_after)
{
if ( !orig || !insert_after ) return;
if (!orig || !insert_after) return;
TemplateVehicle *insert_before = insert_after->Next();
insert_after->SetNext(newv);
insert_before->SetPrev(newv);
@@ -113,9 +129,12 @@ void insertTemplateVehicle(TemplateVehicle *orig, TemplateVehicle *newv, Templat
*/
int TemplateVehicle::Length() const
{
int l=1;
const TemplateVehicle *tmp=this;
while ( tmp->Next() ) { tmp=tmp->Next(); l++; }
int l = 1;
const TemplateVehicle *tmp = this;
while (tmp->Next()) {
tmp = tmp->Next();
l++;
}
return l;
}
@@ -123,32 +142,33 @@ TemplateReplacement* GetTemplateReplacementByGroupID(GroupID gid)
{
TemplateReplacement *tr;
FOR_ALL_TEMPLATE_REPLACEMENTS(tr) {
if ( tr->Group() == gid )
if (tr->Group() == gid) {
return tr;
}
}
return 0;
return NULL;
}
TemplateReplacement* GetTemplateReplacementByTemplateID(TemplateID tid) {
TemplateReplacement* GetTemplateReplacementByTemplateID(TemplateID tid)
{
TemplateReplacement *tr;
FOR_ALL_TEMPLATE_REPLACEMENTS(tr) {
if ( tr->Template() == tid )
if (tr->Template() == tid) {
return tr;
}
}
return 0;
return NULL;
}
bool IssueTemplateReplacement(GroupID gid, TemplateID tid) {
bool IssueTemplateReplacement(GroupID gid, TemplateID tid)
{
TemplateReplacement *tr = GetTemplateReplacementByGroupID(gid);
if ( tr ) {
if (tr) {
/* Then set the new TemplateVehicle and return */
tr->SetTemplate(tid);
return true;
}
else if ( TemplateReplacement::CanAllocateItem() ) {
} else if (TemplateReplacement::CanAllocateItem()) {
tr = new TemplateReplacement(gid, tid);
return true;
}
@@ -161,8 +181,9 @@ short TemplateVehicle::NumGroupsUsingTemplate() const
short amount = 0;
const TemplateReplacement *tr;
FOR_ALL_TEMPLATE_REPLACEMENTS(tr) {
if ( tr->sel_template == this->index )
if (tr->sel_template == this->index) {
amount++;
}
}
return amount;
}
@@ -171,9 +192,11 @@ short TemplateVehicle::CountEnginesInChain()
{
TemplateVehicle *tv = this->first;
short count = 0;
for ( ; tv; tv=tv->GetNextUnit() )
if ( HasBit(tv->subtype, GVSF_ENGINE ) )
for (; tv != NULL; tv = tv->GetNextUnit()) {
if (HasBit(tv->subtype, GVSF_ENGINE)) {
count++;
}
}
return count;
}
@@ -182,46 +205,10 @@ short deleteIllegalTemplateReplacements(GroupID g_id)
short del_amount = 0;
const TemplateReplacement *tr;
FOR_ALL_TEMPLATE_REPLACEMENTS(tr) {
if ( tr->group == g_id ) {
if (tr->group == g_id) {
delete tr;
del_amount++;
}
}
return del_amount;
}