diff --git a/src/unit/unittype.cpp b/src/unit/unittype.cpp index 29fbcebb4..f323d447c 100644 --- a/src/unit/unittype.cpp +++ b/src/unit/unittype.cpp @@ -65,9 +65,9 @@ */ global const char UnitTypeType[] = "unit-type"; -IfDebug( +#ifdef DEBUG global int NoWarningUnitType; /// quiet ident lookup -); +#endif global UnitType* UnitTypes[UnitTypeMax]; /// unit-types definition global int NumUnitTypes; /// number of unit-types made @@ -77,8 +77,8 @@ global int NumUnitTypes; /// number of unit-types made ** ** FIXME: find a way to make it configurable! */ -global UnitType*UnitTypeHumanWall; /// Human wall -global UnitType*UnitTypeOrcWall; /// Orc wall +global UnitType* UnitTypeHumanWall; /// Human wall +global UnitType* UnitTypeOrcWall; /// Orc wall /** ** Mapping of W*rCr*ft number to our internal unit-type symbol. @@ -98,7 +98,7 @@ local UnitType* UnitTypeHash[UnitTypeMax]; /** ** Lookup table for unit-type names */ -local hashtable(UnitType*,UnitTypeMax) UnitTypeHash; +local hashtable(UnitType*, UnitTypeMax) UnitTypeHash; #endif @@ -143,7 +143,7 @@ global char* DefaultResourceNames[MaxCosts]; /** ** Update the player stats for changed unit types. -** @param reset indicates wether default value should be set to each stat ( level, upgrades ) +** @param reset indicates wether default value should be set to each stat (level, upgrades) */ global void UpdateStats(int reset) { @@ -186,12 +186,12 @@ global void UpdateStats(int reset) switch (type->UnitType) { case UnitTypeLand: // on land type->MovementMask = - MapFieldLandUnit - | MapFieldSeaUnit - | MapFieldBuilding // already occuppied - | MapFieldCoastAllowed - | MapFieldWaterAllowed // can't move on this - | MapFieldUnpassable; + MapFieldLandUnit | + MapFieldSeaUnit | + MapFieldBuilding | // already occuppied + MapFieldCoastAllowed | + MapFieldWaterAllowed | // can't move on this + MapFieldUnpassable; break; case UnitTypeFly: // in air type->MovementMask = @@ -200,19 +200,19 @@ global void UpdateStats(int reset) case UnitTypeNaval: // on water if (type->Transporter) { type->MovementMask = - MapFieldLandUnit - | MapFieldSeaUnit - | MapFieldBuilding // already occuppied - | MapFieldLandAllowed; // can't move on this + MapFieldLandUnit | + MapFieldSeaUnit | + MapFieldBuilding | // already occuppied + MapFieldLandAllowed; // can't move on this // Johns: MapFieldUnpassable only for land units? } else { type->MovementMask = - MapFieldLandUnit - | MapFieldSeaUnit - | MapFieldBuilding // already occuppied - | MapFieldCoastAllowed - | MapFieldLandAllowed // can't move on this - | MapFieldUnpassable; + MapFieldLandUnit | + MapFieldSeaUnit | + MapFieldBuilding | // already occuppied + MapFieldCoastAllowed | + MapFieldLandAllowed | // can't move on this + MapFieldUnpassable; } break; default: @@ -220,21 +220,21 @@ global void UpdateStats(int reset) type->MovementMask = 0; break; } - if( type->Building || type->ShoreBuilding ) { + if (type->Building || type->ShoreBuilding) { // Shore building is something special. - if( type->ShoreBuilding ) { + if (type->ShoreBuilding) { type->MovementMask = - MapFieldLandUnit - | MapFieldSeaUnit - | MapFieldBuilding // already occuppied - | MapFieldLandAllowed; // can't build on this + MapFieldLandUnit | + MapFieldSeaUnit | + MapFieldBuilding | // already occuppied + MapFieldLandAllowed; // can't build on this } type->MovementMask |= MapFieldNoBuilding; // // A little chaos, buildings without HP can be entered. // The oil-patch is a very special case. // - if( type->_HitPoints ) { + if (type->_HitPoints) { type->FieldFlags = MapFieldBuilding; } else { type->FieldFlags = MapFieldNoBuilding; @@ -266,7 +266,7 @@ global void UpdateStats(int reset) ** @param udta Pointer to udta area. ** @param length length of udta area. */ -global void ParsePudUDTA(const char* udta,int length __attribute__((unused))) +global void ParsePudUDTA(const char* udta, int length __attribute__((unused))) { int i; int v; @@ -274,225 +274,226 @@ global void ParsePudUDTA(const char* udta,int length __attribute__((unused))) UnitType* unittype; // FIXME: not the fastest, remove UnitTypeByWcNum from loops! - IfDebug( - if( length!=5694 && length!=5948 ) { - DebugLevel0("\n***\n"); - DebugLevel0Fn("%d\n" _C_ length); - DebugLevel0("***\n\n"); - } - ) - start=udta; +#ifdef DEBUG + if (length != 5694 && length != 5948) { + DebugLevel0("\n***\n"); + DebugLevel0Fn("%d\n" _C_ length); + DebugLevel0("***\n\n"); + } +#endif + start = udta; - for( i=0; i<110; ++i ) { // overlap frames - unittype=UnitTypeByWcNum(i); - v=FetchLE16(udta); - unittype->Construction=ConstructionByWcNum(v); + for (i = 0; i < 110; ++i) { // overlap frames + unittype = UnitTypeByWcNum(i); + v = FetchLE16(udta); + unittype->Construction = ConstructionByWcNum(v); } - for( i=0; i<508; ++i ) { // skip obsolete data - v=FetchLE16(udta); + for (i = 0; i < 508; ++i) { // skip obsolete data + v = FetchLE16(udta); } - for( i=0; i<110; ++i ) { // sight range - unittype=UnitTypeByWcNum(i); - v=FetchLE32(udta); - unittype->_SightRange=v; + for (i = 0; i < 110; ++i) { // sight range + unittype = UnitTypeByWcNum(i); + v = FetchLE32(udta); + unittype->_SightRange = v; } - for( i=0; i<110; ++i ) { // hit points - unittype=UnitTypeByWcNum(i); - v=FetchLE16(udta); - unittype->_HitPoints=v; + for (i = 0; i < 110; ++i) { // hit points + unittype = UnitTypeByWcNum(i); + v = FetchLE16(udta); + unittype->_HitPoints = v; } - for( i=0; i<110; ++i ) { // Flag if unit is magic - unittype=UnitTypeByWcNum(i); - v=Fetch8(udta); - unittype->Magic=v; + for (i = 0; i < 110; ++i) { // Flag if unit is magic + unittype = UnitTypeByWcNum(i); + v = Fetch8(udta); + unittype->Magic = v; } - for( i=0; i<110; ++i ) { // Build time * 6 = one second FRAMES - unittype=UnitTypeByWcNum(i); - v=Fetch8(udta); - unittype->_Costs[TimeCost]=v; + for (i = 0; i < 110; ++i) { // Build time * 6 = one second FRAMES + unittype = UnitTypeByWcNum(i); + v = Fetch8(udta); + unittype->_Costs[TimeCost] = v; } - for( i=0; i<110; ++i ) { // Gold cost / 10 - unittype=UnitTypeByWcNum(i); - v=Fetch8(udta); - unittype->_Costs[GoldCost]=v*10; + for (i = 0; i < 110; ++i) { // Gold cost / 10 + unittype = UnitTypeByWcNum(i); + v = Fetch8(udta); + unittype->_Costs[GoldCost] = v * 10; } - for( i=0; i<110; ++i ) { // Lumber cost / 10 - unittype=UnitTypeByWcNum(i); - v=Fetch8(udta); - unittype->_Costs[WoodCost]=v*10; + for (i = 0; i < 110; ++i) { // Lumber cost / 10 + unittype = UnitTypeByWcNum(i); + v = Fetch8(udta); + unittype->_Costs[WoodCost] = v * 10; } - for( i=0; i<110; ++i ) { // Oil cost / 10 - unittype=UnitTypeByWcNum(i); - v=Fetch8(udta); - unittype->_Costs[OilCost]=v*10; + for (i = 0; i < 110; ++i) { // Oil cost / 10 + unittype = UnitTypeByWcNum(i); + v = Fetch8(udta); + unittype->_Costs[OilCost] = v * 10; } - for( i=0; i<110; ++i ) { // Unit size in tiles - unittype=UnitTypeByWcNum(i); - v=FetchLE16(udta); - unittype->TileWidth=v; - v=FetchLE16(udta); - unittype->TileHeight=v; + for (i = 0; i < 110; ++i) { // Unit size in tiles + unittype = UnitTypeByWcNum(i); + v = FetchLE16(udta); + unittype->TileWidth = v; + v = FetchLE16(udta); + unittype->TileHeight = v; } - for( i=0; i<110; ++i ) { // Box size in pixel - unittype=UnitTypeByWcNum(i); - v=FetchLE16(udta); - unittype->BoxWidth=v; - v=FetchLE16(udta); - unittype->BoxHeight=v; + for (i = 0; i < 110; ++i) { // Box size in pixel + unittype = UnitTypeByWcNum(i); + v = FetchLE16(udta); + unittype->BoxWidth = v; + v = FetchLE16(udta); + unittype->BoxHeight = v; } - for( i=0; i<110; ++i ) { // Attack range - unittype=UnitTypeByWcNum(i); - v=Fetch8(udta); - unittype->_AttackRange=v; + for (i = 0; i < 110; ++i) { // Attack range + unittype = UnitTypeByWcNum(i); + v = Fetch8(udta); + unittype->_AttackRange = v; } - for( i=0; i<110; ++i ) { // React range - unittype=UnitTypeByWcNum(i); - v=Fetch8(udta); - unittype->ReactRangeComputer=v; + for (i = 0; i < 110; ++i) { // React range + unittype = UnitTypeByWcNum(i); + v = Fetch8(udta); + unittype->ReactRangeComputer = v; } - for( i=0; i<110; ++i ) { // React range - unittype=UnitTypeByWcNum(i); - v=Fetch8(udta); - unittype->ReactRangePerson=v; + for (i = 0; i < 110; ++i) { // React range + unittype = UnitTypeByWcNum(i); + v = Fetch8(udta); + unittype->ReactRangePerson = v; } - for( i=0; i<110; ++i ) { // Armor - unittype=UnitTypeByWcNum(i); - v=Fetch8(udta); - unittype->_Armor=v; + for (i = 0; i < 110; ++i) { // Armor + unittype = UnitTypeByWcNum(i); + v = Fetch8(udta); + unittype->_Armor = v; } - for( i=0; i<110; ++i ) { // Selectable via rectangle - unittype=UnitTypeByWcNum(i); - v=Fetch8(udta); - unittype->SelectableByRectangle=v!=0; + for (i = 0; i < 110; ++i) { // Selectable via rectangle + unittype = UnitTypeByWcNum(i); + v = Fetch8(udta); + unittype->SelectableByRectangle = v != 0; } - for( i=0; i<110; ++i ) { // Priority - unittype=UnitTypeByWcNum(i); - v=Fetch8(udta); - unittype->Priority=v; + for (i = 0; i < 110; ++i) { // Priority + unittype = UnitTypeByWcNum(i); + v = Fetch8(udta); + unittype->Priority = v; } - for( i=0; i<110; ++i ) { // Basic damage - unittype=UnitTypeByWcNum(i); - v=Fetch8(udta); - unittype->_BasicDamage=v; + for (i = 0; i < 110; ++i) { // Basic damage + unittype = UnitTypeByWcNum(i); + v = Fetch8(udta); + unittype->_BasicDamage = v; } - for( i=0; i<110; ++i ) { // Piercing damage - unittype=UnitTypeByWcNum(i); - v=Fetch8(udta); - unittype->_PiercingDamage=v; + for (i = 0; i < 110; ++i) { // Piercing damage + unittype = UnitTypeByWcNum(i); + v = Fetch8(udta); + unittype->_PiercingDamage = v; } - for( i=0; i<110; ++i ) { // Weapons upgradable - unittype=UnitTypeByWcNum(i); - v=Fetch8(udta); - unittype->WeaponsUpgradable=v; + for (i = 0; i < 110; ++i) { // Weapons upgradable + unittype = UnitTypeByWcNum(i); + v = Fetch8(udta); + unittype->WeaponsUpgradable = v; } - for( i=0; i<110; ++i ) { // Armor upgradable - unittype=UnitTypeByWcNum(i); - v=Fetch8(udta); - unittype->ArmorUpgradable=v; + for (i = 0; i < 110; ++i) { // Armor upgradable + unittype = UnitTypeByWcNum(i); + v = Fetch8(udta); + unittype->ArmorUpgradable = v; } - for( i=0; i<110; ++i ) { // Missile Weapon - unittype=UnitTypeByWcNum(i); - v=Fetch8(udta); - unittype->Missile.Name=strdup(MissileTypeWcNames[v]); - DebugCheck( unittype->Missile.Missile ); + for (i = 0; i < 110; ++i) { // Missile Weapon + unittype = UnitTypeByWcNum(i); + v = Fetch8(udta); + unittype->Missile.Name = strdup(MissileTypeWcNames[v]); + DebugCheck(unittype->Missile.Missile); } - for( i=0; i<110; ++i ) { // Unit type - unittype=UnitTypeByWcNum(i); - v=Fetch8(udta); - unittype->UnitType=v; + for (i = 0; i < 110; ++i) { // Unit type + unittype = UnitTypeByWcNum(i); + v = Fetch8(udta); + unittype->UnitType = v; } - for( i=0; i<110; ++i ) { // Decay rate * 6 = secs - unittype=UnitTypeByWcNum(i); - v=Fetch8(udta); - unittype->DecayRate=v; + for (i = 0; i < 110; ++i) { // Decay rate * 6 = secs + unittype = UnitTypeByWcNum(i); + v = Fetch8(udta); + unittype->DecayRate = v; } - for( i=0; i<110; ++i ) { // Annoy computer factor - unittype=UnitTypeByWcNum(i); - v=Fetch8(udta); - unittype->AnnoyComputerFactor=v; + for (i = 0; i < 110; ++i) { // Annoy computer factor + unittype = UnitTypeByWcNum(i); + v = Fetch8(udta); + unittype->AnnoyComputerFactor = v; } - for( i=0; i<58; ++i ) { // 2nd mouse button action - unittype=UnitTypeByWcNum(i); - v=Fetch8(udta); - unittype->MouseAction=v; + for (i = 0; i < 58; ++i) { // 2nd mouse button action + unittype = UnitTypeByWcNum(i); + v = Fetch8(udta); + unittype->MouseAction = v; } - for( ; i<110; ++i ) { // 2nd mouse button action - unittype=UnitTypeByWcNum(i); - unittype->MouseAction=0; + for (; i < 110; ++i) { // 2nd mouse button action + unittype = UnitTypeByWcNum(i); + unittype->MouseAction = 0; } - for( i=0; i<110; ++i ) { // Point value for killing unit - unittype=UnitTypeByWcNum(i); - v=FetchLE16(udta); - unittype->Points=v; + for (i = 0; i < 110; ++i) { // Point value for killing unit + unittype = UnitTypeByWcNum(i); + v = FetchLE16(udta); + unittype->Points = v; } - for( i=0; i<110; ++i ) { // Can target (1 land, 2 sea, 4 air) - unittype=UnitTypeByWcNum(i); - v=Fetch8(udta); - unittype->CanTarget=v; + for (i = 0; i < 110; ++i) { // Can target (1 land, 2 sea, 4 air) + unittype = UnitTypeByWcNum(i); + v = Fetch8(udta); + unittype->CanTarget = v; } - for( i=0; i<110; ++i ) { // Flags - unittype=UnitTypeByWcNum(i); - v=FetchLE32(udta); + for (i = 0; i < 110; ++i) { // Flags + unittype = UnitTypeByWcNum(i); + v = FetchLE32(udta); /// Nice looking bit macro -#define BIT(b,v) (((v>>b))&1) - unittype->LandUnit=BIT(0,v); - unittype->AirUnit=BIT(1,v); - unittype->ExplodeWhenKilled=BIT(2,v); - unittype->SeaUnit=BIT(3,v); +#define BIT(b,v) (((v >> b)) & 1) + unittype->LandUnit = BIT(0, v); + unittype->AirUnit = BIT(1, v); + unittype->ExplodeWhenKilled = BIT(2, v); + unittype->SeaUnit = BIT(3, v); // BIT(4,v) This makes the unit a critter, true for demons, skeletons and sheep. // There were some uses for this in code, like removing a health bar and the like, // but I (n0body) don't think they were usefull. Thus BIT(4,v) is from now on ignored. - unittype->Building=BIT(5,v); - unittype->PermanentCloak=BIT(6,v); - unittype->DetectCloak=BIT(7,v); + unittype->Building = BIT(5, v); + unittype->PermanentCloak = BIT(6, v); + unittype->DetectCloak = BIT(7, v); // Cowards - unittype->Coward=BIT(8,v)|BIT(26,v); - if (BIT(9,v)) { - unittype->ResInfo[OilCost]=(ResourceInfo*)malloc(sizeof(ResourceInfo)); - memset(unittype->ResInfo[OilCost],0,sizeof(ResourceInfo)); - unittype->ResInfo[OilCost]->ResourceId=OilCost; - unittype->ResInfo[OilCost]->FinalResource=OilCost; - unittype->ResInfo[OilCost]->WaitAtResource=150; - unittype->ResInfo[OilCost]->WaitAtDepot=150; - unittype->ResInfo[OilCost]->ResourceCapacity=100; + unittype->Coward = BIT(8, v) | BIT(26, v); + if (BIT(9, v)) { + unittype->ResInfo[OilCost] = (ResourceInfo*)malloc(sizeof(ResourceInfo)); + memset(unittype->ResInfo[OilCost], 0, sizeof(ResourceInfo)); + unittype->ResInfo[OilCost]->ResourceId = OilCost; + unittype->ResInfo[OilCost]->FinalResource = OilCost; + unittype->ResInfo[OilCost]->WaitAtResource = 150; + unittype->ResInfo[OilCost]->WaitAtDepot = 150; + unittype->ResInfo[OilCost]->ResourceCapacity = 100; } - unittype->Transporter=BIT(10,v); - unittype->CanStore[GoldCost]=BIT(12,v); - unittype->Vanishes=BIT(13,v); - unittype->GroundAttack=BIT(14,v); - unittype->IsUndead=BIT(15,v); - unittype->ShoreBuilding=BIT(16,v); -// unittype->CanCastSpell=BIT(17,v);unittype->CanCastSpell = (char *) malloc(/*nb_spell*/); + unittype->Transporter = BIT(10, v); + unittype->CanStore[GoldCost] = BIT(12, v); + unittype->Vanishes = BIT(13, v); + unittype->GroundAttack = BIT(14, v); + unittype->IsUndead = BIT(15, v); + unittype->ShoreBuilding = BIT(16, v); +// unittype->CanCastSpell = BIT(17,v); +// unittype->CanCastSpell = (char*)malloc(/*nb_spell*/); unittype->CanCastSpell = NULL;// - unittype->CanStore[WoodCost]=BIT(18,v); - unittype->CanAttack=BIT(19,v); - unittype->Hero=BIT(23,v); - unittype->CanStore[OilCost]=BIT(24,v); - unittype->Volatile=BIT(25,v); - unittype->Organic=BIT(27,v); + unittype->CanStore[WoodCost] = BIT(18, v); + unittype->CanAttack = BIT(19, v); + unittype->Hero = BIT(23, v); + unittype->CanStore[OilCost] = BIT(24, v); + unittype->Volatile = BIT(25, v); + unittype->Organic = BIT(27, v); - if (BIT(11,v)||BIT(21,v)) { - unittype->GivesResource=OilCost; + if (BIT(11, v) || BIT(21, v)) { + unittype->GivesResource = OilCost; } - if (BIT(22,v)) { - unittype->GivesResource=GoldCost; + if (BIT(22, v)) { + unittype->GivesResource = GoldCost; } #ifdef DEBUG - if( BIT(28,v) ) DebugLevel0("Unused bit 28 used in %d\n" _C_ i); - if( BIT(29,v) ) DebugLevel0("Unused bit 29 used in %d\n" _C_ i); - if( BIT(30,v) ) DebugLevel0("Unused bit 30 used in %d\n" _C_ i); - if( BIT(31,v) ) DebugLevel0("Unused bit 31 used in %d\n" _C_ i); + if (BIT(28, v)) DebugLevel0("Unused bit 28 used in %d\n" _C_ i); + if (BIT(29, v)) DebugLevel0("Unused bit 29 used in %d\n" _C_ i); + if (BIT(30, v)) DebugLevel0("Unused bit 30 used in %d\n" _C_ i); + if (BIT(31, v)) DebugLevel0("Unused bit 31 used in %d\n" _C_ i); #endif #undef BIT // // Unit type checks. // - if( unittype->CanCastSpell && !unittype->_MaxMana ) { + if (unittype->CanCastSpell && !unittype->_MaxMana) { DebugLevel0Fn("%s: Need max mana value\n" _C_ unittype->Ident); - unittype->_MaxMana=255; + unittype->_MaxMana = 255; } } @@ -516,8 +517,8 @@ global Animations* AnimationsByIdent(const char* ident) { Animations** tmp; - tmp=(Animations**)hash_find(AnimationsHash,ident); - if( tmp ) { + tmp = (Animations**)hash_find(AnimationsHash, ident); + if (tmp) { return *tmp; } DebugLevel0Fn("Warning animation `%s' not found\n" _C_ ident); @@ -531,50 +532,50 @@ global Animations* AnimationsByIdent(const char* ident) ** @param anim Save this animation. ** @param file Output file. */ -local void SaveAnimation(const char* name,const Animation* anim,CLFile* file) +local void SaveAnimation(const char* name, const Animation* anim, CLFile* file) { int i; int p; int frame; const Animation* temp; - if( anim ) { + if (anim) { // // Calculate the wait sum and pixels count. // - i=p=0; - for( temp=anim; ; ++temp ) { - i+=temp->Sleep&0xFF; - p+=temp->Pixel; - if( temp->Flags&AnimationEnd ) { + i = p = 0; + for (temp = anim; ; ++temp) { + i += temp->Sleep & 0xFF; + p += temp->Pixel; + if (temp->Flags & AnimationEnd) { break; } - if( temp->Flags&AnimationRestart ) { - i=p=0; + if (temp->Flags & AnimationRestart) { + i = p = 0; } } - CLprintf(file,"\n '%s '(\t; #%d",name,i); - if( p ) { - CLprintf(file," P%d",p); + CLprintf(file, "\n '%s '(\t; #%d", name, i); + if (p) { + CLprintf(file, " P%d", p); } - temp=anim; - frame=0; - for( ;; ) { - CLprintf(file,"\n "); - for( i=0; i<4; ++i ) { - if( i ) { - CLprintf(file," "); + temp = anim; + frame = 0; + for (;;) { + CLprintf(file, "\n "); + for (i = 0; i < 4; ++i) { + if (i) { + CLprintf(file, " "); } - frame+=temp->Frame; - CLprintf(file,"#(%2d %d %3d %3d)", - temp->Flags&0x7F,temp->Pixel,temp->Sleep&0xFF,frame); - if( temp->Flags&AnimationRestart ) { - frame=0; + frame += temp->Frame; + CLprintf(file, "#(%2d %d %3d %3d)", + temp->Flags & 0x7F, temp->Pixel, temp->Sleep & 0xFF, frame); + if (temp->Flags & AnimationRestart) { + frame = 0; } - if( temp->Flags&AnimationEnd ) { - CLprintf(file,")"); + if (temp->Flags & AnimationEnd) { + CLprintf(file, ")"); return; } ++temp; @@ -597,41 +598,41 @@ local void SaveAnimations(const UnitType* type,CLFile* file) int i; int q; - if( !(anims=type->Animations) ) { + if (!(anims = type->Animations)) { return; } // // Look if this is the first use of it. // - for( i=0; i<NumUnitTypes && UnitTypes[i]!=type ; ++i ) { - if( UnitTypes[i]->Animations==anims ) { + for (i = 0; i < NumUnitTypes && UnitTypes[i] != type ; ++i) { + if (UnitTypes[i]->Animations == anims) { return; // allready handled. } } - CLprintf(file,"\n;;------\n;;\t"); + CLprintf(file, "\n;;------\n;;\t"); // // Print all units that use this animation. // - q=0; - for( i=0 ; i<NumUnitTypes ; ++i ) { - if( UnitTypes[i]->Animations==anims ) { - if( q ) { - CLprintf(file,", "); + q = 0; + for (i = 0 ; i < NumUnitTypes ; ++i) { + if (UnitTypes[i]->Animations == anims) { + if (q) { + CLprintf(file, ", "); } - CLprintf(file,"%s",UnitTypes[i]->Name); - q=1; + CLprintf(file, "%s", UnitTypes[i]->Name); + q = 1; } } - CLprintf(file,"\n(define-animations 'animations-%s",type->Ident+5); + CLprintf(file, "\n(define-animations 'animations-%s", type->Ident + 5); - SaveAnimation("still",anims->Still,file); - SaveAnimation("move",anims->Move,file); - SaveAnimation("attack",anims->Attack,file); - SaveAnimation("die",anims->Die,file); + SaveAnimation("still", anims->Still,file); + SaveAnimation("move", anims->Move,file); + SaveAnimation("attack", anims->Attack,file); + SaveAnimation("die", anims->Die,file); - CLprintf(file,")\n"); + CLprintf(file, ")\n"); } /** @@ -643,429 +644,442 @@ local void SaveAnimations(const UnitType* type,CLFile* file) ** ** @todo Arrange the variables more logical */ -local void SaveUnitType(CLFile* file,const UnitType* type,int all) +local void SaveUnitType(CLFile* file, const UnitType* type, int all) { int i; int flag; ResourceInfo* res; - CLprintf(file,"(define-unit-type '%s",type->Ident); - CLprintf(file," 'name \"%s\"\n ",type->Name); + CLprintf(file, "(define-unit-type '%s", type->Ident); + CLprintf(file, " 'name \"%s\"\n ", type->Name); // Graphic files - if( type->SameSprite ) { - CLprintf(file,"'use '%s",type->SameSprite); + if (type->SameSprite) { + CLprintf(file, "'use '%s", type->SameSprite); } else { - CLprintf(file,"'files '("); - for( flag=i=0; i<TilesetMax; ++i ) { - if( type->File[i] ) { - if( flag ) { - CLprintf(file,"\n "); + CLprintf(file, "'files '("); + for (flag = i = 0; i < TilesetMax; ++i) { + if (type->File[i]) { + if (flag) { + CLprintf(file, "\n "); } - CLprintf(file,"%s \"%s\"",Tilesets[i]->Ident,type->File[i]); - flag=1; + CLprintf(file, "%s \"%s\"", Tilesets[i]->Ident, type->File[i]); + flag = 1; } } - CLprintf(file,")"); + CLprintf(file, ")"); } - CLprintf(file,"\n 'size '(%d %d)\n",type->Width,type->Height); - if( type->ShadowFile ) { - CLprintf(file," 'shadow '(file \"%s\" width %d height %d)\n", - type->ShadowFile, type->ShadowWidth, type->ShadowHeight); + CLprintf(file, "\n 'size '(%d %d)\n", type->Width, type->Height); + if (type->ShadowFile) { + CLprintf(file, " 'shadow '(file \"%s\" width %d height %d)\n", + type->ShadowFile, type->ShadowWidth, type->ShadowHeight); } // // Animations are shared, find first use of the unit-type animation. // - for( i=0; i<NumUnitTypes && UnitTypes[i]!=type ; ++i ) { - if( UnitTypes[i]->Animations==type->Animations ) { + for (i = 0; i < NumUnitTypes && UnitTypes[i] != type ; ++i) { + if (UnitTypes[i]->Animations == type->Animations) { break; } } - CLprintf(file," 'animations 'animations-%s",UnitTypes[i]->Ident+5); - CLprintf(file," 'icon '%s\n",IdentOfIcon(type->Icon.Icon)); - for( i=flag=0; i<MaxCosts; ++i ) { - if( all || type->_Costs[i] ) { - if( !flag ) { - CLprintf(file," 'costs '("); - flag=1; + CLprintf(file, " 'animations 'animations-%s", UnitTypes[i]->Ident + 5); + CLprintf(file, " 'icon '%s\n", IdentOfIcon(type->Icon.Icon)); + for (i = flag = 0; i < MaxCosts; ++i) { + if (all || type->_Costs[i]) { + if (!flag) { + CLprintf(file, " 'costs '("); + flag = 1; } else { - CLprintf(file," "); + CLprintf(file, " "); } - CLprintf(file,"%s %d",DefaultResourceNames[i],type->_Costs[i]); + CLprintf(file, "%s %d", DefaultResourceNames[i], type->_Costs[i]); } } - if( flag ) { - CLprintf(file,")\n"); + if (flag) { + CLprintf(file, ")\n"); } - for( i=flag=0; i<MaxCosts; ++i ) { - if( type->ImproveIncomes[i] > DefaultIncomes[i] ) { - if( !flag ) { - CLprintf(file," 'improve-production '("); - flag=1; + for (i = flag = 0; i < MaxCosts; ++i) { + if (type->ImproveIncomes[i] > DefaultIncomes[i]) { + if (!flag) { + CLprintf(file, " 'improve-production '("); + flag = 1; } else { - CLprintf(file," "); + CLprintf(file, " "); } - CLprintf(file,"%s %d ",DefaultResourceNames[i],type->ImproveIncomes[i]-DefaultIncomes[i]); + CLprintf(file, "%s %d ", DefaultResourceNames[i], + type->ImproveIncomes[i] - DefaultIncomes[i]); } } - if( flag ) { - CLprintf(file,")\n"); + if (flag) { + CLprintf(file, ")\n"); } - if( type->RepairHP ) { - for( i=flag=0; i<MaxCosts; ++i ) { - if( all || type->_Costs[i] ) { - if( !flag ) { - CLprintf(file," 'repair-costs '("); - flag=1; + if (type->RepairHP) { + for (i = flag = 0; i < MaxCosts; ++i) { + if (all || type->_Costs[i]) { + if (!flag) { + CLprintf(file, " 'repair-costs '("); + flag = 1; } else { - CLprintf(file," "); + CLprintf(file, " "); } - CLprintf(file,"%s %d",DefaultResourceNames[i],type->RepairCosts[i]); + CLprintf(file, "%s %d", DefaultResourceNames[i], + type->RepairCosts[i]); } } } - if( flag ) { - CLprintf(file,")\n"); + if (flag) { + CLprintf(file, ")\n"); } - if( type->RepairHP ) { - CLprintf(file," 'repair-hp %d\n",type->RepairHP); + if (type->RepairHP) { + CLprintf(file, " 'repair-hp %d\n", type->RepairHP); } - if( type->Construction ) { - CLprintf(file," 'construction '%s\n",type->Construction->Ident); + if (type->Construction) { + CLprintf(file, " 'construction '%s\n", type->Construction->Ident); } - CLprintf(file," 'speed %d\n",type->_Speed); - CLprintf(file," 'hit-points %d\n",type->_HitPoints); - CLprintf(file," 'regeneration-rate %d\n",type->_RegenerationRate); - if( all || type->_MaxMana ) { - CLprintf(file," 'max-mana %d\n",type->_MaxMana); + CLprintf(file, " 'speed %d\n", type->_Speed); + CLprintf(file, " 'hit-points %d\n", type->_HitPoints); + CLprintf(file, " 'regeneration-rate %d\n", type->_RegenerationRate); + if (all || type->_MaxMana) { + CLprintf(file, " 'max-mana %d\n", type->_MaxMana); } - if( all || type->Magic ) { - CLprintf(file," 'magic %d\n",type->Magic); + if (all || type->Magic) { + CLprintf(file, " 'magic %d\n", type->Magic); } - CLprintf(file," 'tile-size '(%d %d)",type->TileWidth,type->TileHeight); - CLprintf(file," 'box-size '(%d %d)\n",type->BoxWidth,type->BoxHeight); - CLprintf(file," 'sight-range %d",type->_SightRange); - if( all || type->ReactRangeComputer ) { - CLprintf(file," 'computer-reaction-range %d",type->ReactRangeComputer); + CLprintf(file, " 'tile-size '(%d %d)", type->TileWidth, type->TileHeight); + CLprintf(file, " 'box-size '(%d %d)\n", type->BoxWidth, type->BoxHeight); + CLprintf(file, " 'sight-range %d", type->_SightRange); + if (all || type->ReactRangeComputer) { + CLprintf(file, " 'computer-reaction-range %d", type->ReactRangeComputer); } - if( all || type->ReactRangePerson ) { - CLprintf(file," 'person-reaction-range %d",type->ReactRangePerson); + if (all || type->ReactRangePerson) { + CLprintf(file, " 'person-reaction-range %d", type->ReactRangePerson); } - CLprintf(file,"\n"); + CLprintf(file, "\n"); - if( all || type->_Armor ) { - CLprintf(file," 'armor %d",type->_Armor); + if (all || type->_Armor) { + CLprintf(file, " 'armor %d", type->_Armor); } else { - CLprintf(file," "); + CLprintf(file, " "); } - CLprintf(file," 'basic-damage %d",type->_BasicDamage); - CLprintf(file," 'piercing-damage %d",type->_PiercingDamage); - CLprintf(file," 'missile '%s\n",type->Missile.Name); - CLprintf(file," 'draw-level %d",type->DrawLevel); - if( all || type->MinAttackRange ) { - CLprintf(file," 'min-attack-range %d",type->MinAttackRange); - CLprintf(file," 'max-attack-range %d\n",type->_AttackRange); - } else if( type->_AttackRange ) { - CLprintf(file," 'max-attack-range %d\n",type->_AttackRange); + CLprintf(file, " 'basic-damage %d", type->_BasicDamage); + CLprintf(file, " 'piercing-damage %d", type->_PiercingDamage); + CLprintf(file, " 'missile '%s\n", type->Missile.Name); + CLprintf(file, " 'draw-level %d", type->DrawLevel); + if (all || type->MinAttackRange) { + CLprintf(file, " 'min-attack-range %d", type->MinAttackRange); + CLprintf(file, " 'max-attack-range %d\n", type->_AttackRange); + } else if (type->_AttackRange) { + CLprintf(file, " 'max-attack-range %d\n", type->_AttackRange); } - if( all || type->WeaponsUpgradable ) { - CLprintf(file," 'weapons-upgradable %d",type->WeaponsUpgradable); - if( all || type->ArmorUpgradable ) { - CLprintf(file," 'armor-upgradable %d\n",type->ArmorUpgradable); + if (all || type->WeaponsUpgradable) { + CLprintf(file, " 'weapons-upgradable %d", type->WeaponsUpgradable); + if (all || type->ArmorUpgradable) { + CLprintf(file, " 'armor-upgradable %d\n", type->ArmorUpgradable); } else { - CLprintf(file,"\n"); + CLprintf(file, "\n"); } - } else if( type->ArmorUpgradable ) { - CLprintf(file," 'armor-upgradable %d\n",type->ArmorUpgradable); + } else if (type->ArmorUpgradable) { + CLprintf(file, " 'armor-upgradable %d\n", type->ArmorUpgradable); } - CLprintf(file," 'priority %d",type->Priority); - if( all || type->AnnoyComputerFactor ) { - CLprintf(file," 'annoy-computer-factor %d",type->AnnoyComputerFactor); + CLprintf(file, " 'priority %d", type->Priority); + if (all || type->AnnoyComputerFactor) { + CLprintf(file, " 'annoy-computer-factor %d", type->AnnoyComputerFactor); } - CLprintf(file,"\n"); - if( all || type->DecayRate ) { - CLprintf(file," 'decay-rate %d\n",type->DecayRate); + CLprintf(file, "\n"); + if (all || type->DecayRate) { + CLprintf(file, " 'decay-rate %d\n", type->DecayRate); } - if( all || type->Points ) { - CLprintf(file," 'points %d\n",type->Points); + if (all || type->Points) { + CLprintf(file, " 'points %d\n", type->Points); } - if( all || type->Demand ) { - CLprintf(file," 'demand %d\n",type->Demand); + if (all || type->Demand) { + CLprintf(file, " 'demand %d\n", type->Demand); } - if( all || type->Supply ) { - CLprintf(file," 'supply %d\n",type->Supply); + if (all || type->Supply) { + CLprintf(file, " 'supply %d\n", type->Supply); } - if( type->CorpseName ) { - CLprintf(file," 'corpse '(%s %d)\n", - type->CorpseName,type->CorpseScript); + if (type->CorpseName) { + CLprintf(file, " 'corpse '(%s %d)\n", + type->CorpseName, type->CorpseScript); } - if( type->ExplodeWhenKilled ) { - CLprintf(file," 'explode-when-killed '%s\n",type->Missile.Name); + if (type->ExplodeWhenKilled) { + CLprintf(file, " 'explode-when-killed '%s\n", type->Missile.Name); } - CLprintf(file," "); - switch( type->UnitType ) { + CLprintf(file, " "); + switch (type->UnitType) { case UnitTypeLand: - CLprintf(file,"'type-land"); + CLprintf(file, "'type-land"); break; case UnitTypeFly: - CLprintf(file,"'type-fly"); + CLprintf(file, "'type-fly"); break; case UnitTypeNaval: - CLprintf(file,"'type-naval"); + CLprintf(file, "'type-naval"); break; default: - CLprintf(file,"'type-unknown"); + CLprintf(file, "'type-unknown"); break; } - CLprintf(file,"\n"); + CLprintf(file, "\n"); - CLprintf(file," "); - switch( type->MouseAction ) { + CLprintf(file, " "); + switch (type->MouseAction) { case MouseActionNone: - if( all ) { - CLprintf(file,"'right-none"); + if (all) { + CLprintf(file, "'right-none"); } break; case MouseActionAttack: - CLprintf(file,"'right-attack"); + CLprintf(file, "'right-attack"); break; case MouseActionMove: - CLprintf(file,"'right-move"); + CLprintf(file, "'right-move"); break; case MouseActionHarvest: - CLprintf(file,"'right-harvest"); + CLprintf(file, "'right-harvest"); break; case MouseActionDemolish: - CLprintf(file,"'right-demolish"); + CLprintf(file, "'right-demolish"); break; case MouseActionSail: - CLprintf(file,"'right-sail"); + CLprintf(file, "'right-sail"); break; default: - CLprintf(file,"'right-unknown"); + CLprintf(file, "'right-unknown"); break; } - CLprintf(file,"\n"); + CLprintf(file, "\n"); - if( type->GroundAttack ) { - CLprintf(file," 'can-ground-attack\n"); + if (type->GroundAttack) { + CLprintf(file, " 'can-ground-attack\n"); } - if( type->CanAttack ) { - CLprintf(file," 'can-attack\n"); + if (type->CanAttack) { + CLprintf(file, " 'can-attack\n"); } - if( type->RepairRange ) { - CLprintf(file," 'repair-range %d\n",type->RepairRange); + if (type->RepairRange) { + CLprintf(file, " 'repair-range %d\n", type->RepairRange); } - if( type->DemolishRange ) { - CLprintf(file," 'demolish-range %d\n",type->DemolishRange); + if (type->DemolishRange) { + CLprintf(file, " 'demolish-range %d\n", type->DemolishRange); } - if( type->DemolishRange ) { - CLprintf(file," 'demolish-damage %d\n",type->DemolishDamage); + if (type->DemolishRange) { + CLprintf(file, " 'demolish-damage %d\n", type->DemolishDamage); } - if( type->CanTarget ) { - CLprintf(file," "); - if( type->CanTarget&CanTargetLand ) { - CLprintf(file,"'can-target-land "); + if (type->CanTarget) { + CLprintf(file, " "); + if (type->CanTarget & CanTargetLand) { + CLprintf(file, "'can-target-land "); } - if( type->CanTarget&CanTargetSea ) { - CLprintf(file,"'can-target-sea "); + if (type->CanTarget & CanTargetSea) { + CLprintf(file, "'can-target-sea "); } - if( type->CanTarget&CanTargetAir ) { - CLprintf(file,"'can-target-air "); + if (type->CanTarget & CanTargetAir) { + CLprintf(file, "'can-target-air "); } - if( type->CanTarget&~7 ) { - CLprintf(file,"'can-target-other "); + if (type->CanTarget & ~7) { + CLprintf(file, "'can-target-other "); } - CLprintf(file,"\n"); + CLprintf(file, "\n"); } - if( type->Building ) { - CLprintf(file," 'building"); + if (type->Building) { + CLprintf(file, " 'building"); } - if( type->BuilderOutside ) { - CLprintf(file," 'builder-outside"); + if (type->BuilderOutside) { + CLprintf(file, " 'builder-outside"); } - if( type->BuilderLost ) { - CLprintf(file," 'builder-lost"); + if (type->BuilderLost) { + CLprintf(file, " 'builder-lost"); } - if( type->AutoBuildRate ) { - CLprintf(file," 'auto-build-rate"); + if (type->AutoBuildRate) { + CLprintf(file, " 'auto-build-rate"); } - if( type->ShoreBuilding ) { - CLprintf(file," 'shore-building\n"); + if (type->ShoreBuilding) { + CLprintf(file, " 'shore-building\n"); } - if( type->LandUnit ) { - CLprintf(file," 'land-unit\n"); + if (type->LandUnit) { + CLprintf(file, " 'land-unit\n"); } - if( type->AirUnit ) { - CLprintf(file," 'air-unit\n"); + if (type->AirUnit) { + CLprintf(file, " 'air-unit\n"); } - if( type->SeaUnit ) { - CLprintf(file," 'sea-unit\n"); + if (type->SeaUnit) { + CLprintf(file, " 'sea-unit\n"); } - if( type->RandomMovementProbability ) { - CLprintf(file," 'random-movement-probability %d\n",type->RandomMovementProbability); + if (type->RandomMovementProbability) { + CLprintf(file, " 'random-movement-probability %d\n", + type->RandomMovementProbability); } - if( type->ClicksToExplode ) { - CLprintf(file," 'clicks-to-explode %d\n",type->ClicksToExplode); + if (type->ClicksToExplode) { + CLprintf(file, " 'clicks-to-explode %d\n", type->ClicksToExplode); } - if( type->Sniper ) { - CLprintf(file," 'sniper \n"); + if (type->Sniper) { + CLprintf(file, " 'sniper \n"); } - if( type->Revealer ) { - CLprintf(file," 'revealer\n"); + if (type->Revealer) { + CLprintf(file, " 'revealer\n"); } - if( type->PermanentCloak ) { - CLprintf(file," 'permanent-cloak\n"); + if (type->PermanentCloak) { + CLprintf(file, " 'permanent-cloak\n"); } - if( type->DetectCloak ) { - CLprintf(file," 'detect-cloak\n"); + if (type->DetectCloak) { + CLprintf(file, " 'detect-cloak\n"); } - if( type->Transporter ) { - CLprintf(file," 'transporter\n"); + if (type->Transporter) { + CLprintf(file, " 'transporter\n"); } - if( type->Transporter ) { - CLprintf(file," 'max-on-board %d\n",type->MaxOnBoard); + if (type->Transporter) { + CLprintf(file, " 'max-on-board %d\n", type->MaxOnBoard); } - if( type->Coward ) { - CLprintf(file," 'coward\n"); + if (type->Coward) { + CLprintf(file, " 'coward\n"); } - if( type->Harvester ) { - for (i=0;i<MaxCosts;i++) { + if (type->Harvester) { + for (i = 0; i < MaxCosts; ++i) { if (type->ResInfo[i]) { - res=type->ResInfo[i]; - CLprintf(file," 'can-gather-resource '(\n"); - CLprintf(file," resource-id %s\n",DefaultResourceNames[res->ResourceId]); - CLprintf(file," final-resource %s\n",DefaultResourceNames[res->FinalResource]); - if( res->HarvestFromOutside ) { - CLprintf(file," harvest-from-outside\n"); + res = type->ResInfo[i]; + CLprintf(file, " 'can-gather-resource '(\n"); + CLprintf(file, " resource-id %s\n", + DefaultResourceNames[res->ResourceId]); + CLprintf(file, " final-resource %s\n", + DefaultResourceNames[res->FinalResource]); + if (res->HarvestFromOutside) { + CLprintf(file, " harvest-from-outside\n"); } - if ( res->WaitAtResource ) { - CLprintf(file," wait-at-resource %d\n",res->WaitAtResource); + if (res->WaitAtResource) { + CLprintf(file, " wait-at-resource %d\n", + res->WaitAtResource); } - if ( res->WaitAtDepot ) { - CLprintf(file," wait-at-depot %d\n",res->WaitAtDepot); + if (res->WaitAtDepot) { + CLprintf(file, " wait-at-depot %d\n", + res->WaitAtDepot); } - if ( res->ResourceCapacity ) { - CLprintf(file," resource-capacity %d\n",res->ResourceCapacity); + if (res->ResourceCapacity) { + CLprintf(file, " resource-capacity %d\n", + res->ResourceCapacity); } - if( res->ResourceStep ) { - CLprintf(file," resource-step %d\n",res->ResourceStep); + if (res->ResourceStep) { + CLprintf(file, " resource-step %d\n", + res->ResourceStep); } - if( res->TerrainHarvester ) { - CLprintf(file," terrain-harvester\n"); + if (res->TerrainHarvester) { + CLprintf(file, " terrain-harvester\n"); } - if( res->LoseResources ) { - CLprintf(file," lose-resources\n"); + if (res->LoseResources) { + CLprintf(file, " lose-resources\n"); } - if ( res->FileWhenEmpty ) { - CLprintf(file," file-when-empty %s\n",res->FileWhenEmpty); + if (res->FileWhenEmpty) { + CLprintf(file, " file-when-empty %s\n", + res->FileWhenEmpty); } - if ( res->FileWhenLoaded ) { - CLprintf(file," file-when-loaded %s\n",res->FileWhenLoaded); + if (res->FileWhenLoaded) { + CLprintf(file, " file-when-loaded %s\n", + res->FileWhenLoaded); } - CLprintf(file," )\n"); + CLprintf(file, " )\n"); } } } - if( type->GivesResource ) { - CLprintf(file," 'gives-resource '%s\n",DefaultResourceNames[type->GivesResource]); + if (type->GivesResource) { + CLprintf(file, " 'gives-resource '%s\n", + DefaultResourceNames[type->GivesResource]); } - if( type->MaxWorkers ) { - CLprintf(file," 'max-workers %d\n",type->MaxWorkers); + if (type->MaxWorkers) { + CLprintf(file, " 'max-workers %d\n", + type->MaxWorkers); } // Save store info. - for (flag=i=0;i<MaxCosts;i++) + for (flag = i = 0; i < MaxCosts; ++i) if (type->CanStore[i]) { if (!flag) { - flag=1; - CLprintf(file," 'can-store '(%s",DefaultResourceNames[i]); + flag = 1; + CLprintf(file, " 'can-store '(%s", DefaultResourceNames[i]); } else { - CLprintf(file," %s",DefaultResourceNames[i]); + CLprintf(file, " %s", DefaultResourceNames[i]); } } if (flag) - CLprintf(file,")"); + CLprintf(file, ")"); - if( type->CanCastSpell ) { - CLprintf(file," 'can-cast-spell '( "); - for (i=0;i<SpellTypeCount;++i) { + if (type->CanCastSpell) { + CLprintf(file, " 'can-cast-spell '( "); + for (i = 0; i < SpellTypeCount; ++i) { if (type->CanCastSpell[i]) { - CLprintf(file,"%s ",SpellTypeTable[i].IdentName); + CLprintf(file, "%s ", SpellTypeTable[i].IdentName); } } - CLprintf(file,")\n"); + CLprintf(file, ")\n"); } - if( type->MustBuildOnTop ) { - CLprintf(file," 'must-build-on-top '%s\n",type->MustBuildOnTop->Ident); + if (type->MustBuildOnTop) { + CLprintf(file, " 'must-build-on-top '%s\n", type->MustBuildOnTop->Ident); } - if( type->CanHarvest ) { - CLprintf(file," 'can-harvest\n"); + if (type->CanHarvest) { + CLprintf(file, " 'can-harvest\n"); } - if( type->Vanishes ) { - CLprintf(file," 'vanishes\n"); + if (type->Vanishes) { + CLprintf(file, " 'vanishes\n"); } - if( type->Hero ) { - CLprintf(file," 'hero\n"); + if (type->Hero) { + CLprintf(file, " 'hero\n"); } - if( type->Volatile ) { - CLprintf(file," 'volatile\n"); + if (type->Volatile) { + CLprintf(file, " 'volatile\n"); } - if( type->IsUndead ) { - CLprintf(file," 'isundead\n"); + if (type->IsUndead) { + CLprintf(file, " 'isundead\n"); } - if( type->Organic ) { - CLprintf(file," 'organic\n"); + if (type->Organic) { + CLprintf(file, " 'organic\n"); } - if( type->SelectableByRectangle ) { - CLprintf(file," 'selectable-by-rectangle\n"); + if (type->SelectableByRectangle) { + CLprintf(file, " 'selectable-by-rectangle\n"); } - if( type->Teleporter ) { - CLprintf(file," 'teleporter\n"); + if (type->Teleporter) { + CLprintf(file, " 'teleporter\n"); } #ifdef NEW_UI - CLprintf(file," 'add-buttons '"); - lprin1CL(type->AddButtonsHook,file); - CLprintf(file,"\n"); + CLprintf(file, " 'add-buttons '"); + lprin1CL(type->AddButtonsHook, file); + CLprintf(file, "\n"); #endif - CLprintf(file," 'sounds '("); - if( type->Sound.Selected.Name ) { - CLprintf(file,"\n selected \"%s\"",type->Sound.Selected.Name); + CLprintf(file, " 'sounds '("); + if (type->Sound.Selected.Name) { + CLprintf(file, "\n selected \"%s\"", type->Sound.Selected.Name); } - if( type->Sound.Acknowledgement.Name ) { - CLprintf(file,"\n acknowledge \"%s\"", - type->Sound.Acknowledgement.Name); + if (type->Sound.Acknowledgement.Name) { + CLprintf(file, "\n acknowledge \"%s\"", + type->Sound.Acknowledgement.Name); } - if( type->Sound.Ready.Name ) { - CLprintf(file,"\n ready \"%s\"",type->Sound.Ready.Name); + if (type->Sound.Ready.Name) { + CLprintf(file, "\n ready \"%s\"", type->Sound.Ready.Name); } - if( type->Sound.Help.Name ) { - CLprintf(file,"\n help \"%s\"",type->Sound.Help.Name); + if (type->Sound.Help.Name) { + CLprintf(file, "\n help \"%s\"", type->Sound.Help.Name); } - if( type->Sound.Dead.Name ) { - CLprintf(file,"\n dead \"%s\"",type->Sound.Dead.Name); + if (type->Sound.Dead.Name) { + CLprintf(file, "\n dead \"%s\"", type->Sound.Dead.Name); } // FIXME: Attack should be removed! - if( type->Weapon.Attack.Name ) { - CLprintf(file,"\n attack \"%s\"",type->Weapon.Attack.Name); + if (type->Weapon.Attack.Name) { + CLprintf(file, "\n attack \"%s\"", type->Weapon.Attack.Name); } - CLprintf(file,")"); - CLprintf(file,")\n\n"); + CLprintf(file, ")"); + CLprintf(file, ")\n\n"); } /** @@ -1077,34 +1091,34 @@ local void SaveUnitType(CLFile* file,const UnitType* type,int all) ** @param file Output file. */ local void SaveUnitStats(const UnitStats* stats,const char* ident,int plynr, - CLFile* file) + CLFile* file) { int j; - DebugCheck(plynr>=PlayerMax); - CLprintf(file,"(define-unit-stats '%s %d\n ",ident,plynr); - CLprintf(file,"'level %d ",stats->Level); - CLprintf(file,"'speed %d ",stats->Speed); - CLprintf(file,"'attack-range %d ",stats->AttackRange); - CLprintf(file,"'sight-range %d\n ",stats->SightRange); - CLprintf(file,"'armor %d ",stats->Armor); - CLprintf(file,"'basic-damage %d ",stats->BasicDamage); - CLprintf(file,"'piercing-damage %d ",stats->PiercingDamage); - CLprintf(file,"'hit-points %d\n ",stats->HitPoints); - CLprintf(file," 'regeneration-rate %d\n",stats->RegenerationRate); - CLprintf(file,"'costs '("); - for( j=0; j<MaxCosts; ++j ) { - if( j ) { -// if( j==MaxCosts/2 ) { -// fputs("\n ",file); + DebugCheck(plynr >= PlayerMax); + CLprintf(file, "(define-unit-stats '%s %d\n ", ident, plynr); + CLprintf(file, "'level %d ", stats->Level); + CLprintf(file, "'speed %d ", stats->Speed); + CLprintf(file, "'attack-range %d ", stats->AttackRange); + CLprintf(file, "'sight-range %d\n ", stats->SightRange); + CLprintf(file, "'armor %d ", stats->Armor); + CLprintf(file, "'basic-damage %d ", stats->BasicDamage); + CLprintf(file, "'piercing-damage %d ", stats->PiercingDamage); + CLprintf(file, "'hit-points %d\n ", stats->HitPoints); + CLprintf(file, " 'regeneration-rate %d\n", stats->RegenerationRate); + CLprintf(file, "'costs '("); + for (j = 0; j < MaxCosts; ++j) { + if (j) { +// if (j == MaxCosts / 2) { +// fputs("\n ", file); // } else { - CLprintf(file," "); + CLprintf(file, " "); // } } - CLprintf(file,"%s %d",DefaultResourceNames[j],stats->Costs[j]); + CLprintf(file, "%s %d", DefaultResourceNames[j], stats->Costs[j]); } - CLprintf(file,") )\n"); + CLprintf(file, ") )\n"); } /** @@ -1115,12 +1129,13 @@ local void SaveUnitStats(const UnitStats* stats,const char* ident,int plynr, global void SaveUnitTypeDefs(CLFile* file) { int i; - CLprintf(file,"\n;;; Declare all unit types in advance.\n"); + + CLprintf(file, "\n;;; Declare all unit types in advance.\n"); // Define all types in advance to avoid undefined unit problems. - for ( i=0; i<NumUnitTypes; ++i ) { - CLprintf(file,"(define-unit-type '%s)\n",UnitTypes[i]->Ident); + for (i = 0; i < NumUnitTypes; ++i) { + CLprintf(file, "(define-unit-type '%s)\n", UnitTypes[i]->Ident); } - CLprintf(file,"\n"); + CLprintf(file, "\n"); } /** @@ -1132,41 +1147,41 @@ global void SaveUnitTypes(CLFile* file) { int i; int j; - char **sp; + char** sp; - CLprintf(file,"\n;;; -----------------------------------------\n"); - CLprintf(file,";;; MODULE: unittypes $Id$\n\n"); + CLprintf(file, "\n;;; -----------------------------------------\n"); + CLprintf(file, ";;; MODULE: unittypes $Id$\n\n"); // Original number to internal unit-type name. - i=CLprintf(file,"(define-unittype-wc-names"); - for( sp=UnitTypeWcNames; *sp; ++sp ) { - if( i+strlen(*sp)>79 ) { - i=CLprintf(file,"\n "); + i = CLprintf(file, "(define-unittype-wc-names"); + for (sp = UnitTypeWcNames; *sp; ++sp) { + if (i + strlen(*sp) > 79) { + i = CLprintf(file, "\n "); } - i+=CLprintf(file," '%s",*sp); + i += CLprintf(file, " '%s", *sp); } - CLprintf(file,")\n"); + CLprintf(file, ")\n"); // Save all animations. - for( i=0; i<NumUnitTypes; ++i ) { - SaveAnimations(UnitTypes[i],file); + for (i = 0; i < NumUnitTypes; ++i) { + SaveAnimations(UnitTypes[i], file); } // Save all types - for( i=0; i<NumUnitTypes; ++i ) { - CLprintf(file,"\n"); - SaveUnitType(file,UnitTypes[i],0); + for (i = 0; i < NumUnitTypes; ++i) { + CLprintf(file, "\n"); + SaveUnitType(file, UnitTypes[i], 0); } // Save all stats - for( i=0; i<NumUnitTypes; ++i ) { - CLprintf(file,"\n"); - for( j=0; j<PlayerMax; ++j ) { - SaveUnitStats(&UnitTypes[i]->Stats[j],UnitTypes[i]->Ident,j,file); + for (i = 0; i < NumUnitTypes; ++i) { + CLprintf(file, "\n"); + for (j = 0; j < PlayerMax; ++j) { + SaveUnitStats(&UnitTypes[i]->Stats[j], UnitTypes[i]->Ident, j, file); } } } @@ -1181,17 +1196,17 @@ global UnitType* UnitTypeByIdent(const char* ident) { UnitType* const* type; - type=(UnitType* const*)hash_find(UnitTypeHash,ident); - if( type ) { + type = (UnitType* const*)hash_find(UnitTypeHash, ident); + if (type) { return *type; } - IfDebug( - if( !NoWarningUnitType ) { - DebugLevel0Fn("Name `%s' not found\n" _C_ ident); - DebugCheck(1); - } - ); +#ifdef DEBUG + if (!NoWarningUnitType) { + DebugLevel0Fn("Name `%s' not found\n" _C_ ident); + DebugCheck(1); + } +#endif return NULL; } @@ -1218,19 +1233,19 @@ global UnitType* NewUnitTypeSlot(char* ident) { UnitType* type; - type=malloc(sizeof(UnitType)); - if( !type ) { - fprintf(stderr,"Out of memory\n"); + type = malloc(sizeof(UnitType)); + if (!type) { + fprintf(stderr, "Out of memory\n"); ExitFatal(-1); } - memset(type,0,sizeof(UnitType)); - type->Type=NumUnitTypes; - type->Ident=ident; - UnitTypes[NumUnitTypes++]=type; + memset(type, 0, sizeof(UnitType)); + type->Type = NumUnitTypes; + type->Ident = ident; + UnitTypes[NumUnitTypes++] = type; // // Rehash. // - *(UnitType**)hash_add(UnitTypeHash,type->Ident)=type; + *(UnitType**)hash_add(UnitTypeHash, type->Ident) = type; return type; } @@ -1245,17 +1260,17 @@ global UnitType* NewUnitTypeSlot(char* ident) ** @todo Do screen position caculation in high level. ** Better way to handle in x mirrored sprites. */ -global void DrawUnitType(const UnitType* type,int frame,int x,int y) +global void DrawUnitType(const UnitType* type, int frame, int x, int y) { // FIXME: move this calculation to high level. - x-=(type->Width-type->TileWidth*TileSizeX)/2; - y-=(type->Height-type->TileHeight*TileSizeY)/2; + x -= (type->Width - type->TileWidth * TileSizeX) / 2; + y -= (type->Height - type->TileHeight * TileSizeY) / 2; // FIXME: This is a hack for mirrored sprites - if( frame<0 ) { - VideoDrawClipX(type->Sprite,-frame,x,y); + if (frame < 0) { + VideoDrawClipX(type->Sprite, -frame, x, y); } else { - VideoDrawClip(type->Sprite,frame,x,y); + VideoDrawClip(type->Sprite, frame, x, y); } } @@ -1266,16 +1281,16 @@ global void InitUnitTypes(int reset_player_stats) { int type; - for( type=0; type<NumUnitTypes; ++type ) { + for (type = 0; type < NumUnitTypes; ++type) { // // Initialize: // - DebugCheck( UnitTypes[type]->Type!=type ); + DebugCheck(UnitTypes[type]->Type != type); // // Add idents to hash. // - *(UnitType**)hash_add(UnitTypeHash,UnitTypes[type]->Ident) - =UnitTypes[type]; + *(UnitType**)hash_add(UnitTypeHash, UnitTypes[type]->Ident) = + UnitTypes[type]; } // LUDO : called after game is loaded -> don't reset stats ! @@ -1284,8 +1299,8 @@ global void InitUnitTypes(int reset_player_stats) // // Setup hardcoded unit types. FIXME: should be moved to some configs. // - UnitTypeHumanWall=UnitTypeByIdent("unit-human-wall"); - UnitTypeOrcWall=UnitTypeByIdent("unit-orc-wall"); + UnitTypeHumanWall = UnitTypeByIdent("unit-human-wall"); + UnitTypeOrcWall = UnitTypeByIdent("unit-orc-wall"); } /** @@ -1300,27 +1315,30 @@ global void LoadUnitTypes(void) int res; ResourceInfo* resinfo; - for( i=0; i<NumUnitTypes; ++i ) { - type=UnitTypes[i]; - if( (file=type->ShadowFile) ) { - file=strcat(strcpy(buf,"graphics/"),file); - ShowLoadProgress("\tUnit `%s'\n",file); - type->ShadowSprite=LoadSprite(file,type->ShadowWidth,type->ShadowHeight); + for (i = 0; i < NumUnitTypes; ++i) { + type = UnitTypes[i]; + if ((file = type->ShadowFile)) { + file = strcat(strcpy(buf, "graphics/"), file); + ShowLoadProgress("\tUnit `%s'\n", file); + type->ShadowSprite = LoadSprite(file, type->ShadowWidth, + type->ShadowHeight); } // Load empty/loaded graphics if (type->Harvester) { - for (res=0;res<MaxCosts;res++) { - if ((resinfo=type->ResInfo[res])) { - if ((file=resinfo->FileWhenLoaded)) { - file=strcat(strcpy(buf,"graphics/"),file); - ShowLoadProgress("\tUnit `%s'\n",file); - resinfo->SpriteWhenLoaded=LoadSprite(file,type->Width,type->Height); + for (res = 0; res < MaxCosts; ++res) { + if ((resinfo = type->ResInfo[res])) { + if ((file = resinfo->FileWhenLoaded)) { + file = strcat(strcpy(buf, "graphics/"), file); + ShowLoadProgress("\tUnit `%s'\n", file); + resinfo->SpriteWhenLoaded = LoadSprite(file, type->Width, + type->Height); } - if ((file=resinfo->FileWhenEmpty)) { - file=strcat(strcpy(buf,"graphics/"),file); - ShowLoadProgress("\tUnit `%s'\n",file); - resinfo->SpriteWhenEmpty=LoadSprite(file,type->Width,type->Height); + if ((file = resinfo->FileWhenEmpty)) { + file = strcat(strcpy(buf, "graphics/"), file); + ShowLoadProgress("\tUnit `%s'\n", file); + resinfo->SpriteWhenEmpty = LoadSprite(file, type->Width, + type->Height); } } } @@ -1329,7 +1347,7 @@ global void LoadUnitTypes(void) // // Unit-type uses the same sprite as an other. // - if( type->SameSprite ) { + if (type->SameSprite) { continue; } @@ -1337,57 +1355,57 @@ global void LoadUnitTypes(void) // FIXME: must handle terrain different! // - file=type->File[TheMap.Terrain]; - if( !file ) { // default one - file=type->File[0]; + file = type->File[TheMap.Terrain]; + if (!file) { // default one + file = type->File[0]; } - if( file ) { + if (file) { char* buf; - buf=alloca(strlen(file)+9+1); - file=strcat(strcpy(buf,"graphics/"),file); - ShowLoadProgress("\tUnit `%s'\n",file); - type->Sprite=LoadSprite(file,type->Width,type->Height); + buf = alloca(strlen(file) + 9 + 1); + file = strcat(strcpy(buf, "graphics/"), file); + ShowLoadProgress("\tUnit `%s'\n", file); + type->Sprite = LoadSprite(file, type->Width, type->Height); } } - for( i=0; i<NumUnitTypes; ++i ) { - type=UnitTypes[i]; + for (i = 0; i<NumUnitTypes; ++i) { + type = UnitTypes[i]; // // Unit-type uses the same sprite as an other. // - if( type->SameSprite ) { + if (type->SameSprite) { const UnitType* unittype; - unittype=UnitTypeByIdent(type->SameSprite); - if( !unittype ) { + unittype = UnitTypeByIdent(type->SameSprite); + if (!unittype) { PrintFunction(); - fprintf(stdout,"Unit-type %s not found\n" ,type->SameSprite); + fprintf(stdout, "Unit-type %s not found\n", type->SameSprite); ExitFatal(-1); } - type->Sprite=unittype->Sprite; + type->Sprite = unittype->Sprite; } // // Lookup icons. // - type->Icon.Icon=IconByIdent(type->Icon.Name); + type->Icon.Icon = IconByIdent(type->Icon.Name); if (!type->Icon.Icon) { - printf("Can't find icon %s\n",type->Icon.Name); + printf("Can't find icon %s\n", type->Icon.Name); ExitFatal(-1); } // // Lookup missiles. // - type->Missile.Missile=MissileTypeByIdent(type->Missile.Name); - if( type->Explosion.Name ) { - type->Explosion.Missile=MissileTypeByIdent(type->Explosion.Name); + type->Missile.Missile = MissileTypeByIdent(type->Missile.Name); + if (type->Explosion.Name) { + type->Explosion.Missile = MissileTypeByIdent(type->Explosion.Name); } // // Lookup corpse. // - if( type->CorpseName ) { - type->CorpseType=UnitTypeByIdent(type->CorpseName); + if (type->CorpseName) { + type->CorpseType = UnitTypeByIdent(type->CorpseName); } // FIXME: should i copy the animations of same graphics? @@ -1411,41 +1429,40 @@ global void CleanUnitTypes(void) // // Mapping the original unit-type numbers in puds to our internal strings // - if( (ptr=(void**)UnitTypeWcNames) ) { // Free all old names - while( *ptr ) { + if ((ptr = (void**)UnitTypeWcNames)) { // Free all old names + while (*ptr) { free(*ptr++); } free(UnitTypeWcNames); - UnitTypeWcNames=NULL; + UnitTypeWcNames = NULL; } // FIXME: scheme contains references on this structure. // Clean all animations. - for( i=0; i<NumUnitTypes; ++i ) - { - type=UnitTypes[i]; + for (i = 0; i < NumUnitTypes; ++i) { + type = UnitTypes[i]; - if( !(anims=type->Animations) ) { // Must be handled? + if (!(anims = type->Animations)) { // Must be handled? continue; } - for( j=i; j<NumUnitTypes; ++j ) { // Remove all uses. - if( anims==UnitTypes[j]->Animations ) { - UnitTypes[j]->Animations=NULL; + for (j = i; j < NumUnitTypes; ++j) { // Remove all uses. + if (anims == UnitTypes[j]->Animations) { + UnitTypes[j]->Animations = NULL; } } - type->Animations=NULL; - if( anims->Still ) { + type->Animations = NULL; + if (anims->Still) { free(anims->Still); } - if( anims->Move ) { + if (anims->Move) { free(anims->Move); } - if( anims->Attack ) { + if (anims->Attack) { free(anims->Attack); } - if( anims->Die ) { + if (anims->Die) { free(anims->Die); } free(anims); @@ -1453,44 +1470,44 @@ global void CleanUnitTypes(void) // Clean all unit-types - for( i=0;i<NumUnitTypes;++i ) { - type=UnitTypes[i]; - hash_del(UnitTypeHash,type->Ident); + for (i = 0; i < NumUnitTypes; ++i) { + type = UnitTypes[i]; + hash_del(UnitTypeHash, type->Ident); - DebugCheck( !type->Ident ); + DebugCheck(!type->Ident); free(type->Ident); - DebugCheck( !type->Name ); + DebugCheck(!type->Name); free(type->Name); - if( type->SameSprite ) { + if (type->SameSprite) { free(type->SameSprite); } - if( type->File[0] ) { + if (type->File[0]) { free(type->File[0]); } - if( type->File[1] ) { + if (type->File[1]) { free(type->File[1]); } - if( type->File[2] ) { + if (type->File[2]) { free(type->File[2]); } - if( type->File[3] ) { + if (type->File[3]) { free(type->File[3]); } - if( type->Icon.Name ) { + if (type->Icon.Name) { free(type->Icon.Name); } - if( type->Missile.Name ) { + if (type->Missile.Name) { free(type->Missile.Name); } - if( type->Explosion.Name ) { + if (type->Explosion.Name) { free(type->Explosion.Name); } - if( type->CorpseName ) { + if (type->CorpseName) { free(type->CorpseName); } - for (res=0;res<MaxCosts;res++) { + for (res = 0; res < MaxCosts; ++res) { if (type->ResInfo[res]) { if (type->ResInfo[res]->SpriteWhenLoaded) { free (type->ResInfo[res]->SpriteWhenLoaded); @@ -1511,43 +1528,43 @@ global void CleanUnitTypes(void) // // FIXME: Sounds can't be freed, they still stuck in sound hash. // - if( type->Sound.Selected.Name ) { + if (type->Sound.Selected.Name) { free(type->Sound.Selected.Name); } - if( type->Sound.Acknowledgement.Name ) { + if (type->Sound.Acknowledgement.Name) { free(type->Sound.Acknowledgement.Name); } - if( type->Sound.Ready.Name ) { + if (type->Sound.Ready.Name) { free(type->Sound.Ready.Name); } - if( type->Sound.Help.Name ) { + if (type->Sound.Help.Name) { free(type->Sound.Help.Name); } - if( type->Sound.Dead.Name ) { + if (type->Sound.Dead.Name) { free(type->Sound.Dead.Name); } - if( type->Weapon.Attack.Name ) { + if (type->Weapon.Attack.Name) { free(type->Weapon.Attack.Name); } - if( !type->SameSprite ) { // our own graphics + if (!type->SameSprite) { // our own graphics VideoSaveFree(type->Sprite); } #ifdef USE_OPENGL - for( i=0; i<PlayerMax; ++i ) { + for (i = 0; i < PlayerMax; ++i) { VideoSaveFree(type->PlayerColorSprite[i]); } #endif free(UnitTypes[i]); - UnitTypes[i]=0; + UnitTypes[i] = 0; } - NumUnitTypes=0; + NumUnitTypes = 0; // // Clean hardcoded unit types. // - UnitTypeHumanWall=NULL; - UnitTypeOrcWall=NULL; + UnitTypeHumanWall = NULL; + UnitTypeOrcWall = NULL; } //@}