[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stratagus-CVS] stratagus/src/game trigger.c
From: |
Jimmy Salmon |
Subject: |
[Stratagus-CVS] stratagus/src/game trigger.c |
Date: |
Fri, 26 Sep 2003 22:52:19 -0400 |
CVSROOT: /cvsroot/stratagus
Module name: stratagus
Branch:
Changes by: Jimmy Salmon <address@hidden> 03/09/26 22:52:19
Modified files:
src/game : trigger.c
Log message:
Cleanup
Patches:
Index: stratagus/src/game/trigger.c
diff -u stratagus/src/game/trigger.c:1.42 stratagus/src/game/trigger.c:1.43
--- stratagus/src/game/trigger.c:1.42 Sun Aug 17 11:57:07 2003
+++ stratagus/src/game/trigger.c Fri Sep 26 22:52:18 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: trigger.c,v 1.42 2003/08/17 15:57:07 n0body Exp $
+// $Id: trigger.c,v 1.43 2003/09/27 02:52:18 jsalmon3 Exp $
//@{
@@ -124,32 +124,32 @@
// --------------------------------------------------------------------------
// Conditions
-local int CompareEq(int a,int b)
+local int CompareEq(int a, int b)
{
- return a==b;
+ return a == b;
}
-local int CompareNEq(int a,int b)
+local int CompareNEq(int a, int b)
{
- return a!=b;
+ return a != b;
}
-local int CompareGrEq(int a,int b)
+local int CompareGrEq(int a, int b)
{
- return a>=b;
+ return a >= b;
}
-local int CompareGr(int a,int b)
+local int CompareGr(int a, int b)
{
- return a>b;
+ return a > b;
}
-local int CompareLeEq(int a,int b)
+local int CompareLeEq(int a, int b)
{
- return a<=b;
+ return a <= b;
}
-local int CompareLe(int a,int b)
+local int CompareLe(int a, int b)
{
- return a<b;
+ return a < b;
}
-typedef int (*CompareFunction)(int,int);
+typedef int (*CompareFunction)(int, int);
/**
** Returns a function pointer to the comparison function
@@ -160,28 +160,23 @@
*/
local CompareFunction GetCompareFunction(const char* op)
{
- if( op[0]=='=' ) {
- if( (op[1]=='=' && op[2]=='\0') || (op[1]=='\0') ) {
+ if (op[0] == '=') {
+ if ((op[1] == '=' && op[2] == '\0') || (op[1] == '\0')) {
return &CompareEq;
}
- }
- else if( op[0]=='>' ) {
- if( op[1]=='=' && op[2]=='\0' ) {
+ } else if (op[0] == '>') {
+ if (op[1] == '=' && op[2] == '\0' ) {
return &CompareGrEq;
- }
- else if( op[1]=='\0' ) {
+ } else if (op[1] == '\0') {
return &CompareGr;
}
- }
- else if( op[0]=='<' ) {
- if( op[1]=='=' && op[2]=='\0' ) {
+ } else if (op[0] == '<') {
+ if (op[1] == '=' && op[2] == '\0') {
return &CompareLeEq;
- }
- else if( op[1]=='\0' ) {
+ } else if (op[1] == '\0') {
return &CompareLe;
}
- }
- else if( op[0]=='!' && op[1]=='=' && op[2]=='\0' ) {
+ } else if (op[0] == '!' && op[1] == '=' && op[2] == '\0' ) {
return &CompareNEq;
}
return NULL;
@@ -190,7 +185,7 @@
/**
** Player has the quantity of unit-type.
*/
-local SCM CclIfUnit(SCM player,SCM operation,SCM quantity,SCM unit)
+local SCM CclIfUnit(SCM player, SCM operation, SCM quantity, SCM unit)
{
int plynr;
int q;
@@ -199,55 +194,55 @@
const char* op;
CompareFunction compare;
- plynr=TriggerGetPlayer(player);
- op=get_c_string(operation);
- q=gh_scm2int(quantity);
- unittype=TriggerGetUnitType(unit);
-
- compare=GetCompareFunction(op);
- if( !compare ) {
- errl("Illegal comparison operation in if-unit",operation);
+ plynr = TriggerGetPlayer(player);
+ op = get_c_string(operation);
+ q = gh_scm2int(quantity);
+ unittype = TriggerGetUnitType(unit);
+
+ compare = GetCompareFunction(op);
+ if (!compare) {
+ errl("Illegal comparison operation in if-unit", operation);
}
- if( plynr==-1 ) {
- plynr=0;
- pn=PlayerMax;
+ if (plynr == -1) {
+ plynr = 0;
+ pn = PlayerMax;
} else {
- pn=plynr+1;
+ pn = plynr + 1;
}
- if( unittype==ANY_UNIT ) {
- for( ; plynr<pn; ++plynr ) {
+ if (unittype == ANY_UNIT) {
+ for (; plynr < pn; ++plynr) {
int j;
- for( j=0; j<NumUnitTypes; ++j ) {
- if( compare(Players[plynr].UnitTypesCount[j],q) ) {
+ for (j = 0; j < NumUnitTypes; ++j) {
+ if (compare(Players[plynr].UnitTypesCount[j], q)) {
return SCM_BOOL_T;
}
}
}
- } else if( unittype==ALL_UNITS ) {
- for( ; plynr<pn; ++plynr ) {
- if( compare(Players[plynr].TotalNumUnits,q) ) {
+ } else if (unittype == ALL_UNITS) {
+ for (; plynr < pn; ++plynr) {
+ if (compare(Players[plynr].TotalNumUnits, q)) {
return SCM_BOOL_T;
}
}
- } else if( unittype==ALL_FOODUNITS ) {
- for( ; plynr<pn; ++plynr ) {
- if( compare(Players[plynr].NumFoodUnits,q) ) {
+ } else if (unittype == ALL_FOODUNITS) {
+ for (; plynr < pn; ++plynr) {
+ if (compare(Players[plynr].NumFoodUnits, q)) {
return SCM_BOOL_T;
}
}
- } else if( unittype==ALL_BUILDINGS ) {
- for( ; plynr<pn; ++plynr ) {
- if( compare(Players[plynr].NumBuildings,q) ) {
+ } else if (unittype == ALL_BUILDINGS) {
+ for (; plynr < pn; ++plynr) {
+ if (compare(Players[plynr].NumBuildings, q)) {
return SCM_BOOL_T;
}
}
} else {
- for( ; plynr<pn; ++plynr ) {
+ for (; plynr < pn; ++plynr) {
DebugLevel3Fn("Player%d, %d == %s\n" _C_ plynr _C_ q _C_
unittype->Ident);
- if( compare(Players[plynr].UnitTypesCount[unittype->Type],q) ) {
+ if (compare(Players[plynr].UnitTypesCount[unittype->Type], q)) {
return SCM_BOOL_T;
}
}
@@ -277,23 +272,23 @@
int j;
int s;
- plynr=TriggerGetPlayer(gh_car(list));
- list=gh_cdr(list);
- compare=GetCompareFunction(get_c_string(gh_car(list)));
- if( !compare ) {
- errl("Illegal comparison operator in if-unit-at",gh_car(list));
- }
- list=gh_cdr(list);
- q=gh_scm2int(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))));
- list=gh_cdr(list);
- x2=gh_scm2int(gh_car(gh_car(list)));
- y2=gh_scm2int(gh_car(gh_cdr(gh_car(list))));
- list=gh_cdr(list);
+ plynr = TriggerGetPlayer(gh_car(list));
+ list = gh_cdr(list);
+ compare = GetCompareFunction(get_c_string(gh_car(list)));
+ if (!compare) {
+ errl("Illegal comparison operator in if-unit-at", gh_car(list));
+ }
+ list = gh_cdr(list);
+ q = gh_scm2int(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))));
+ list = gh_cdr(list);
+ x2 = gh_scm2int(gh_car(gh_car(list)));
+ y2 = gh_scm2int(gh_car(gh_cdr(gh_car(list))));
+ list = gh_cdr(list);
//
// Get all unit types in location.
@@ -304,29 +299,29 @@
// FIXME: I hope SelectUnits checks bounds?
// FIXME: Yes, but caller should check.
// NOTE: +1 right,bottom isn't inclusive :(
- an=SelectUnits(x1,y1,x2+1,y2+1,table);
+ an = SelectUnits(x1, y1, x2 + 1, y2 + 1, table);
//
// Count the requested units
//
- for( j=s=0; j<an; ++j ) {
- unit=table[j];
+ for (j = s = 0; j < an; ++j) {
+ unit = table[j];
//
// Check unit type
//
// FIXME: ALL_UNITS
- if( unittype==ANY_UNIT
- || (unittype==ALL_FOODUNITS && !unit->Type->Building)
- || (unittype==ALL_BUILDINGS && unit->Type->Building)
- || (unittype==unit->Type) ) {
+ if (unittype == ANY_UNIT ||
+ (unittype == ALL_FOODUNITS && !unit->Type->Building) ||
+ (unittype == ALL_BUILDINGS && unit->Type->Building) ||
+ (unittype == unit->Type)) {
//
// Check the player
//
- if( plynr==-1 || plynr==unit->Player->Player ) {
+ if (plynr == -1 || plynr == unit->Player->Player) {
++s;
}
}
}
- if( compare(s,q) ) {
+ if (compare(s, q)) {
return SCM_BOOL_T;
}
@@ -336,8 +331,8 @@
/**
** Player has the quantity of unit-type near to unit-type.
*/
-local SCM CclIfNearUnit(SCM player,SCM operation,SCM quantity,SCM unit,
- SCM nearunit)
+local SCM CclIfNearUnit(SCM player, SCM operation, SCM quantity, SCM unit,
+ SCM nearunit)
{
int plynr;
int q;
@@ -349,30 +344,30 @@
Unit* table[UnitMax];
CompareFunction compare;
- plynr=TriggerGetPlayer(player);
- op=get_c_string(operation);
- q=gh_scm2int(quantity);
- unittype=TriggerGetUnitType(unit);
- ut2=CclGetUnitType(nearunit);
-
- compare=GetCompareFunction(op);
- if( !compare ) {
- errl("Illegal comparison operation in if-near-unit",operation);
+ plynr = TriggerGetPlayer(player);
+ op = get_c_string(operation);
+ q = gh_scm2int(quantity);
+ unittype = TriggerGetUnitType(unit);
+ ut2 = CclGetUnitType(nearunit);
+
+ compare = GetCompareFunction(op);
+ if (!compare) {
+ errl("Illegal comparison operation in if-near-unit", operation);
}
//
// Get all unit types 'near'.
//
- n=FindUnitsByType(ut2,table);
+ n = FindUnitsByType(ut2, table);
DebugLevel3Fn("%s: %d\n" _C_ ut2->Ident _C_ n);
- for( i=0; i<n; ++i ) {
+ for (i = 0; i < n; ++i) {
Unit* unit;
Unit* around[UnitMax];
int an;
int j;
int s;
- unit=table[i];
+ unit = table[i];
#ifdef UNIT_ON_MAP
// FIXME: could be done faster?
@@ -380,46 +375,46 @@
// FIXME: I hope SelectUnits checks bounds?
// FIXME: Yes, but caller should check.
// NOTE: +1 right,bottom isn't inclusive :(
- if( unit->Type->UnitType==UnitTypeLand ) {
- an=SelectUnits(
- unit->X-1,unit->Y-1,
- unit->X+unit->Type->TileWidth+1,
- unit->Y+unit->Type->TileHeight+1,around);
+ if (unit->Type->UnitType == UnitTypeLand) {
+ an = SelectUnits(
+ unit->X - 1, unit->Y - 1,
+ unit->X + unit->Type->TileWidth + 1,
+ unit->Y + unit->Type->TileHeight + 1, around);
} else {
- an=SelectUnits(
- unit->X-2,unit->Y-2,
- unit->X+unit->Type->TileWidth+2,
- unit->Y+unit->Type->TileHeight+2,around);
+ an = SelectUnits(
+ unit->X - 2, unit->Y - 2,
+ unit->X + unit->Type->TileWidth + 2,
+ unit->Y + unit->Type->TileHeight + 2, around);
}
DebugLevel3Fn("Units around %d: %d\n" _C_ UnitNumber(unit) _C_ an);
//
// Count the requested units
//
- for( j=s=0; j<an; ++j ) {
- unit=around[j];
+ for (j = s = 0; j < an; ++j) {
+ unit = around[j];
//
// Check unit type
//
// FIXME: ALL_UNITS
- if( unittype==ANY_UNIT
- || (unittype==ALL_FOODUNITS && !unit->Type->Building)
- || (unittype==ALL_BUILDINGS && unit->Type->Building)
- || (unittype==unit->Type) ) {
+ if (unittype == ANY_UNIT ||
+ (unittype == ALL_FOODUNITS && !unit->Type->Building) ||
+ (unittype == ALL_BUILDINGS && unit->Type->Building) ||
+ (unittype == unit->Type)) {
//
// Check the player
//
- if( plynr==-1 || plynr==unit->Player->Player ) {
+ if (plynr == -1 || plynr == unit->Player->Player) {
++s;
}
}
}
// Check if we counted the unit near itself
- if( unittype==ANY_UNIT
- || (unittype==ALL_FOODUNITS && ut2->Building)
- || (unittype==ALL_BUILDINGS && ut2->Building) ) {
+ if (unittype == ANY_UNIT ||
+ (unittype == ALL_FOODUNITS && ut2->Building) ||
+ (unittype == ALL_BUILDINGS && ut2->Building)) {
--s;
}
- if( compare(s,q) ) {
+ if (compare(s, q)) {
return SCM_BOOL_T;
}
}
@@ -430,8 +425,8 @@
/**
** Player has the quantity of rescued unit-type near to unit-type.
*/
-local SCM CclIfRescuedNearUnit(SCM player,SCM operation,SCM quantity,SCM unit,
- SCM nearunit)
+local SCM CclIfRescuedNearUnit(SCM player, SCM operation, SCM quantity, SCM
unit,
+ SCM nearunit)
{
int plynr;
int q;
@@ -443,30 +438,30 @@
Unit* table[UnitMax];
CompareFunction compare;
- plynr=TriggerGetPlayer(player);
- op=get_c_string(operation);
- q=gh_scm2int(quantity);
- unittype=TriggerGetUnitType(unit);
- ut2=CclGetUnitType(nearunit);
-
- compare=GetCompareFunction(op);
- if( !compare ) {
- errl("Illegal comparison operation in if-rescued-near-unit",operation);
+ plynr = TriggerGetPlayer(player);
+ op = get_c_string(operation);
+ q = gh_scm2int(quantity);
+ unittype = TriggerGetUnitType(unit);
+ ut2 = CclGetUnitType(nearunit);
+
+ compare = GetCompareFunction(op);
+ if (!compare) {
+ errl("Illegal comparison operation in if-rescued-near-unit", operation);
}
//
// Get all unit types 'near'.
//
- n=FindUnitsByType(ut2,table);
+ n = FindUnitsByType(ut2, table);
DebugLevel3Fn("%s: %d\n" _C_ ut2->Ident _C_ n);
- for( i=0; i<n; ++i ) {
+ for (i = 0; i < n; ++i) {
Unit* unit;
Unit* around[UnitMax];
int an;
int j;
int s;
- unit=table[i];
+ unit = table[i];
#ifdef UNIT_ON_MAP
// FIXME: could be done faster?
@@ -474,48 +469,48 @@
// FIXME: I hope SelectUnits checks bounds?
// FIXME: Yes, but caller should check.
// NOTE: +1 right,bottom isn't inclusive :(
- if( unit->Type->UnitType==UnitTypeLand ) {
+ if (unit->Type->UnitType == UnitTypeLand) {
an=SelectUnits(
- unit->X-1,unit->Y-1,
- unit->X+unit->Type->TileWidth+1,
- unit->Y+unit->Type->TileHeight+1,around);
+ unit->X - 1, unit->Y - 1,
+ unit->X + unit->Type->TileWidth + 1,
+ unit->Y + unit->Type->TileHeight + 1, around);
} else {
an=SelectUnits(
- unit->X-2,unit->Y-2,
- unit->X+unit->Type->TileWidth+2,
- unit->Y+unit->Type->TileHeight+2,around);
+ unit->X - 2, unit->Y - 2,
+ unit->X + unit->Type->TileWidth + 2,
+ unit->Y + unit->Type->TileHeight + 2, around);
}
DebugLevel3Fn("Units around %d: %d\n" _C_ UnitNumber(unit) _C_ an);
//
// Count the requested units
//
- for( j=s=0; j<an; ++j ) {
- unit=around[j];
- if( unit->RescuedFrom ) { // only rescued units
+ for (j = s = 0; j < an; ++j) {
+ unit = around[j];
+ if (unit->RescuedFrom) { // only rescued units
//
// Check unit type
//
// FIXME: ALL_UNITS
- if( unittype==ANY_UNIT
- || (unittype==ALL_FOODUNITS && !unit->Type->Building)
- || (unittype==ALL_BUILDINGS && unit->Type->Building)
- || (unittype==unit->Type) ) {
+ if (unittype == ANY_UNIT ||
+ (unittype == ALL_FOODUNITS && !unit->Type->Building) ||
+ (unittype == ALL_BUILDINGS && unit->Type->Building) ||
+ (unittype == unit->Type)) {
//
// Check the player
//
- if( plynr==-1 || plynr==unit->Player->Player ) {
+ if (plynr == -1 || plynr == unit->Player->Player) {
++s;
}
}
}
}
// Check if we counted the unit near itself
- if( unittype==ANY_UNIT
- || (unittype==ALL_FOODUNITS && ut2->Building)
- || (unittype==ALL_BUILDINGS && ut2->Building) ) {
+ if (unittype == ANY_UNIT ||
+ (unittype == ALL_FOODUNITS && ut2->Building) ||
+ (unittype == ALL_BUILDINGS && ut2->Building)) {
--s;
}
- if( compare(s,q) ) {
+ if (compare(s, q)) {
return SCM_BOOL_T;
}
}
@@ -526,7 +521,7 @@
/**
** Player has n opponents left.
*/
-local SCM CclIfOpponents(SCM player,SCM operation,SCM quantity)
+local SCM CclIfOpponents(SCM player, SCM operation, SCM quantity)
{
int plynr;
int q;
@@ -535,38 +530,38 @@
const char* op;
CompareFunction compare;
- plynr=TriggerGetPlayer(player);
- op=get_c_string(operation);
- q=gh_scm2int(quantity);
-
- compare=GetCompareFunction(op);
- if( !compare ) {
- errl("Illegal comparison operation in if-opponents",operation);
+ plynr = TriggerGetPlayer(player);
+ op = get_c_string(operation);
+ q = gh_scm2int(quantity);
+
+ compare = GetCompareFunction(op);
+ if (!compare) {
+ errl("Illegal comparison operation in if-opponents", operation);
}
- if( plynr==-1 ) {
- plynr=0;
- pn=PlayerMax;
+ if (plynr == -1) {
+ plynr = 0;
+ pn = PlayerMax;
} else {
- pn=plynr+1;
+ pn = plynr + 1;
}
//
// Check the player opponents
//
- for( n=0; plynr<pn; ++plynr ) {
+ for (n = 0; plynr < pn; ++plynr) {
int i;
- for( i=0; i<PlayerMax; ++i ) {
+ for (i = 0; i < PlayerMax; ++i) {
//
// This player is our enemy and has units left.
//
- if( (Players[i].Enemy&(1<<plynr)) && Players[i].TotalNumUnits ) {
+ if ((Players[i].Enemy & (1 << plynr)) && Players[i].TotalNumUnits) {
++n;
}
}
DebugLevel3Fn("Opponents of %d = %d\n" _C_ plynr _C_ n);
- if( compare(n,q) ) {
+ if (compare(n, q)) {
return SCM_BOOL_T;
}
}
@@ -577,7 +572,7 @@
/**
** Player has the quantity of resource.
*/
-local SCM CclIfResource(SCM player,SCM operation,SCM quantity,SCM resource)
+local SCM CclIfResource(SCM player, SCM operation, SCM quantity, SCM resource)
{
int plynr;
int q;
@@ -587,52 +582,52 @@
CompareFunction compare;
int i;
- plynr=TriggerGetPlayer(player);
- op=get_c_string(operation);
- q=gh_scm2int(quantity);
- res=get_c_string(resource);
-
- compare=GetCompareFunction(op);
- if( !compare ) {
- errl("Illegal comparison operation in if-resource",operation);
+ plynr = TriggerGetPlayer(player);
+ op = get_c_string(operation);
+ q = gh_scm2int(quantity);
+ res = get_c_string(resource);
+
+ compare = GetCompareFunction(op);
+ if (!compare) {
+ errl("Illegal comparison operation in if-resource", operation);
}
- if( plynr==-1 ) {
- plynr=0;
- pn=PlayerMax;
+ if (plynr == -1) {
+ plynr = 0;
+ pn = PlayerMax;
} else {
- pn=plynr+1;
+ pn = plynr+1;
}
- for( i=0; i<MaxCosts; ++i ) {
- if( !strcmp(res, DefaultResourceNames[i]) ) {
- for( ; plynr<pn; ++plynr ) {
- if( compare(Players[plynr].Resources[i],q) ) {
+ for (i = 0; i < MaxCosts; ++i) {
+ if (!strcmp(res, DefaultResourceNames[i])) {
+ for (; plynr < pn; ++plynr) {
+ if (compare(Players[plynr].Resources[i], q)) {
return SCM_BOOL_T;
}
}
return SCM_BOOL_F;
}
}
- if( !strcmp(res, "all") ) {
+ if (!strcmp(res, "all")) {
int j;
int sum;
- sum=0;
- for( ; plynr<pn; ++plynr ) {
- for( j=1; j<MaxCosts; ++j ) {
- sum+=Players[plynr].Resources[j];
+ sum = 0;
+ for (; plynr < pn; ++plynr) {
+ for (j = 1; j < MaxCosts; ++j) {
+ sum += Players[plynr].Resources[j];
}
}
- if( compare(sum,q) ) {
+ if (compare(sum, q)) {
return SCM_BOOL_T;
}
- } else if( !strcmp(res, "any") ) {
+ } else if (!strcmp(res, "any")) {
int j;
- for( ; plynr<pn; ++plynr ) {
- for( j=1; j<MaxCosts; ++j ) {
- if( compare(Players[plynr].Resources[j],q) ) {
+ for (; plynr < pn; ++plynr) {
+ for (j = 1; j < MaxCosts; ++j) {
+ if (compare(Players[plynr].Resources[j], q)) {
return SCM_BOOL_T;
}
}
@@ -645,7 +640,7 @@
/**
** Player has quantity kills
*/
-local SCM CclIfKills(SCM player,SCM operation,SCM quantity)
+local SCM CclIfKills(SCM player, SCM operation, SCM quantity)
{
int plynr;
int q;
@@ -654,24 +649,24 @@
const char* op;
CompareFunction compare;
- plynr=TriggerGetPlayer(player);
- op=get_c_string(operation);
- q=gh_scm2int(quantity);
-
- compare=GetCompareFunction(op);
- if( !compare ) {
- errl("Illegal comparison operation in if-kills",operation);
+ plynr = TriggerGetPlayer(player);
+ op = get_c_string(operation);
+ q = gh_scm2int(quantity);
+
+ compare = GetCompareFunction(op);
+ if (!compare) {
+ errl("Illegal comparison operation in if-kills", operation);
}
- if( plynr==-1 ) {
- plynr=0;
- pn=PlayerMax;
+ if (plynr == -1) {
+ plynr = 0;
+ pn = PlayerMax;
} else {
- pn=plynr+1;
+ pn = plynr + 1;
}
- for( n=0; plynr<pn; ++plynr ) {
- if( compare(Players[plynr].TotalKills,q) ) {
+ for (n = 0; plynr < pn; ++plynr) {
+ if (compare(Players[plynr].TotalKills, q)) {
return SCM_BOOL_T;
}
}
@@ -682,7 +677,7 @@
/**
** Player has a certain score
*/
-local SCM CclIfScore(SCM player,SCM operation,SCM quantity)
+local SCM CclIfScore(SCM player, SCM operation, SCM quantity)
{
int plynr;
int q;
@@ -691,24 +686,24 @@
const char* op;
CompareFunction compare;
- plynr=TriggerGetPlayer(player);
- op=get_c_string(operation);
- q=gh_scm2int(quantity);
-
- compare=GetCompareFunction(op);
- if( !compare ) {
- errl("Illegal comparison operation in if-score",operation);
+ plynr = TriggerGetPlayer(player);
+ op = get_c_string(operation);
+ q = gh_scm2int(quantity);
+
+ compare = GetCompareFunction(op);
+ if (!compare) {
+ errl("Illegal comparison operation in if-score", operation);
}
- if( plynr==-1 ) {
- plynr=0;
- pn=PlayerMax;
+ if (plynr == -1) {
+ plynr = 0;
+ pn = PlayerMax;
} else {
- pn=plynr+1;
+ pn = plynr + 1;
}
- for( n=0; plynr<pn; ++plynr ) {
- if( compare(Players[plynr].Score,q) ) {
+ for (n = 0; plynr < pn; ++plynr) {
+ if (compare(Players[plynr].Score, q)) {
return SCM_BOOL_T;
}
}
@@ -719,21 +714,21 @@
/**
** Number of game cycles elapsed
*/
-local SCM CclIfElapsed(SCM operation,SCM quantity)
+local SCM CclIfElapsed(SCM operation, SCM quantity)
{
int q;
const char* op;
CompareFunction compare;
- op=get_c_string(operation);
- q=gh_scm2int(quantity);
+ op = get_c_string(operation);
+ q = gh_scm2int(quantity);
- compare=GetCompareFunction(op);
- if( !compare ) {
- errl("Illegal comparison operation in if-elapsed",operation);
+ compare = GetCompareFunction(op);
+ if (!compare) {
+ errl("Illegal comparison operation in if-elapsed", operation);
}
- if( compare(GameCycle,q) ) {
+ if (compare(GameCycle, q)) {
return SCM_BOOL_T;
}
@@ -743,25 +738,25 @@
/**
** Check the timer value
*/
-local SCM CclIfTimer(SCM operation,SCM quantity)
+local SCM CclIfTimer(SCM operation, SCM quantity)
{
int q;
const char* op;
CompareFunction compare;
- if( !GameTimer.Init ) {
+ if (!GameTimer.Init) {
return SCM_BOOL_F;
}
- op=get_c_string(operation);
- q=gh_scm2int(quantity);
+ op = get_c_string(operation);
+ q = gh_scm2int(quantity);
- compare=GetCompareFunction(op);
- if( !compare ) {
- errl("Illegal comparison operation in if-timer",operation);
+ compare = GetCompareFunction(op);
+ if (!compare) {
+ errl("Illegal comparison operation in if-timer", operation);
}
- if( compare(GameTimer.Cycles,q) ) {
+ if (compare(GameTimer.Cycles, q)) {
return SCM_BOOL_T;
}
@@ -771,26 +766,26 @@
/**
** Check the switch value
*/
-local SCM CclIfSwitch(SCM number,SCM set)
+local SCM CclIfSwitch(SCM number, SCM set)
{
int i;
unsigned char s;
- i=gh_scm2int(number);
- if( i<0 || i>=MAX_SWITCH ) {
- errl("Invalid switch number",number);
+ i = gh_scm2int(number);
+ if (i < 0 || i >= MAX_SWITCH) {
+ errl("Invalid switch number", number);
}
- if( gh_boolean_p(set) ) {
- s=gh_scm2bool(set);
+ if (gh_boolean_p(set)) {
+ s = gh_scm2bool(set);
} else {
- s=gh_scm2int(set);
- if( s ) {
- s=1;
+ s = gh_scm2int(set);
+ if (s) {
+ s = 1;
}
}
- if( Switch[i]==s ) {
+ if (Switch[i] == s) {
return SCM_BOOL_T;
}
return SCM_BOOL_F;
@@ -804,9 +799,9 @@
*/
local SCM CclActionVictory(void)
{
- GameResult=GameVictory;
- GamePaused=1;
- GameRunning=0;
+ GameResult = GameVictory;
+ GamePaused = 1;
+ GameRunning = 0;
return SCM_UNSPECIFIED;
}
@@ -815,9 +810,9 @@
*/
local SCM CclActionDefeat(void)
{
- GameResult=GameDefeat;
- GamePaused=1;
- GameRunning=0;
+ GameResult = GameDefeat;
+ GamePaused = 1;
+ GameRunning = 0;
return SCM_UNSPECIFIED;
}
@@ -826,9 +821,9 @@
*/
local SCM CclActionDraw(void)
{
- GameResult=GameDraw;
- GamePaused=1;
- GameRunning=0;
+ GameResult = GameDraw;
+ GamePaused = 1;
+ GameRunning = 0;
return SCM_UNSPECIFIED;
}
@@ -837,10 +832,10 @@
*/
local SCM CclActionSetTimer(SCM cycles, SCM increasing)
{
- GameTimer.Cycles=gh_scm2int(cycles);
- GameTimer.Increasing=gh_scm2int(increasing);
- GameTimer.Init=1;
- GameTimer.LastUpdate=GameCycle;
+ GameTimer.Cycles = gh_scm2int(cycles);
+ GameTimer.Increasing = gh_scm2int(increasing);
+ GameTimer.Init = 1;
+ GameTimer.LastUpdate = GameCycle;
return SCM_UNSPECIFIED;
}
@@ -850,8 +845,8 @@
*/
local SCM CclActionStartTimer(void)
{
- GameTimer.Running=1;
- GameTimer.Init=1;
+ GameTimer.Running = 1;
+ GameTimer.Init = 1;
return SCM_UNSPECIFIED;
}
@@ -860,7 +855,7 @@
*/
local SCM CclActionStopTimer(void)
{
- GameTimer.Running=0;
+ GameTimer.Running = 0;
return SCM_UNSPECIFIED;
}
@@ -869,41 +864,41 @@
*/
local SCM CclActionWait(SCM ms)
{
- WaitFrame=FrameCounter+
- (FRAMES_PER_SECOND*VideoSyncSpeed/100*gh_scm2int(ms)+999)/1000;
+ WaitFrame = FrameCounter +
+ (FRAMES_PER_SECOND * VideoSyncSpeed / 100 * gh_scm2int(ms) + 999) /
1000;
return SCM_UNSPECIFIED;
}
/**
** Action stop timer
*/
-local SCM CclActionSetSwitch(SCM number,SCM set)
+local SCM CclActionSetSwitch(SCM number, SCM set)
{
int i;
unsigned char s;
- i=gh_scm2int(number);
- if( i<0 || i>=MAX_SWITCH ) {
- errl("Invalid switch number",number);
+ i = gh_scm2int(number);
+ if (i < 0 || i >= MAX_SWITCH) {
+ errl("Invalid switch number", number);
}
- if( gh_boolean_p(set) ) {
- s=gh_scm2bool(set);
+ if (gh_boolean_p(set)) {
+ s = gh_scm2bool(set);
} else {
- s=gh_scm2int(set);
- if( s ) {
- s=1;
+ s = gh_scm2int(set);
+ if (s) {
+ s = 1;
}
}
- Switch[i]=s;
+ Switch[i] = s;
return set;
}
/**
** Add a trigger.
*/
-local SCM CclAddTrigger(SCM condition,SCM action)
+local SCM CclAddTrigger(SCM condition, SCM action)
{
SCM var;
@@ -913,16 +908,16 @@
//
var = gh_symbol2scm("*triggers*");
- if( gh_null_p(symbol_value(var,NIL)) ) {
- puts("Trigger not set, defining trigger");
+ if (gh_null_p(symbol_value(var,NIL))) {
+ puts("Trigger not set, defining trigger");
setvar(var, cons(cons(condition,action),NIL), NIL);
} else {
// Search for the last element in the list
- var=symbol_value(var,NIL);
- while( !gh_null_p(gh_cdr(var)) ) {
- var=gh_cdr(var);
+ var = symbol_value(var, NIL);
+ while(!gh_null_p(gh_cdr(var))) {
+ var = gh_cdr(var);
}
- gh_set_cdr_x(var, cons(cons(condition,action),NIL));
+ gh_set_cdr_x(var, cons(cons(condition, action), NIL));
}
return SCM_UNSPECIFIED;
@@ -938,21 +933,21 @@
int num;
int i;
- num=gh_scm2int(number);
- if( num==-1 ) {
- Trigger=NULL;
+ num = gh_scm2int(number);
+ if (num == -1) {
+ Trigger = NULL;
} else {
- Trigger=symbol_value(gh_symbol2scm("*triggers*"),NIL);
- if( gh_null_p(Trigger) ) {
+ Trigger = symbol_value(gh_symbol2scm("*triggers*"), NIL);
+ if (gh_null_p(Trigger)) {
DebugLevel0Fn("Invalid trigger number: %d out of -1\n" _C_ num);
} else {
- for( i=0; i<num; ++i ) {
- if( gh_null_p(Trigger) ) {
+ for (i = 0; i < num; ++i) {
+ if (gh_null_p(Trigger)) {
DebugLevel0Fn("Invalid trigger number: %d out of %d\n" _C_
- num _C_ i-1);
+ num _C_ i - 1);
break;
}
- Trigger=gh_cdr(Trigger);
+ Trigger = gh_cdr(Trigger);
}
}
}
@@ -971,19 +966,19 @@
{
SCM value;
- value=NULL;
+ value = NULL;
- while( !gh_null_p(script) ) {
+ while (!gh_null_p(script)) {
value = gh_eval(gh_car(script), NIL);
- script=gh_cdr(script);
- if( WaitFrame>FrameCounter ) {
- WaitScript=script;
+ script = gh_cdr(script);
+ if (WaitFrame > FrameCounter) {
+ WaitScript = script;
return 0;
}
}
// If action returns false remove it
- if( gh_null_p(value) ) {
+ if (gh_null_p(value)) {
return 1;
}
return 0;
@@ -996,14 +991,14 @@
*/
local void TriggerRemoveTrigger(SCM trig)
{
- if( !gh_null_p(Trigger) ) {
- gh_set_car_x(trig,gh_car(Trigger));
- gh_set_cdr_x(trig,gh_cdr(Trigger));
+ if (!gh_null_p(Trigger)) {
+ gh_set_car_x(trig, gh_car(Trigger));
+ gh_set_cdr_x(trig, gh_cdr(Trigger));
} else {
gh_set_car_x(trig, NIL);
gh_set_cdr_x(trig, NIL);
}
- Trigger=trig;
+ Trigger = trig;
}
/**
@@ -1016,47 +1011,47 @@
SCM value;
SCM script;
- if( !Trigger ) {
- Trigger=symbol_value(gh_symbol2scm("*triggers*"),NIL);
+ if (!Trigger) {
+ Trigger = symbol_value(gh_symbol2scm("*triggers*"), NIL);
}
- trig=Trigger;
+ trig = Trigger;
- if( WaitFrame>FrameCounter ) {
+ if (WaitFrame > FrameCounter) {
return;
}
- if( WaitFrame && WaitFrame<=FrameCounter ) {
- WaitFrame=0;
- if( TriggerExecuteAction(WaitScript) ) {
+ if (WaitFrame && WaitFrame <= FrameCounter) {
+ WaitFrame = 0;
+ if (TriggerExecuteAction(WaitScript)) {
TriggerRemoveTrigger(WaitTrigger);
}
return;
}
- if( GamePaused ) {
+ if (GamePaused) {
return;
}
- if( !gh_null_p(trig) ) { // Next trigger
- pair=gh_car(trig);
- Trigger=gh_cdr(trig);
- WaitTrigger=trig;
+ if (!gh_null_p(trig)) { // Next trigger
+ pair = gh_car(trig);
+ Trigger = gh_cdr(trig);
+ WaitTrigger = trig;
// Pair is condition action
- if( !gh_null_p(pair) ) {
- script=gh_car(pair);
- value=NULL;
- while( !gh_null_p(script) ) {
- value=gh_eval(gh_car(script),NIL);
- script=gh_cdr(script);
+ if (!gh_null_p(pair)) {
+ script = gh_car(pair);
+ value = NULL;
+ while (!gh_null_p(script)) {
+ value = gh_eval(gh_car(script), NIL);
+ script = gh_cdr(script);
}
// If condition is true execute action
- if( value != SCM_BOOL_F ) {
- if( TriggerExecuteAction(gh_cdr(pair)) ) {
+ if (value != SCM_BOOL_F) {
+ if (TriggerExecuteAction(gh_cdr(pair))) {
TriggerRemoveTrigger(trig);
}
}
}
} else {
- Trigger=NULL;
+ Trigger = NULL;
}
}
@@ -1065,31 +1060,31 @@
*/
global void TriggerCclRegister(void)
{
- gh_new_procedure2_0("add-trigger",CclAddTrigger);
- gh_new_procedure1_0("set-trigger-number!",CclSetTriggerNumber);
+ gh_new_procedure2_0("add-trigger", CclAddTrigger);
+ gh_new_procedure1_0("set-trigger-number!", CclSetTriggerNumber);
// Conditions
- gh_new_procedure4_0("if-unit",CclIfUnit);
- gh_new_procedureN("if-unit-at",CclIfUnitAt);
- gh_new_procedure5_0("if-near-unit",CclIfNearUnit);
- gh_new_procedure5_0("if-rescued-near-unit",CclIfRescuedNearUnit);
- gh_new_procedure3_0("if-opponents",CclIfOpponents);
- gh_new_procedure4_0("if-resource",CclIfResource);
- gh_new_procedure3_0("if-kills",CclIfKills);
- gh_new_procedure3_0("if-score",CclIfScore);
- gh_new_procedure2_0("if-elapsed",CclIfElapsed);
- gh_new_procedure2_0("if-timer",CclIfTimer);
- gh_new_procedure2_0("if-switch",CclIfSwitch);
+ gh_new_procedure4_0("if-unit", CclIfUnit);
+ gh_new_procedureN("if-unit-at", CclIfUnitAt);
+ gh_new_procedure5_0("if-near-unit", CclIfNearUnit);
+ gh_new_procedure5_0("if-rescued-near-unit", CclIfRescuedNearUnit);
+ gh_new_procedure3_0("if-opponents", CclIfOpponents);
+ gh_new_procedure4_0("if-resource", CclIfResource);
+ gh_new_procedure3_0("if-kills", CclIfKills);
+ gh_new_procedure3_0("if-score", CclIfScore);
+ gh_new_procedure2_0("if-elapsed", CclIfElapsed);
+ gh_new_procedure2_0("if-timer", CclIfTimer);
+ gh_new_procedure2_0("if-switch", CclIfSwitch);
// Actions
- gh_new_procedure0_0("action-victory",CclActionVictory);
- gh_new_procedure0_0("action-defeat",CclActionDefeat);
- gh_new_procedure0_0("action-draw",CclActionDraw);
- gh_new_procedure2_0("action-set-timer",CclActionSetTimer);
- gh_new_procedure0_0("action-start-timer",CclActionStartTimer);
- gh_new_procedure0_0("action-stop-timer",CclActionStopTimer);
- gh_new_procedure1_0("action-wait",CclActionWait);
- gh_new_procedure2_0("action-set-switch",CclActionSetSwitch);
+ gh_new_procedure0_0("action-victory", CclActionVictory);
+ gh_new_procedure0_0("action-defeat", CclActionDefeat);
+ gh_new_procedure0_0("action-draw", CclActionDraw);
+ gh_new_procedure2_0("action-set-timer", CclActionSetTimer);
+ gh_new_procedure0_0("action-start-timer", CclActionStartTimer);
+ gh_new_procedure0_0("action-stop-timer", CclActionStopTimer);
+ gh_new_procedure1_0("action-wait", CclActionWait);
+ gh_new_procedure2_0("action-set-switch", CclActionSetSwitch);
- gh_define("*triggers*",NIL);
+ gh_define("*triggers*", NIL);
}
/**
@@ -1100,45 +1095,45 @@
** @param exp Expression
** @param f File to print to
*/
-local void PrintTrigger(SCM exp, CLFile *f)
+local void PrintTrigger(SCM exp, CLFile* f)
{
#ifdef USE_GUILE
#else
SCM tmp;
long n;
// struct user_type_hooks *p;
- extern char *subr_kind_str(long);
+ extern char* subr_kind_str(long);
STACK_CHECK(&exp);
INTERRUPT_CHECK();
switch TYPE(exp) {
case tc_nil:
- CLprintf(f,"()");
+ CLprintf(f, "()");
break;
case tc_cons:
- CLprintf(f,"(");
- PrintTrigger(car(exp),f);
- for(tmp=cdr(exp);CONSP(tmp);tmp=cdr(tmp)) {
- CLprintf(f," ");
- PrintTrigger(car(tmp),f);
- }
- if NNULLP(tmp) {
- CLprintf(f," . ");
- PrintTrigger(tmp,f);
+ CLprintf(f, "(");
+ PrintTrigger(car(exp), f);
+ for (tmp = cdr(exp); CONSP(tmp); tmp = cdr(tmp)) {
+ CLprintf(f, " ");
+ PrintTrigger(car(tmp), f);
+ }
+ if (NNULLP(tmp)) {
+ CLprintf(f, " . ");
+ PrintTrigger(tmp, f);
}
- CLprintf(f,")");
+ CLprintf(f, ")");
break;
case tc_flonum:
- n = (long) FLONM(exp);
- if (((double) n) == FLONM(exp)) {
- sprintf(tkbuffer,"%ld",n);
+ n = (long)FLONM(exp);
+ if (((double)n) == FLONM(exp)) {
+ sprintf(tkbuffer, "%ld", n);
} else {
- sprintf(tkbuffer,"%g",FLONM(exp));
+ sprintf(tkbuffer, "%g", FLONM(exp));
}
- CLprintf(f,tkbuffer);
+ CLprintf(f, tkbuffer);
break;
case tc_symbol:
- CLprintf(f,PNAME(exp));
+ CLprintf(f, PNAME(exp));
break;
case tc_subr_0:
case tc_subr_1:
@@ -1150,33 +1145,33 @@
case tc_lsubr:
case tc_fsubr:
case tc_msubr:
- sprintf(tkbuffer,"#<%s ",subr_kind_str(TYPE(exp)));
- CLprintf(f,tkbuffer);
- CLprintf(f,(*exp).storage_as.subr.name);
- CLprintf(f,">");
+ sprintf(tkbuffer, "#<%s ", subr_kind_str(TYPE(exp)));
+ CLprintf(f, tkbuffer);
+ CLprintf(f, (*exp).storage_as.subr.name);
+ CLprintf(f, ">");
break;
case tc_string:
- CLprintf(f,"\"%s\"",(*exp).storage_as.string.data);
+ CLprintf(f, "\"%s\"", (*exp).storage_as.string.data);
break;
case tc_closure:
- CLprintf(f,"(lambda ");
- if CONSP((*exp).storage_as.closure.code) {
- PrintTrigger(car((*exp).storage_as.closure.code),f);
- CLprintf(f," ");
- PrintTrigger(cdr((*exp).storage_as.closure.code),f);
+ CLprintf(f, "(lambda ");
+ if (CONSP((*exp).storage_as.closure.code)) {
+ PrintTrigger(car((*exp).storage_as.closure.code), f);
+ CLprintf(f, " ");
+ PrintTrigger(cdr((*exp).storage_as.closure.code), f);
} else
- PrintTrigger((*exp).storage_as.closure.code,f);
- CLprintf(f,")");
+ PrintTrigger((*exp).storage_as.closure.code, f);
+ CLprintf(f, ")");
break;
default:
break;
#if 0
p = get_user_type_hooks(TYPE(exp));
if (p->prin1)
- (*p->prin1)(exp,f);
+ (*p->prin1)(exp, f);
else {
- sprintf(tkbuffer,"#<UNKNOWN %d %p>",TYPE(exp),exp);
- CLprintf(f,tkbuffer);
+ sprintf(tkbuffer, "#<UNKNOWN %d %p>", TYPE(exp), exp);
+ CLprintf(f, tkbuffer);
}
#endif
}
@@ -1194,31 +1189,31 @@
int i;
int trigger;
- CLprintf(file,"\n;;; -----------------------------------------\n");
- CLprintf(file,";;; MODULE: trigger $Id: trigger.c,v 1.42 2003/08/17
15:57:07 n0body Exp $\n\n");
+ CLprintf(file, "\n;;; -----------------------------------------\n");
+ CLprintf(file, ";;; MODULE: trigger $Id: trigger.c,v 1.43 2003/09/27
02:52:18 jsalmon3 Exp $\n\n");
- i=0;
- trigger=-1;
- list=symbol_value(gh_symbol2scm("*triggers*"),NIL);
- while( !gh_null_p(list) ) {
- if( gh_eq_p(Trigger,list) ) {
- trigger=i;
- }
- CLprintf(file,"(add-trigger '");
- PrintTrigger(gh_car(gh_car(list)),file);
- CLprintf(file," '");
- PrintTrigger(gh_cdr(gh_car(list)),file);
- CLprintf(file,")\n");
- list=gh_cdr(list);
+ i = 0;
+ trigger = -1;
+ list = symbol_value(gh_symbol2scm("*triggers*"), NIL);
+ while (!gh_null_p(list)) {
+ if (gh_eq_p(Trigger, list)) {
+ trigger = i;
+ }
+ CLprintf(file, "(add-trigger '");
+ PrintTrigger(gh_car(gh_car(list)), file);
+ CLprintf(file, " '");
+ PrintTrigger(gh_cdr(gh_car(list)), file);
+ CLprintf(file, ")\n");
+ list = gh_cdr(list);
++i;
}
- CLprintf(file,"(set-trigger-number! %d)\n",trigger);
+ CLprintf(file, "(set-trigger-number! %d)\n", trigger);
- if( GameTimer.Init ) {
- CLprintf(file,"(action-set-timer %ld %d)\n",
- GameTimer.Cycles,GameTimer.Increasing);
- if( GameTimer.Running ) {
- CLprintf(file,"(action-start-timer)\n");
+ if (GameTimer.Init) {
+ CLprintf(file, "(action-set-timer %ld %d)\n",
+ GameTimer.Cycles, GameTimer.Increasing);
+ if (GameTimer.Running) {
+ CLprintf(file, "(action-start-timer)\n");
}
}
}
@@ -1231,16 +1226,16 @@
//
// Setup default triggers
//
- WaitFrame=0;
+ WaitFrame = 0;
// FIXME: choose the triggers for game type
- if( gh_null_p(symbol_value(gh_symbol2scm("*triggers*"),NIL)) ) {
+ if (gh_null_p(symbol_value(gh_symbol2scm("*triggers*"), NIL))) {
DebugLevel0Fn("Default triggers\n");
- gh_apply(symbol_value(gh_symbol2scm("single-player-triggers"),NIL),NIL);
+ gh_apply(symbol_value(gh_symbol2scm("single-player-triggers"), NIL),
NIL);
}
- memset(Switch,0,sizeof(Switch));
+ memset(Switch, 0, sizeof(Switch));
}
/**
@@ -1252,12 +1247,12 @@
DebugLevel0Fn("FIXME: Cleaning trigger not written\n");
- var=gh_symbol2scm("*triggers*");
- setvar(var,NIL,NIL);
+ var = gh_symbol2scm("*triggers*");
+ setvar(var, NIL, NIL);
- Trigger=NULL;
+ Trigger = NULL;
- memset(&GameTimer,0,sizeof(GameTimer));
+ memset(&GameTimer, 0, sizeof(GameTimer));
}
//@}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Stratagus-CVS] stratagus/src/game trigger.c,
Jimmy Salmon <=