[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stratagus-CVS] stratagus/src/clone mainloop.c player.c selecti...
From: |
Jimmy Salmon |
Subject: |
[Stratagus-CVS] stratagus/src/clone mainloop.c player.c selecti... |
Date: |
Thu, 09 Oct 2003 23:56:44 -0400 |
CVSROOT: /cvsroot/stratagus
Module name: stratagus
Branch:
Changes by: Jimmy Salmon <address@hidden> 03/10/09 23:56:41
Modified files:
src/clone : mainloop.c player.c selection.c spells.c
unit_find.c
Log message:
Cleanup
Patches:
Index: stratagus/src/clone/mainloop.c
diff -u stratagus/src/clone/mainloop.c:1.147
stratagus/src/clone/mainloop.c:1.148
--- stratagus/src/clone/mainloop.c:1.147 Tue Oct 7 20:06:40 2003
+++ stratagus/src/clone/mainloop.c Thu Oct 9 23:56:40 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: mainloop.c,v 1.147 2003/10/08 00:06:40 jsalmon3 Exp $
+// $Id: mainloop.c,v 1.148 2003/10/10 03:56:40 jsalmon3 Exp $
//@{
@@ -78,10 +78,10 @@
//----------------------------------------------------------------------------
/// variable set when we are scrolling via keyboard
-global enum _scroll_state_ KeyScrollState=ScrollNone;
+global enum _scroll_state_ KeyScrollState = ScrollNone;
/// variable set when we are scrolling via mouse
-global enum _scroll_state_ MouseScrollState=ScrollNone;
+global enum _scroll_state_ MouseScrollState = ScrollNone;
#if defined(DEBUG) && defined(HIERARCHIC_PATHFINDER)
global jmp_buf MainLoopJmpBuf; /// Hierarchic pathfinder error exit.
@@ -104,11 +104,11 @@
{
Viewport* vp;
- vp=TheUI.SelectedViewport;
- if( vp->MapY>step ) {
- vp->MapY-=step;
+ vp = TheUI.SelectedViewport;
+ if (vp->MapY > step) {
+ vp->MapY -= step;
} else {
- vp->MapY=0;
+ vp->MapY = 0;
}
}
@@ -121,11 +121,11 @@
{
Viewport* vp;
- vp=TheUI.SelectedViewport;
- if( vp->MapX>step ) {
- vp->MapX-=step;
+ vp = TheUI.SelectedViewport;
+ if (vp->MapX > step) {
+ vp->MapX -= step;
} else {
- vp->MapX=0;
+ vp->MapX = 0;
}
}
@@ -138,12 +138,12 @@
{
Viewport* vp;
- vp=TheUI.SelectedViewport;
- if( TheMap.Height>vp->MapHeight
- && vp->MapY<TheMap.Height-vp->MapHeight-step ) {
- vp->MapY+=step;
+ vp = TheUI.SelectedViewport;
+ if (TheMap.Height > vp->MapHeight &&
+ vp->MapY < TheMap.Height - vp->MapHeight - step) {
+ vp->MapY += step;
} else {
- vp->MapY=TheMap.Height-vp->MapHeight;
+ vp->MapY = TheMap.Height - vp->MapHeight;
}
}
@@ -156,12 +156,12 @@
{
Viewport* vp;
- vp=TheUI.SelectedViewport;
- if( TheMap.Width>vp->MapWidth
- && vp->MapX<TheMap.Width-vp->MapWidth-step) {
- vp->MapX+=step;
+ vp = TheUI.SelectedViewport;
+ if (TheMap.Width > vp->MapWidth &&
+ vp->MapX < TheMap.Width - vp->MapWidth - step) {
+ vp->MapX += step;
} else {
- vp->MapX=TheMap.Width-vp->MapWidth;
+ vp->MapX = TheMap.Width - vp->MapWidth;
}
}
@@ -184,14 +184,14 @@
int stepx;
int stepy;
- if( fast ) {
- stepx=TheUI.SelectedViewport->MapWidth/2;
- stepy=TheUI.SelectedViewport->MapHeight/2;
+ if (fast) {
+ stepx = TheUI.SelectedViewport->MapWidth / 2;
+ stepy = TheUI.SelectedViewport->MapHeight / 2;
} else { // dynamic: let these variables increase upto fast..
- stepx=stepy=1;
+ stepx = stepy = 1;
}
- switch( state ) {
+ switch (state) {
case ScrollUp:
MoveMapViewPointUp(stepy);
break;
@@ -223,9 +223,9 @@
default:
return; // skip marking map
}
- HandleMouseMove(CursorX,CursorY); // This recalulates some values
+ HandleMouseMove(CursorX, CursorY); // This recalulates some values
MarkDrawEntireMap();
- MustRedraw|=RedrawMinimap|RedrawCursors;
+ MustRedraw |= RedrawMinimap | RedrawCursors;
}
#ifdef DEBUG // {
@@ -238,13 +238,13 @@
*/
global void DebugTestDisplay(void)
{
- static int a=0;
+ static int a = 0;
extern void DebugTestDisplayLines(void);
- if( a ) {
+ if (a) {
return;
}
- a=1;
+ a = 1;
//Enable one function-call as type of test to show one time
DebugTestDisplayLines();
@@ -252,7 +252,7 @@
//DebugTestDisplayColorCube();
// put it all on screen (when it is not already there ;)
- InvalidateArea(0,0,VideoWidth,VideoHeight);
+ InvalidateArea(0, 0, VideoWidth, VideoHeight);
}
#endif // } DEBUG
@@ -267,39 +267,39 @@
local void DrawMenuButtonArea(void)
{
if (TheUI.MenuButtonGraphic.Graphic) {
- VideoDrawSub(TheUI.MenuButtonGraphic.Graphic,0,0,
- TheUI.MenuButtonGraphic.Graphic->Width,
- TheUI.MenuButtonGraphic.Graphic->Height,
- TheUI.MenuButtonGraphicX, TheUI.MenuButtonGraphicY);
+ VideoDrawSub(TheUI.MenuButtonGraphic.Graphic, 0, 0,
+ TheUI.MenuButtonGraphic.Graphic->Width,
+ TheUI.MenuButtonGraphic.Graphic->Height,
+ TheUI.MenuButtonGraphicX, TheUI.MenuButtonGraphicY);
}
- if( NetworkFildes==(Socket)-1 ) {
- if( TheUI.MenuButton.X!=-1 ) {
+ if (NetworkFildes == (Socket)-1) {
+ if (TheUI.MenuButton.X != -1) {
DrawMenuButton(TheUI.MenuButton.Button,
- (ButtonAreaUnderCursor==ButtonAreaMenu
- && ButtonUnderCursor==ButtonUnderMenu ?
MenuButtonActive : 0) |
- (GameMenuButtonClicked ? MenuButtonClicked : 0),
- TheUI.MenuButton.Width, TheUI.MenuButton.Height,
- TheUI.MenuButton.X,TheUI.MenuButton.Y,
- GameFont,TheUI.MenuButton.Text,NULL,NULL);
+ (ButtonAreaUnderCursor == ButtonAreaMenu
+ && ButtonUnderCursor == ButtonUnderMenu ? MenuButtonActive
: 0) |
+ (GameMenuButtonClicked ? MenuButtonClicked : 0),
+ TheUI.MenuButton.Width, TheUI.MenuButton.Height,
+ TheUI.MenuButton.X, TheUI.MenuButton.Y,
+ GameFont, TheUI.MenuButton.Text, NULL, NULL);
}
} else {
- if( TheUI.NetworkMenuButton.X!=-1 ) {
+ if (TheUI.NetworkMenuButton.X != -1) {
DrawMenuButton(TheUI.NetworkMenuButton.Button,
- (ButtonAreaUnderCursor==ButtonAreaMenu
- && ButtonUnderCursor==ButtonUnderNetworkMenu ?
MenuButtonActive : 0) |
- (GameMenuButtonClicked ? MenuButtonClicked : 0),
- TheUI.NetworkMenuButton.Width,
TheUI.NetworkMenuButton.Height,
- TheUI.NetworkMenuButton.X,TheUI.NetworkMenuButton.Y,
- GameFont,TheUI.NetworkMenuButton.Text,NULL,NULL);
+ (ButtonAreaUnderCursor == ButtonAreaMenu
+ && ButtonUnderCursor == ButtonUnderNetworkMenu ?
MenuButtonActive : 0) |
+ (GameMenuButtonClicked ? MenuButtonClicked : 0),
+ TheUI.NetworkMenuButton.Width, TheUI.NetworkMenuButton.Height,
+ TheUI.NetworkMenuButton.X, TheUI.NetworkMenuButton.Y,
+ GameFont, TheUI.NetworkMenuButton.Text, NULL, NULL);
}
- if( TheUI.NetworkDiplomacyButton.X!=-1 ) {
+ if (TheUI.NetworkDiplomacyButton.X != -1) {
DrawMenuButton(TheUI.NetworkDiplomacyButton.Button,
- (ButtonAreaUnderCursor==ButtonAreaMenu
- && ButtonUnderCursor==ButtonUnderNetworkDiplomacy ?
MenuButtonActive : 0) |
- (GameDiplomacyButtonClicked ? MenuButtonClicked : 0),
- TheUI.NetworkDiplomacyButton.Width,
TheUI.NetworkDiplomacyButton.Height,
-
TheUI.NetworkDiplomacyButton.X,TheUI.NetworkDiplomacyButton.Y,
- GameFont,TheUI.NetworkDiplomacyButton.Text,NULL,NULL);
+ (ButtonAreaUnderCursor == ButtonAreaMenu
+ && ButtonUnderCursor == ButtonUnderNetworkDiplomacy ?
MenuButtonActive : 0) |
+ (GameDiplomacyButtonClicked ? MenuButtonClicked : 0),
+ TheUI.NetworkDiplomacyButton.Width,
TheUI.NetworkDiplomacyButton.Height,
+ TheUI.NetworkDiplomacyButton.X, TheUI.NetworkDiplomacyButton.Y,
+ GameFont, TheUI.NetworkDiplomacyButton.Text, NULL, NULL);
}
}
@@ -309,18 +309,18 @@
//
{ int f;
- f=168*(NextFrameTicks-GetTicks());
- if( VideoSyncSpeed ) {
- f/=(100*1000/CYCLES_PER_SECOND)/VideoSyncSpeed;
+ f = 168 * (NextFrameTicks - GetTicks());
+ if (VideoSyncSpeed) {
+ f /= (100 * 1000 / CYCLES_PER_SECOND) / VideoSyncSpeed;
}
- if( f<0 || f>168 ) {
- f=168;
+ if (f < 0 || f > 168) {
+ f = 168;
}
- if( f ) {
- VideoDrawHLine(ColorGreen,TheUI.MenuButtonX,TheUI.MenuButtonY,f);
+ if (f) {
+ VideoDrawHLine(ColorGreen, TheUI.MenuButtonX, TheUI.MenuButtonY, f);
}
- if( 168-f ) {
- VideoDrawHLine(ColorRed,TheUI.MenuButtonX+f,TheUI.MenuButtonY,168-f);
+ if (168 - f) {
+ VideoDrawHLine(ColorRed, TheUI.MenuButtonX + f, TheUI.MenuButtonY, 168
- f);
}
}
//
@@ -330,19 +330,19 @@
int i;
int f;
- if( NetworkLag ) {
- for( i=0; i<PlayerMax; ++i ) {
- f=16-(16*(NetworkStatus[i]-GameCycle))/(NetworkLag*2);
- if( f<0 || f>16 ) {
- f=16;
+ if (NetworkLag) {
+ for (i = 0; i < PlayerMax; ++i) {
+ f = 16 - (16 * (NetworkStatus[i] - GameCycle)) / (NetworkLag * 2);
+ if (f < 0 || f > 16) {
+ f = 16;
}
- if( f ) {
+ if (f) {
VideoDrawHLine(ColorRed,
- TheUI.MenuButtonX,TheUI.MenuButtonY+1+i,f);
+ TheUI.MenuButtonX, TheUI.MenuButtonY + 1 + i, f);
}
- if( 16-f ) {
+ if (16 - f) {
VideoDrawHLine(ColorGreen,
- TheUI.MenuButtonX+f,TheUI.MenuButtonY+1+i,16-f);
+ TheUI.MenuButtonX + f, TheUI.MenuButtonY + 1 + i, 16 - f);
}
}
}
@@ -360,7 +360,7 @@
local void DrawMapViewport(Viewport* vp)
{
Unit* table[UnitMax];
- Missile* missiletable[MAX_MISSILES*9];
+ Missile* missiletable[MAX_MISSILES * 9];
int nunits;
int nmissiles;
int i;
@@ -373,13 +373,13 @@
// overlapping and draw only that what has changed..
// Every to-be-drawn item added to this mechanism, can be handed by this
// call.
- if( InterfaceState==IfaceStateNormal ) {
+ if (InterfaceState == IfaceStateNormal) {
// DecorationRefreshDisplay();
DecorationUpdateDisplay();
}
#else
- if( InterfaceState==IfaceStateNormal ) {
+ if (InterfaceState == IfaceStateNormal) {
#ifdef NEW_MAPDRAW
MapUpdateFogOfWar(vp->MapX, vp->MapY);
#else
@@ -387,90 +387,92 @@
// FIXME: Johns: this didn't work correct with viewports!
// FIXME: only needed until flags are correct set
- for( u=0; u < vp->MapHeight; ++u ) {
- MustRedrawRow[u]=1;
+ for (u = 0; u < vp->MapHeight; ++u) {
+ MustRedrawRow[u] = 1;
}
- for (u=0; u<vp->MapHeight*vp->MapWidth; ++u ) {
- MustRedrawTile[u]=1;
+ for (u = 0; u < vp->MapHeight * vp->MapWidth; ++u) {
+ MustRedrawTile[u] = 1;
}
#endif
//
// An unit is tracked, center viewport on this unit.
//
- if( vp->Unit ) {
- if( vp->Unit->Destroyed ||
- vp->Unit->Orders[0].Action==UnitActionDie ) {
- vp->Unit=NoUnitP;
+ if (vp->Unit) {
+ if (vp->Unit->Destroyed ||
+ vp->Unit->Orders[0].Action == UnitActionDie) {
+ vp->Unit = NoUnitP;
} else {
- ViewportCenterViewpoint(vp,vp->Unit->X,vp->Unit->Y);
+ ViewportCenterViewpoint(vp, vp->Unit->X, vp->Unit->Y);
}
}
- SetClipping(vp->X,vp->Y,vp->EndX,vp->EndY);
+ SetClipping(vp->X, vp->Y, vp->EndX, vp->EndY);
- DrawMapBackgroundInViewport(vp,vp->MapX,vp->MapY);
+ DrawMapBackgroundInViewport(vp, vp->MapX, vp->MapY);
//
// We find and sort units after draw level.
//
- nunits=FindAndSortUnits(vp,table);
- nmissiles=FindAndSortMissiles(vp,missiletable);
+ nunits = FindAndSortUnits(vp, table);
+ nmissiles = FindAndSortMissiles(vp, missiletable);
- i=0;
- j=0;
- CurrentViewport=vp;
- while( i<nunits && j<nmissiles ) {
- if( table[i]->Type->DrawLevel <= missiletable[j]->Type->DrawLevel )
{
- if( UnitVisibleInViewport(vp,table[i]) ) {
- if( table[i]->Type->Building ) {
+ i = 0;
+ j = 0;
+ CurrentViewport = vp;
+ while (i < nunits && j < nmissiles) {
+ if (table[i]->Type->DrawLevel <= missiletable[j]->Type->DrawLevel) {
+ if (UnitVisibleInViewport(vp, table[i])) {
+ if (table[i]->Type->Building) {
DrawBuilding(table[i]);
} else {
DrawUnit(table[i]);
}
}
- i++;
+ ++i;
} else {
x = missiletable[j]->X - vp->MapX * TileSizeX + vp->X;
y = missiletable[j]->Y - vp->MapY * TileSizeY + vp->Y;
// FIXME: I should copy SourcePlayer for second level missiles.
- if( missiletable[j]->SourceUnit &&
missiletable[j]->SourceUnit->Player ) {
+ if (missiletable[j]->SourceUnit &&
missiletable[j]->SourceUnit->Player) {
GraphicPlayerPixels(missiletable[j]->SourceUnit->Player,
missiletable[j]->Type->Sprite);
}
- switch( missiletable[j]->Type->Class ) {
+ switch (missiletable[j]->Type->Class) {
case MissileClassHit:
-
VideoDrawNumberClip(x,y,GameFont,missiletable[j]->Damage);
+ VideoDrawNumberClip(x, y, GameFont,
missiletable[j]->Damage);
break;
default:
-
DrawMissile(missiletable[j]->Type,missiletable[j]->SpriteFrame,x,y);
+ DrawMissile(missiletable[j]->Type,
missiletable[j]->SpriteFrame,
+ x, y);
break;
}
- j++;
+ ++j;
}
}
- for( ; i<nunits; ++i ) {
- if ( UnitVisibleInViewport(vp, table[i]) ) {
- if( table[i]->Type->Building ) {
+ for (; i < nunits; ++i) {
+ if (UnitVisibleInViewport(vp, table[i])) {
+ if (table[i]->Type->Building) {
DrawBuilding(table[i]);
} else {
DrawUnit(table[i]);
}
}
}
- for( ; j<nmissiles; ++j ) {
+ for (; j < nmissiles; ++j) {
x = missiletable[j]->X - vp->MapX * TileSizeX + vp->X;
y = missiletable[j]->Y - vp->MapY * TileSizeY + vp->Y;
// FIXME: I should copy SourcePlayer for second level missiles.
- if( missiletable[j]->SourceUnit &&
missiletable[j]->SourceUnit->Player ) {
+ if (missiletable[j]->SourceUnit &&
missiletable[j]->SourceUnit->Player) {
GraphicPlayerPixels(missiletable[j]->SourceUnit->Player,
missiletable[j]->Type->Sprite);
}
- switch( missiletable[j]->Type->Class ) {
+ switch (missiletable[j]->Type->Class) {
case MissileClassHit:
- VideoDrawNumberClip(x,y,GameFont,missiletable[j]->Damage);
+ VideoDrawNumberClip(x, y, GameFont,
missiletable[j]->Damage);
break;
default:
-
DrawMissile(missiletable[j]->Type,missiletable[j]->SpriteFrame,x,y);
+ DrawMissile(missiletable[j]->Type,
missiletable[j]->SpriteFrame,
+ x, y);
break;
}
}
@@ -479,19 +481,19 @@
// Draw orders of selected units.
// Drawn here so that they are shown even when the unit is out of
the screen.
//
- if( ShowOrders==SHOW_ORDERS_ALWAYS ||
- ((ShowOrdersCount>=GameCycle ||(KeyModifiers&ModifierShift))) )
{
- for (i=0;i<NumSelected;i++) {
+ if (ShowOrders == SHOW_ORDERS_ALWAYS ||
+ ((ShowOrdersCount >= GameCycle || (KeyModifiers &
ModifierShift)))) {
+ for (i = 0; i < NumSelected; ++i) {
ShowOrder(Selected[i]);
}
}
DrawConsole();
- SetClipping(0,0,VideoWidth-1,VideoHeight-1);
+ SetClipping(0, 0, VideoWidth - 1, VideoHeight - 1);
}
// Resources over map
- if (TheUI.ResourceX==-1 || TheUI.ResourceY==-1) {
- MustRedraw|=RedrawResources;
+ if (TheUI.ResourceX == -1 || TheUI.ResourceY == -1) {
+ MustRedraw |= RedrawResources;
}
#endif
}
@@ -508,7 +510,7 @@
const Viewport* evp;
// Draw all map viewports
- evp = TheUI.Viewports+TheUI.NumViewports;
+ evp = TheUI.Viewports + TheUI.NumViewports;
for (vp = TheUI.Viewports; vp < evp; ++vp) {
DrawMapViewport(vp);
}
@@ -549,77 +551,78 @@
*/
global void UpdateDisplay(void)
{
- MustRedraw&=EnableRedraw; // Don't redraw disabled parts
+ MustRedraw &= EnableRedraw; // Don't redraw disabled parts
VideoLockScreen(); // prepare video write
HideAnyCursor(); // remove cursor (when available)
- if( MustRedraw&RedrawMap ) {
+ if (MustRedraw & RedrawMap) {
DrawMapArea();
}
- if( MustRedraw&(RedrawMessage|RedrawMap) ) {
+ if (MustRedraw & (RedrawMessage | RedrawMap)) {
DrawMessages();
}
- if( MustRedraw&RedrawFillers ) {
+ if (MustRedraw & RedrawFillers) {
int i;
- for( i=0; i<TheUI.NumFillers; ++i ) {
- VideoDrawSubClip(TheUI.Filler[i].Graphic,0,0
- ,TheUI.Filler[i].Graphic->Width
- ,TheUI.Filler[i].Graphic->Height
- ,TheUI.FillerX[i],TheUI.FillerY[i]);
+ for (i = 0; i < TheUI.NumFillers; ++i) {
+ VideoDrawSubClip(TheUI.Filler[i].Graphic, 0, 0,
+ TheUI.Filler[i].Graphic->Width,
+ TheUI.Filler[i].Graphic->Height,
+ TheUI.FillerX[i], TheUI.FillerY[i]);
}
}
- if( MustRedraw&RedrawMenuButton ) {
+ if (MustRedraw & RedrawMenuButton) {
DrawMenuButtonArea();
}
- if( MustRedraw&RedrawMinimapBorder ) {
- VideoDrawSubClip(TheUI.MinimapPanel.Graphic,0,0
-
,TheUI.MinimapPanel.Graphic->Width,TheUI.MinimapPanel.Graphic->Height
- ,TheUI.MinimapPanelX,TheUI.MinimapPanelY);
+ if (MustRedraw & RedrawMinimapBorder) {
+ VideoDrawSubClip(TheUI.MinimapPanel.Graphic, 0, 0,
+ TheUI.MinimapPanel.Graphic->Width,
+ TheUI.MinimapPanel.Graphic->Height,
+ TheUI.MinimapPanelX, TheUI.MinimapPanelY);
}
PlayerPixels(Players); // Reset to default colors
- if( MustRedraw&RedrawMinimap ) {
+ if (MustRedraw & RedrawMinimap) {
// FIXME: redraw only 1* per second!
// HELPME: Viewpoint rectangle must be drawn faster (if implemented) ?
DrawMinimap(TheUI.SelectedViewport->MapX, TheUI.SelectedViewport->MapY);
DrawMinimapCursor(TheUI.SelectedViewport->MapX,
- TheUI.SelectedViewport->MapY);
- } else if( MustRedraw&RedrawMinimapCursor ) {
+ TheUI.SelectedViewport->MapY);
+ } else if (MustRedraw & RedrawMinimapCursor) {
HideMinimapCursor();
DrawMinimapCursor(TheUI.SelectedViewport->MapX,
- TheUI.SelectedViewport->MapY);
+ TheUI.SelectedViewport->MapY);
}
- if( MustRedraw&RedrawInfoPanel ) {
+ if (MustRedraw & RedrawInfoPanel) {
DrawInfoPanel();
PlayerPixels(Players); // Reset to default colors
}
- if( MustRedraw&RedrawButtonPanel ) {
+ if (MustRedraw & RedrawButtonPanel) {
DrawButtonPanel();
PlayerPixels(Players); // Reset to default colors
}
- if( MustRedraw&RedrawResources ) {
+ if (MustRedraw & RedrawResources) {
DrawResources();
}
- if( MustRedraw&RedrawStatusLine ) {
+ if (MustRedraw & RedrawStatusLine) {
DrawStatusLine();
- MustRedraw|=RedrawCosts;
+ MustRedraw |= RedrawCosts;
}
- if( MustRedraw&RedrawCosts ) {
+ if (MustRedraw & RedrawCosts) {
DrawCosts();
}
- if( MustRedraw&RedrawTimer ) {
+ if (MustRedraw & RedrawTimer) {
DrawTimer();
}
- if( MustRedraw&RedrawMenu ) {
+ if (MustRedraw & RedrawMenu) {
DrawMenu(CurrentMenu);
}
@@ -630,90 +633,92 @@
//
// Update changes to display.
//
- if( MustRedraw&RedrawAll ) {
+ if (MustRedraw & RedrawAll) {
// refresh entire screen, so no further invalidate needed
- InvalidateAreaAndCheckCursor(0,0,VideoWidth,VideoHeight);
+ InvalidateAreaAndCheckCursor(0, 0, VideoWidth, VideoHeight);
} else {
- if( MustRedraw&RedrawMap ) {
+ if (MustRedraw & RedrawMap) {
// FIXME: split into small parts see RedrawTile and RedrawRow
InvalidateAreaAndCheckCursor(
- TheUI.MapArea.X,TheUI.MapArea.Y
- ,TheUI.MapArea.EndX-TheUI.MapArea.X+1
- ,TheUI.MapArea.EndY-TheUI.MapArea.Y+1);
+ TheUI.MapArea.X, TheUI.MapArea.Y,
+ TheUI.MapArea.EndX - TheUI.MapArea.X + 1,
+ TheUI.MapArea.EndY - TheUI.MapArea.Y + 1);
}
- if( MustRedraw&RedrawFillers ) {
+ if (MustRedraw & RedrawFillers) {
int i;
- for( i=0; i<TheUI.NumFillers; ++i ) {
+ for (i = 0; i < TheUI.NumFillers; ++i) {
InvalidateAreaAndCheckCursor(
- TheUI.FillerX[i],TheUI.FillerY[i]
- ,TheUI.Filler[i].Graphic->Width
- ,TheUI.Filler[i].Graphic->Height);
+ TheUI.FillerX[i], TheUI.FillerY[i],
+ TheUI.Filler[i].Graphic->Width,
+ TheUI.Filler[i].Graphic->Height);
}
}
- if(MustRedraw&RedrawMenuButton ) {
- if( NetworkFildes==(Socket)-1 ) {
- if( TheUI.MenuButton.X!=-1 ) {
+ if(MustRedraw & RedrawMenuButton) {
+ if (NetworkFildes == (Socket)-1) {
+ if (TheUI.MenuButton.X != -1) {
InvalidateAreaAndCheckCursor(
- TheUI.MenuButton.X,TheUI.MenuButton.Y,
- TheUI.MenuButton.Width,
- TheUI.MenuButton.Height);
+ TheUI.MenuButton.X, TheUI.MenuButton.Y,
+ TheUI.MenuButton.Width,
+ TheUI.MenuButton.Height);
}
} else {
- if( TheUI.NetworkMenuButton.X!=-1 ) {
+ if (TheUI.NetworkMenuButton.X != -1) {
InvalidateAreaAndCheckCursor(
- TheUI.NetworkMenuButton.X,
- TheUI.NetworkMenuButton.Y,
- TheUI.NetworkMenuButton.Width,
- TheUI.NetworkMenuButton.Height);
+ TheUI.NetworkMenuButton.X,
+ TheUI.NetworkMenuButton.Y,
+ TheUI.NetworkMenuButton.Width,
+ TheUI.NetworkMenuButton.Height);
}
- if( TheUI.NetworkDiplomacyButton.X!=-1 ) {
+ if (TheUI.NetworkDiplomacyButton.X != -1) {
InvalidateAreaAndCheckCursor(
- TheUI.NetworkDiplomacyButton.X,
- TheUI.NetworkDiplomacyButton.Y,
- TheUI.NetworkDiplomacyButton.Width,
- TheUI.NetworkDiplomacyButton.Height);
+ TheUI.NetworkDiplomacyButton.X,
+ TheUI.NetworkDiplomacyButton.Y,
+ TheUI.NetworkDiplomacyButton.Width,
+ TheUI.NetworkDiplomacyButton.Height);
}
}
}
- if( MustRedraw&RedrawMinimapBorder ) {
+ if (MustRedraw & RedrawMinimapBorder) {
InvalidateAreaAndCheckCursor(
- TheUI.MinimapPanelX,TheUI.MinimapPanelY
-
,TheUI.MinimapPanel.Graphic->Width,TheUI.MinimapPanel.Graphic->Height);
- } else if( (MustRedraw&RedrawMinimap)
- || (MustRedraw&RedrawMinimapCursor) ) {
+ TheUI.MinimapPanelX, TheUI.MinimapPanelY,
+ TheUI.MinimapPanel.Graphic->Width,
+ TheUI.MinimapPanel.Graphic->Height);
+ } else if ((MustRedraw & RedrawMinimap) ||
+ (MustRedraw & RedrawMinimapCursor)) {
// FIXME: Redraws too much of the minimap
InvalidateAreaAndCheckCursor(
- TheUI.MinimapPosX,TheUI.MinimapPosY
- ,TheUI.MinimapW,TheUI.MinimapH);
+ TheUI.MinimapPosX, TheUI.MinimapPosY,
+ TheUI.MinimapW, TheUI.MinimapH);
}
- if( MustRedraw&RedrawInfoPanel ) {
+ if (MustRedraw & RedrawInfoPanel) {
InvalidateAreaAndCheckCursor(
- TheUI.InfoPanelX,TheUI.InfoPanelY
- ,TheUI.InfoPanelW,TheUI.InfoPanelH);
+ TheUI.InfoPanelX, TheUI.InfoPanelY,
+ TheUI.InfoPanelW, TheUI.InfoPanelH);
}
- if( MustRedraw&RedrawButtonPanel && TheUI.ButtonPanel.Graphic ) {
+ if ((MustRedraw & RedrawButtonPanel) && TheUI.ButtonPanel.Graphic) {
InvalidateAreaAndCheckCursor(
- TheUI.ButtonPanelX,TheUI.ButtonPanelY
- ,TheUI.ButtonPanel.Graphic->Width
- ,TheUI.ButtonPanel.Graphic->Height);
+ TheUI.ButtonPanelX, TheUI.ButtonPanelY,
+ TheUI.ButtonPanel.Graphic->Width,
+ TheUI.ButtonPanel.Graphic->Height);
}
- if( MustRedraw&RedrawResources && TheUI.Resource.Graphic) {
+ if (MustRedraw&RedrawResources && TheUI.Resource.Graphic) {
InvalidateAreaAndCheckCursor(
- TheUI.ResourceX,TheUI.ResourceY
- ,TheUI.Resource.Graphic->Width
- ,TheUI.Resource.Graphic->Height);
+ TheUI.ResourceX, TheUI.ResourceY,
+ TheUI.Resource.Graphic->Width,
+ TheUI.Resource.Graphic->Height);
}
- if( (MustRedraw&RedrawStatusLine || MustRedraw&RedrawCosts) &&
TheUI.StatusLine.Graphic ) {
+ if (((MustRedraw & RedrawStatusLine) || MustRedraw&RedrawCosts) &&
+ TheUI.StatusLine.Graphic) {
InvalidateAreaAndCheckCursor(
- TheUI.StatusLineX,TheUI.StatusLineY
- ,TheUI.StatusLine.Graphic->Width
- ,TheUI.StatusLine.Graphic->Height);
+ TheUI.StatusLineX, TheUI.StatusLineY,
+ TheUI.StatusLine.Graphic->Width,
+ TheUI.StatusLine.Graphic->Height);
}
- if( MustRedraw&RedrawTimer ) {
+ if (MustRedraw & RedrawTimer) {
// FIXME: Invalidate timer area
}
- if( MustRedraw&RedrawMenu ) {
+ if (MustRedraw & RedrawMenu) {
InvalidateMenuAreas();
}
@@ -728,7 +733,7 @@
*/
local void EnableDrawRefresh(void)
{
- MustRedraw=RedrawEverything;
+ MustRedraw = RedrawEverything;
MarkDrawEntireMap();
}
@@ -751,52 +756,45 @@
#endif
int RealVideoSyncSpeed;
- GameCallbacks.ButtonPressed=(void*)HandleButtonDown;
- GameCallbacks.ButtonReleased=(void*)HandleButtonUp;
- GameCallbacks.MouseMoved=(void*)HandleMouseMove;
- GameCallbacks.MouseExit=(void*)HandleMouseExit;
- GameCallbacks.KeyPressed=HandleKeyDown;
- GameCallbacks.KeyReleased=HandleKeyUp;
- GameCallbacks.KeyRepeated=HandleKeyRepeat;
- GameCallbacks.NetworkEvent=NetworkEvent;
- GameCallbacks.SoundReady=WriteSound;
+ GameCallbacks.ButtonPressed = HandleButtonDown;
+ GameCallbacks.ButtonReleased = HandleButtonUp;
+ GameCallbacks.MouseMoved = HandleMouseMove;
+ GameCallbacks.MouseExit = HandleMouseExit;
+ GameCallbacks.KeyPressed = HandleKeyDown;
+ GameCallbacks.KeyReleased = HandleKeyUp;
+ GameCallbacks.KeyRepeated = HandleKeyRepeat;
+ GameCallbacks.NetworkEvent = NetworkEvent;
+ GameCallbacks.SoundReady = WriteSound;
- Callbacks=&GameCallbacks;
+ Callbacks = &GameCallbacks;
SetVideoSync();
EnableDrawRefresh();
- GameCursor=TheUI.Point.Cursor;
- GameRunning=1;
+ GameCursor = TheUI.Point.Cursor;
+ GameRunning = 1;
- showtip=0;
+ showtip = 0;
RealVideoSyncSpeed = VideoSyncSpeed;
- if( NetworkFildes==(Socket)-1 ) { // Don't show them for net play
- showtip=ShowTips;
+ if (NetworkFildes == (Socket)-1) { // Don't show them for net play
+ showtip = ShowTips;
}
MultiPlayerReplayEachCycle();
PlaySectionMusic(PlaySectionGame);
- while( GameRunning ) {
+ while (GameRunning) {
#if defined(DEBUG) && defined(HIERARCHIC_PATHFINDER)
- if( setjmp(MainLoopJmpBuf) ) {
+ if (setjmp(MainLoopJmpBuf)) {
GamePaused = 1;
}
#endif
//
// Game logic part
//
- if( !GamePaused && NetworkInSync && !SkipGameCycle ) {
+ if (!GamePaused && NetworkInSync && !SkipGameCycle) {
SinglePlayerReplayEachCycle();
- if( !++GameCycle ) {
- // FIXME: tests with game cycle counter now fails :(
- // FIXME: Should happen in 68 years :)
- fprintf(stderr,"FIXME: *** round robin ***\n");
- fprintf(stderr,"FIXME: *** round robin ***\n");
- fprintf(stderr,"FIXME: *** round robin ***\n");
- fprintf(stderr,"FIXME: *** round robin ***\n");
- }
+ ++GameCycle;
MultiPlayerReplayEachCycle();
NetworkCommands(); // Get network commands
UnitActions(); // handle units
@@ -814,7 +812,7 @@
// Check game goals.
// Check rescue of units.
//
- switch( GameCycle%CYCLES_PER_SECOND ) {
+ switch (GameCycle % CYCLES_PER_SECOND) {
case 0:
HandleCloak();
break;
@@ -822,7 +820,7 @@
break;
case 2: // minimap update
UpdateMinimap();
- MustRedraw|=RedrawMinimap;
+ MustRedraw |= RedrawMinimap;
break;
case 3: // computer players
PlayersEachSecond();
@@ -842,10 +840,10 @@
// Check cd-rom (every 2nd second)
// FIXME: Not called while pause or in the user interface.
//
- switch( GameCycle%((CYCLES_PER_SECOND*VideoSyncSpeed/100)+1) ) {
+ switch (GameCycle % ((CYCLES_PER_SECOND * VideoSyncSpeed / 100) +
1)) {
case 0: // Check cd-rom
#if defined(USE_SDLCD)
- if ( !(GameCycle%4) ) { // every 2nd second
+ if (!(GameCycle % 4)) { // every 2nd second
SDL_CreateThread(CDRomCheck, NULL);
}
#elif defined(USE_LIBCDA) || defined(USE_CDDA)
@@ -853,7 +851,7 @@
#endif
break;
case 10:
- if ( !(GameCycle%2) ) {
+ if (!(GameCycle % 2)) {
PlaySectionMusic(PlaySectionUnknown);
}
break;
@@ -866,41 +864,41 @@
//
// Map scrolling
//
- if( TheUI.MouseScroll && !(FrameCounter%SpeedMouseScroll) ) {
+ if (TheUI.MouseScroll && !(FrameCounter % SpeedMouseScroll)) {
DoScrollArea(MouseScrollState, 0);
}
- if( TheUI.KeyScroll && !(FrameCounter%SpeedKeyScroll) ) {
+ if (TheUI.KeyScroll && !(FrameCounter % SpeedKeyScroll)) {
DoScrollArea(KeyScrollState, KeyModifiers&ModifierControl);
}
- if( !(FrameCounter%COLOR_CYCLE_SPEED) ) {
- if( ColorCycleAll>=0 ) {
+ if (!(FrameCounter % COLOR_CYCLE_SPEED)) {
+ if (ColorCycleAll >= 0) {
ColorCycle();
} else {
// FIXME: should only update when needed
- MustRedraw|=RedrawInfoPanel;
+ MustRedraw |= RedrawInfoPanel;
}
}
#if defined(DEBUG) && !defined(FLAG_DEBUG)
- MustRedraw|=RedrawMenuButton;
+ MustRedraw |= RedrawMenuButton;
#endif
- if( FastForwardCycle > GameCycle
- && RealVideoSyncSpeed != VideoSyncSpeed ) {
+ if (FastForwardCycle > GameCycle &&
+ RealVideoSyncSpeed != VideoSyncSpeed) {
RealVideoSyncSpeed = VideoSyncSpeed;
VideoSyncSpeed = 3000;
}
- if( FastForwardCycle >= GameCycle ) {
+ if (FastForwardCycle >= GameCycle) {
MustRedraw = RedrawEverything;
}
- if( MustRedraw /* && !VideoInterrupts */
- && (FastForwardCycle <= GameCycle || GameCycle <= 10
- || !(GameCycle & 0x3f)) ) {
- if( Callbacks==&MenuCallbacks ) {
- MustRedraw|=RedrawMenu;
+ if (MustRedraw /* && !VideoInterrupts */ &&
+ (FastForwardCycle <= GameCycle || GameCycle <= 10 ||
+ !(GameCycle & 0x3f))) {
+ if (Callbacks == &MenuCallbacks) {
+ MustRedraw |= RedrawMenu;
}
- if( CurrentMenu && CurrentMenu->Panel
- && !strcmp(CurrentMenu->Panel, ScPanel) ) {
+ if (CurrentMenu && CurrentMenu->Panel &&
+ !strcmp(CurrentMenu->Panel, ScPanel)) {
MustRedraw = RedrawEverything;
}
@@ -919,31 +917,31 @@
//
RealizeVideoMemory();
#ifndef USE_OPENGL
- MustRedraw=0;
+ MustRedraw = 0;
#endif
}
CheckVideoInterrupts(); // look if already an interrupt
- if( FastForwardCycle == GameCycle ) {
+ if (FastForwardCycle == GameCycle) {
VideoSyncSpeed = RealVideoSyncSpeed;
}
- if( FastForwardCycle <= GameCycle || !(GameCycle & 0x3f) ) {
+ if (FastForwardCycle <= GameCycle || !(GameCycle & 0x3f)) {
WaitEventsOneFrame(Callbacks);
}
- if( !NetworkInSync ) {
+ if (!NetworkInSync) {
NetworkRecover(); // recover network
}
- if( showtip ) {
- ProcessMenu("menu-tips",1);
+ if (showtip) {
+ ProcessMenu("menu-tips", 1);
InterfaceState = IfaceStateNormal;
- showtip=0;
+ showtip = 0;
}
}
- if( Callbacks==&MenuCallbacks ) {
- while( CurrentMenu ) {
+ if (Callbacks == &MenuCallbacks) {
+ while (CurrentMenu) {
EndMenu();
}
}
@@ -951,31 +949,31 @@
//
// Game over
//
- if( FastForwardCycle > GameCycle ) {
+ if (FastForwardCycle > GameCycle) {
VideoSyncSpeed = RealVideoSyncSpeed;
}
NetworkQuit();
EndReplayLog();
- if( GameResult==GameDefeat ) {
- fprintf(stderr,"You have lost!\n");
+ if (GameResult == GameDefeat) {
+ fprintf(stderr, "You have lost!\n");
SetStatusLine("You have lost!");
ProcessMenu("menu-defeated", 1);
}
- else if( GameResult==GameVictory ) {
- fprintf(stderr,"You have won!\n");
+ else if (GameResult == GameVictory) {
+ fprintf(stderr, "You have won!\n");
SetStatusLine("You have won!");
ProcessMenu("menu-victory", 1);
}
- if( GameResult==GameVictory || GameResult==GameDefeat ) {
+ if (GameResult == GameVictory || GameResult == GameDefeat) {
PlaySectionMusic(PlaySectionStats);
ShowStats();
}
- FlagRevealMap=0;
- ReplayRevealMap=0;
- GamePaused=0;
- GodMode=0;
+ FlagRevealMap = 0;
+ ReplayRevealMap = 0;
+ GamePaused = 0;
+ GodMode = 0;
}
//@}
Index: stratagus/src/clone/player.c
diff -u stratagus/src/clone/player.c:1.93 stratagus/src/clone/player.c:1.94
--- stratagus/src/clone/player.c:1.93 Tue Oct 7 20:06:41 2003
+++ stratagus/src/clone/player.c Thu Oct 9 23:56:40 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: player.c,v 1.93 2003/10/08 00:06:41 jsalmon3 Exp $
+// $Id: player.c,v 1.94 2003/10/10 03:56:40 jsalmon3 Exp $
//@{
@@ -202,7 +202,7 @@
int j;
CLprintf(file, "\n;;; -----------------------------------------\n");
- CLprintf(file, ";;; MODULE: players $Id: player.c,v 1.93 2003/10/08
00:06:41 jsalmon3 Exp $\n\n");
+ CLprintf(file, ";;; MODULE: players $Id: player.c,v 1.94 2003/10/10
03:56:40 jsalmon3 Exp $\n\n");
//
// Dump table wc2 race numbers -> internal symbol.
@@ -430,13 +430,13 @@
break;
}
- player->Type=type;
- player->Race=PlayerRaces.Race[0];
- player->RaceName=PlayerRaces.Name[0];
- player->Team=team;
- player->Enemy=0;
- player->Allied=0;
- player->AiNum=PlayerAiUniversal;
+ player->Type = type;
+ player->Race = PlayerRaces.Race[0];
+ player->RaceName = PlayerRaces.Name[0];
+ player->Team = team;
+ player->Enemy = 0;
+ player->Allied = 0;
+ player->AiNum = PlayerAiUniversal;
//
// Calculate enemy/allied mask.
@@ -1081,7 +1081,7 @@
continue;
}
DebugLevel0("%2d: %8.8s %c %-8.8s " _C_ i _C_ colors[i] _C_
- ThisPlayer==&Players[i] ? '*' :
+ ThisPlayer == &Players[i] ? '*' :
Players[i].AiEnabled ? '+' : ' ' _C_
Players[i].Name);
switch (Players[i].Type) {
Index: stratagus/src/clone/selection.c
diff -u stratagus/src/clone/selection.c:1.49
stratagus/src/clone/selection.c:1.50
--- stratagus/src/clone/selection.c:1.49 Fri Sep 12 13:44:36 2003
+++ stratagus/src/clone/selection.c Thu Oct 9 23:56:40 2003
@@ -10,7 +10,7 @@
//
/address@hidden selection.c - The units' selection. */
//
-// (c) Copyright 1999-2002 by Patrice Fortier, Lutz Sammer
+// (c) Copyright 1999-2003 by Patrice Fortier, Lutz Sammer
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: selection.c,v 1.49 2003/09/12 17:44:36 n0body Exp $
+// $Id: selection.c,v 1.50 2003/10/10 03:56:40 jsalmon3 Exp $
//@{
@@ -55,9 +55,9 @@
global int NumSelected; /// Number of selected units
global Unit* Selected[MaxSelectable] = {
- NoUnitP,NoUnitP,NoUnitP,
- NoUnitP,NoUnitP,NoUnitP,
- NoUnitP,NoUnitP,NoUnitP
+ NoUnitP, NoUnitP, NoUnitP,
+ NoUnitP, NoUnitP, NoUnitP,
+ NoUnitP, NoUnitP, NoUnitP
}; /// All selected units
local unsigned GroupId; /// Unique group # for
automatic groups
@@ -73,39 +73,39 @@
{
Unit* unit;
- while( !++GroupId ) { // Advance group id, but keep non zero
+ while (!++GroupId) { // Advance group id, but keep non zero
}
- while( NumSelected ) {
- unit=Selected[--NumSelected];
- Selected[NumSelected]=NoUnitP; // FIXME: only needed for old code
- unit->Selected=0;
+ while (NumSelected) {
+ unit = Selected[--NumSelected];
+ Selected[NumSelected] = NoUnitP; // FIXME: only needed for old
code
+ unit->Selected = 0;
CheckUnitToBeDrawn(unit);
}
}
/**
-** Handle a an suicide unit click
+** Handle a suicide unit click
**
** @param unit suicide unit.
*/
local void HandleSuicideClick(Unit* unit)
{
DebugCheck(!unit->Type->ClicksToExplode);
- if( GameObserve ) {
+ if (GameObserve) {
return;
}
- if( NumSelected==1 && Selected[0]==unit ) {
+ if (NumSelected == 1 && Selected[0] == unit) {
unit->Value++;
} else {
- unit->Value=1;
+ unit->Value = 1;
}
// FIXME: make this configurable
- if( unit->Value==unit->Type->ClicksToExplode ) {
- SendCommandDemolish(unit,unit->X,unit->Y,0,FlushCommands);
- unit->Value=0;
+ if (unit->Value == unit->Type->ClicksToExplode) {
+ SendCommandDemolish(unit, unit->X, unit->Y, 0, FlushCommands);
+ unit->Value = 0;
}
}
@@ -121,24 +121,24 @@
int i;
int n;
- DebugCheck( count>MaxSelectable );
+ DebugCheck(count > MaxSelectable);
- if( count==1 && units[0]->Type->ClicksToExplode ) {
+ if (count == 1 && units[0]->Type->ClicksToExplode) {
HandleSuicideClick(units[0]);
}
UnSelectAll();
- for( n=i=0; i<count; i++ ) {
- if( !units[i]->Removed ) {
- Selected[n++]=unit=units[i];
- unit->Selected=1;
- if( count>1 ) {
- unit->LastGroup=GroupId;
+ for (n = i = 0; i < count; ++i) {
+ if (!units[i]->Removed) {
+ Selected[n++] = unit = units[i];
+ unit->Selected = 1;
+ if (count > 1) {
+ unit->LastGroup = GroupId;
}
CheckUnitToBeDrawn(unit);
}
}
- NumSelected=n;
+ NumSelected = n;
}
/**
@@ -185,7 +185,7 @@
*/
global void SelectSingleUnit(Unit* unit)
{
- ChangeSelectedUnits(&unit,1);
+ ChangeSelectedUnits(&unit, 1);
}
/**
@@ -197,29 +197,29 @@
{
int i;
- if( !unit->Selected ) {
+ if (!unit->Selected) {
return;
}
- for( i=0; Selected[i]!=unit; i++) {
+ for (i = 0; Selected[i] != unit; ++i) {
;
}
- DebugCheck( i>=NumSelected );
+ DebugCheck(i >= NumSelected);
- if( i<--NumSelected ) {
- Selected[i]=Selected[NumSelected];
+ if (i < --NumSelected) {
+ Selected[i] = Selected[NumSelected];
}
- if( NumSelected>1 ) { // Assign new group to remaining units
- while( !++GroupId ) { // Advance group id, but keep non zero
+ if (NumSelected > 1) { // Assign new group to remaining units
+ while (!++GroupId) { // Advance group id, but keep non zero
}
- for( i=0; i<NumSelected; ++i ) {
- Selected[i]->LastGroup=GroupId;
+ for (i = 0; i < NumSelected; ++i) {
+ Selected[i]->LastGroup = GroupId;
}
}
- Selected[NumSelected]=NoUnitP; // FIXME: only needed for old code
- unit->Selected=0;
+ Selected[NumSelected] = NoUnitP; // FIXME: only needed for old code
+ unit->Selected = 0;
CheckUnitToBeDrawn(unit);
}
@@ -231,7 +231,7 @@
*/
global int ToggleSelectUnit(Unit* unit)
{
- if( unit->Selected ) {
+ if (unit->Selected) {
UnSelectUnit(unit);
return 0;
}
@@ -262,38 +262,38 @@
int i;
const Viewport* vp;
- DebugCheck( !TheUI.MouseViewport );
+ DebugCheck(!TheUI.MouseViewport);
DebugLevel3Fn(" %s\n" _C_ base->Type->Ident);
- type=base->Type;
+ type = base->Type;
// select all visible units.
// StephanR: should be (MapX,MapY,MapX+MapWidth-1,MapY+MapHeight-1) ???
/* FIXME: this should probably be cleaner implemented if
SelectUnitsByType()
* took parameters of the selection rectangle as arguments */
vp = TheUI.MouseViewport;
- r = SelectUnits(vp->MapX-1, vp->MapY-1, vp->MapX + vp->MapWidth+1,
- vp->MapY + vp->MapHeight+1, table);
+ r = SelectUnits(vp->MapX - 1, vp->MapY - 1, vp->MapX + vp->MapWidth + 1,
+ vp->MapY + vp->MapHeight + 1, table);
// if unit is a cadaver or hidden (not on map)
// no unit can be selected.
- if( base->Removed || base->Orders[0].Action==UnitActionDie ) {
+ if (base->Removed || base->Orders[0].Action == UnitActionDie) {
return 0;
}
- if( base->Type->ClicksToExplode ) {
+ if (base->Type->ClicksToExplode) {
HandleSuicideClick(base);
}
UnSelectAll();
- Selected[0]=base;
- base->Selected=1;
- NumSelected=1;
+ Selected[0] = base;
+ base->Selected = 1;
+ NumSelected = 1;
CheckUnitToBeDrawn(base);
// if unit isn't belonging to the player, or is a static unit
// (like a building), only 1 unit can be selected at the same time.
- if( base->Player!=ThisPlayer || !type->SelectableByRectangle ) {
+ if (base->Player != ThisPlayer || !type->SelectableByRectangle) {
return NumSelected;
}
@@ -302,28 +302,28 @@
//
// FIXME: peon/peasant with gold/wood & co are considered from
// different type... idem for tankers
- for( i=0; i<r; ++i ) {
- unit=table[i];
- if( unit->Player!=ThisPlayer || unit->Type!=type ) {
+ for (i = 0; i < r; ++i) {
+ unit = table[i];
+ if (unit->Player != ThisPlayer || unit->Type != type) {
continue;
}
- if( UnitUnusable(unit) ) { // guess SelectUnits doesn't check this
+ if (UnitUnusable(unit)) { // guess SelectUnits doesn't check this
continue;
}
- if( unit==base ) { // no need to have the same unit twice :)
+ if (unit == base) { // no need to have the same unit twice :)
continue;
}
- Selected[NumSelected++]=unit;
- unit->Selected=1;
+ Selected[NumSelected++] = unit;
+ unit->Selected = 1;
CheckUnitToBeDrawn(unit);
- if( NumSelected==MaxSelectable ) {
+ if (NumSelected == MaxSelectable) {
break;
}
}
- if( NumSelected>1 ) {
- for( i=0; i<NumSelected; ++i ) {
- Selected[i]->LastGroup=GroupId;
+ if (NumSelected > 1) {
+ for (i = 0; i < NumSelected; ++i) {
+ Selected[i]->LastGroup = GroupId;
}
}
@@ -413,13 +413,13 @@
{
int nunits;
- DebugCheck(group_number>NUM_GROUPS);
+ DebugCheck(group_number > NUM_GROUPS);
- if( !(nunits=GetNumberUnitsOfGroup(group_number)) ) {
+ if (!(nunits = GetNumberUnitsOfGroup(group_number))) {
return 0;
}
- ChangeSelectedUnits(GetUnitsOfGroup(group_number),nunits);
+ ChangeSelectedUnits(GetUnitsOfGroup(group_number), nunits);
return NumSelected;
}
@@ -435,12 +435,12 @@
int i;
int group;
- if( !(group=unit->LastGroup) ) { // belongs to no group
+ if (!(group = unit->LastGroup)) { // belongs to no group
return 0;
}
- for( i=0; i<NumUnits; ++i ) {
- if( Units[i]->LastGroup==group && !Units[i]->Removed ) {
+ for (i = 0; i < NumUnits; ++i) {
+ if (Units[i]->LastGroup == group && !Units[i]->Removed) {
SelectUnit(Units[i]);
if (NumSelected == MaxSelectable) {
return NumSelected;
@@ -461,7 +461,7 @@
*/
global int SelectGroupFromUnit(Unit* unit)
{
- if( !unit->LastGroup ) { // belongs to no group
+ if (!unit->LastGroup) { // belongs to no group
return 0;
}
@@ -484,16 +484,16 @@
int n;
int i;
- for( n=i=0; i<num_units; i++ ) {
- unit=table[i];
- if( unit->Player!=ThisPlayer || !unit->Type->SelectableByRectangle ) {
+ for (n = i = 0; i < num_units; ++i) {
+ unit = table[i];
+ if (unit->Player != ThisPlayer || !unit->Type->SelectableByRectangle) {
continue;
}
- if( UnitUnusable(unit) ) { // guess SelectUnits doesn't check this
+ if (UnitUnusable(unit)) { // guess SelectUnits doesn't check this
continue;
}
- table[n++]=unit;
- if( n==MaxSelectable ) {
+ table[n++] = unit;
+ if (n == MaxSelectable) {
break;
}
}
@@ -516,12 +516,12 @@
** @return number of units found
*/
local int SelectSpritesInsideRectangle (int sx0, int sy0, int sx1, int sy1,
- Unit **table, int num_units)
+ Unit** table, int num_units)
{
int n;
int i;
- for (i=n=0; i<num_units; i++) {
+ for (i = n = 0; i < num_units; ++i) {
int sprite_x;
int sprite_y;
Unit* unit;
@@ -529,10 +529,10 @@
unit = table[i];
type = unit->Type;
- sprite_x = unit->X*TileSizeX + unit->IX;
- sprite_x -= (type->BoxWidth - TileSizeX*type->TileWidth)/2;
+ sprite_x = unit->X * TileSizeX + unit->IX;
+ sprite_x -= (type->BoxWidth - TileSizeX * type->TileWidth) / 2;
sprite_y = unit->Y*TileSizeY + unit->IY;
- sprite_y -= (type->BoxHeight - TileSizeY*type->TileHeight)/2;
+ sprite_y -= (type->BoxHeight - TileSizeY * type->TileHeight) / 2;
if (sprite_x + type->BoxWidth < sx0) {
continue;
}
@@ -559,7 +559,7 @@
** @param y1 Y start of selection rectangle in tile coordinates
** @return the _total_ number of units selected.
*/
-global int AddSelectedUnitsInRectangle(int x0,int y0,int x1,int y1)
+global int AddSelectedUnitsInRectangle(int x0, int y0, int x1, int y1)
{
Unit* table[UnitMax];
int toggle_num;
@@ -567,37 +567,37 @@
int i;
// If there is no selected unit yet, do a simple selection.
- if( !NumSelected ) {
+ if (!NumSelected) {
return SelectUnitsInRectangle(x0, y0, x1, y1);
}
// Check if the original selected unit (if it's alone) is ours,
// and can be selectable by rectangle.
// In this case, do nothing.
- if( NumSelected == 1 &&
- ( Selected[0]->Player!=ThisPlayer ||
- !Selected[0]->Type->SelectableByRectangle )) {
+ if (NumSelected == 1 &&
+ (Selected[0]->Player != ThisPlayer ||
+ !Selected[0]->Type->SelectableByRectangle)) {
return NumSelected;
}
// If no unit in rectangle area... do nothing
- toggle_num=SelectUnits((x0/TileSizeX)-2, (y0/TileSizeY)-2,
- (x1/TileSizeX)+2+1, (y1/TileSizeX)+2+1, table);
- if( !toggle_num ) {
+ toggle_num = SelectUnits((x0 / TileSizeX) - 2, (y0 / TileSizeY) - 2,
+ (x1 / TileSizeX) + 2 + 1, (y1 / TileSizeX) + 2 + 1, table);
+ if (!toggle_num) {
return NumSelected;
}
- toggle_num=SelectSpritesInsideRectangle (x0, y0, x1, y1, table,
toggle_num);
- if( !toggle_num ) {
+ toggle_num = SelectSpritesInsideRectangle(x0, y0, x1, y1, table,
toggle_num);
+ if (!toggle_num) {
return NumSelected;
}
// Now we should only have mobile (organic) units belonging to us,
// so if there's no such units in the rectangle, do nothing.
- if( !(n=SelectOrganicUnitsInTable(table,toggle_num)) ) {
+ if (!(n = SelectOrganicUnitsInTable(table, toggle_num))) {
return NumSelected;
}
- for( i=0; i<n && NumSelected<MaxSelectable; i++ ) {
+ for (i = 0; i < n && NumSelected < MaxSelectable; ++i) {
SelectUnit(table[i]);
}
return NumSelected;
@@ -638,27 +638,27 @@
tx1 = sx1 / TileSizeX;
ty1 = sy1 / TileSizeY;
- r=SelectUnits (tx0-2, ty0-2, tx1+2+1, ty1+2+1, table);
- r=SelectSpritesInsideRectangle (sx0, sy0, sx1, sy1, table, r);
+ r = SelectUnits(tx0 - 2, ty0 - 2, tx1 + 2 + 1, ty1 + 2 + 1, table);
+ r = SelectSpritesInsideRectangle(sx0, sy0, sx1, sy1, table, r);
//
// 1) search for the player units selectable with rectangle
//
- if( (n=SelectOrganicUnitsInTable(table,r)) ) {
- ChangeSelectedUnits(table,n);
+ if ((n = SelectOrganicUnitsInTable(table, r))) {
+ ChangeSelectedUnits(table, n);
return n;
}
//
// 2) If no unit found, try a player's unit not selectable by rectangle
//
- for( i=0; i<r; ++i ) {
- unit=table[i];
- if( unit->Player!=ThisPlayer ) {
+ for (i = 0; i < r; ++i) {
+ unit = table[i];
+ if (unit->Player != ThisPlayer) {
continue;
}
// FIXME: Can we get this?
- if( !unit->Removed && unit->Orders[0].Action!=UnitActionDie ) {
+ if (!unit->Removed && unit->Orders[0].Action != UnitActionDie) {
SelectSingleUnit(unit);
return 1;
}
@@ -667,18 +667,18 @@
//
// 3) If no unit found, try a resource or a neutral critter
//
- for( i=0; i<r; ++i ) {
- unit=table[i];
+ for (i = 0; i < r; ++i) {
+ unit = table[i];
// Unit visible FIXME: write function UnitSelectable
- if( !UnitVisibleInViewport(TheUI.SelectedViewport, unit) ) {
+ if (!UnitVisibleInViewport(TheUI.SelectedViewport, unit)) {
continue;
}
- type=unit->Type;
+ type = unit->Type;
// Buildings are visible but not selectable
- if( type->Building && !UnitVisibleOnMap(unit) ) {
+ if (type->Building && !UnitVisibleOnMap(unit)) {
continue;
}
- if( (type->GivesResource && !unit->Removed) ) { // no built resources.
+ if ((type->GivesResource && !unit->Removed)) { // no built resources.
SelectSingleUnit(unit);
return 1;
}
@@ -687,17 +687,17 @@
//
// 4) If no unit found, select an enemy unit (first found)
//
- for( i=0; i<r; ++i ) {
- unit=table[i];
+ for (i = 0; i < r; ++i) {
+ unit = table[i];
// Unit visible FIXME: write function UnitSelectable
- if( !UnitVisibleInViewport(TheUI.SelectedViewport,unit) ) {
+ if (!UnitVisibleInViewport(TheUI.SelectedViewport, unit)) {
continue;
}
// Buildings are visible but not selectable
- if( unit->Type->Building && !UnitVisibleOnMap(unit) ) {
+ if (unit->Type->Building && !UnitVisibleOnMap(unit)) {
continue;
}
- if( !unit->Removed && unit->Orders[0].Action!=UnitActionDie ) {
+ if (!unit->Removed && unit->Orders[0].Action != UnitActionDie) {
SelectSingleUnit(unit);
return 1;
}
@@ -716,7 +716,7 @@
**
** @return the number of units found.
*/
-global int SelectGroundUnitsInRectangle (int sx0, int sy0, int sx1, int sy1)
+global int SelectGroundUnitsInRectangle(int sx0, int sy0, int sx1, int sy1)
{
Unit* unit;
Unit* table[UnitMax];
@@ -733,27 +733,27 @@
tx1 = sx1 / TileSizeX;
ty1 = sy1 / TileSizeY;
- r=SelectUnits (tx0-2, ty0-2, tx1+2+1, ty1+2+1, table);
- r=SelectSpritesInsideRectangle (sx0, sy0, sx1, sy1, table, r);
+ r = SelectUnits(tx0 - 2, ty0 - 2, tx1 + 2 + 1, ty1 + 2 + 1, table);
+ r = SelectSpritesInsideRectangle(sx0, sy0, sx1, sy1, table, r);
- for( n=i=0; i<r; i++ ) {
- unit=table[i];
- if( unit->Player!=ThisPlayer || !unit->Type->SelectableByRectangle ) {
+ for (n = i = 0; i < r; ++i) {
+ unit = table[i];
+ if (unit->Player != ThisPlayer || !unit->Type->SelectableByRectangle) {
continue;
}
- if( UnitUnusable(unit) ) { // guess SelectUnits doesn't check this
+ if (UnitUnusable(unit)) { // guess SelectUnits doesn't check this
continue;
}
- if( unit->Type->UnitType==UnitTypeFly ) {
+ if (unit->Type->UnitType == UnitTypeFly) {
continue;
}
- table[n++]=unit;
- if( n==MaxSelectable ) {
+ table[n++] = unit;
+ if (n == MaxSelectable) {
break;
}
}
- if( n ) {
- ChangeSelectedUnits(table,n);
+ if (n) {
+ ChangeSelectedUnits(table, n);
}
return n;
}
@@ -768,7 +768,7 @@
**
** @return the number of units found.
*/
-global int SelectAirUnitsInRectangle (int sx0, int sy0, int sx1, int sy1)
+global int SelectAirUnitsInRectangle(int sx0, int sy0, int sx1, int sy1)
{
Unit* unit;
Unit* table[UnitMax];
@@ -785,27 +785,27 @@
tx1 = sx1 / TileSizeX;
ty1 = sy1 / TileSizeY;
- r=SelectUnits (tx0-2, ty0-2, tx1+2+1, ty1+2+1, table);
- r=SelectSpritesInsideRectangle (sx0, sy0, sx1, sy1, table, r);
+ r = SelectUnits(tx0 - 2, ty0 - 2, tx1 + 2 + 1, ty1 + 2 + 1, table);
+ r = SelectSpritesInsideRectangle(sx0, sy0, sx1, sy1, table, r);
- for( n=i=0; i<r; i++ ) {
- unit=table[i];
- if( unit->Player!=ThisPlayer || !unit->Type->SelectableByRectangle ) {
+ for (n = i = 0; i < r; ++i) {
+ unit = table[i];
+ if (unit->Player != ThisPlayer || !unit->Type->SelectableByRectangle) {
continue;
}
- if( UnitUnusable(unit) ) { // guess SelectUnits doesn't check this
+ if (UnitUnusable(unit)) { // guess SelectUnits doesn't check this
continue;
}
- if( unit->Type->UnitType!=UnitTypeFly ) {
+ if (unit->Type->UnitType != UnitTypeFly) {
continue;
}
- table[n++]=unit;
- if( n==MaxSelectable ) {
+ table[n++] = unit;
+ if (n == MaxSelectable) {
break;
}
}
- if( n ) {
- ChangeSelectedUnits(table,n);
+ if (n) {
+ ChangeSelectedUnits(table, n);
}
return n;
}
@@ -820,7 +820,7 @@
**
** @return the number of units found.
*/
-global int AddSelectedGroundUnitsInRectangle (int sx0, int sy0, int sx1,int
sy1)
+global int AddSelectedGroundUnitsInRectangle(int sx0, int sy0, int sx1, int
sy1)
{
Unit* unit;
Unit* table[UnitMax];
@@ -833,16 +833,16 @@
int ty1;
// If there is no selected unit yet, do a simple selection.
- if( !NumSelected ) {
+ if (!NumSelected) {
return SelectGroundUnitsInRectangle(sx0, sy0, sx1, sy1);
}
// Check if the original selected unit (if it's alone) is ours,
// and can be selectable by rectangle.
// In this case, do nothing.
- if( NumSelected == 1 &&
- ( Selected[0]->Player!=ThisPlayer ||
- !Selected[0]->Type->SelectableByRectangle )) {
+ if (NumSelected == 1 &&
+ (Selected[0]->Player != ThisPlayer ||
+ !Selected[0]->Type->SelectableByRectangle)) {
return NumSelected;
}
@@ -851,22 +851,22 @@
tx1 = sx1 / TileSizeX;
ty1 = sy1 / TileSizeY;
- r=SelectUnits (tx0-2, ty0-2, tx1+2+1, ty1+2+1, table);
- r=SelectSpritesInsideRectangle (sx0, sy0, sx1, sy1, table, r);
+ r = SelectUnits(tx0 - 2, ty0 - 2, tx1 + 2 + 1, ty1 + 2 + 1, table);
+ r = SelectSpritesInsideRectangle(sx0, sy0, sx1, sy1, table, r);
- for( n=i=0; i<r; i++ ) {
- unit=table[i];
- if( unit->Player!=ThisPlayer || !unit->Type->SelectableByRectangle ) {
+ for (n = i = 0; i < r; ++i) {
+ unit = table[i];
+ if (unit->Player != ThisPlayer || !unit->Type->SelectableByRectangle) {
continue;
}
- if( UnitUnusable(unit) ) { // guess SelectUnits doesn't check this
+ if (UnitUnusable(unit)) { // guess SelectUnits doesn't check this
continue;
}
- if( unit->Type->UnitType==UnitTypeFly ) {
+ if (unit->Type->UnitType == UnitTypeFly) {
continue;
}
- table[n++]=unit;
- if( n==MaxSelectable ) {
+ table[n++] = unit;
+ if (n == MaxSelectable) {
break;
}
}
@@ -874,7 +874,7 @@
//
// Add the units to selected.
//
- for( i=0; i<n && NumSelected<MaxSelectable; i++ ) {
+ for (i = 0; i < n && NumSelected < MaxSelectable; ++i) {
SelectUnit(table[i]);
}
return NumSelected;
@@ -890,7 +890,7 @@
**
** @return the number of units found.
*/
-global int AddSelectedAirUnitsInRectangle (int sx0, int sy0, int sx1, int sy1)
+global int AddSelectedAirUnitsInRectangle(int sx0, int sy0, int sx1, int sy1)
{
Unit* unit;
Unit* table[UnitMax];
@@ -903,16 +903,16 @@
int ty1;
// If there is no selected unit yet, do a simple selection.
- if( !NumSelected ) {
+ if (!NumSelected) {
return SelectAirUnitsInRectangle(sx0, sy0, sx1, sy1);
}
// Check if the original selected unit (if it's alone) is ours,
// and can be selectable by rectangle.
// In this case, do nothing.
- if( NumSelected == 1 &&
- ( Selected[0]->Player!=ThisPlayer ||
- !Selected[0]->Type->SelectableByRectangle )) {
+ if (NumSelected == 1 &&
+ (Selected[0]->Player != ThisPlayer ||
+ !Selected[0]->Type->SelectableByRectangle)) {
return NumSelected;
}
@@ -921,22 +921,22 @@
tx1 = sx1 / TileSizeX;
ty1 = sy1 / TileSizeY;
- r=SelectUnits (tx0-2, ty0-2, tx1+2+1, ty1+2+1, table);
- r=SelectSpritesInsideRectangle (sx0, sy0, sx1, sy1, table, r);
+ r = SelectUnits(tx0 - 2, ty0 - 2, tx1 + 2 + 1, ty1 + 2 + 1, table);
+ r = SelectSpritesInsideRectangle(sx0, sy0, sx1, sy1, table, r);
- for( n=i=0; i<r; i++ ) {
- unit=table[i];
- if( unit->Player!=ThisPlayer || !unit->Type->SelectableByRectangle ) {
+ for (n = i = 0; i < r; ++i) {
+ unit = table[i];
+ if (unit->Player != ThisPlayer || !unit->Type->SelectableByRectangle) {
continue;
}
- if( UnitUnusable(unit) ) { // guess SelectUnits doesn't check this
+ if (UnitUnusable(unit)) { // guess SelectUnits doesn't check this
continue;
}
- if( unit->Type->UnitType!=UnitTypeFly ) {
+ if (unit->Type->UnitType != UnitTypeFly) {
continue;
}
- table[n++]=unit;
- if( n==MaxSelectable ) {
+ table[n++] = unit;
+ if (n == MaxSelectable) {
break;
}
}
@@ -944,7 +944,7 @@
//
// Add the units to selected.
//
- for( i=0; i<n && NumSelected<MaxSelectable; i++ ) {
+ for (i = 0; i < n && NumSelected < MaxSelectable; ++i) {
SelectUnit(table[i]);
}
return NumSelected;
@@ -957,9 +957,9 @@
{
int i;
- if( (i=NumSelected) ) { // Cleanup after load
- while( i-- ) {
- Selected[i]=UnitSlots[(int)Selected[i]];
+ if ((i = NumSelected)) { // Cleanup after load
+ while (i--) {
+ Selected[i] = UnitSlots[(int)Selected[i]];
}
}
}
@@ -972,19 +972,19 @@
global void SaveSelections(CLFile* file)
{
int i;
- char *ref;
+ char* ref;
- CLprintf(file,"\n;;; -----------------------------------------\n");
- CLprintf(file,";;; MODULE: selection $Id: selection.c,v 1.49 2003/09/12
17:44:36 n0body Exp $\n\n");
+ CLprintf(file, "\n;;; -----------------------------------------\n");
+ CLprintf(file, ";;; MODULE: selection $Id: selection.c,v 1.50 2003/10/10
03:56:40 jsalmon3 Exp $\n\n");
- CLprintf(file,"(set-group-id! %d)\n",GroupId);
- CLprintf(file,"(selection %d '(",NumSelected);
- for( i=0; i<NumSelected; ++i ) {
- ref=UnitReference(Selected[i]);
- CLprintf(file,"%s ",ref);
+ CLprintf(file, "(set-group-id! %d)\n", GroupId);
+ CLprintf(file, "(selection %d '(", NumSelected);
+ for (i = 0; i < NumSelected; ++i) {
+ ref = UnitReference(Selected[i]);
+ CLprintf(file, "%s ", ref);
free(ref);
}
- CLprintf(file,"))\n");
+ CLprintf(file, "))\n");
}
/**
@@ -992,10 +992,10 @@
*/
global void CleanSelections(void)
{
- GroupId=0;
- NumSelected=0;
- DebugCheck( NoUnitP ); // Code fails if none zero
- memset(Selected,0,sizeof(Selected));
+ GroupId = 0;
+ NumSelected = 0;
+ DebugCheck(NoUnitP); // Code fails if none zero
+ memset(Selected, 0, sizeof(Selected));
}
// ----------------------------------------------------------------------------
@@ -1010,8 +1010,8 @@
{
SCM old;
- old=gh_int2scm(GroupId);
- GroupId=gh_scm2int(id);
+ old = gh_int2scm(GroupId);
+ GroupId = gh_scm2int(id);
return old;
}
@@ -1022,19 +1022,19 @@
** @param num Number of units in selection
** @param units Units in selection
*/
-local SCM CclSelection(SCM num,SCM units)
+local SCM CclSelection(SCM num, SCM units)
{
int i;
- NumSelected=gh_scm2int(num);
- i=0;
- while( !gh_null_p(units) ) {
+ NumSelected = gh_scm2int(num);
+ i = 0;
+ while (!gh_null_p(units)) {
char* str;
- str=gh_scm2newstr(gh_car(units),NULL);
- Selected[i++]=(Unit*)strtol(str+1,NULL,16);
+ str = gh_scm2newstr(gh_car(units), NULL);
+ Selected[i++] = (Unit*)strtol(str + 1, NULL, 16);
free(str);
- units=gh_cdr(units);
+ units = gh_cdr(units);
}
return SCM_UNSPECIFIED;
@@ -1045,8 +1045,8 @@
*/
global void SelectionCclRegister(void)
{
- gh_new_procedure1_0("set-group-id!",CclSetGroupId);
- gh_new_procedure2_0("selection",CclSelection);
+ gh_new_procedure1_0("set-group-id!", CclSetGroupId);
+ gh_new_procedure2_0("selection", CclSelection);
}
//@}
Index: stratagus/src/clone/spells.c
diff -u stratagus/src/clone/spells.c:1.107 stratagus/src/clone/spells.c:1.108
--- stratagus/src/clone/spells.c:1.107 Thu Oct 9 07:31:46 2003
+++ stratagus/src/clone/spells.c Thu Oct 9 23:56:40 2003
@@ -27,7 +27,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: spells.c,v 1.107 2003/10/09 11:31:46 n0body Exp $
+// $Id: spells.c,v 1.108 2003/10/10 03:56:40 jsalmon3 Exp $
/*
** And when we cast our final spell
@@ -66,7 +66,7 @@
----------------------------------------------------------------------------*/
// TODO Move this in missile.c and remove Hardcoded string.
-MissileType *MissileTypeRune; // MissileTypeByIdent("missile-rune");
+MissileType* MissileTypeRune; // MissileTypeByIdent("missile-rune");
/*----------------------------------------------------------------------------
-- Variables
@@ -75,7 +75,7 @@
/**
** Define the names and effects of all im play available spells.
*/
-global SpellType *SpellTypeTable;
+global SpellType* SpellTypeTable;
/// How many spell-types are available
@@ -106,9 +106,9 @@
**
** @todo Move this code into the missile code
*/
-local void SpellFireballController(Missile *missile)
+local void SpellFireballController(Missile* missile)
{
- Unit *table[UnitMax];
+ Unit* table[UnitMax];
int i;
int n;
int x;
@@ -148,32 +148,32 @@
**
** @todo Move this code into the missile code
*/
-local void SpellDeathCoilController(Missile *missile)
+local void SpellDeathCoilController(Missile* missile)
{
- Unit *table[UnitMax];
+ Unit* table[UnitMax];
int i;
int n;
- Unit *source;
+ Unit* source;
//
// missile has not reached target unit/spot
//
if (!(missile->X == missile->DX && missile->Y == missile->DY)) {
- return ;
+ return;
}
source = missile->SourceUnit;
if (source->Destroyed) {
- return ;
+ return;
}
// source unit still exists
//
// Target unit still exists and casted on a special target
//
- if (missile->TargetUnit && !missile->TargetUnit->Destroyed
- && missile->TargetUnit->HP) {
+ if (missile->TargetUnit && !missile->TargetUnit->Destroyed &&
+ missile->TargetUnit->HP) {
if (missile->TargetUnit->HP <= 50) {// 50 should be parametrable
source->Player->Score += missile->TargetUnit->Type->Points;
- if( missile->TargetUnit->Type->Building) {
+ if (missile->TargetUnit->Type->Building) {
source->Player->TotalRazings++;
} else {
source->Player->TotalKills++;
@@ -212,12 +212,11 @@
n = SelectUnits(x - 2, y - 2, x + 2, y + 2, table);
if (n == 0) {
- return ;
+ return;
}
// calculate organic enemy count
for (i = 0; i < n; ++i) {
- ec += (IsEnemy(source->Player, table[i])
- && table[i]->Type->Organic != 0);
+ ec += (IsEnemy(source->Player, table[i]) && table[i]->Type->Organic
!= 0);
}
if (ec > 0) {
// yes organic enemies found
@@ -225,9 +224,9 @@
if (IsEnemy(source->Player, table[i]) &&
table[i]->Type->Organic != 0) {
// disperse damage between them
//NOTE: 1 is the minimal damage
- if (table[i]->HP <= 50 / ec ) {
+ if (table[i]->HP <= 50 / ec) {
source->Player->Score += table[i]->Type->Points;
- if( table[i]->Type->Building ) {
+ if (table[i]->Type->Building) {
source->Player->TotalRazings++;
} else {
source->Player->TotalKills++;
@@ -242,13 +241,13 @@
LetUnitDie(table[i]); // too much damage
} else {
#ifdef USE_HP_FOR_XP
- source->XP += 50/ec;
+ source->XP += 50 / ec;
#endif
table[i]->HP -= 50 / ec;
}
}
}
- if (source->Orders[0].Action!=UnitActionDie) {
+ if (source->Orders[0].Action != UnitActionDie) {
source->HP += 50;
if (source->HP > source->Stats->HitPoints) {
source->HP = source->Stats->HitPoints;
@@ -265,9 +264,9 @@
**
** @todo Move this code into the missile code
*/
-local void SpellWhirlwindController(Missile *missile)
+local void SpellWhirlwindController(Missile* missile)
{
- Unit *table[UnitMax];
+ Unit* table[UnitMax];
int i;
int n;
int x;
@@ -276,8 +275,8 @@
//
// Center of the tornado
//
- x = (missile->X+TileSizeX/2+missile->Type->Width/2) / TileSizeX;
- y = (missile->Y+TileSizeY+missile->Type->Height/2) / TileSizeY;
+ x = (missile->X + TileSizeX / 2 + missile->Type->Width / 2) / TileSizeX;
+ y = (missile->Y + TileSizeY + missile->Type->Height / 2) / TileSizeY;
//
// Every 4 cycles 4 points damage in tornado center
//
@@ -285,25 +284,27 @@
n = SelectUnitsOnTile(x, y, table);
for (i = 0; i < n; ++i) {
if (table[i]->HP) {
- HitUnit(missile->SourceUnit,table[i], WHIRLWIND_DAMAGE1);//
should be missile damage ?
+ // should be missile damage?
+ HitUnit(missile->SourceUnit, table[i], WHIRLWIND_DAMAGE1);
}
}
}
//
// Every 1/10s 1 points damage on tornado periphery
//
- if (!(missile->TTL % (CYCLES_PER_SECOND/10))) {
+ if (!(missile->TTL % (CYCLES_PER_SECOND / 10))) {
// we should parameter this
n = SelectUnits(x - 1, y - 1, x + 1, y + 1, table);
DebugLevel3Fn("Damage on %d,%d-%d,%d = %d\n" _C_ x-1 _C_ y-1 _C_ x+1
_C_ y+1 _C_ n);
for (i = 0; i < n; ++i) {
- if( (table[i]->X != x || table[i]->Y != y) && table[i]->HP) {
- HitUnit(missile->SourceUnit,table[i], WHIRLWIND_DAMAGE2); //
should be in missile
+ if ((table[i]->X != x || table[i]->Y != y) && table[i]->HP) {
+ // should be in missile
+ HitUnit(missile->SourceUnit, table[i], WHIRLWIND_DAMAGE2);
}
}
}
- DebugLevel3Fn( "Whirlwind: %d, %d, TTL: %d\n" _C_
- missile->X _C_ missile->Y _C_ missile->TTL );
+ DebugLevel3Fn("Whirlwind: %d, %d, TTL: %d\n" _C_
+ missile->X _C_ missile->Y _C_ missile->TTL);
//
// Changes direction every 3 seconds (approx.)
@@ -319,9 +320,9 @@
} while (nx < 0 && ny < 0 && nx >= TheMap.Width && ny >= TheMap.Height);
missile->DX = nx * TileSizeX + TileSizeX / 2;
missile->DY = ny * TileSizeY + TileSizeY / 2;
- missile->State=0;
- DebugLevel3Fn( "Whirlwind new direction: %d, %d, TTL: %d\n" _C_
- missile->X _C_ missile->Y _C_ missile->TTL );
+ missile->State = 0;
+ DebugLevel3Fn("Whirlwind new direction: %d, %d, TTL: %d\n" _C_
+ missile->X _C_ missile->Y _C_ missile->TTL);
}
}
@@ -332,9 +333,9 @@
**
** @todo Move this code into the missile code
*/
-local void SpellRunesController(Missile *missile)
+local void SpellRunesController(Missile* missile)
{
- Unit *table[UnitMax];
+ Unit* table[UnitMax];
int i;
int n;
int x;
@@ -349,14 +350,14 @@
// FIXME: don't use ident!!!
PlayMissileSound(missile, SoundIdForName("explosion"));
MakeMissile(MissileTypeExplosion, missile->X, missile->Y,
- missile->X, missile->Y);
+ missile->X, missile->Y);
HitUnit(missile->SourceUnit, table[i], RUNE_DAMAGE);
- missile->TTL=0; // Rune can only hit once
+ missile->TTL = 0; // Rune can only hit once
}
}
// show rune every 4 seconds (approx.)
if (missile->TTL % 100 == 0) {
- MakeMissile(MissileTypeRune, missile->X, missile->Y,missile->X,
missile->Y);
+ MakeMissile(MissileTypeRune, missile->X, missile->Y, missile->X,
missile->Y);
}
}
@@ -367,7 +368,7 @@
**
** @todo Move this code into the missile code
*/
-local void SpellFlameShieldController(Missile *missile)
+local void SpellFlameShieldController(Missile* missile)
{
static int fs_dc[] = {
0, 32, 5, 31, 10, 30, 16, 27, 20, 24, 24, 20, 27, 15, 30, 10, 31,
@@ -375,7 +376,7 @@
-30, 5, -31, 0, -32, -5, -31, -10, -30, -16, -27, -20, -24, -24, -20,
-27, -15, -30, -10, -31, -5, -32, 0, -31, 5, -30, 10, -27, 16, -24,
20, -20, 24, -15, 27, -10, 30, -5, 31, 0, 32};
- Unit *table[UnitMax];
+ Unit* table[UnitMax];
int n;
int i;
int dx;
@@ -442,12 +443,12 @@
**
** @return =!0 if spell should be repeated, 0 if not
*/
-global int CastSpawnPortal(Unit *caster, const SpellType *spell
__attribute__((unused)),
- Unit *target __attribute__((unused)), int x, int y)
+global int CastSpawnPortal(Unit* caster, const SpellType* spell
__attribute__((unused)),
+ Unit* target __attribute__((unused)), int x, int y)
{
// FIXME: vladi: cop should be placed only on explored land
- Unit *portal;
- UnitType *ptype;
+ Unit* portal;
+ UnitType* ptype;
DebugCheck(!caster);
DebugCheck(!spell);
@@ -465,8 +466,8 @@
portal = MakeUnitAndPlace(x, y, ptype, &Players[PlayerMax - 1]);
}
MakeMissile(spell->Missile,
- x * TileSizeX + TileSizeX / 2, y * TileSizeY + TileSizeY / 2,
- x * TileSizeX + TileSizeX / 2, y * TileSizeY + TileSizeY / 2);
+ x * TileSizeX + TileSizeX / 2, y * TileSizeY + TileSizeY / 2,
+ x * TileSizeX + TileSizeX / 2, y * TileSizeY + TileSizeY / 2);
// Goal is used to link to destination circle of power
caster->Goal = portal;
RefsDebugCheck(!portal->Refs || portal->Destroyed);
@@ -490,13 +491,13 @@
**
** @return =!0 if spell should be repeated, 0 if not
*/
-global int CastAreaBombardment(Unit *caster, const SpellType *spell,
- Unit *target __attribute__((unused)), int x, int y)
+global int CastAreaBombardment(Unit* caster, const SpellType* spell,
+ Unit* target __attribute__((unused)), int x, int y)
{
int fields;
int shards;
int damage;
- Missile *mis;
+ Missile* mis;
int offsetx;
int offsety;
int dx;
@@ -524,10 +525,10 @@
} while (dx < 0 && dy < 0 && dx >= TheMap.Width && dy >= TheMap.Height);
for (i = 0; i < shards; ++i) {
mis = MakeMissile(spell->Missile,
- dx * TileSizeX + TileSizeX / 2 + offsetx,
- dy * TileSizeY + TileSizeY / 2 + offsety,
- dx * TileSizeX + TileSizeX / 2,
- dy * TileSizeY + TileSizeY / 2);
+ dx * TileSizeX + TileSizeX / 2 + offsetx,
+ dy * TileSizeY + TileSizeY / 2 + offsety,
+ dx * TileSizeX + TileSizeX / 2,
+ dy * TileSizeY + TileSizeY / 2);
// FIXME: This is just patched up, it works, but I have no idea
why.
// FIXME: What is the reasoning behind all this?
if (mis->Type->Speed) {
@@ -559,18 +560,18 @@
**
** @return =!0 if spell should be repeated, 0 if not
*/
-global int CastDeathCoil(Unit *caster, const SpellType *spell, Unit *target,
+global int CastDeathCoil(Unit* caster, const SpellType* spell, Unit* target,
int x, int y)
{
- Missile *mis;
+ Missile* mis;
int sx;
int sy;
DebugCheck(!caster);
DebugCheck(!spell);
DebugCheck(!spell->Action);
-// assert(target);
-// assert(x in range, y in range);
+// DebugCheck(target);
+// DebugCheck(x in range, y in range);
mis = NULL;
sx = caster->X;
@@ -580,8 +581,8 @@
PlayGameSound(spell->SoundWhenCast.Sound, MaxSampleVolume);
mis = MakeMissile(spell->Missile,
- sx * TileSizeX + TileSizeX / 2, sy * TileSizeY + TileSizeY / 2,
- x * TileSizeX + TileSizeX / 2, y * TileSizeY + TileSizeY / 2);
+ sx * TileSizeX + TileSizeX / 2, sy * TileSizeY + TileSizeY / 2,
+ x * TileSizeX + TileSizeX / 2, y * TileSizeY + TileSizeY / 2);
mis->SourceUnit = caster;
RefsDebugCheck(!caster->Refs || caster->Destroyed);
caster->Refs++;
@@ -605,10 +606,10 @@
**
** @return =!0 if spell should be repeated, 0 if not
*/
-global int CastFireball(Unit *caster, const SpellType *spell,
- Unit *target __attribute__((unused)), int x, int y)
+global int CastFireball(Unit* caster, const SpellType* spell,
+ Unit* target __attribute__((unused)), int x, int y)
{
- Missile *missile;
+ Missile* missile;
int sx;
int sy;
int dist;
@@ -654,17 +655,17 @@
**
** @return =!0 if spell should be repeated, 0 if not
*/
-global int CastFlameShield(Unit* caster, const SpellType *spell, Unit *target,
+global int CastFlameShield(Unit* caster, const SpellType* spell, Unit* target,
int x __attribute__((unused)), int y __attribute__((unused)))
{
- Missile *mis;
+ Missile* mis;
int i;
DebugCheck(!caster);
DebugCheck(!spell);
DebugCheck(!spell->Action);
DebugCheck(!target);
-// assert(x in range, y in range);
+// DebugCheck(x in range, y in range);
DebugCheck(!spell->Missile);
mis = NULL;
@@ -673,7 +674,7 @@
caster->Mana -= spell->ManaCost;
target->FlameShield = spell->Action->Data.FlameShield.TTL;
PlayGameSound(spell->SoundWhenCast.Sound, MaxSampleVolume);
- for (i = 0; i < 5; i++) {
+ for (i = 0; i < 5; ++i) {
mis = MakeMissile(spell->Missile, 0, 0, 0, 0);
mis->TTL = spell->Action->Data.FlameShield.TTL + i * 7;
mis->TargetUnit = target;
@@ -695,7 +696,7 @@
**
** @return =!0 if spell should be repeated, 0 if not
*/
-global int CastAdjustBuffs(Unit *caster, const SpellType *spell, Unit *target,
+global int CastAdjustBuffs(Unit* caster, const SpellType* spell, Unit* target,
int x, int y)
{
DebugCheck(!caster);
@@ -707,25 +708,25 @@
caster->Mana -= spell->ManaCost;
if (spell->Action->Data.AdjustBuffs.HasteTicks!=BUFF_NOT_AFFECTED) {
- target->Haste=spell->Action->Data.AdjustBuffs.HasteTicks;
+ target->Haste = spell->Action->Data.AdjustBuffs.HasteTicks;
}
if (spell->Action->Data.AdjustBuffs.SlowTicks!=BUFF_NOT_AFFECTED) {
- target->Slow=spell->Action->Data.AdjustBuffs.SlowTicks;
+ target->Slow = spell->Action->Data.AdjustBuffs.SlowTicks;
}
if (spell->Action->Data.AdjustBuffs.BloodlustTicks!=BUFF_NOT_AFFECTED) {
- target->Bloodlust=spell->Action->Data.AdjustBuffs.BloodlustTicks;
+ target->Bloodlust = spell->Action->Data.AdjustBuffs.BloodlustTicks;
}
if (spell->Action->Data.AdjustBuffs.InvisibilityTicks!=BUFF_NOT_AFFECTED) {
- target->Invisible=spell->Action->Data.AdjustBuffs.InvisibilityTicks;
+ target->Invisible = spell->Action->Data.AdjustBuffs.InvisibilityTicks;
}
if (spell->Action->Data.AdjustBuffs.InvincibilityTicks!=BUFF_NOT_AFFECTED)
{
- target->UnholyArmor=spell->Action->Data.AdjustBuffs.InvincibilityTicks;
+ target->UnholyArmor =
spell->Action->Data.AdjustBuffs.InvincibilityTicks;
}
CheckUnitToBeDrawn(target);
- PlayGameSound(spell->SoundWhenCast.Sound,MaxSampleVolume);
+ PlayGameSound(spell->SoundWhenCast.Sound, MaxSampleVolume);
MakeMissile(spell->Missile,
- x*TileSizeX+TileSizeX/2, y*TileSizeY+TileSizeY/2,
- x*TileSizeX+TileSizeX/2, y*TileSizeY+TileSizeY/2 );
+ x * TileSizeX+TileSizeX / 2, y * TileSizeY+TileSizeY / 2,
+ x * TileSizeX+TileSizeX / 2, y * TileSizeY+TileSizeY / 2);
return 0;
}
@@ -740,7 +741,7 @@
**
** @return =!0 if spell should be repeated, 0 if not
*/
-global int CastAdjustVitals(Unit *caster, const SpellType *spell, Unit *target,
+global int CastAdjustVitals(Unit* caster, const SpellType* spell, Unit* target,
int x, int y)
{
int castcount;
@@ -760,12 +761,12 @@
manacost = spell->ManaCost;
// Healing and harming
- if (hp>0) {
+ if (hp > 0) {
diffHP = target->Stats->HitPoints - target->HP;
} else {
diffHP = target->HP;
}
- if (mana>0) {
+ if (mana > 0) {
diffMana = target->Type->_MaxMana - target->Mana;
} else {
diffMana = target->Mana;
@@ -774,46 +775,50 @@
// When harming cast again to send the hp to negative values.
// Carefull, a perfect 0 target hp kills too.
// Avoid div by 0 errors too!
- castcount=0;
+ castcount = 0;
if (hp) {
- castcount=max(castcount,diffHP/abs(hp)+( ( (hp<0) && (diffHP%(-hp)>0) )
? 1 : 0));
+ castcount = max(castcount, diffHP / abs(hp) + (((hp < 0) &&
+ (diffHP % (-hp) > 0)) ? 1 : 0));
}
if (mana) {
- castcount=max(castcount,diffMana/abs(mana)+( ( (mana<0) &&
(diffMana%(-mana)>0) ) ? 1 : 0));
+ castcount = max(castcount, diffMana / abs(mana) + (((mana < 0) &&
+ (diffMana % (-mana) > 0)) ? 1 : 0));
}
if (manacost) {
- castcount=min(castcount,caster->Mana/manacost);
+ castcount = min(castcount, caster->Mana / manacost);
}
if (spell->Action->Data.AdjustVitals.MaxMultiCast) {
- castcount=min(castcount,spell->Action->Data.AdjustVitals.MaxMultiCast);
+ castcount = min(castcount,
spell->Action->Data.AdjustVitals.MaxMultiCast);
}
- DebugCheck(castcount<0);
+ DebugCheck(castcount < 0);
- DebugLevel3Fn("Used to have %d hp and %d mana.\n" _C_ target->HP _C_
target->Mana);
+ DebugLevel3Fn("Used to have %d hp and %d mana.\n" _C_
+ target->HP _C_ target->Mana);
- caster->Mana-=castcount*manacost;
+ caster->Mana -= castcount * manacost;
if (hp < 0) {
- HitUnit(caster,target,castcount*hp);
+ HitUnit(caster, target, castcount * hp);
} else {
target->HP += castcount * hp;
- if (target->HP>target->Stats->HitPoints) {
- target->HP=target->Stats->HitPoints;
+ if (target->HP > target->Stats->HitPoints) {
+ target->HP = target->Stats->HitPoints;
}
}
- target->Mana+=castcount*mana;
- if (target->Mana<0) {
- target->Mana=0;
+ target->Mana += castcount*mana;
+ if (target->Mana < 0) {
+ target->Mana = 0;
}
- if (target->Mana>target->Type->_MaxMana) {
- target->Mana=target->Type->_MaxMana;
+ if (target->Mana > target->Type->_MaxMana) {
+ target->Mana = target->Type->_MaxMana;
}
- DebugLevel3Fn("Unit now has %d hp and %d mana.\n" _C_ target->HP _C_
target->Mana);
+ DebugLevel3Fn("Unit now has %d hp and %d mana.\n" _C_
+ target->HP _C_ target->Mana);
PlayGameSound(spell->SoundWhenCast.Sound, MaxSampleVolume);
MakeMissile(spell->Missile,
- x * TileSizeX + TileSizeX / 2, y * TileSizeY + TileSizeY / 2,
- x * TileSizeX + TileSizeX / 2, y * TileSizeY + TileSizeY / 2);
+ x * TileSizeX + TileSizeX / 2, y * TileSizeY + TileSizeY / 2,
+ x * TileSizeX + TileSizeX / 2, y * TileSizeY + TileSizeY / 2);
return 0;
}
@@ -828,10 +833,10 @@
**
** @return =!0 if spell should be repeated, 0 if not
*/
-global int CastPolymorph(Unit *caster, const SpellType *spell, Unit *target,
+global int CastPolymorph(Unit* caster, const SpellType* spell, Unit* target,
int x, int y)
{
- UnitType *type;
+ UnitType* type;
DebugCheck(!caster);
DebugCheck(!spell);
@@ -854,7 +859,7 @@
#endif
caster->Kills++;
// as said somewhere else -- no corpses :)
- RemoveUnit(target,NULL);
+ RemoveUnit(target, NULL);
UnitLost(target);
UnitClearOrders(target);
ReleaseUnit(target);
@@ -864,8 +869,8 @@
caster->Mana -= spell->ManaCost;
PlayGameSound(spell->SoundWhenCast.Sound, MaxSampleVolume);
MakeMissile(spell->Missile,
- x*TileSizeX+TileSizeX/2, y*TileSizeY+TileSizeY/2,
- x*TileSizeX+TileSizeX/2, y*TileSizeY+TileSizeY/2 );
+ x * TileSizeX + TileSizeX / 2, y * TileSizeY + TileSizeY / 2,
+ x * TileSizeX + TileSizeX / 2, y * TileSizeY + TileSizeY / 2);
return 0;
}
@@ -880,10 +885,10 @@
**
** @return =!0 if spell should be repeated, 0 if not
*/
-global int CastRunes(Unit *caster, const SpellType *spell,
- Unit *target __attribute__((unused)), int x, int y)
+global int CastRunes(Unit* caster, const SpellType* spell,
+ Unit* target __attribute__((unused)), int x, int y)
{
- Missile *mis;
+ Missile* mis;
const int xx[] = {-1,+1, 0, 0, 0};
const int yy[] = { 0, 0, 0,-1,+1};
int oldx;
@@ -893,23 +898,23 @@
DebugCheck(!caster);
DebugCheck(spell);
DebugCheck(!spell->Action);
-// assert(x in range, y in range);
+// DebugCheck(x in range, y in range);
mis = NULL;
oldx = x;
oldy = y;
PlayGameSound(spell->SoundWhenCast.Sound, MaxSampleVolume);
- for (i = 0; i < 5; i++) {
+ for (i = 0; i < 5; ++i) {
x = oldx + xx[i];
y = oldy + yy[i];
if (IsMapFieldEmpty(x - 1, y + 0)) {
mis = MakeMissile(spell->Missile,
- x * TileSizeX + TileSizeX / 2,
- y * TileSizeY + TileSizeY / 2,
- x * TileSizeX + TileSizeX / 2,
- y * TileSizeY + TileSizeY / 2);
+ x * TileSizeX + TileSizeX / 2,
+ y * TileSizeY + TileSizeY / 2,
+ x * TileSizeX + TileSizeX / 2,
+ y * TileSizeY + TileSizeY / 2);
mis->TTL = spell->Action->Data.Runes.TTL;
mis->Controller = SpellRunesController;
caster->Mana -= spell->ManaCost / 5;
@@ -929,13 +934,13 @@
**
** @return =!0 if spell should be repeated, 0 if not
*/
-global int CastSummon(Unit *caster, const SpellType *spell, Unit *target,
+global int CastSummon(Unit* caster, const SpellType* spell, Unit* target,
int x, int y)
{
int ttl;
int cansummon;
- Unit **corpses;
- Unit *tempcorpse;
+ Unit** corpses;
+ Unit* tempcorpse;
UnitType* unittype;
DebugCheck(!caster);
@@ -943,34 +948,34 @@
DebugCheck(!spell->Action);
DebugCheck(!spell->Action->Data.Summon.UnitType);
- unittype=spell->Action->Data.Summon.UnitType;
- ttl=spell->Action->Data.Summon.TTL;
+ unittype = spell->Action->Data.Summon.UnitType;
+ ttl = spell->Action->Data.Summon.TTL;
if (spell->Action->Data.Summon.RequireCorpse) {
corpses = &CorpseList;
- cansummon=0;
+ cansummon = 0;
while (*corpses) {
// FIXME: this tries to raise all corps, I can raise ships?
- if ((*corpses)->Orders[0].Action == UnitActionDie
- && !(*corpses)->Type->Building
- && (*corpses)->X >= x - 1 && (*corpses)->X <= x + 1
- && (*corpses)->Y >= y - 1 && (*corpses)->Y <= y + 1) {
+ if ((*corpses)->Orders[0].Action == UnitActionDie &&
+ !(*corpses)->Type->Building &&
+ (*corpses)->X >= x - 1 && (*corpses)->X <= x + 1 &&
+ (*corpses)->Y >= y - 1 && (*corpses)->Y <= y + 1) {
//
// Found a corpse. eliminate it and proceed to summoning.
//
- x=(*corpses)->X;
- y=(*corpses)->Y;
+ x = (*corpses)->X;
+ y = (*corpses)->Y;
tempcorpse = *corpses;
corpses = &(*corpses)->Next;
ReleaseUnit(tempcorpse);
- cansummon=1;
+ cansummon = 1;
break;
} else {
- corpses=&(*corpses)->Next;
+ corpses = &(*corpses)->Next;
}
}
} else {
- cansummon=1;
+ cansummon = 1;
}
if (cansummon) {
@@ -987,14 +992,14 @@
// set life span. ttl=0 results in a permanent unit.
//
if (ttl) {
- target->TTL=GameCycle+ttl;
+ target->TTL = GameCycle + ttl;
}
//
// Revealers are always removed, since they don't have graphics
//
if (target->Type->Revealer) {
DebugLevel0Fn("summoned unit is a revealer, removed.\n");
- target->Removed=1;
+ target->Removed = 1;
target->CurrentSightRange = target->Stats->SightRange;
MapMarkUnitSight(target);
} else {
@@ -1005,10 +1010,10 @@
caster->Mana -= spell->ManaCost;
}
- PlayGameSound(spell->SoundWhenCast.Sound,MaxSampleVolume);
+ PlayGameSound(spell->SoundWhenCast.Sound, MaxSampleVolume);
MakeMissile(spell->Missile,
- x*TileSizeX+TileSizeX/2, y*TileSizeY+TileSizeY/2,
- x*TileSizeX+TileSizeX/2, y*TileSizeY+TileSizeY/2 );
+ x * TileSizeX + TileSizeX / 2, y * TileSizeY + TileSizeY / 2,
+ x * TileSizeX + TileSizeX / 2, y * TileSizeY + TileSizeY / 2);
return 0;
}
@@ -1023,23 +1028,23 @@
**
** @return =!0 if spell should be repeated, 0 if not
*/
-global int CastWhirlwind(Unit *caster, const SpellType *spell,
- Unit *target __attribute__((unused)), int x, int y)
+global int CastWhirlwind(Unit* caster, const SpellType* spell,
+ Unit* target __attribute__((unused)), int x, int y)
{
- Missile *mis;
+ Missile* mis;
DebugCheck(!caster);
DebugCheck(!spell);
DebugCheck(!spell->Action);
-// assert(x in range, y in range);
+// DebugCheck(x in range, y in range);
mis = NULL;
caster->Mana -= spell->ManaCost;
PlayGameSound(spell->SoundWhenCast.Sound, MaxSampleVolume);
mis = MakeMissile(spell->Missile,
- x * TileSizeX + TileSizeX / 2, y * TileSizeY + TileSizeY / 2,
- x * TileSizeX + TileSizeX / 2, y * TileSizeY + TileSizeY / 2);
+ x * TileSizeX + TileSizeX / 2, y * TileSizeY + TileSizeY / 2,
+ x * TileSizeX + TileSizeX / 2, y * TileSizeY + TileSizeY / 2);
mis->TTL = spell->Action->Data.Whirlwind.TTL;
mis->Controller = SpellWhirlwindController;
return 0;
@@ -1052,18 +1057,18 @@
/**
** FIXME: docu
*/
-local Target *NewTarget(TargetType t, const Unit *unit, int x, int y)
+local Target* NewTarget(TargetType t, const Unit* unit, int x, int y)
{
- Target *target;
+ Target* target;
- target = (Target *)malloc(sizeof(*target));
+ target = (Target*)malloc(sizeof(*target));
DebugCheck(unit == NULL && t == TargetUnit);
DebugCheck(!(0 <= x && x < TheMap.Width) && t == TargetPosition);
DebugCheck(!(0 <= y && y < TheMap.Height) && t == TargetPosition);
target->which_sort_of_target = t;
- target->unit = (Unit *)unit;
+ target->unit = (Unit*)unit;
target->X = x;
target->Y = y;
return target;
@@ -1072,7 +1077,7 @@
/**
** FIXME: docu
*/
-local Target *NewTargetUnit(const Unit *unit)
+local Target* NewTargetUnit(const Unit* unit)
{
DebugCheck(!unit);
return NewTarget(TargetUnit, unit, 0, 0);
@@ -1081,7 +1086,7 @@
/**
** FIXME: docu
*/
-local Target *NewTargetPosition(int x, int y)
+local Target* NewTargetPosition(int x, int y)
{
DebugCheck(!(0 <= x && x < TheMap.Width));
DebugCheck(!(0 <= y && y < TheMap.Height));
@@ -1105,19 +1110,19 @@
**
** @return 1 if passed, 0 otherwise.
*/
-local int PassCondition(const Unit* caster,const SpellType* spell,const Unit*
target,
- int x,int y,const ConditionInfo* condition)
+local int PassCondition(const Unit* caster, const SpellType* spell, const
Unit* target,
+ int x, int y, const ConditionInfo* condition)
{
//
// Check caster mana. FIXME: move somewhere else?
//
- if (caster->Mana<spell->ManaCost) {
+ if (caster->Mana < spell->ManaCost) {
return 0;
}
//
// Casting an unit spell without a target.
//
- if (spell->Target==TargetUnit&&!target) {
+ if (spell->Target == TargetUnit && !target) {
return 0;
}
if (!condition) {
@@ -1128,60 +1133,61 @@
// Now check conditions regarding the target unit.
//
if (target) {
- if (condition->Undead!=CONDITION_TRUE) {
- if ((condition->Undead==CONDITION_ONLY)^(target->Type->IsUndead)) {
+ if (condition->Undead != CONDITION_TRUE) {
+ if ((condition->Undead == CONDITION_ONLY) ^
(target->Type->IsUndead)) {
return 0;
}
}
- if (condition->Organic!=CONDITION_TRUE) {
- if ((condition->Organic==CONDITION_ONLY)^(target->Type->Organic)) {
+ if (condition->Organic != CONDITION_TRUE) {
+ if ((condition->Organic == CONDITION_ONLY) ^
(target->Type->Organic)) {
return 0;
}
}
- if (condition->Volatile!=CONDITION_TRUE) {
- if ((condition->Volatile==CONDITION_ONLY)^(target->Type->Volatile))
{
+ if (condition->Volatile != CONDITION_TRUE) {
+ if ((condition->Volatile == CONDITION_ONLY) ^
(target->Type->Volatile)) {
return 0;
}
}
- if (condition->Building!=CONDITION_TRUE) {
- if ((condition->Building==CONDITION_ONLY)^(target->Type->Building))
{
+ if (condition->Building != CONDITION_TRUE) {
+ if ((condition->Building == CONDITION_ONLY) ^
(target->Type->Building)) {
return 0;
}
}
- if (condition->Hero!=CONDITION_TRUE) {
- if ((condition->Hero==CONDITION_ONLY)^(target->Type->Hero)) {
+ if (condition->Hero != CONDITION_TRUE) {
+ if ((condition->Hero == CONDITION_ONLY) ^ (target->Type->Hero)) {
return 0;
}
}
- if (condition->Coward!=CONDITION_TRUE) {
- if ((condition->Coward==CONDITION_ONLY)^(target->Type->Coward)) {
+ if (condition->Coward != CONDITION_TRUE) {
+ if ((condition->Coward == CONDITION_ONLY) ^ (target->Type->Coward))
{
return 0;
}
}
- if (condition->Alliance!=CONDITION_TRUE) {
- if
((condition->Alliance==CONDITION_ONLY)^(IsAllied(caster->Player,target)||target->Player==caster->Player))
{
+ if (condition->Alliance != CONDITION_TRUE) {
+ if ((condition->Alliance == CONDITION_ONLY) ^
+ (IsAllied(caster->Player,target) || target->Player ==
caster->Player)) {
return 0;
}
}
- if (condition->TargetSelf!=CONDITION_TRUE) {
- if ((condition->TargetSelf==CONDITION_ONLY)^(caster==target)) {
+ if (condition->TargetSelf != CONDITION_TRUE) {
+ if ((condition->TargetSelf == CONDITION_ONLY) ^ (caster == target))
{
return 0;
}
}
//
// Check vitals now.
//
- if (condition->MinHpPercent*target->Stats->HitPoints/100>target->HP) {
+ if (condition->MinHpPercent * target->Stats->HitPoints / 100 >
target->HP) {
return 0;
}
- if (condition->MaxHpPercent*target->Stats->HitPoints/100<=target->HP) {
+ if (condition->MaxHpPercent * target->Stats->HitPoints / 100 <=
target->HP) {
return 0;
}
if (target->Type->CanCastSpell) {
- if
(condition->MinManaPercent*target->Type->_MaxMana/100>target->Mana) {
+ if (condition->MinManaPercent * target->Type->_MaxMana / 100 >
target->Mana) {
return 0;
}
- if
(condition->MaxManaPercent*target->Type->_MaxMana/100<target->Mana) {
+ if (condition->MaxManaPercent * target->Type->_MaxMana / 100 <
target->Mana) {
return 0;
}
}
@@ -1190,19 +1196,19 @@
// This should be used mostly for ai, if you want to keep casting
// slow to no effect I can't see why should we stop you.
//
- if (condition->MaxSlowTicks<target->Slow) {
+ if (condition->MaxSlowTicks < target->Slow) {
return 0;
}
- if (condition->MaxHasteTicks<target->Haste) {
+ if (condition->MaxHasteTicks < target->Haste) {
return 0;
}
- if (condition->MaxBloodlustTicks<target->Bloodlust) {
+ if (condition->MaxBloodlustTicks < target->Bloodlust) {
return 0;
}
- if (condition->MaxInvisibilityTicks<target->Invisible) {
+ if (condition->MaxInvisibilityTicks < target->Invisible) {
return 0;
}
- if (condition->MaxInvincibilityTicks<target->UnholyArmor) {
+ if (condition->MaxInvincibilityTicks < target->UnholyArmor) {
return 0;
}
}
@@ -1219,7 +1225,7 @@
**
*/
// FIXME: should be global (for AI) ???
-local Target *SelectTargetUnitsOfAutoCast(const Unit *caster, const SpellType
*spell)
+local Target* SelectTargetUnitsOfAutoCast(const Unit* caster, const SpellType*
spell)
{
Unit* table[UnitMax];
int x;
@@ -1238,38 +1244,39 @@
//
// Ai cast should be a lot better. Use autocast if not found.
//
- if (caster->Player->Ai&&spell->AICast) {
+ if (caster->Player->Ai && spell->AICast) {
DebugLevel3Fn("The borg uses AI autocast XP.\n");
- autocast=spell->AICast;
+ autocast = spell->AICast;
} else {
DebugLevel3Fn("You puny mortal, join the colective!\n");
- autocast=spell->AutoCast;
+ autocast = spell->AutoCast;
}
- x=caster->X;
- y=caster->Y;
- range=spell->AutoCast->Range;
+ x = caster->X;
+ y = caster->Y;
+ range = spell->AutoCast->Range;
//
// Select all units aroung the caster
//
nunits = SelectUnits(caster->X - range, caster->Y - range,
- caster->X + range + caster->Type->TileWidth, caster->Y + range +
caster->Type->TileHeight, table);
+ caster->X + range + caster->Type->TileWidth,
+ caster->Y + range + caster->Type->TileHeight, table);
//
// Check every unit if it is hostile
//
- combat=0;
- for (i = 0; i < nunits; i++) {
- if (IsEnemy(caster->Player,table[i]) && !table[i]->Type->Coward) {
- combat=1;
+ combat = 0;
+ for (i = 0; i < nunits; ++i) {
+ if (IsEnemy(caster->Player, table[i]) && !table[i]->Type->Coward) {
+ combat = 1;
}
}
//
// Check generic conditions. FIXME: a better way to do this?
//
- if (autocast->Combat!=CONDITION_TRUE) {
- if ((autocast->Combat==CONDITION_ONLY)^(combat)) {
+ if (autocast->Combat != CONDITION_TRUE) {
+ if ((autocast->Combat == CONDITION_ONLY) ^ (combat)) {
return 0;
}
}
@@ -1294,7 +1301,7 @@
// The units are already selected.
// Check every unit if it is a possible target
//
- for (i = 0, j = 0; i < nunits; i++) {
+ for (i = 0, j = 0; i < nunits; ++i) {
// FIXME: autocast conditions should include normal conditions.
// FIXME: no, really, they should.
if (PassCondition(caster, spell, table[i], x, y,
spell->Condition) &&
@@ -1358,7 +1365,7 @@
**
** @return Spell id (index in spell-type table)
*/
-global int SpellIdByIdent(const char *ident)
+global int SpellIdByIdent(const char* ident)
{
int id;
@@ -1379,7 +1386,7 @@
**
** @return spell-type struct pointer.
*/
-global SpellType *SpellTypeByIdent(const char *ident)
+global SpellType* SpellTypeByIdent(const char* ident)
{
int id;
@@ -1411,7 +1418,7 @@
**
** @return spell-type struct ptr
*/
-global SpellType *SpellTypeById(int id)
+global SpellType* SpellTypeById(int id)
{
DebugCheck(!(0 <= id && id < SpellTypeCount));
return &SpellTypeTable[id];
@@ -1426,7 +1433,7 @@
** @param player : player for who we want to know if he knows the spell.
** @param id :
*/
-global int SpellIsAvailable(const Player *player, int spellid)
+global int SpellIsAvailable(const Player* player, int spellid)
{
int dependencyId;
@@ -1446,7 +1453,7 @@
**
** @return 1 if spell can be cast, 0 if not
*/
-global int CanAutoCastSpell(const SpellType *spell)
+global int CanAutoCastSpell(const SpellType* spell)
{
DebugCheck(!spell);
@@ -1464,8 +1471,8 @@
**
** @return =!0 if spell should/can casted, 0 if not
*/
-global int CanCastSpell(const Unit *caster, const SpellType *spell,
- const Unit *target, // FIXME : Use an unique struture t_Target ?
+global int CanCastSpell(const Unit* caster, const SpellType* spell,
+ const Unit* target, // FIXME : Use a unique struture t_Target ?
int x, int y)
{
DebugCheck(!caster);
@@ -1475,13 +1482,13 @@
// FIXME spell->Ident < MaxSpell
DebugCheck(!(caster->Type->CanCastSpell &&
caster->Type->CanCastSpell[spell->Ident]));
- if (!caster->Type->CanCastSpell
- || !caster->Type->CanCastSpell[spell->Ident]
- || (spell->Target == TargetUnit && target == NULL)) {
+ if (!caster->Type->CanCastSpell ||
+ !caster->Type->CanCastSpell[spell->Ident] ||
+ (spell->Target == TargetUnit && target == NULL)) {
return 0;
}
- return PassCondition(caster,spell,target,x,y,spell->Condition);
+ return PassCondition(caster, spell, target, x, y, spell->Condition);
}
/**
@@ -1492,9 +1499,9 @@
**
** @return 1 if spell is casted, 0 if not.
*/
-global int AutoCastSpell(Unit *caster, const SpellType *spell)
+global int AutoCastSpell(Unit* caster, const SpellType* spell)
{
- Target *target;
+ Target* target;
DebugCheck(!caster);
DebugCheck(!spell);
@@ -1505,7 +1512,7 @@
target = NULL;
// Check for mana, trivial optimization.
- if (caster->Mana<spell->ManaCost) {
+ if (caster->Mana < spell->ManaCost) {
return 0;
}
target = SelectTargetUnitsOfAutoCast(caster, spell);
@@ -1514,7 +1521,8 @@
} else {
// Must move before ?
// FIXME SpellType* of CommandSpellCast must be const.
- CommandSpellCast(caster, target->X, target->Y, target->unit,
(SpellType*) spell, FlushCommands);
+ CommandSpellCast(caster, target->X, target->Y, target->unit,
+ (SpellType*)spell, FlushCommands);
free(target);
}
return 1;
@@ -1531,7 +1539,7 @@
**
** @return !=0 if spell should/can continue or 0 to stop
*/
-global int SpellCast(Unit *caster, const SpellType *spell, Unit *target,
+global int SpellCast(Unit* caster, const SpellType* spell, Unit* target,
int x, int y)
{
DebugCheck(!spell);
@@ -1548,8 +1556,9 @@
y += spell->Range; // Why ??
}
DebugLevel3Fn("Spell cast: (%s), %s -> %s (%d,%d)\n" _C_ spell->IdentName
_C_
- unit->Type->Name _C_ target ? target->Type->Name : "none" _C_ x _C_
y);
- return CanCastSpell(caster, spell, target, x, y) &&
spell->Action->CastFunction(caster, spell, target, x, y);
+ unit->Type->Name _C_ target ? target->Type->Name : "none" _C_ x _C_ y);
+ return CanCastSpell(caster, spell, target, x, y) &&
+ spell->Action->CastFunction(caster, spell, target, x, y);
}
/*
@@ -1588,8 +1597,8 @@
// FIXME: missile free somewhere else, right?
}
free(SpellTypeTable);
- SpellTypeTable=0;
- SpellTypeCount=0;
+ SpellTypeTable = 0;
+ SpellTypeCount = 0;
}
#if 0
Index: stratagus/src/clone/unit_find.c
diff -u stratagus/src/clone/unit_find.c:1.60
stratagus/src/clone/unit_find.c:1.61
--- stratagus/src/clone/unit_find.c:1.60 Thu Oct 9 19:15:28 2003
+++ stratagus/src/clone/unit_find.c Thu Oct 9 23:56:41 2003
@@ -26,7 +26,7 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: unit_find.c,v 1.60 2003/10/09 23:15:28 mr-russ Exp $
+// $Id: unit_find.c,v 1.61 2003/10/10 03:56:41 jsalmon3 Exp $
//@{
@@ -87,12 +87,12 @@
**
** @return Returns the number of units found
*/
-global int SelectUnits(int x1,int y1,int x2,int y2,Unit** table)
+global int SelectUnits(int x1, int y1, int x2, int y2, Unit** table)
{
- if ( x1 == x2 && y1 == y2 ) {
- return UnitCacheOnTile(x1,y1,table);
+ if (x1 == x2 && y1 == y2) {
+ return UnitCacheOnTile(x1, y1, table);
} else {
- return UnitCacheSelect(x1,y1,x2,y2,table);
+ return UnitCacheSelect(x1, y1, x2, y2, table);
}
}
@@ -105,9 +105,9 @@
**
** @return Returns the number of units found
*/
-global int SelectUnitsOnTile(int x,int y,Unit** table)
+global int SelectUnitsOnTile(int x, int y, Unit** table)
{
- return UnitCacheOnTile(x,y,table);
+ return UnitCacheOnTile(x, y, table);
}
/**
@@ -118,16 +118,16 @@
**
** @return Returns the number of units found.
*/
-global int FindUnitsByType(const UnitType* type,Unit** table)
+global int FindUnitsByType(const UnitType* type, Unit** table)
{
Unit* unit;
int i;
int num;
- for( num=i=0; i<NumUnits; i++ ) {
- unit=Units[i];
- if( unit->Type==type && !UnitUnusable(unit) ) {
- table[num++]=unit;
+ for (num = i = 0; i < NumUnits; ++i) {
+ unit = Units[i];
+ if (unit->Type == type && !UnitUnusable(unit)) {
+ table[num++] = unit;
}
}
return num;
@@ -142,8 +142,8 @@
**
** @return Returns the number of units found.
*/
-global int FindPlayerUnitsByType(const Player* player,const UnitType* type
- ,Unit** table)
+global int FindPlayerUnitsByType(const Player* player,const UnitType* type,
+ Unit** table)
{
Unit* unit;
Unit** units;
@@ -151,13 +151,13 @@
int nunits;
int i;
- nunits=player->TotalNumUnits;
- units=player->Units;
+ nunits = player->TotalNumUnits;
+ units = player->Units;
// FIXME: Can't abort if all units are found: UnitTypeCount
- for( num=0,i=0; i<nunits; i++ ) {
- unit=units[i];
- if( unit->Type==type && !UnitUnusable(unit) ) {
- table[num++]=unit;
+ for (num = 0, i = 0; i < nunits; ++i) {
+ unit = units[i];
+ if (unit->Type == type && !UnitUnusable(unit)) {
+ table[num++] = unit;
}
}
return num;
@@ -171,17 +171,17 @@
**
** @return Returns first found unit on tile.
*/
-global Unit* UnitOnMapTile(int tx,int ty)
+global Unit* UnitOnMapTile(int tx, int ty)
{
Unit* table[UnitMax];
int n;
int i;
- n=SelectUnitsOnTile(tx,ty,table);
- for( i=0; i<n; ++i ) {
+ n = SelectUnitsOnTile(tx, ty, table);
+ for (i = 0; i < n; ++i) {
// Note: this is less restrictive than UnitActionDie...
// Is it normal?
- if( table[i]->Type->Vanishes ) {
+ if (table[i]->Type->Vanishes) {
continue;
}
return table[i];
@@ -198,19 +198,19 @@
**
** @return Returns repairable unit found on tile.
*/
-global Unit* RepairableOnMapTile(int tx,int ty)
+global Unit* RepairableOnMapTile(int tx, int ty)
{
Unit* table[UnitMax];
int n;
int i;
- n=SelectUnitsOnTile(tx,ty,table);
- for( i=0; i<n; ++i ) {
+ n = SelectUnitsOnTile(tx, ty, table);
+ for (i = 0; i < n; ++i) {
// FIXME: could use more or less for repair? Repair of ships/catapults.
// Only repairable if target is a building or tansporter and it's HP is
// not at max
- if( (table[i]->Type->Building || table[i]->Type->Transporter)
- && table[i]->HP < table[i]->Stats->HitPoints ) {
+ if ((table[i]->Type->Building || table[i]->Type->Transporter) &&
+ table[i]->HP < table[i]->Stats->HitPoints) {
return table[i];
}
}
@@ -235,34 +235,34 @@
int n;
int i;
- n=SelectUnitsOnTile(tx,ty,table);
- best=NoUnitP;
- for( i=0; i<n; ++i ) {
- unit=table[i];
+ n = SelectUnitsOnTile(tx, ty, table);
+ best = NoUnitP;
+ for (i = 0; i < n; ++i) {
+ unit = table[i];
// unusable unit ?
- // if( UnitUnusable(unit) ) can't attack constructions
+ // if (UnitUnusable(unit)) can't attack constructions
// FIXME: did SelectUnitsOnTile already filter this?
// Invisible and not Visible
- if( unit->Removed || unit->Invisible || !unit->HP
- || !(unit->Visible&(1<<source->Player->Player))
- || unit->Orders[0].Action==UnitActionDie ) {
+ if (unit->Removed || unit->Invisible || !unit->HP ||
+ !(unit->Visible & (1 << source->Player->Player)) ||
+ unit->Orders[0].Action == UnitActionDie) {
continue;
}
- type=unit->Type;
- if( tx<unit->X || tx>=unit->X+type->TileWidth
- || ty<unit->Y || ty>=unit->Y+type->TileHeight ) {
+ type = unit->Type;
+ if (tx < unit->X || tx >= unit->X + type->TileWidth ||
+ ty < unit->Y || ty >= unit->Y + type->TileHeight) {
// When does that happen???
DebugLevel0("This is a wierd world");
continue;
}
- if( !CanTarget(source->Type,unit->Type) ) {
+ if (!CanTarget(source->Type, unit->Type)) {
continue;
}
//
// Choose the best target.
//
- if( !best || best->Type->Priority<unit->Type->Priority ) {
- best=unit;
+ if (!best || best->Type->Priority<unit->Type->Priority) {
+ best = unit;
}
}
return best;
@@ -279,7 +279,7 @@
**
** @return Returns ideal target on map tile.
*/
-global Unit* TargetOnMap(const Unit* source,int x1,int y1,int x2,int y2)
+global Unit* TargetOnMap(const Unit* source, int x1, int y1, int x2, int y2)
{
Unit* table[UnitMax];
Unit* unit;
@@ -288,33 +288,33 @@
int n;
int i;
- n=SelectUnits(x1,y1,x2,y2,table);
- best=NoUnitP;
- for( i=0; i<n; ++i ) {
- unit=table[i];
+ n = SelectUnits(x1, y1, x2, y2, table);
+ best = NoUnitP;
+ for (i = 0; i < n; ++i) {
+ unit = table[i];
// unusable unit ?
- // if( UnitUnusable(unit) ) can't attack constructions
+ // if (UnitUnusable(unit)) can't attack constructions
// FIXME: did SelectUnitsOnTile already filter this?
// Invisible and not Visible
- if( unit->Removed || unit->Invisible || !unit->HP
- || !(unit->Visible&(1<<source->Player->Player))
- || unit->Orders[0].Action==UnitActionDie ) {
+ if (unit->Removed || unit->Invisible || !unit->HP ||
+ !(unit->Visible & (1 << source->Player->Player)) ||
+ unit->Orders[0].Action == UnitActionDie) {
continue;
}
- type=unit->Type;
- if( x2<unit->X || x1>=unit->X+type->TileWidth
- || y2<unit->Y || y1>=unit->Y+type->TileHeight ) {
+ type = unit->Type;
+ if (x2 < unit->X || x1 >= unit->X + type->TileWidth ||
+ y2 < unit->Y || y1 >= unit->Y + type->TileHeight) {
continue;
}
- if( !CanTarget(source->Type,unit->Type) ) {
+ if (!CanTarget(source->Type, unit->Type)) {
continue;
}
//
// Choose the best target.
//
- if( !best || best->Type->Priority<unit->Type->Priority ) {
- best=unit;
+ if (!best || best->Type->Priority < unit->Type->Priority) {
+ best = unit;
}
}
return best;
@@ -328,15 +328,15 @@
**
** @return Returns transporter unit found on tile.
*/
-global Unit* TransporterOnMapTile(int tx,int ty)
+global Unit* TransporterOnMapTile(int tx, int ty)
{
Unit* table[UnitMax];
int n;
int i;
- n=SelectUnitsOnTile(tx,ty,table);
- for( i=0; i<n; ++i ) {
- if( table[i]->Type->Transporter ) {
+ n = SelectUnitsOnTile(tx, ty, table);
+ for (i = 0; i < n; ++i) {
+ if (table[i]->Type->Transporter) {
return table[i];
}
}
@@ -353,20 +353,20 @@
**
** @return true if (x,y) is inside the unit's sprite
*/
-local int InsideUnitSprite(const Unit* unit,int x,int y)
+local int InsideUnitSprite(const Unit* unit, int x, int y)
{
int ux;
int uy; // position at which unit's sprite is currently drawn
const UnitType* type;
- type=unit->Type;
- ux = TileSizeX*unit->X + unit->IX;
- ux -= (type->BoxWidth - TileSizeX*type->TileWidth)/2;
+ type = unit->Type;
+ ux = TileSizeX * unit->X + unit->IX;
+ ux -= (type->BoxWidth - TileSizeX * type->TileWidth) / 2;
uy = TileSizeY*unit->Y + unit->IY;
- uy -= (type->BoxHeight - TileSizeY*type->TileHeight)/2;
+ uy -= (type->BoxHeight - TileSizeY * type->TileHeight) / 2;
- if (x < ux || x >= ux+type->BoxWidth
- || y < uy || y >= uy+type->BoxHeight) {
+ if (x < ux || x >= ux + type->BoxWidth ||
+ y < uy || y >= uy + type->BoxHeight) {
return 0;
} else {
return 1;
@@ -386,15 +386,15 @@
**
** @return Returns the unit if found, or NoUnitP.
*/
-global Unit* UnitTypeOnMap(int tx,int ty,UnitType* type)
+global Unit* UnitTypeOnMap(int tx, int ty, UnitType* type)
{
Unit* table[UnitMax];
int i;
int n;
- n=SelectUnitsOnTile(tx,ty,table);
- for( i=0; i<n; ++i ) {
- if( table[i]->Type==type ) {
+ n = SelectUnitsOnTile(tx, ty, table);
+ for (i = 0; i < n; ++i) {
+ if (table[i]->Type == type) {
return table[i];
}
}
@@ -410,18 +410,19 @@
**
** @return Returns the deposit if found, or NoUnitP.
*/
-global Unit* ResourceOnMap(int tx,int ty,int resource)
+global Unit* ResourceOnMap(int tx, int ty, int resource)
{
Unit* table[UnitMax];
int i;
int n;
- n=SelectUnitsOnTile(tx,ty,table);
- for( i=0; i<n; ++i ) {
- if( UnitUnusable(table[i]) || !table[i]->Type->CanHarvest ||
table[i]->Value==0) {
+ n = SelectUnitsOnTile(tx, ty, table);
+ for (i = 0; i < n; ++i) {
+ if (UnitUnusable(table[i]) || !table[i]->Type->CanHarvest ||
+ table[i]->Value == 0) {
continue;
}
- if( table[i]->Type->GivesResource==resource ) {
+ if (table[i]->Type->GivesResource == resource) {
return table[i];
}
}
@@ -437,18 +438,18 @@
**
** @return Returns the deposit if found, or NoUnitP.
*/
-global Unit* ResourceDepositOnMap(int tx,int ty,int resource)
+global Unit* ResourceDepositOnMap(int tx, int ty, int resource)
{
Unit* table[UnitMax];
int i;
int n;
- n=SelectUnitsOnTile(tx,ty,table);
- for( i=0; i<n; ++i ) {
- if( UnitUnusable(table[i]) ) {
+ n = SelectUnitsOnTile(tx, ty, table);
+ for (i = 0; i < n; ++i) {
+ if (UnitUnusable(table[i])) {
continue;
}
- if( table[i]->Type->CanStore[resource] ) {
+ if (table[i]->Type->CanStore[resource]) {
return table[i];
}
}
@@ -503,17 +504,31 @@
*/
local Unit* FindRangeAttack(Unit* u, int range)
{
- int x, y, n, cost,d,effective_hp,enemy_count;
- int missile_range,attackrange,hp_damage_evaluate;
- int good[32][32], bad[32][32];
+ int x;
+ int y;
+ int n;
+ int cost;
+ int d;
+ int effective_hp;
+ int enemy_count;
+ int missile_range;
+ int attackrange;
+ int hp_damage_evaluate;
+ int good[32][32];
+ int bad[32][32];
Unit* table[UnitMax];
Unit* dest;
const UnitType* dtype;
const UnitType* type;
const Player* player;
- int xx, yy;
- int best_x, best_y, best_cost;
- int i, sbad, sgood;
+ int xx;
+ int yy;
+ int best_x;
+ int best_y;
+ int best_cost;
+ int i;
+ int sbad;
+ int sgood;
Unit* best;
type = u->Type;
@@ -524,9 +539,9 @@
//
missile_range = type->Missile.Missile->Range + range - 1;
- attackrange=u->Stats->AttackRange;
+ attackrange = u->Stats->AttackRange;
// Evaluation of possible damage...
- hp_damage_evaluate=u->Stats->BasicDamage+u->Stats->PiercingDamage;
+ hp_damage_evaluate = u->Stats->BasicDamage + u->Stats->PiercingDamage;
DebugCheck(2 * missile_range + 1 >= 32);
@@ -539,28 +554,28 @@
return NoUnitP;
}
- for (y = 0; y < 2 * missile_range + 1; y++) {
- for (x = 0; x < 2 * missile_range + 1; x++) {
+ for (y = 0; y < 2 * missile_range + 1; ++y) {
+ for (x = 0; x < 2 * missile_range + 1; ++x) {
good[y][x] = 0;
bad[y][x] = 0;
}
}
- enemy_count=0;
+ enemy_count = 0;
// FIXME: (mr-russ) Breaks all good coding rules...
- localunit=u;
- qsort((void *)table,n,sizeof(Unit*),InDistanceCompare);
+ localunit = u;
+ qsort((void*)table, n, sizeof(Unit*), InDistanceCompare);
// FILL good/bad...
- for (i = 0; i < n; i++) {
+ for (i = 0; i < n; ++i) {
dest = table[i];
dtype = dest->Type;
//
// unusable unit
//
// FIXME: did SelectUnits already filter this.
- if (dest->Removed || dest->Invisible || !u->HP
- || !(dest->Visible & (1 << player->Player))
- || dest->Orders[0].Action == UnitActionDie) {
+ if (dest->Removed || dest->Invisible || !u->HP ||
+ !(dest->Visible & (1 << player->Player)) ||
+ dest->Orders[0].Action == UnitActionDie) {
table[i] = 0;
continue;
}
@@ -578,9 +593,10 @@
// The gost is more important when the unit would be killed
// by our fire.
- // It costs ( is positive ) if hp_damage_evaluate>dest->HP ... )
+ // It costs (is positive) if hp_damage_evaluate>dest->HP ...)
// FIXME : assume that PRIORITY_FACTOR>HEALTH_FACTOR
- cost = HEALTH_FACTOR*(2*hp_damage_evaluate-dest->HP) /
(dtype->TileWidth * dtype->TileWidth);
+ cost = HEALTH_FACTOR * (2 * hp_damage_evaluate - dest->HP) /
+ (dtype->TileWidth * dtype->TileWidth);
if (cost < 1) {
cost = 1;
}
@@ -603,27 +619,27 @@
//
// calculate HP which will remain in the enemy unit, after hit
//
- effective_hp=(dest->HP-2*hp_damage_evaluate);
+ effective_hp = (dest->HP - 2 * hp_damage_evaluate);
//
// Unit we won't kill are evaluated the same
//
- if (effective_hp>0){
- effective_hp=0;
+ if (effective_hp > 0){
+ effective_hp = 0;
}
//
- // Unit we are sure to kill are all evaluated the same ( except
PRIORITY )
+ // Unit we are sure to kill are all evaluated the same (except
PRIORITY)
//
- if (effective_hp<(-hp_damage_evaluate)){
- effective_hp=(-hp_damage_evaluate);
+ if (effective_hp < -hp_damage_evaluate){
+ effective_hp = -hp_damage_evaluate;
}
//
- // Here, effective_hp vary from -hp_damage_evaluate ( unit will be
killed) to 0 ( unit can't be killed )
+ // Here, effective_hp vary from -hp_damage_evaluate (unit will be
killed) to 0 (unit can't be killed)
// => we prefer killing rather than only hitting...
//
- cost += (-effective_hp) * HEALTH_FACTOR;
+ cost += -effective_hp * HEALTH_FACTOR;
//
// Unit can attack back.
@@ -635,28 +651,28 @@
//
// the cost may be divided accros multiple cells
//
- cost=cost / (dtype->TileWidth * dtype->TileWidth);
+ cost = cost / (dtype->TileWidth * dtype->TileWidth);
if (cost < 1) {
cost = 1;
}
- d=MapDistanceBetweenUnits(u,dest);
+ d = MapDistanceBetweenUnits(u, dest);
- if((d<=range)&&UnitReachable(u,dest,attackrange)) {
- enemy_count++;
+ if (d <= range && UnitReachable(u, dest, attackrange)) {
+ ++enemy_count;
} else {
- table[i]=0;
+ table[i] = 0;
}
}
- x = dest->X - u->X + missile_range+1;
- y = dest->Y - u->Y + missile_range+1;
+ x = dest->X - u->X + missile_range + 1;
+ y = dest->Y - u->Y + missile_range + 1;
// Mark the good/bad array...
- for (xx = 0; xx < dtype->TileWidth; xx++) {
- for (yy = 0; yy < dtype->TileWidth; yy++) {
- if ((x + xx < 0) || (y + yy < 0)
- || (x + xx >= 2 * missile_range + 1)
- || (y + yy >= 2 * missile_range + 1)) {
+ for (xx = 0; xx < dtype->TileWidth; ++xx) {
+ for (yy = 0; yy < dtype->TileWidth; ++yy) {
+ if ((x + xx < 0) || (y + yy < 0) ||
+ (x + xx >= 2 * missile_range + 1) ||
+ (y + yy >= 2 * missile_range + 1)) {
continue;
}
if (cost < 0) {
@@ -678,7 +694,7 @@
best_y = -1;
best_cost = -1;
best = NoUnitP;
- for (i = 0; i < n; i++) {
+ for (i = 0; i < n; ++i) {
if (!table[i]) {
continue;
}
@@ -686,42 +702,42 @@
dtype = dest->Type;
// put in x-y the real point which will be hit...
- // ( only meaningfull when dtype->TileWidth>1 )
- if (u->X<dest->X){
- x=dest->X;
- } else if (u->X>dest->X+dtype->TileWidth-1){
- x=dest->X+dtype->TileWidth-1;
+ // (only meaningfull when dtype->TileWidth > 1)
+ if (u->X < dest->X){
+ x = dest->X;
+ } else if (u->X > dest->X + dtype->TileWidth - 1){
+ x = dest->X + dtype->TileWidth - 1;
} else {
- x=u->X;
+ x = u->X;
}
- if (u->Y<dest->Y){
- y=dest->Y;
- } else if(u->Y>dest->Y+dtype->TileWidth-1){
- y=dest->Y+dtype->TileWidth-1;
+ if (u->Y < dest->Y){
+ y = dest->Y;
+ } else if(u->Y > dest->Y + dtype->TileWidth - 1){
+ y = dest->Y + dtype->TileWidth - 1;
} else {
- y=u->Y;
+ y = u->Y;
}
// Make x,y relative to u->x...
- x = x - u->X + missile_range+1;
- y = y - u->Y + missile_range+1;
+ x = x - u->X + missile_range + 1;
+ y = y - u->Y + missile_range + 1;
sbad = 0;
sgood = 0;
for (yy = -(type->Missile.Missile->Range - 1);
- yy <= type->Missile.Missile->Range - 1; yy++) {
+ yy <= type->Missile.Missile->Range - 1; ++yy) {
for (xx = -(type->Missile.Missile->Range - 1);
- xx <= type->Missile.Missile->Range - 1; xx++) {
- if ((x + xx < 0) || (y + yy < 0)
- || ((x + xx) >= 2 * missile_range + 1)
- || ((y + yy) >= 2 * missile_range + 1)) {
+ xx <= type->Missile.Missile->Range - 1; ++xx) {
+ if ((x + xx < 0) || (y + yy < 0) ||
+ ((x + xx) >= 2 * missile_range + 1) ||
+ ((y + yy) >= 2 * missile_range + 1)) {
continue;
}
sbad += bad[y + yy][x + xx];
sgood += good[y + yy][x + xx];
- if ((!yy) && (!xx)) {
+ if (!yy && !xx) {
sbad += bad[y + yy][x + xx];
sgood += good[y + yy][x + xx];
}
@@ -754,7 +770,7 @@
** @return Unit to be attacked.
**
*/
-global Unit* AttackUnitsInDistance(Unit* unit,int range)
+global Unit* AttackUnitsInDistance(Unit* unit, int range)
{
Unit* dest;
const UnitType* type;
@@ -775,51 +791,52 @@
DebugLevel3Fn("(%d)%s\n" _C_ UnitNumber(unit) _C_ unit->Type->Ident);
// if necessary, take possible damage on allied units into account...
- if (unit->Type->Missile.Missile->Range>1
- && (range+unit->Type->Missile.Missile->Range<15)) {
- return FindRangeAttack(unit,range);
+ if (unit->Type->Missile.Missile->Range > 1 &&
+ (range + unit->Type->Missile.Missile->Range < 15)) {
+ return FindRangeAttack(unit, range);
}
//
// Select all units in range.
//
- x=unit->X;
- y=unit->Y;
- type=unit->Type;
-
n=SelectUnits(x-range,y-range,x+range+type->TileWidth-1,y+range+type->TileHeight-1,table);
-
- best_unit=NoUnitP;
- best_cost=INT_MAX;
- tried_units=0;
+ x = unit->X;
+ y = unit->Y;
+ type = unit->Type;
+ n = SelectUnits(x - range, y - range, x + range + type->TileWidth - 1,
+ y + range + type->TileHeight - 1, table);
+
+ best_unit = NoUnitP;
+ best_cost = INT_MAX;
+ tried_units = 0;
- player=unit->Player;
- attackrange=unit->Stats->AttackRange;
+ player = unit->Player;
+ attackrange = unit->Stats->AttackRange;
//
// Find the best unit to attack
//
// FIXME: (mr-russ) Breaks all good coding rules...
- localunit=unit;
- qsort((void *)table,n,sizeof(Unit*),InDistanceCompare);
- for( i=0; i<n; ++i ) {
- dest=table[i];
+ localunit = unit;
+ qsort((void*)table, n, sizeof(Unit*), InDistanceCompare);
+ for (i = 0; i < n; ++i) {
+ dest = table[i];
//
// unusable unit
//
// FIXME: did SelectUnits already filter this.
- if( dest->Removed || dest->Invisible || !unit->HP
- || !(dest->Visible&(1<<player->Player))
- || dest->Orders[0].Action==UnitActionDie ) {
+ if (dest->Removed || dest->Invisible || !unit->HP ||
+ !(dest->Visible & (1 << player->Player)) ||
+ dest->Orders[0].Action == UnitActionDie) {
continue;
}
- if( !IsEnemy(player,dest) ) { // a friend or neutral
+ if (!IsEnemy(player, dest)) { // a friend or neutral
continue;
}
- dtype=dest->Type;
- if( !CanTarget(type,dtype) ) { // can't be attacked.
+ dtype = dest->Type;
+ if (!CanTarget(type, dtype)) { // can't be attacked.
continue;
}
@@ -827,35 +844,35 @@
// Calculate the costs to attack the unit.
// Unit with the smallest attack costs will be taken.
//
- cost=0;
+ cost = 0;
//
// Priority 0-255
//
- cost-=dtype->Priority*PRIORITY_FACTOR;
+ cost -= dtype->Priority * PRIORITY_FACTOR;
//
// Remaining HP (Health) 0-65535
//
- cost+=dest->HP*HEALTH_FACTOR;
+ cost += dest->HP * HEALTH_FACTOR;
//
// Unit in attack range?
//
- d=MapDistanceBetweenUnits(unit,dest);
+ d = MapDistanceBetweenUnits(unit, dest);
// Use Circle, not square :)
- if( d>range ) {
+ if (d > range) {
continue;
}
- if( d<attackrange && d>type->MinAttackRange ) {
- cost+=d*INRANGE_FACTOR;
- cost-=INRANGE_BONUS;
+ if (d < attackrange && d > type->MinAttackRange) {
+ cost += d * INRANGE_FACTOR;
+ cost -= INRANGE_BONUS;
} else {
- cost+=d*DISTANCE_FACTOR;
+ cost += d * DISTANCE_FACTOR;
}
//
// Unit can attack back.
//
- if( CanTarget(dtype,type) ) {
- cost-=CANATTACK_BONUS;
+ if (CanTarget(dtype, type)) {
+ cost -= CANATTACK_BONUS;
}
DebugLevel3Fn("%s -> %s\t%08x\n" _C_ type->Ident _C_ dtype->Ident _C_
cost);
@@ -863,22 +880,23 @@
// Take this target?
//
// If we failed 5 closest units, we probably can't get anything
- if( tried_units >= 5 && best_cost == INT_MAX ) {
- best_unit=NULL;
+ if (tried_units >= 5 && best_cost == INT_MAX) {
+ best_unit = NULL;
break;
}
- if( cost<best_cost && d>attackrange &&
!UnitReachable(unit,dest,attackrange)) {
- tried_units++;
+ if (cost < best_cost && d > attackrange &&
+ !UnitReachable(unit, dest, attackrange)) {
+ ++tried_units;
} else {
- best_unit=dest;
- best_cost=cost;
+ best_unit = dest;
+ best_cost = cost;
}
}
/*
- if( best_unit ) {
+ if (best_unit) {
DebugLevel3Fn("Attacking (%d)%s -> %s\n" _C_ UnitNumber(unit) _C_
- unit->Type->Ident _C_ best_unit->Type->Ident);
+ unit->Type->Ident _C_ best_unit->Type->Ident);
}
*/
@@ -897,16 +915,15 @@
//
// Only units which can attack.
//
- IfDebug(
-
- if( !unit->Type->CanAttack ) {
- DebugLevel0Fn("Should be handled by caller?\n");
- abort();
- return NoUnitP;
- }
- );
+#ifdef DEBUG
+ if (!unit->Type->CanAttack) {
+ DebugLevel0Fn("Should be handled by caller?\n");
+ DebugCheck(1);
+ return NoUnitP;
+ }
+#endif
- return AttackUnitsInDistance(unit,unit->Stats->AttackRange);
+ return AttackUnitsInDistance(unit, unit->Stats->AttackRange);
}
/**
@@ -924,22 +941,22 @@
//
// Only units which can attack.
//
- type=unit->Type;
- IfDebug(
- if( !type->CanAttack ) {
- DebugLevel0Fn("Should be handled by caller?\n");
- abort();
- return NoUnitP;
- }
- );
+ type = unit->Type;
+#ifdef DEBUG
+ if (!type->CanAttack) {
+ DebugLevel0Fn("Should be handled by caller?\n");
+ DebugCheck(1);
+ return NoUnitP;
+ }
+#endif
- if( unit->Player->Type==PlayerPerson ) {
- range=type->ReactRangePerson;
+ if (unit->Player->Type == PlayerPerson) {
+ range = type->ReactRangePerson;
} else {
- range=type->ReactRangeComputer;
+ range = type->ReactRangeComputer;
}
- return AttackUnitsInDistance(unit,range);
+ return AttackUnitsInDistance(unit, range);
}
//@}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Stratagus-CVS] stratagus/src/clone mainloop.c player.c selecti...,
Jimmy Salmon <=