From e943c8a434337b59d44589aa36db6794f623746a Mon Sep 17 00:00:00 2001 From: jsalmon3 <> Date: Thu, 2 Oct 2003 15:15:06 +0000 Subject: [PATCH] Cleanup --- src/unit/depend.cpp | 309 +++++----- src/unit/script_unit.cpp | 955 +++++++++++++++--------------- src/unit/script_unittype.cpp | 1063 +++++++++++++++++----------------- 3 files changed, 1167 insertions(+), 1160 deletions(-) diff --git a/src/unit/depend.cpp b/src/unit/depend.cpp index c7d13b2fe..c846385b4 100644 --- a/src/unit/depend.cpp +++ b/src/unit/depend.cpp @@ -49,7 +49,7 @@ ----------------------------------------------------------------------------*/ /// All dependencies hash -local DependRule* DependHash[101]; +local DependRule* DependHash[101]; /*---------------------------------------------------------------------------- -- Functions @@ -63,8 +63,8 @@ local DependRule* DependHash[101]; ** @param count Amount of the required needed. ** @param or_flag Start of or rule. */ -global void AddDependency(const char* target,const char* required,int count - ,int or_flag) +global void AddDependency(const char* target, const char* required, int count, + int or_flag) { DependRule rule; DependRule* node; @@ -74,106 +74,105 @@ global void AddDependency(const char* target,const char* required,int count // // Setup structure. // - if ( !strncmp( target, "unit-", 5 ) ) { + if (!strncmp(target, "unit-", 5)) { // target string refers to unit-xxx rule.Type = DependRuleUnitType; - rule.Kind.UnitType = UnitTypeByIdent( target ); - } else if ( !strncmp( target, "upgrade-", 8 ) ) { + rule.Kind.UnitType = UnitTypeByIdent(target); + } else if (!strncmp(target, "upgrade-", 8)) { // target string refers to upgrade-XXX rule.Type = DependRuleUpgrade; - rule.Kind.Upgrade = UpgradeByIdent( target ); + rule.Kind.Upgrade = UpgradeByIdent(target); } else { - DebugLevel0Fn("dependency target `%s' should be unit-type or upgrade\n" - _C_ target); + DebugLevel0Fn("dependency target `%s' should be unit-type or upgrade\n" _C_ + target); return; } - hash=(int)(long)rule.Kind.UnitType%(sizeof(DependHash)/sizeof(*DependHash)); + hash = (int)(long)rule.Kind.UnitType % (sizeof(DependHash) / sizeof(*DependHash)); // // Find correct hash slot. // - if( (node=DependHash[hash]) ) { // find correct entry - while( node->Type!=rule.Type - || node->Kind.Upgrade!=rule.Kind.Upgrade ) { - if( !node->Next ) { // end of list - temp=malloc(sizeof(DependRule)); - temp->Next=NULL; - temp->Rule=NULL; - temp->Type=rule.Type; - temp->Kind=rule.Kind; - node->Next=temp; - node=temp; + if ((node = DependHash[hash])) { // find correct entry + while (node->Type != rule.Type || + node->Kind.Upgrade != rule.Kind.Upgrade) { + if (!node->Next) { // end of list + temp = malloc(sizeof(DependRule)); + temp->Next = NULL; + temp->Rule = NULL; + temp->Type = rule.Type; + temp->Kind = rule.Kind; + node->Next = temp; + node = temp; break; } node=node->Next; } } else { // create new slow - node=malloc(sizeof(DependRule)); - node->Next=NULL; - node->Rule=NULL; - node->Type=rule.Type; - node->Kind=rule.Kind; - DependHash[hash]=node; + node = malloc(sizeof(DependRule)); + node->Next = NULL; + node->Rule = NULL; + node->Type = rule.Type; + node->Kind = rule.Kind; + DependHash[hash] = node; } // // Adjust count. // - if ( count < 0 || count > 255 ) { + if (count < 0 || count > 255) { DebugLevel0Fn("wrong count `%d' range 0 .. 255\n" _C_ count); count = 255; } - temp=malloc(sizeof(DependRule)); - temp->Rule=NULL; - temp->Next=NULL; - temp->Count=count; + temp = malloc(sizeof(DependRule)); + temp->Rule = NULL; + temp->Next = NULL; + temp->Count = count; // // Setup structure. // - if ( !strncmp( required, "unit-", 5 ) ) { + if (!strncmp(required, "unit-", 5)) { // required string refers to unit-xxx temp->Type = DependRuleUnitType; - temp->Kind.UnitType = UnitTypeByIdent( required ); - } else if ( !strncmp( required, "upgrade-", 8 ) ) { + temp->Kind.UnitType = UnitTypeByIdent(required); + } else if (!strncmp(required, "upgrade-", 8)) { // required string refers to upgrade-XXX temp->Type = DependRuleUpgrade; - temp->Kind.Upgrade = UpgradeByIdent( required ); + temp->Kind.Upgrade = UpgradeByIdent(required); } else { - DebugLevel0Fn( - "dependency required `%s' should be unit-type or upgrade\n" - _C_ required); + DebugLevel0Fn("dependency required `%s' should be unit-type or upgrade\n" _C_ + required); free(temp); return; } - if( or_flag ) { + if (or_flag) { // move rule to temp->next - temp->Next=node->Rule; // insert rule - node->Rule=temp; + temp->Next = node->Rule; // insert rule + node->Rule = temp; } else { // move rule to temp->rule - temp->Rule=node->Rule; // insert rule + temp->Rule = node->Rule; // insert rule // also Link temp to old "or" list if (node->Rule) { - temp->Next=node->Rule->Next; + temp->Next = node->Rule->Next; } - node->Rule=temp; + node->Rule = temp; } #ifdef neverDEBUG printf("New rules are :"); - node=node->Rule; - while(node){ - temp=node; - while(temp){ - printf("temp->Kind.UnitType=%p ",temp->Kind.UnitType); - temp=temp->Rule; - } - node=node->Next; - printf("\n or ... "); + node = node->Rule; + while (node) { + temp = node; + while (temp){ + printf("temp->Kind.UnitType=%p ", temp->Kind.UnitType); + temp = temp->Rule; + } + node = node->Next; + printf("\n or ... "); } printf("\n"); #endif @@ -187,7 +186,7 @@ global void AddDependency(const char* target,const char* required,int count ** ** @return True if available, false otherwise. */ -global int CheckDependByIdent(const Player* player,const char* target) +global int CheckDependByIdent(const Player* player, const char* target) { DependRule rule; const DependRule* node; @@ -197,17 +196,17 @@ global int CheckDependByIdent(const Player* player,const char* target) // // first have to check, if target is allowed itself // - if ( !strncmp( target, "unit-", 5 ) ) { + if (!strncmp(target, "unit-", 5)) { // target string refers to unit-XXX - rule.Kind.UnitType = UnitTypeByIdent( target ); - if ( UnitIdAllowed( player, rule.Kind.UnitType->Type ) != 'A' ) { + rule.Kind.UnitType = UnitTypeByIdent(target); + if (UnitIdAllowed(player, rule.Kind.UnitType->Type) != 'A') { return 0; } rule.Type = DependRuleUnitType; - } else if ( !strncmp( target, "upgrade-", 8 ) ) { + } else if (!strncmp(target, "upgrade-", 8)) { // target string refers to upgrade-XXX - rule.Kind.Upgrade = UpgradeByIdent( target ); - if( UpgradeIdAllowed( player, rule.Kind.Upgrade-Upgrades ) != 'A' ) { + rule.Kind.Upgrade = UpgradeByIdent(target); + if (UpgradeIdAllowed(player, rule.Kind.Upgrade-Upgrades) != 'A') { return 0; } rule.Type = DependRuleUpgrade; @@ -219,15 +218,15 @@ global int CheckDependByIdent(const Player* player,const char* target) // // Find rule // - i=(int)(long)rule.Kind.UnitType%(sizeof(DependHash)/sizeof(*DependHash)); + i = (int)(long)rule.Kind.UnitType % (sizeof(DependHash) / sizeof(*DependHash)); - if( (node=DependHash[i]) ) { // find correct entry - while( node->Type!=rule.Type - || node->Kind.Upgrade!=rule.Kind.Upgrade ) { - if( !node->Next ) { // end of list + if ((node = DependHash[i])) { // find correct entry + while (node->Type != rule.Type || + node->Kind.Upgrade != rule.Kind.Upgrade) { + if (!node->Next) { // end of list return 1; } - node=node->Next; + node = node->Next; } } else { return 1; @@ -236,31 +235,31 @@ global int CheckDependByIdent(const Player* player,const char* target) // // Prove the rules // - node=node->Rule; + node = node->Rule; - while( node ) { - temp=node; - while( temp ) { - switch( temp->Type ) { - case DependRuleUnitType: - i=HaveUnitTypeByType( player, temp->Kind.UnitType ); - if ( temp->Count ? i<temp->Count : i ) { - goto try_or; - } - break; - case DependRuleUpgrade: - i=UpgradeIdAllowed( player, temp->Kind.Upgrade-Upgrades) != 'R'; - if ( temp->Count ? i : !i ) { - goto try_or; - } - break; + while (node) { + temp = node; + while (temp) { + switch (temp->Type) { + case DependRuleUnitType: + i = HaveUnitTypeByType(player, temp->Kind.UnitType); + if (temp->Count ? i < temp->Count : i) { + goto try_or; + } + break; + case DependRuleUpgrade: + i = UpgradeIdAllowed(player, temp->Kind.Upgrade-Upgrades) != 'R'; + if (temp->Count ? i : !i) { + goto try_or; + } + break; } - temp=temp->Rule; + temp = temp->Rule; } return 1; // all rules matches. try_or: - node=node->Next; + node = node->Next; } return 0; // no rule matches @@ -269,7 +268,9 @@ try_or: /** ** Initialize unit and upgrade dependencies. */ -global void InitDependencies(void){} +global void InitDependencies(void) +{ +} /** ** Save state of the dependencies to file. @@ -288,48 +289,48 @@ global void SaveDependencies(CLFile* file) // Save all dependencies - for( u=0; u<sizeof(DependHash)/sizeof(*DependHash); ++u ) { - node=DependHash[u]; - while( node ) { // all hash links - CLprintf(file,"(define-dependency '"); - switch( node->Type ) { + for (u = 0; u < sizeof(DependHash) / sizeof(*DependHash); ++u) { + node = DependHash[u]; + while (node) { // all hash links + CLprintf(file, "(define-dependency '"); + switch (node->Type) { case DependRuleUnitType: - CLprintf(file,"%s",node->Kind.UnitType->Ident); + CLprintf(file, "%s", node->Kind.UnitType->Ident); break; case DependRuleUpgrade: - CLprintf(file,"%s",node->Kind.Upgrade->Ident); + CLprintf(file, "%s", node->Kind.Upgrade->Ident); break; } // All or cases - CLprintf(file,"\n '("); - rule=node->Rule; - for( ;; ) { - temp=rule; - while( temp ) { - switch( temp->Type ) { - case DependRuleUnitType: - CLprintf(file,"%s",temp->Kind.UnitType->Ident); - break; - case DependRuleUpgrade: - CLprintf(file,"%s",temp->Kind.Upgrade->Ident); - break; + CLprintf(file, "\n '("); + rule = node->Rule; + for (;;) { + temp = rule; + while (temp) { + switch (temp->Type) { + case DependRuleUnitType: + CLprintf(file, "%s", temp->Kind.UnitType->Ident); + break; + case DependRuleUpgrade: + CLprintf(file, "%s", temp->Kind.Upgrade->Ident); + break; } - temp=temp->Rule; - if( temp ) { + temp = temp->Rule; + if (temp) { CLprintf(file," "); } } - CLprintf(file,")"); - if( !(rule=rule->Next) ) { + CLprintf(file, ")"); + if (!(rule = rule->Next)) { break; } - CLprintf(file,"\n 'or '( "); + CLprintf(file, "\n 'or '( "); } - CLprintf(file,")\n"); + CLprintf(file, ")\n"); - node=node->Next; + node = node->Next; } } } @@ -347,30 +348,30 @@ global void CleanDependencies(void) // Free all dependencies - for( u=0; u<sizeof(DependHash)/sizeof(*DependHash); ++u ) { - node=DependHash[u]; - while( node ) { // all hash links + for (u = 0; u < sizeof(DependHash) / sizeof(*DependHash); ++u) { + node = DependHash[u]; + while (node) { // all hash links // All or cases - rule=node->Rule; - while( rule ) { - if( rule ) { - temp=rule->Rule; - while( temp ) { - next=temp; - temp=temp->Rule; + rule = node->Rule; + while (rule) { + if (rule) { + temp = rule->Rule; + while (temp) { + next = temp; + temp = temp->Rule; free(next); } } - temp=rule; - rule=rule->Next; + temp = rule; + rule = rule->Next; free(temp); } - temp=node; - node=node->Next; + temp = node; + node = node->Next; free(temp); } - DependHash[u]=NULL; + DependHash[u] = NULL; } } @@ -394,40 +395,40 @@ local SCM CclDefineDependency(SCM list) SCM temp; int or_flag; - value=gh_car(list); - list=gh_cdr(list); - target=gh_scm2newstr(value,NULL); + value = gh_car(list); + list = gh_cdr(list); + target = gh_scm2newstr(value,NULL); // // All or rules. // - or_flag=0; - while( !gh_null_p(list) ) { - temp=gh_car(list); - list=gh_cdr(list); + or_flag = 0; + while (!gh_null_p(list)) { + temp = gh_car(list); + list = gh_cdr(list); - while( !gh_null_p(temp) ) { - value=gh_car(temp); - temp=gh_cdr(temp); - required=gh_scm2newstr(value,NULL); - count=1; - if( !gh_null_p(temp) && gh_exact_p(temp) ) { - value=gh_car(temp); - count=gh_scm2int(value); - temp=gh_cdr(temp); + while (!gh_null_p(temp)) { + value = gh_car(temp); + temp = gh_cdr(temp); + required = gh_scm2newstr(value, NULL); + count = 1; + if (!gh_null_p(temp) && gh_exact_p(temp)) { + value = gh_car(temp); + count = gh_scm2int(value); + temp = gh_cdr(temp); } - AddDependency(target,required,count,or_flag); + AddDependency(target, required, count, or_flag); free(required); - or_flag=0; + or_flag = 0; } - if( !gh_null_p(list) ) { - if( !gh_eq_p(gh_car(list),gh_symbol2scm("or")) ) { - errl("not or symbol",gh_car(list)); + if (!gh_null_p(list)) { + if (!gh_eq_p(gh_car(list), gh_symbol2scm("or"))) { + errl("not or symbol", gh_car(list)); return SCM_UNSPECIFIED; } - or_flag=1; - list=gh_cdr(list); + or_flag = 1; + list = gh_cdr(list); } } free(target); @@ -468,9 +469,9 @@ local SCM CclCheckDependency(SCM target __attribute__((unused))) */ global void DependenciesCclRegister(void) { - gh_new_procedureN("define-dependency",CclDefineDependency); - gh_new_procedure1_0("get-dependency",CclGetDependency); - gh_new_procedure1_0("check-dependency",CclCheckDependency); + gh_new_procedureN("define-dependency", CclDefineDependency); + gh_new_procedure1_0("get-dependency", CclGetDependency); + gh_new_procedure1_0("check-dependency", CclCheckDependency); } //@} diff --git a/src/unit/script_unit.cpp b/src/unit/script_unit.cpp index 14d7d503a..6faf0996a 100644 --- a/src/unit/script_unit.cpp +++ b/src/unit/script_unit.cpp @@ -172,132 +172,132 @@ local void CclParseOrder(SCM list,Order* order) // // Parse the list: (still everything could be changed!) // - while( !gh_null_p(list) ) { - value=gh_car(list); - list=gh_cdr(list); - if( gh_eq_p(value,gh_symbol2scm("action-none")) ) { - order->Action=UnitActionNone; - } else if( gh_eq_p(value,gh_symbol2scm("action-still")) ) { - order->Action=UnitActionStill; - } else if( gh_eq_p(value,gh_symbol2scm("action-stand-ground")) ) { - order->Action=UnitActionStandGround; - } else if( gh_eq_p(value,gh_symbol2scm("action-follow")) ) { - order->Action=UnitActionFollow; - } else if( gh_eq_p(value,gh_symbol2scm("action-move")) ) { - order->Action=UnitActionMove; - } else if( gh_eq_p(value,gh_symbol2scm("action-attack")) ) { - order->Action=UnitActionAttack; - } else if( gh_eq_p(value,gh_symbol2scm("action-attack-ground")) ) { - order->Action=UnitActionAttackGround; - } else if( gh_eq_p(value,gh_symbol2scm("action-die")) ) { - order->Action=UnitActionDie; - } else if( gh_eq_p(value,gh_symbol2scm("action-spell-cast")) ) { - order->Action=UnitActionSpellCast; - } else if( gh_eq_p(value,gh_symbol2scm("action-train")) ) { - order->Action=UnitActionTrain; - } else if( gh_eq_p(value,gh_symbol2scm("action-upgrade-to")) ) { - order->Action=UnitActionUpgradeTo; - } else if( gh_eq_p(value,gh_symbol2scm("action-research")) ) { - order->Action=UnitActionResearch; - } else if( gh_eq_p(value,gh_symbol2scm("action-builded")) ) { - order->Action=UnitActionBuilded; - } else if( gh_eq_p(value,gh_symbol2scm("action-board")) ) { - order->Action=UnitActionBoard; - } else if( gh_eq_p(value,gh_symbol2scm("action-unload")) ) { - order->Action=UnitActionUnload; - } else if( gh_eq_p(value,gh_symbol2scm("action-patrol")) ) { - order->Action=UnitActionPatrol; - } else if( gh_eq_p(value,gh_symbol2scm("action-build")) ) { - order->Action=UnitActionBuild; - } else if( gh_eq_p(value,gh_symbol2scm("action-repair")) ) { - order->Action=UnitActionRepair; - } else if( gh_eq_p(value,gh_symbol2scm("action-resource")) ) { - order->Action=UnitActionResource; - } else if( gh_eq_p(value,gh_symbol2scm("action-return-goods")) ) { - order->Action=UnitActionReturnGoods; - } else if( gh_eq_p(value,gh_symbol2scm("action-demolish")) ) { - order->Action=UnitActionDemolish; + while (!gh_null_p(list)) { + value = gh_car(list); + list = gh_cdr(list); + if (gh_eq_p(value, gh_symbol2scm("action-none"))) { + order->Action = UnitActionNone; + } else if (gh_eq_p(value, gh_symbol2scm("action-still"))) { + order->Action = UnitActionStill; + } else if (gh_eq_p(value, gh_symbol2scm("action-stand-ground"))) { + order->Action = UnitActionStandGround; + } else if (gh_eq_p(value, gh_symbol2scm("action-follow"))) { + order->Action = UnitActionFollow; + } else if (gh_eq_p(value, gh_symbol2scm("action-move"))) { + order->Action = UnitActionMove; + } else if (gh_eq_p(value, gh_symbol2scm("action-attack"))) { + order->Action = UnitActionAttack; + } else if (gh_eq_p(value, gh_symbol2scm("action-attack-ground"))) { + order->Action = UnitActionAttackGround; + } else if (gh_eq_p(value, gh_symbol2scm("action-die"))) { + order->Action = UnitActionDie; + } else if (gh_eq_p(value, gh_symbol2scm("action-spell-cast"))) { + order->Action = UnitActionSpellCast; + } else if (gh_eq_p(value, gh_symbol2scm("action-train"))) { + order->Action = UnitActionTrain; + } else if (gh_eq_p(value, gh_symbol2scm("action-upgrade-to"))) { + order->Action = UnitActionUpgradeTo; + } else if (gh_eq_p(value, gh_symbol2scm("action-research"))) { + order->Action = UnitActionResearch; + } else if (gh_eq_p(value, gh_symbol2scm("action-builded"))) { + order->Action = UnitActionBuilded; + } else if (gh_eq_p(value, gh_symbol2scm("action-board"))) { + order->Action = UnitActionBoard; + } else if (gh_eq_p(value, gh_symbol2scm("action-unload"))) { + order->Action = UnitActionUnload; + } else if (gh_eq_p(value, gh_symbol2scm("action-patrol"))) { + order->Action = UnitActionPatrol; + } else if (gh_eq_p(value, gh_symbol2scm("action-build"))) { + order->Action = UnitActionBuild; + } else if (gh_eq_p(value, gh_symbol2scm("action-repair"))) { + order->Action = UnitActionRepair; + } else if (gh_eq_p(value, gh_symbol2scm("action-resource"))) { + order->Action = UnitActionResource; + } else if (gh_eq_p(value, gh_symbol2scm("action-return-goods"))) { + order->Action = UnitActionReturnGoods; + } else if (gh_eq_p(value, gh_symbol2scm("action-demolish"))) { + order->Action = UnitActionDemolish; - } else if( gh_eq_p(value,gh_symbol2scm("flags")) ) { - value=gh_car(list); - list=gh_cdr(list); - order->Flags=gh_scm2int(value); + } else if (gh_eq_p(value, gh_symbol2scm("flags"))) { + value = gh_car(list); + list = gh_cdr(list); + order->Flags = gh_scm2int(value); - } else if( gh_eq_p(value,gh_symbol2scm("range")) ) { - sublist=gh_car(list); - list=gh_cdr(list); - order->RangeX=gh_scm2int(gh_car(sublist)); - order->RangeY=gh_scm2int(gh_cadr(sublist)); + } else if (gh_eq_p(value, gh_symbol2scm("range"))) { + sublist = gh_car(list); + list = gh_cdr(list); + order->RangeX = gh_scm2int(gh_car(sublist)); + order->RangeY = gh_scm2int(gh_cadr(sublist)); - } else if( gh_eq_p(value,gh_symbol2scm("goal")) ) { + } else if (gh_eq_p(value, gh_symbol2scm("goal"))) { char* str; int slot; - value=gh_car(list); - list=gh_cdr(list); - str=gh_scm2newstr(value,NULL); + value = gh_car(list); + list = gh_cdr(list); + str = gh_scm2newstr(value,NULL); - slot=strtol(str+1,NULL,16); - order->Goal=UnitSlots[slot]; - if( !UnitSlots[slot] ) { + slot = strtol(str + 1, NULL, 16); + order->Goal = UnitSlots[slot]; + if (!UnitSlots[slot]) { DebugLevel0Fn("FIXME: Forward reference not supported\n"); } ++UnitSlots[slot]->Refs; free(str); - } else if( gh_eq_p(value,gh_symbol2scm("tile")) ) { - sublist=gh_car(list); - list=gh_cdr(list); - order->X=gh_scm2int(gh_car(sublist)); - order->Y=gh_scm2int(gh_cadr(sublist)); + } else if (gh_eq_p(value, gh_symbol2scm("tile"))) { + sublist = gh_car(list); + list = gh_cdr(list); + order->X = gh_scm2int(gh_car(sublist)); + order->Y = gh_scm2int(gh_cadr(sublist)); - } else if( gh_eq_p(value,gh_symbol2scm("type")) ) { + } else if (gh_eq_p(value, gh_symbol2scm("type"))) { char* str; - value=gh_car(list); - list=gh_cdr(list); - str=gh_scm2newstr(value,NULL); - order->Type=UnitTypeByIdent(str); + value = gh_car(list); + list = gh_cdr(list); + str = gh_scm2newstr(value,NULL); + order->Type = UnitTypeByIdent(str); free(str); - } else if( gh_eq_p(value,gh_symbol2scm("patrol")) ) { - sublist=gh_car(list); - list=gh_cdr(list); - order->Arg1=(void*)((gh_scm2int(gh_car(sublist))<<16)| - gh_scm2int(gh_cadr(sublist))); + } else if (gh_eq_p(value, gh_symbol2scm("patrol"))) { + sublist = gh_car(list); + list = gh_cdr(list); + order->Arg1 = (void*)((gh_scm2int(gh_car(sublist)) << 16) | + gh_scm2int(gh_cadr(sublist))); - } else if( gh_eq_p(value,gh_symbol2scm("spell")) ) { + } else if (gh_eq_p(value, gh_symbol2scm("spell"))) { char* str; - value=gh_car(list); - list=gh_cdr(list); - str=gh_scm2newstr(value,NULL); - order->Arg1=SpellTypeByIdent(str); + value = gh_car(list); + list = gh_cdr(list); + str = gh_scm2newstr(value, NULL); + order->Arg1 = SpellTypeByIdent(str); free(str); - } else if( gh_eq_p(value,gh_symbol2scm("upgrade")) ) { + } else if (gh_eq_p(value, gh_symbol2scm("upgrade"))) { char* str; - value=gh_car(list); - list=gh_cdr(list); - str=gh_scm2newstr(value,NULL); - order->Arg1=UpgradeByIdent(str); + value = gh_car(list); + list = gh_cdr(list); + str = gh_scm2newstr(value, NULL); + order->Arg1 = UpgradeByIdent(str); free(str); - } else if( gh_eq_p(value,gh_symbol2scm("mine")) ) { - sublist=gh_car(list); - list=gh_cdr(list); - order->Arg1=(void*)((gh_scm2int(gh_car(sublist))<<16)| - gh_scm2int(gh_cadr(sublist))); + } else if (gh_eq_p(value, gh_symbol2scm("mine"))) { + sublist = gh_car(list); + list = gh_cdr(list); + order->Arg1 = (void*)((gh_scm2int(gh_car(sublist)) << 16) | + gh_scm2int(gh_cadr(sublist))); - } else if( gh_eq_p(value,gh_symbol2scm("arg1")) ) { - value=gh_car(list); - list=gh_cdr(list); - order->Arg1 = (void * )gh_scm2int(value); + } else if (gh_eq_p(value, gh_symbol2scm("arg1"))) { + value = gh_car(list); + list = gh_cdr(list); + order->Arg1 = (void*)gh_scm2int(value); } else { // FIXME: this leaves a half initialized unit - errl("Unsupported tag",value); + errl("Unsupported tag", value); } } } @@ -308,15 +308,15 @@ local void CclParseOrder(SCM list,Order* order) ** @param unit Unit pointer which should get the orders. ** @param vector All options of the order. */ -local void CclParseOrders(Unit* unit,SCM vector) +local void CclParseOrders(Unit* unit, SCM vector) { int i; int n; n=gh_vector_length(vector); - DebugCheck( n!=MAX_ORDERS ); - for( i=0; i<n; ++i ) { - CclParseOrder(gh_vector_ref(vector,gh_int2scm(i)),&unit->Orders[i]); + DebugCheck(n != MAX_ORDERS); + for (i = 0; i < n; ++i) { + CclParseOrder(gh_vector_ref(vector, gh_int2scm(i)), &unit->Orders[i]); } } @@ -340,7 +340,7 @@ local void CclParseBuilded(Unit* unit, SCM list) value = gh_car(list); str = gh_scm2newstr(value, NULL); slot = strtol(str + 1, NULL, 16); - DebugCheck( !UnitSlots[slot] ); + DebugCheck(!UnitSlots[slot]); unit->Data.Builded.Worker = UnitSlots[slot]; ++UnitSlots[slot]->Refs; free(str); @@ -356,7 +356,7 @@ local void CclParseBuilded(Unit* unit, SCM list) frame = gh_scm2int(gh_car(list)); cframe = unit->Type->Construction->Frames; - while( frame-- ) { + while (frame--) { cframe = cframe->Next; } unit->Data.Builded.Frame = cframe; @@ -445,23 +445,23 @@ local void CclParseTrain(Unit *unit, SCM list) SCM sublist; int i; - while ( !gh_null_p(list) ) { + while (!gh_null_p(list)) { value = gh_car(list); list = gh_cdr(list); - if (gh_eq_p(value, gh_symbol2scm("ticks")) ) { + if (gh_eq_p(value, gh_symbol2scm("ticks"))) { value = gh_car(list); list = gh_cdr(list); unit->Data.Train.Ticks = gh_scm2int(value); - } else if (gh_eq_p(value, gh_symbol2scm("count")) ) { + } else if (gh_eq_p(value, gh_symbol2scm("count"))) { value = gh_car(list); list = gh_cdr(list); unit->Data.Train.Count = gh_scm2int(value); - } else if (gh_eq_p(value, gh_symbol2scm("queue")) ) { - sublist=gh_car(list); - list=gh_cdr(list); - for (i=0; i<MAX_UNIT_TRAIN; ++i) { + } else if (gh_eq_p(value, gh_symbol2scm("queue"))) { + sublist = gh_car(list); + list = gh_cdr(list); + for (i = 0; i < MAX_UNIT_TRAIN; ++i) { value = gh_vector_ref(sublist, gh_int2scm(i)); - if ( gh_eq_p(value, gh_symbol2scm("unit-none")) ) { + if (gh_eq_p(value, gh_symbol2scm("unit-none"))) { unit->Data.Train.What[i] = NULL; } else { char *ident; @@ -486,19 +486,19 @@ local void CclParseMove(Unit *unit, SCM list) SCM sublist; int i; - while ( !gh_null_p(list) ) { + while (!gh_null_p(list)) { value = gh_car(list); list = gh_cdr(list); - if (gh_eq_p(value, gh_symbol2scm("fast")) ) { + if (gh_eq_p(value, gh_symbol2scm("fast"))) { unit->Data.Move.Fast = 1; - } else if (gh_eq_p(value, gh_symbol2scm("path")) ) { + } else if (gh_eq_p(value, gh_symbol2scm("path"))) { int len; - sublist=gh_car(list); + sublist = gh_car(list); list = gh_cdr(list); len = gh_length(sublist); - for( i=0; i<len; ++i ) { + for (i = 0; i < len; ++i) { value = gh_vector_ref(sublist, gh_int2scm(i)); - unit->Data.Move.Path[i]=gh_scm2int(value); + unit->Data.Move.Path[i] = gh_scm2int(value); } unit->Data.Move.Length = len; } @@ -520,42 +520,43 @@ local SCM CclUnit(SCM list) Player* player; int slot; int i; - int insidecount=-1; + int insidecount; char* str; char* s; - slot=gh_scm2int(gh_car(list)); - list=gh_cdr(list); + insidecount = -1; + slot = gh_scm2int(gh_car(list)); + list = gh_cdr(list); DebugLevel3Fn("parsing unit #%d\n" _C_ slot); - unit=NULL; - type=NULL; - seentype=NULL; - player=NULL; - i=0; + unit = NULL; + type = NULL; + seentype = NULL; + player = NULL; + i = 0; // // Parse the list: (still everything could be changed!) // - while( !gh_null_p(list) ) { + while (!gh_null_p(list)) { - value=gh_car(list); - list=gh_cdr(list); + value = gh_car(list); + list = gh_cdr(list); - if( gh_eq_p(value,gh_symbol2scm("type")) ) { - type=UnitTypeByIdent(str=gh_scm2newstr(gh_car(list),NULL)); + if (gh_eq_p(value, gh_symbol2scm("type"))) { + type=UnitTypeByIdent(str = gh_scm2newstr(gh_car(list),NULL)); free(str); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("seen-type")) ) { - seentype=UnitTypeByIdent(str=gh_scm2newstr(gh_car(list),NULL)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("seen-type"))) { + seentype=UnitTypeByIdent(str = gh_scm2newstr(gh_car(list),NULL)); free(str); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("name")) ) { - unit->Name=gh_scm2newstr(gh_car(list),NULL); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("player")) ) { - player=&Players[gh_scm2int(gh_car(list))]; - list=gh_cdr(list); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("name"))) { + unit->Name = gh_scm2newstr(gh_car(list),NULL); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("player"))) { + player = &Players[gh_scm2int(gh_car(list))]; + list = gh_cdr(list); // During a unit's death animation (when action is "die" but the // unit still has its original type, i.e. it's still not a corpse) @@ -567,275 +568,275 @@ local SCM CclUnit(SCM list) // characterized by unit->HP==0 and by // unit->Orders[0].Action==UnitActionDie so we have to wait // until we parsed at least Unit::Orders[]. - DebugCheck( !type ); + DebugCheck(!type); unit = UnitSlots[slot]; InitUnit(unit, type); - unit->SeenType=seentype; - unit->Active=0; - unit->Removed=0; - unit->Reset=0; // JOHNS ???? - DebugCheck( unit->Slot!=slot ); - } else if( gh_eq_p(value,gh_symbol2scm("next")) ) { - unit->Next=UnitSlots[gh_scm2int(gh_car(list))]; - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("current-sight-range")) ) { - unit->CurrentSightRange=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("host-info")) ) { - value=gh_car(list); - list=gh_cdr(list); - MapMarkSight(player,gh_scm2int(gh_car(value)),gh_scm2int(gh_cadr(value)), - gh_scm2int(gh_cadr(gh_cdr(value))), - gh_scm2int(gh_cadr(gh_cdr(gh_cdr(value)))), - unit->CurrentSightRange); - } else if( gh_eq_p(value,gh_symbol2scm("tile")) ) { - value=gh_car(list); - list=gh_cdr(list); - unit->X=gh_scm2int(gh_car(value)); - unit->Y=gh_scm2int(gh_cadr(value)); - } else if( gh_eq_p(value,gh_symbol2scm("stats")) ) { - unit->Stats=&type->Stats[gh_scm2int(gh_car(list))]; - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("pixel")) ) { - value=gh_car(list); - list=gh_cdr(list); - unit->IX=gh_scm2int(gh_car(value)); - unit->IY=gh_scm2int(gh_cadr(value)); - } else if( gh_eq_p(value,gh_symbol2scm("seen-pixel")) ) { - value=gh_car(list); - list=gh_cdr(list); - unit->SeenIX=gh_scm2int(gh_car(value)); - unit->SeenIY=gh_scm2int(gh_cadr(value)); - } else if( gh_eq_p(value,gh_symbol2scm("frame")) ) { - unit->Frame=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("flipped-frame")) ) { - unit->Frame=-gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("seen")) ) { - unit->SeenFrame=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("flipped-seen")) ) { - unit->SeenFrame=-gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("not-seen")) ) { - unit->SeenFrame=UnitNotSeen; - } else if( gh_eq_p(value,gh_symbol2scm("direction")) ) { - unit->Direction=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("attacked")) ) { - unit->Attacked=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("burning")) ) { - unit->Burning=1; - } else if( gh_eq_p(value,gh_symbol2scm("destroyed")) ) { - unit->Destroyed=1; - } else if( gh_eq_p(value,gh_symbol2scm("seen-destroyed")) ) { - unit->SeenDestroyed=1; - } else if( gh_eq_p(value,gh_symbol2scm("removed")) ) { - unit->Removed=1; - } else if( gh_eq_p(value,gh_symbol2scm("selected")) ) { - unit->Selected=1; - } else if( gh_eq_p(value,gh_symbol2scm("rescued-from")) ) { - unit->RescuedFrom=&Players[gh_scm2int(gh_car(list))]; - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("visible")) ) { - str=s=gh_scm2newstr(gh_car(list),NULL); - list=gh_cdr(list); - for( i=0; i<PlayerMax && *s; ++i,++s ) { - if( *s=='-' || *s=='_' || *s==' ' ) { - unit->Visible&=~(1<<i); + unit->SeenType = seentype; + unit->Active = 0; + unit->Removed = 0; + unit->Reset = 0; // JOHNS ???? + DebugCheck(unit->Slot != slot); + } else if (gh_eq_p(value, gh_symbol2scm("next"))) { + unit->Next = UnitSlots[gh_scm2int(gh_car(list))]; + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("current-sight-range"))) { + unit->CurrentSightRange = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("host-info"))) { + value = gh_car(list); + list = gh_cdr(list); + MapMarkSight(player, gh_scm2int(gh_car(value)), gh_scm2int(gh_cadr(value)), + gh_scm2int(gh_cadr(gh_cdr(value))), + gh_scm2int(gh_cadr(gh_cdr(gh_cdr(value)))), + unit->CurrentSightRange); + } else if (gh_eq_p(value, gh_symbol2scm("tile"))) { + value = gh_car(list); + list = gh_cdr(list); + unit->X = gh_scm2int(gh_car(value)); + unit->Y = gh_scm2int(gh_cadr(value)); + } else if (gh_eq_p(value, gh_symbol2scm("stats"))) { + unit->Stats = &type->Stats[gh_scm2int(gh_car(list))]; + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("pixel"))) { + value = gh_car(list); + list = gh_cdr(list); + unit->IX = gh_scm2int(gh_car(value)); + unit->IY = gh_scm2int(gh_cadr(value)); + } else if (gh_eq_p(value, gh_symbol2scm("seen-pixel"))) { + value = gh_car(list); + list = gh_cdr(list); + unit->SeenIX = gh_scm2int(gh_car(value)); + unit->SeenIY = gh_scm2int(gh_cadr(value)); + } else if (gh_eq_p(value, gh_symbol2scm("frame"))) { + unit->Frame = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("flipped-frame"))) { + unit->Frame = -gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("seen"))) { + unit->SeenFrame = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("flipped-seen"))) { + unit->SeenFrame = -gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("not-seen"))) { + unit->SeenFrame = UnitNotSeen; + } else if (gh_eq_p(value, gh_symbol2scm("direction"))) { + unit->Direction = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("attacked"))) { + unit->Attacked = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("burning"))) { + unit->Burning = 1; + } else if (gh_eq_p(value, gh_symbol2scm("destroyed"))) { + unit->Destroyed = 1; + } else if (gh_eq_p(value, gh_symbol2scm("seen-destroyed"))) { + unit->SeenDestroyed = 1; + } else if (gh_eq_p(value, gh_symbol2scm("removed"))) { + unit->Removed = 1; + } else if (gh_eq_p(value, gh_symbol2scm("selected"))) { + unit->Selected = 1; + } else if (gh_eq_p(value, gh_symbol2scm("rescued-from"))) { + unit->RescuedFrom = &Players[gh_scm2int(gh_car(list))]; + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("visible"))) { + str=s = gh_scm2newstr(gh_car(list), NULL); + list = gh_cdr(list); + for (i = 0; i < PlayerMax && *s; ++i, ++s) { + if (*s == '-' || *s == '_' || *s == ' ') { + unit->Visible &= ~(1 << i); } else { - unit->Visible|=(1<<i); + unit->Visible |= (1 << i); } } free(str); - } else if( gh_eq_p(value,gh_symbol2scm("constructed")) ) { - unit->Constructed=1; - } else if( gh_eq_p(value,gh_symbol2scm("seen-constructed")) ) { - unit->SeenConstructed=1; - } else if( gh_eq_p(value,gh_symbol2scm("seen-state")) ) { - unit->SeenState=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("active")) ) { - unit->Active=1; - } else if( gh_eq_p(value,gh_symbol2scm("resource-active")) ) { - unit->Data.Resource.Active=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("mana")) ) { - unit->Mana=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("hp")) ) { - unit->HP=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("xp")) ) { - unit->XP=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("kills")) ) { - unit->Kills=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("ttl")) ) { - unit->TTL=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("bloodlust")) ) { - unit->Bloodlust=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("haste")) ) { - unit->Haste=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("slow")) ) { - unit->Slow=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("invisible")) ) { - unit->Invisible=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("flame-shield")) ) { - unit->FlameShield=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("unholy-armor")) ) { - unit->UnholyArmor=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("group-id")) ) { - unit->GroupId=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("last-group")) ) { - unit->LastGroup=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("value")) ) { - unit->Value=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("current-resource")) ) { - unit->CurrentResource=CclGetResourceByName(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("sub-action")) ) { - unit->SubAction=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("wait")) ) { - unit->Wait=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("state")) ) { - unit->State=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("reset")) ) { - unit->Reset=1; - } else if( gh_eq_p(value,gh_symbol2scm("blink")) ) { - unit->Blink=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("moving")) ) { - unit->Moving=1; - } else if( gh_eq_p(value,gh_symbol2scm("rs")) ) { - unit->Rs=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("units-contained-count")) ) { - insidecount=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("units-contained")) ) { - sublist=gh_car(list); - list=gh_cdr(list); - for (i=0;i<insidecount;i++) { - value=gh_vector_ref(sublist,gh_int2scm(i)); - if( !gh_null_p(value) ) { - str=gh_scm2newstr(value,NULL); - slot=strtol(str+1,NULL,16); - AddUnitInContainer(UnitSlots[slot],unit); - DebugCheck( !UnitSlots[slot] ); + } else if (gh_eq_p(value, gh_symbol2scm("constructed"))) { + unit->Constructed = 1; + } else if (gh_eq_p(value, gh_symbol2scm("seen-constructed"))) { + unit->SeenConstructed = 1; + } else if (gh_eq_p(value, gh_symbol2scm("seen-state"))) { + unit->SeenState = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("active"))) { + unit->Active = 1; + } else if (gh_eq_p(value, gh_symbol2scm("resource-active"))) { + unit->Data.Resource.Active = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("mana"))) { + unit->Mana = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("hp"))) { + unit->HP = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("xp"))) { + unit->XP = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("kills"))) { + unit->Kills = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("ttl"))) { + unit->TTL = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("bloodlust"))) { + unit->Bloodlust = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("haste"))) { + unit->Haste = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("slow"))) { + unit->Slow = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("invisible"))) { + unit->Invisible = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("flame-shield"))) { + unit->FlameShield = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("unholy-armor"))) { + unit->UnholyArmor = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("group-id"))) { + unit->GroupId = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("last-group"))) { + unit->LastGroup = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("value"))) { + unit->Value = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("current-resource"))) { + unit->CurrentResource = CclGetResourceByName(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("sub-action"))) { + unit->SubAction = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("wait"))) { + unit->Wait = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("state"))) { + unit->State = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("reset"))) { + unit->Reset = 1; + } else if (gh_eq_p(value, gh_symbol2scm("blink"))) { + unit->Blink = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("moving"))) { + unit->Moving = 1; + } else if (gh_eq_p(value, gh_symbol2scm("rs"))) { + unit->Rs = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("units-contained-count"))) { + insidecount = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("units-contained"))) { + sublist = gh_car(list); + list = gh_cdr(list); + for (i = 0; i < insidecount; ++i) { + value = gh_vector_ref(sublist, gh_int2scm(i)); + if (!gh_null_p(value)) { + str = gh_scm2newstr(value, NULL); + slot = strtol(str + 1, NULL, 16); + AddUnitInContainer(UnitSlots[slot], unit); + DebugCheck(!UnitSlots[slot]); ++UnitSlots[slot]->Refs; free(str); } } - } else if( gh_eq_p(value,gh_symbol2scm("order-count")) ) { - unit->OrderCount=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("order-flush")) ) { - unit->OrderFlush=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("orders")) ) { + } else if (gh_eq_p(value, gh_symbol2scm("order-count"))) { + unit->OrderCount = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("order-flush"))) { + unit->OrderFlush = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("orders"))) { int hp; - sublist=gh_car(list); - list=gh_cdr(list); + sublist = gh_car(list); + list = gh_cdr(list); CclParseOrders(unit,sublist); // now we know unit's action so we can assign it to a player hp = unit->HP; AssignUnitToPlayer (unit, player); unit->HP = hp; - if( unit->Orders[0].Action==UnitActionBuilded ) { + if (unit->Orders[0].Action == UnitActionBuilded) { // HACK: the building is not ready yet unit->Player->UnitTypesCount[type->Type]--; } // FIXME: (mr-russ) Does not load CorpseList Properly - if( unit->Type->Building && - ( unit->Orders[0].Action==UnitActionDie || unit->Destroyed )) { + if (unit->Type->Building && + (unit->Orders[0].Action == UnitActionDie || unit->Destroyed)) { DeadBuildingCacheInsert(unit); - } else if( unit->Orders[0].Action==UnitActionDie ) { + } else if (unit->Orders[0].Action == UnitActionDie) { CorpseCacheInsert(unit); } #if 0 - if( unit->Orders[0].Action==UnitActionDie && - unit->Type->CorpseScript ) { + if (unit->Orders[0].Action == UnitActionDie && + unit->Type->CorpseScript) { MapMarkUnitSight(unit); } #endif - } else if( gh_eq_p(value,gh_symbol2scm("saved-order")) ) { - value=gh_car(list); - list=gh_cdr(list); - CclParseOrder(value,&unit->SavedOrder); - } else if( gh_eq_p(value,gh_symbol2scm("new-order")) ) { - value=gh_car(list); - list=gh_cdr(list); - CclParseOrder(value,&unit->NewOrder); - } else if( gh_eq_p(value,gh_symbol2scm("data-builded")) ) { - sublist=gh_car(list); - list=gh_cdr(list); - CclParseBuilded(unit,sublist); - } else if( gh_eq_p(value,gh_symbol2scm("data-res-worker")) ) { - sublist=gh_car(list); - list=gh_cdr(list); - CclParseResWorker(unit,sublist); - } else if( gh_eq_p(value,gh_symbol2scm("data-research")) ) { - sublist=gh_car(list); - list=gh_cdr(list); - CclParseResearch(unit,sublist); - } else if( gh_eq_p(value,gh_symbol2scm("data-upgrade-to")) ) { - sublist=gh_car(list); - list=gh_cdr(list); - CclParseUpgradeTo(unit,sublist); - } else if( gh_eq_p(value,gh_symbol2scm("data-train")) ) { - sublist=gh_car(list); - list=gh_cdr(list); - CclParseTrain(unit,sublist); - } else if( gh_eq_p(value,gh_symbol2scm("data-move")) ) { - sublist=gh_car(list); - list=gh_cdr(list); - CclParseMove(unit,sublist); - } else if( gh_eq_p(value,gh_symbol2scm("goal")) ) { + } else if (gh_eq_p(value, gh_symbol2scm("saved-order"))) { + value = gh_car(list); + list = gh_cdr(list); + CclParseOrder(value, &unit->SavedOrder); + } else if (gh_eq_p(value, gh_symbol2scm("new-order"))) { + value = gh_car(list); + list = gh_cdr(list); + CclParseOrder(value, &unit->NewOrder); + } else if (gh_eq_p(value, gh_symbol2scm("data-builded"))) { + sublist = gh_car(list); + list = gh_cdr(list); + CclParseBuilded(unit, sublist); + } else if (gh_eq_p(value, gh_symbol2scm("data-res-worker"))) { + sublist = gh_car(list); + list = gh_cdr(list); + CclParseResWorker(unit, sublist); + } else if (gh_eq_p(value, gh_symbol2scm("data-research"))) { + sublist = gh_car(list); + list = gh_cdr(list); + CclParseResearch(unit, sublist); + } else if (gh_eq_p(value, gh_symbol2scm("data-upgrade-to"))) { + sublist = gh_car(list); + list = gh_cdr(list); + CclParseUpgradeTo(unit, sublist); + } else if (gh_eq_p(value, gh_symbol2scm("data-train"))) { + sublist = gh_car(list); + list = gh_cdr(list); + CclParseTrain(unit, sublist); + } else if (gh_eq_p(value, gh_symbol2scm("data-move"))) { + sublist = gh_car(list); + list = gh_cdr(list); + CclParseMove(unit, sublist); + } else if (gh_eq_p(value, gh_symbol2scm("goal"))) { unit->Goal=UnitSlots[gh_scm2int(gh_car(list))]; - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("auto-cast")) ) { - str=gh_scm2newstr(gh_car(list),NULL); - unit->AutoCastSpell=SpellTypeByIdent(str); - list=gh_cdr(list); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("auto-cast"))) { + str = gh_scm2newstr(gh_car(list),NULL); + unit->AutoCastSpell = SpellTypeByIdent(str); + list = gh_cdr(list); free(str); } else { // FIXME: this leaves a half initialized unit - errl("Unsupported tag",value); + errl("Unsupported tag", value); } } if (!unit->Player) { AssignUnitToPlayer (unit, player); - UpdateForNewUnit(unit,0); + UpdateForNewUnit(unit, 0); unit->HP = unit->Type->_HitPoints; } // Revealers are units that can see while removed - if ( unit->Removed && unit->Type->Revealer ) { + if (unit->Removed && unit->Type->Revealer) { MapMarkUnitSight(unit); } // Place on map - if( !unit->Removed && !unit->Destroyed && !unit->Type->Vanishes ) { - unit->Removed=1; - PlaceUnit(unit,unit->X,unit->Y); + if (!unit->Removed && !unit->Destroyed && !unit->Type->Vanishes) { + unit->Removed = 1; + PlaceUnit(unit, unit->X, unit->Y); } // FIXME: johns: works only for debug code. @@ -844,7 +845,7 @@ local SCM CclUnit(SCM list) } // Fix Colors for rescued units. if (unit->RescuedFrom) { - unit->Colors=&unit->RescuedFrom->UnitColors; + unit->Colors = &unit->RescuedFrom->UnitColors; } DebugLevel3Fn("unit #%d parsed\n" _C_ slot); @@ -859,13 +860,13 @@ local SCM CclUnit(SCM list) ** ** @return Returns the slot number of the made unit. */ -local SCM CclMakeUnit(SCM type,SCM player) +local SCM CclMakeUnit(SCM type, SCM player) { UnitType* unittype; Unit* unit; - unittype=CclGetUnitType(type); - unit=MakeUnit(unittype,&Players[gh_scm2int(player)]); + unittype = CclGetUnitType(type); + unit = MakeUnit(unittype, &Players[gh_scm2int(player)]); return gh_int2scm(unit->Slot); } @@ -879,9 +880,9 @@ local SCM CclMakeUnit(SCM type,SCM player) ** ** @return Returns the slot number of the made placed. */ -local SCM CclPlaceUnit(SCM unit,SCM x,SCM y) +local SCM CclPlaceUnit(SCM unit, SCM x, SCM y) { - PlaceUnit(CclGetUnit(unit),gh_scm2int(x),gh_scm2int(y)); + PlaceUnit(CclGetUnit(unit), gh_scm2int(x), gh_scm2int(y)); return unit; } @@ -895,7 +896,7 @@ local SCM CclPlaceUnit(SCM unit,SCM x,SCM y) ** ** @return Returns the slot number of the made unit. */ -local SCM CclCreateUnit(SCM type,SCM player,SCM x,SCM y) +local SCM CclCreateUnit(SCM type, SCM player, SCM x, SCM y) { UnitType* unittype; Unit* unit; @@ -904,20 +905,20 @@ local SCM CclCreateUnit(SCM type,SCM player,SCM x,SCM y) int ix; int iy; - unittype=CclGetUnitType(type); - ix=gh_scm2int(x); - iy=gh_scm2int(y); + unittype = CclGetUnitType(type); + ix = gh_scm2int(x); + iy = gh_scm2int(y); - heading=SyncRand()%256; - unit=MakeUnit(unittype,&Players[gh_scm2int(player)]); - mask=UnitMovementMask(unit); - if( CheckedCanMoveToMask(ix,iy,mask) ) { - unit->Wait=1; - PlaceUnit(unit,ix,iy); + heading = SyncRand() % 256; + unit = MakeUnit(unittype, &Players[gh_scm2int(player)]); + mask = UnitMovementMask(unit); + if (CheckedCanMoveToMask(ix, iy, mask)) { + unit->Wait = 1; + PlaceUnit(unit, ix, iy); } else { - unit->X=ix; - unit->Y=iy; - DropOutOnSide(unit,heading,unittype->TileWidth,unittype->TileHeight); + unit->X = ix; + unit->Y = iy; + DropOutOnSide(unit, heading, unittype->TileWidth, unittype->TileHeight); } return gh_int2scm(unit->Slot); @@ -947,45 +948,45 @@ local SCM CclOrderUnit(SCM list) char* order; plynr=TriggerGetPlayer(gh_car(list)); - list=gh_cdr(list); - unittype=TriggerGetUnitType(gh_car(list)); - list=gh_cdr(list); - x1=gh_scm2int(gh_car(gh_car(list))); - y1=gh_scm2int(gh_car(gh_cdr(gh_car(list)))); - x2=gh_scm2int(gh_car(gh_cdr(gh_cdr(gh_car(list))))); - y2=gh_scm2int(gh_car(gh_cdr(gh_cdr(gh_cdr(gh_car(list)))))); - list=gh_cdr(list); - dx1=gh_scm2int(gh_car(gh_car(list))); - dy1=gh_scm2int(gh_car(gh_cdr(gh_car(list)))); - if( !gh_null_p(gh_cdr(gh_cdr(gh_car(list)))) ) { - dx2=gh_scm2int(gh_car(gh_cdr(gh_cdr(gh_car(list))))); - dy2=gh_scm2int(gh_car(gh_cdr(gh_cdr(gh_cdr(gh_car(list)))))); + list = gh_cdr(list); + unittype = TriggerGetUnitType(gh_car(list)); + list = gh_cdr(list); + x1 = gh_scm2int(gh_car(gh_car(list))); + y1 = gh_scm2int(gh_car(gh_cdr(gh_car(list)))); + x2 = gh_scm2int(gh_car(gh_cdr(gh_cdr(gh_car(list))))); + y2 = gh_scm2int(gh_car(gh_cdr(gh_cdr(gh_cdr(gh_car(list)))))); + list = gh_cdr(list); + dx1 = gh_scm2int(gh_car(gh_car(list))); + dy1 = gh_scm2int(gh_car(gh_cdr(gh_car(list)))); + if (!gh_null_p(gh_cdr(gh_cdr(gh_car(list))))) { + dx2 = gh_scm2int(gh_car(gh_cdr(gh_cdr(gh_car(list))))); + dy2 = gh_scm2int(gh_car(gh_cdr(gh_cdr(gh_cdr(gh_car(list)))))); } else { - dx2=dx1; - dy2=dy1; + dx2 = dx1; + dy2 = dy1; } - list=gh_cdr(list); - order=gh_scm2newstr(gh_car(list),NULL); + list = gh_cdr(list); + order = gh_scm2newstr(gh_car(list),NULL); - an=SelectUnits(x1,y1,x2+1,y2+1,table); - for( j=0; j<an; ++j ) { - unit=table[j]; - if( unittype==ANY_UNIT - || (unittype==ALL_FOODUNITS && !unit->Type->Building) - || (unittype==ALL_BUILDINGS && unit->Type->Building) - || unittype==unit->Type ) { - if( plynr==-1 || plynr==unit->Player->Player ) { - if( !strcmp(order,"move") ) { - CommandMove(unit,(dx1+dx2)/2,(dy1+dy2)/2,1); - } else if( !strcmp(order,"attack") ) { + an = SelectUnits(x1, y1, x2 + 1, y2 + 1, table); + for (j = 0; j < an; ++j) { + unit = table[j]; + if (unittype == ANY_UNIT || + (unittype == ALL_FOODUNITS && !unit->Type->Building) || + (unittype == ALL_BUILDINGS && unit->Type->Building) || + unittype == unit->Type) { + if (plynr == -1 || plynr == unit->Player->Player) { + if (!strcmp(order,"move")) { + CommandMove(unit, (dx1 + dx2) / 2, (dy1 + dy2) / 2, 1); + } else if (!strcmp(order, "attack")) { Unit* attack; - attack=TargetOnMap(unit,dx1,dy1,dx2,dy2); - CommandAttack(unit,(dx1+dx2)/2,(dy1+dy2)/2,attack,1); - } else if( !strcmp(order,"patrol") ) { - CommandPatrolUnit(unit,(dx1+dx2)/2,(dy1+dy2)/2,1); + attack=TargetOnMap(unit, dx1, dy1, dx2, dy2); + CommandAttack(unit, (dx1 + dx2) / 2, (dy1 + dy2) / 2, attack, 1); + } else if (!strcmp(order,"patrol")) { + CommandPatrolUnit(unit, (dx1 + dx2) / 2, (dy1 + dy2) / 2, 1); } else { - errl("Unsupported order",gh_car(list)); + errl("Unsupported order", gh_car(list)); } } } @@ -1003,7 +1004,7 @@ local SCM CclOrderUnit(SCM list) ** ** @return Returns true if a unit was killed. */ -local SCM CclKillUnit(SCM type,SCM player) +local SCM CclKillUnit(SCM type, SCM player) { int j; int plynr; @@ -1011,22 +1012,22 @@ local SCM CclKillUnit(SCM type,SCM player) Unit* unit; Unit** table; - unittype=TriggerGetUnitType(type); - plynr=TriggerGetPlayer(player); - if( plynr==-1 ) { - table=Units; - j=NumUnits-1; + unittype = TriggerGetUnitType(type); + plynr = TriggerGetPlayer(player); + if (plynr == -1) { + table = Units; + j = NumUnits - 1; } else { - table=Players[plynr].Units; - j=Players[plynr].TotalNumUnits-1; + table = Players[plynr].Units; + j = Players[plynr].TotalNumUnits - 1; } - for( ; j>=0; --j ) { - unit=table[j]; - if( unittype==ANY_UNIT - || (unittype==ALL_FOODUNITS && !unit->Type->Building) - || (unittype==ALL_BUILDINGS && unit->Type->Building) - || unittype==unit->Type ) { + for (; j >= 0; --j) { + unit = table[j]; + if (unittype == ANY_UNIT || + (unittype == ALL_FOODUNITS && !unit->Type->Building) || + (unittype == ALL_BUILDINGS && unit->Type->Building) || + unittype == unit->Type) { LetUnitDie(unit); return SCM_BOOL_T; } @@ -1045,7 +1046,7 @@ local SCM CclKillUnit(SCM type,SCM player) ** ** @return Returns the number of units killed. */ -local SCM CclKillUnitAt(SCM type,SCM player,SCM quantity,SCM loc) +local SCM CclKillUnitAt(SCM type, SCM player, SCM quantity, SCM loc) { int plynr; int q; @@ -1061,21 +1062,21 @@ local SCM CclKillUnitAt(SCM type,SCM player,SCM quantity,SCM loc) int s; plynr=TriggerGetPlayer(player); - q=gh_scm2int(quantity); - unittype=TriggerGetUnitType(type); - x1=gh_scm2int(gh_car(loc)); - y1=gh_scm2int(gh_car(gh_cdr(loc))); - x2=gh_scm2int(gh_car(gh_cdr(gh_cdr(loc)))); - y2=gh_scm2int(gh_car(gh_cdr(gh_cdr(gh_cdr(loc))))); + q = gh_scm2int(quantity); + unittype = TriggerGetUnitType(type); + x1 = gh_scm2int(gh_car(loc)); + y1 = gh_scm2int(gh_car(gh_cdr(loc))); + x2 = gh_scm2int(gh_car(gh_cdr(gh_cdr(loc)))); + y2 = gh_scm2int(gh_car(gh_cdr(gh_cdr(gh_cdr(loc))))); - an=SelectUnits(x1,y1,x2+1,y2+1,table); - for( j=s=0; j<an && s<q; ++j ) { - unit=table[j]; - if( unittype==ANY_UNIT - || (unittype==ALL_FOODUNITS && !unit->Type->Building) - || (unittype==ALL_BUILDINGS && unit->Type->Building) - || unittype==unit->Type ) { - if( plynr==-1 || plynr==unit->Player->Player ) { + an=SelectUnits(x1, y1, x2 + 1, y2 + 1, table); + for (j = s = 0; j < an && s < q; ++j) { + unit = table[j]; + if (unittype == ANY_UNIT || + (unittype == ALL_FOODUNITS && !unit->Type->Building) || + (unittype == ALL_BUILDINGS && unit->Type->Building) || + unittype==unit->Type) { + if (plynr == -1 || plynr == unit->Player->Player) { LetUnitDie(unit); ++s; } @@ -1097,8 +1098,8 @@ local SCM CclGetUnitUnholyArmor(SCM ptr) const Unit* unit; SCM value; - unit=CclGetUnit(ptr); - value=gh_int2scm(unit->UnholyArmor); + unit = CclGetUnit(ptr); + value = gh_int2scm(unit->UnholyArmor); return value; } @@ -1110,19 +1111,19 @@ local SCM CclGetUnitUnholyArmor(SCM ptr) ** ** @return The value of the unit. */ -local SCM CclSetUnitUnholyArmor(SCM ptr,SCM value) +local SCM CclSetUnitUnholyArmor(SCM ptr, SCM value) { Unit* unit; - unit=CclGetUnit(ptr); - unit->UnholyArmor=gh_scm2int(value); + unit = CclGetUnit(ptr); + unit->UnholyArmor = gh_scm2int(value); return value; } -local SCM CclSlotUsage (SCM list) +local SCM CclSlotUsage(SCM list) { -#define SLOT_LEN MAX_UNIT_SLOTS/8 + 1 +#define SLOT_LEN MAX_UNIT_SLOTS / 8 + 1 unsigned char SlotUsage[SLOT_LEN]; int i; int prev; @@ -1130,7 +1131,7 @@ local SCM CclSlotUsage (SCM list) memset(SlotUsage, 0, SLOT_LEN); prev = -1; - while ( !gh_null_p(list) ) { + while (!gh_null_p(list)) { value = gh_car(list); list = gh_cdr(list); if (gh_eq_p(value, gh_symbol2scm("-"))) { @@ -1138,24 +1139,26 @@ local SCM CclSlotUsage (SCM list) value = gh_car(list); list = gh_cdr(list); range_end = gh_scm2int(value); - for (i=prev; i<=range_end; i++) - SlotUsage[i/8] |= 1 << (i%8); + for (i = prev; i <= range_end; ++i) { + SlotUsage[i / 8] |= 1 << (i % 8); + } prev = -1; } else { - if (prev >= 0) - SlotUsage[prev/8] |= 1 << (prev%8); + if (prev >= 0) { + SlotUsage[prev / 8] |= 1 << (prev % 8); + } prev = gh_scm2int(value); } } if (prev >= 0) { - SlotUsage[prev/8] |= 1 << (prev%8); + SlotUsage[prev / 8] |= 1 << (prev % 8); } /* now walk through the bitfield and create the needed unit slots */ - for (i=0; i<SLOT_LEN*8; i++) { - if ( SlotUsage[i/8] & (1 << i%8) ) { - Unit *new_unit = (Unit * )calloc(1, sizeof (Unit)); - UnitSlotFree = (void *)UnitSlots[i]; + for (i = 0; i < SLOT_LEN * 8; ++i) { + if (SlotUsage[i / 8] & (1 << i % 8)) { + Unit* new_unit = (Unit*)calloc(1, sizeof(Unit)); + UnitSlotFree = (void*)UnitSlots[i]; UnitSlots[i] = new_unit; new_unit->Slot = i; } @@ -1172,24 +1175,24 @@ local SCM CclSlotUsage (SCM list) global void UnitCclRegister(void) { gh_new_procedure1_0("set-hitpoint-regeneration!", - CclSetHitPointRegeneration); - gh_new_procedure1_0("set-xp-damage!",CclSetXpDamage); - gh_new_procedure1_0("set-training-queue!",CclSetTrainingQueue); - gh_new_procedure1_0("set-building-capture!",CclSetBuildingCapture); - gh_new_procedure1_0("set-reveal-attacker!",CclSetRevealAttacker); + CclSetHitPointRegeneration); + gh_new_procedure1_0("set-xp-damage!", CclSetXpDamage); + gh_new_procedure1_0("set-training-queue!", CclSetTrainingQueue); + gh_new_procedure1_0("set-building-capture!", CclSetBuildingCapture); + gh_new_procedure1_0("set-reveal-attacker!", CclSetRevealAttacker); - gh_new_procedureN("unit",CclUnit); + gh_new_procedureN("unit", CclUnit); - gh_new_procedure2_0("make-unit",CclMakeUnit); - gh_new_procedure3_0("place-unit",CclPlaceUnit); - gh_new_procedure4_0("create-unit",CclCreateUnit); - gh_new_procedureN("order-unit",CclOrderUnit); - gh_new_procedure2_0("kill-unit",CclKillUnit); - gh_new_procedure4_0("kill-unit-at",CclKillUnitAt); + gh_new_procedure2_0("make-unit", CclMakeUnit); + gh_new_procedure3_0("place-unit", CclPlaceUnit); + gh_new_procedure4_0("create-unit", CclCreateUnit); + gh_new_procedureN("order-unit", CclOrderUnit); + gh_new_procedure2_0("kill-unit", CclKillUnit); + gh_new_procedure4_0("kill-unit-at", CclKillUnitAt); // unit member access functions - gh_new_procedure1_0("get-unit-unholy-armor",CclGetUnitUnholyArmor); - gh_new_procedure2_0("set-unit-unholy-armor!",CclSetUnitUnholyArmor); + gh_new_procedure1_0("get-unit-unholy-armor", CclGetUnitUnholyArmor); + gh_new_procedure2_0("set-unit-unholy-armor!", CclSetUnitUnholyArmor); gh_new_procedure1_0 ("slot-usage", CclSlotUsage); } diff --git a/src/unit/script_unittype.cpp b/src/unit/script_unittype.cpp index fefc4ae84..489a745b1 100644 --- a/src/unit/script_unittype.cpp +++ b/src/unit/script_unittype.cpp @@ -54,9 +54,9 @@ -- Variables ----------------------------------------------------------------------------*/ -IfDebug( +#ifdef DEBUG extern int NoWarningUnitType; /// quiet ident lookup. -); +#endif global _AnimationsHash AnimationsHash; /// Animations hash table @@ -75,12 +75,13 @@ local ccl_smob_type_t SiodUnitTypeTag; /// siod unit-type object global unsigned CclGetResourceByName(SCM value) { int i; - for( i=0; i<MaxCosts; ++i ) { - if( gh_eq_p(value,gh_symbol2scm(DefaultResourceNames[i])) ) { + + for (i = 0; i < MaxCosts; ++i) { + if (gh_eq_p(value, gh_symbol2scm(DefaultResourceNames[i]))) { return i; } } - errl("Unsupported resource tag",value); + errl("Unsupported resource tag", value); return 0xABCDEF; } @@ -104,513 +105,518 @@ local SCM CclDefineUnitType(SCM list) // Slot identifier - str=gh_scm2newstr(gh_car(list),NULL); - list=gh_cdr(list); + str = gh_scm2newstr(gh_car(list), NULL); + list = gh_cdr(list); - IfDebug( i=NoWarningUnitType; NoWarningUnitType=1; ); - type=UnitTypeByIdent(str); - IfDebug( NoWarningUnitType=i; ); - if( type ) { +#ifdef DEBUG + i = NoWarningUnitType; + NoWarningUnitType = 1; +#endif + type = UnitTypeByIdent(str); +#ifdef DEBUG + NoWarningUnitType = i; +#endif + if (type) { DebugLevel3Fn("Redefining unit-type `%s'\n" _C_ str); free(str); redefine = 1; } else { DebugLevel3Fn("Defining unit-type `%s'\n" _C_ str); - type=NewUnitTypeSlot(str); + type = NewUnitTypeSlot(str); redefine = 0; //Set some default values - type->_RegenerationRate=0; + type->_RegenerationRate = 0; } - type->NumDirections=8; + type->NumDirections = 8; #ifdef NEW_UI type->AddButtonsHook = NIL; - #endif + // // Parse the list: (still everything could be changed!) // - while( !gh_null_p(list) ) { + while (!gh_null_p(list)) { - value=gh_car(list); - list=gh_cdr(list); + value = gh_car(list); + list = gh_cdr(list); - if( gh_eq_p(value,gh_symbol2scm("name")) ) { - if( redefine ) { + if (gh_eq_p(value, gh_symbol2scm("name"))) { + if (redefine) { free(type->Name); } - type->Name=gh_scm2newstr(gh_car(list),NULL); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("use")) ) { - if( redefine ) { + type->Name = gh_scm2newstr(gh_car(list), NULL); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("use"))) { + if (redefine) { free(type->SameSprite); } - type->SameSprite=gh_scm2newstr(gh_car(list),NULL); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("files")) ) { - sublist=gh_car(list); - list=gh_cdr(list); - while( !gh_null_p(sublist) ) { + type->SameSprite = gh_scm2newstr(gh_car(list), NULL); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("files"))) { + sublist = gh_car(list); + list = gh_cdr(list); + while (!gh_null_p(sublist)) { char* str; - value=gh_car(sublist); - sublist=gh_cdr(sublist); + value = gh_car(sublist); + sublist = gh_cdr(sublist); // FIXME: use a general get tileset function here! - str=gh_scm2newstr(value,NULL); - i=0; - if( strcmp(str,"default") ) { - for( ; i<TilesetMax; ++i ) { - if( !strcmp(str,Tilesets[i]->Ident) || - !strcmp(str,Tilesets[i]->Class) ) { + str = gh_scm2newstr(value, NULL); + i = 0; + if (strcmp(str, "default")) { + for (; i < TilesetMax; ++i) { + if (!strcmp(str,Tilesets[i]->Ident) || + !strcmp(str,Tilesets[i]->Class)) { break; } } - if( i==TilesetMax ) { + if (i == TilesetMax) { // FIXME: this leaves half initialized unit-type - errl("Unsupported tileset tag",value); + errl("Unsupported tileset tag", value); } } free(str); - if( redefine ) { + if (redefine) { free(type->File[i]); } - type->File[i]=gh_scm2newstr(gh_car(sublist),NULL); - sublist=gh_cdr(sublist); + type->File[i] = gh_scm2newstr(gh_car(sublist), NULL); + sublist = gh_cdr(sublist); } - } else if( gh_eq_p(value,gh_symbol2scm("shadow")) ) { - sublist=gh_car(list); - list=gh_cdr(list); - while( !gh_null_p(sublist) ) { - value=gh_car(sublist); - sublist=gh_cdr(sublist); + } else if (gh_eq_p(value, gh_symbol2scm("shadow"))) { + sublist = gh_car(list); + list = gh_cdr(list); + while (!gh_null_p(sublist)) { + value = gh_car(sublist); + sublist = gh_cdr(sublist); - if( gh_eq_p(value,gh_symbol2scm("file")) ) { - if( redefine ) { + if (gh_eq_p(value, gh_symbol2scm("file"))) { + if (redefine) { free(type->ShadowFile); } - type->ShadowFile=gh_scm2newstr(gh_car(sublist),NULL); - } else if( gh_eq_p(value,gh_symbol2scm("width")) ) { - type->ShadowWidth=gh_scm2int(gh_car(sublist)); - } else if( gh_eq_p(value,gh_symbol2scm("height")) ) { - type->ShadowHeight=gh_scm2int(gh_car(sublist)); - } else if( gh_eq_p(value,gh_symbol2scm("offset")) ) { - type->ShadowOffset=gh_scm2int(gh_car(sublist)); + type->ShadowFile = gh_scm2newstr(gh_car(sublist), NULL); + } else if (gh_eq_p(value, gh_symbol2scm("width"))) { + type->ShadowWidth = gh_scm2int(gh_car(sublist)); + } else if (gh_eq_p(value, gh_symbol2scm("height"))) { + type->ShadowHeight = gh_scm2int(gh_car(sublist)); + } else if (gh_eq_p(value, gh_symbol2scm("offset"))) { + type->ShadowOffset = gh_scm2int(gh_car(sublist)); } else { - errl("Unsupported shadow tag",value); + errl("Unsupported shadow tag", value); } - sublist=gh_cdr(sublist); + sublist = gh_cdr(sublist); } - } else if( gh_eq_p(value,gh_symbol2scm("size")) ) { - sublist=gh_car(list); - list=gh_cdr(list); - type->Width=gh_scm2int(gh_car(sublist)); - type->Height=gh_scm2int(gh_cadr(sublist)); - } else if( gh_eq_p(value,gh_symbol2scm("animations")) ) { - type->Animations= - AnimationsByIdent(str=gh_scm2newstr(gh_car(list),NULL)); + } else if (gh_eq_p(value, gh_symbol2scm("size"))) { + sublist = gh_car(list); + list = gh_cdr(list); + type->Width = gh_scm2int(gh_car(sublist)); + type->Height = gh_scm2int(gh_cadr(sublist)); + } else if (gh_eq_p(value, gh_symbol2scm("animations"))) { + type->Animations = + AnimationsByIdent(str = gh_scm2newstr(gh_car(list), NULL)); free(str); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("icon")) ) { - if( redefine ) { + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("icon"))) { + if (redefine) { free(type->Icon.Name); } - type->Icon.Name=gh_scm2newstr(gh_car(list),NULL); - type->Icon.Icon=NULL; - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("costs")) ) { - sublist=gh_car(list); - list=gh_cdr(list); - while( !gh_null_p(sublist) ) { - value=gh_car(sublist); - sublist=gh_cdr(sublist); - type->_Costs[CclGetResourceByName(value)]=gh_scm2int(gh_car(sublist)); - sublist=gh_cdr(sublist); + type->Icon.Name = gh_scm2newstr(gh_car(list), NULL); + type->Icon.Icon = NULL; + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("costs"))) { + sublist = gh_car(list); + list = gh_cdr(list); + while (!gh_null_p(sublist)) { + value = gh_car(sublist); + sublist = gh_cdr(sublist); + type->_Costs[CclGetResourceByName(value)] = gh_scm2int(gh_car(sublist)); + sublist = gh_cdr(sublist); } - } else if( gh_eq_p(value,gh_symbol2scm("improve-production")) ) { - sublist=gh_car(list); - list=gh_cdr(list); - while( !gh_null_p(sublist) ) { - value=gh_car(sublist); - sublist=gh_cdr(sublist); - type->ImproveIncomes[CclGetResourceByName(value)]= - DefaultIncomes[CclGetResourceByName(value)]+gh_scm2int(gh_car(sublist)); - sublist=gh_cdr(sublist); + } else if (gh_eq_p(value, gh_symbol2scm("improve-production"))) { + sublist = gh_car(list); + list = gh_cdr(list); + while (!gh_null_p(sublist)) { + value = gh_car(sublist); + sublist = gh_cdr(sublist); + type->ImproveIncomes[CclGetResourceByName(value)] = + DefaultIncomes[CclGetResourceByName(value)] + gh_scm2int(gh_car(sublist)); + sublist = gh_cdr(sublist); } - } else if( gh_eq_p(value,gh_symbol2scm("construction")) ) { + } else if (gh_eq_p(value, gh_symbol2scm("construction"))) { // FIXME: What if constructions arn't yet loaded? - str=gh_scm2newstr(gh_car(list),NULL); - type->Construction=ConstructionByIdent(str); - list=gh_cdr(list); + str = gh_scm2newstr(gh_car(list), NULL); + type->Construction = ConstructionByIdent(str); + list = gh_cdr(list); free(str); - } else if( gh_eq_p(value,gh_symbol2scm("speed")) ) { - type->_Speed=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("draw-level")) ) { - type->DrawLevel=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("max-on-board")) ) { - type->MaxOnBoard=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("hit-points")) ) { - type->_HitPoints=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("regeneration-rate")) ) { - type->_RegenerationRate=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("max-mana")) ) { - type->_MaxMana=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("magic")) ) { - type->Magic=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("tile-size")) ) { - sublist=gh_car(list); - list=gh_cdr(list); - type->TileWidth=gh_scm2int(gh_car(sublist)); - type->TileHeight=gh_scm2int(gh_cadr(sublist)); - } else if( gh_eq_p(value,gh_symbol2scm("must-build-on-top")) ){ - str=gh_scm2newstr(gh_car(list),NULL); - auxtype=UnitTypeByIdent(str); + } else if (gh_eq_p(value, gh_symbol2scm("speed"))) { + type->_Speed = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("draw-level"))) { + type->DrawLevel = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("max-on-board"))) { + type->MaxOnBoard = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("hit-points"))) { + type->_HitPoints = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("regeneration-rate"))) { + type->_RegenerationRate = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("max-mana"))) { + type->_MaxMana = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("magic"))) { + type->Magic = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("tile-size"))) { + sublist = gh_car(list); + list = gh_cdr(list); + type->TileWidth = gh_scm2int(gh_car(sublist)); + type->TileHeight = gh_scm2int(gh_cadr(sublist)); + } else if (gh_eq_p(value, gh_symbol2scm("must-build-on-top"))) { + str = gh_scm2newstr(gh_car(list), NULL); + auxtype = UnitTypeByIdent(str); if (!auxtype) { DebugLevel0("Build on top of undefined unit \"%s\".\n" _C_ str); DebugCheck(1); } - type->MustBuildOnTop=auxtype; + type->MustBuildOnTop = auxtype; free(str); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("box-size")) ) { - sublist=gh_car(list); - list=gh_cdr(list); - type->BoxWidth=gh_scm2int(gh_car(sublist)); - type->BoxHeight=gh_scm2int(gh_cadr(sublist)); - } else if( gh_eq_p(value,gh_symbol2scm("num-directions")) ) { - type->NumDirections=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("revealer")) ) { - type->Revealer=1; - } else if( gh_eq_p(value,gh_symbol2scm("sight-range")) ) { - type->_SightRange=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("computer-reaction-range")) ) { - type->ReactRangeComputer=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("person-reaction-range")) ) { - type->ReactRangePerson=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("armor")) ) { - type->_Armor=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("basic-damage")) ) { - type->_BasicDamage=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("piercing-damage")) ) { - type->_PiercingDamage=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("missile")) ) { - type->Missile.Name=gh_scm2newstr(gh_car(list),NULL); - type->Missile.Missile=NULL; - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("min-attack-range")) ) { - type->MinAttackRange=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("max-attack-range")) ) { - type->_AttackRange=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("weapons-upgradable")) ) { - type->WeaponsUpgradable=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("armor-upgradable")) ) { - type->ArmorUpgradable=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("priority")) ) { - type->Priority=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("annoy-computer-factor")) ) { - type->AnnoyComputerFactor=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("decay-rate")) ) { - type->DecayRate=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("points")) ) { - type->Points=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("demand")) ) { - type->Demand=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("supply")) ) { - type->Supply=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("corpse")) ) { - sublist=gh_car(list); - list=gh_cdr(list); - if( redefine ) { + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("box-size"))) { + sublist = gh_car(list); + list = gh_cdr(list); + type->BoxWidth = gh_scm2int(gh_car(sublist)); + type->BoxHeight = gh_scm2int(gh_cadr(sublist)); + } else if (gh_eq_p(value, gh_symbol2scm("num-directions"))) { + type->NumDirections = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("revealer"))) { + type->Revealer = 1; + } else if (gh_eq_p(value, gh_symbol2scm("sight-range"))) { + type->_SightRange = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("computer-reaction-range"))) { + type->ReactRangeComputer = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("person-reaction-range"))) { + type->ReactRangePerson = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("armor"))) { + type->_Armor = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("basic-damage"))) { + type->_BasicDamage = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("piercing-damage"))) { + type->_PiercingDamage = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("missile"))) { + type->Missile.Name = gh_scm2newstr(gh_car(list), NULL); + type->Missile.Missile = NULL; + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("min-attack-range"))) { + type->MinAttackRange = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("max-attack-range"))) { + type->_AttackRange = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("weapons-upgradable"))) { + type->WeaponsUpgradable = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("armor-upgradable"))) { + type->ArmorUpgradable = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("priority"))) { + type->Priority = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("annoy-computer-factor"))) { + type->AnnoyComputerFactor = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("decay-rate"))) { + type->DecayRate = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("points"))) { + type->Points = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("demand"))) { + type->Demand = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("supply"))) { + type->Supply = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("corpse"))) { + sublist = gh_car(list); + list = gh_cdr(list); + if (redefine) { free(type->CorpseName); } - type->CorpseName=gh_scm2newstr(gh_car(sublist),NULL); - type->CorpseType=NULL; - type->CorpseScript=gh_scm2int(gh_cadr(sublist)); - } else if( gh_eq_p(value,gh_symbol2scm("explode-when-killed")) ) { - type->ExplodeWhenKilled=1; - type->Explosion.Name=gh_scm2newstr(gh_car(list),NULL); - type->Explosion.Missile=NULL; - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("type-land")) ) { - type->UnitType=UnitTypeLand; - } else if( gh_eq_p(value,gh_symbol2scm("type-fly")) ) { - type->UnitType=UnitTypeFly; - } else if( gh_eq_p(value,gh_symbol2scm("type-naval")) ) { - type->UnitType=UnitTypeNaval; + type->CorpseName = gh_scm2newstr(gh_car(sublist), NULL); + type->CorpseType = NULL; + type->CorpseScript = gh_scm2int(gh_cadr(sublist)); + } else if (gh_eq_p(value, gh_symbol2scm("explode-when-killed"))) { + type->ExplodeWhenKilled = 1; + type->Explosion.Name = gh_scm2newstr(gh_car(list), NULL); + type->Explosion.Missile = NULL; + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("type-land"))) { + type->UnitType = UnitTypeLand; + } else if (gh_eq_p(value, gh_symbol2scm("type-fly"))) { + type->UnitType = UnitTypeFly; + } else if (gh_eq_p(value, gh_symbol2scm("type-naval"))) { + type->UnitType = UnitTypeNaval; - } else if( gh_eq_p(value,gh_symbol2scm("right-none")) ) { - type->MouseAction=MouseActionNone; - } else if( gh_eq_p(value,gh_symbol2scm("right-attack")) ) { - type->MouseAction=MouseActionAttack; - } else if( gh_eq_p(value,gh_symbol2scm("right-move")) ) { - type->MouseAction=MouseActionMove; - } else if( gh_eq_p(value,gh_symbol2scm("right-harvest")) ) { - type->MouseAction=MouseActionHarvest; - } else if( gh_eq_p(value,gh_symbol2scm("right-demolish")) ) { - type->MouseAction=MouseActionDemolish; - } else if( gh_eq_p(value,gh_symbol2scm("right-sail")) ) { - type->MouseAction=MouseActionSail; + } else if (gh_eq_p(value, gh_symbol2scm("right-none"))) { + type->MouseAction = MouseActionNone; + } else if (gh_eq_p(value, gh_symbol2scm("right-attack"))) { + type->MouseAction = MouseActionAttack; + } else if (gh_eq_p(value, gh_symbol2scm("right-move"))) { + type->MouseAction = MouseActionMove; + } else if (gh_eq_p(value, gh_symbol2scm("right-harvest"))) { + type->MouseAction = MouseActionHarvest; + } else if (gh_eq_p(value, gh_symbol2scm("right-demolish"))) { + type->MouseAction = MouseActionDemolish; + } else if (gh_eq_p(value, gh_symbol2scm("right-sail"))) { + type->MouseAction = MouseActionSail; - } else if( gh_eq_p(value,gh_symbol2scm("can-ground-attack")) ) { - type->GroundAttack=1; - } else if( gh_eq_p(value,gh_symbol2scm("can-attack")) ) { - type->CanAttack=1; - } else if( gh_eq_p(value,gh_symbol2scm("demolish-range"))){ - type->DemolishRange=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("demolish-damage"))){ - type->DemolishDamage=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("repair-range")) ) { - type->RepairRange=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("repair-hp")) ) { - type->RepairHP=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("repair-costs")) ) { - sublist=gh_car(list); - list=gh_cdr(list); - while( !gh_null_p(sublist) ) { - value=gh_car(sublist); - sublist=gh_cdr(sublist); - type->RepairCosts[CclGetResourceByName(value)]=gh_scm2int(gh_car(sublist)); - sublist=gh_cdr(sublist); + } else if (gh_eq_p(value, gh_symbol2scm("can-ground-attack"))) { + type->GroundAttack = 1; + } else if (gh_eq_p(value, gh_symbol2scm("can-attack"))) { + type->CanAttack = 1; + } else if (gh_eq_p(value, gh_symbol2scm("demolish-range"))){ + type->DemolishRange = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("demolish-damage"))){ + type->DemolishDamage = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("repair-range"))) { + type->RepairRange = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("repair-hp"))) { + type->RepairHP = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("repair-costs"))) { + sublist = gh_car(list); + list = gh_cdr(list); + while (!gh_null_p(sublist)) { + value = gh_car(sublist); + sublist = gh_cdr(sublist); + type->RepairCosts[CclGetResourceByName(value)] = gh_scm2int(gh_car(sublist)); + sublist = gh_cdr(sublist); } - } else if( gh_eq_p(value,gh_symbol2scm("can-target-land")) ) { - type->CanTarget|=CanTargetLand; - } else if( gh_eq_p(value,gh_symbol2scm("can-target-sea")) ) { - type->CanTarget|=CanTargetSea; - } else if( gh_eq_p(value,gh_symbol2scm("can-target-air")) ) { - type->CanTarget|=CanTargetAir; + } else if (gh_eq_p(value, gh_symbol2scm("can-target-land"))) { + type->CanTarget |= CanTargetLand; + } else if (gh_eq_p(value, gh_symbol2scm("can-target-sea"))) { + type->CanTarget |= CanTargetSea; + } else if (gh_eq_p(value, gh_symbol2scm("can-target-air"))) { + type->CanTarget |= CanTargetAir; - } else if( gh_eq_p(value,gh_symbol2scm("building")) ) { - type->Building=1; - } else if( gh_eq_p(value,gh_symbol2scm("wall")) ) { - type->Wall=1; - } else if( gh_eq_p(value,gh_symbol2scm("builder-outside")) ) { - type->BuilderOutside=1; - } else if( gh_eq_p(value,gh_symbol2scm("builder-lost")) ) { - type->BuilderLost=1; - } else if( gh_eq_p(value,gh_symbol2scm("auto-build-rate")) ) { - type->AutoBuildRate=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("shore-building")) ) { - type->ShoreBuilding=1; - } else if( gh_eq_p(value,gh_symbol2scm("land-unit")) ) { - type->LandUnit=1; - } else if( gh_eq_p(value,gh_symbol2scm("air-unit")) ) { - type->AirUnit=1; - } else if( gh_eq_p(value,gh_symbol2scm("sea-unit")) ) { - type->SeaUnit=1; - } else if( gh_eq_p(value,gh_symbol2scm("random-movement-probability")) ) { - type->RandomMovementProbability=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("clicks-to-explode")) ) { - type->ClicksToExplode=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("sniper")) ) { - type->Sniper=1; - } else if( gh_eq_p(value,gh_symbol2scm("permanent-cloak")) ) { - type->PermanentCloak=1; - } else if( gh_eq_p(value,gh_symbol2scm("detect-cloak")) ) { - type->DetectCloak=1; - } else if( gh_eq_p(value,gh_symbol2scm("transporter")) ) { - type->Transporter=1; - } else if( gh_eq_p(value,gh_symbol2scm("coward")) ) { - type->Coward=1; - } else if( gh_eq_p(value,gh_symbol2scm("can-gather-resource")) ) { - sublist=gh_car(list); - list=gh_cdr(list); - res=(ResourceInfo*)malloc(sizeof(ResourceInfo)); - memset(res,0,sizeof(ResourceInfo)); - while( !gh_null_p(sublist) ) { - value=gh_car(sublist); - sublist=gh_cdr(sublist); - if (gh_eq_p(value,gh_symbol2scm("resource-id")) ) { - res->ResourceId=CclGetResourceByName(gh_car(sublist)); - type->ResInfo[res->ResourceId]=res; - sublist=gh_cdr(sublist); - } else if( gh_eq_p(value,gh_symbol2scm("resource-step")) ) { - res->ResourceStep=gh_scm2int(gh_car(sublist)); - sublist=gh_cdr(sublist); - } else if( gh_eq_p(value,gh_symbol2scm("final-resource")) ) { - res->FinalResource=CclGetResourceByName(gh_car(sublist)); - sublist=gh_cdr(sublist); - } else if( gh_eq_p(value,gh_symbol2scm("wait-at-resource")) ) { - res->WaitAtResource=gh_scm2int(gh_car(sublist)); - sublist=gh_cdr(sublist); - } else if( gh_eq_p(value,gh_symbol2scm("wait-at-depot")) ) { - res->WaitAtDepot=gh_scm2int(gh_car(sublist)); - sublist=gh_cdr(sublist); - } else if( gh_eq_p(value,gh_symbol2scm("resource-capacity")) ) { - res->ResourceCapacity=gh_scm2int(gh_car(sublist)); - sublist=gh_cdr(sublist); - } else if( gh_eq_p(value,gh_symbol2scm("terrain-harvester")) ) { - res->TerrainHarvester=1; - } else if( gh_eq_p(value,gh_symbol2scm("lose-resources")) ) { - res->LoseResources=1; - } else if( gh_eq_p(value,gh_symbol2scm("harvest-from-outside")) ) { - res->HarvestFromOutside=1; - } else if( gh_eq_p(value,gh_symbol2scm("file-when-empty")) ) { - res->FileWhenLoaded=gh_scm2newstr(gh_car(sublist),0); - sublist=gh_cdr(sublist); - } else if( gh_eq_p(value,gh_symbol2scm("file-when-loaded")) ) { - res->FileWhenLoaded=gh_scm2newstr(gh_car(sublist),0); - sublist=gh_cdr(sublist); + } else if (gh_eq_p(value, gh_symbol2scm("building"))) { + type->Building = 1; + } else if (gh_eq_p(value, gh_symbol2scm("wall"))) { + type->Wall = 1; + } else if (gh_eq_p(value, gh_symbol2scm("builder-outside"))) { + type->BuilderOutside = 1; + } else if (gh_eq_p(value, gh_symbol2scm("builder-lost"))) { + type->BuilderLost = 1; + } else if (gh_eq_p(value, gh_symbol2scm("auto-build-rate"))) { + type->AutoBuildRate = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("shore-building"))) { + type->ShoreBuilding = 1; + } else if (gh_eq_p(value, gh_symbol2scm("land-unit"))) { + type->LandUnit = 1; + } else if (gh_eq_p(value, gh_symbol2scm("air-unit"))) { + type->AirUnit = 1; + } else if (gh_eq_p(value, gh_symbol2scm("sea-unit"))) { + type->SeaUnit = 1; + } else if (gh_eq_p(value, gh_symbol2scm("random-movement-probability"))) { + type->RandomMovementProbability = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("clicks-to-explode"))) { + type->ClicksToExplode = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("sniper"))) { + type->Sniper = 1; + } else if (gh_eq_p(value, gh_symbol2scm("permanent-cloak"))) { + type->PermanentCloak = 1; + } else if (gh_eq_p(value, gh_symbol2scm("detect-cloak"))) { + type->DetectCloak = 1; + } else if (gh_eq_p(value, gh_symbol2scm("transporter"))) { + type->Transporter = 1; + } else if (gh_eq_p(value, gh_symbol2scm("coward"))) { + type->Coward = 1; + } else if (gh_eq_p(value, gh_symbol2scm("can-gather-resource"))) { + sublist = gh_car(list); + list = gh_cdr(list); + res = (ResourceInfo*)malloc(sizeof(ResourceInfo)); + memset(res, 0, sizeof(ResourceInfo)); + while (!gh_null_p(sublist)) { + value = gh_car(sublist); + sublist = gh_cdr(sublist); + if (gh_eq_p(value, gh_symbol2scm("resource-id"))) { + res->ResourceId = CclGetResourceByName(gh_car(sublist)); + type->ResInfo[res->ResourceId] = res; + sublist = gh_cdr(sublist); + } else if (gh_eq_p(value, gh_symbol2scm("resource-step"))) { + res->ResourceStep = gh_scm2int(gh_car(sublist)); + sublist = gh_cdr(sublist); + } else if (gh_eq_p(value, gh_symbol2scm("final-resource"))) { + res->FinalResource = CclGetResourceByName(gh_car(sublist)); + sublist = gh_cdr(sublist); + } else if (gh_eq_p(value, gh_symbol2scm("wait-at-resource"))) { + res->WaitAtResource = gh_scm2int(gh_car(sublist)); + sublist = gh_cdr(sublist); + } else if (gh_eq_p(value, gh_symbol2scm("wait-at-depot"))) { + res->WaitAtDepot = gh_scm2int(gh_car(sublist)); + sublist = gh_cdr(sublist); + } else if (gh_eq_p(value, gh_symbol2scm("resource-capacity"))) { + res->ResourceCapacity = gh_scm2int(gh_car(sublist)); + sublist = gh_cdr(sublist); + } else if (gh_eq_p(value, gh_symbol2scm("terrain-harvester"))) { + res->TerrainHarvester = 1; + } else if (gh_eq_p(value, gh_symbol2scm("lose-resources"))) { + res->LoseResources = 1; + } else if (gh_eq_p(value, gh_symbol2scm("harvest-from-outside"))) { + res->HarvestFromOutside = 1; + } else if (gh_eq_p(value, gh_symbol2scm("file-when-empty"))) { + res->FileWhenLoaded = gh_scm2newstr(gh_car(sublist),0); + sublist = gh_cdr(sublist); + } else if (gh_eq_p(value, gh_symbol2scm("file-when-loaded"))) { + res->FileWhenLoaded = gh_scm2newstr(gh_car(sublist),0); + sublist = gh_cdr(sublist); } else { printf("\n%s\n",type->Name); - errl("Unsupported tag",value); - DebugCheck( 1 ); + errl("Unsupported tag", value); + DebugCheck(1); } } - type->Harvester=1; + type->Harvester = 1; if (!res->FinalResource) { - res->FinalResource=res->ResourceId; + res->FinalResource = res->ResourceId; } DebugCheck(!res->ResourceId); - } else if( gh_eq_p(value,gh_symbol2scm("gives-resource")) ) { - type->GivesResource=CclGetResourceByName(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("max-workers")) ) { - type->MaxWorkers=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("can-harvest")) ) { - type->CanHarvest=1; - } else if( gh_eq_p(value,gh_symbol2scm("can-store")) ) { - sublist=gh_car(list); - list=gh_cdr(list); - while( !gh_null_p(sublist) ) { - type->CanStore[CclGetResourceByName(gh_car(sublist))]=1; - sublist=gh_cdr(sublist); + } else if (gh_eq_p(value, gh_symbol2scm("gives-resource"))) { + type->GivesResource = CclGetResourceByName(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("max-workers"))) { + type->MaxWorkers = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("can-harvest"))) { + type->CanHarvest = 1; + } else if (gh_eq_p(value, gh_symbol2scm("can-store"))) { + sublist = gh_car(list); + list = gh_cdr(list); + while (!gh_null_p(sublist)) { + type->CanStore[CclGetResourceByName(gh_car(sublist))] = 1; + sublist = gh_cdr(sublist); } - } else if( gh_eq_p(value,gh_symbol2scm("vanishes")) ) { - type->Vanishes=1; - } else if( gh_eq_p(value,gh_symbol2scm("hero")) ) { - type->Hero=1; - } else if( gh_eq_p(value,gh_symbol2scm("volatile")) ) { - type->Volatile=1; - } else if( gh_eq_p(value,gh_symbol2scm("isundead")) ) { - type->IsUndead=1; - } else if( gh_eq_p(value,gh_symbol2scm("can-cast-spell")) ) { + } else if (gh_eq_p(value, gh_symbol2scm("vanishes"))) { + type->Vanishes = 1; + } else if (gh_eq_p(value, gh_symbol2scm("hero"))) { + type->Hero = 1; + } else if (gh_eq_p(value, gh_symbol2scm("volatile"))) { + type->Volatile = 1; + } else if (gh_eq_p(value, gh_symbol2scm("isundead"))) { + type->IsUndead = 1; + } else if (gh_eq_p(value, gh_symbol2scm("can-cast-spell"))) { // // Warning: can-cast-spell should only be used AFTER all spells // have been defined. FIXME: MaxSpellType=500 or something? // if (!type->CanCastSpell) { - type->CanCastSpell=malloc(SpellTypeCount); - memset(type->CanCastSpell,0,SpellTypeCount); + type->CanCastSpell = malloc(SpellTypeCount); + memset(type->CanCastSpell, 0, SpellTypeCount); } - sublist=gh_car(list); - list=gh_cdr(list); - while( !gh_null_p(sublist) ) { + sublist = gh_car(list); + list = gh_cdr(list); + while (!gh_null_p(sublist)) { DebugLevel3Fn("%d \n" _C_ CclGetSpellByIdent(gh_car(sublist))); - type->CanCastSpell[CclGetSpellByIdent(gh_car(sublist))]=1; - sublist=gh_cdr(sublist); + type->CanCastSpell[CclGetSpellByIdent(gh_car(sublist))] = 1; + sublist = gh_cdr(sublist); } - } else if( gh_eq_p(value,gh_symbol2scm("organic")) ) { - type->Organic=1; - } else if( gh_eq_p(value,gh_symbol2scm("selectable-by-rectangle")) ) { - type->SelectableByRectangle=1; - } else if( gh_eq_p(value,gh_symbol2scm("teleporter")) ) { - type->Teleporter=1; - } else if( gh_eq_p(value,gh_symbol2scm("sounds")) ) { - sublist=gh_car(list); - list=gh_cdr(list); - while( !gh_null_p(sublist) ) { + } else if (gh_eq_p(value, gh_symbol2scm("organic"))) { + type->Organic = 1; + } else if (gh_eq_p(value, gh_symbol2scm("selectable-by-rectangle"))) { + type->SelectableByRectangle = 1; + } else if (gh_eq_p(value, gh_symbol2scm("teleporter"))) { + type->Teleporter = 1; + } else if (gh_eq_p(value, gh_symbol2scm("sounds"))) { + sublist = gh_car(list); + list = gh_cdr(list); + while (!gh_null_p(sublist)) { - value=gh_car(sublist); - sublist=gh_cdr(sublist); + value = gh_car(sublist); + sublist = gh_cdr(sublist); - if( gh_eq_p(value,gh_symbol2scm("selected")) ) { - if( redefine ) { + if (gh_eq_p(value, gh_symbol2scm("selected"))) { + if (redefine) { free(type->Sound.Selected.Name); } - type->Sound.Selected.Name=gh_scm2newstr( - gh_car(sublist),NULL); - sublist=gh_cdr(sublist); - } else if( gh_eq_p(value,gh_symbol2scm("acknowledge")) ) { - if( redefine ) { + type->Sound.Selected.Name = gh_scm2newstr( + gh_car(sublist), NULL); + sublist = gh_cdr(sublist); + } else if (gh_eq_p(value, gh_symbol2scm("acknowledge"))) { + if (redefine) { free(type->Sound.Acknowledgement.Name); } - type->Sound.Acknowledgement.Name=gh_scm2newstr( - gh_car(sublist),NULL); - sublist=gh_cdr(sublist); - } else if( gh_eq_p(value,gh_symbol2scm("ready")) ) { - if( redefine ) { + type->Sound.Acknowledgement.Name = gh_scm2newstr( + gh_car(sublist), NULL); + sublist = gh_cdr(sublist); + } else if (gh_eq_p(value, gh_symbol2scm("ready"))) { + if (redefine) { free(type->Sound.Ready.Name); } - type->Sound.Ready.Name=gh_scm2newstr( - gh_car(sublist),NULL); - sublist=gh_cdr(sublist); - } else if( gh_eq_p(value,gh_symbol2scm("help")) ) { - if( redefine ) { + type->Sound.Ready.Name = gh_scm2newstr( + gh_car(sublist), NULL); + sublist = gh_cdr(sublist); + } else if (gh_eq_p(value, gh_symbol2scm("help"))) { + if (redefine) { free(type->Sound.Help.Name); } - type->Sound.Help.Name=gh_scm2newstr( - gh_car(sublist),NULL); - sublist=gh_cdr(sublist); - } else if( gh_eq_p(value,gh_symbol2scm("dead")) ) { - if( redefine ) { + type->Sound.Help.Name = gh_scm2newstr( + gh_car(sublist), NULL); + sublist = gh_cdr(sublist); + } else if (gh_eq_p(value, gh_symbol2scm("dead"))) { + if (redefine) { free(type->Sound.Dead.Name); } - type->Sound.Dead.Name=gh_scm2newstr( - gh_car(sublist),NULL); - sublist=gh_cdr(sublist); - } else if( gh_eq_p(value,gh_symbol2scm("attack")) ) { - if( redefine ) { + type->Sound.Dead.Name = gh_scm2newstr( + gh_car(sublist), NULL); + sublist = gh_cdr(sublist); + } else if (gh_eq_p(value, gh_symbol2scm("attack"))) { + if (redefine) { free(type->Weapon.Attack.Name); } - type->Weapon.Attack.Name=gh_scm2newstr( - gh_car(sublist),NULL); - sublist=gh_cdr(sublist); + type->Weapon.Attack.Name = gh_scm2newstr( + gh_car(sublist), NULL); + sublist = gh_cdr(sublist); } else { - errl("Unsupported sound tag",value); + errl("Unsupported sound tag", value); } } #ifdef NEW_UI - } else if( gh_eq_p(value,gh_symbol2scm("add-buttons")) ) { - value=gh_car(list); - list=gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("add-buttons"))) { + value = gh_car(list); + list = gh_cdr(list); CclGcProtect(value); type->AddButtonsHook = value; #endif } else { // FIXME: this leaves a half initialized unit-type printf("\n%s\n",type->Name); - errl("Unsupported tag",value); - DebugCheck( 1 ); + errl("Unsupported tag", value); + DebugCheck(1); } } // // Unit type checks. // - if( type->CanCastSpell && !type->_MaxMana ) { + if (type->CanCastSpell && !type->_MaxMana) { DebugLevel0Fn("%s: Need max mana value\n" _C_ type->Ident); - type->_MaxMana=1; + type->_MaxMana = 1; } return SCM_UNSPECIFIED; @@ -631,75 +637,75 @@ local SCM CclDefineUnitStats(SCM list) int i; char* str; - type=UnitTypeByIdent(str=gh_scm2newstr(gh_car(list),NULL)); + type = UnitTypeByIdent(str = gh_scm2newstr(gh_car(list), NULL)); DebugCheck(!type); free(str); - list=gh_cdr(list); - i=gh_scm2int(gh_car(list)); - DebugCheck(i>=PlayerMax); - list=gh_cdr(list); + list = gh_cdr(list); + i = gh_scm2int(gh_car(list)); + DebugCheck(i >= PlayerMax); + list = gh_cdr(list); - stats=&type->Stats[i]; + stats = &type->Stats[i]; // // Parse the list: (still everything could be changed!) // - while( !gh_null_p(list) ) { + while (!gh_null_p(list)) { - value=gh_car(list); - list=gh_cdr(list); + value = gh_car(list); + list = gh_cdr(list); - if( gh_eq_p(value,gh_symbol2scm("level")) ) { - stats->Level=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("speed")) ) { - stats->Speed=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("attack-range")) ) { - stats->AttackRange=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("sight-range")) ) { - stats->SightRange=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("armor")) ) { - stats->Armor=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("basic-damage")) ) { - stats->BasicDamage=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("piercing-damage")) ) { - stats->PiercingDamage=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("hit-points")) ) { - stats->HitPoints=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("regeneration-rate")) ) { - stats->RegenerationRate=gh_scm2int(gh_car(list)); - list=gh_cdr(list); - } else if( gh_eq_p(value,gh_symbol2scm("costs")) ) { - sublist=gh_car(list); - list=gh_cdr(list); - while( !gh_null_p(sublist) ) { + if (gh_eq_p(value, gh_symbol2scm("level"))) { + stats->Level = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("speed"))) { + stats->Speed = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("attack-range"))) { + stats->AttackRange = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("sight-range"))) { + stats->SightRange = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("armor"))) { + stats->Armor = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("basic-damage"))) { + stats->BasicDamage = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("piercing-damage"))) { + stats->PiercingDamage = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("hit-points"))) { + stats->HitPoints = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("regeneration-rate"))) { + stats->RegenerationRate = gh_scm2int(gh_car(list)); + list = gh_cdr(list); + } else if (gh_eq_p(value, gh_symbol2scm("costs"))) { + sublist = gh_car(list); + list = gh_cdr(list); + while (!gh_null_p(sublist)) { - value=gh_car(sublist); - sublist=gh_cdr(sublist); + value = gh_car(sublist); + sublist = gh_cdr(sublist); - for( i=0; i<MaxCosts; ++i ) { - if( gh_eq_p(value,gh_symbol2scm(DefaultResourceNames[i])) ) { - stats->Costs[i]=gh_scm2int(gh_car(sublist)); + for (i = 0; i < MaxCosts; ++i) { + if (gh_eq_p(value, gh_symbol2scm(DefaultResourceNames[i]))) { + stats->Costs[i] = gh_scm2int(gh_car(sublist)); break; } } - if( i==MaxCosts ) { + if (i == MaxCosts) { // FIXME: this leaves half initialized stats - errl("Unsupported tag",value); + errl("Unsupported tag", value); } - sublist=gh_cdr(sublist); + sublist = gh_cdr(sublist); } } else { // FIXME: this leaves a half initialized unit - errl("Unsupported tag",value); + errl("Unsupported tag", value); } } @@ -717,7 +723,7 @@ global UnitType* CclGetUnitType(SCM ptr) UnitType* type; // Be kind allow also strings or symbols - if( (str = CclConvertToString(ptr)) != NULL ) { + if ((str = CclConvertToString(ptr)) != NULL) { DebugLevel3("CclGetUnitType: %s\n"_C_ str); type = UnitTypeByIdent(str); free(str); @@ -771,18 +777,15 @@ local SCM CclUnitType(SCM ident) UnitType* type; str = CclConvertToString(ident); - if (str) - { + if (str) { type = UnitTypeByIdent(str); printf("CclUnitType: '%s' -> '%ld'\n", str, (long)type); free(str); return CclMakeSmobObj(SiodUnitTypeTag, type); - } - else - { + } else { errl("CclUnitType: no unittype by ident: ", ident); return SCM_BOOL_F; - } + } } /** @@ -798,7 +801,7 @@ local SCM CclUnitTypeArray(void) array = cons_array(gh_int2scm(UnitTypeMax), NIL); - for( i=0; i<UnitTypeMax; ++i ) { + for (i = 0; i < UnitTypeMax; ++i) { value = CclMakeSmobObj(SiodUnitTypeTag, &UnitTypes[i]); gh_vector_set_x(array, gh_int2scm(i), value); } @@ -817,8 +820,8 @@ local SCM CclGetUnitTypeIdent(SCM ptr) const UnitType* type; SCM value; - type=CclGetUnitType(ptr); - value=gh_str02scm(type->Ident); + type = CclGetUnitType(ptr); + value = gh_str02scm(type->Ident); return value; } @@ -834,8 +837,8 @@ local SCM CclGetUnitTypeName(SCM ptr) const UnitType* type; SCM value; - type=CclGetUnitType(ptr); - value=gh_str02scm(type->Name); + type = CclGetUnitType(ptr); + value = gh_str02scm(type->Name); return value; } @@ -847,13 +850,13 @@ local SCM CclGetUnitTypeName(SCM ptr) ** ** @return The name of the unit-type. */ -local SCM CclSetUnitTypeName(SCM ptr,SCM name) +local SCM CclSetUnitTypeName(SCM ptr, SCM name) { UnitType* type; - type=CclGetUnitType(ptr); + type = CclGetUnitType(ptr); free(type->Name); - type->Name=gh_scm2newstr(name,NULL); + type->Name = gh_scm2newstr(name, NULL); return name; } @@ -871,7 +874,7 @@ local SCM CclGetUnitTypeProperty(SCM ptr) { const UnitType* type; - type=CclGetUnitType(ptr); + type = CclGetUnitType(ptr); return type->Property; } @@ -883,19 +886,19 @@ local SCM CclGetUnitTypeProperty(SCM ptr) ** ** @return The property of the unit-type. */ -local SCM CclSetUnitTypeProperty(SCM ptr,SCM property) +local SCM CclSetUnitTypeProperty(SCM ptr, SCM property) { UnitType* type; - type=CclGetUnitType(ptr); + type = CclGetUnitType(ptr); - if( type->Property ) { + if (type->Property) { // FIXME: old value must be unprotected!! } - if( !property ) { + if (!property) { DebugLevel0Fn("oops, my fault\n"); } - type->Property=property; + type->Property = property; CclGcProtect(type->Property); return property; @@ -911,8 +914,8 @@ local SCM CclDefineUnitTypeWcNames(SCM list) int i; char** cp; - if( (cp=UnitTypeWcNames) ) { // Free all old names - while( *cp ) { + if ((cp = UnitTypeWcNames)) { // Free all old names + while (*cp) { free(*cp++); } free(UnitTypeWcNames); @@ -921,13 +924,13 @@ local SCM CclDefineUnitTypeWcNames(SCM list) // // Get new table. // - i=gh_length(list); - UnitTypeWcNames=cp=malloc((i+1)*sizeof(char*)); - while( i-- ) { - *cp++=gh_scm2newstr(gh_car(list),NULL); - list=gh_cdr(list); + i = gh_length(list); + UnitTypeWcNames = cp = malloc((i + 1) * sizeof(char*)); + while (i--) { + *cp++ = gh_scm2newstr(gh_car(list), NULL); + list = gh_cdr(list); } - *cp=NULL; + *cp = NULL; return SCM_UNSPECIFIED; } @@ -950,59 +953,59 @@ local SCM CclDefineAnimations(SCM list) int i; int frame; - str=gh_scm2newstr(gh_car(list),NULL); - list=gh_cdr(list); - anims=calloc(1,sizeof(Animations)); + str = gh_scm2newstr(gh_car(list), NULL); + list = gh_cdr(list); + anims = calloc(1,sizeof(Animations)); - while( !gh_null_p(list) ) { - id=gh_car(list); - list=gh_cdr(list); - value=gh_car(list); - list=gh_cdr(list); + while (!gh_null_p(list)) { + id = gh_car(list); + list = gh_cdr(list); + value = gh_car(list); + list = gh_cdr(list); - t=anim=malloc(gh_length(value)*sizeof(Animation)); - frame=0; - while( !gh_null_p(value) ) { - t->Flags=gh_scm2int(gh_vector_ref(gh_car(value),gh_int2scm(0))); - t->Pixel=gh_scm2int(gh_vector_ref(gh_car(value),gh_int2scm(1))); - t->Sleep=gh_scm2int(gh_vector_ref(gh_car(value),gh_int2scm(2))); - i=gh_scm2int(gh_vector_ref(gh_car(value),gh_int2scm(3))); - t->Frame=i-frame; - frame=i; - if( t->Flags&AnimationRestart ) { - frame=0; + t = anim = malloc(gh_length(value) * sizeof(Animation)); + frame = 0; + while (!gh_null_p(value)) { + t->Flags = gh_scm2int(gh_vector_ref(gh_car(value), gh_int2scm(0))); + t->Pixel = gh_scm2int(gh_vector_ref(gh_car(value), gh_int2scm(1))); + t->Sleep = gh_scm2int(gh_vector_ref(gh_car(value), gh_int2scm(2))); + i = gh_scm2int(gh_vector_ref(gh_car(value), gh_int2scm(3))); + t->Frame = i - frame; + frame = i; + if (t->Flags&AnimationRestart) { + frame = 0; } ++t; - value=gh_cdr(value); + value = gh_cdr(value); } - t[-1].Flags|=0x80; // Marks end of list + t[-1].Flags |= 0x80; // Marks end of list - if( gh_eq_p(id,gh_symbol2scm("still")) ) { - if( anims->Still ) { + if (gh_eq_p(id, gh_symbol2scm("still"))) { + if (anims->Still) { free(anims->Still); } - anims->Still=anim; - } else if( gh_eq_p(id,gh_symbol2scm("move")) ) { - if( anims->Move ) { + anims->Still = anim; + } else if (gh_eq_p(id, gh_symbol2scm("move"))) { + if (anims->Move) { free(anims->Move); } - anims->Move=anim; - } else if( gh_eq_p(id,gh_symbol2scm("attack")) ) { - if( anims->Attack ) { + anims->Move = anim; + } else if (gh_eq_p(id, gh_symbol2scm("attack"))) { + if (anims->Attack) { free(anims->Attack); } anims->Attack=anim; - } else if( gh_eq_p(id,gh_symbol2scm("die")) ) { - if( anims->Die ) { + } else if (gh_eq_p(id, gh_symbol2scm("die"))) { + if (anims->Die) { free(anims->Die); } - anims->Die=anim; + anims->Die = anim; } else { - errl("Unsupported tag",id); + errl("Unsupported tag", id); } } - *(Animations**)hash_add(AnimationsHash,str)=anims; + *(Animations**)hash_add(AnimationsHash, str) = anims; free(str); return SCM_UNSPECIFIED; @@ -1015,30 +1018,30 @@ local SCM CclDefineAnimations(SCM list) */ global void UnitTypeCclRegister(void) { - gh_new_procedureN("define-unit-type",CclDefineUnitType); - gh_new_procedureN("define-unit-stats",CclDefineUnitStats); + gh_new_procedureN("define-unit-type", CclDefineUnitType); + gh_new_procedureN("define-unit-stats", CclDefineUnitStats); SiodUnitTypeTag = CclMakeSmobType("UnitType"); #ifndef USE_GUILE - set_print_hooks(SiodUnitTypeTag,CclUnitTypePrin1); + set_print_hooks(SiodUnitTypeTag, CclUnitTypePrin1); #endif - gh_new_procedure1_0("unit-type",CclUnitType); - gh_new_procedure0_0("unit-type-array",CclUnitTypeArray); + gh_new_procedure1_0("unit-type", CclUnitType); + gh_new_procedure0_0("unit-type-array", CclUnitTypeArray); // unit type structure access - gh_new_procedure1_0("get-unit-type-ident",CclGetUnitTypeIdent); - gh_new_procedure1_0("get-unit-type-name",CclGetUnitTypeName); - gh_new_procedure2_0("set-unit-type-name!",CclSetUnitTypeName); + gh_new_procedure1_0("get-unit-type-ident", CclGetUnitTypeIdent); + gh_new_procedure1_0("get-unit-type-name", CclGetUnitTypeName); + gh_new_procedure2_0("set-unit-type-name!", CclSetUnitTypeName); // FIXME: write the missing access functions - gh_new_procedure1_0("get-unit-type-property",CclGetUnitTypeProperty); - gh_new_procedure2_0("set-unit-type-property!",CclSetUnitTypeProperty); + gh_new_procedure1_0("get-unit-type-property", CclGetUnitTypeProperty); + gh_new_procedure2_0("set-unit-type-property!", CclSetUnitTypeProperty); - gh_new_procedureN("define-unittype-wc-names",CclDefineUnitTypeWcNames); + gh_new_procedureN("define-unittype-wc-names", CclDefineUnitTypeWcNames); - gh_new_procedureN("define-animations",CclDefineAnimations); + gh_new_procedureN("define-animations", CclDefineAnimations); } //@}