merge
authorkoda
Wed, 18 Jan 2012 01:11:09 +0100
changeset 6586 51d5dd5464aa
parent 6585 6225b838a630 (diff)
parent 6577 9e49e6a8585b (current diff)
child 6587 3a0b9257c4f9
merge
QTfrontend/ui/page/pagemain.cpp
--- a/QTfrontend/gameuiconfig.cpp	Mon Jan 16 00:03:13 2012 +0100
+++ b/QTfrontend/gameuiconfig.cpp	Wed Jan 18 01:11:09 2012 +0100
@@ -61,7 +61,7 @@
     Form->ui.pageOptions->CBFrontendEffects->setChecked(frontendEffects);
     Form->ui.pageOptions->CBEnableSound->setChecked(value("audio/sound", true).toBool());
     Form->ui.pageOptions->CBEnableFrontendSound->setChecked(value("frontend/sound", true).toBool());
-    Form->ui.pageOptions->CBEnableMusic->setChecked(value("audio/music", true).toBool());
+    Form->ui.pageOptions->CBEnableMusic->setChecked(value(" audio/music", true).toBool());
     Form->ui.pageOptions->CBEnableFrontendMusic->setChecked(value("frontend/music", true).toBool());
     Form->ui.pageOptions->volumeBox->setValue(value("audio/volume", 100).toUInt());
 
--- a/QTfrontend/hedgewars.qrc	Mon Jan 16 00:03:13 2012 +0100
+++ b/QTfrontend/hedgewars.qrc	Wed Jan 18 01:11:09 2012 +0100
@@ -1,8 +1,11 @@
 <RCC>
     <qresource prefix="/">
         <file alias="Ammos.png">../share/hedgewars/Data/Graphics/AmmoMenu/Ammos.png</file>
-		  <file>res/css/qt.css</file>
-		  <file>res/css/chat.css</file>
+        <file>res/css/qt.css</file>
+        <file>res/css/chat.css</file>
+        <file>res/css/christmas.css</file>
+        <file>res/css/easter.css</file>
+        <file>res/css/birthday.css</file>		  
         <file>res/hh25x25.png</file>
         <file>res/hh25x25grey.png</file>
         <file>res/ammopic.png</file>
@@ -34,6 +37,9 @@
         <file>res/Multiplayer.png</file>
         <file>res/Trainings.png</file>
         <file>res/Background.png</file>
+        <file>res/BackgroundChristmas.png</file>
+        <file>res/BackgroundEaster.png</file>
+        <file>res/BackgroundBirthday.png</file>
         <file>res/Exit.png</file>
         <file>res/HedgewarsTitle.png</file>
         <file>res/LocalPlay.png</file>
@@ -95,6 +101,9 @@
         <file>res/iconRope.png</file>
         <file>res/dice.png</file>
         <file>res/Star.png</file>
+	<file>res/Flake.png</file>
+	<file>res/Egg.png</file>
+	<file>res/Confetti.png</file>
         <file>res/file_save.png</file>
         <file>res/file_demo.png</file>
         <file>res/chat_default.png</file>
--- a/QTfrontend/hwconsts.cpp.in	Mon Jan 16 00:03:13 2012 +0100
+++ b/QTfrontend/hwconsts.cpp.in	Wed Jan 18 01:11:09 2012 +0100
@@ -71,3 +71,6 @@
 
 bool haveServer = ${HAVE_NETSERVER};
 bool isDevBuild = ${HW_DEV};
+
+int season = SEASON_NONE;
+int years_since_foundation = 0;
--- a/QTfrontend/hwconsts.h	Mon Jan 16 00:03:13 2012 +0100
+++ b/QTfrontend/hwconsts.h	Wed Jan 18 01:11:09 2012 +0100
@@ -56,24 +56,32 @@
 
 extern bool haveServer;
 extern bool isDevBuild;
+
+//Current season, SEASON_NONE by default
+extern int season;
+//On the day of hedgewars birthday (Oct 31st) this variable is assigned
+//with number of years past 2004 (foundation of hedgewars)
+//Could be used to implement a text/graphic like "This is the xxth birthday of hedgewars" or similar
+extern int years_since_foundation;
+
 #endif
 
 #define HEDGEHOGS_PER_TEAM           8
 
 #define AMMOLINE_DEFAULT_QT     "939192942219912103223511100120100000021111010101111101"
-#define AMMOLINE_DEFAULT_PROB   "040504054160065554655446477657666666615551010111541111"
+#define AMMOLINE_DEFAULT_PROB   "040504054160065554655446477657666666615551010111541101"
 #define AMMOLINE_DEFAULT_DELAY  "000000000000020550000004000700400000000022000000060000"
-#define AMMOLINE_DEFAULT_CRATE  "131111031211111112311411111111111111121111110111111111"
+#define AMMOLINE_DEFAULT_CRATE  "131111031211111112311411111111111111121111110111111101"
 
-#define AMMOLINE_CRAZY_QT       "999999999999999999299999999999999929999999990999999229"
-#define AMMOLINE_CRAZY_PROB     "111111011111111111111111111111111111111111110111111111"
+#define AMMOLINE_CRAZY_QT       "999999999999999999299999999999999929999999990999999209"
+#define AMMOLINE_CRAZY_PROB     "111111011111111111111111111111111111111111110111111101"
 #define AMMOLINE_CRAZY_DELAY    "000000000000000000000000000000000000000000000000000000"
-#define AMMOLINE_CRAZY_CRATE    "131111031211111112311411111111111111121111010111111111"
+#define AMMOLINE_CRAZY_CRATE    "131111031211111112311411111111111111121111010111111101"
 
 #define AMMOLINE_PROMODE_QT     "909000900000000000000900000000000000000000000000000000"
 #define AMMOLINE_PROMODE_PROB   "000000000000000000000000000000000000000000000000000000"
 #define AMMOLINE_PROMODE_DELAY  "000000000000020550000004000700400000000020000000000000"
-#define AMMOLINE_PROMODE_CRATE  "111111111111111111111111111111111111111110010111111111"
+#define AMMOLINE_PROMODE_CRATE  "111111111111111111111111111111111111111110010111111101"
 
 #define AMMOLINE_SHOPPA_QT      "000000990000000000000000000000000000000000000000000000"
 #define AMMOLINE_SHOPPA_PROB    "444441004424440221011212122242200000000200040001001100"
@@ -81,20 +89,25 @@
 #define AMMOLINE_SHOPPA_CRATE   "111111111111111111111111111111111111111110110111111100"
 
 #define AMMOLINE_CLEAN_QT       "101000900001000001100000000000000000000000000000100000"
-#define AMMOLINE_CLEAN_PROB     "040504054160065554655446477657666666615551010111541111"
+#define AMMOLINE_CLEAN_PROB     "040504054160065554655446477657666666615551010111541101"
 #define AMMOLINE_CLEAN_DELAY    "000000000000000000000000000000000000000000000000000000"
-#define AMMOLINE_CLEAN_CRATE    "131111031211111112311411111111111111121111110111111111"
+#define AMMOLINE_CLEAN_CRATE    "131111031211111112311411111111111111121111110111111101"
 
 #define AMMOLINE_MINES_QT       "000000990009000000030000000000000000000000000000000000"
 #define AMMOLINE_MINES_PROB     "000000000000000000000000000000000000000000000000000000"
 #define AMMOLINE_MINES_DELAY    "000000000000020550000004000700400000000020000000060000"
-#define AMMOLINE_MINES_CRATE    "111111111111111111111111111111111111111111110111111111"
+#define AMMOLINE_MINES_CRATE    "111111111111111111111111111111111111111111110111111101"
 
 #define AMMOLINE_PORTALS_QT     "900000900200000000210000000000000011000009000000000000"
-#define AMMOLINE_PORTALS_PROB   "040504054160065554655446477657666666615551010111541111"
+#define AMMOLINE_PORTALS_PROB   "040504054160065554655446477657666666615551010111541101"
 #define AMMOLINE_PORTALS_DELAY  "000000000000020550000004000700400000000020000000060000"
-#define AMMOLINE_PORTALS_CRATE  "131111031211111112311411111111111111121111110111111111"
+#define AMMOLINE_PORTALS_CRATE  "131111031211111112311411111111111111121111110111111101"
 
+//Different seasons; assigned to season (int)
+#define SEASON_NONE 0
+#define SEASON_CHRISTMAS 2
+#define SEASON_HWBDAY 4
+#define SEASON_EASTER 8
 
 #define NETGAME_DEFAULT_PORT 46631
 
--- a/QTfrontend/main.cpp	Mon Jan 16 00:03:13 2012 +0100
+++ b/QTfrontend/main.cpp	Wed Jan 18 01:11:09 2012 +0100
@@ -26,6 +26,7 @@
 #include <QMap>
 #include <QSettings>
 #include <QStringListModel>
+#include <QDate>
 
 #include "hwform.h"
 #include "hwconsts.h"
@@ -39,6 +40,50 @@
 #include "CocoaInitializer.h"
 #endif
 
+
+//Determines the day of easter in year
+//from http://aa.usno.navy.mil/faq/docs/easter.php,adapted to C/C++
+QDate calculateEaster(long year)
+{
+    int c, n, k, i, j, l, m, d;
+    
+    c = year/100;
+    n = year - 19*(year/19);
+    k = (c - 17)/25;
+    i = c - c/4 - (c - k)/3 + 19*n + 15;
+    i = i - 30*(i/30);
+    i = i - (i/28)*(1 - (i/28)*(29/(i + 1))*((21 - n)/11));
+    j = year + year/4 + i + 2 - c + c/4;
+    j = j - 7*(j/7);
+    l = i - j;
+    m = 3 + (l + 40)/44;
+    d = l + 28 - 31*(m / 4);
+
+    return QDate(year, m, d);
+}
+
+//Checks season and assigns it to the variable season in "hwconsts.h"
+void checkSeason()
+{
+   QDate date = QDate::currentDate();
+   
+   //Christmas?
+   if (date.month() == 12 && date.daysInMonth() >= 24 
+	&& date.daysInMonth() <= 26)
+	season = SEASON_CHRISTMAS;
+   //Hedgewars birthday?
+   else if (date.month() == 10 && date.daysInMonth() == 31)
+   {
+   	season = SEASON_HWBDAY;
+	years_since_foundation = date.year() - 2004;
+   }
+   //Easter?
+   else if (calculateEaster(date.year()) == date)
+	season = SEASON_EASTER;
+   else
+	season = SEASON_NONE;
+}
+
 bool checkForDir(const QString & dir)
 {
     QDir tmpdir;
@@ -244,11 +289,28 @@
 #endif
 
     QString style = "";
+    QString fname;
+    
+    checkSeason();
+    //For each season, there is an extra stylesheet
+    //Todo: change background for easter and birthday
+    //(simply replace res/BackgroundBirthday.png and res/BackgroundEaster.png
+    //with an appropriate background
+    switch (season)
+    {
+    case SEASON_CHRISTMAS : fname = "christmas.css";
+			    break;
+    case SEASON_EASTER : fname = "easter.css";
+			 break;
+    case SEASON_HWBDAY : fname = "birthday.css";
+			 break;
+    default : fname = "qt.css";
+    }
 
     // load external stylesheet if there is any
-    QFile extFile(dataMgr.findFileForRead("css/qt.css"));
+    QFile extFile(dataMgr.findFileForRead("css/" + fname));
 
-    QFile resFile(":/res/css/qt.css");
+    QFile resFile(":/res/css/" + fname);
 
     QFile & file = (extFile.exists()?extFile:resFile);
 
Binary file QTfrontend/res/BackgroundBirthday.png has changed
Binary file QTfrontend/res/BackgroundChristmas.png has changed
Binary file QTfrontend/res/BackgroundEaster.png has changed
Binary file QTfrontend/res/Confetti.png has changed
Binary file QTfrontend/res/Egg.png has changed
Binary file QTfrontend/res/Flake.png has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/res/css/birthday.css	Wed Jan 18 01:11:09 2012 +0100
@@ -0,0 +1,248 @@
+/******************************************************************************
+ *
+ * CSS-like definition of Qt frontend appearance
+ *
+ ******************************************************************************
+ *
+ * see http://doc.qt.nokia.com/4.5/stylesheet.html
+ *
+ ******************************************************************************
+ *
+ * This file can be stored at different locations, but it will be read only
+ * once, based on first file found in this order:
+ *
+ *    <userdir>/Data/css/birthday.css
+ *    <datadir>/css/birthday.css
+ *    <internal default style-sheet> (:/res/css/birthday.css)
+ *
+ *****************************************************************************/
+
+HWForm,QDialog {
+background-image: url(":/res/BackgroundBirthday.png");
+background-position: bottom center;
+background-repeat: repeat-x;
+background-color: #141250;
+}
+
+* {
+color: #ffcc00;
+selection-background-color: #ffcc00;
+selection-color: #00351d;
+}
+
+a { color:#c8c8ff; }
+
+QLineEdit, QListWidget, QTableView, QTextBrowser, QSpinBox, QComboBox,
+QComboBox QAbstractItemView, QMenu::item {
+background-color: rgba(13, 5, 68, 70%);
+}
+
+QComboBox::separator {
+border: solid; border-width: 3px; border-color: #ffcc00;
+}
+
+QPushButton, QListWidget, QTableView, QLineEdit, QHeaderView,
+QTextBrowser, QSpinBox, QToolBox, QComboBox,
+QComboBox QAbstractItemView, IconedGroupBox,
+.QGroupBox, GameCFGWidget, TeamSelWidget, SelWeaponWidget,
+QTabWidget::pane, QTabBar::tab {
+border: solid;
+border-width: 3px;
+border-color: #ffcc00;
+}
+
+QPushButton:hover, QLineEdit:hover, QListWidget:hover,
+QSpinBox:hover, QToolBox:hover, QComboBox:hover {
+border-color: yellow;
+}
+
+QLineEdit, QListWidget,QTableView, QTextBrowser,
+QSpinBox, QToolBox {
+border-radius: 10px;
+}
+
+QLineEdit, QLabel, QHeaderView, QListWidget, QTableView,
+QSpinBox, QToolBox::tab, QComboBox, QComboBox QAbstractItemView,
+IconedGroupBox, .QGroupBox, GameCFGWidget, TeamSelWidget,
+SelWeaponWidget, QCheckBox, QRadioButton, QPushButton {
+font: bold 13px;
+}
+SelWeaponWidget QTabWidget::pane, SelWeaponWidget QTabBar::tab:selected {
+background-position: bottom center;
+background-repeat: repeat-x;
+background-color: #000000;
+}
+.QGroupBox,GameCFGWidget,TeamSelWidget,SelWeaponWidget {
+background-position: bottom center;
+background-repeat: repeat-x;
+border-radius: 16px;
+background-color: rgba(13, 5, 68, 70%);
+padding: 6px;
+}
+/*  Experimenting with PaintOnScreen and border-radius on IconedGroupBox children didn't work out well
+IconedGroupBox QComboBox, IconedGroupBox QPushButton, IconedGroupBox QLineEdit,
+IconedGroupBox QSpinBox {
+border-radius: 0;
+}
+IconedGroupBox, IconedGroupBox *, QTabWidget::pane, QTabBar::tab:selected, QToolBox::tab QWidget{" */
+IconedGroupBox, QTabWidget::pane, QTabBar::tab:selected, QToolBox::tab QWidget{
+background-color: #130f2c;
+}
+
+
+QPushButton {
+border-radius: 8px;
+background-origin: margin;
+background-position: top left;
+background-color: rgba(18, 42, 5, 70%);
+}
+
+QPushButton:pressed{
+border-color: white;
+}
+
+QPushButton:focus {
+outline: none;
+}
+
+
+QHeaderView {
+border-radius: 0;
+border-width: 0;
+border-bottom-width: 3px;
+background-color: #00351d;
+}
+QTableView {
+alternate-background-color: #2f213a;
+gridline-color: transparent;
+}
+
+QTabBar::tab {
+border-bottom-width: 0;
+border-radius: 0;
+border-top-left-radius: 6px;
+border-top-right-radius: 6px;
+padding: 3px;
+}
+QTabBar::tab:!selected {
+color: #0d0544;
+background-color: #ffcc00;
+}
+QSpinBox::up-button{
+background: transparent;
+width: 16px;
+height: 10px;
+}
+
+QSpinBox::up-arrow {
+image: url(":/res/spin_up.png");
+}
+
+QSpinBox::down-arrow {
+image: url(":/res/spin_down.png");
+}
+
+QSpinBox::down-button {
+background: transparent;
+width: 16px;
+height: 10px;
+}
+
+QComboBox {
+border-radius: 10px;
+padding: 3px;
+}
+QComboBox:pressed{
+border-color: white;
+}
+QComboBox::drop-down{
+border: transparent;
+width: 25px;
+}
+QComboBox::down-arrow {
+image: url(":/res/dropdown.png");
+}
+
+VertScrArea {
+background-position: bottom center;
+background-repeat: repeat-x;
+}
+
+IconedGroupBox {
+border-radius: 16px;
+padding: 2px;
+}
+
+QGroupBox::title{
+subcontrol-origin: margin;
+subcontrol-position: top left;
+text-align: left;
+left: 15px;
+top: -4px;
+}
+
+QCheckBox::indicator:checked{
+image: url(":/res/checked.png");
+}
+QCheckBox::indicator:unchecked{
+image: url(":/res/unchecked.png");
+}
+
+.QWidget{
+background: transparent;
+}
+
+QTabWidget::pane {
+border-top-width: 2px;
+}
+
+QMenu{
+background-color: #ffcc00;
+margin: 3px;
+}
+QMenu::item {
+background-color: #0d0544;
+border: 1px solid transparent;
+font: bold;
+padding: 2px 25px 2px 20px;
+}
+QMenu::item:selected {
+background-color: #2d2564;
+}
+QMenu::indicator {
+width: 16px;
+height: 16px;
+}
+QMenu::indicator:non-exclusive:checked{
+image: url(":/res/checked.png");
+}
+QMenu::indicator:non-exclusive:unchecked{
+image: url(":/res/unchecked.png");
+}
+
+QToolTip{
+background-color: #0d0544;
+border: 1px solid #ffcc00;
+}
+
+:disabled{
+color: #a0a0a0;
+}
+SquareLabel, ItemNum {
+background-color: #000000;
+}
+
+QSlider::groove::horizontal {
+height: 2px;
+margin: 2px 0px;
+background-color: #ffcc00;
+}
+
+QSlider::handle::horizontal {
+border: 0px;
+margin: -2px 0px;
+border-radius: 3px;
+background-color: #ffcc00;
+width: 8px;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/res/css/christmas.css	Wed Jan 18 01:11:09 2012 +0100
@@ -0,0 +1,248 @@
+/******************************************************************************
+ *
+ * CSS-like definition of Qt frontend appearance
+ *
+ ******************************************************************************
+ *
+ * see http://doc.qt.nokia.com/4.5/stylesheet.html
+ *
+ ******************************************************************************
+ *
+ * This file can be stored at different locations, but it will be read only
+ * once, based on first file found in this order:
+ *
+ *    <userdir>/Data/css/christmas.css
+ *    <datadir>/css/christmas.css
+ *    <internal default style-sheet> (:/res/css/christmas.css)
+ *
+ *****************************************************************************/
+
+HWForm,QDialog {
+background-image: url(":/res/BackgroundChristmas.png");
+background-position: bottom center;
+background-repeat: repeat-x;
+background-color: #141250;
+}
+
+* {
+color: #ffcc00;
+selection-background-color: #ffcc00;
+selection-color: #00351d;
+}
+
+a { color:#c8c8ff; }
+
+QLineEdit, QListWidget, QTableView, QTextBrowser, QSpinBox, QComboBox,
+QComboBox QAbstractItemView, QMenu::item {
+background-color: rgba(13, 5, 68, 70%);
+}
+
+QComboBox::separator {
+border: solid; border-width: 3px; border-color: #ffcc00;
+}
+
+QPushButton, QListWidget, QTableView, QLineEdit, QHeaderView,
+QTextBrowser, QSpinBox, QToolBox, QComboBox,
+QComboBox QAbstractItemView, IconedGroupBox,
+.QGroupBox, GameCFGWidget, TeamSelWidget, SelWeaponWidget,
+QTabWidget::pane, QTabBar::tab {
+border: solid;
+border-width: 3px;
+border-color: #ffcc00;
+}
+
+QPushButton:hover, QLineEdit:hover, QListWidget:hover,
+QSpinBox:hover, QToolBox:hover, QComboBox:hover {
+border-color: yellow;
+}
+
+QLineEdit, QListWidget,QTableView, QTextBrowser,
+QSpinBox, QToolBox {
+border-radius: 10px;
+}
+
+QLineEdit, QLabel, QHeaderView, QListWidget, QTableView,
+QSpinBox, QToolBox::tab, QComboBox, QComboBox QAbstractItemView,
+IconedGroupBox, .QGroupBox, GameCFGWidget, TeamSelWidget,
+SelWeaponWidget, QCheckBox, QRadioButton, QPushButton {
+font: bold 13px;
+}
+SelWeaponWidget QTabWidget::pane, SelWeaponWidget QTabBar::tab:selected {
+background-position: bottom center;
+background-repeat: repeat-x;
+background-color: #000000;
+}
+.QGroupBox,GameCFGWidget,TeamSelWidget,SelWeaponWidget {
+background-position: bottom center;
+background-repeat: repeat-x;
+border-radius: 16px;
+background-color: rgba(13, 5, 68, 70%);
+padding: 6px;
+}
+/*  Experimenting with PaintOnScreen and border-radius on IconedGroupBox children didn't work out well
+IconedGroupBox QComboBox, IconedGroupBox QPushButton, IconedGroupBox QLineEdit,
+IconedGroupBox QSpinBox {
+border-radius: 0;
+}
+IconedGroupBox, IconedGroupBox *, QTabWidget::pane, QTabBar::tab:selected, QToolBox::tab QWidget{" */
+IconedGroupBox, QTabWidget::pane, QTabBar::tab:selected, QToolBox::tab QWidget{
+background-color: #130f2c;
+}
+
+
+QPushButton {
+border-radius: 8px;
+background-origin: margin;
+background-position: top left;
+background-color: rgba(18, 42, 5, 70%);
+}
+
+QPushButton:pressed{
+border-color: white;
+}
+
+QPushButton:focus {
+outline: none;
+}
+
+
+QHeaderView {
+border-radius: 0;
+border-width: 0;
+border-bottom-width: 3px;
+background-color: #00351d;
+}
+QTableView {
+alternate-background-color: #2f213a;
+gridline-color: transparent;
+}
+
+QTabBar::tab {
+border-bottom-width: 0;
+border-radius: 0;
+border-top-left-radius: 6px;
+border-top-right-radius: 6px;
+padding: 3px;
+}
+QTabBar::tab:!selected {
+color: #0d0544;
+background-color: #ffcc00;
+}
+QSpinBox::up-button{
+background: transparent;
+width: 16px;
+height: 10px;
+}
+
+QSpinBox::up-arrow {
+image: url(":/res/spin_up.png");
+}
+
+QSpinBox::down-arrow {
+image: url(":/res/spin_down.png");
+}
+
+QSpinBox::down-button {
+background: transparent;
+width: 16px;
+height: 10px;
+}
+
+QComboBox {
+border-radius: 10px;
+padding: 3px;
+}
+QComboBox:pressed{
+border-color: white;
+}
+QComboBox::drop-down{
+border: transparent;
+width: 25px;
+}
+QComboBox::down-arrow {
+image: url(":/res/dropdown.png");
+}
+
+VertScrArea {
+background-position: bottom center;
+background-repeat: repeat-x;
+}
+
+IconedGroupBox {
+border-radius: 16px;
+padding: 2px;
+}
+
+QGroupBox::title{
+subcontrol-origin: margin;
+subcontrol-position: top left;
+text-align: left;
+left: 15px;
+top: -4px;
+}
+
+QCheckBox::indicator:checked{
+image: url(":/res/checked.png");
+}
+QCheckBox::indicator:unchecked{
+image: url(":/res/unchecked.png");
+}
+
+.QWidget{
+background: transparent;
+}
+
+QTabWidget::pane {
+border-top-width: 2px;
+}
+
+QMenu{
+background-color: #ffcc00;
+margin: 3px;
+}
+QMenu::item {
+background-color: #0d0544;
+border: 1px solid transparent;
+font: bold;
+padding: 2px 25px 2px 20px;
+}
+QMenu::item:selected {
+background-color: #2d2564;
+}
+QMenu::indicator {
+width: 16px;
+height: 16px;
+}
+QMenu::indicator:non-exclusive:checked{
+image: url(":/res/checked.png");
+}
+QMenu::indicator:non-exclusive:unchecked{
+image: url(":/res/unchecked.png");
+}
+
+QToolTip{
+background-color: #0d0544;
+border: 1px solid #ffcc00;
+}
+
+:disabled{
+color: #a0a0a0;
+}
+SquareLabel, ItemNum {
+background-color: #000000;
+}
+
+QSlider::groove::horizontal {
+height: 2px;
+margin: 2px 0px;
+background-color: #ffcc00;
+}
+
+QSlider::handle::horizontal {
+border: 0px;
+margin: -2px 0px;
+border-radius: 3px;
+background-color: #ffcc00;
+width: 8px;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QTfrontend/res/css/easter.css	Wed Jan 18 01:11:09 2012 +0100
@@ -0,0 +1,248 @@
+/******************************************************************************
+ *
+ * CSS-like definition of Qt frontend appearance
+ *
+ ******************************************************************************
+ *
+ * see http://doc.qt.nokia.com/4.5/stylesheet.html
+ *
+ ******************************************************************************
+ *
+ * This file can be stored at different locations, but it will be read only
+ * once, based on first file found in this order:
+ *
+ *    <userdir>/Data/css/easter.css
+ *    <datadir>/css/easter.css
+ *    <internal default style-sheet> (:/res/css/easter.css)
+ *
+ *****************************************************************************/
+
+HWForm,QDialog {
+background-image: url(":/res/BackgroundEaster.png");
+background-position: bottom center;
+background-repeat: repeat-x;
+background-color: #141250;
+}
+
+* {
+color: #ffcc00;
+selection-background-color: #ffcc00;
+selection-color: #00351d;
+}
+
+a { color:#c8c8ff; }
+
+QLineEdit, QListWidget, QTableView, QTextBrowser, QSpinBox, QComboBox,
+QComboBox QAbstractItemView, QMenu::item {
+background-color: rgba(13, 5, 68, 70%);
+}
+
+QComboBox::separator {
+border: solid; border-width: 3px; border-color: #ffcc00;
+}
+
+QPushButton, QListWidget, QTableView, QLineEdit, QHeaderView,
+QTextBrowser, QSpinBox, QToolBox, QComboBox,
+QComboBox QAbstractItemView, IconedGroupBox,
+.QGroupBox, GameCFGWidget, TeamSelWidget, SelWeaponWidget,
+QTabWidget::pane, QTabBar::tab {
+border: solid;
+border-width: 3px;
+border-color: #ffcc00;
+}
+
+QPushButton:hover, QLineEdit:hover, QListWidget:hover,
+QSpinBox:hover, QToolBox:hover, QComboBox:hover {
+border-color: yellow;
+}
+
+QLineEdit, QListWidget,QTableView, QTextBrowser,
+QSpinBox, QToolBox {
+border-radius: 10px;
+}
+
+QLineEdit, QLabel, QHeaderView, QListWidget, QTableView,
+QSpinBox, QToolBox::tab, QComboBox, QComboBox QAbstractItemView,
+IconedGroupBox, .QGroupBox, GameCFGWidget, TeamSelWidget,
+SelWeaponWidget, QCheckBox, QRadioButton, QPushButton {
+font: bold 13px;
+}
+SelWeaponWidget QTabWidget::pane, SelWeaponWidget QTabBar::tab:selected {
+background-position: bottom center;
+background-repeat: repeat-x;
+background-color: #000000;
+}
+.QGroupBox,GameCFGWidget,TeamSelWidget,SelWeaponWidget {
+background-position: bottom center;
+background-repeat: repeat-x;
+border-radius: 16px;
+background-color: rgba(13, 5, 68, 70%);
+padding: 6px;
+}
+/*  Experimenting with PaintOnScreen and border-radius on IconedGroupBox children didn't work out well
+IconedGroupBox QComboBox, IconedGroupBox QPushButton, IconedGroupBox QLineEdit,
+IconedGroupBox QSpinBox {
+border-radius: 0;
+}
+IconedGroupBox, IconedGroupBox *, QTabWidget::pane, QTabBar::tab:selected, QToolBox::tab QWidget{" */
+IconedGroupBox, QTabWidget::pane, QTabBar::tab:selected, QToolBox::tab QWidget{
+background-color: #130f2c;
+}
+
+
+QPushButton {
+border-radius: 8px;
+background-origin: margin;
+background-position: top left;
+background-color: rgba(18, 42, 5, 70%);
+}
+
+QPushButton:pressed{
+border-color: white;
+}
+
+QPushButton:focus {
+outline: none;
+}
+
+
+QHeaderView {
+border-radius: 0;
+border-width: 0;
+border-bottom-width: 3px;
+background-color: #00351d;
+}
+QTableView {
+alternate-background-color: #2f213a;
+gridline-color: transparent;
+}
+
+QTabBar::tab {
+border-bottom-width: 0;
+border-radius: 0;
+border-top-left-radius: 6px;
+border-top-right-radius: 6px;
+padding: 3px;
+}
+QTabBar::tab:!selected {
+color: #0d0544;
+background-color: #ffcc00;
+}
+QSpinBox::up-button{
+background: transparent;
+width: 16px;
+height: 10px;
+}
+
+QSpinBox::up-arrow {
+image: url(":/res/spin_up.png");
+}
+
+QSpinBox::down-arrow {
+image: url(":/res/spin_down.png");
+}
+
+QSpinBox::down-button {
+background: transparent;
+width: 16px;
+height: 10px;
+}
+
+QComboBox {
+border-radius: 10px;
+padding: 3px;
+}
+QComboBox:pressed{
+border-color: white;
+}
+QComboBox::drop-down{
+border: transparent;
+width: 25px;
+}
+QComboBox::down-arrow {
+image: url(":/res/dropdown.png");
+}
+
+VertScrArea {
+background-position: bottom center;
+background-repeat: repeat-x;
+}
+
+IconedGroupBox {
+border-radius: 16px;
+padding: 2px;
+}
+
+QGroupBox::title{
+subcontrol-origin: margin;
+subcontrol-position: top left;
+text-align: left;
+left: 15px;
+top: -4px;
+}
+
+QCheckBox::indicator:checked{
+image: url(":/res/checked.png");
+}
+QCheckBox::indicator:unchecked{
+image: url(":/res/unchecked.png");
+}
+
+.QWidget{
+background: transparent;
+}
+
+QTabWidget::pane {
+border-top-width: 2px;
+}
+
+QMenu{
+background-color: #ffcc00;
+margin: 3px;
+}
+QMenu::item {
+background-color: #0d0544;
+border: 1px solid transparent;
+font: bold;
+padding: 2px 25px 2px 20px;
+}
+QMenu::item:selected {
+background-color: #2d2564;
+}
+QMenu::indicator {
+width: 16px;
+height: 16px;
+}
+QMenu::indicator:non-exclusive:checked{
+image: url(":/res/checked.png");
+}
+QMenu::indicator:non-exclusive:unchecked{
+image: url(":/res/unchecked.png");
+}
+
+QToolTip{
+background-color: #0d0544;
+border: 1px solid #ffcc00;
+}
+
+:disabled{
+color: #a0a0a0;
+}
+SquareLabel, ItemNum {
+background-color: #000000;
+}
+
+QSlider::groove::horizontal {
+height: 2px;
+margin: 2px 0px;
+background-color: #ffcc00;
+}
+
+QSlider::handle::horizontal {
+border: 0px;
+margin: -2px 0px;
+border-radius: 3px;
+background-color: #ffcc00;
+width: 8px;
+}
+
--- a/QTfrontend/ui/mouseoverfilter.cpp	Mon Jan 16 00:03:13 2012 +0100
+++ b/QTfrontend/ui/mouseoverfilter.cpp	Wed Jan 18 01:11:09 2012 +0100
@@ -1,11 +1,18 @@
-#include "mouseoverfilter.h"
-#include "ui/page/AbstractPage.h"
-#include "ui_hwform.h"
 
 #include <QEvent>
 #include <QWidget>
 #include <QStackedLayout>
 #include <QLabel>
+#include <QLineEdit>
+#include <QCheckBox>
+
+#include "mouseoverfilter.h"
+#include "ui/page/AbstractPage.h"
+#include "ui_hwform.h"
+#include "hwform.h"
+#include "gameuiconfig.h"
+#include "HWDataManager.h"
+#include "SDLInteraction.h"
 
 MouseOverFilter::MouseOverFilter(QObject *parent) :
     QObject(parent)
@@ -25,6 +32,18 @@
         else if (widget->toolTip() != NULL)
             abstractpage->setButtonDescription(widget->toolTip());
 
+        // play a sound when mouse hovers certain ui elements
+        QPushButton * button = dynamic_cast<QPushButton*>(dist);
+        QLineEdit * textfield = dynamic_cast<QLineEdit*>(dist);
+        QCheckBox * checkbox = dynamic_cast<QCheckBox*>(dist);
+        QComboBox * droplist = dynamic_cast<QComboBox*>(dist);
+        QSlider * slider = dynamic_cast<QSlider*>(dist);
+        QTabWidget * tab = dynamic_cast<QTabWidget*>(dist);
+        if (HWForm::config->isFrontendSoundEnabled() && (button || textfield || checkbox || droplist || slider || tab)) {
+            HWDataManager & dataMgr = HWDataManager::instance();
+            SDLInteraction::instance().playSoundFile(dataMgr.findFileForRead("Sounds/steps.ogg"));
+        }
+
         return true;
     }
     else if (event->type() == QEvent::Leave)
--- a/QTfrontend/ui/page/pagemain.cpp	Mon Jan 16 00:03:13 2012 +0100
+++ b/QTfrontend/ui/page/pagemain.cpp	Wed Jan 18 01:11:09 2012 +0100
@@ -58,7 +58,11 @@
     BtnInfo->setWhatsThis(tr("Read about who is behind the Hedgewars Project"));
     pageLayout->setAlignment(BtnInfo, Qt::AlignHCenter);
 
-    BtnDataDownload = addButton(tr("Downloadable Content"), pageLayout, 4, 0, 1, 4, false);
+    BtnFeedback = addButton("Feedback", pageLayout, 4, 0, 1, 4, false);
+    BtnFeedback->setWhatsThis(tr("Leave a feeback here, reporting issues, suggesting features or just saying how you like Hedgewars"));
+    pageLayout->setAlignment(BtnFeedback, Qt::AlignHCenter);
+
+    BtnDataDownload = addButton(tr("Downloadable Content"), pageLayout, 5, 0, 1, 4, false);
     //BtnDataDownload->setToolTip(tr(Downloadable Content"));
     BtnDataDownload->setWhatsThis(tr("Access the user created content downloadable from our website"));
     pageLayout->setAlignment(BtnDataDownload, Qt::AlignHCenter);
@@ -81,9 +85,6 @@
     bottomLayout->setStretch(0,1);
 
     BtnSetup = addButton(":/res/Settings.png", bottomLayout, 1, true);
-    BtnFeedback = addButton("Feedback", bottomLayout, 0);
-    bottomLayout->setStretch(1,0);
-
     return bottomLayout;
 }
 
--- a/QTfrontend/ui/widget/bgwidget.cpp	Mon Jan 16 00:03:13 2012 +0100
+++ b/QTfrontend/ui/widget/bgwidget.cpp	Wed Jan 18 01:11:09 2012 +0100
@@ -18,6 +18,7 @@
  */
 
 #include "bgwidget.h"
+#include "hwconsts.h"
 
 SpritePosition::SpritePosition(QWidget * parent, int sw, int sh)
 {
@@ -85,7 +86,24 @@
 BGWidget::BGWidget(QWidget * parent) : QWidget(parent), enabled(false)
 {
     setAttribute(Qt::WA_NoSystemBackground, true);
-    sprite.load(":/res/Star.png");
+
+    QString fname;
+
+    //For each season, there is a replacement for the star (Star.png)
+    //Todo: change element for easter and birthday
+    //Simply replace Confetti.png and Egg.png with an appropriate graphic)
+    switch (season)
+    {
+    case SEASON_CHRISTMAS : fname = "Flake.png";
+			    break;
+    case SEASON_EASTER : fname = "Egg.png";
+			 break;
+    case SEASON_HWBDAY : fname = "Confetti.png";
+			 break;
+    default : fname = "Star.png";
+    }
+
+    sprite.load(":/res/" + fname);
 
     setAutoFillBackground(false);
 
--- a/QTfrontend/ui/widget/qpushbuttonwithsound.cpp	Mon Jan 16 00:03:13 2012 +0100
+++ b/QTfrontend/ui/widget/qpushbuttonwithsound.cpp	Wed Jan 18 01:11:09 2012 +0100
@@ -1,11 +1,11 @@
-#include "qpushbuttonwithsound.h"
 #include <QMessageBox>
-#include <HWDataManager.h>
 #include <QDir>
-#include <SDLInteraction.h>
-#include <hwform.h>
-#include <QSettings>
-#include <gameuiconfig.h>
+
+#include "qpushbuttonwithsound.h"
+#include "HWDataManager.h"
+#include "SDLInteraction.h"
+#include "hwform.h"
+#include "gameuiconfig.h"
 
 QPushButtonWithSound::QPushButtonWithSound(QWidget *parent) :
     QPushButton(parent),
@@ -21,14 +21,6 @@
 
     HWDataManager & dataMgr = HWDataManager::instance();
 
-    QString soundsDir = QString("Sounds/");
-
-    QStringList list = dataMgr.entryList(
-            soundsDir,
-            QDir::Files,
-            QStringList() <<
-                "shotgunreload.ogg"
-            );
-    if(!list.empty())
-        SDLInteraction::instance().playSoundFile(dataMgr.findFileForRead(soundsDir + "/" + list[0]));
+    if (this->isEnabled())
+        SDLInteraction::instance().playSoundFile(dataMgr.findFileForRead("Sounds/roperelease.ogg"));
 }
--- a/QTfrontend/util/SDLInteraction.cpp	Mon Jan 16 00:03:13 2012 +0100
+++ b/QTfrontend/util/SDLInteraction.cpp	Wed Jan 18 01:11:09 2012 +0100
@@ -193,10 +193,11 @@
     if (!m_soundMap->contains(soundFile))
         m_soundMap->insert(soundFile, Mix_LoadWAV(soundFile.toLocal8Bit().constData()));
 
-    Mix_PlayChannel(-1, m_soundMap->value(soundFile), 0);
+    //FIXME: this is a hack, but works as long as we have few concurrent playing sounds
+    if (Mix_Playing(lastchannel) == false)
+        lastchannel = Mix_PlayChannel(-1, m_soundMap->value(soundFile), 0);
 }
 
-
 void SDLInteraction::setMusicTrack(const QString & musicFile)
 {
     bool wasPlayingMusic = m_isPlayingMusic;
--- a/QTfrontend/util/SDLInteraction.h	Mon Jan 16 00:03:13 2012 +0100
+++ b/QTfrontend/util/SDLInteraction.h	Wed Jan 18 01:11:09 2012 +0100
@@ -59,6 +59,8 @@
 
     QMap<QString,Mix_Chunk*> * m_soundMap; ///< maps sound file paths to channels
 
+    int lastchannel; ///< channel of the last music played
+
 public:
     /**
      * @brief Returns reference to the <i>singleton</i> instance of this class.
--- a/hedgewars/ArgParsers.inc	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/ArgParsers.inc	Wed Jan 18 01:11:09 2012 +0100
@@ -56,8 +56,10 @@
         cGrayScale:= true;
         cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp-9)))
         end
-    else if tmp <= 9 then cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp)))
-    else cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp-6)));
+    else if tmp <= 9 then 
+        cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp)))
+    else 
+        cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp-6)));
     cLocaleFName:= ParamStr(17);
 end;
 
--- a/hedgewars/GSHandlers.inc	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/GSHandlers.inc	Wed Jan 18 01:11:09 2012 +0100
@@ -53,6 +53,7 @@
         sX:= dX / steps;
         sY:= dY / steps;
         end
+        
     else
         begin
         sX:= dX;
@@ -88,64 +89,74 @@
                 begin
                 if (CurrentHedgehog^.Gear = gi) then
                     PlaySound(sndOops, gi^.Hedgehog^.Team^.voicepack)
+                    
                 else
                     begin
                     if (gi^.State and gstMoving) = 0 then
                         gi^.State := gi^.State or gstLoser;
+                        
                     if d > r div 2 then
-                        PlaySound(sndNooo, gi^.Hedgehog^.Team^.voicepack)
+                        PlaySound(sndNooo, gi^.Hedgehog^.Team^.voicepack) 
                     else
                         PlaySound(sndUhOh, gi^.Hedgehog^.Team^.voicepack);
                     end;
                 end;
             end;
+            
         gi := gi^.NextGear
         end;
 end;
 
 procedure HideHog(HH: PHedgehog);
 begin
-ScriptCall('onHogHide', HH^.Gear^.Uid);
-DeleteCI(HH^.Gear);
-if FollowGear = HH^.Gear then FollowGear:= nil;
-if lastGearByUID = HH^.Gear then lastGearByUID := nil;
-RemoveGearFromList(HH^.Gear);
-with HH^.Gear^ do
-    begin
-    Z := cHHZ;
-    Active := false;
-    State:= State and (not (gstHHDriven or gstAttacking or gstAttacked));
-    Message := Message and (not gmAttack);
+    ScriptCall('onHogHide', HH^.Gear^.Uid);
+    DeleteCI(HH^.Gear);
+    if FollowGear = HH^.Gear then
+        FollowGear:= nil;
+        
+    if lastGearByUID = HH^.Gear then
+        lastGearByUID := nil;
+        
+    RemoveGearFromList(HH^.Gear);
+    with HH^.Gear^ do
+        begin
+        Z := cHHZ;
+        Active := false;
+        State:= State and (not (gstHHDriven or gstAttacking or gstAttacked));
+        Message := Message and (not gmAttack);
     end;
-HH^.GearHidden:= HH^.Gear;
-HH^.Gear:= nil
+    HH^.GearHidden:= HH^.Gear;
+    HH^.Gear:= nil
 end;
 
 procedure RestoreHog(HH: PHedgehog);
 begin
-HH^.Gear:=HH^.GearHidden;
-HH^.GearHidden:= nil;
-InsertGearToList(HH^.Gear);
-HH^.Gear^.State:= (HH^.Gear^.State and (not (gstHHDriven or gstInvisible or gstAttacking))) or gstAttacked;
-AddGearCI(HH^.Gear);
-HH^.Gear^.Active:= true;
-ScriptCall('onHogRestore', HH^.Gear^.Uid)
+    HH^.Gear:=HH^.GearHidden;
+    HH^.GearHidden:= nil;
+    InsertGearToList(HH^.Gear);
+    HH^.Gear^.State:= (HH^.Gear^.State and (not (gstHHDriven or gstInvisible or gstAttacking))) or gstAttacked;
+    AddGearCI(HH^.Gear);
+    HH^.Gear^.Active:= true;
+    ScriptCall('onHogRestore', HH^.Gear^.Uid)
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
 procedure CheckCollision(Gear: PGear); inline;
 begin
-    if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) or (TestCollisionYwithGear(Gear, hwSign(Gear^.dY)) <> 0) then
+    if TestCollisionXwithGear(Gear, hwSign(Gear^.dX))
+    or (TestCollisionYwithGear(Gear, hwSign(Gear^.dY)) <> 0) then
         Gear^.State := Gear^.State or gstCollision
-    else Gear^.State := Gear^.State and (not gstCollision)
+    else
+        Gear^.State := Gear^.State and (not gstCollision)
 end;
 
 procedure CheckCollisionWithLand(Gear: PGear); inline;
 begin
-    if TestCollisionX(Gear, hwSign(Gear^.dX)) or TestCollisionY(Gear, hwSign(Gear^.dY)
-       )
-        then Gear^.State := Gear^.State or      gstCollision
-    else Gear^.State := Gear^.State and (not gstCollision)
+    if TestCollisionX(Gear, hwSign(Gear^.dX))
+    or TestCollisionY(Gear, hwSign(Gear^.dY)) then
+        Gear^.State := Gear^.State or gstCollision
+    else 
+        Gear^.State := Gear^.State and (not gstCollision)
 end;
 
 
@@ -154,19 +165,22 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 procedure doStepDrowningGear(Gear: PGear);
-begin
+    begin
     AllInactive := false;
     Gear^.Y := Gear^.Y + cDrownSpeed;
     Gear^.X := Gear^.X + Gear^.dX * cDrownSpeed;
     // Create some bubbles (0.5% might be better but causes too few bubbles sometimes)
-    if ((not SuddenDeathDmg and (cWaterOpacity < $FF)) or (SuddenDeathDmg and (cSDWaterOpacity < $FF))) and ((GameTicks and $1F) = 0) then
+    if ((not SuddenDeathDmg and (cWaterOpacity < $FF))
+    or (SuddenDeathDmg and (cSDWaterOpacity < $FF))) and ((GameTicks and $1F) = 0) then
         if (Gear^.Kind = gtHedgehog) and (Random(4) = 0) then
             AddVisualGear(hwRound(Gear^.X) - Gear^.Radius, hwRound(Gear^.Y) - Gear^.Radius, vgtBubble)
     else if Random(12) = 0 then
              AddVisualGear(hwRound(Gear^.X) - Gear^.Radius, hwRound(Gear^.Y) - Gear^.Radius, vgtBubble);
-    if (not SuddenDeathDmg and (cWaterOpacity > $FE)) or (SuddenDeathDmg and (cSDWaterOpacity > $FE)) or (hwRound(Gear^.Y) > Gear^.Radius + cWaterLine + cVisibleWater) then
+    if (not SuddenDeathDmg and (cWaterOpacity > $FE))
+    or (SuddenDeathDmg and (cSDWaterOpacity > $FE))
+    or (hwRound(Gear^.Y) > Gear^.Radius + cWaterLine + cVisibleWater) then
         DeleteGear(Gear);
-end;
+    end;
 
 ////////////////////////////////////////////////////////////////////////////////
 procedure doStepFallingGear(Gear: PGear);
@@ -178,8 +192,10 @@
     land: word;
 begin
     // clip velocity at 1.9 - over 1 per pixel, but really shouldn't cause many actual problems.
-    if Gear^.dX.QWordValue > 8160437862 then Gear^.dX.QWordValue:= 8160437862;
-    if Gear^.dY.QWordValue > 8160437862 then Gear^.dY.QWordValue:= 8160437862;
+    if Gear^.dX.QWordValue > 8160437862 then
+        Gear^.dX.QWordValue:= 8160437862;
+    if Gear^.dY.QWordValue > 8160437862 then
+        Gear^.dY.QWordValue:= 8160437862;
     Gear^.State := Gear^.State and (not gstCollision);
     collV := 0;
     collH := 0;
@@ -188,7 +204,9 @@
 
 
 // might need some testing/adjustments - just to avoid projectiles to fly forever (accelerated by wind/skips)
-    if (hwRound(Gear^.X) < LAND_WIDTH div -2) or (hwRound(Gear^.X) > LAND_WIDTH * 3 div 2) then Gear^.State := Gear^.State or gstCollision;
+    if (hwRound(Gear^.X) < LAND_WIDTH div -2)
+    or (hwRound(Gear^.X) > LAND_WIDTH * 3 div 2) then
+        Gear^.State := Gear^.State or gstCollision;
 
     if Gear^.dY.isNegative then
         begin
@@ -197,13 +215,16 @@
         if land <> 0 then
             begin
             collV := -1;
-            if land and lfIce <> 0 then Gear^.dX := Gear^.dX * (_0_9 + Gear^.Friction * _0_1)
-            else Gear^.dX := Gear^.dX * Gear^.Friction;
+            if land and lfIce <> 0 then
+                Gear^.dX := Gear^.dX * (_0_9 + Gear^.Friction * _0_1)
+            else
+                Gear^.dX := Gear^.dX * Gear^.Friction;
 
             Gear^.dY := - Gear^.dY * Gear^.Elasticity;
             Gear^.State := Gear^.State or gstCollision
             end
-        else if (Gear^.AdvBounce=1) and (TestCollisionYwithGear(Gear, 1) <> 0) then collV := 1;
+        else if (Gear^.AdvBounce=1) and (TestCollisionYwithGear(Gear, 1) <> 0) then
+            collV := 1;
         end
     else 
         begin // Gear^.dY.isNegative is false
@@ -239,8 +260,8 @@
     else if (Gear^.AdvBounce=1) and TestCollisionXwithGear(Gear, -hwSign(Gear^.dX)) then
         collH := -hwSign(Gear^.dX); 
     //if Gear^.AdvBounce and (collV <>0) and (collH <> 0) and (hwSqr(tdX) + hwSqr(tdY) > _0_08) then
-    if (Gear^.AdvBounce=1) and (collV <>0) and (collH <> 0) and ((collV=-1) or ((tdX.QWordValue +
-       tdY.QWordValue) > _0_2.QWordValue)) then
+    if (Gear^.AdvBounce=1) and (collV <>0) and (collH <> 0) and ((collV=-1)
+    or ((tdX.QWordValue + tdY.QWordValue) > _0_2.QWordValue)) then
         begin
         Gear^.dX := tdY*Gear^.Elasticity*Gear^.Friction;
         Gear^.dY := tdX*Gear^.Elasticity;
@@ -250,13 +271,15 @@
         Gear^.AdvBounce := 10;
         end;
 
-    if Gear^.AdvBounce > 1 then dec(Gear^.AdvBounce);
+    if Gear^.AdvBounce > 1 then
+        dec(Gear^.AdvBounce);
 
     if isFalling then
         begin
         Gear^.dY := Gear^.dY + cGravity;
-        if (GameFlags and gfMoreWind) <> 0 then Gear^.dX := Gear^.dX + cWindSpeed / Gear^.Density
-        end;
+        if (GameFlags and gfMoreWind) <> 0 then
+            Gear^.dX := Gear^.dX + cWindSpeed / Gear^.Density
+            end;
 
     Gear^.X := Gear^.X + Gear^.dX;
     Gear^.Y := Gear^.Y + Gear^.dY;
@@ -266,14 +289,12 @@
     if (not isFalling) and ((Gear^.dX.QWordValue + Gear^.dY.QWordValue) < _0_02.QWordValue) then
         Gear^.State := Gear^.State and (not gstMoving)
     else
-        Gear^.State := Gear^.State or      gstMoving;
-
-    if (Gear^.nImpactSounds > 0) and 
-       (((Gear^.Kind <> gtMine) and (Gear^.Damage <> 0)) or 
-          ((Gear^.State and (gstCollision or gstMoving)) = (gstCollision or gstMoving))) and
-       (((Gear^.Radius < 3) and (Gear^.dY < -_0_1)) or
-        ((Gear^.Radius >= 3) and ((Gear^.dX.QWordValue > _0_1.QWordValue) or 
-          (Gear^.dY.QWordValue > _0_1.QWordValue)))) then
+        Gear^.State := Gear^.State or gstMoving;
+
+    if (Gear^.nImpactSounds > 0) and (((Gear^.Kind <> gtMine) and (Gear^.Damage <> 0))
+    or ((Gear^.State and (gstCollision or gstMoving)) = (gstCollision or gstMoving))) and(((Gear^.Radius < 3) and (Gear^.dY < -_0_1))
+    or ((Gear^.Radius >= 3) and ((Gear^.dX.QWordValue > _0_1.QWordValue)
+    or (Gear^.dY.QWordValue > _0_1.QWordValue)))) then
         PlaySound(TSound(ord(Gear^.ImpactSound) + LongInt(GetRandom(Gear^.nImpactSounds))), true);
 end;
 
@@ -299,35 +320,35 @@
         end;
 
     if (Gear^.Kind = gtBall) and ((Gear^.State and gstTmpFlag) <> 0) then
-    begin
+        begin
         CheckCollision(Gear);
         if (Gear^.State and gstCollision) <> 0 then
             doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 20, Gear^.Hedgehog, EXPLDontDraw or EXPLNoGfx);
     end;
 
     if (Gear^.Kind = gtGasBomb) and ((GameTicks mod 200) = 0) then
-    begin
+        begin
         vg:= AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtSmokeWhite);
         if vg <> nil then
             vg^.Tint:= $FFC0C000;
     end;
 
     if Gear^.Timer = 0 then
-    begin
+        begin
         case Gear^.Kind of 
             gtGrenade: doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 50, Gear^.Hedgehog, EXPLAutoSound);
             gtBall: doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 40, Gear^.Hedgehog, EXPLAutoSound);
             gtClusterBomb: 
                 begin
-                    x := hwRound(Gear^.X);
-                    y := hwRound(Gear^.Y);
-                    doMakeExplosion(x, y, 20, Gear^.Hedgehog, EXPLAutoSound);
-                    for i:= 0 to 4 do
-                        begin
-                        dX := rndSign(GetRandom * _0_1) + Gear^.dX / 5;
-                        dY := (GetRandom - _3) * _0_08;
-                        FollowGear := AddGear(x, y, gtCluster, 0, dX, dY, 25)
-                        end
+                x := hwRound(Gear^.X);
+                y := hwRound(Gear^.Y);
+                doMakeExplosion(x, y, 20, Gear^.Hedgehog, EXPLAutoSound);
+                for i:= 0 to 4 do
+                    begin
+                    dX := rndSign(GetRandom * _0_1) + Gear^.dX / 5;
+                    dY := (GetRandom - _3) * _0_08;
+                    FollowGear := AddGear(x, y, gtCluster, 0, dX, dY, 25)
+                    end
                 end;
             gtWatermelon: 
                 begin
@@ -382,18 +403,18 @@
     CalcRotationDirAngle(Gear);
 
     if Gear^.Kind = gtHellishBomb then
-    begin
+        begin
 
         if Gear^.Timer = 3000 then
-        begin
+            begin
             Gear^.nImpactSounds := 0;
             PlaySound(sndHellish);
-        end;
+            end;
 
         if (GameTicks and $3F) = 0 then
             if (Gear^.State and gstCollision) = 0 then
                 AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtEvilTrace);
-    end;
+        end;
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -414,13 +435,18 @@
     if (GameTicks mod s) = 0 then
         begin
         // adjust angle to match the texture
-        if Gear^.dX.isNegative then i:= 130 else i:= 50;
+        if Gear^.dX.isNegative then
+            i:= 130
+        else
+            i:= 50;
+            
         smoke:= AddVisualGear(hwRound(Gear^.X)-round(cos((Gear^.DirAngle+i) * pi / 180)*20), hwRound(Gear^.Y)-round(sin((Gear^.DirAngle+i) * pi / 180)*20), vgtSmoke);
-        if smoke <> nil then smoke^.Scale:= 0.75;
+        if smoke <> nil then
+            smoke^.Scale:= 0.75;
         end;
 
     if (Gear^.State and gstCollision) <> 0 then
-    begin
+        begin
         PlaySound(sndMolotov);
         gX := hwRound(Gear^.X);
         gY := hwRound(Gear^.Y);
@@ -443,7 +469,8 @@
                     Angle:= random * 360;
                     dx:= 0.0000001;
                     dy:= 0;
-                    if random(2) = 0 then dx := -dx;
+                    if random(2) = 0 then
+                        dx := -dx;
                     FrameTicks:= 750;
                     State:= ord(sprEgg)
                     end;
@@ -459,7 +486,7 @@
             end;
         DeleteGear(Gear);
         exit
-    end;
+        end;
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -469,13 +496,14 @@
     AllInactive := false;
     doStepFallingGear(Gear);
     if (Gear^.State and gstCollision) <> 0 then
-    begin
+        begin
         doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), Gear^.Timer, Gear^.Hedgehog, EXPLAutoSound);
         DeleteGear(Gear);
         exit
     end;
 
-    if (Gear^.Kind = gtMelonPiece) or (Gear^.Kind = gtBall) then
+    if (Gear^.Kind = gtMelonPiece)
+    or (Gear^.Kind = gtBall) then
         CalcRotationDirAngle(Gear)
     else if (GameTicks and $1F) = 0 then
         AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtSmokeTrace)
@@ -485,7 +513,8 @@
 procedure doStepShell(Gear: PGear);
 begin
     AllInactive := false;
-    if (GameFlags and gfMoreWind) = 0 then Gear^.dX := Gear^.dX + cWindSpeed;
+    if (GameFlags and gfMoreWind) = 0 then
+        Gear^.dX := Gear^.dX + cWindSpeed;
     doStepFallingGear(Gear);
     if (Gear^.State and gstCollision) <> 0 then
         begin
@@ -503,7 +532,8 @@
     particle: PVisualGear;
 begin
     AllInactive := false;
-    if (GameFlags and gfMoreWind) = 0 then Gear^.dX := Gear^.dX + cWindSpeed;
+    if (GameFlags and gfMoreWind) = 0 then
+        Gear^.dX := Gear^.dX + cWindSpeed;
     doStepFallingGear(Gear);
     CalcRotationDirAngle(Gear);
     if (Gear^.State and gstCollision) <> 0 then
@@ -515,7 +545,8 @@
         for i:= 15 + kick div 10 downto 0 do
             begin
             particle := AddVisualGear(hwRound(Gear^.X) + Random(25), hwRound(Gear^.Y) + Random(25), vgtDust);
-            if particle <> nil then particle^.dX := particle^.dX + (Gear^.dX.QWordValue / 21474836480)
+            if particle <> nil then
+                particle^.dX := particle^.dX + (Gear^.dX.QWordValue / 21474836480)
             end;
         DeleteGear(Gear);
         exit
@@ -523,7 +554,8 @@
     if ((GameTicks and $1F) = 0) and (Random(3) = 0) then
         begin
         particle:= AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtDust);
-        if particle <> nil then particle^.dX := particle^.dX + (Gear^.dX.QWordValue / 21474836480)
+        if particle <> nil then
+            particle^.dX := particle^.dX + (Gear^.dX.QWordValue / 21474836480)
         end
 end;
 
@@ -544,7 +576,8 @@
     Gear^.State:= Gear^.State and (not gstInvisible);
     doStepFallingGear(Gear);
     CheckCollision(Gear);
-    if ((Gear^.State and gstCollision) <> 0) or ((Gear^.State and gstMoving) = 0) then draw:= true;
+    if ((Gear^.State and gstCollision) <> 0) or ((Gear^.State and gstMoving) = 0) then
+        draw:= true;
     xx:= hwRound(Gear^.X);
     yy:= hwRound(Gear^.Y);
     end
@@ -560,8 +593,10 @@
         if vobVelocity <> 0 then
             begin
             DirAngle := DirAngle + (Angle / 1250000000);
-            if DirAngle < 0 then DirAngle := DirAngle + 360
-            else if 360 < DirAngle then DirAngle := DirAngle - 360;
+            if DirAngle < 0 then
+                DirAngle := DirAngle + 360
+            else if 360 < DirAngle then
+                DirAngle := DirAngle - 360;
             end;
 
         inc(Health, 8);
@@ -569,11 +604,15 @@
             begin
             dec(Health, vobFrameTicks);
             inc(Timer);
-            if Timer = vobFramesCount then Timer:= 0
+            if Timer = vobFramesCount then
+                Timer:= 0
             end;
     // move back to cloud layer
-        if yy > cWaterLine then move:= true
-        else if ((yy and LAND_HEIGHT_MASK) <> 0) or (xx > LAND_WIDTH + 512) or (xx < -512) then move:=true
+        if yy > cWaterLine then
+            move:= true
+        else if ((yy and LAND_HEIGHT_MASK) <> 0)
+        or (xx > LAND_WIDTH + 512) or (xx < -512) then
+            move:=true
         // Solid pixel encountered
         else if ((xx and LAND_WIDTH_MASK) = 0) and (Land[yy, xx] <> 0) then
             begin
@@ -616,7 +655,8 @@
         begin
         // we've collided with land. draw some stuff and get back into the clouds
         move:= true;
-        if (Pos > 20) and ((CurAmmoGear = nil) or (CurAmmoGear^.Kind <> gtRope)) then
+        if (Pos > 20) and ((CurAmmoGear = nil)
+        or (CurAmmoGear^.Kind <> gtRope)) then
             begin
 ////////////////////////////////// TODO - ASK UNC0RR FOR A GOOD HOME FOR THIS ////////////////////////////////////
             if not gun then
@@ -644,7 +684,8 @@
                             if gun then
                                 begin
                                 LandDirty[yy div 32, xx div 32]:= 1;
-                                if LandPixels[ry, rx] = 0 then Land[ly, lx]:=  lfDamaged or lfObject
+                                if LandPixels[ry, rx] = 0 then
+                                    Land[ly, lx]:=  lfDamaged or lfObject
                                 else Land[ly, lx]:=  lfDamaged or lfBasic
                                 end
                             else Land[ly, lx]:= lf;
@@ -660,7 +701,8 @@
             // Why is this here.  For one thing, there's no test on +1 being safe. 
             //Land[py, px+1]:= lfBasic;
             
-            if allpx then UpdateLandTexture(xx, Pred(s^.h), yy, Pred(s^.w))
+            if allpx then
+                UpdateLandTexture(xx, Pred(s^.h), yy, Pred(s^.w))
             else
                 begin
                 UpdateLandTexture(
@@ -693,7 +735,8 @@
 begin
     AllInactive := false;
     if Gear^.dY.isNegative then
-        if TestCollisionY(Gear, -1) then Gear^.dY := _0;
+        if TestCollisionY(Gear, -1) then
+            Gear^.dY := _0;
 
     if not Gear^.dY.isNegative then
         if TestCollisionY(Gear, 1) then
@@ -704,7 +747,8 @@
                 Gear^.Active := false;
                 exit
             end
-            else if Gear^.dY < - _0_03 then PlaySound(Gear^.ImpactSound)
+            else if Gear^.dY < - _0_03 then
+                PlaySound(Gear^.ImpactSound)
         end;
 
     Gear^.Y := Gear^.Y + Gear^.dY;
@@ -729,7 +773,7 @@
 
     // if water entered or left
     if nuw <> uw then
-    begin
+        begin
         AddVisualGear(gX, cWaterLine, vgtSplash);
         AddVisualGear(gX - 3 + Random(6), cWaterLine, vgtDroplet);
         AddVisualGear(gX - 3 + Random(6), cWaterLine, vgtDroplet);
@@ -737,24 +781,24 @@
         AddVisualGear(gX - 3 + Random(6), cWaterLine, vgtDroplet);
         StopSound(Gear^.SoundChannel);
         if nuw then
-        begin
+            begin
             Gear^.SoundChannel := LoopSound(sndBeeWater);
             Gear^.Tag := 1;
         end
         else
-        begin
+            begin
             Gear^.SoundChannel := LoopSound(sndBee);
             Gear^.Tag := 0;
+            end;
         end;
-    end;
 
 
     if Gear^.Timer = 0 then
         Gear^.RenderTimer:= false
     else
-    begin
+        begin
         if (GameTicks and $F) = 0 then
-        begin
+            begin
             if (GameTicks and $30) = 0 then
                 AddVisualGear(gX, gY, vgtBeeTrace);
             Gear^.dX := Gear^.Elasticity * (Gear^.dX + _0_000064 * (Gear^.Target.X - gX));
@@ -763,17 +807,17 @@
             t := Gear^.Friction / Distance(Gear^.dX, Gear^.dY);
             Gear^.dX := Gear^.dX * t;
             Gear^.dY := Gear^.dY * t;
-        end;
+            end;
 
         Gear^.X := Gear^.X + Gear^.dX;
         Gear^.Y := Gear^.Y + Gear^.dY;
 
-    end;
+        end;
 
 
     CheckCollision(Gear);
     if ((Gear^.State and gstCollision) <> 0) then
-    begin
+        begin
         StopSound(Gear^.SoundChannel);
         doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 50, Gear^.Hedgehog, EXPLAutoSound);
         for i:= 0 to 31 do
@@ -785,8 +829,10 @@
                     Scale:= 0.75;
                     dx:= 0.001 * (random(200));
                     dy:= 0.001 * (random(200));
-                    if random(2) = 0 then dx := -dx;
-                    if random(2) = 0 then dy := -dy;
+                    if random(2) = 0 then
+                        dx := -dx;
+                    if random(2) = 0 then
+                        dy := -dy;
                     FrameTicks:= random(250) + 250;
                     State:= ord(sprTargetBee);
                     end;
@@ -797,15 +843,15 @@
     if (Gear^.Timer > 0) then
         dec(Gear^.Timer)
     else
-    begin
+        begin
         if nuw then
-        begin
+           begin
             StopSound(Gear^.SoundChannel);
             CheckGearDrowning(Gear);
-        end
+            end
         else
             doStepFallingGear(Gear);
-    end;
+        end;
 end;
 
 procedure doStepBee(Gear: PGear);
@@ -816,14 +862,14 @@
     Gear^.dY := Gear^.dY + cGravity;
     CheckCollision(Gear);
     if (Gear^.State and gstCollision) <> 0 then
-    begin
+        begin
         doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 50, Gear^.Hedgehog, EXPLAutoSound);
         DeleteGear(Gear);
         exit
     end;
     dec(Gear^.Timer);
     if Gear^.Timer = 0 then
-    begin
+        begin
         Gear^.Hedgehog^.Gear^.Message:= Gear^.Hedgehog^.Gear^.Message and (not gmAttack);
         Gear^.Hedgehog^.Gear^.State:= Gear^.Hedgehog^.Gear^.State and (not gstAttacking);
         AttackBar:= 0;
@@ -833,7 +879,7 @@
         // save initial speed in otherwise unused Friction variable
         Gear^.Friction := Distance(Gear^.dX, Gear^.dY);
         Gear^.doStep := @doStepBeeWork
-    end;
+        end;
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -842,10 +888,10 @@
     AllInactive := false;
     inc(Gear^.Timer);
     if Gear^.Timer > 75 then
-    begin
+        begin
         DeleteGear(Gear);
         AfterAttack
-    end
+        end
 end;
 
 procedure doStepShotgunShot(Gear: PGear);
@@ -856,48 +902,48 @@
     AllInactive := false;
 
     if ((Gear^.State and gstAnimation) = 0) then
-    begin
+        begin
         dec(Gear^.Timer);
         if Gear^.Timer = 0 then
-        begin
+            begin
             PlaySound(sndShotgunFire);
             shell := AddVisualGear(hwRound(Gear^.x), hwRound(Gear^.y), vgtShell);
             if shell <> nil then
-            begin
+                begin
                 shell^.dX := gear^.dX.QWordValue / -17179869184;
                 shell^.dY := gear^.dY.QWordValue / -17179869184;
                 shell^.Frame := 0
-            end;
+                end;
             Gear^.State := Gear^.State or gstAnimation
-        end;
-        exit
-    end
-    else inc(Gear^.Timer);
-
-    i := 200;
+            end;
+            exit
+        end
+    else
+        inc(Gear^.Timer);
+
+        i := 200;
     repeat
         Gear^.X := Gear^.X + Gear^.dX;
         Gear^.Y := Gear^.Y + Gear^.dY;
         CheckCollision(Gear);
         if (Gear^.State and gstCollision) <> 0 then
-        begin
+            begin
             Gear^.X := Gear^.X + Gear^.dX * 8;
             Gear^.Y := Gear^.Y + Gear^.dY * 8;
             ShotgunShot(Gear);
             Gear^.doStep := @doStepShotIdle;
             exit
-        end;
+            end;
 
         CheckGearDrowning(Gear);
         if (Gear^.State and gstDrowning) <> 0 then
-        begin
+            begin
             Gear^.doStep := @doStepShotIdle;
             exit
-        end;
+            end;
         dec(i)
     until i = 0;
-    if (hwRound(Gear^.X) and LAND_WIDTH_MASK <> 0) or (hwRound(Gear^.Y) and LAND_HEIGHT_MASK <> 0)
-        then
+    if (hwRound(Gear^.X) and LAND_WIDTH_MASK <> 0) or (hwRound(Gear^.Y) and LAND_HEIGHT_MASK <> 0) then
         Gear^.doStep := @doStepShotIdle
 end;
 
@@ -919,6 +965,7 @@
 
         // Bullet trail
         VGear := AddVisualGear(hwRound(ox), hwRound(oy), vgtLineTrail);
+        
         if VGear <> nil then
             begin
             VGear^.X:= hwFloat2Float(ox);
@@ -928,7 +975,7 @@
 
             // reached edge of land. assume infinite beam. Extend it way out past camera
             if (hwRound(Bullet^.X) and LAND_WIDTH_MASK <> 0)
-                or (hwRound(Bullet^.Y) and LAND_HEIGHT_MASK <> 0) then
+            or (hwRound(Bullet^.Y) and LAND_HEIGHT_MASK <> 0) then
                     // only extend if not under water
                     if hwRound(Bullet^.Y) < cWaterLine then
                         begin
@@ -956,18 +1003,19 @@
         Gear^.Y := Gear^.Y + Gear^.dY;
         x := hwRound(Gear^.X);
         y := hwRound(Gear^.Y);
-        if ((y and LAND_HEIGHT_MASK) = 0) and ((x and LAND_WIDTH_MASK) = 0)
-           and (Land[y, x] <> 0) then inc(Gear^.Damage);
+        
+        if ((y and LAND_HEIGHT_MASK) = 0) and ((x and LAND_WIDTH_MASK) = 0) and (Land[y, x] <> 0) then
+            inc(Gear^.Damage);
         // let's interrupt before a collision to give portals a chance to catch the bullet
         if (Gear^.Damage = 1) and (Gear^.Tag = 0) and (Land[y, x] > 255) then
-        begin
+            begin
             Gear^.Tag := 1;
             Gear^.Damage := 0;
             Gear^.X := Gear^.X - Gear^.dX;
             Gear^.Y := Gear^.Y - Gear^.dY;
             CheckGearDrowning(Gear);
             break;
-        end
+            end
         else
             Gear^.Tag := 0;
 
@@ -977,48 +1025,46 @@
         else
             AmmoShove(Gear, Gear^.Timer, 20);
         CheckGearDrowning(Gear);
-        dec(i)
-    until (i = 0) or (Gear^.Damage > Gear^.Health) or ((Gear^.State and gstDrowning) <> 0);
+        dec(i) until (i = 0) or (Gear^.Damage > Gear^.Health) or ((Gear^.State and gstDrowning) <> 0);
     if Gear^.Damage > 0 then
-    begin
+        begin
         DrawTunnel(oX, oY, Gear^.dX, Gear^.dY, 82 - i, 1);
         dec(Gear^.Health, Gear^.Damage);
         Gear^.Damage := 0
-    end;
+        end;
     if ((Gear^.State and gstDrowning) <> 0) and (Gear^.Damage < Gear^.Health) and ((not SuddenDeathDmg and (cWaterOpacity < $FF)) or (SuddenDeathDmg and (cSDWaterOpacity < $FF))) then
-    begin
+        begin
         for i:=(Gear^.Health - Gear^.Damage) * 4 downto 0 do
-        begin
+            begin
             if Random(6) = 0 then
                 AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtBubble);
             Gear^.X := Gear^.X + Gear^.dX;
             Gear^.Y := Gear^.Y + Gear^.dY;
+            end;
         end;
-    end;
 
     if (Gear^.Health <= 0)
-       or (hwRound(Gear^.X) and LAND_WIDTH_MASK <> 0)
-       or (hwRound(Gear^.Y) and LAND_HEIGHT_MASK <> 0) then
-    begin
-        if (Gear^.Kind = gtSniperRifleShot) and ((GameFlags and gfLaserSight) = 0) then
-            cLaserSighting := false;
-        if (Ammoz[Gear^.AmmoType].Ammo.NumPerTurn <= CurrentHedgehog^.MultiShootAttacks) and
-           ((GameFlags and gfArtillery) = 0) then cArtillery := false;
+        or (hwRound(Gear^.X) and LAND_WIDTH_MASK <> 0)
+        or (hwRound(Gear^.Y) and LAND_HEIGHT_MASK <> 0) then
+            begin
+            if (Gear^.Kind = gtSniperRifleShot) and ((GameFlags and gfLaserSight) = 0) then
+                cLaserSighting := false;
+            if (Ammoz[Gear^.AmmoType].Ammo.NumPerTurn <= CurrentHedgehog^.MultiShootAttacks) and ((GameFlags and gfArtillery) = 0) then
+                cArtillery := false;
         
         // Bullet Hit
-        if (hwRound(Gear^.X) and LAND_WIDTH_MASK = 0) 
-            and (hwRound(Gear^.Y) and LAND_HEIGHT_MASK = 0) then
-        begin
-            VGear := AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtBulletHit);
-            if VGear <> nil then
-            begin
-                VGear^.Angle := DxDy2Angle(-Gear^.dX, Gear^.dY);
+            if (hwRound(Gear^.X) and LAND_WIDTH_MASK = 0) and (hwRound(Gear^.Y) and LAND_HEIGHT_MASK = 0) then
+                begin
+                VGear := AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtBulletHit);
+                if VGear <> nil then
+                    begin
+                    VGear^.Angle := DxDy2Angle(-Gear^.dX, Gear^.dY);
+                    end;
+                end;
+       
+            spawnBulletTrail(Gear);
+            Gear^.doStep := @doStepShotIdle
             end;
-        end;
-       
-        spawnBulletTrail(Gear);
-        Gear^.doStep := @doStepShotIdle
-    end;
 end;
 
 procedure doStepDEagleShot(Gear: PGear);
@@ -1041,21 +1087,22 @@
     HedgehogChAngle(HHGear);
     if not cLaserSighting then
         // game does not have default laser sight. turn it on and give them a chance to aim
-    begin
+        begin
         cLaserSighting := true;
         HHGear^.Message := 0;
-        if (HHGear^.Angle - 32 >= 0) then dec(HHGear^.Angle,32)
-    end;
+        if (HHGear^.Angle - 32 >= 0) then
+            dec(HHGear^.Angle,32)
+        end;
 
     if (HHGear^.Message and gmAttack) <> 0 then
-    begin
+        begin
         shell := AddVisualGear(hwRound(Gear^.x), hwRound(Gear^.y), vgtShell);
         if shell <> nil then
-        begin
+            begin
             shell^.dX := gear^.dX.QWordValue / -8589934592;
             shell^.dY := gear^.dY.QWordValue / -8589934592;
             shell^.Frame := 1
-        end;
+            end;
         Gear^.State := Gear^.State or gstAnimation;
         Gear^.dX := SignAs(AngleSin(HHGear^.Angle), HHGear^.dX) * _0_5;
         Gear^.dY := -AngleCos(HHGear^.Angle) * _0_5;
@@ -1064,56 +1111,59 @@
         Gear^.X := Gear^.X + Gear^.dX * 3;  
         Gear^.Y := Gear^.Y + Gear^.dY * 3;
         Gear^.doStep := @doStepBulletWork;
-    end
+        end
     else
         if (GameTicks mod 32) = 0 then
             if (GameTicks mod 4096) < 2048 then
-            begin
-                if (HHGear^.Angle + 1 <= cMaxAngle) then inc(HHGear^.Angle)
-            end
+                begin
+                if (HHGear^.Angle + 1 <= cMaxAngle) then
+                    inc(HHGear^.Angle)
+                end
     else
-        if (HHGear^.Angle - 1 >= 0) then dec(HHGear^.Angle);
+        if (HHGear^.Angle - 1 >= 0) then
+            dec(HHGear^.Angle);
 
     if (TurnTimeLeft > 0) then
         dec(TurnTimeLeft)
     else
-    begin
+        begin
         DeleteGear(Gear);
         AfterAttack
-    end;
+        end;
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
 procedure doStepActionTimer(Gear: PGear);
 begin
-    dec(Gear^.Timer);
-    case Gear^.Kind of 
-        gtATStartGame: 
+dec(Gear^.Timer);
+case Gear^.Kind of
+    gtATStartGame: 
     begin
         AllInactive := false;
         if Gear^.Timer = 0 then
-        begin
+            begin
             AddCaption(trmsg[sidStartFight], cWhiteColor, capgrpGameState);
-        end
+            end
     end;
     gtATFinishGame: 
     begin
         AllInactive := false;
         if Gear^.Timer = 1000 then
-        begin
+            begin
             ScreenFade := sfToBlack;
             ScreenFadeValue := 0;
             ScreenFadeSpeed := 1;
-        end;
+            end;
         if Gear^.Timer = 0 then
-        begin
+            begin
             SendIPC('N');
             SendIPC('q');
             GameState := gsExit
-        end
+            end
     end;
 end;
-if Gear^.Timer = 0 then DeleteGear(Gear)
+if Gear^.Timer = 0 then
+    DeleteGear(Gear)
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -1125,9 +1175,11 @@
     AllInactive := false;
     HHGear := Gear^.Hedgehog^.Gear;
     dec(Gear^.Timer);
-    if ((GameFlags and gfInfAttack) <> 0) and (TurnTimeLeft > 0) then dec(TurnTimeLeft);
-    if (TurnTimeLeft = 0) or (Gear^.Timer = 0)or((Gear^.Message and gmDestroy) <> 0)or((HHGear^.State and gstHHDriven) =
-       0) then
+    if ((GameFlags and gfInfAttack) <> 0) and (TurnTimeLeft > 0) then
+        dec(TurnTimeLeft);
+    if (TurnTimeLeft = 0) or (Gear^.Timer = 0)
+    or((Gear^.Message and gmDestroy) <> 0)
+    or((HHGear^.State and gstHHDriven) =0) then
         begin
         StopSound(Gear^.SoundChannel);
         DeleteGear(Gear);
@@ -1180,7 +1232,8 @@
             Gear^.dY := Gear^.dY + cGravity;
             Gear^.Y := Gear^.Y + Gear^.dY
             end;
-        if hwRound(Gear^.Y) > cWaterLine then Gear^.Timer := 1
+        if hwRound(Gear^.Y) > cWaterLine then
+            Gear^.Timer := 1
         end;
 
     Gear^.X := Gear^.X + HHGear^.dX;
@@ -1191,13 +1244,17 @@
         end;
 
     if (Gear^.Message and gmAttack) <> 0 then
-        if (Gear^.State and gsttmpFlag) <> 0 then Gear^.Timer := 1
-    else
+        if (Gear^.State and gsttmpFlag) <> 0 then
+            Gear^.Timer := 1
+    else //there would be a mistake.
     else
-        if (Gear^.State and gsttmpFlag) = 0 then Gear^.State := Gear^.State or gsttmpFlag;
-    if ((Gear^.Message and gmLeft) <> 0) then Gear^.dX := - _0_3
+        if (Gear^.State and gsttmpFlag) = 0 then
+            Gear^.State := Gear^.State or gsttmpFlag;
+    if ((Gear^.Message and gmLeft) <> 0) then
+        Gear^.dX := - _0_3
     else
-        if ((Gear^.Message and gmRight) <> 0) then Gear^.dX := _0_3
+        if ((Gear^.Message and gmRight) <> 0) then
+            Gear^.dX := _0_3
     else Gear^.dX := _0;
 end;
 
@@ -1212,12 +1269,12 @@
 
     y := hwRound(Gear^.Y) - cHHRadius * 2;
     while y < hwRound(Gear^.Y) do
-    begin
+        begin
         ar[i].Left := hwRound(Gear^.X) - Gear^.Radius - LongInt(GetRandom(2));
         ar[i].Right := hwRound(Gear^.X) + Gear^.Radius + LongInt(GetRandom(2));
         inc(y, 2);
         inc(i)
-    end;
+        end;
 
     DrawHLinesExplosions(@ar, 3, hwRound(Gear^.Y) - cHHRadius * 2, 2, Pred(i));
     Gear^.dY := HHGear^.dY;
@@ -1240,7 +1297,8 @@
 begin
     AllInactive := false;
     dec(Gear^.Timer);
-    if ((GameFlags and gfInfAttack) <> 0) and (TurnTimeLeft > 0) then dec(TurnTimeLeft);
+    if ((GameFlags and gfInfAttack) <> 0) and (TurnTimeLeft > 0) then
+        dec(TurnTimeLeft);
     
     HHGear := Gear^.Hedgehog^.Gear;
 
@@ -1259,7 +1317,8 @@
     if ((HHGear^.State and gstMoving) <> 0) then
         begin
         doStepHedgehogMoving(HHGear);
-        if (HHGear^.State and gstHHDriven) = 0 then Gear^.Timer := 0
+        if (HHGear^.State and gstHHDriven) = 0 then
+            Gear^.Timer := 0
         end;
 
     if Gear^.Timer mod cHHStepTicks = 0 then
@@ -1290,9 +1349,7 @@
         if BTSteps = 7 then
             begin
             BTSteps := 0;
-            if CheckLandValue(hwRound(HHGear^.X + Gear^.dX * (cHHRadius + cBlowTorchC) + SignAs(_6,
-               Gear^.dX)), hwRound(HHGear^.Y + Gear^.dY * (cHHRadius + cBlowTorchC)),
-               lfIndestructible) then
+            if CheckLandValue(hwRound(HHGear^.X + Gear^.dX * (cHHRadius + cBlowTorchC) + SignAs(_6,Gear^.dX)), hwRound(HHGear^.Y + Gear^.dY * (cHHRadius + cBlowTorchC)),lfIndestructible) then
                 begin
                 Gear^.X := HHGear^.X + Gear^.dX * (cHHRadius + cBlowTorchC);
                 Gear^.Y := HHGear^.Y + Gear^.dY * (cHHRadius + cBlowTorchC);
@@ -1312,7 +1369,8 @@
         cHHStepTicks, cHHRadius * 2 + 7);
     end;
 
-    if (TurnTimeLeft = 0) or (Gear^.Timer = 0) or ((HHGear^.Message and gmAttack) <> 0) then
+    if (TurnTimeLeft = 0) or (Gear^.Timer = 0)
+    or ((HHGear^.Message and gmAttack) <> 0) then
         begin
         HHGear^.Message := 0;
         HHGear^.State := HHGear^.State and (not gstNotKickable);
@@ -1344,24 +1402,28 @@
 begin
     HHGear := Gear^.Hedgehog^.Gear;
     if ((HHGear^.State and gstHHDriven) = 0)
-       or (CheckGearDrowning(HHGear))
-       or (TestCollisionYwithGear(HHGear, 1) <> 0) then
-    begin
+    or (CheckGearDrowning(HHGear))
+    or (TestCollisionYwithGear(HHGear, 1) <> 0) then
+        begin
         DeleteGear(Gear);
         isCursorVisible := false;
         ApplyAmmoChanges(HHGear^.Hedgehog^);
         exit
-    end;
+        end;
 
     HedgehogChAngle(HHGear);
 
-    if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then SetLittle(HHGear^.dX);
-
-    if HHGear^.dY.isNegative and (TestCollisionYwithGear(HHGear, -1) <> 0) then HHGear^.dY := _0;
+    if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then
+        SetLittle(HHGear^.dX);
+
+    if HHGear^.dY.isNegative and (TestCollisionYwithGear(HHGear, -1) <> 0) then
+        HHGear^.dY := _0;
     HHGear^.X := HHGear^.X + HHGear^.dX;
     HHGear^.Y := HHGear^.Y + HHGear^.dY;
     HHGear^.dY := HHGear^.dY + cGravity;
-    if (GameFlags and gfMoreWind) <> 0 then HHGear^.dX := HHGear^.dX + cWindSpeed / HHGear^.Density;
+    
+    if (GameFlags and gfMoreWind) <> 0 then
+        HHGear^.dX := HHGear^.dX + cWindSpeed / HHGear^.Density;
 
     if (Gear^.Message and gmAttack) <> 0 then
         begin
@@ -1382,20 +1444,20 @@
 procedure RopeDeleteMe(Gear, HHGear: PGear);
 begin
     with HHGear^ do
-    begin
+        begin
         Message := Message and (not gmAttack);
         State := (State or gstMoving) and (not gstWinner);
-    end;
+        end;
     DeleteGear(Gear)
 end;
 
 procedure RopeWaitCollision(Gear, HHGear: PGear);
 begin
     with HHGear^ do
-    begin
+        begin
         Message := Message and (not gmAttack);
         State := State or gstMoving;
-    end;
+        end;
     RopePoints.Count := 0;
     Gear^.Elasticity := _0;
     Gear^.doStep := @doStepRopeAfterAttack
@@ -1467,12 +1529,12 @@
 
     if ((Gear^.Message and gmDown) <> 0) and (Gear^.Elasticity < Gear^.Friction) then
         if not (TestCollisionXwithGear(HHGear, hwSign(ropeDx))
-           or (TestCollisionYwithGear(HHGear, hwSign(ropeDy)) <> 0)) then
+        or (TestCollisionYwithGear(HHGear, hwSign(ropeDy)) <> 0)) then
             Gear^.Elasticity := Gear^.Elasticity + _0_3;
 
     if ((Gear^.Message and gmUp) <> 0) and (Gear^.Elasticity > _30) then
         if not (TestCollisionXwithGear(HHGear, -hwSign(ropeDx))
-           or (TestCollisionYwithGear(HHGear, -hwSign(ropeDy)) <> 0)) then
+        or (TestCollisionYwithGear(HHGear, -hwSign(ropeDy)) <> 0)) then
             Gear^.Elasticity := Gear^.Elasticity - _0_3;
 
     HHGear^.X := Gear^.X + mdX * Gear^.Elasticity;
@@ -1507,10 +1569,12 @@
                 begin
                 X := Gear^.X;
                 Y := Gear^.Y;
-                if RopePoints.Count = 0 then RopePoints.HookAngle := DxDy2Angle(Gear^.dY, Gear^.dX);
+                if RopePoints.Count = 0 then
+                    RopePoints.HookAngle := DxDy2Angle(Gear^.dY, Gear^.dX);
                 b := (nx * HHGear^.dY) > (ny * HHGear^.dX);
                 dLen := len
                 end;
+                
             with RopePoints.rounded[RopePoints.Count] do
                 begin
                 X := hwRound(Gear^.X);
@@ -1570,9 +1634,7 @@
         haveCollision := true
         end;
 
-    if haveCollision
-       and (Gear^.Message and (gmLeft or gmRight) <> 0)
-       and (Gear^.Message and (gmUp or gmDown) <> 0) then
+    if haveCollision and (Gear^.Message and (gmLeft or gmRight) <> 0) and (Gear^.Message and (gmUp or gmDown) <> 0) then
         begin
         HHGear^.dX := SignAs(hwAbs(HHGear^.dX) + _0_2, HHGear^.dX);
         HHGear^.dY := SignAs(hwAbs(HHGear^.dY) + _0_2, HHGear^.dY)
@@ -1642,10 +1704,10 @@
 procedure RopeRemoveFromAmmo(Gear, HHGear: PGear);
 begin
     if (Gear^.State and gstAttacked) = 0 then
-    begin
+        begin
         OnUsedAmmo(HHGear^.Hedgehog^);
         Gear^.State := Gear^.State or gstAttacked
-    end;
+        end;
     ApplyAmmoChanges(HHGear^.Hedgehog^)
 end;
 
@@ -1663,8 +1725,10 @@
 
     if (HHGear^.State and gstMoving) <> 0 then
         begin
-        if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then SetLittle(HHGear^.dX);
-        if HHGear^.dY.isNegative and (TestCollisionYwithGear(HHGear, -1) <> 0) then HHGear^.dY := _0;
+        if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then
+            SetLittle(HHGear^.dX);
+        if HHGear^.dY.isNegative and (TestCollisionYwithGear(HHGear, -1) <> 0) then
+            HHGear^.dY := _0;
 
         HHGear^.X := HHGear^.X + HHGear^.dX;
         Gear^.X := Gear^.X + HHGear^.dX;
@@ -1680,7 +1744,8 @@
             HHGear^.Y := HHGear^.Y + HHGear^.dY;
             Gear^.Y := Gear^.Y + HHGear^.dY;
             HHGear^.dY := HHGear^.dY + cGravity;
-            if (GameFlags and gfMoreWind) <> 0 then HHGear^.dX := HHGear^.dX + cWindSpeed / HHGear^.Density
+            if (GameFlags and gfMoreWind) <> 0 then
+                HHGear^.dX := HHGear^.dX + cWindSpeed / HHGear^.Density
             end;
 
         tt := Gear^.Elasticity;
@@ -1733,15 +1798,15 @@
         end;
 
     if (Gear^.Elasticity > Gear^.Friction)
-       or ((Gear^.Message and gmAttack) = 0)
-       or ((HHGear^.State and gstHHDriven) = 0)
-       or (HHGear^.Damage > 0) then
-        begin
-        with Gear^.Hedgehog^.Gear^ do
+        or ((Gear^.Message and gmAttack) = 0)
+        or ((HHGear^.State and gstHHDriven) = 0)
+        or (HHGear^.Damage > 0) then
             begin
-            State := State and (not gstAttacking);
-            Message := Message and (not gmAttack)
-            end;
+            with Gear^.Hedgehog^.Gear^ do
+                begin
+                State := State and (not gstAttacking);
+                Message := Message and (not gmAttack)
+                end;
         DeleteGear(Gear)
         end;
     CheckGearDrowning(HHGear)
@@ -1760,15 +1825,15 @@
 var vg: PVisualGear;
 begin
     if (Gear^.State and gstMoving) <> 0 then
-    begin
+        begin
         DeleteCI(Gear);
         doStepFallingGear(Gear);
         if (Gear^.State and gstMoving) = 0 then
-        begin
+            begin
             AddGearCI(Gear);
             Gear^.dX := _0;
             Gear^.dY := _0
-        end;
+            end;
         CalcRotationDirAngle(Gear);
         AllInactive := false
     end
@@ -1779,18 +1844,22 @@
         begin
             if not Gear^.dY.isNegative and (Gear^.dY > _0_2) and (TestCollisionYwithGear(Gear, 1) <> 0) then
                 inc(Gear^.Damage, hwRound(Gear^.dY * _70))
+                
             else if not Gear^.dX.isNegative and (Gear^.dX > _0_2) and TestCollisionXwithGear(Gear, 1) then
-                 inc(Gear^.Damage, hwRound(Gear^.dX * _70))
+                inc(Gear^.Damage, hwRound(Gear^.dX * _70))
+                
             else if Gear^.dY.isNegative and (Gear^.dY < -_0_2) and (TestCollisionYwithGear(Gear, -1) <> 0) then
-                 inc(Gear^.Damage, hwRound(Gear^.dY * -_70))
+                inc(Gear^.Damage, hwRound(Gear^.dY * -_70))
+                
             else if Gear^.dX.isNegative and (Gear^.dX < -_0_2) and TestCollisionXwithGear(Gear, -1) then
-                 inc(Gear^.Damage, hwRound(Gear^.dX * -_70));
+                inc(Gear^.Damage, hwRound(Gear^.dX * -_70));
         
         if ((GameTicks and $FF) = 0) and (Gear^.Damage > random(30)) then
-            begin
-            vg:= AddVisualGear(hwRound(Gear^.X) - 4  + Random(8), hwRound(Gear^.Y) - 4 - Random(4), vgtSmoke);
-            if vg <> nil then vg^.Scale:= 0.5
-            end;
+                begin
+                vg:= AddVisualGear(hwRound(Gear^.X) - 4  + Random(8), hwRound(Gear^.Y) - 4 - Random(4), vgtSmoke);
+                if vg <> nil then
+                    vg^.Scale:= 0.5
+                end;
 
         if (Gear^.Damage > 35) then
             begin
@@ -1804,18 +1873,19 @@
         if ((Gear^.State and gstAttacking) = 0) then
             begin
             if ((GameTicks and $1F) = 0) then
-                if CheckGearNear(Gear, gtHedgehog, 46, 32) <> nil then Gear^.State := Gear^.State or
-                                                                                      gstAttacking
+                if CheckGearNear(Gear, gtHedgehog, 46, 32) <> nil then
+                    Gear^.State := Gear^.State or gstAttacking
             end
         else // gstAttacking <> 0
             begin
             AllInactive := false;
-            if (Gear^.Timer and $FF) = 0 then PlaySound(sndMineTick);
+            if (Gear^.Timer and $FF) = 0 then
+                PlaySound(sndMineTick);
             if Gear^.Timer = 0 then
                 begin
-                if ((Gear^.State and gstWait) <> 0) or
-                   (cMineDudPercent = 0) or
-                   (getRandom(100) > cMineDudPercent) then
+                if ((Gear^.State and gstWait) <> 0)
+                or (cMineDudPercent = 0)
+                or (getRandom(100) > cMineDudPercent) then
                     begin
                     doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 50, Gear^.Hedgehog, EXPLAutoSound);
                     DeleteGear(Gear)
@@ -1823,7 +1893,8 @@
                 else
                     begin
                     vg:= AddVisualGear(hwRound(Gear^.X) - 4  + Random(8), hwRound(Gear^.Y) - 4 - Random(4), vgtSmoke);
-                    if vg <> nil then vg^.Scale:= 0.5;
+                    if vg <> nil then
+                        vg^.Scale:= 0.5;
                     PlaySound(sndVaporize);
                     Gear^.Health := 0;
                     Gear^.Damage := 0;
@@ -1834,7 +1905,10 @@
             dec(Gear^.Timer);
             end
     else // gsttmpFlag = 0
-        if (TurnTimeLeft = 0) or ((GameFlags and gfInfAttack <> 0) and (GameTicks > Gear^.FlightTime)) or (Gear^.Hedgehog^.Gear = nil) then Gear^.State := Gear^.State or gsttmpFlag;
+        if (TurnTimeLeft = 0)
+        or ((GameFlags and gfInfAttack <> 0) and (GameTicks > Gear^.FlightTime))
+        or (Gear^.Hedgehog^.Gear = nil) then
+            Gear^.State := Gear^.State or gsttmpFlag;
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -1842,50 +1916,54 @@
 begin
     // TODO: do real calculation?
     if TestCollisionXwithGear(Gear, 2) 
-        or (TestCollisionYwithGear(Gear, -2) <> 0) 
-        or TestCollisionXwithGear(Gear, -2) 
-        or (TestCollisionYwithGear(Gear, 2) <> 0) then
-    begin
+    or (TestCollisionYwithGear(Gear, -2) <> 0) 
+    or TestCollisionXwithGear(Gear, -2) 
+    or (TestCollisionYwithGear(Gear, 2) <> 0) then
+        begin
         if (hwAbs(Gear^.dX) > _0) or (hwAbs(Gear^.dY) > _0) then
-        begin
+            begin
             PlaySound(sndRopeAttach);
             Gear^.dX:= _0;
             Gear^.dY:= _0;
             AddGearCI(Gear);
-        end;
-    end
+            end;
+        end
     else
-    begin
+        begin
         DeleteCI(Gear);
         doStepFallingGear(Gear);
         AllInactive := false;
         CalcRotationDirAngle(Gear);
-    end;
+        end;
 
     if ((Gear^.State and gsttmpFlag) <> 0) and (Gear^.Health <> 0) then
-    begin
+        begin
         if ((Gear^.State and gstAttacking) = 0) then
-        begin
+            begin
             if ((GameTicks and $1F) = 0) then
-                if CheckGearNear(Gear, gtHedgehog, 46, 32) <> nil then Gear^.State := Gear^.State or
-                                                                                      gstAttacking
-        end
+                if CheckGearNear(Gear, gtHedgehog, 46, 32) <> nil then
+                    Gear^.State := Gear^.State or gstAttacking
+            end
         else // gstAttacking <> 0
         begin
             AllInactive := false;
             if Gear^.Timer = 0 then
-            begin
+                begin
                 doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 30, Gear^.Hedgehog, EXPLAutoSound);
                 DeleteGear(Gear);
                 exit
             end else
-                if (Gear^.Timer and $FF) = 0 then PlaySound(sndMineTick);
+                if (Gear^.Timer and $FF) = 0 then
+                    PlaySound(sndMineTick);
 
             dec(Gear^.Timer);
+                end
         end
-    end
     else // gsttmpFlag = 0
-        if (TurnTimeLeft = 0) or ((GameFlags and gfInfAttack <> 0) and (GameTicks > Gear^.FlightTime)) or (Gear^.Hedgehog^.Gear = nil) then Gear^.State := Gear^.State or gsttmpFlag;
+        if (TurnTimeLeft = 0)
+        or ((GameFlags and gfInfAttack <> 0) and (GameTicks > Gear^.FlightTime))
+        or (Gear^.Hedgehog^.Gear = nil) then
+            Gear^.State := Gear^.State or gsttmpFlag;
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -1893,15 +1971,16 @@
 begin
     doStepFallingGear(Gear);
     AllInactive := false;
-    if Gear^.Timer mod 166 = 0 then inc(Gear^.Tag);
+    if Gear^.Timer mod 166 = 0 then
+        inc(Gear^.Tag);
     if Gear^.Timer = 1000 then // might need better timing
         makeHogsWorry(Gear^.X, Gear^.Y, 75);
     if Gear^.Timer = 0 then
-    begin
+        begin
         doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 75, Gear^.Hedgehog, EXPLAutoSound);
         DeleteGear(Gear);
         exit
-    end;
+        end;
     dec(Gear^.Timer);
 end;
 
@@ -1917,42 +1996,44 @@
     i: LongInt;
     particle: PVisualGear;
 begin
-    if (Gear^.dY.QWordValue = 0) and (Gear^.dY.QWordValue = 0) and (TestCollisionYwithGear(Gear, 1) = 0) then SetLittle(Gear^.dY);
+    if (Gear^.dY.QWordValue = 0) and (Gear^.dY.QWordValue = 0) and (TestCollisionYwithGear(Gear, 1) = 0) then
+        SetLittle(Gear^.dY);
     Gear^.State := Gear^.State or gstAnimation;
-    if ((Gear^.dX.QWordValue <> 0) or (Gear^.dY.QWordValue <> 0))  then
-    begin
+    
+    if ((Gear^.dX.QWordValue <> 0)
+    or (Gear^.dY.QWordValue <> 0))  then
+        begin
         DeleteCI(Gear);
         AllInactive := false;
         if not Gear^.dY.isNegative and (Gear^.dY > _0_2) and (TestCollisionYwithGear(Gear, 1) <> 0) then
-        begin
+            begin
             Gear^.State := Gear^.State or gsttmpFlag;
             inc(Gear^.Damage, hwRound(Gear^.dY * _70));
             for i:= min(12, hwRound(Gear^.dY*_10)) downto 0 do
-            begin
-                particle := AddVisualGear(hwRound(Gear^.X) - 5 + Random(10), hwRound(Gear^.Y) + 12,
-                            vgtDust);
-                if particle <> nil then particle^.dX := particle^.dX + (Gear^.dX.QWordValue / 21474836480)
+                begin
+                particle := AddVisualGear(hwRound(Gear^.X) - 5 + Random(10), hwRound(Gear^.Y) + 12,vgtDust);
+                if particle <> nil then
+                    particle^.dX := particle^.dX + (Gear^.dX.QWordValue / 21474836480)
+                end
             end
-        end
-        else if not Gear^.dX.isNegative and (Gear^.dX > _0_2) and TestCollisionXwithGear(Gear, 1)
-                 then
-                 inc(Gear^.Damage, hwRound(Gear^.dX * _70))
-        else if Gear^.dY.isNegative and (Gear^.dY < -_0_2) and (TestCollisionYwithGear(Gear, -1) <> 0)
-                 then
-                 inc(Gear^.Damage, hwRound(Gear^.dY * -_70))
-        else if Gear^.dX.isNegative and (Gear^.dX < -_0_2) and TestCollisionXwithGear(Gear, -1)
-                 then
-                 inc(Gear^.Damage, hwRound(Gear^.dX * -_70));
+        else if not Gear^.dX.isNegative and (Gear^.dX > _0_2) and TestCollisionXwithGear(Gear, 1) then
+                inc(Gear^.Damage, hwRound(Gear^.dX * _70))
+                
+        else if Gear^.dY.isNegative and (Gear^.dY < -_0_2) and (TestCollisionYwithGear(Gear, -1) <> 0) then
+                inc(Gear^.Damage, hwRound(Gear^.dY * -_70))
+                
+        else if Gear^.dX.isNegative and (Gear^.dX < -_0_2) and TestCollisionXwithGear(Gear, -1) then
+                inc(Gear^.Damage, hwRound(Gear^.dX * -_70));
 
         doStepFallingGear(Gear);
         CalcRotationDirAngle(Gear);
         //CheckGearDrowning(Gear)
-    end
+        end
     else
-    begin
+        begin
         Gear^.State := Gear^.State or gsttmpFlag;
         AddGearCI(Gear)
-    end;
+        end;
 
 (*
 Attempt to make a barrel knock itself over an edge.  Would need more checks to avoid issues like burn damage
@@ -1970,9 +2051,10 @@
     if Gear^.dX.QWordValue = 0 then AddGearCI(Gear)
     end; *)
 
-    if not Gear^.dY.isNegative and (Gear^.dY < _0_001) and (TestCollisionYwithGear(Gear, 1) <> 0) then Gear
-        ^.dY := _0;
-    if hwAbs(Gear^.dX) < _0_001 then Gear^.dX := _0;
+    if not Gear^.dY.isNegative and (Gear^.dY < _0_001) and (TestCollisionYwithGear(Gear, 1) <> 0) then
+        Gear^.dY := _0;
+    if hwAbs(Gear^.dX) < _0_001 then
+        Gear^.dX := _0;
 
     if (Gear^.Health > 0) and ((Gear^.Health * 100 div cBarrelHealth) < random(90)) and ((GameTicks and $FF) = 0) then
         if (cBarrelHealth div Gear^.Health) > 2 then
@@ -1981,7 +2063,8 @@
         AddVisualGear(hwRound(Gear^.X) - 16 + Random(32), hwRound(Gear^.Y) - 2, vgtSmokeWhite);
     dec(Gear^.Health, Gear^.Damage);
     Gear^.Damage := 0;
-    if Gear^.Health <= 0 then Gear^.doStep := @doStepCase;
+    if Gear^.Health <= 0 then
+        Gear^.doStep := @doStepCase;
     // Hand off to doStepCase for the explosion
 
 end;
@@ -1998,21 +2081,22 @@
     exBoom := false;
 
     if (Gear^.Message and gmDestroy) > 0 then
-    begin
+        begin
         DeleteGear(Gear);
         FreeActionsList;
         SetAllToActive;
         // something (hh, mine, etc...) could be on top of the case
         with CurrentHedgehog^ do
-            if Gear <> nil then Gear^.Message := Gear^.Message and (not (gmLJump or gmHJump));
+            if Gear <> nil then
+                Gear^.Message := Gear^.Message and (not (gmLJump or gmHJump));
         exit
-    end;
+        end;
 
     if k = gtExplosives then
-    begin
+        begin
         //if V > _0_03 then Gear^.State:= Gear^.State or gstAnimation;
-        if (hwAbs(Gear^.dX) > _0_15) or ((hwAbs(Gear^.dY) > _0_15) and (hwAbs(Gear^.dX) > _0_02))
-            then Gear^.doStep := @doStepRollingBarrel;
+        if (hwAbs(Gear^.dX) > _0_15) or ((hwAbs(Gear^.dY) > _0_15) and (hwAbs(Gear^.dX) > _0_02)) then
+            Gear^.doStep := @doStepRollingBarrel;
 
         if (Gear^.Health > 0) and ((Gear^.Health * 100 div cBarrelHealth) < random(90)) and ((GameTicks and $FF) = 0) then
             if (cBarrelHealth div Gear^.Health) > 2 then
@@ -2023,10 +2107,10 @@
         Gear^.Damage := 0;
         if Gear^.Health <= 0 then
             exBoom := true;
-    end;
+        end;
 
     if (Gear^.Damage > 0) or exBoom then
-    begin
+        begin
         x := hwRound(Gear^.X);
         y := hwRound(Gear^.Y);
         hog:= Gear^.Hedgehog;
@@ -2035,52 +2119,60 @@
         // <-- delete gear!
 
         if k = gtCase then
-        begin
+            begin
             doMakeExplosion(x, y, 25, hog, EXPLAutoSound);
             for i:= 0 to 63 do
                 AddGear(x, y, gtFlame, 0, _0, _0, 0);
-        end
+            end
         else if k = gtExplosives then
-            begin
+                begin
                 doMakeExplosion(x, y, 75, hog, EXPLAutoSound);
                 for i:= 0 to 31 do
-                begin
+                    begin
                     dX := AngleCos(i * 64) * _0_5 * (getrandom + _1);
                     dY := AngleSin(i * 64) * _0_5 * (getrandom + _1);
                     AddGear(x, y, gtFlame, 0, dX, dY, 0);
                     AddGear(x, y, gtFlame, gstTmpFlag, -dX, -dY, 0);
-                end
-            end;
-        exit
-    end;
-
-    if (Gear^.dY.QWordValue <> 0) or (TestCollisionYwithGear(Gear, 1) = 0) then
-    begin
+                    end
+                end;
+            exit
+        end;
+
+    if (Gear^.dY.QWordValue <> 0)
+    or (TestCollisionYwithGear(Gear, 1) = 0) then
+        begin
         AllInactive := false;
         Gear^.dY := Gear^.dY + cGravity;
         Gear^.Y := Gear^.Y + Gear^.dY;
-        if (not Gear^.dY.isNegative) and (Gear^.dY > _0_001) then SetAllHHToActive;
-        if (Gear^.dY.isNegative) and (TestCollisionYwithGear(Gear, -1) <> 0) then Gear^.dY := _0;
+        if (not Gear^.dY.isNegative) and (Gear^.dY > _0_001) then
+            SetAllHHToActive;
+            
+        if (Gear^.dY.isNegative) and (TestCollisionYwithGear(Gear, -1) <> 0) then
+            Gear^.dY := _0;
+            
         if (not Gear^.dY.isNegative) and (TestCollisionYwithGear(Gear, 1) <> 0) then
-        begin
+            begin
             if (Gear^.dY > _0_2) and (k = gtExplosives) then
                 inc(Gear^.Damage, hwRound(Gear^.dY * _70));
 
             if Gear^.dY > _0_2 then
                 for i:= min(12, hwRound(Gear^.dY*_10)) downto 0 do
-                    AddVisualGear(hwRound(Gear^.X) - 5 + Random(10), hwRound(Gear^.Y) + 12, vgtDust)
-            ;
+                    AddVisualGear(hwRound(Gear^.X) - 5 + Random(10), hwRound(Gear^.Y) + 12, vgtDust);
+                    
             Gear^.dY := - Gear^.dY * Gear^.Elasticity;
-            if Gear^.dY > - _0_001 then Gear^.dY := _0
+            if Gear^.dY > - _0_001 then
+                Gear^.dY := _0
             else if Gear^.dY < - _0_03 then
-                     PlaySound(Gear^.ImpactSound);
-        end;
+                PlaySound(Gear^.ImpactSound);
+            end;
         //if Gear^.dY > - _0_001 then Gear^.dY:= _0
         CheckGearDrowning(Gear);
-    end;
-
-    if (Gear^.dY.QWordValue = 0) then AddGearCI(Gear)
-    else if (Gear^.dY.QWordValue <> 0) then DeleteCI(Gear)
+        end;
+
+    if (Gear^.dY.QWordValue = 0) then
+        AddGearCI(Gear)
+    else if (Gear^.dY.QWordValue <> 0) then
+        DeleteCI(Gear)
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -2095,13 +2187,13 @@
     else if Gear^.Tag = 1 then
         Gear^.Tag := 2
     else if Gear^.Tag = 2 then
-             if Gear^.Timer > 0 then
-                 dec(Gear^.Timer)
+            if Gear^.Timer > 0 then
+                dec(Gear^.Timer)
     else
-    begin
+        begin
         DeleteGear(Gear);
         exit;
-    end;
+        end;
 
     doStepCase(Gear)
 end;
@@ -2112,10 +2204,10 @@
     AllInactive := false;
     dec(Gear^.Timer);
     if Gear^.Timer = 0 then
-    begin
+        begin
         DeleteGear(Gear);
         AfterAttack
-    end
+        end
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -2168,7 +2260,7 @@
     if not sticky then AllInactive := false;
 
     if TestCollisionYwithGear(Gear, 1) = 0 then
-    begin
+        begin
         AllInactive := false;
 
         if ((GameTicks mod 100) = 0) then
@@ -2185,26 +2277,29 @@
 
         if Gear^.dX.QWordValue > _0_01.QWordValue then
             Gear^.dX := Gear^.dX * _0_995;
+            
         Gear^.dY := Gear^.dY + cGravity;
         // if sticky then Gear^.dY := Gear^.dY + cGravity;
-        if Gear^.dY.QWordValue > _0_2.QWordValue then Gear^.dY := Gear^.dY * _0_995;
+        
+        if Gear^.dY.QWordValue > _0_2.QWordValue then
+            Gear^.dY := Gear^.dY * _0_995;
 
         //if sticky then Gear^.X := Gear^.X + Gear^.dX else
         Gear^.X := Gear^.X + Gear^.dX + cWindSpeed * 640;
         Gear^.Y := Gear^.Y + Gear^.dY;
 
         if (hwRound(Gear^.Y) > cWaterLine) then
-        begin
+            begin
             gX := hwRound(Gear^.X);
             for i:= 0 to 3 do
                 AddVisualGear(gX - 16 + Random(32), cWaterLine - 16 + Random(16), vgtSteam);
             PlaySound(sndVaporize);
             DeleteGear(Gear);
             exit
+            end
         end
-    end
     else
-    begin
+        begin
         if sticky then
             begin
             Gear^.Radius := 7;
@@ -2225,7 +2320,7 @@
             inc(Gear^.Damage)
             end
         else
-        begin
+            begin
             gX := hwRound(Gear^.X);
             gY := hwRound(Gear^.Y);
             // Standard fire
@@ -2245,12 +2340,16 @@
                     Gear^.dY:= tdY;
                     Gear^.Radius := 1;
                     end
-                else if ((GameTicks and $3) = 3) then doMakeExplosion(gX, gY, 8, Gear^.Hedgehog, 0);//, EXPLNoDamage); 
+                else if ((GameTicks and $3) = 3) then
+                    doMakeExplosion(gX, gY, 8, Gear^.Hedgehog, 0);//, EXPLNoDamage); 
                 //DrawExplosion(gX, gY, 4);
+                
                 if ((GameTicks and $7) = 0) and (Random(2) = 0) then
                     for i:= 1 to Random(2)+1 do
                         AddVisualGear(gX - 3 + Random(6), gY - 2, vgtSmoke);
-                if Gear^.Health > 0 then dec(Gear^.Health);
+                        
+                if Gear^.Health > 0 then
+                    dec(Gear^.Health);
                 Gear^.Timer := 450 - Gear^.Tag * 8
                 end
             else
@@ -2266,34 +2365,35 @@
 
 // This one is interesting.  I think I understand the purpose, but I wonder if a bit more fuzzy of kicking could be done with getrandom.
                 Gear^.Timer := 100 - Gear^.Tag * 3;
-                if (Gear^.Damage > 3000+Gear^.Tag*1500) then Gear^.Health := 0
+                if (Gear^.Damage > 3000+Gear^.Tag*1500) then
+                    Gear^.Health := 0
+                end
             end
-        end
-    end;
+        end;
     if Gear^.Health = 0 then
-    begin
+        begin
         gX := hwRound(Gear^.X);
         gY := hwRound(Gear^.Y);
         if not sticky then
-        begin
-            if ((GameTicks and $3) = 0) and (Random(1) = 0) then
             begin
-                for i:= 1 to Random(2)+1 do
+            if ((GameTicks and $3) = 0) and (Random(1) = 0) then
                 begin
+                for i:= 1 to Random(2)+1 do
+                    begin
                     AddVisualGear(gX - 3 + Random(6), gY - 2, vgtSmoke);
+                    end;
+                end;
+            end
+        else
+            begin
+            for i:= 0 to Random(3) do
+                begin
+                AddVisualGear(gX - 3 + Random(6), gY - 2, vgtSmoke);
                 end;
             end;
-        end
-        else
-        begin
-            for i:= 0 to Random(3) do
-            begin
-                AddVisualGear(gX - 3 + Random(6), gY - 2, vgtSmoke);
-            end;
-        end;
 
         DeleteGear(Gear)
-    end;
+        end;
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -2303,35 +2403,35 @@
 begin
     AllInactive := false;
     if ((Gear^.Message and gmDestroy) <> 0) then
-    begin
+        begin
         DeleteGear(Gear);
         AfterAttack;
         exit
-    end;
+        end;
 
     HHGear := Gear^.Hedgehog^.Gear;
     if hwRound(HHGear^.Y) <= Gear^.Tag - 2 then
-    begin
+        begin
         Gear^.Tag := hwRound(HHGear^.Y);
         DrawTunnel(HHGear^.X - int2hwFloat(cHHRadius), HHGear^.Y - _1, _0_5, _0, cHHRadius * 4, 2);
         HHGear^.State := HHGear^.State or gstNoDamage;
         Gear^.Y := HHGear^.Y;
         AmmoShove(Gear, 30, 40);
         HHGear^.State := HHGear^.State and (not gstNoDamage)
-    end;
+        end;
 
     HHGear^.dY := HHGear^.dY + cGravity;
     if not (HHGear^.dY.isNegative) then
-    begin
+        begin
         HHGear^.State := HHGear^.State or gstMoving;
         DeleteGear(Gear);
         AfterAttack;
         exit
-    end;
+        end;
 
     if CheckLandValue(hwRound(HHGear^.X), hwRound(HHGear^.Y + HHGear^.dY + SignAs(_6,Gear^.dY)),
-       lfIndestructible) then
-        HHGear^.Y := HHGear^.Y + HHGear^.dY
+        lfIndestructible) then
+            HHGear^.Y := HHGear^.Y + HHGear^.dY
 end;
 
 procedure doStepFirePunch(Gear: PGear);
@@ -2366,29 +2466,36 @@
     inc(Gear^.Timer);
 
     if (TestCollisionYwithGear(HHGear, 1) <> 0)
-       or ((HHGear^.State and gstHHDriven) = 0)
-       or CheckGearDrowning(HHGear)
-       or ((Gear^.Message and gmAttack) <> 0) then
-    begin
+    or ((HHGear^.State and gstHHDriven) = 0)
+    or CheckGearDrowning(HHGear)
+    or ((Gear^.Message and gmAttack) <> 0) then
+        begin
         with HHGear^ do
-        begin
+            begin
             Message := 0;
             SetLittle(dX);
             dY := _0;
             State := State or gstMoving;
-        end;
+            end;
         DeleteGear(Gear);
         isCursorVisible := false;
         ApplyAmmoChanges(HHGear^.Hedgehog^);
         exit
-    end;
+        end;
 
     HHGear^.X := HHGear^.X + cWindSpeed * 200;
 
-    if (Gear^.Message and gmLeft) <> 0 then HHGear^.X := HHGear^.X - cMaxWindSpeed * 80
-    else if (Gear^.Message and gmRight) <> 0 then HHGear^.X := HHGear^.X + cMaxWindSpeed * 80;
-    if (Gear^.Message and gmUp) <> 0 then HHGear^.Y := HHGear^.Y - cGravity * 40
-    else if (Gear^.Message and gmDown) <> 0 then HHGear^.Y := HHGear^.Y + cGravity * 40;
+    if (Gear^.Message and gmLeft) <> 0 then
+        HHGear^.X := HHGear^.X - cMaxWindSpeed * 80
+        
+    else if (Gear^.Message and gmRight) <> 0 then
+        HHGear^.X := HHGear^.X + cMaxWindSpeed * 80;
+        
+    if (Gear^.Message and gmUp) <> 0 then
+        HHGear^.Y := HHGear^.Y - cGravity * 40
+        
+    else if (Gear^.Message and gmDown) <> 0 then
+        HHGear^.Y := HHGear^.Y + cGravity * 40;
 
     // don't drift into obstacles
     if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then
@@ -2426,15 +2533,11 @@
     if (Gear^.Health > 0)and(not (Gear^.X < Gear^.dX))and(Gear^.X < Gear^.dX + cAirPlaneSpeed) then
         begin
         dec(Gear^.Health);
-        case Gear^.State of 
-            0: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtAirBomb, 0, cBombsSpeed *
-                             Gear^.Tag, _0, 0);
-            1: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtMine,    0, cBombsSpeed *
-                             Gear^.Tag, _0, 0);
-            2: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtNapalmBomb, 0, cBombsSpeed *
-                             Gear^.Tag, _0, 0);
-            3: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtDrill, gsttmpFlag, cBombsSpeed *
-                             Gear^.Tag, _0, Gear^.Timer + 1);
+            case Gear^.State of 
+                0: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtAirBomb, 0, cBombsSpeed * Gear^.Tag, _0, 0);
+                1: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtMine,    0, cBombsSpeed * Gear^.Tag, _0, 0);
+                2: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtNapalmBomb, 0, cBombsSpeed * Gear^.Tag, _0, 0);
+                3: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtDrill, gsttmpFlag, cBombsSpeed * Gear^.Tag, _0, Gear^.Timer + 1);
             //4: FollowGear := AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtWaterMelon, 0, cBombsSpeed *
             //                 Gear^.Tag, _0, 5000);
             end;
@@ -2446,11 +2549,11 @@
         AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtSmokeTrace);
 
     if (hwRound(Gear^.X) > (LAND_WIDTH+2048)) or (hwRound(Gear^.X) < -2048) then
-    begin
+        begin
         // avoid to play forever (is this necessary?)
         StopSound(Gear^.SoundChannel);
         DeleteGear(Gear)
-    end;
+        end;
 end;
 
 procedure doStepAirAttack(Gear: PGear);
@@ -2458,15 +2561,15 @@
     AllInactive := false;
 
     if Gear^.X.QWordValue = 0 then
-    begin
+        begin
         Gear^.Tag :=  1;
         Gear^.X := -_2048;
-    end
+        end
     else
-    begin
+        begin
         Gear^.Tag := -1;
         Gear^.X := int2hwFloat(LAND_WIDTH + 2048);
-    end;
+        end;
 
     Gear^.Y := int2hwFloat(topY-300);
     Gear^.dX := int2hwFloat(Gear^.Target.X - 5 * Gear^.Tag * 15);
@@ -2492,12 +2595,12 @@
     AllInactive := false;
     doStepFallingGear(Gear);
     if (Gear^.State and gstCollision) <> 0 then
-    begin
+        begin
         doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 30, Gear^.Hedgehog, EXPLAutoSound);
         DeleteGear(Gear);
         performRumble();
         exit
-    end;
+        end;
     if (GameTicks and $3F) = 0 then
         AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtSmokeTrace)
 end;
@@ -2517,24 +2620,22 @@
     x := HHGear^.X;
     y := HHGear^.Y;
 
-    if (Distance(tx - x, ty - y) > _256) or
-       (not TryPlaceOnLand(Gear^.Target.X - SpritesData[sprAmGirder].Width div 2,
-       Gear^.Target.Y - SpritesData[sprAmGirder].Height div 2,
-       sprAmGirder, Gear^.State, true, false)) then
-    begin
+    if (Distance(tx - x, ty - y) > _256)
+    or (not TryPlaceOnLand(Gear^.Target.X - SpritesData[sprAmGirder].Width div 2, Gear^.Target.Y - SpritesData[sprAmGirder].Height div 2, sprAmGirder, Gear^.State, true, false)) then
+        begin
         PlaySound(sndDenied);
         HHGear^.Message := HHGear^.Message and (not gmAttack);
         HHGear^.State := HHGear^.State and (not gstAttacking);
         HHGear^.State := HHGear^.State or gstHHChooseTarget;
         isCursorVisible := true;
         DeleteGear(Gear)
-    end
+        end
     else 
-    begin
+        begin
         PlaySound(sndPlaced);
         DeleteGear(Gear);
         AfterAttack;
-    end;
+        end;
 
     HHGear^.State := HHGear^.State and (not (gstAttacking or gstAttacked));
     HHGear^.Message := HHGear^.Message and (not gmAttack);
@@ -2552,23 +2653,23 @@
     // hedgehog falling to collect cases
     HHGear^.dY := HHGear^.dY + cGravity;
     if (TestCollisionYwithGear(HHGear, 1) <> 0)
-       or CheckGearDrowning(HHGear) then
-    begin
+    or CheckGearDrowning(HHGear) then
+        begin
         DeleteGear(Gear);
         AfterAttack
-    end
+        end
 end;
 
 procedure doStepTeleportAnim(Gear: PGear);
 begin
     inc(Gear^.Timer);
     if Gear^.Timer = 65 then
-    begin
+        begin
         Gear^.Timer := 0;
         inc(Gear^.Pos);
         if Gear^.Pos = 11 then
             Gear^.doStep := @doStepTeleportAfter
-    end;
+        end;
 end;
 
 procedure doStepTeleport(Gear: PGear);
@@ -2579,18 +2680,18 @@
 
     HHGear := Gear^.Hedgehog^.Gear;
     if not TryPlaceOnLand(Gear^.Target.X - SpritesData[sprHHTelepMask].Width div 2,
-       Gear^.Target.Y - SpritesData[sprHHTelepMask].Height div 2,
-       sprHHTelepMask, 0, false, false) then
-    begin
+        Gear^.Target.Y - SpritesData[sprHHTelepMask].Height div 2,
+        sprHHTelepMask, 0, false, false) then
+        begin
         HHGear^.Message := HHGear^.Message and (not gmAttack);
         HHGear^.State := HHGear^.State and (not gstAttacking);
         HHGear^.State := HHGear^.State or gstHHChooseTarget;
         DeleteGear(Gear);
         isCursorVisible := true;
         PlaySound(sndDenied)
-    end
+        end
     else
-    begin
+        begin
         DeleteCI(HHGear);
         SetAllHHToActive;
         Gear^.doStep := @doStepTeleportAnim;
@@ -2605,7 +2706,7 @@
         HHGear^.Y := int2hwFloat(Gear^.Target.Y);
         HHGear^.State := HHGear^.State or gstMoving;
         playSound(sndWarp)
-    end;
+        end;
     Gear^.Target.X:= NoPointX
 end;
 
@@ -2618,7 +2719,7 @@
     AllInactive := false;
 
     if ((Gear^.Message and (not gmSwitch)) <> 0) or (TurnTimeLeft = 0) then
-    begin
+        begin
         HHGear := Gear^.Hedgehog^.Gear;
         //Msg := Gear^.Message and (not gmSwitch);
         DeleteGear(Gear);
@@ -2628,10 +2729,10 @@
         ApplyAmmoChanges(HHGear^.Hedgehog^);
         //HHGear^.Message := Msg;
         exit
-    end;
+        end;
 
     if (Gear^.Message and gmSwitch) <> 0 then
-    begin
+        begin
         HHGear := CurrentHedgehog^.Gear;
         HHGear^.Message := HHGear^.Message and (not gmSwitch);
         Gear^.Message := Gear^.Message and (not gmSwitch);
@@ -2645,8 +2746,7 @@
         PlaySound(sndSwitchHog);
 
         repeat
-            CurrentTeam^.CurrHedgehog := Succ(CurrentTeam^.CurrHedgehog) mod (CurrentTeam^.
-                                         HedgehogsNumber);
+            CurrentTeam^.CurrHedgehog := Succ(CurrentTeam^.CurrHedgehog) mod (CurrentTeam^.HedgehogsNumber);
         until (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil) and (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear^.Damage = 0);
 
         CurrentHedgehog := @CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog];
@@ -2660,7 +2760,7 @@
         InsertGearToList(HHGear);
         Gear^.X := HHGear^.X;
         Gear^.Y := HHGear^.Y
-    end;
+        end;
 end;
 
 procedure doStepSwitcher(Gear: PGear);
@@ -2672,10 +2772,10 @@
     HHGear := Gear^.Hedgehog^.Gear;
     OnUsedAmmo(HHGear^.Hedgehog^);
     with HHGear^ do
-    begin
+        begin
         State := State and (not gstAttacking);
         Message := Message and (not gmAttack)
-    end
+        end
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -2691,21 +2791,21 @@
 
     doStepFallingGear(Gear);
     if (Gear^.State and gstCollision) <> 0 then
-    begin
+        begin
         doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 20, Gear^.Hedgehog, EXPLAutoSound);
 
         Gear^.dX.isNegative := not dxn;
         Gear^.dY.isNegative := not dyn;
         for i:= 0 to 4 do
-        begin
+            begin
             dX := Gear^.dX + (GetRandom - _0_5) * _0_03;
             dY := Gear^.dY + (GetRandom - _0_5) * _0_03;
             AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtCluster, 0, dX, dY, 25);
-        end;
+            end;
 
         DeleteGear(Gear);
         exit
-    end;
+        end;
 
     if (GameTicks and $3F) = 0 then
         AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtSmokeTrace)
@@ -2723,7 +2823,8 @@
 begin
     AllInactive := false;
     hasWishes:= ((Gear^.Message and (gmPrecise or gmSwitch)) = (gmPrecise or gmSwitch));
-    if hasWishes then Gear^.AdvBounce:= 1;
+    if hasWishes then
+        Gear^.AdvBounce:= 1;
 
     HHGear := Gear^.Hedgehog^.Gear;
     HHGear^.State := HHGear^.State or gstNoDamage;
@@ -2755,33 +2856,34 @@
         //      or TestCollisionYwithGear(HHGear, hwSign(Gear^.dY)) then inc(Gear^.Damage, 3);
 
         dec(i)
-    until (i = 0) or (Gear^.Damage > Gear^.Health);
+    until (i = 0)
+    or (Gear^.Damage > Gear^.Health);
 
     inc(upd);
     if upd > 3 then
-    begin
+        begin
         if Gear^.Health < 1500 then
-        begin
+            begin
             if Gear^.AdvBounce <> 0 then
                 Gear^.Pos := 3
             else
                 Gear^.Pos := 2;
-        end;
+            end;
 
         AmmoShove(Gear, 30, 40);
 
         DrawTunnel(HHGear^.X - HHGear^.dX * 10,
-                   HHGear^.Y - _2 - HHGear^.dY * 10 + hwAbs(HHGear^.dY) * 2,
+                    HHGear^.Y - _2 - HHGear^.dY * 10 + hwAbs(HHGear^.dY) * 2,
         HHGear^.dX,
         HHGear^.dY,
         20 + cHHRadius * 2,
         cHHRadius * 2 + 7);
 
         upd := 0
-    end;
+        end;
 
     if Gear^.Health < Gear^.Damage then
-    begin
+        begin
         doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 30, Gear^.Hedgehog, EXPLAutoSound);
         if hasWishes then
             for i:= 0 to 31 do
@@ -2794,8 +2896,10 @@
                         Angle:= random * 360;
                         dx:= 0.001 * (random(200));
                         dy:= 0.001 * (random(200));
-                        if random(2) = 0 then dx := -dx;
-                        if random(2) = 0 then dy := -dy;
+                        if random(2) = 0 then
+                            dx := -dx;
+                        if random(2) = 0 then
+                            dy := -dy;
                         FrameTicks:= random(400) + 250
                         end
                 end;
@@ -2804,10 +2908,10 @@
         DeleteGear(HHGear);
     end
     else
-    begin
+        begin
         dec(Gear^.Health, Gear^.Damage);
         Gear^.Damage := 0
-    end
+        end
 end;
 
 procedure doStepKamikazeIdle(Gear: PGear);
@@ -2856,7 +2960,8 @@
     AllInactive := false;
 
     inc(Gear^.Tag);
-    if Gear^.Tag < 2250 then exit;
+    if Gear^.Tag < 2250 then
+        exit;
 
     doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), cakeDmg, Gear^.Hedgehog, EXPLAutoSound);
     AfterAttack;
@@ -2871,14 +2976,15 @@
     AllInactive := false;
 
     inc(Gear^.Tag);
-    if Gear^.Tag < 100 then exit;
+    if Gear^.Tag < 100 then
+        exit;
     Gear^.Tag := 0;
 
     if Gear^.Pos = 0 then
-    begin
+        begin
         gi := GearsList;
         while gi <> nil do
-        begin
+            begin
             dmg := cakeDmg * 2 - hwRound(Distance(gi^.X - Gear^.X, gi^.Y - Gear^.Y));
             if (dmg > 1) and (gi^.Kind = gtHedgehog) then
                 if (CurrentHedgehog^.Gear = gi) and (not gi^.Invulnerable) then
@@ -2886,10 +2992,10 @@
             else
                 gi^.State := gi^.State or gstWinner;
             gi := gi^.NextGear
-        end;
+            end;
         Gear^.doStep := @doStepCakeExpl;
         PlaySound(sndCake)
-    end
+        end
     else dec(Gear^.Pos)
 end;
 
@@ -2915,7 +3021,8 @@
     AllInactive := false;
 
     inc(Gear^.Tag);
-    if Gear^.Tag < 7 then exit;
+    if Gear^.Tag < 7 then
+        exit;
 
     dA := hwSign(Gear^.dX);
     xx := dirs[Gear^.Angle].x;
@@ -2927,50 +3034,51 @@
         if TestCollisionYwithGear(Gear, yy) <> 0 then
             PrevAngle(Gear, dA)
     else
-    begin
+        begin
         Gear^.Tag := 0;
         Gear^.Y := Gear^.Y + int2hwFloat(yy);
         if not TestCollisionXwithGear(Gear, xxn) then
-        begin
+            begin
             Gear^.X := Gear^.X + int2hwFloat(xxn);
             NextAngle(Gear, dA)
+            end;
         end;
-    end;
 
     if (yy = 0) then
         if TestCollisionXwithGear(Gear, xx) then
             PrevAngle(Gear, dA)
     else
-    begin
+        begin
         Gear^.Tag := 0;
         Gear^.X := Gear^.X + int2hwFloat(xx);
         if not TestCollisionY(Gear, yyn) then
-        begin
+            begin
             Gear^.Y := Gear^.Y + int2hwFloat(yyn);
             NextAngle(Gear, dA)
+            end;
         end;
-    end;
 
     if Gear^.Tag = 0 then
-    begin
+        begin
         CakeI := (CakeI + 1) mod cakeh;
         tdx := CakePoints[CakeI].x - Gear^.X;
         tdy := - CakePoints[CakeI].y + Gear^.Y;
         CakePoints[CakeI].x := Gear^.X;
         CakePoints[CakeI].y := Gear^.Y;
         Gear^.DirAngle := DxDy2Angle(tdx, tdy);
-    end;
+        end;
 
     dec(Gear^.Health);
     Gear^.Timer := Gear^.Health*10;
-    if Gear^.Health mod 100 = 0 then Gear^.PortalCounter:= 0;
+    if Gear^.Health mod 100 = 0 then
+        Gear^.PortalCounter:= 0;
     // This is not seconds, but at least it is *some* feedback
     if (Gear^.Health = 0) or ((Gear^.Message and gmAttack) <> 0) then
-    begin
+        begin
         FollowGear := Gear;
         Gear^.RenderTimer := false;
         Gear^.doStep := @doStepCakeDown
-    end
+        end
 end;
 
 procedure doStepCakeUp(Gear: PGear);
@@ -2980,20 +3088,22 @@
     AllInactive := false;
 
     inc(Gear^.Tag);
-    if Gear^.Tag < 100 then exit;
+    if Gear^.Tag < 100 then
+        exit;
     Gear^.Tag := 0;
 
     if Gear^.Pos = 6 then
-    begin
+        begin
         for i:= 0 to Pred(cakeh) do
-        begin
+            begin
             CakePoints[i].x := Gear^.X;
             CakePoints[i].y := Gear^.Y
-        end;
+            end;
         CakeI := 0;
         Gear^.doStep := @doStepCakeWork
-    end
-    else inc(Gear^.Pos)
+        end
+    else
+        inc(Gear^.Pos)
 end;
 
 procedure doStepCakeFall(Gear: PGear);
@@ -3001,11 +3111,13 @@
     AllInactive := false;
 
     Gear^.dY := Gear^.dY + cGravity;
-    if TestCollisionYwithGear(Gear, 1) <> 0 then Gear^.doStep := @doStepCakeUp
+    if TestCollisionYwithGear(Gear, 1) <> 0 then
+        Gear^.doStep := @doStepCakeUp
     else
         begin
         Gear^.Y := Gear^.Y + Gear^.dY;
-        if CheckGearDrowning(Gear) then AfterAttack
+        if CheckGearDrowning(Gear) then
+            AfterAttack
         end
 end;
 
@@ -3094,8 +3206,10 @@
                 begin
                 dx:= 0.001 * (random(200));
                 dy:= 0.001 * (random(200));
-                if random(2) = 0 then dx := -dx;
-                if random(2) = 0 then dy := -dy;
+                if random(2) = 0 then
+                    dx := -dx;
+                if random(2) = 0 then
+                    dy := -dy;
                 FrameTicks:= random(750) + 1000;
                 State:= ord(sprSeduction)
                 end;
@@ -3117,10 +3231,11 @@
 var 
     i: LongWord;
 begin
-    if (Gear^.Tag = 0) or (cWaterLine = 0) then
-        begin
-            DeleteGear(Gear);
-            exit
+    if (Gear^.Tag = 0)
+    or (cWaterLine = 0) then
+        begin
+        DeleteGear(Gear);
+        exit
         end;
 
     AllInactive := false;
@@ -3132,12 +3247,12 @@
         exit;
 
     if cWaterLine > 0 then
-    begin
+        begin
         dec(cWaterLine);
         for i:= 0 to LAND_WIDTH - 1 do
             Land[cWaterLine, i] := 0;
         SetAllToActive
-    end;
+        end;
 
     dec(Gear^.Tag);
 end;
@@ -3163,21 +3278,22 @@
         if (Gear^.Timer mod 30) = 0 then
             AddVisualGear(hwRound(Gear^.X + _20 * Gear^.dX), hwRound(Gear^.Y + _20 * Gear^.dY), vgtDust);
         if (CheckGearDrowning(Gear)) then
-        begin
+           begin
             StopSound(Gear^.SoundChannel);
             exit
-        end
+    end
     end;
 
-    if GameTicks > Gear^.FlightTime then t := CheckGearsCollision(Gear)
+    if GameTicks > Gear^.FlightTime then
+        t := CheckGearsCollision(Gear)
+        
     else t := nil;
     //fixes drill not exploding when touching HH bug
-    if (Gear^.Timer = 0) or ((t <> nil) and (t^.Count <> 0)) or 
-       ( ((Gear^.State and gsttmpFlag) = 0) and
-         (TestCollisionYWithGear(Gear, hwSign(Gear^.dY)) = 0)
-         and (not TestCollisionXWithGear(Gear, hwSign(Gear^.dX))))
+    
+    if (Gear^.Timer = 0) or ((t <> nil) and (t^.Count <> 0))
+    or ( ((Gear^.State and gsttmpFlag) = 0) and (TestCollisionYWithGear(Gear, hwSign(Gear^.dY)) = 0) and (not TestCollisionXWithGear(Gear, hwSign(Gear^.dX))))
 // CheckLandValue returns true if the type isn't matched
-       or (not CheckLandValue(hwRound(Gear^.X), hwRound(Gear^.Y), lfIndestructible)) then
+    or (not CheckLandValue(hwRound(Gear^.X), hwRound(Gear^.Y), lfIndestructible)) then
         begin
         //out of time or exited ground
         StopSound(Gear^.SoundChannel);
@@ -3188,6 +3304,7 @@
         DeleteGear(Gear);
         exit
         end
+        
     else if (TestCollisionYWithGear(Gear, hwSign(Gear^.dY)) = 0) and (not TestCollisionXWithGear(Gear, hwSign(Gear^.dX))) then
         begin
         StopSound(Gear^.SoundChannel);
@@ -3218,13 +3335,15 @@
         AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtSmokeTrace);
 
     if ((Gear^.State and gstCollision) <> 0) then
-    begin
+        begin
         //hit
         Gear^.dX := oldDx;
         Gear^.dY := oldDy;
 
-        if GameTicks > Gear^.FlightTime then t := CheckGearsCollision(Gear)
-        else t := nil;
+        if GameTicks > Gear^.FlightTime then 
+            t := CheckGearsCollision(Gear)
+        else
+            t := nil;
         if (t = nil) or (t^.Count = 0) then
             begin
             //hit the ground not the HH
@@ -3232,6 +3351,7 @@
             Gear^.dX := Gear^.dX * t2;
             Gear^.dY := Gear^.dY * t2;
             end
+            
         else if (t <> nil) then
             begin
             //explode right on contact with HH
@@ -3245,20 +3365,22 @@
 
         Gear^.SoundChannel := LoopSound(sndDrillRocket);
         Gear^.doStep := @doStepDrillDrilling;
+        
         if (Gear^.State and gsttmpFlag) <> 0 then
             gear^.RenderTimer:= true;
         dec(Gear^.Timer)
-    end
-    else if ((Gear^.State and gsttmpFlag) <> 0) and (Gear^.Tag <> 0) then
-         begin
+        end
+        
+        else if ((Gear^.State and gsttmpFlag) <> 0) and (Gear^.Tag <> 0) then
+            begin
             if Gear^.Timer = 0 then
-            begin
+                begin
                 doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 30, Gear^.Hedgehog, EXPLAutoSound);
                 DeleteGear(Gear);
-            end
+                end
             else
                 dec(Gear^.Timer);
-         end;
+            end;
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -3275,23 +3397,20 @@
     gX := hwRound(Gear^.X) + GetLaunchX(amBallgun, hwSign(HHGear^.dX), HHGear^.Angle);
     gY := hwRound(Gear^.Y) + GetLaunchY(amBallgun, HHGear^.Angle);
     if (Gear^.Timer mod 100) = 0 then
-    begin
+        begin
         rx := rndSign(getRandom * _0_1);
         ry := rndSign(getRandom * _0_1);
 
-        AddGear(gx, gy, gtBall, 0,
-                SignAs(AngleSin(HHGear^.Angle) * _0_8, HHGear^.dX) + rx,
-        AngleCos(HHGear^.Angle) * ( - _0_8) + ry,
-        0);
+        AddGear(gx, gy, gtBall, 0, SignAs(AngleSin(HHGear^.Angle) * _0_8, HHGear^.dX) + rx, AngleCos(HHGear^.Angle) * ( - _0_8) + ry, 0);
 
         PlaySound(sndGun);
-    end;
+        end;
 
     if (Gear^.Timer = 0) or (HHGear^.Damage <> 0) then
-    begin
+        begin
         DeleteGear(Gear);
         AfterAttack
-    end
+        end
 end;
 
 procedure doStepBallgun(Gear: PGear);
@@ -3321,34 +3440,38 @@
     HHGear := Gear^.Hedgehog^.Gear;
     FollowGear := Gear;
 
-    if Gear^.Timer > 0 then dec(Gear^.Timer);
+    if Gear^.Timer > 0 then
+        dec(Gear^.Timer);
 
     fChanged := false;
     if ((HHGear^.State and gstHHDriven) = 0) or (Gear^.Timer = 0) then
-    begin
+        begin
         fChanged := true;
-        if Gear^.Angle > 2048 then dec(Gear^.Angle)
+        if Gear^.Angle > 2048 then
+            dec(Gear^.Angle)
         else
-            if Gear^.Angle < 2048 then inc(Gear^.Angle)
-        else fChanged := false
+            if Gear^.Angle < 2048 then
+                inc(Gear^.Angle)
+        else
+            fChanged := false
     end
     else
-    begin
+        begin
         if ((Gear^.Message and gmLeft) <> 0) then
-        begin
+            begin
             fChanged := true;
             Gear^.Angle := (Gear^.Angle + (4096 - cAngleSpeed)) mod 4096
-        end;
+            end;
 
         if ((Gear^.Message and gmRight) <> 0) then
-        begin
+            begin
             fChanged := true;
             Gear^.Angle := (Gear^.Angle + cAngleSpeed) mod 4096
-        end
-    end;
+            end
+        end;
 
     if fChanged then
-    begin
+        begin
         Gear^.dX.isNegative := (Gear^.Angle > 2048);
         if Gear^.dX.isNegative then
             trueAngle := 4096 - Gear^.Angle
@@ -3357,7 +3480,7 @@
 
         Gear^.dX := SignAs(AngleSin(trueAngle), Gear^.dX) * _0_25;
         Gear^.dY := AngleCos(trueAngle) * -_0_25;
-    end;
+        end;
 
     Gear^.X := Gear^.X + Gear^.dX;
     Gear^.Y := Gear^.Y + Gear^.dY;
@@ -3369,20 +3492,19 @@
         AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtSmokeTrace);
 
     if ((HHGear^.Message and gmAttack) <> 0) and (Gear^.Health <> 0) then
-    begin
+        begin
         HHGear^.Message := HHGear^.Message and (not gmAttack);
         AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtAirBomb, 0, Gear^.dX * _0_5, Gear^.dY *
         _0_5, 0);
         dec(Gear^.Health)
-    end;
-
-    if ((HHGear^.Message and gmLJump) <> 0)
-       and ((Gear^.State and gsttmpFlag) = 0) then
-    begin
+        end;
+
+    if ((HHGear^.Message and gmLJump) <> 0) and ((Gear^.State and gsttmpFlag) = 0) then
+        begin
         Gear^.State := Gear^.State or gsttmpFlag;
         PauseMusic;
         playSound(sndRideOfTheValkyries);
-    end;
+        end;
 
     // pickup bonuses
     t := CheckGearNear(Gear, gtCase, 36, 36);
@@ -3392,35 +3514,37 @@
     CheckCollision(Gear);
 
     if ((Gear^.State and gstCollision) <> 0) or CheckGearDrowning(Gear) then
-    begin
+        begin
         StopSound(Gear^.SoundChannel);
         StopSound(sndRideOfTheValkyries);
         ResumeMusic;
 
         if ((Gear^.State and gstCollision) <> 0) then
-        begin
+            begin
             doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 25, Gear^.Hedgehog, EXPLAutoSound);
             for i:= 0 to 15 do
-            begin
+                begin
                 dX := AngleCos(i * 64) * _0_5 * (GetRandom + _1);
                 dY := AngleSin(i * 64) * _0_5 * (GetRandom + _1);
                 AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtFlame, 0, dX, dY, 0);
                 AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtFlame, 0, dX, -dY, 0);
-            end;
+                end;
             DeleteGear(Gear)
-        end;
+            end;
 
         AfterAttack;
         CurAmmoGear := nil;
         if (GameFlags and gfInfAttack) = 0 then
             begin
-            if TagTurnTimeLeft = 0 then TagTurnTimeLeft:= TurnTimeLeft;
+            if TagTurnTimeLeft = 0 then
+                TagTurnTimeLeft:= TurnTimeLeft;
+                
             TurnTimeLeft:= 14 * 125;
             end;
 
         HHGear^.Message := 0;
         ParseCommand('/taunt ' + #1, true)
-    end
+        end
 end;
 
 procedure doStepRCPlane(Gear: PGear);
@@ -3432,7 +3556,9 @@
     HHGear^.State := HHGear^.State or gstNotKickable;
     Gear^.Angle := HHGear^.Angle;
     Gear^.Tag := hwSign(HHGear^.dX);
-    if HHGear^.dX.isNegative then Gear^.Angle := 4096 - Gear^.Angle;
+    
+    if HHGear^.dX.isNegative then
+        Gear^.Angle := 4096 - Gear^.Angle;
     Gear^.doStep := @doStepRCPlaneWork
 end;
 
@@ -3446,7 +3572,8 @@
     bubble: PVisualGear;
 begin
     isUnderwater:= cWaterLine < hwRound(Gear^.Y) + Gear^.Radius;
-    if Gear^.Pos > 0 then dec(Gear^.Pos);
+    if Gear^.Pos > 0 then
+        dec(Gear^.Pos);
     AllInactive := false;
     HHGear := Gear^.Hedgehog^.Gear;
     //dec(Gear^.Timer);
@@ -3470,7 +3597,8 @@
                     for i:= random(10)+10 downto 0 do
                         begin
                         bubble := AddVisualGear(hwRound(HHGear^.X) - 8 + random(16), hwRound(HHGear^.Y) + 16 + random(8), vgtBubble);
-                        if bubble <> nil then bubble^.dY:= random(20)/10+0.1;
+                        if bubble <> nil then
+                            bubble^.dY:= random(20)/10+0.1;
                         end
                     end
                 else HHGear^.dY := HHGear^.dY - move;
@@ -3513,19 +3641,22 @@
         Gear^.MsgParam := 0
         end;
 
-    if Gear^.Health < 0 then Gear^.Health := 0;
+    if Gear^.Health < 0 then
+        Gear^.Health := 0;
+        
     i:= Gear^.Health div 20;
+    
     if (i <> Gear^.Damage) and ((GameTicks and $3F) = 0) then
         begin
         Gear^.Damage:= i;
         //AddCaption('Fuel: '+inttostr(round(Gear^.Health/20))+'%', cWhiteColor, capgrpAmmostate);
         FreeTexture(Gear^.Tex);
-        Gear^.Tex := RenderStringTex(trmsg[sidFuel] + ': ' + inttostr(i) +
-                     '%', cWhiteColor, fntSmall)
+        Gear^.Tex := RenderStringTex(trmsg[sidFuel] + ': ' + inttostr(i) + '%', cWhiteColor, fntSmall)
         end;
 
     if HHGear^.Message and (gmAttack or gmUp or gmPrecise or gmLeft or gmRight) <> 0 then 
         Gear^.State := Gear^.State and (not gsttmpFlag);
+        
     HHGear^.Message := HHGear^.Message and (not (gmUp or gmPrecise or gmLeft or gmRight));
     HHGear^.State := HHGear^.State or gstMoving;
 
@@ -3533,10 +3664,16 @@
     Gear^.Y := HHGear^.Y;
     // For some reason I need to reapply followgear here, something else grabs it otherwise.
     // This is probably not needed anymore
-    if not CurrentTeam^.ExtDriven then FollowGear := HHGear;
-
-    if not isUnderWater and hasBorder and ((HHGear^.X < _0) or (hwRound(HHGear^.X) > LAND_WIDTH)) then HHGear^.dY.isNegative:= false;
-    if ((Gear^.State and gsttmpFlag) = 0) or (HHGear^.dY < _0) then doStepHedgehogMoving(HHGear);
+    if not CurrentTeam^.ExtDriven then
+        FollowGear := HHGear;
+
+    if not isUnderWater and hasBorder and ((HHGear^.X < _0)
+    or (hwRound(HHGear^.X) > LAND_WIDTH)) then
+        HHGear^.dY.isNegative:= false;
+        
+    if ((Gear^.State and gsttmpFlag) = 0)
+    or (HHGear^.dY < _0) then
+        doStepHedgehogMoving(HHGear);
 
     if // (Gear^.Health = 0)
         (HHGear^.Damage <> 0)
@@ -3546,22 +3683,22 @@
         // allow brief ground touches - to be fair on this, might need another counter
         or (((GameTicks and $1FF) = 0) and (not HHGear^.dY.isNegative) and (TestCollisionYwithGear(HHGear, 1) <> 0))
         or ((Gear^.Message and gmAttack) <> 0) then
-        begin
-        with HHGear^ do
             begin
-            Message := 0;
-            Active := true;
-            State := State or gstMoving
-            end;
-        DeleteGear(Gear);
-        isCursorVisible := false;
-        ApplyAmmoChanges(HHGear^.Hedgehog^);
+            with HHGear^ do
+                begin
+                Message := 0;
+                Active := true;
+                State := State or gstMoving
+                end;
+            DeleteGear(Gear);
+            isCursorVisible := false;
+            ApplyAmmoChanges(HHGear^.Hedgehog^);
         //    if Gear^.Tex <> nil then FreeTexture(Gear^.Tex);
 
 //    Gear^.Tex:= RenderStringTex(trmsg[sidFuel] + ': ' + inttostr(round(Gear^.Health / 20)) + '%', cWhiteColor, fntSmall)
 
 //AddCaption(trmsg[sidFuel]+': '+inttostr(round(Gear^.Health/20))+'%', cWhiteColor, capgrpAmmostate);
-        end
+            end
 end;
 
 procedure doStepJetpack(Gear: PGear);
@@ -3575,15 +3712,16 @@
     FollowGear := HHGear;
     AfterAttack;
     with HHGear^ do
-    begin
+        begin
         State := State and (not gstAttacking);
         Message := Message and (not (gmAttack or gmUp or gmPrecise or gmLeft or gmRight));
+        
         if (dY < _0_1) and (dY > -_0_1) then
-        begin
+            begin
             Gear^.State := Gear^.State or gsttmpFlag;
             dY := dY - _0_2
+            end
         end
-    end
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -3594,9 +3732,9 @@
     if Gear^.Timer < 2000 then
         inc(Gear^.Timer, 1)
     else
-    begin
+        begin
         DeleteGear(Gear);
-    end;
+        end;
 end;
 
 procedure doStepBirdyFly(Gear: PGear);
@@ -3618,7 +3756,7 @@
     if Gear^.Pos > 0 then
         dec(Gear^.Pos, 1)
     else if (HHGear^.Message and (gmLeft or gmRight or gmUp)) <> 0 then
-             Gear^.Pos := 500;
+            Gear^.Pos := 500;
 
     if HHGear^.dX.isNegative then
         Gear^.Tag := -1
@@ -3627,11 +3765,14 @@
 
     if (HHGear^.Message and gmUp) <> 0 then
         begin
-        if (not HHGear^.dY.isNegative) or (HHGear^.Y > -_256) then
+        if (not HHGear^.dY.isNegative)
+        or (HHGear^.Y > -_256) then
             HHGear^.dY := HHGear^.dY - move;
+            
         dec(Gear^.Health, fuel);
         Gear^.MsgParam := Gear^.MsgParam or gmUp;
         end;
+        
     if (HHGear^.Message and gmLeft) <> 0 then move.isNegative := true;
     if (HHGear^.Message and (gmLeft or gmRight)) <> 0 then
         begin
@@ -3640,7 +3781,9 @@
         Gear^.MsgParam := Gear^.MsgParam or (HHGear^.Message and (gmLeft or gmRight));
         end;
 
-    if Gear^.Health < 0 then Gear^.Health := 0;
+    if Gear^.Health < 0 then
+        Gear^.Health := 0;
+        
     if ((GameTicks and $FF) = 0) and (Gear^.Health < 500) then
         for i:= ((500-Gear^.Health) div 250) downto 0 do
             AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtFeather);
@@ -3658,6 +3801,7 @@
 
     if HHGear^.Message and (gmUp or gmPrecise or gmLeft or gmRight) <> 0 then
         Gear^.State := Gear^.State and (not gsttmpFlag);
+        
     HHGear^.Message := HHGear^.Message and (not (gmUp or gmPrecise or gmLeft or gmRight));
     HHGear^.State := HHGear^.State or gstMoving;
 
@@ -3667,34 +3811,36 @@
     // this is probably not needed anymore
     if not CurrentTeam^.ExtDriven then FollowGear := HHGear;
 
-    if ((Gear^.State and gsttmpFlag) = 0) or (HHGear^.dY < _0) then doStepHedgehogMoving(HHGear);
+    if ((Gear^.State and gsttmpFlag) = 0)
+    or (HHGear^.dY < _0) then
+        doStepHedgehogMoving(HHGear);
 
     if  (Gear^.Health = 0)
-       or (HHGear^.Damage <> 0)
-       or CheckGearDrowning(HHGear)
-       or (TurnTimeLeft = 0)
-       // allow brief ground touches - to be fair on this, might need another counter
-       or (((GameTicks and $1FF) = 0) and (not HHGear^.dY.isNegative) and (TestCollisionYwithGear(HHGear, 1) <> 0))
-       or ((Gear^.Message and gmAttack) <> 0) then
-        begin
-        with HHGear^ do
+        or (HHGear^.Damage <> 0)
+        or CheckGearDrowning(HHGear)
+        or (TurnTimeLeft = 0)
+        // allow brief ground touches - to be fair on this, might need another counter
+        or (((GameTicks and $1FF) = 0) and (not HHGear^.dY.isNegative) and (TestCollisionYwithGear(HHGear, 1) <> 0))
+        or ((Gear^.Message and gmAttack) <> 0) then
             begin
-            Message := 0;
-            Active := true;
-            State := State or gstMoving
-            end;
-        Gear^.State := Gear^.State or gstAnimation or gstTmpFlag;
-        if HHGear^.dY < _0 then
-            begin
-            Gear^.dX := HHGear^.dX;
-            Gear^.dY := HHGear^.dY;
-            end;
-        Gear^.Timer := 0;
-        Gear^.doStep := @doStepBirdyDisappear;
-        CurAmmoGear := nil;
-        isCursorVisible := false;
-        AfterAttack;
-        end
+            with HHGear^ do
+                begin
+                Message := 0;
+                Active := true;
+                State := State or gstMoving
+                end;
+            Gear^.State := Gear^.State or gstAnimation or gstTmpFlag;
+            if HHGear^.dY < _0 then
+                begin
+                Gear^.dX := HHGear^.dX;
+                Gear^.dY := HHGear^.dY;
+                end;
+            Gear^.Timer := 0;
+            Gear^.doStep := @doStepBirdyDisappear;
+            CurAmmoGear := nil;
+            isCursorVisible := false;
+            AfterAttack;
+            end
 end;
 
 procedure doStepBirdyDescend(Gear: PGear);
@@ -3705,21 +3851,21 @@
         dec(Gear^.Timer, 1)
     else if Gear^.Hedgehog^.Gear = nil then
         begin
-            DeleteGear(Gear);
-            AfterAttack;
-            exit
+        DeleteGear(Gear);
+        AfterAttack;
+        exit
         end;
     HHGear := Gear^.Hedgehog^.Gear;
     HHGear^.Message := HHGear^.Message and (not (gmUp or gmPrecise or gmLeft or gmRight));
     if abs(hwRound(HHGear^.Y - Gear^.Y)) > 32 then
-    begin
+        begin
         if Gear^.Timer = 0 then
             Gear^.Y := Gear^.Y + _0_1
-    end
+        end
     else if Gear^.Timer = 0 then
         begin
-            Gear^.doStep := @doStepBirdyFly;
-            HHGear^.dY := -_0_2
+        Gear^.doStep := @doStepBirdyFly;
+        HHGear^.dY := -_0_2
         end
 end;
 
@@ -3729,13 +3875,13 @@
     if Gear^.Timer < 2000 then
         inc(Gear^.Timer, 1)
     else
-    begin
+        begin
         Gear^.Timer := 500;
         Gear^.dX := _0;
         Gear^.dY := _0;
         Gear^.State :=  Gear^.State and (not gstAnimation);
         Gear^.doStep := @doStepBirdyDescend;
-    end
+        end
 end;
 
 procedure doStepBirdy(Gear: PGear);
@@ -3744,11 +3890,12 @@
 begin
     gear^.State :=  gear^.State or gstAnimation and (not gstTmpFlag);
     Gear^.doStep := @doStepBirdyAppear;
+    
     if CurrentHedgehog = nil then
-    begin
+        begin
         DeleteGear(Gear);
         exit
-    end;
+        end;
 
     HHGear := CurrentHedgehog^.Gear;
 
@@ -3779,43 +3926,44 @@
     CalcRotationDirAngle(Gear);
 
     if (Gear^.State and gstCollision) <> 0 then
-    begin
+        begin
         doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 10, Gear^.Hedgehog, EXPLPoisoned, $C0E0FFE0);
         PlaySound(sndEggBreak);
         AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtEgg);
         vg := AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtEgg);
-        if vg <> nil then vg^.Frame := 2;
+        if vg <> nil then
+            vg^.Frame := 2;
 
         for i:= 10 downto 0 do
-        begin
+            begin
             vg := AddVisualGear(hwRound(Gear^.X) - 3 + Random(6), hwRound(Gear^.Y) - 3 + Random(6),
                   vgtDust);
-            if vg <> nil then vg^.dX := vg^.dX + (Gear^.dX.QWordValue / 21474836480);
-        end;
+            if vg <> nil then
+                vg^.dX := vg^.dX + (Gear^.dX.QWordValue / 21474836480);
+            end;
 
         DeleteGear(Gear);
         exit
-    end;
+        end;
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
 procedure doPortalColorSwitch();
 var CurWeapon: PAmmo;
 begin
-    if (CurrentHedgehog <> nil)
-       and (CurrentHedgehog^.Gear <> nil)
-       and ((CurrentHedgehog^.Gear^.Message and gmSwitch) <> 0) then
-        with CurrentHedgehog^ do
-            if (CurAmmoType = amPortalGun) then
-            begin
-                CurrentHedgehog^.Gear^.Message := CurrentHedgehog^.Gear^.Message and (not gmSwitch);
+    if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil) and ((CurrentHedgehog^.Gear^.Message and gmSwitch) <> 0) then
+            with CurrentHedgehog^ do
+                if (CurAmmoType = amPortalGun) then
+                    begin
+                    CurrentHedgehog^.Gear^.Message := CurrentHedgehog^.Gear^.Message and (not gmSwitch);
                 
-                CurWeapon:= GetAmmoEntry(CurrentHedgehog^);
-                if CurWeapon^.Pos <> 0 then
-                    CurWeapon^.Pos := 0
-                else
+                    CurWeapon:= GetAmmoEntry(CurrentHedgehog^);
+                    if CurWeapon^.Pos <> 0 then
+                        CurWeapon^.Pos := 0
+                        
+                    else
                     CurWeapon^.Pos := 1;
-            end;
+                    end;
 end;
 
 procedure doStepPortal(Gear: PGear);
@@ -3830,16 +3978,16 @@
 
     // destroy portal if ground it was attached too is gone
     if ((Land[hwRound(Gear^.Y), hwRound(Gear^.X)] and $FF00) = 0)
-       or (Gear^.Timer < 1)
-       or (Gear^.Hedgehog^.Team <> CurrentHedgehog^.Team)
-       or (hwRound(Gear^.Y) > cWaterLine) then
-    begin
+    or (Gear^.Timer < 1)
+    or (Gear^.Hedgehog^.Team <> CurrentHedgehog^.Team)
+    or (hwRound(Gear^.Y) > cWaterLine) then
+        begin
         deleteGear(Gear);
         EXIT;
-    end;
+        end;
 
     if (TurnTimeLeft < 1)
-       or (Gear^.Health < 1) then
+    or (Gear^.Health < 1) then
         dec(Gear^.Timer);
 
     if Gear^.Timer < 10000 then
@@ -3870,8 +4018,8 @@
 
         // don't port portals or other gear that wouldn't make sense
         if (iterator^.Kind in [gtPortal, gtRope, gtRCPlane])
-            or (iterator^.PortalCounter > 32) then
-             continue;
+        or (iterator^.PortalCounter > 32) then
+            continue;
 
         // don't port hogs on rope
         // TODO: this will also prevent hogs while falling after rope use from
@@ -3886,37 +4034,36 @@
 
         // too far away?
         if (iterator^.X < Gear^.X - r)
-           or (iterator^.X > Gear^.X + r)
-           or (iterator^.Y < Gear^.Y - r)
-           or (iterator^.Y > Gear^.Y + r) then
+        or (iterator^.X > Gear^.X + r)
+        or (iterator^.Y < Gear^.Y - r)
+        or (iterator^.Y > Gear^.Y + r) then
             continue;
 
-        hasdxy := (((iterator^.dX.QWordValue <> 0) or (iterator^.dY.QWordValue <> 0))
-                    or ((iterator^.State or gstMoving) = 0));
+        hasdxy := (((iterator^.dX.QWordValue <> 0) or (iterator^.dY.QWordValue <> 0)) or ((iterator^.State or gstMoving) = 0));
 
         // in case the object is not moving, let's asume it's falling towards the portal
         if not hasdxy then
-        begin
+            begin
             if Gear^.Y < iterator^.Y then
                 continue;
             ox:= Gear^.X - iterator^.X;
             oy:= Gear^.Y - iterator^.Y;
-        end
+            end
         else
-        begin
+            begin
             ox:= iterator^.dX;
             oy:= iterator^.dY;
-        end;
+            end;
 
         // cake will need extra treatment... it's so delicious and moist!
         iscake:= (iterator^.Kind = gtCake);
 
         // won't port stuff that does not move towards the front/portal entrance
         if iscake then
-        begin
+            begin
             if not (((iterator^.X - Gear^.X)*ox + (iterator^.Y - Gear^.Y)*oy).isNegative) then
                 continue;
-        end
+            end
         else
             if not ((Gear^.dX*ox + Gear^.dY*oy).isNegative) then
                 continue;
@@ -3926,23 +4073,23 @@
         r:= int2hwFloat(iterator^.Radius);
 
         if not (isbullet or iscake) then
-        begin
+            begin
             // wow! good candidate there, let's see if the distance and direction is okay!
             if hasdxy then
-            begin
+                begin
                 s := r / Distance(iterator^.dX, iterator^.dY);
                 ox:= iterator^.X + s * iterator^.dX;
                 oy:= iterator^.Y + s * iterator^.dY;
-            end
+                end
             else
-            begin
+                begin
                 ox:= iterator^.X;
                 oy:= iterator^.Y + r;
-            end;
+                end;
 
             if (hwRound(Distance(Gear^.X-ox,Gear^.Y-oy)) > Gear^.Radius + 1 ) then
                 continue;
-        end;
+            end;
 
         // draw bullet trail
         if isbullet then
@@ -3989,22 +4136,24 @@
             continue;
 
         // avoid gravity related loops of not really moving gear
-        if not (iscake or isbullet) and (Gear^.dY.isNegative) and (conPortal^.dY.isNegative)
-            and ((iterator^.dX.QWordValue + iterator^.dY.QWordValue) < _0_08.QWordValue)
-            and (iterator^.PortalCounter > 0) then
-             continue;
+        if not (iscake or isbullet)
+        and (Gear^.dY.isNegative)
+        and (conPortal^.dY.isNegative)
+        and ((iterator^.dX.QWordValue + iterator^.dY.QWordValue) < _0_08.QWordValue)
+        and (iterator^.PortalCounter > 0) then
+            continue;
 
         // calc gear speed along to the vector and the normal vector of the portal
         if hasdxy then
-        begin
+            begin
             pspeed:= (Gear^.dX * iterator^.dX + Gear^.dY * iterator^.dY);
             nspeed:= (nx * iterator^.dX + ny * iterator^.dY);
-        end
+            end
         else
-        begin
+            begin
             pspeed:= hwAbs(cGravity * oy);
             nspeed:= _0;
-        end;
+            end;
 
         // creating normal vector of connected (exit) portal
         nx := conPortal^.dY;
@@ -4025,37 +4174,38 @@
         // make the gear's exit position close to the portal while
         // still respecting the movement direction
 
-         // determine the distance (in exit vector direction)
-         // that we want the gear at
-         if iscake then
-             ox:= (r - _0_7)
-         else
-             ox:= (r * _1_5);
-         s:= ox / poffs;
-         poffs:= ox;
-         if (nspeed.QWordValue <> 0) and (pspeed > _0) then
-             noffs:= noffs * s * (nspeed / pspeed);
+        // determine the distance (in exit vector direction)
+        // that we want the gear at
+        if iscake then
+            ox:= (r - _0_7)
+        else
+            ox:= (r * _1_5);
+        s:= ox / poffs;
+        poffs:= ox;
+        if (nspeed.QWordValue <> 0)
+        and (pspeed > _0) then
+            noffs:= noffs * s * (nspeed / pspeed);
 
         // move stuff with high normal offset closer to the portal's center
         if not isbullet then
-        begin
+            begin
             s := hwAbs(noffs) + r - int2hwFloat(Gear^.Radius);
             if s > _0 then
                 noffs:= noffs - SignAs(s,noffs)
-        end;
+            end;
 
         iterator^.X := conPortal^.X + poffs * conPortal^.dX + noffs * nx;
         iterator^.Y := conPortal^.Y + poffs * conPortal^.dY + noffs * ny;
 
         if not hasdxy and (not (conPortal^.dY.isNegative)) then
-        begin
+            begin
             iterator^.dY:= iterator^.dY + hwAbs(cGravity * (iterator^.Y - conPortal^.Y))
-        end;
+            end;
 
         // see if the space on the exit side actually is enough
 
         if not (isBullet or isCake) then
-        begin
+            begin
             // TestCollisionXwithXYShift requires a hwFloat for xShift
             ox.QWordValue := _1.QWordValue;
             ox.isNegative := not iterator^.dX.isNegative;
@@ -4071,34 +4221,35 @@
                         or TestCollisionX(iterator, sx);
 
             if not isCollision then
-            begin
+                begin
                 // check center area (with half the radius so that the
                 // the square check won't check more pixels than we want to)
                 iterator^.Radius := 1 + resetr div 2;
                 rh := resetr div 4;
                 isCollision := TestCollisionYwithXYShift(iterator,       0, -sy * rh, sy, false)
                             or TestCollisionXwithXYShift(iterator, ox * rh,        0, sx, false);
-            end;
+                end;
 
             iterator^.Radius := resetr;
 
             if isCollision then
-            begin
+                begin
                 // collision! oh crap! go back!
                 iterator^.X  := resetx;
                 iterator^.Y  := resety;
                 iterator^.dX := resetdx;
                 iterator^.dY := resetdy;
                 continue;
+                end;
             end;
-        end;
 
         //
         // You're now officially portaled!
         //
 
         // Until loops are reliably broken
-        if iscake then iterator^.PortalCounter:= 33
+        if iscake then
+            iterator^.PortalCounter:= 33
         else
             begin
             inc(iterator^.PortalCounter);
@@ -4106,36 +4257,41 @@
             end;
 
         if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil)
-           and (iterator = CurrentHedgehog^.Gear) and (CurAmmoGear <> nil) and (CurAmmoGear^.Kind =
-           gtRope) then CurAmmoGear^.PortalCounter:= 1;
-
-        if not isbullet and (iterator^.Kind <> gtFlake) then
+        and (iterator = CurrentHedgehog^.Gear)
+        and (CurAmmoGear <> nil)
+        and (CurAmmoGear^.Kind =gtRope) then
+               CurAmmoGear^.PortalCounter:= 1;
+
+        if not isbullet
+        and (iterator^.Kind <> gtFlake) then
             FollowGear := iterator;
 
         // store X/Y values of exit for net bullet trail
         if isbullet then
-        begin
+            begin
             iterator^.Elasticity:= iterator^.X;
             iterator^.Friction  := iterator^.Y;
-        end;
+            end;
 
         // This jiggles gears, to ensure a portal connection just placed under a gear takes effect.
         iterator:= GearsList;
         while iterator <> nil do
             begin
-            if (iterator^.Kind <> gtPortal) and 
-               ((iterator^.Hedgehog <> CurrentHedgehog) or ((iterator^.Message and gmAllStoppable) = 0)) then
-                begin
-                iterator^.Active:= true;
-                if iterator^.dY.QWordValue = _0.QWordValue then iterator^.dY.isNegative:= false;
-                iterator^.State:= iterator^.State or gstMoving;
-                DeleteCI(iterator);
+            if (iterator^.Kind <> gtPortal) and ((iterator^.Hedgehog <> CurrentHedgehog)
+            or ((iterator^.Message and gmAllStoppable) = 0)) then
+                    begin
+                    iterator^.Active:= true;
+                    if iterator^.dY.QWordValue = _0.QWordValue then
+                        iterator^.dY.isNegative:= false;
+                    iterator^.State:= iterator^.State or gstMoving;
+                    DeleteCI(iterator);
                 //inc(iterator^.dY.QWordValue,10);
-                end;
+                    end;
             iterator:= iterator^.NextGear
             end;
 
-        if Gear^.Health > 1 then dec(Gear^.Health);
+        if Gear^.Health > 1 then
+            dec(Gear^.Health);
     end;
 end;
 
@@ -4164,7 +4320,8 @@
                 CurWeapon^.Timer := 0;
                 end
             end;
-    if destroyGear then oldPortal^.Timer:= 0;
+    if destroyGear then
+        oldPortal^.Timer:= 0;
 end;
 
 procedure doStepMovingPortal_real(Gear: PGear);
@@ -4179,15 +4336,16 @@
     // avoid compiler hints
 
     if ((y and LAND_HEIGHT_MASK) = 0) and ((x and LAND_WIDTH_MASK) = 0) and (Land[y, x] > 255) then
-    begin
+        begin
         Gear^.State := Gear^.State or gstCollision;
         Gear^.State := Gear^.State and (not gstMoving);
+        
         if not CalcSlopeTangent(Gear, x, y, tx, ty, 255)
-           or (DistanceI(tx,ty) < _12) then // reject shots at too irregular terrain
-        begin
+        or (DistanceI(tx,ty) < _12) then // reject shots at too irregular terrain
+            begin
             loadNewPortalBall(Gear, true);
             EXIT;
-        end;
+            end;
 
         // making a normalized normal vector
         s := _1/DistanceI(tx,ty);
@@ -4195,13 +4353,12 @@
         Gear^.dY := -s * tx;
 
         Gear^.DirAngle := DxDy2Angle(-Gear^.dY,Gear^.dX);
-        if not Gear^.dX.isNegative then Gear^.DirAngle := 180-Gear^.DirAngle;
+        if not Gear^.dX.isNegative then
+            Gear^.DirAngle := 180-Gear^.DirAngle;
 
         if ((Gear^.IntersectGear = nil)
-           or (hwRound(Distance(Gear^.X - Gear^.IntersectGear^.X,Gear^.Y-Gear^.IntersectGear^.Y)) >=
-           Gear^.Radius*2))
-            then
-        begin
+        or (hwRound(Distance(Gear^.X - Gear^.IntersectGear^.X,Gear^.Y-Gear^.IntersectGear^.Y)) >=Gear^.Radius*2)) then
+            begin
             loadNewPortalBall(Gear, false);
             inc(Gear^.Tag);
             Gear^.doStep := @doStepPortal;
@@ -4209,9 +4366,12 @@
         else
             loadNewPortalBall(Gear, true);
     end
-    else if (y > cWaterLine) or (y < -LAND_WIDTH)
-            or (x > 2*LAND_WIDTH) or (x < -LAND_WIDTH) then
-             loadNewPortalBall(Gear, true);
+    
+    else if (y > cWaterLine)
+    or (y < -LAND_WIDTH)
+    or (x > 2*LAND_WIDTH)
+    or (x < -LAND_WIDTH) then
+        loadNewPortalBall(Gear, true);
 end;
 
 procedure doStepMovingPortal(Gear: PGear);
@@ -4219,8 +4379,8 @@
     doPortalColorSwitch();
     doStepPerPixel(Gear, @doStepMovingPortal_real, true);
     if (Gear^.Timer < 1) 
-       or (Gear^.Hedgehog^.Team <> CurrentHedgehog^.Team) then
-            deleteGear(Gear);
+    or (Gear^.Hedgehog^.Team <> CurrentHedgehog^.Team) then
+        deleteGear(Gear);
 end;
 
 procedure doStepPortalShot(newPortal: PGear);
@@ -4243,7 +4403,7 @@
 
     if CurrentHedgehog <> nil then
         with CurrentHedgehog^ do
-        begin
+            begin
             CurWeapon:= GetAmmoEntry(CurrentHedgehog^);
             // let's save the HH's dX's direction so we can decide where the "top" of the portal hole
             newPortal^.Elasticity.isNegative := CurrentHedgehog^.Gear^.dX.isNegative;
@@ -4260,7 +4420,7 @@
             begin
                 if (iterator^.Kind = gtPortal) then
                     if (iterator <> newPortal) and (iterator^.Timer > 0) and (iterator^.Hedgehog = CurrentHedgehog) then
-                    begin
+                        begin
                         if ((iterator^.Tag and 2) = (newPortal^.Tag and 2)) then
                             begin
                             iterator^.Timer:= 0;
@@ -4272,11 +4432,11 @@
                             iterator^.IntersectGear := newPortal;
                             iterator^.Health := newPortal^.Health;
                             end;
-                    end;
+                        end;
                 iterator^.PortalCounter:= 0;
                 iterator := iterator^.NextGear
             end;
-        end;
+            end;
     newPortal^.State := newPortal^.State and (not gstCollision);
     newPortal^.State := newPortal^.State or gstMoving;
     newPortal^.doStep := @doStepMovingPortal;
@@ -4290,19 +4450,19 @@
 begin
     AllInactive := false;
     if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil) and 
-       ((CurrentHedgehog^.Gear^.Message and gmSlot) <> 0) then
-        begin
-        case CurrentHedgehog^.Gear^.MsgParam of 
-            0: PlaySound(sndPiano0);
-            1: PlaySound(sndPiano1);
-            2: PlaySound(sndPiano2);
-            3: PlaySound(sndPiano3);
-            4: PlaySound(sndPiano4);
-            5: PlaySound(sndPiano5);
-            6: PlaySound(sndPiano6);
-            7: PlaySound(sndPiano7);
-            else PlaySound(sndPiano8);
-        end;
+        ((CurrentHedgehog^.Gear^.Message and gmSlot) <> 0) then
+            begin
+                case CurrentHedgehog^.Gear^.MsgParam of 
+                0: PlaySound(sndPiano0);
+                1: PlaySound(sndPiano1);
+                2: PlaySound(sndPiano2);
+                3: PlaySound(sndPiano3);
+                4: PlaySound(sndPiano4);
+                5: PlaySound(sndPiano5);
+                6: PlaySound(sndPiano6);
+                7: PlaySound(sndPiano7);
+                else PlaySound(sndPiano8);
+            end;
         AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtNote);
         CurrentHedgehog^.Gear^.MsgParam := 0;
         CurrentHedgehog^.Gear^.Message := CurrentHedgehog^.Gear^.Message and (not gmSlot);
@@ -4323,7 +4483,8 @@
                 CurrentHedgehog^.Gear^.X := Gear^.X;
                 CurrentHedgehog^.Gear^.Y := int2hwFloat(cWaterLine+cVisibleWater)+_128;
                 CurrentHedgehog^.Unplaced := false;
-                if TagTurnTimeLeft = 0 then TagTurnTimeLeft:= TurnTimeLeft;
+                if TagTurnTimeLeft = 0 then
+                    TagTurnTimeLeft:= TurnTimeLeft;
                 TurnTimeLeft:= 0
                 end;
             ResumeMusic
@@ -4344,7 +4505,8 @@
             CurrentHedgehog^.Gear^.X := Gear^.X;
             CurrentHedgehog^.Gear^.Y := int2hwFloat(cWaterLine+cVisibleWater)+_128;
             CurrentHedgehog^.Unplaced := false;
-            if TagTurnTimeLeft = 0 then TagTurnTimeLeft:= TurnTimeLeft;
+            if TagTurnTimeLeft = 0 then
+                TagTurnTimeLeft:= TurnTimeLeft;
             TurnTimeLeft:= 0
             end;
         ResumeMusic
@@ -4386,7 +4548,8 @@
     sdY := hwAbs(ldX) + hwAbs(ldY);
     sdX := _1 - hwAbs(ldX/sdY);
     sdY := _1 - hwAbs(ldY/sdY);
-    if (ldX.isNegative = ldY.isNegative) then sdY := -sdY;
+    if (ldX.isNegative = ldY.isNegative) then
+        sdY := -sdY;
 
     // initial angle depends on current GameTicks
     t := GameTicks mod 4096;
@@ -4417,35 +4580,35 @@
 
         // if borders are on, stop outside land array
         if hasBorder and (((x and LAND_WIDTH_MASK) <> 0) or ((y and LAND_HEIGHT_MASK) <> 0)) then
-        begin
+            begin
             Gear^.Damage := 0;
             Gear^.Health := 0;
-        end
+            end
         else
-        begin
+            begin
             if (rY <= cWaterLine) or (y <= cWaterLine) then
-            begin
-                if ((y and LAND_HEIGHT_MASK) = 0) and ((x and LAND_WIDTH_MASK) = 0)
-                   and (Land[y, x] <> 0) then
                 begin
-                    if justCollided then
-                    begin
-                        Gear^.Damage := 0;
-                        Gear^.Health := 0;
-                    end
-                    else
-                    begin
-                        inc(Gear^.Damage,3);
-                        justCollided := true;
-                    end;
-                end
+                if ((y and LAND_HEIGHT_MASK) = 0) and ((x and LAND_WIDTH_MASK) = 0)
+                    and (Land[y, x] <> 0) then
+                        begin
+                            if justCollided then
+                                begin
+                                Gear^.Damage := 0;
+                                Gear^.Health := 0;
+                                end
+                            else
+                                begin
+                                inc(Gear^.Damage,3);
+                                justCollided := true;
+                                end;
+                        end
                 else
                     justCollided := false;
 
                 // kick nearby hogs, dig tunnel and add some fire
                 // if at least 5 collisions occured
                 if Gear^.Damage > 0 then
-                begin
+                    begin
                     DrawExplosion(rX,rY,Gear^.Radius);
 
                     // kick nearby hogs
@@ -4458,25 +4621,36 @@
                     if getRandom(6) = 0 then
                         AddGear(x - Gear^.Radius + LongInt(getRandom(2 * Gear^.Radius)), y -
                         getRandom(Gear^.Radius + 1), gtFlame, gsttmpFlag, _0, _0, 0);
-                end;
+                    end;
 
                 if getRandom(100) = 0 then
                     AddVisualGear(x, y, vgtSmokeTrace); 
-            end
-            else dec(Gear^.Health, 5); // if underwater get additional damage
-        end;
+                end
+                else dec(Gear^.Health, 5); // if underwater get additional damage
+            end;
 
         dec(Gear^.Health);
 
         // decrease bullet size towards the end
-        if (Gear^.Radius > 4) then begin
-            if (Gear^.Health <= (initHealth div 3)) then dec(Gear^.Radius) end
-        else if (Gear^.Radius > 3) then begin
-            if (Gear^.Health <= (initHealth div 4)) then dec(Gear^.Radius) end
+        if (Gear^.Radius > 4) then
+            begin
+            if (Gear^.Health <= (initHealth div 3)) then
+                dec(Gear^.Radius)
+            end
+        else if (Gear^.Radius > 3) then
+            begin
+            if (Gear^.Health <= (initHealth div 4)) then
+                dec(Gear^.Radius)
+            end
         else if (Gear^.Radius > 2) then begin
-            if (Gear^.Health <= (initHealth div 5)) then dec(Gear^.Radius) end
-        else if (Gear^.Radius > 1) then begin
-            if (Gear^.Health <= (initHealth div 6)) then dec(Gear^.Radius) end;
+            if (Gear^.Health <= (initHealth div 5)) then
+                dec(Gear^.Radius)
+            end
+        else if (Gear^.Radius > 1) then
+            begin
+            if (Gear^.Health <= (initHealth div 6)) then
+                dec(Gear^.Radius)
+            end;
 
     until (Gear^.Health <= 0);
 
@@ -4521,13 +4695,17 @@
         begin
         if (HHGear^.Message and gmRight) <> 0 then
             begin
-            if HHGear^.dX.isNegative and (Gear^.Tag < 20) then inc(Gear^.Tag)
-            else if Gear^.Tag > 5 then dec(Gear^.Tag);
+            if HHGear^.dX.isNegative and (Gear^.Tag < 20) then
+                inc(Gear^.Tag)
+            else if Gear^.Tag > 5 then
+                dec(Gear^.Tag);
             end
         else if (HHGear^.Message and gmLeft) <> 0 then
             begin
-            if HHGear^.dX.isNegative and (Gear^.Tag > 5) then dec(Gear^.Tag)
-            else if Gear^.Tag < 20 then inc(Gear^.Tag);
+            if HHGear^.dX.isNegative and (Gear^.Tag > 5) then
+                dec(Gear^.Tag)
+            else if Gear^.Tag < 20 then 
+                inc(Gear^.Tag);
             end
         end;
     
@@ -4598,13 +4776,17 @@
         begin
         if (HHGear^.Message and gmRight) <> 0 then
             begin
-            if HHGear^.dX.isNegative and (Gear^.Tag < 20) then inc(Gear^.Tag)
-            else if Gear^.Tag > 5 then dec(Gear^.Tag);
+            if HHGear^.dX.isNegative and (Gear^.Tag < 20) then
+                inc(Gear^.Tag)
+            else if Gear^.Tag > 5 then
+                dec(Gear^.Tag);
             end
         else if (HHGear^.Message and gmLeft) <> 0 then
             begin
-            if HHGear^.dX.isNegative and (Gear^.Tag > 5) then dec(Gear^.Tag)
-            else if Gear^.Tag < 20 then inc(Gear^.Tag);
+            if HHGear^.dX.isNegative and (Gear^.Tag > 5) then
+                dec(Gear^.Tag)
+            else if Gear^.Tag < 20 then
+                inc(Gear^.Tag);
             end
         end;
     
@@ -4657,10 +4839,10 @@
 procedure doStepPoisonCloud(Gear: PGear);
 begin
     if Gear^.Timer = 0 then
-    begin
+        begin
         DeleteGear(Gear);
         exit
-    end;
+        end;
     dec(Gear^.Timer);
     Gear^.X:= Gear^.X + Gear^.dX;
     Gear^.Y:= Gear^.Y + Gear^.dY;
@@ -4695,7 +4877,8 @@
         if (tmp^.Kind = gtHedgehog) or (tmp^.Kind = gtMine) or (tmp^.Kind = gtExplosives) then
             begin
             //tmp^.State:= tmp^.State or gstFlatened;
-            if not tmp^.Invulnerable then ApplyDamage(tmp, CurrentHedgehog, tmp^.Health div 3, dsUnknown);
+            if not tmp^.Invulnerable then
+                ApplyDamage(tmp, CurrentHedgehog, tmp^.Health div 3, dsUnknown);
             //DrawTunnel(tmp^.X, tmp^.Y - _1, _0, _0_5, cHHRadius * 6, cHHRadius * 3);
             tmp2:= AddGear(hwRound(tmp^.X), hwRound(tmp^.Y), gtHammerHit, 0, _0, _0, 0);
             tmp2^.IntersectGear:= tmp;
@@ -4756,7 +4939,8 @@
         begin
         Gear^.dY := Gear^.dY + cGravity;
         Gear^.Y := Gear^.Y + Gear^.dY;
-        if hwRound(Gear^.Y) > cWaterLine then Gear^.Timer := 1
+        if hwRound(Gear^.Y) > cWaterLine then
+            Gear^.Timer := 1
         end;
 
     Gear^.X := Gear^.X + HitGear^.dX;
@@ -4776,12 +4960,12 @@
 
     y := hwRound(Gear^.Y) - cHHRadius * 2;
     while y < hwRound(Gear^.Y) do
-    begin
+        begin
         ar[i].Left := hwRound(Gear^.X) - Gear^.Radius - LongInt(GetRandom(2));
         ar[i].Right := hwRound(Gear^.X) + Gear^.Radius + LongInt(GetRandom(2));
         inc(y, 2);
         inc(i)
-    end;
+        end;
 
     DrawHLinesExplosions(@ar, 3, hwRound(Gear^.Y) - cHHRadius * 2, 2, Pred(i));
     Gear^.dY := HHGear^.dY;
@@ -4814,14 +4998,17 @@
 
     if ((Gear^.Message and gmUp) <> 0) then
         begin
-        if (GameTicks and $F) <> 0 then exit;
+        if (GameTicks and $F) <> 0 then
+        exit;
         end 
-    else if (GameTicks and $1FF) <> 0 then exit;
+    else if (GameTicks and $1FF) <> 0 then
+        exit;
 
     if Gear^.Power < 45 then
         begin
         inc(Gear^.Power);
-        if TestCollisionYwithGear(hh^.Gear, -1) = 0 then hh^.Gear^.Y := hh^.Gear^.Y - _1;
+        if TestCollisionYwithGear(hh^.Gear, -1) = 0 then
+            hh^.Gear^.Y := hh^.Gear^.Y - _1;
         end;
 
     graves := GearsNear(Gear^.X, Gear^.Y, gtGrave, Gear^.Radius);
@@ -4856,8 +5043,7 @@
         for i:= 0 to High(graves) do
             if graves[i]^.Health > 0 then
                 begin
-                resgear := AddGear(hwRound(graves[i]^.X), hwRound(graves[i]^.Y),
-                        gtHedgehog, gstWait, _0, _0, 0);
+                resgear := AddGear(hwRound(graves[i]^.X), hwRound(graves[i]^.Y), gtHedgehog, gstWait, _0, _0, 0);
                 resgear^.Hedgehog := graves[i]^.Hedgehog;
                 resgear^.Health := graves[i]^.Health;
                 PHedgehog(graves[i]^.Hedgehog)^.Gear := resgear;
@@ -4866,6 +5052,7 @@
                 RecountTeamHealth(resgear^.Hedgehog^.Team);
                 resgear^.Hedgehog^.Effects[heResurrected]:= true;
                 // only make hat-less hedgehogs look like zombies, preserve existing hats
+                
                 if resgear^.Hedgehog^.Hat = 'NoHat' then
                     LoadHedgehogHat(resgear, 'Reserved/Zombie');
                 end;
@@ -4931,13 +5118,13 @@
         exit
     end;
     if (Gear^.Timer = 0) then
-    begin
+        begin
         doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 10, Gear^.Hedgehog, EXPLAutoSound);
         for i:= -19 to 19 do
            FollowGear := AddGear(hwRound(Gear^.X) + i div 3, hwRound(Gear^.Y), gtFlame, 0, _0_001 * i, _0, 0);
         DeleteGear(Gear);
         exit
-    end;
+        end;
     if (GameTicks and $3F) = 0 then
         AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtSmokeTrace);
     dec(Gear^.Timer)
@@ -4967,8 +5154,10 @@
         begin
         AddGearCI(Gear);
         AfterAttack;
-        if Gear = CurAmmoGear then CurAmmoGear:= nil;
-        if HH^.Gear <> nil then HideHog(HH);
+        if Gear = CurAmmoGear then
+            CurAmmoGear:= nil;
+        if HH^.Gear <> nil then
+            HideHog(HH);
         Gear^.Pos:= 2
         end;
         
@@ -4984,7 +5173,8 @@
                 end;
             inc(Gear^.Timer);
             end;
-        if Gear^.Tag <= TotalRounds then Gear^.Pos:= 3;
+        if Gear^.Tag <= TotalRounds then
+            Gear^.Pos:= 3;
         end;
         
     if Gear^.Pos = 3 then
@@ -5000,7 +5190,8 @@
             end
         else
             begin
-            if HH^.GearHidden <> nil then RestoreHog(HH);
+            if HH^.GearHidden <> nil then
+                RestoreHog(HH);
             Gear^.Pos:= 4;
             end;
         
@@ -5018,7 +5209,8 @@
         
     if Gear^.Health <= 0 then
         begin
-        if HH^.GearHidden <> nil then RestoreHog(HH);
+        if HH^.GearHidden <> nil then
+            RestoreHog(HH);
         
         x := hwRound(Gear^.X);
         y := hwRound(Gear^.Y);
@@ -5079,18 +5271,20 @@
     begin
     inc(Gear^.Power);
     if (Gear^.Power = 172) and (HH^.Gear <> nil) and 
-       (HH^.Gear^.Damage = 0) and (HH^.Gear^.Health > 0) and
-       ((HH^.Gear^.State and (gstMoving or gstHHDeath or gstHHGone)) = 0) then
-        with HH^.Gear^ do
-            begin
-            State:= State or gstAnimation;
-            Tag:= 2;
-            Timer:= 0;
-            Pos:= 0
-            end
+        (HH^.Gear^.Damage = 0) and (HH^.Gear^.Health > 0) and
+        ((HH^.Gear^.State and (gstMoving or gstHHDeath or gstHHGone)) = 0) then
+            with HH^.Gear^ do
+                begin
+                State:= State or gstAnimation;
+                Tag:= 2;
+                Timer:= 0;
+                Pos:= 0
+                end
     end;
-if (Gear^.Pos = 3) and (GameTicks and $1F = 0) and (Gear^.Power > 0) then dec(Gear^.Power);
-if (Gear^.Pos = 1) and (Gear^.Power = 255) and ((GameTicks mod 2000) = 1000) then Gear^.Pos:= 2;
+if (Gear^.Pos = 3) and (GameTicks and $1F = 0) and (Gear^.Power > 0) then
+    dec(Gear^.Power);
+if (Gear^.Pos = 1) and (Gear^.Power = 255) and ((GameTicks mod 2000) = 1000) then
+    Gear^.Pos:= 2;
 if (Gear^.Pos = 3) and (Gear^.Power = 0) then
     begin
     StopSound(Gear^.SoundChannel);
@@ -5109,17 +5303,21 @@
     cnt:= 0;
     for j:= 0 to Pred(HH^.Team^.Clan^.TeamsNumber) do
         for i:= 0 to Pred(HH^.Team^.Clan^.Teams[j]^.HedgehogsNumber) do
-            if (HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear <> nil) and
-               ((HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.State and gstDrowning) = 0) and
-               (HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.Health >
-                HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.Damage) then inc(cnt);
+            if (HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear <> nil)
+            and ((HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.State and gstDrowning) = 0)
+            and (HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.Health > HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.Damage) then
+                inc(cnt);
+                
     if (cnt = 0) or SuddenDeathDmg or (Gear^.Timer = 0) then
         begin
         Gear^.SoundChannel := LoopSound(sndTardis);
         Gear^.Pos:= 1;
         Gear^.Power:= 0;
         Gear^.Timer:= 0;
-        if HH^.GearHidden <> nil then FindPlace(HH^.GearHidden, false, 0, LAND_WIDTH,true);
+        
+        if HH^.GearHidden <> nil then
+            FindPlace(HH^.GearHidden, false, 0, LAND_WIDTH,true);
+            
         if HH^.GearHidden <> nil then
             begin
             Gear^.X:= HH^.GearHidden^.X;
@@ -5160,10 +5358,10 @@
     cnt:= 0;
     for j:= 0 to Pred(HH^.Team^.Clan^.TeamsNumber) do
         for i:= 0 to Pred(HH^.Team^.Clan^.Teams[j]^.HedgehogsNumber) do
-            if (HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear <> nil) and
-               ((HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.State and gstDrowning) = 0) and
-               (HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.Health >
-                HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.Damage) then inc(cnt);
+            if (HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear <> nil)
+            and ((HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.State and gstDrowning) = 0)
+            and (HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.Health > HH^.Team^.Clan^.Teams[j]^.Hedgehogs[i].Gear^.Damage) then
+                inc(cnt);
     if cnt < 2 then
         begin
         if HH^.Gear <> nil then
--- a/hedgewars/LuaPas.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/LuaPas.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -15,12 +15,12 @@
 {$INCLUDE "config.inc"}
 
 type
-  size_t   = Cardinal;
-  Psize_t  = ^size_t;
-  PPointer = ^Pointer;
+    size_t   = Cardinal;
+    Psize_t  = ^size_t;
+    PPointer = ^Pointer;
 
-  lua_State = record end;
-  Plua_State = ^lua_State;
+    lua_State = record end;
+    Plua_State = ^lua_State;
 
 const
     LuaLibName = cLuaLibrary;
@@ -45,8 +45,8 @@
 ** ===================================================================
 *)
 type
-  LUA_NUMBER_  = Double;            // ending underscore is needed in Pascal
-  LUA_INTEGER_ = PtrInt;
+    LUA_NUMBER_  = Double;            // ending underscore is needed in Pascal
+    LUA_INTEGER_ = PtrInt;
 
 (*
 @@ LUA_IDSIZE gives the maximum size for the description of the source
@@ -54,13 +54,13 @@
 ** CHANGE it if you want a different size.
 *)
 const
-  LUA_IDSIZE = 60;
+    LUA_IDSIZE = 60;
 
 (*
 @@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
 *)
 const
-  LUAL_BUFFERSIZE = 1024;
+    LUAL_BUFFERSIZE = 1024;
 
 (*
 @@ LUA_PROMPT is the default prompt used by stand-alone Lua.
@@ -69,8 +69,8 @@
 ** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.)
 *)
 const
-  LUA_PROMPT  = '> ';
-  LUA_PROMPT2 = '>> ';
+    LUA_PROMPT  = '> ';
+    LUA_PROMPT2 = '>> ';
 
 (*
 @@ lua_readline defines how to show a prompt and then read a line from
@@ -80,8 +80,11 @@
 ** CHANGE them if you want to improve this functionality (e.g., by using
 ** GNU readline and history facilities).
 *)
-function  lua_readline(L : Plua_State; var b : PChar; p : PChar): Boolean;
+function  lua_readline(L : Plua_State;
+var b : PChar; p : PChar): Boolean;
+
 procedure lua_saveline(L : Plua_State; idx : LongInt);
+
 procedure lua_freeline(L : Plua_State; b : PChar);
 
 (*
@@ -95,7 +98,7 @@
 #define lua_stdin_is_tty()  _isatty(_fileno(stdin))
 *)
 const
-  lua_stdin_is_tty = TRUE;
+    lua_stdin_is_tty = TRUE;
 
 (*****************************************************************************)
 (*                                  lua.h                                    *)
@@ -109,283 +112,329 @@
 *)
 
 const
-  LUA_VERSION     = 'Lua 5.1';
-  LUA_VERSION_NUM = 501;
-  LUA_COPYRIGHT   = 'Copyright (C) 1994-2006 Tecgraf, PUC-Rio';
-  LUA_AUTHORS     = 'R. Ierusalimschy, L. H. de Figueiredo & W. Celes';
+    LUA_VERSION     = 'Lua 5.1';
+    LUA_VERSION_NUM = 501;
+    LUA_COPYRIGHT   = 'Copyright (C) 1994-2006 Tecgraf, PUC-Rio';
+    LUA_AUTHORS     = 'R. Ierusalimschy, L. H. de Figueiredo & W. Celes';
 
-  (* mark for precompiled code (`<esc>Lua') *)
-  LUA_SIGNATURE = #27 + 'Lua';
+    (* mark for precompiled code (`<esc>Lua') *)
+    LUA_SIGNATURE = #27 + 'Lua';
 
-  (* option for multiple returns in `lua_pcall' and `lua_call' *)
-  LUA_MULTRET = -1;
+    (* option for multiple returns in `lua_pcall' and `lua_call' *)
+    LUA_MULTRET = -1;
 
-  (*
-  ** pseudo-indices
-  *)
-  LUA_REGISTRYINDEX = -10000;
-  LUA_ENVIRONINDEX  = -10001;
-  LUA_GLOBALSINDEX  = -10002;
+    (*
+    ** pseudo-indices
+    *)
+    LUA_REGISTRYINDEX = -10000;
+    LUA_ENVIRONINDEX  = -10001;
+    LUA_GLOBALSINDEX  = -10002;
 
 function lua_upvalueindex(idx : LongInt) : LongInt;   // a marco
 
 const
-  (* thread status; 0 is OK *)
-  LUA_YIELD_    = 1;     // Note: the ending underscore is needed in Pascal
-  LUA_ERRRUN    = 2;
-  LUA_ERRSYNTAX = 3;
-  LUA_ERRMEM    = 4;
-  LUA_ERRERR    = 5;
+   (* thread status; 0 is OK *)
+    LUA_YIELD_    = 1;     // Note: the ending underscore is needed in Pascal
+    LUA_ERRRUN    = 2;
+    LUA_ERRSYNTAX = 3;
+    LUA_ERRMEM    = 4;
+    LUA_ERRERR    = 5;
 
 type
-  lua_CFunction = function(L : Plua_State) : LongInt; cdecl;
+   lua_CFunction = function(L : Plua_State) : LongInt; cdecl;
 
-  (*
-  ** functions that read/write blocks when loading/dumping Lua chunks
-  *)
-  lua_Reader = function (L : Plua_State; ud : Pointer;
-                         sz : Psize_t) : PChar; cdecl;
-  lua_Writer = function (L : Plua_State; const p : Pointer; sz : size_t;
-                         ud : Pointer) : LongInt; cdecl;
+    (*
+    ** functions that read/write blocks when loading/dumping Lua chunks
+    *)
+    lua_Reader = function (L : Plua_State; ud : Pointer; sz : Psize_t) : PChar; cdecl;
+    lua_Writer = function (L : Plua_State; const p : Pointer; sz : size_t; ud : Pointer) : LongInt; cdecl;
 
   (*
   ** prototype for memory-allocation functions
   *)
-  lua_Alloc = function (ud, ptr : Pointer;
-                        osize, nsize : size_t) : Pointer; cdecl;
+  lua_Alloc = function (ud, ptr : Pointer; osize, nsize : size_t) : Pointer; cdecl;
 
 const
-  (*
-  ** basic types
-  *)
-  LUA_TNONE          = -1;
+    (*
+    ** basic types
+    *)
+    LUA_TNONE          = -1;
+    LUA_TNIL           = 0;
+    LUA_TBOOLEAN       = 1;
+    LUA_TLIGHTUSERDATA = 2;
+    LUA_TNUMBER        = 3;
+    LUA_TSTRING        = 4;
+    LUA_TTABLE         = 5;
+    LUA_TFUNCTION      = 6;
+    LUA_TUSERDATA      = 7;
+    LUA_TTHREAD        = 8;
 
-  LUA_TNIL           = 0;
-  LUA_TBOOLEAN       = 1;
-  LUA_TLIGHTUSERDATA = 2;
-  LUA_TNUMBER        = 3;
-  LUA_TSTRING        = 4;
-  LUA_TTABLE         = 5;
-  LUA_TFUNCTION      = 6;
-  LUA_TUSERDATA      = 7;
-  LUA_TTHREAD        = 8;
-
-  (* minimum Lua stack available to a C function *)
-  LUA_MINSTACK = 20;
+    (* minimum Lua stack available to a C function *)
+    LUA_MINSTACK = 20;
 
 type
-  (* type of numbers in Lua *)
-  lua_Number = LUA_NUMBER_;
+    (* type of numbers in Lua *)
+    lua_Number = LUA_NUMBER_;
 
-  (* type for integer functions *)
-  lua_Integer = LUA_INTEGER_;
+    (* type for integer functions *)
+    lua_Integer = LUA_INTEGER_;
 
 (*
 ** state manipulation
 *)
 function  lua_newstate(f : lua_Alloc; ud : Pointer) : Plua_State;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 procedure lua_close(L: Plua_State);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 function  lua_newthread(L : Plua_State) : Plua_State;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
 function  lua_atpanic(L : Plua_State; panicf : lua_CFunction) : lua_CFunction;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
 
 (*
 ** basic stack manipulation
 *)
 function  lua_gettop(L : Plua_State) : LongInt;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 procedure lua_settop(L : Plua_State; idx : LongInt);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 procedure lua_pushvalue(L : Plua_State; idx : LongInt);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 procedure lua_remove(L : Plua_State; idx : LongInt);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 procedure lua_insert(L : Plua_State; idx : LongInt);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 procedure lua_replace(L : Plua_State; idx : LongInt);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 function  lua_checkstack(L : Plua_State; sz : LongInt) : LongBool;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
 procedure lua_xmove(src, dest : Plua_State; n : LongInt);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
 
 (*
 ** access functions (stack -> C)
 *)
 function lua_isnumber(L : Plua_State; idx : LongInt) : LongBool;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 function lua_isstring(L : Plua_State; idx : LongInt) : LongBool;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 function lua_iscfunction(L : Plua_State; idx : LongInt) : LongBool;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 function lua_isuserdata(L : Plua_State; idx : LongInt) : LongBool;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 function lua_type(L : Plua_State; idx : LongInt) : LongInt;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 function lua_typename(L : Plua_State; tp : LongInt) : PChar;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
+    
 function lua_equal(L : Plua_State; idx1, idx2 : LongInt) : LongBool;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 function lua_rawequal(L : Plua_State; idx1, idx2 : LongInt) : LongBool;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 function lua_lessthan(L : Plua_State; idx1, idx2 : LongInt) : LongBool;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
 function lua_tonumber(L : Plua_State; idx : LongInt) : lua_Number;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 function lua_tointeger(L : Plua_State; idx : LongInt) : lua_Integer;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 function lua_toboolean(L : Plua_State; idx : LongInt) : LongBool;
-  cdecl; external LuaLibName;
-function lua_tolstring(L : Plua_State; idx : LongInt;
-                       len : Psize_t) : PChar;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
+    
+function lua_tolstring(L : Plua_State; idx : LongInt; len : Psize_t) : PChar;
+    cdecl; external LuaLibName;
+    
 function lua_objlen(L : Plua_State; idx : LongInt) : size_t;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 function lua_tocfunction(L : Plua_State; idx : LongInt) : lua_CFunction;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 function lua_touserdata(L : Plua_State; idx : LongInt) : Pointer;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 function lua_tothread(L : Plua_State; idx : LongInt) : Plua_State;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 function lua_topointer(L : Plua_State; idx : LongInt) : Pointer;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
 
 (*
 ** push functions (C -> stack)
 *)
 procedure lua_pushnil(L : Plua_State);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 procedure lua_pushnumber(L : Plua_State; n : lua_Number);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 procedure lua_pushinteger(L : Plua_State; n : lua_Integer);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 procedure lua_pushlstring(L : Plua_State; const s : PChar; ls : size_t);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 procedure lua_pushstring(L : Plua_State; const s : PChar);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
+    
 function  lua_pushvfstring(L : Plua_State;
-                           const fmt : PChar; argp : Pointer) : PChar;
-  cdecl; external LuaLibName;
+    const fmt : PChar; argp : Pointer) : PChar;
+    cdecl; external LuaLibName;
+    
 function  lua_pushfstring(L : Plua_State; const fmt : PChar) : PChar; varargs;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 procedure lua_pushcclosure(L : Plua_State; fn : lua_CFunction; n : LongInt);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 procedure lua_pushboolean(L : Plua_State; b : LongBool);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 procedure lua_pushlightuserdata(L : Plua_State; p : Pointer);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 function  lua_pushthread(L : Plua_state) : Cardinal;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
 
 (*
 ** get functions (Lua -> stack)
 *)
 procedure lua_gettable(L : Plua_State ; idx : LongInt);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 procedure lua_getfield(L : Plua_State; idx : LongInt; k : PChar);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 procedure lua_rawget(L : Plua_State; idx : LongInt);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 procedure lua_rawgeti(L : Plua_State; idx, n : LongInt);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 procedure lua_createtable(L : Plua_State; narr, nrec : LongInt);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 function  lua_newuserdata(L : Plua_State; sz : size_t) : Pointer;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 function  lua_getmetatable(L : Plua_State; objindex : LongInt) : LongBool;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 procedure lua_getfenv(L : Plua_State; idx : LongInt);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
 
 (*
 ** set functions (stack -> Lua)
 *)
 procedure lua_settable(L : Plua_State; idx : LongInt);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 procedure lua_setfield(L : Plua_State; idx : LongInt; const k : PChar);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 procedure lua_rawset(L : Plua_State; idx : LongInt);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 procedure lua_rawseti(L : Plua_State; idx , n: LongInt);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 function lua_setmetatable(L : Plua_State; objindex : LongInt): LongBool;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 function lua_setfenv(L : Plua_State; idx : LongInt): LongBool;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
 (*
 ** `load' and `call' functions (load and run Lua code)
 *)
 procedure lua_call(L : Plua_State; nargs, nresults : LongInt);
-  cdecl; external LuaLibName;
-function  lua_pcall(L : Plua_State;
-                    nargs, nresults, errfunc : LongInt) : LongInt;
-  cdecl; external LuaLibName;
-function  lua_cpcall(L : Plua_State;
-                     func : lua_CFunction; ud : Pointer) : LongInt;
-  cdecl; external LuaLibName;
-function  lua_load(L : Plua_State; reader : lua_Reader;
-                   dt : Pointer; const chunkname : PChar) : LongInt;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
+function  lua_pcall(L : Plua_State; nargs, nresults, errfunc : LongInt) : LongInt;
+    cdecl; external LuaLibName;
+    
+function  lua_cpcall(L : Plua_State; func : lua_CFunction; ud : Pointer) : LongInt;
+    cdecl; external LuaLibName;
+    
+function  lua_load(L : Plua_State; reader : lua_Reader; dt : Pointer; const chunkname : PChar) : LongInt;
+    cdecl; external LuaLibName;
+    
 
 function lua_dump(L : Plua_State; writer : lua_Writer; data: Pointer) : LongInt;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
 
 (*
 ** coroutine functions
 *)
 function lua_yield(L : Plua_State; nresults : LongInt) : LongInt;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 function lua_resume(L : Plua_State; narg : LongInt) : LongInt;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 function lua_status(L : Plua_State) : LongInt;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
 (*
 ** garbage-collection functions and options
 *)
 const
-  LUA_GCSTOP       = 0;
-  LUA_GCRESTART    = 1;
-  LUA_GCCOLLECT    = 2;
-  LUA_GCCOUNT      = 3;
-  LUA_GCCOUNTB     = 4;
-  LUA_GCSTEP       = 5;
-  LUA_GCSETPAUSE   = 6;
-  LUA_GCSETSTEPMUL = 7;
+    LUA_GCSTOP       = 0;
+    LUA_GCRESTART    = 1;
+    LUA_GCCOLLECT    = 2;
+    LUA_GCCOUNT      = 3;
+    LUA_GCCOUNTB     = 4;
+    LUA_GCSTEP       = 5;
+    LUA_GCSETPAUSE   = 6;
+    LUA_GCSETSTEPMUL = 7;
 
 function lua_gc(L : Plua_State; what, data : LongInt) : LongInt;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
 (*
 ** miscellaneous functions
 *)
 function lua_error(L : Plua_State) : LongInt;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
 function lua_next(L : Plua_State; idx : LongInt) : LongInt;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
 procedure lua_concat(L : Plua_State; n : LongInt);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
 function  lua_getallocf(L : Plua_State; ud : PPointer) : lua_Alloc;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 procedure lua_setallocf(L : Plua_State; f : lua_Alloc; ud : Pointer);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
 (*
 ** ===============================================================
@@ -429,8 +478,8 @@
 function lua_getgccount(L : Plua_State) : LongInt;
 
 type
-  lua_Chuckreader = lua_Reader;
-  lua_Chuckwriter = lua_Writer;
+    lua_Chuckreader = lua_Reader;
+    lua_Chuckwriter = lua_Writer;
 
 (* ====================================================================== *)
 
@@ -444,23 +493,23 @@
 ** Event codes
 *)
 const
-  LUA_HOOKCALL    = 0;
-  LUA_HOOKRET     = 1;
-  LUA_HOOKLINE    = 2;
-  LUA_HOOKCOUNT   = 3;
-  LUA_HOOKTAILRET = 4;
+    LUA_HOOKCALL    = 0;
+    LUA_HOOKRET     = 1;
+    LUA_HOOKLINE    = 2;
+    LUA_HOOKCOUNT   = 3;
+    LUA_HOOKTAILRET = 4;
 
 
 (*
 ** Event masks
 *)
-  LUA_MASKCALL  = 1 shl LUA_HOOKCALL;
-  LUA_MASKRET   = 1 shl LUA_HOOKRET;
-  LUA_MASKLINE  = 1 shl LUA_HOOKLINE;
-  LUA_MASKCOUNT = 1 shl LUA_HOOKCOUNT;
+    LUA_MASKCALL  = 1 shl LUA_HOOKCALL;
+    LUA_MASKRET   = 1 shl LUA_HOOKRET;
+    LUA_MASKLINE  = 1 shl LUA_HOOKLINE;
+    LUA_MASKCOUNT = 1 shl LUA_HOOKCOUNT;
 
 type
-  lua_Debug = packed record
+    lua_Debug = packed record
     event : LongInt;
     name : PChar;          (* (n) *)
     namewhat : PChar;      (* (n) `global', `local', `field', `method' *)
@@ -472,42 +521,44 @@
     short_src : array [0..LUA_IDSIZE-1] of Char; (* (S) *)
     (* private part *)
     i_ci : LongInt;        (* active function *)
-  end;
-  Plua_Debug = ^lua_Debug;
+    end;
+    Plua_Debug = ^lua_Debug;
 
   (* Functions to be called by the debuger in specific events *)
   lua_Hook = procedure (L : Plua_State; ar : Plua_Debug); cdecl;
 
 
-function lua_getstack(L : Plua_State; level : LongInt;
-                      ar : Plua_Debug) : LongInt;
-  cdecl; external LuaLibName;
-function lua_getinfo(L : Plua_State; const what : PChar;
-                     ar: Plua_Debug): LongInt;
-  cdecl; external LuaLibName;
-function lua_getlocal(L : Plua_State;
-                      ar : Plua_Debug; n : LongInt) : PChar;
-  cdecl; external LuaLibName;
-function lua_setlocal(L : Plua_State;
-                      ar : Plua_Debug; n : LongInt) : PChar;
-  cdecl; external LuaLibName;
+function lua_getstack(L : Plua_State; level : LongInt; ar : Plua_Debug) : LongInt;
+    cdecl; external LuaLibName;
+    
+function lua_getinfo(L : Plua_State; const what : PChar; ar: Plua_Debug): LongInt;
+    cdecl; external LuaLibName;
+    
+function lua_getlocal(L : Plua_State; ar : Plua_Debug; n : LongInt) : PChar;
+    cdecl; external LuaLibName;
+    
+function lua_setlocal(L : Plua_State; ar : Plua_Debug; n : LongInt) : PChar;
+    cdecl; external LuaLibName;
+    
 function lua_getupvalue(L : Plua_State; funcindex, n : LongInt) : PChar;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 function lua_setupvalue(L : Plua_State; funcindex, n : LongInt) : PChar;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
-function lua_sethook(L : Plua_State; func : lua_Hook;
-                     mask, count: LongInt): LongInt;
-  cdecl; external LuaLibName;
+function lua_sethook(L : Plua_State; func : lua_Hook; mask, count: LongInt): LongInt;
+    cdecl; external LuaLibName;
+  
 {$IFDEF LUA_GETHOOK}
 function lua_gethook(L : Plua_State) : lua_Hook;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 {$ENDIF}
 
 function lua_gethookmask(L : Plua_State) : LongInt;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+    
 function lua_gethookcount(L : Plua_State) : LongInt;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
 
 (*****************************************************************************)
@@ -521,44 +572,44 @@
 *)
 
 const
-  (* Key to file-handle type *)
-  LUA_FILEHANDLE  = 'FILE*';
+    (* Key to file-handle type *)
+    LUA_FILEHANDLE  = 'FILE*';
 
-  LUA_COLIBNAME   = 'coroutine';
-  LUA_TABLIBNAME  = 'table';
-  LUA_IOLIBNAME   = 'io';
-  LUA_OSLIBNAME   = 'os';
-  LUA_STRLIBNAME  = 'string';
-  LUA_MATHLIBNAME = 'math';
-  LUA_DBLIBNAME   = 'debug';
-  LUA_LOADLIBNAME = 'package';
+    LUA_COLIBNAME   = 'coroutine';
+    LUA_TABLIBNAME  = 'table';
+    LUA_IOLIBNAME   = 'io';
+    LUA_OSLIBNAME   = 'os';
+    LUA_STRLIBNAME  = 'string';
+    LUA_MATHLIBNAME = 'math';
+    LUA_DBLIBNAME   = 'debug';
+    LUA_LOADLIBNAME = 'package';
 
 function luaopen_base(L : Plua_State) : LongInt;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
 function luaopen_table(L : Plua_State) : LongInt;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
 function luaopen_io(L : Plua_State) : LongInt;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
 function luaopen_os(L : Plua_State) : LongInt;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
 function luaopen_string(L : Plua_State) : LongInt;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
 function luaopen_math(L : Plua_State) : LongInt;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
 function luaopen_debug(L : Plua_State) : LongInt;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
 function luaopen_package(L : Plua_State) : LongInt;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
 procedure luaL_openlibs(L : Plua_State);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
 procedure lua_assert(x : Boolean);    // a macro
 
@@ -578,97 +629,83 @@
 procedure luaL_setn(L : Plua_State; i, j : LongInt);
 
 const
-  LUA_ERRFILE = LUA_ERRERR + 1;
+    LUA_ERRFILE = LUA_ERRERR + 1;
 
 type
-  luaL_Reg = packed record
+    luaL_Reg = packed record
     name : PChar;
     func : lua_CFunction;
-  end;
-  PluaL_Reg = ^luaL_Reg;
+    end;
+    PluaL_Reg = ^luaL_Reg;
 
 
-procedure luaL_openlib(L : Plua_State; const libname : PChar;
-                       const lr : PluaL_Reg; nup : LongInt);
-  cdecl; external LuaLibName;
-procedure luaL_register(L : Plua_State; const libname : PChar;
-                       const lr : PluaL_Reg);
-  cdecl; external LuaLibName;
-function luaL_getmetafield(L : Plua_State; obj : LongInt;
-                           const e : PChar) : LongInt;
-  cdecl; external LuaLibName;
-function luaL_callmeta(L : Plua_State; obj : LongInt;
-                       const e : PChar) : LongInt;
-  cdecl; external LuaLibName;
-function luaL_typerror(L : Plua_State; narg : LongInt;
-                       const tname : PChar) : LongInt;
-  cdecl; external LuaLibName;
-function luaL_argerror(L : Plua_State; numarg : LongInt;
-                       const extramsg : PChar) : LongInt;
-  cdecl; external LuaLibName;
-function luaL_checklstring(L : Plua_State; numArg : LongInt;
-                           ls : Psize_t) : PChar;
-  cdecl; external LuaLibName;
-function luaL_optlstring(L : Plua_State; numArg : LongInt;
-                         const def: PChar; ls: Psize_t) : PChar;
-  cdecl; external LuaLibName;
+procedure luaL_openlib(L : Plua_State; const libname : PChar; const lr : PluaL_Reg; nup : LongInt);
+    cdecl; external LuaLibName;
+procedure luaL_register(L : Plua_State; const libname : PChar; const lr : PluaL_Reg);
+    cdecl; external LuaLibName;
+function luaL_getmetafield(L : Plua_State; obj : LongInt; const e : PChar) : LongInt;
+    cdecl; external LuaLibName;
+function luaL_callmeta(L : Plua_State; obj : LongInt; const e : PChar) : LongInt;
+    cdecl; external LuaLibName;
+function luaL_typerror(L : Plua_State; narg : LongInt; const tname : PChar) : LongInt;
+    cdecl; external LuaLibName;
+function luaL_argerror(L : Plua_State; numarg : LongInt; const extramsg : PChar) : LongInt;
+    cdecl; external LuaLibName;
+function luaL_checklstring(L : Plua_State; numArg : LongInt; ls : Psize_t) : PChar;
+    cdecl; external LuaLibName;
+function luaL_optlstring(L : Plua_State; numArg : LongInt; const def: PChar; ls: Psize_t) : PChar;
+    cdecl; external LuaLibName;
 function luaL_checknumber(L : Plua_State; numArg : LongInt) : lua_Number;
-  cdecl; external LuaLibName;
-function luaL_optnumber(L : Plua_State; nArg : LongInt;
-                        def : lua_Number) : lua_Number;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+function luaL_optnumber(L : Plua_State; nArg : LongInt; def : lua_Number) : lua_Number;
+    cdecl; external LuaLibName;
 
 function luaL_checkinteger(L : Plua_State; numArg : LongInt) : lua_Integer;
-  cdecl; external LuaLibName;
-function luaL_optinteger(L : Plua_State; nArg : LongInt;
-                        def : lua_Integer) : lua_Integer;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+function luaL_optinteger(L : Plua_State; nArg : LongInt; def : lua_Integer) : lua_Integer;
+    cdecl; external LuaLibName;
 
 procedure luaL_checkstack(L : Plua_State; sz : LongInt; const msg : PChar);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 procedure luaL_checktype(L : Plua_State; narg, t : LongInt);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 procedure luaL_checkany(L : Plua_State; narg : LongInt);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
 function luaL_newmetatable(L : Plua_State; const tname : PChar) : LongInt;
-  cdecl; external LuaLibName;
-function luaL_checkudata(L : Plua_State; ud : LongInt;
-                         const tname : PChar) : Pointer;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+function luaL_checkudata(L : Plua_State; ud : LongInt; const tname : PChar) : Pointer;
+    cdecl; external LuaLibName;
 
 procedure luaL_where(L : Plua_State; lvl : LongInt);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 function  luaL_error(L : Plua_State; const fmt : PChar) : LongInt; varargs;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
-function luaL_checkoption(L : Plua_State; narg : LongInt; const def : PChar;
-                          const lst : array of PChar) : LongInt;
-  cdecl; external LuaLibName;
+function luaL_checkoption(L : Plua_State; narg : LongInt; const def : PChar; const lst : array of PChar) : LongInt;
+    cdecl; external LuaLibName;
 
 function  luaL_ref(L : Plua_State; t : LongInt) : LongInt;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 procedure luaL_unref(L : Plua_State; t, ref : LongInt);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
 function luaL_loadfile(L : Plua_State; const filename : PChar) : LongInt;
-  cdecl; external LuaLibName;
-function luaL_loadbuffer(L : Plua_State; const buff : PChar;
-                         sz : size_t; const name: PChar) : LongInt;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
+function luaL_loadbuffer(L : Plua_State; const buff : PChar; sz : size_t; const name: PChar) : LongInt;
+    cdecl; external LuaLibName;
 
 function luaL_loadstring(L : Plua_State; const s : Pchar) : LongInt;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
 function luaL_newstate : Plua_State;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
 function luaL_gsub(L : Plua_State; const s, p, r : PChar) : PChar;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
-function luaL_findtable(L : Plua_State; idx : LongInt;
-                        const fname : PChar; szhint : LongInt) : PChar;
-  cdecl; external LuaLibName;
+function luaL_findtable(L : Plua_State; idx : LongInt; const fname : PChar; szhint : LongInt) : PChar;
+    cdecl; external LuaLibName;
 
 
 (*
@@ -677,8 +714,7 @@
 ** ===============================================================
 *)
 
-function luaL_argcheck(L : Plua_State; cond : Boolean; numarg : LongInt;
-                       extramsg : PChar): LongInt;
+function luaL_argcheck(L : Plua_State; cond : Boolean; numarg : LongInt; extramsg : PChar): LongInt;
 function luaL_checkstring(L : Plua_State; n : LongInt) : PChar;
 function luaL_optstring(L : Plua_State; n : LongInt; d : PChar) : PChar;
 function luaL_checkint(L : Plua_State; n : LongInt) : lua_Integer;
@@ -705,13 +741,13 @@
 *)
 
 type
-  luaL_Buffer = packed record
+    luaL_Buffer = packed record
     p : PChar;       (* current position in buffer *)
     lvl : LongInt;   (* number of strings in the stack (level) *)
     L : Plua_State;
     buffer : array [0..LUAL_BUFFERSIZE-1] of Char;
-  end;
-  PluaL_Buffer = ^luaL_Buffer;
+    end;
+    PluaL_Buffer = ^luaL_Buffer;
 
 procedure luaL_addchar(B : PluaL_Buffer; c : Char);
 
@@ -721,17 +757,17 @@
 procedure luaL_addsize(B : PluaL_Buffer; n : LongInt);
 
 procedure luaL_buffinit(L : Plua_State; B : PluaL_Buffer);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 function  luaL_prepbuffer(B : PluaL_Buffer) : PChar;
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 procedure luaL_addlstring(B : PluaL_Buffer; const s : PChar; ls : size_t);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 procedure luaL_addstring(B : PluaL_Buffer; const s : PChar);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 procedure luaL_addvalue(B : PluaL_Buffer);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 procedure luaL_pushresult(B : PluaL_Buffer);
-  cdecl; external LuaLibName;
+    cdecl; external LuaLibName;
 
 (* ====================================================== *)
 
@@ -740,8 +776,8 @@
 
 (* pre-defined references *)
 const
-  LUA_NOREF  = -2;
-  LUA_REFNIL = -1;
+    LUA_NOREF  = -2;
+    LUA_REFNIL = -1;
 
 function lua_ref(L : Plua_State; lock : Boolean) : LongInt;
 
@@ -763,14 +799,16 @@
 (*                            luaconfig.h                                    *)
 (*****************************************************************************)
 
-function  lua_readline(L : Plua_State; var b : PChar; p : PChar): Boolean;
+function  lua_readline(L : Plua_State;
 var
-  s : AnsiString;
+    b : PChar; p : PChar): Boolean;
+var
+    s : AnsiString;
 begin
-  Write(p);                        // show prompt
-  ReadLn(s);                       // get line
-  b := PChar(s);                   //   and return it
-  lua_readline := (b[0] <> #4);          // test for ctrl-D
+    Write(p);                        // show prompt
+    ReadLn(s);                       // get line
+    b := PChar(s);                   //   and return it
+    lua_readline := (b[0] <> #4);          // test for ctrl-D
 end;
 
 procedure lua_saveline(L : Plua_State; idx : LongInt);
@@ -788,108 +826,108 @@
 
 function lua_upvalueindex(idx : LongInt) : LongInt;
 begin
-  lua_upvalueindex := LUA_GLOBALSINDEX - idx;
+lua_upvalueindex := LUA_GLOBALSINDEX - idx;
 end;
 
 procedure lua_pop(L : Plua_State; n : LongInt);
 begin
-  lua_settop(L, -n - 1);
+lua_settop(L, -n - 1);
 end;
 
 procedure lua_newtable(L : Plua_State);
 begin
-  lua_createtable(L, 0, 0);
+lua_createtable(L, 0, 0);
 end;
 
 procedure lua_register(L : Plua_State; n : PChar; f : lua_CFunction);
 begin
-  lua_pushcfunction(L, f);
-  lua_setglobal(L, n);
+lua_pushcfunction(L, f);
+lua_setglobal(L, n);
 end;
 
 procedure lua_pushcfunction(L : Plua_State; f : lua_CFunction);
 begin
-  lua_pushcclosure(L, f, 0);
+    lua_pushcclosure(L, f, 0);
 end;
 
 function  lua_strlen(L : Plua_State; idx : LongInt) : LongInt;
 begin
-  lua_strlen := lua_objlen(L, idx);
+    lua_strlen := lua_objlen(L, idx);
 end;
 
 function lua_isfunction(L : Plua_State; n : LongInt) : Boolean;
 begin
-  lua_isfunction := lua_type(L, n) = LUA_TFUNCTION;
+    lua_isfunction := lua_type(L, n) = LUA_TFUNCTION;
 end;
 
 function lua_istable(L : Plua_State; n : LongInt) : Boolean;
 begin
-  lua_istable := lua_type(L, n) = LUA_TTABLE;
+    lua_istable := lua_type(L, n) = LUA_TTABLE;
 end;
 
 function lua_islightuserdata(L : Plua_State; n : LongInt) : Boolean;
 begin
-  lua_islightuserdata := lua_type(L, n) = LUA_TLIGHTUSERDATA;
+    lua_islightuserdata := lua_type(L, n) = LUA_TLIGHTUSERDATA;
 end;
 
 function lua_isnil(L : Plua_State; n : LongInt) : Boolean;
 begin
-  lua_isnil := lua_type(L, n) = LUA_TNIL;
+    lua_isnil := lua_type(L, n) = LUA_TNIL;
 end;
 
 function lua_isboolean(L : Plua_State; n : LongInt) : Boolean;
 begin
-  lua_isboolean := lua_type(L, n) = LUA_TBOOLEAN;
+    lua_isboolean := lua_type(L, n) = LUA_TBOOLEAN;
 end;
 
 function lua_isthread(L : Plua_State; n : LongInt) : Boolean;
 begin
-  lua_isthread := lua_type(L, n) = LUA_TTHREAD;
+    lua_isthread := lua_type(L, n) = LUA_TTHREAD;
 end;
 
 function lua_isnone(L : Plua_State; n : LongInt) : Boolean;
 begin
-  lua_isnone := lua_type(L, n) = LUA_TNONE;
+    lua_isnone := lua_type(L, n) = LUA_TNONE;
 end;
 
 function lua_isnoneornil(L : Plua_State; n : LongInt) : Boolean;
 begin
-  lua_isnoneornil := lua_type(L, n) <= 0;
+    lua_isnoneornil := lua_type(L, n) <= 0;
 end;
 
 procedure lua_pushliteral(L : Plua_State; s : PChar);
 begin
-  lua_pushlstring(L, s, StrLen(s));
+    lua_pushlstring(L, s, StrLen(s));
 end;
 
 procedure lua_setglobal(L : Plua_State; s : PChar);
 begin
-  lua_setfield(L, LUA_GLOBALSINDEX, s);
+    lua_setfield(L, LUA_GLOBALSINDEX, s);
 end;
 
 procedure lua_getglobal(L: Plua_State; s: PChar);
 begin
-  lua_getfield(L, LUA_GLOBALSINDEX, s);
+    lua_getfield(L, LUA_GLOBALSINDEX, s);
 end;
 
 function lua_tostring(L : Plua_State; idx : LongInt) : AnsiString;
 begin
-  lua_tostring := SysUtils.StrPas(lua_tolstring(L, idx, nil));
+    lua_tostring := SysUtils.StrPas(lua_tolstring(L, idx, nil));
 end;
 
 function lua_open : Plua_State;
 begin
-  lua_open := luaL_newstate;
+    lua_open := luaL_newstate;
 end;
 
 procedure lua_getregistry(L : Plua_State);
 begin
-  lua_pushvalue(L, LUA_REGISTRYINDEX);
+    lua_pushvalue(L, LUA_REGISTRYINDEX);
 end;
 
 function lua_getgccount(L : Plua_State) : LongInt;
 begin
-  lua_getgccount := lua_gc(L, LUA_GCCOUNT, 0);
+    lua_getgccount := lua_gc(L, LUA_GCCOUNT, 0);
 end;
 
 
@@ -908,88 +946,87 @@
 
 function luaL_getn(L : Plua_State; idx : LongInt) : LongInt;
 begin
-  luaL_getn := lua_objlen(L, idx);
+    luaL_getn := lua_objlen(L, idx);
 end;
 
 procedure luaL_setn(L : plua_State; i, j : LongInt);
 begin
-  (* no op *)
+    (* no op *)
 end;
 
-function luaL_argcheck(L : Plua_State; cond : Boolean; numarg : LongInt;
-                       extramsg : PChar): LongInt;
+function luaL_argcheck(L : Plua_State; cond : Boolean; numarg : LongInt; extramsg : PChar): LongInt;
 begin
-  if not cond then
-    luaL_argcheck := luaL_argerror(L, numarg, extramsg)
-  else
-    luaL_argcheck := 0;
+    if not cond then
+        luaL_argcheck := luaL_argerror(L, numarg, extramsg)
+    else
+        luaL_argcheck := 0;
 end;
 
 function luaL_checkstring(L : Plua_State; n : LongInt) : PChar;
 begin
-  luaL_checkstring := luaL_checklstring(L, n, nil);
+    luaL_checkstring := luaL_checklstring(L, n, nil);
 end;
 
 function luaL_optstring(L : Plua_State; n : LongInt; d : PChar) : PChar;
 begin
-  luaL_optstring := luaL_optlstring(L, n, d, nil);
+    luaL_optstring := luaL_optlstring(L, n, d, nil);
 end;
 
 function luaL_checkint(L : Plua_State; n : LongInt) : lua_Integer;
 begin
-  luaL_checkint := luaL_checkinteger(L, n);
+    luaL_checkint := luaL_checkinteger(L, n);
 end;
 
 function luaL_optint(L : Plua_State; n : LongInt; d : lua_Integer): lua_Integer;
 begin
-  luaL_optint := luaL_optinteger(L, n, d);
+    luaL_optint := luaL_optinteger(L, n, d);
 end;
 
 function luaL_checklong(L : Plua_State; n : LongInt) : lua_Integer;
 begin
-  luaL_checklong := luaL_checkinteger(L, n);
+    luaL_checklong := luaL_checkinteger(L, n);
 end;
 
 function luaL_optlong(L : Plua_State; n : LongInt; d : lua_Integer) : lua_Integer;
 begin
-  luaL_optlong := luaL_optinteger(L, n, d);
+    luaL_optlong := luaL_optinteger(L, n, d);
 end;
 
 function luaL_typename(L : Plua_State; idx : LongInt) : PChar;
 begin
-  luaL_typename := lua_typename( L, lua_type(L, idx) );
+    luaL_typename := lua_typename( L, lua_type(L, idx) );
 end;
 
 function luaL_dofile(L : Plua_State; fn : PChar) : LongInt;
 begin
-  luaL_dofile := luaL_loadfile(L, fn);
-  if luaL_dofile = 0 then
-    luaL_dofile := lua_pcall(L, 0, 0, 0);
+    luaL_dofile := luaL_loadfile(L, fn);
+    if luaL_dofile = 0 then
+        luaL_dofile := lua_pcall(L, 0, 0, 0);
 end;
 
 function luaL_dostring(L : Plua_State; s : PChar) : LongInt;
 begin
-  luaL_dostring := luaL_loadstring(L, s);
-  if luaL_dostring = 0 then
-    luaL_dostring := lua_pcall(L, 0, 0, 0);
+    luaL_dostring := luaL_loadstring(L, s);
+    if luaL_dostring = 0 then
+        luaL_dostring := lua_pcall(L, 0, 0, 0);
 end;
 
 procedure luaL_getmetatable(L : Plua_State; n : PChar);
 begin
-  lua_getfield(L, LUA_REGISTRYINDEX, n);
+    lua_getfield(L, LUA_REGISTRYINDEX, n);
 end;
 
 procedure luaL_addchar(B : PluaL_Buffer; c : Char);
 begin
-  if not(B^.p < B^.buffer + LUAL_BUFFERSIZE) then
-    luaL_prepbuffer(B);
-  (B^.p^) := c;
-  Inc(B^.p);
+    if not(B^.p < B^.buffer + LUAL_BUFFERSIZE) then
+        luaL_prepbuffer(B);
+    (B^.p^) := c;
+    Inc(B^.p);
 end;
 
 procedure luaL_putchar(B : PluaL_Buffer; c : Char);
 begin
-  luaL_addchar(B, c);
+    luaL_addchar(B, c);
 end;
 
 procedure luaL_addsize(B : PluaL_Buffer; n : LongInt);
@@ -999,23 +1036,24 @@
 
 function lua_ref(L : Plua_State; lock : Boolean) : LongInt;
 begin
-  if lock then
-    lua_ref := luaL_ref(L, LUA_REGISTRYINDEX)
-  else begin
-    lua_pushstring(L, 'unlocked references are obsolete');
-    lua_error(L);
-    lua_ref := 0;
-  end;
+    if lock then
+        lua_ref := luaL_ref(L, LUA_REGISTRYINDEX)
+    else
+        begin
+        lua_pushstring(L, 'unlocked references are obsolete');
+        lua_error(L);
+        lua_ref := 0;
+        end;
 end;
 
 procedure lua_unref(L : Plua_State; ref : LongInt);
 begin
-  luaL_unref(L, LUA_REGISTRYINDEX, ref);
+    luaL_unref(L, LUA_REGISTRYINDEX, ref);
 end;
 
 procedure lua_getref(L : Plua_State; ref : LongInt);
 begin
-  lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
+    lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
 end;
 
 
--- a/hedgewars/PascalExports.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/PascalExports.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -32,9 +32,13 @@
 
 {$INCLUDE "config.inc"}
 procedure HW_versionInfo(netProto: PLongInt; versionStr: PPChar); cdecl; export;
+
 function HW_getNumberOfWeapons:LongInt; cdecl; export;
+
 function HW_getMaxNumberOfTeams:LongInt; cdecl; export;
+
 function HW_getMaxNumberOfHogs:LongInt; cdecl; export;
+
 procedure HW_terminate(closeFrontend: Boolean); cdecl; export;
 
 implementation
@@ -225,8 +229,8 @@
 
 function HW_isAmmoMenuNotAllowed: boolean; cdecl; export;
 begin;
-    exit( (TurnTimeLeft = 0) or (not CurrentTeam^.ExtDriven and (((CurAmmoGear = nil) or
-          ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) = 0)) and hideAmmoMenu)) );
+    exit( (TurnTimeLeft = 0) or (not CurrentTeam^.ExtDriven and (((CurAmmoGear = nil)
+    or ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) = 0)) and hideAmmoMenu)) );
 end;
 
 function HW_isWeaponRequiringClick: boolean; cdecl; export;
@@ -270,7 +274,7 @@
 begin
     // this most likely won't work in network game
     if (CurrentHedgehog <> nil) and (CurrentHedgehog^.Ammo <> nil) and (CurrentHedgehog^.BotLevel = 0)
-       and (CurrentHedgehog^.CurAmmoType = amPiano) then
+        and (CurrentHedgehog^.CurAmmoType = amPiano) then
         case snd of
             0: PlaySound(sndPiano0);
             1: PlaySound(sndPiano1);
--- a/hedgewars/SDLh.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/SDLh.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -22,48 +22,48 @@
 interface
 
 {$IFDEF LINUX}
-  {$DEFINE UNIX}
+    {$DEFINE UNIX}
 {$ENDIF}
 {$IFDEF FREEBSD}
-  {$DEFINE UNIX}
+    {$DEFINE UNIX}
 {$ENDIF}
 {$IFDEF DARWIN}
-  {$DEFINE UNIX}
+    {$DEFINE UNIX}
 {$ENDIF}
 {$IFDEF HAIKU}
-  {$DEFINE UNIX}
+    {$DEFINE UNIX}
 {$ENDIF}
 
 {$IFDEF UNIX}
-  {$IFNDEF DARWIN}
-    {$linklib c}
-  {$ENDIF}
-  {$IFDEF HAIKU}
-    {$linklib root}
-  {$ELSE}
-    {$IFNDEF ANDROID}
-      {$linklib pthread}
+    {$IFNDEF DARWIN}
+        {$linklib c}
     {$ENDIF}
-  {$ENDIF}
+    {$IFDEF HAIKU}
+        {$linklib root}
+    {$ELSE}
+        {$IFNDEF ANDROID}
+        {$linklib pthread}
+    {$ENDIF}
+    {$ENDIF}
 {$ENDIF}
 
 {$IFDEF FPC}
-  {$PACKRECORDS C}
+    {$PACKRECORDS C}
 {$ELSE}
-  {$DEFINE cdecl attribute(cdecl)}
+    {$DEFINE cdecl attribute(cdecl)}
 {$ENDIF}
 
 {$IFDEF DARWIN}
-  {$IFNDEF IPHONEOS}
-    {$PASCALMAINNAME SDL_main}
-    {$linkframework Cocoa}
-    {$linkframework SDL}
-    {$linkframework SDL_net}
-    {$linkframework SDL_image}
-    {$linkframework SDL_ttf}
-    {$linkframework SDL_mixer}
-    {$linkframework OpenGL}
-  {$ENDIF}
+    {$IFNDEF IPHONEOS}
+        {$PASCALMAINNAME SDL_main}
+        {$linkframework Cocoa}
+        {$linkframework SDL}
+        {$linkframework SDL_net}
+        {$linkframework SDL_image}
+        {$linkframework SDL_ttf}
+        {$linkframework SDL_mixer}
+        {$linkframework OpenGL}
+    {$ENDIF}
 {$ENDIF}
 
 
@@ -76,19 +76,19 @@
     SDL_ImageLibName = 'SDL_image.dll';
     SDL_NetLibName = 'SDL_net.dll';
 {$ELSE}
-  {$IFDEF DARWIN}
+    {$IFDEF DARWIN}
     SDLLibName = 'SDL';
     SDL_TTFLibName = 'SDL_ttf';
     SDL_MixerLibName = 'SDL_mixer';
     SDL_ImageLibName = 'SDL_image';
     SDL_NetLibName = 'SDL_net';
-  {$ELSE}
+    {$ELSE}
     SDLLibName = 'libSDL.so';
     SDL_TTFLibName = 'libSDL_ttf.so';
     SDL_MixerLibName = 'libSDL_mixer.so';
     SDL_ImageLibName = 'libSDL_image.so';
     SDL_NetLibName = 'libSDL_net.so';
-  {$ENDIF}
+    {$ENDIF}
 {$ENDIF}
 
 /////////////////////////////////////////////////////////////////
@@ -794,40 +794,40 @@
     TMix_Fading = (MIX_NO_FADING, MIX_FADING_OUT, MIX_FADING_IN);
 
     TMidiSong = record
-               samples : LongInt;
-               events  : Pointer;
-               end;
+                samples : LongInt;
+                events  : Pointer;
+                end;
 
     TMusicUnion = record
         case Byte of
-             0: ( midi : TMidiSong );
-             1: ( ogg  : Pointer);
-             end;
+            0: ( midi : TMidiSong );
+            1: ( ogg  : Pointer);
+            end;
 
     PMixMusic = ^TMixMusic;
     TMixMusic = record
-                 end;
+                end;
 
     {* SDL_net *}
     TIPAddress = record
-                  host: LongWord;
-                  port: Word;
-                  end;
+                host: LongWord;
+                port: Word;
+                end;
 
     PTCPSocket = ^TTCPSocket;
     TTCPSocket = record
-                  ready: LongInt;
-                  channel: LongInt;
-                  remoteAddress: TIPaddress;
-                  localAddress: TIPaddress;
-                  sflag: LongInt;
-                  end;
+                ready: LongInt;
+                channel: LongInt;
+                remoteAddress: TIPaddress;
+                localAddress: TIPaddress;
+                sflag: LongInt;
+                end;
     PSDLNet_SocketSet = ^TSDLNet_SocketSet;
     TSDLNet_SocketSet = record
-                         numsockets,
-                         maxsockets: LongInt;
-                         sockets: PTCPSocket;
-                         end;
+                        numsockets,
+                        maxsockets: LongInt;
+                        sockets: PTCPSocket;
+                        end;
 
 
 /////////////////////////////////////////////////////////////////
--- a/hedgewars/VGSHandlers.inc	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/VGSHandlers.inc	Wed Jan 18 01:11:09 2012 +0100
@@ -38,13 +38,15 @@
         begin
         dec(FrameTicks, vobFrameTicks);
         inc(Frame);
-        if Frame = vobFramesCount then Frame:= 0
+        if Frame = vobFramesCount then
+            Frame:= 0
         end
     else if SuddenDeathDmg and (FrameTicks > vobSDFrameTicks) then
         begin
         dec(FrameTicks, vobSDFrameTicks);
         inc(Frame);
-        if Frame = vobSDFramesCount then Frame:= 0
+        if Frame = vobSDFramesCount then
+            Frame:= 0
         end;
     X:= X + (cWindSpeedf * 400 + dX + tdX) * Steps * Gear^.Scale;
     if SuddenDeathDmg then
@@ -59,28 +61,39 @@
             Angle:= Angle + 360;
     
   
-    if (round(X) >= cLeftScreenBorder) and
-       (round(X) <= cRightScreenBorder) and
-       (round(Y) - 75 <= LAND_HEIGHT) and
-       (Timer > 0) and (Timer-Steps > 0) then
+    if (round(X) >= cLeftScreenBorder)
+    and (round(X) <= cRightScreenBorder)
+    and (round(Y) - 75 <= LAND_HEIGHT)
+    and (Timer > 0) and (Timer-Steps > 0) then
         begin
-        if tdX > 0 then sign := 1
-        else sign:= -1;
+        if tdX > 0 then
+            sign := 1
+        else
+            sign:= -1;
         tdX:= tdX - 0.005*Steps*sign;
-        if ((sign < 0) and (tdX > 0)) or ((sign > 0) and (tdX < 0)) then tdX:= 0;
-        if tdX > 0 then sign := 1
-        else sign:= -1;
+        if ((sign < 0) and (tdX > 0)) or ((sign > 0) and (tdX < 0)) then
+            tdX:= 0;
+        if tdX > 0 then
+            sign := 1
+        else
+            sign:= -1;
         tdY:= tdY - 0.005*Steps*sign;
-        if ((sign < 0) and (tdY > 0)) or ((sign > 0) and (tdY < 0)) then tdY:= 0;
+        if ((sign < 0) and (tdY > 0)) or ((sign > 0) and (tdY < 0)) then
+            tdY:= 0;
         dec(Timer, Steps)
         end
     else
         begin
-        if round(X) < cLeftScreenBorder then X:= X + cScreenSpace else
-        if round(X) > cRightScreenBorder then X:= X - cScreenSpace;
-        // if round(Y) < (LAND_HEIGHT - 1024 - 75) then Y:= Y + 25.0; // For if flag is set for flakes rising upwards?
-        if (Gear^.Layer = 2) and (round(Y) - 225 > LAND_HEIGHT) then Y:= Y - (1024 + 300) // TODO - configure in theme (jellies for example could use limited range)
-        else if (Gear^.Layer <> 2) and (round(Y) + 50 > LAND_HEIGHT) then Y:= Y - (1024 + 25);
+        if round(X) < cLeftScreenBorder then
+            X:= X + cScreenSpace
+        else
+            if round(X) > cRightScreenBorder then
+                X:= X - cScreenSpace;
+            // if round(Y) < (LAND_HEIGHT - 1024 - 75) then Y:= Y + 25.0; // For if flag is set for flakes rising upwards?
+            if (Gear^.Layer = 2) and (round(Y) - 225 > LAND_HEIGHT) then
+                Y:= Y - (1024 + 300) // TODO - configure in theme (jellies for example could use limited range)
+            else if (Gear^.Layer <> 2) and (round(Y) + 50 > LAND_HEIGHT) then
+                Y:= Y - (1024 + 25);
         Timer:= 0;
         tdX:= 0;
         tdY:= 0
@@ -112,8 +125,11 @@
 
 Gear^.Y := LAND_HEIGHT - 1184 + LongInt(Gear^.Timer mod 8) + t;
 
-if round(Gear^.X) < cLeftScreenBorder then Gear^.X:= Gear^.X + cScreenSpace else
-if round(Gear^.X) > cRightScreenBorder then Gear^.X:= Gear^.X - cScreenSpace
+if round(Gear^.X) < cLeftScreenBorder then
+    Gear^.X:= Gear^.X + cScreenSpace
+else
+    if round(Gear^.X) > cRightScreenBorder then
+        Gear^.X:= Gear^.X - cScreenSpace
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -125,7 +141,8 @@
 //Gear^.dY:= Gear^.dY + cGravityf;
 
 if Gear^.FrameTicks <= Steps then
-    if Gear^.Frame = 0 then DeleteVisualGear(Gear)
+    if Gear^.Frame = 0 then
+        DeleteVisualGear(Gear)
     else
         begin
         dec(Gear^.Frame);
@@ -243,102 +260,108 @@
 ////////////////////////////////////////////////////////////////////////////////
 procedure doStepBubble(Gear: PVisualGear; Steps: Longword);
 begin
-    Gear^.X:= Gear^.X + Gear^.dX * Steps;
-    Gear^.Y:= Gear^.Y + Gear^.dY * Steps;
-    Gear^.Y:= Gear^.Y - cDrownSpeedf * Steps;
+Gear^.X:= Gear^.X + Gear^.dX * Steps;
+Gear^.Y:= Gear^.Y + Gear^.dY * Steps;
+Gear^.Y:= Gear^.Y - cDrownSpeedf * Steps;
+Gear^.dX := Gear^.dX / (1.001 * Steps);
+Gear^.dY := Gear^.dY / (1.001 * Steps);
 
-    Gear^.dX := Gear^.dX / (1.001 * Steps);
-    Gear^.dY := Gear^.dY / (1.001 * Steps);
-
-    if (Gear^.FrameTicks <= Steps) or (round(Gear^.Y) < cWaterLine) then
-        DeleteVisualGear(Gear)
-    else
-        dec(Gear^.FrameTicks, Steps)
+if (Gear^.FrameTicks <= Steps) or (round(Gear^.Y) < cWaterLine) then
+    DeleteVisualGear(Gear)
+else
+    dec(Gear^.FrameTicks, Steps)
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
 procedure doStepSteam(Gear: PVisualGear; Steps: Longword);
 begin
-    Gear^.X:= Gear^.X + (cWindSpeedf * 100 + Gear^.dX) * Steps;
-    Gear^.Y:= Gear^.Y - cDrownSpeedf * Steps;
+Gear^.X:= Gear^.X + (cWindSpeedf * 100 + Gear^.dX) * Steps;
+Gear^.Y:= Gear^.Y - cDrownSpeedf * Steps;
 
-    if Gear^.FrameTicks <= Steps then
-        if Gear^.Frame = 0 then DeleteVisualGear(Gear)
-        else
-            begin
-            if Random(2) = 0 then dec(Gear^.Frame);
-            Gear^.FrameTicks:= cExplFrameTicks
-            end
-        else dec(Gear^.FrameTicks, Steps)
+if Gear^.FrameTicks <= Steps then
+    if Gear^.Frame = 0 then
+        DeleteVisualGear(Gear)
+    else
+        begin
+        if Random(2) = 0 then
+            dec(Gear^.Frame);
+        Gear^.FrameTicks:= cExplFrameTicks
+        end
+else dec(Gear^.FrameTicks, Steps)
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
 procedure doStepAmmo(Gear: PVisualGear; Steps: Longword);
 begin
-    Gear^.Y:= Gear^.Y - cDrownSpeedf * Steps;
+Gear^.Y:= Gear^.Y - cDrownSpeedf * Steps;
 
-    Gear^.scale:= Gear^.scale + 0.0025 * Steps;
-    Gear^.alpha:= Gear^.alpha - 0.0015 * Steps;
+Gear^.scale:= Gear^.scale + 0.0025 * Steps;
+Gear^.alpha:= Gear^.alpha - 0.0015 * Steps;
 
-    if Gear^.alpha < 0 then DeleteVisualGear(Gear)
+if Gear^.alpha < 0 then
+    DeleteVisualGear(Gear)
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
 procedure doStepSmoke(Gear: PVisualGear; Steps: Longword);
 begin
-    Gear^.X:= Gear^.X + (cWindSpeedf + Gear^.dX) * Steps;
-    Gear^.Y:= Gear^.Y - (cDrownSpeedf + Gear^.dY) * Steps;
+Gear^.X:= Gear^.X + (cWindSpeedf + Gear^.dX) * Steps;
+Gear^.Y:= Gear^.Y - (cDrownSpeedf + Gear^.dY) * Steps;
 
-    Gear^.dX := Gear^.dX + (cWindSpeedf * 0.3 * Steps);
-    //Gear^.dY := Gear^.dY - (cDrownSpeedf * 0.995);
+Gear^.dX := Gear^.dX + (cWindSpeedf * 0.3 * Steps);
+//Gear^.dY := Gear^.dY - (cDrownSpeedf * 0.995);
 
-    if Gear^.FrameTicks <= Steps then
-        if Gear^.Frame = 0 then DeleteVisualGear(Gear)
-        else
-            begin
-            if Random(2) = 0 then dec(Gear^.Frame);
-            Gear^.FrameTicks:= cExplFrameTicks
-            end
-        else dec(Gear^.FrameTicks, Steps)
+if Gear^.FrameTicks <= Steps then
+    if Gear^.Frame = 0 then
+        DeleteVisualGear(Gear)
+    else
+        begin
+        if Random(2) = 0 then
+            dec(Gear^.Frame);
+        Gear^.FrameTicks:= cExplFrameTicks
+        end
+    else dec(Gear^.FrameTicks, Steps)
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
 procedure doStepDust(Gear: PVisualGear; Steps: Longword);
 begin
-    Gear^.X:= Gear^.X + (cWindSpeedf + (cWindSpeedf * 0.03 * Steps) + Gear^.dX) * Steps;
-    Gear^.Y:= Gear^.Y - (Gear^.dY) * Steps;
+Gear^.X:= Gear^.X + (cWindSpeedf + (cWindSpeedf * 0.03 * Steps) + Gear^.dX) * Steps;
+Gear^.Y:= Gear^.Y - (Gear^.dY) * Steps;
 
-    Gear^.dX := Gear^.dX - (Gear^.dX * 0.005 * Steps);
-    Gear^.dY := Gear^.dY - (cDrownSpeedf * 0.001 * Steps);
+Gear^.dX := Gear^.dX - (Gear^.dX * 0.005 * Steps);
+Gear^.dY := Gear^.dY - (cDrownSpeedf * 0.001 * Steps);
 
-    if Gear^.FrameTicks <= Steps then
-        if Gear^.Frame = 0 then DeleteVisualGear(Gear)
-        else
-            begin
-            dec(Gear^.Frame);
-            Gear^.FrameTicks:= cExplFrameTicks
-            end
-        else dec(Gear^.FrameTicks, Steps)
+if Gear^.FrameTicks <= Steps then
+    if Gear^.Frame = 0 then
+            DeleteVisualGear(Gear)
+    else
+        begin
+        dec(Gear^.Frame);
+        Gear^.FrameTicks:= cExplFrameTicks
+        end
+    else dec(Gear^.FrameTicks, Steps)
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
 procedure doStepSplash(Gear: PVisualGear; Steps: Longword);
 begin
-  if Gear^.FrameTicks <= Steps then
-      DeleteVisualGear(Gear)
-  else
-      dec(Gear^.FrameTicks, Steps);
+if Gear^.FrameTicks <= Steps then
+    DeleteVisualGear(Gear)
+else
+    dec(Gear^.FrameTicks, Steps);
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
 procedure doStepDroplet(Gear: PVisualGear; Steps: Longword);
 begin
-  Gear^.X:= Gear^.X + Gear^.dX * Steps;
+Gear^.X:= Gear^.X + Gear^.dX * Steps;
 
-  Gear^.Y:= Gear^.Y + Gear^.dY * Steps;
-  Gear^.dY:= Gear^.dY + cGravityf * Steps;
+Gear^.Y:= Gear^.Y + Gear^.dY * Steps;
+Gear^.dY:= Gear^.dY + cGravityf * Steps;
 
-  if round(Gear^.Y) > cWaterLine then begin
+if round(Gear^.Y) > cWaterLine then
+    begin
     DeleteVisualGear(Gear);
     PlaySound(TSound(ord(sndDroplet1) + Random(3)));
     end;
@@ -348,12 +371,14 @@
 procedure doStepSmokeRing(Gear: PVisualGear; Steps: Longword);
 begin
 inc(Gear^.Timer, Steps);
-if Gear^.Timer >= Gear^.FrameTicks then DeleteVisualGear(Gear)
+if Gear^.Timer >= Gear^.FrameTicks then
+    DeleteVisualGear(Gear)
 else
     begin
     Gear^.scale := 1.25 * (-power(2, -10 * Int(Gear^.Timer)/Gear^.FrameTicks) + 1) + 0.4;
     Gear^.alpha := 1 - power(Gear^.Timer / 350, 4);
-    if Gear^.alpha < 0 then Gear^.alpha:= 0;
+    if Gear^.alpha < 0 then
+        Gear^.alpha:= 0;
     end;
 end;
 
@@ -401,7 +426,8 @@
 
     if (Gear^.Timer = 0) or (currsorter <> Gear) then
         begin
-        if currsorter = Gear then currsorter:= nil;
+        if currsorter = Gear then
+            currsorter:= nil;
         DeleteVisualGear(Gear);
         exit
         end
@@ -477,7 +503,8 @@
 Steps:= Steps; // avoid compiler hint
 
 with Gear^.Hedgehog^ do
-    if SpeechGear <> nil then SpeechGear^.Timer:= 0;
+    if SpeechGear <> nil then
+        SpeechGear^.Timer:= 0;
 
 Gear^.Hedgehog^.SpeechGear:= Gear;
 
@@ -536,7 +563,8 @@
 
 Gear^.Y:= Gear^.Y - Gear^.Tex^.h;
 
-if Steps > 1 then Gear^.doStep(Gear, Steps-1);
+if Steps > 1 then
+    Gear^.doStep(Gear, Steps-1);
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -546,10 +574,10 @@
 if Gear^.Timer > 64 then
     begin
     if Gear^.State = 0 then
-      begin
-      DeleteVisualGear(Gear);
-      exit;
-      end;
+        begin
+        DeleteVisualGear(Gear);
+        exit;
+        end;
     dec(Gear^.State, Gear^.Timer div 65);
     Gear^.Timer:= Gear^.Timer mod 65;
     end;
@@ -565,7 +593,8 @@
     begin
     inc(Gear^.State, Gear^.Timer div 76);
     Gear^.Timer:= Gear^.Timer mod 76;
-    if Gear^.State > 5 then DeleteVisualGear(Gear);
+    if Gear^.State > 5 then
+        DeleteVisualGear(Gear);
     end;
 end;
 
@@ -588,7 +617,8 @@
 for i:= 0 to  8 do AddVisualGear(gX, gY, vgtExplPart);
 for i:= 0 to  8 do AddVisualGear(gX, gY, vgtExplPart2);
 Gear^.doStep:= @doStepExplosionWork;
-if Steps > 1 then Gear^.doStep(Gear, Steps-1);
+if Steps > 1 then
+    Gear^.doStep(Gear, Steps-1);
 end;
 
 
@@ -604,7 +634,8 @@
     ShakeCamera(maxMovement);
     end;
 
-if Gear^.Timer > 250 then DeleteVisualGear(Gear);
+if Gear^.Timer > 250 then
+    DeleteVisualGear(Gear);
 end;
 
 procedure doStepBigExplosion(Gear: PVisualGear; Steps: Longword);
@@ -627,10 +658,13 @@
         inc(vg^.FrameTicks, vg^.FrameTicks)
         end
     end;
-for i:= 0 to 15 do AddVisualGear(gX, gY, vgtExplPart);
-for i:= 0 to 15 do AddVisualGear(gX, gY, vgtExplPart2);
+for i:= 0 to 15 do
+    AddVisualGear(gX, gY, vgtExplPart);
+for i:= 0 to 15 do
+    AddVisualGear(gX, gY, vgtExplPart2);
 Gear^.doStep:= @doStepBigExplosionWork;
-if Steps > 1 then Gear^.doStep(Gear, Steps-1);
+if Steps > 1 then
+    Gear^.doStep(Gear, Steps-1);
 performRumble();
 end;
 
@@ -653,10 +687,10 @@
 ////////////////////////////////////////////////////////////////////////////////
 procedure doStepBulletHit(Gear: PVisualGear; Steps: Longword);
 begin
-  if Gear^.FrameTicks <= Steps then
-      DeleteVisualGear(Gear)
-  else
-      dec(Gear^.FrameTicks, Steps);
+if Gear^.FrameTicks <= Steps then
+    DeleteVisualGear(Gear)
+else
+    dec(Gear^.FrameTicks, Steps);
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -672,12 +706,18 @@
             if (FrameTicks mod Frame) = 0 then
                 begin
                 tmp:= Gear^.Tint and $FF;
-                if tdY >= 0 then inc(tmp)
-                else dec(tmp);
-                if tmp < round(dX) then tdY:= 1;
-                if tmp > round(dY) then tdY:= -1;
-                if tmp > 255 then tmp := 255;
-                if tmp < 0 then tmp := 0;
+                if tdY >= 0 then
+                    inc(tmp)
+                else
+                    dec(tmp);
+                if tmp < round(dX) then
+                    tdY:= 1;
+                if tmp > round(dY) then
+                    tdY:= -1;
+                if tmp > 255 then
+                    tmp := 255;
+                if tmp < 0 then
+                    tmp := 0;
                 Gear^.Tint:= (Gear^.Tint and $FFFFFF00) or Longword(tmp)
                 end
             end
@@ -686,13 +726,15 @@
 ////////////////////////////////////////////////////////////////////////////////
 procedure doStepSmoothWindBar(Gear: PVisualGear; Steps: Longword);
 begin
-    inc(Gear^.Timer, Steps);
+inc(Gear^.Timer, Steps);
     
     while Gear^.Timer >= 10 do
         begin
         dec(Gear^.Timer, 10);
-        if WindBarWidth < Gear^.Tag then inc(WindBarWidth)
-        else if WindBarWidth > Gear^.Tag then dec(WindBarWidth);
+        if WindBarWidth < Gear^.Tag then
+            inc(WindBarWidth)
+        else if WindBarWidth > Gear^.Tag then
+            dec(WindBarWidth);
         end;
         
 if WindBarWidth = Gear^.Tag then 
--- a/hedgewars/adler32.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/adler32.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -65,7 +65,7 @@
 That means no btypes, file loading, and the assembly version disabled.
 *)
 
-procedure Adler32Update(var adler: longint; Msg: pointer; Len: longint);
+procedure Adler32Update ( var adler     :longint; Msg     :pointer; Len     :longint );
 
 implementation
 
@@ -73,29 +73,33 @@
 $ifdef BASM16
 
 procedure Adler32Update(var adler: longint; Msg: pointer; Len: longint);
-  //-update Adler32 with Msg data
+    //-update Adler32 with Msg data
 const
-  BASE = 65521; // max. prime < 65536
-  NMAX =  5552; // max. n with 255n(n+1)/2 + (n+1)(BASE-1) < 2^32
+    BASE = 65521; // max. prime < 65536
+    NMAX =  5552; // max. n with 255n(n+1)/2 + (n+1)(BASE-1) < 2^32
 type
-  LH    = packed record
+    LH    = packed record
             L,H: word;
-          end;
+            end;
 var
-  s1,s2: longint;
-  n: integer;
+    s1,s2: longint;
+    n: integer;
 begin
-  s1 := LH(adler).L;
-  s2 := LH(adler).H;
-  while Len > 0 do begin
-    if Len<NMAX then n := Len else n := NMAX;
+    s1 := LH(adler).L;
+    s2 := LH(adler).H;
+    while Len > 0 do
+        begin
+    if Len<NMAX then
+        n := Len
+    else
+        n := NMAX;
     //BASM increases speed from about 52 cyc/byte to about 3.7 cyc/byte
     asm
                     mov  cx,[n]
             db $66; mov  ax,word ptr [s1]
             db $66; mov  di,word ptr [s2]
                     les  si,[msg]
-      @@1:  db $66, $26, $0f, $b6, $1c      // movzx ebx,es:[si]
+        @@1:  db $66, $26, $0f, $b6, $1c      // movzx ebx,es:[si]
                     inc  si
             db $66; add  ax,bx              // inc(s1, pByte(Msg)^)
             db $66; add  di,ax              // inc(s2, s1
@@ -111,42 +115,48 @@
             db $66; div  cx
             db $66; mov  word ptr [s2],dx   // s2 := s2 mod BASE
                     mov  word ptr [msg],si  // save offset for next chunk
-    end;
+        end;
     dec(len, n);
-  end;
-  LH(adler).L := word(s1);
-  LH(adler).H := word(s2);
+    end;
+    LH(adler).L := word(s1);
+    LH(adler).H := word(s2);
 end;
 *)
 
-procedure Adler32Update(var adler: longint; Msg: pointer; Len: longint);
-  {-update Adler32 with Msg data}
-const
-  BASE = 65521; {max. prime < 65536 }
-  NMAX =  3854; {max. n with 255n(n+1)/2 + (n+1)(BASE-1) < 2^31}
-type
-  LH    = packed record
-            L,H: word;
-          end;
-var
-  s1,s2: longint;
-  i,n: integer;
-begin
-  s1 := LH(adler).L;
-  s2 := LH(adler).H;
-  while Len > 0 do begin
-    if Len<NMAX then n := Len else n := NMAX;
-    for i:=1 to n do begin
-      inc(s1, pByte(Msg)^);
-      inc(Msg);
-      inc(s2, s1);
+procedure Adler32Update(var adler: longint; Msg: pointer; Len :longint);
+    {-update Adler32 with Msg data}
+    const
+        BASE = 65521; {max. prime < 65536 }
+        NMAX = 3854; {max. n with 255n(n+1)/2 + (n+1)(BASE-1) < 2^31}
+    type
+        LH = packed record
+            L, H: word;
+            end;
+    var
+        s1, s2: longint;
+        i, n: integer;
+    begin
+        s1 := LH(adler).L;
+        s2 := LH(adler).H;
+        while Len>0 do
+            begin
+            if Len<NMAX then
+                n := Len
+            else
+                n := NMAX;
+
+            for i := 1 to n do
+                begin
+                inc(s1, pByte(Msg)^);
+                inc(Msg);
+                inc(s2, s1);
+                end;
+            s1 := s1 mod BASE;
+            s2 := s2 mod BASE;
+            dec(len, n);
+            end;
+        LH(adler).L := word(s1);
+        LH(adler).H := word(s2);
     end;
-    s1 := s1 mod BASE;
-    s2 := s2 mod BASE;
-    dec(len, n);
-  end;
-  LH(adler).L := word(s1);
-  LH(adler).H := word(s2);
-end;
 
 end.
--- a/hedgewars/hwengine.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/hwengine.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -55,55 +55,61 @@
         inc(RealTicks, Lag);
 
     case GameState of
-        gsLandGen: begin
-                GenMap;
-                ParseCommand('sendlanddigest', true);
-                GameState:= gsStart;
+        gsLandGen:
+            begin
+            GenMap;
+            ParseCommand('sendlanddigest', true);
+            GameState:= gsStart;
+            end;
+        gsStart:
+            begin
+            if HasBorder then
+                DisableSomeWeapons;
+            AddClouds;
+            AddFlakes;
+            AssignHHCoords;
+            AddMiscGears;
+            StoreLoad;
+            InitWorld;
+            ResetKbd;
+            SoundLoad;
+            if GameType = gmtSave then
+                begin
+                isSEBackup:= isSoundEnabled;
+                isSoundEnabled:= false
                 end;
-        gsStart: begin
-                if HasBorder then DisableSomeWeapons;
-                AddClouds;
-                AddFlakes;
-                AssignHHCoords;
-                AddMiscGears;
-                StoreLoad;
-                InitWorld;
-                ResetKbd;
-                SoundLoad;
-                if GameType = gmtSave then
-                    begin
-                    isSEBackup:= isSoundEnabled;
-                    isSoundEnabled:= false
-                    end;
-                FinishProgress;
-                PlayMusic;
-                SetScale(zoom);
-                ScriptCall('onGameStart');
-                GameState:= gsGame;
+            FinishProgress;
+            PlayMusic;
+            SetScale(zoom);
+            ScriptCall('onGameStart');
+            GameState:= gsGame;
+            end;
+        gsConfirm, gsGame:
+            begin
+            DrawWorld(Lag); // never place between ProcessKbd and DoGameTick - bugs due to /put cmd and isCursorVisible
+            ProcessKbd;
+            if not isPaused then
+                begin
+                DoGameTick(Lag);
+                ProcessVisualGears(Lag);
                 end;
-        gsConfirm,
-        gsGame: begin
-                DrawWorld(Lag); // never place between ProcessKbd and DoGameTick - bugs due to /put cmd and isCursorVisible
-                ProcessKbd;
-                if not isPaused then
-                    begin
-                    DoGameTick(Lag);
-                    ProcessVisualGears(Lag);
-                    end;
+            end;
+        gsChat:
+            begin
+            DrawWorld(Lag);
+            if not isPaused then
+                begin
+                DoGameTick(Lag);
+                ProcessVisualGears(Lag);
                 end;
-        gsChat: begin
-                DrawWorld(Lag);
-                if not isPaused then
-                    begin
-                    DoGameTick(Lag);
-                    ProcessVisualGears(Lag);
-                    end;
-                end;
-        gsExit: begin
-                isTerminated:= true;
-                end;
-        gsSuspend: exit;
-        end;
+            end;
+        gsExit:
+            begin
+            isTerminated:= true;
+            end;
+        gsSuspend:
+            exit;
+            end;
 
 {$IFDEF SDL13}
     SDL_GL_SwapWindow(SDLwindow);
@@ -112,17 +118,20 @@
 {$ENDIF}
 
     if flagMakeCapture then
-    begin
+        begin
         flagMakeCapture:= false;
         s:= 'hw_' + FormatDateTime('YYYY-MM-DD_HH-mm-ss', Now()) + inttostr(GameTicks);
 
         playSound(sndShutter);
-        if MakeScreenshot(s) then WriteLnToConsole('Screenshot saved: ' + s)
-        else begin
+        
+        if MakeScreenshot(s) then
+            WriteLnToConsole('Screenshot saved: ' + s)
+        else
+            begin
             WriteLnToConsole('Screenshot failed.');
             AddChatString(#5 + 'screen capture failed (lack of memory or write permissions)');
             end
-    end;
+        end;
 end;
 
 ////////////////////
@@ -162,9 +171,11 @@
         begin
             case event.type_ of
 {$IFDEF SDL13}
-                SDL_KEYDOWN: if GameState = gsChat then
+                SDL_KEYDOWN:
+                if GameState = gsChat then
                     // sdl on iphone supports only ashii keyboards and the unicode field is deprecated in sdl 1.3
                     KeyPressChat(event.key.keysym.sym);
+                    
                 SDL_WINDOWEVENT:
                     if event.window.event = SDL_WINDOWEVENT_SHOWN then
                         begin
@@ -189,14 +200,28 @@
                         cScreenResizeDelay:= RealTicks+500;
                         *)
                         end;
-                SDL_FINGERMOTION: onTouchMotion(event.tfinger.x, event.tfinger.y,event.tfinger.dx, event.tfinger.dy, event.tfinger.fingerId);
-                SDL_FINGERDOWN: onTouchDown(event.tfinger.x, event.tfinger.y, event.tfinger.fingerId);
-                SDL_FINGERUP: onTouchUp(event.tfinger.x, event.tfinger.y, event.tfinger.fingerId);
+                        
+                SDL_FINGERMOTION:
+                    onTouchMotion(event.tfinger.x, event.tfinger.y,event.tfinger.dx, event.tfinger.dy, event.tfinger.fingerId);
+                
+                SDL_FINGERDOWN:
+                    onTouchDown(event.tfinger.x, event.tfinger.y, event.tfinger.fingerId);
+                
+                SDL_FINGERUP:
+                    onTouchUp(event.tfinger.x, event.tfinger.y, event.tfinger.fingerId);
 {$ELSE}
-                SDL_KEYDOWN: if GameState = gsChat then
-                    KeyPressChat(event.key.keysym.unicode);
-                SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then wheelDown:= true;
-                SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELUP then wheelUp:= true;
+                SDL_KEYDOWN:
+                    if GameState = gsChat then
+                        KeyPressChat(event.key.keysym.unicode);
+                    
+                SDL_MOUSEBUTTONDOWN:
+                    if event.button.button = SDL_BUTTON_WHEELDOWN then
+                        wheelDown:= true;
+                
+                SDL_MOUSEBUTTONUP:
+                    if event.button.button = SDL_BUTTON_WHEELUP then
+                        wheelUp:= true;
+                    
                 SDL_ACTIVEEVENT:
                     if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then
                         begin
@@ -205,7 +230,9 @@
                         if prevFocusState xor cHasFocus then
                             onFocusStateChanged()
                         end;
-                SDL_VIDEORESIZE: begin
+                        
+                SDL_VIDEORESIZE:
+                    begin
                     // using lower values than cMinScreenWidth or cMinScreenHeight causes widget overlap and off-screen widget parts
                     // Change by sheepluva:
                     // Let's only use even numbers for custom width/height since I ran into scaling issues with odd width values.
@@ -215,15 +242,21 @@
                     cScreenResizeDelay:= RealTicks+500;
                     end;
 {$ENDIF}
-                SDL_JOYAXISMOTION: ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value);
-                SDL_JOYHATMOTION: ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value);
-                SDL_JOYBUTTONDOWN: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, true);
-                SDL_JOYBUTTONUP: ControllerButtonEvent(event.jbutton.which, event.jbutton.button, false);
-                SDL_QUITEV: isTerminated:= true
-            end; //end case event.type_ of
-        end; //end while SDL_PollEvent(@event) <> 0 do
+                SDL_JOYAXISMOTION:
+                    ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value);
+                SDL_JOYHATMOTION:
+                    ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value);
+                SDL_JOYBUTTONDOWN:
+                    ControllerButtonEvent(event.jbutton.which, event.jbutton.button, true);
+                SDL_JOYBUTTONUP:
+                    ControllerButtonEvent(event.jbutton.which, event.jbutton.button, false);
+                SDL_QUITEV:
+                    isTerminated:= true
+        end; //end case event.type_ of
+    end; //end while SDL_PollEvent(@event) <> 0 do
 
-        if (cScreenResizeDelay <> 0) and (cScreenResizeDelay < RealTicks) and ((cNewScreenWidth <> cScreenWidth) or (cNewScreenHeight <> cScreenHeight)) then
+        if (cScreenResizeDelay <> 0) and (cScreenResizeDelay < RealTicks)
+        and ((cNewScreenWidth <> cScreenWidth) or (cNewScreenHeight <> cScreenHeight)) then
             begin
             cScreenResizeDelay:= 0;
             cScreenWidth:= cNewScreenWidth;
@@ -251,7 +284,8 @@
 
 ///////////////
 procedure Game{$IFDEF HWLIBRARY}(gameArgs: PPChar); cdecl; export{$ENDIF};
-var p: TPathType;
+var
+    p: TPathType;
     s: shortstring;
     i: LongInt;
 begin
@@ -265,8 +299,12 @@
     val(gameArgs[2], cScreenHeight);
     val(gameArgs[3], cReducedQuality);
     cLocaleFName:= gameArgs[4];
-    if (Length(cLocaleFName) > 6) then cLocale := Copy(cLocaleFName,1,5)
-    else cLocale := Copy(cLocaleFName,1,2);
+    
+    if (Length(cLocaleFName) > 6) then
+        cLocale := Copy(cLocaleFName,1,5)
+    else
+        cLocale := Copy(cLocaleFName,1,2);
+        
     UserNick:= gameArgs[5];
     isSoundEnabled:= gameArgs[6] = '1';
     isMusicEnabled:= gameArgs[7] = '1';
@@ -285,16 +323,19 @@
     WriteLnToConsole('Hedgewars ' + cVersionString + ' engine (network protocol: ' + inttostr(cNetProtoVersion) + ')');
     AddFileLog('Prefix: "' + PathPrefix +'"');
     AddFileLog('UserPrefix: "' + UserPathPrefix +'"');
+    
     for i:= 0 to ParamCount do
         AddFileLog(inttostr(i) + ': ' + ParamStr(i));
 
     for p:= Succ(Low(TPathType)) to High(TPathType) do
-        if (p <> ptMapCurrent) and (p <> ptData) then UserPathz[p]:= UserPathPrefix + '/Data/' + Pathz[p];
+        if (p <> ptMapCurrent) and (p <> ptData) then
+            UserPathz[p]:= UserPathPrefix + '/Data/' + Pathz[p];
 
     UserPathz[ptData]:= UserPathPrefix + '/Data';
 
     for p:= Succ(Low(TPathType)) to High(TPathType) do
-        if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p];
+        if p <> ptMapCurrent then
+            Pathz[p]:= PathPrefix + '/' + Pathz[p];
 
     WriteToConsole('Init SDL... ');
     SDLTry(SDL_Init(SDL_INIT_VIDEO or SDL_INIT_NOPARACHUTE) >= 0, true);
@@ -308,8 +349,10 @@
     WriteLnToConsole(msgOK);
 
     // show main window
-    if cFullScreen then ParseCommand('fullscr 1', true)
-    else ParseCommand('fullscr 0', true);
+    if cFullScreen then
+        ParseCommand('fullscr 1', true)
+    else
+        ParseCommand('fullscr 0', true);
 
     ControllerInit(); // has to happen before InitKbdKeyTable to map keys
     InitKbdKeyTable();
@@ -362,15 +405,18 @@
     OnDestroy();
     // clean up all the other memory allocated
     freeEverything(true);
-    if alsoShutdownFrontend then halt;
+    if alsoShutdownFrontend then
+        halt;
 end;
 
 procedure initEverything (complete:boolean);
 begin
     Randomize();
 
-    if complete then cLogfileBase:= 'game'
-    else cLogfileBase:= 'preview';
+    if complete then
+        cLogfileBase:= 'game'
+    else
+        cLogfileBase:= 'preview';
 
     // uConsts does not need initialization as they are all consts
     uUtils.initModule;
@@ -386,7 +432,7 @@
     uIO.initModule;
 
     if complete then
-    begin
+        begin
 {$IFDEF ANDROID}GLUnit.init;{$ENDIF}
 {$IFDEF SDL13}uTouch.initModule;{$ENDIF}
         uAI.initModule;
@@ -414,13 +460,13 @@
         uVisualGears.initModule;
         uWorld.initModule;
         uCaptions.initModule;
-    end;
+        end;
 end;
 
 procedure freeEverything (complete:boolean);
 begin
     if complete then
-    begin
+        begin
         uCaptions.freeModule;
         uWorld.freeModule;
         uVisualGears.freeModule;
@@ -446,7 +492,7 @@
         //uAIAmmoTests does not need to be freed
         //uAIActions does not need to be freed
         uAI.freeModule;             //stub
-    end;
+        end;
 
     uIO.freeModule;             //stub
     uLand.freeModule;
@@ -462,7 +508,8 @@
 
 /////////////////////////
 procedure GenLandPreview{$IFDEF HWLIBRARY}(port: LongInt); cdecl; export{$ENDIF};
-var Preview: TPreview;
+var
+    Preview: TPreview;
 begin
     initEverything(false);
 {$IFDEF HWLIBRARY}
@@ -502,8 +549,10 @@
     WriteLn('Read documentation online at http://code.google.com/p/hedgewars/wiki/CommandLineOptions for more information');
     WriteLn();
     Write('PARSED COMMAND: ');
+    
     for i:=0 to ParamCount do
         Write(ParamStr(i) + ' ');
+        
     WriteLn();
 end;
 
@@ -529,11 +578,15 @@
 ////////////////////////////////////////////////////////////////////////////////
 begin
     GetParams();
-    if (Length(cLocaleFName) > 6) then cLocale := Copy(cLocaleFName,1,5)
-    else cLocale := Copy(cLocaleFName,1,2);
+    if (Length(cLocaleFName) > 6) then
+        cLocale := Copy(cLocaleFName,1,5)
+    else
+        cLocale := Copy(cLocaleFName,1,2);
 
-    if GameType = gmtLandPreview then GenLandPreview()
-    else if GameType = gmtSyntax then DisplayUsage()
+    if GameType = gmtLandPreview then
+        GenLandPreview()
+    else if GameType = gmtSyntax then
+        DisplayUsage()
     else Game();
 
     // return 1 when engine is not called correctly
--- a/hedgewars/options.inc	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/options.inc	Wed Jan 18 01:11:09 2012 +0100
@@ -17,9 +17,9 @@
  *)
 
 {$IFDEF FPC}
-  {$J+}
+    {$J+}
 {$ELSE}
-  {$ERROR Only Free Pascal supported!}
+    {$ERROR Only Free Pascal supported!}
 {$ENDIF}
 
 {$MODE OBJFPC}
@@ -28,28 +28,28 @@
 {$DEFINE GLunit:=GL}
 
 {$IFDEF ANDROID}
-  {$DEFINE SDL13}
-  {$DEFINE HWLIBRARY}
-  {$DEFINE S3D_DISABLED}
-  {$DEFINE GLunit:=gles11}
-  {$DEFINE MOBILE}
-  {$DEFINE Java_Prefix := 'Java_org_hedgewars_hedgeroid_EngineProtocol_PascalExports_'}
-  {$DEFINE USE_SDLTHREADS}
+    {$DEFINE SDL13}
+    {$DEFINE HWLIBRARY}
+    {$DEFINE S3D_DISABLED}
+    {$DEFINE GLunit:=gles11}
+    {$DEFINE MOBILE}
+    {$DEFINE Java_Prefix := 'Java_org_hedgewars_hedgeroid_EngineProtocol_PascalExports_'}
+    {$DEFINE USE_SDLTHREADS}
 {$ENDIF}
 
 {$IFDEF IPHONEOS}
-  {$DEFINE SDL13}
-  {$DEFINE HWLIBRARY}
-  {$DEFINE S3D_DISABLED}
-  {$DEFINE GLunit:=gles11}
-  {$DEFINE MOBILE}
+    {$DEFINE SDL13}
+    {$DEFINE HWLIBRARY}
+    {$DEFINE S3D_DISABLED}
+    {$DEFINE GLunit:=gles11}
+    {$DEFINE MOBILE}
 {$ENDIF}
 
 {$IFNDEF IPHONEOS}
-  // not needed on ios because it is switched from the compiler command line arguments
-  {$DEFINE DEBUGFILE}
-  //{$DEFINE TRACEAIACTIONS}
-  //{$DEFINE COUNTTICKS}
+    // not needed on ios because it is switched from the compiler command line arguments
+    {$DEFINE DEBUGFILE}
+    //{$DEFINE TRACEAIACTIONS}
+    //{$DEFINE COUNTTICKS}
 {$ENDIF}
 
 //also available LUA_DISABLED
--- a/hedgewars/uAI.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uAI.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -30,8 +30,8 @@
 
 implementation
 uses uConsts, SDLh, uAIMisc, uAIAmmoTests, uAIActions,
-     uAmmos, SysUtils{$IFNDEF USE_SDLTHREADS} {$IFDEF UNIX}, cthreads{$ENDIF} {$ENDIF}, uTypes,
-     uVariables, uCommands, uUtils, uDebug;
+    uAmmos, SysUtils{$IFNDEF USE_SDLTHREADS} {$IFDEF UNIX}, cthreads{$ENDIF} {$ENDIF}, uTypes,
+    uVariables, uCommands, uUtils, uDebug;
 
 var BestActions: TActions;
     CanUseAmmo: array [TAmmoType] of boolean;
@@ -47,18 +47,18 @@
 begin
 AddFileLog('FreeActionsList called');
 if hasThread <> 0 then
-   begin
-   AddFileLog('Waiting AI thread to finish');
-   StopThinking:= true;
-   repeat
-     SDL_Delay(10)
-   until hasThread = 0
-   end;
+    begin
+    AddFileLog('Waiting AI thread to finish');
+    StopThinking:= true;
+    repeat
+        SDL_Delay(10)
+    until hasThread = 0
+    end;
 
 with CurrentHedgehog^ do
-     if Gear <> nil then
+    if Gear <> nil then
         if BotLevel <> 0 then
-           StopMessages(Gear^.Message);
+            StopMessages(Gear^.Message);
 
 BestActions.Count:= 0;
 BestActions.Pos:= 0
@@ -117,66 +117,71 @@
 
 for i:= 0 to Pred(Targets.Count) do
     if (Targets.ar[i].Score >= 0) and (not StopThinking) then
-       begin
-       with CurrentHedgehog^ do
+        begin
+        with CurrentHedgehog^ do
             a:= CurAmmoType;
-       aa:= a;
+        aa:= a;
 {$IFDEF USE_SDLTHREADS}
-       SDL_delay(0);    //ThreadSwitch was only a hint
+        SDL_delay(0);    //ThreadSwitch was only a hint
 {$ELSE}
-       ThreadSwitch();
+        ThreadSwitch();
 {$ENDIF}       
-       repeat
+        repeat
         if (CanUseAmmo[a]) and
-           ((not isMoved) or ((AmmoTests[a].flags and amtest_OnTurn) = 0)) then
-           begin
+            ((not isMoved) or ((AmmoTests[a].flags and amtest_OnTurn) = 0)) then
+            begin
 {$HINTS OFF}
-           Score:= AmmoTests[a].proc(Me, Targets.ar[i].Point, BotLevel, ap);
+            Score:= AmmoTests[a].proc(Me, Targets.ar[i].Point, BotLevel, ap);
 {$HINTS ON}
-           if Actions.Score + Score > BestActions.Score then
-            if (BestActions.Score < 0) or (Actions.Score + Score > BestActions.Score + Byte(BotLevel) * 2048) then
-              begin
-              BestActions:= Actions;
-              inc(BestActions.Score, Score);
-              BestActions.isWalkingToABetterPlace:= false;
+            if Actions.Score + Score > BestActions.Score then
+                if (BestActions.Score < 0) or (Actions.Score + Score > BestActions.Score + Byte(BotLevel) * 2048) then
+                    begin
+                    BestActions:= Actions;
+                    inc(BestActions.Score, Score);
+                    BestActions.isWalkingToABetterPlace:= false;
 
-              if (ap.Angle > 0) then AddAction(BestActions, aia_LookRight, 0, 200, 0, 0)
-              else if (ap.Angle < 0) then AddAction(BestActions, aia_LookLeft, 0, 200, 0, 0);
+                if (ap.Angle > 0) then
+                    AddAction(BestActions, aia_LookRight, 0, 200, 0, 0)
+            else if (ap.Angle < 0) then
+                AddAction(BestActions, aia_LookLeft, 0, 200, 0, 0);
 
-              AddAction(BestActions, aia_Weapon, Longword(a), 300 + random(400), 0, 0);
-              if (ap.Time <> 0) then AddAction(BestActions, aia_Timer, ap.Time div 1000, 400, 0, 0);
-              if (Ammoz[a].Ammo.Propz and ammoprop_NoCrosshair) = 0 then
-                 begin
-                 ap.Angle:= LongInt(Me^.Angle) - Abs(ap.Angle);
-                 if ap.Angle > 0 then
-                    begin
-                    AddAction(BestActions, aia_Up, aim_push, 300 + random(250), 0, 0);
-                    AddAction(BestActions, aia_Up, aim_release, ap.Angle, 0, 0)
-                    end else if ap.Angle < 0 then
+                AddAction(BestActions, aia_Weapon, Longword(a), 300 + random(400), 0, 0);
+                
+                if (ap.Time <> 0) then
+                    AddAction(BestActions, aia_Timer, ap.Time div 1000, 400, 0, 0);
+                if (Ammoz[a].Ammo.Propz and ammoprop_NoCrosshair) = 0 then
                     begin
-                    AddAction(BestActions, aia_Down, aim_push, 300 + random(250), 0, 0);
-                    AddAction(BestActions, aia_Down, aim_release, -ap.Angle, 0, 0)
-                    end
-                 end;
-              if (Ammoz[a].Ammo.Propz and ammoprop_NeedTarget) <> 0 then
-                 begin
-                 AddAction(BestActions, aia_Put, 0, 1, ap.AttackPutX, ap.AttackPutY)
-                 end;
-              if (Ammoz[a].Ammo.Propz and ammoprop_AttackingPut) = 0 then
-                 begin
-                 AddAction(BestActions, aia_attack, aim_push, 650 + random(300), 0, 0);
-                 AddAction(BestActions, aia_attack, aim_release, ap.Power, 0, 0);
-                 end;
-              if ap.ExplR > 0 then
-                 AddAction(BestActions, aia_AwareExpl, ap.ExplR, 10, ap.ExplX, ap.ExplY);
-              end
-           end;
-        if a = High(TAmmoType) then a:= Low(TAmmoType)
-                               else inc(a)
-       until (a = aa) or
-             (CurrentHedgehog^.MultiShootAttacks > 0) or // shooting same weapon
-             StopThinking
-       end
+                    ap.Angle:= LongInt(Me^.Angle) - Abs(ap.Angle);
+                    if ap.Angle > 0 then
+                        begin
+                        AddAction(BestActions, aia_Up, aim_push, 300 + random(250), 0, 0);
+                        AddAction(BestActions, aia_Up, aim_release, ap.Angle, 0, 0)
+                        end
+                    else if ap.Angle < 0 then
+                        begin
+                        AddAction(BestActions, aia_Down, aim_push, 300 + random(250), 0, 0);
+                        AddAction(BestActions, aia_Down, aim_release, -ap.Angle, 0, 0)
+                        end
+                    end;
+                if (Ammoz[a].Ammo.Propz and ammoprop_NeedTarget) <> 0 then
+                    begin
+                    AddAction(BestActions, aia_Put, 0, 1, ap.AttackPutX, ap.AttackPutY)
+                    end;
+                if (Ammoz[a].Ammo.Propz and ammoprop_AttackingPut) = 0 then
+                    begin
+                    AddAction(BestActions, aia_attack, aim_push, 650 + random(300), 0, 0);
+                    AddAction(BestActions, aia_attack, aim_release, ap.Power, 0, 0);
+                    end;
+                if ap.ExplR > 0 then
+                    AddAction(BestActions, aia_AwareExpl, ap.ExplR, 10, ap.ExplX, ap.ExplY);
+                end
+            end;
+        if a = High(TAmmoType) then
+            a:= Low(TAmmoType)
+        else inc(a)
+        until (a = aa) or (CurrentHedgehog^.MultiShootAttacks > 0) or // shooting same weapon
+        StopThinking
+        end
 end;
 
 procedure Walk(Me: PGear; var Actions: TActions);
@@ -202,10 +207,14 @@
 Push(0, Actions, Me^, tmp);
 Push(0, Actions, Me^, tmp xor 3);
 
-if (Me^.State and gstAttacked) = 0 then maxticks:= Max(0, TurnTimeLeft - 5000 - LongWord(4000 * BotLevel))
-                                   else maxticks:= TurnTimeLeft;
+if (Me^.State and gstAttacked) = 0 then
+    maxticks:= Max(0, TurnTimeLeft - 5000 - LongWord(4000 * BotLevel))
+else
+    maxticks:= TurnTimeLeft;
 
-if (Me^.State and gstAttacked) = 0 then TestAmmos(Actions, Me, false);
+if (Me^.State and gstAttacked) = 0 then
+    TestAmmos(Actions, Me, false);
+    
 BestRate:= RatePlace(Me);
 BaseRate:= Max(BestRate, 0);
 
@@ -217,54 +226,67 @@
     Pop(ticks, Actions, Me^);
 
     AddAction(Actions, Me^.Message, aim_push, 250, 0, 0);
-    if (Me^.Message and gmLeft) <> 0 then AddAction(Actions, aia_WaitXL, hwRound(Me^.X), 0, 0, 0)
-                                      else AddAction(Actions, aia_WaitXR, hwRound(Me^.X), 0, 0, 0);
+    if (Me^.Message and gmLeft) <> 0 then
+        AddAction(Actions, aia_WaitXL, hwRound(Me^.X), 0, 0, 0)
+    else
+        AddAction(Actions, aia_WaitXR, hwRound(Me^.X), 0, 0, 0);
+    
     steps:= 0;
 
     while (not StopThinking) do
-       begin
+        begin
 {$HINTS OFF}
-       CanGo:= HHGo(Me, @AltMe, GoInfo);
+        CanGo:= HHGo(Me, @AltMe, GoInfo);
 {$HINTS ON}
-       inc(ticks, GoInfo.Ticks);
-       if ticks > maxticks then break;
+        inc(ticks, GoInfo.Ticks);
+        if ticks > maxticks then
+            break;
 
-       if (BotLevel < 5) and (GoInfo.JumpType = jmpHJump) then // hjump support
-          if Push(ticks, Actions, AltMe, Me^.Message) then
-             with Stack.States[Pred(Stack.Count)] do
-                  begin
-                  if Me^.dX.isNegative then AddAction(MadeActions, aia_LookRight, 0, 200, 0, 0)
-                                       else AddAction(MadeActions, aia_LookLeft, 0, 200, 0, 0);
-                  AddAction(MadeActions, aia_HJump, 0, 305 + random(50), 0, 0);
-                  AddAction(MadeActions, aia_HJump, 0, 350, 0, 0);
-                  if Me^.dX.isNegative then AddAction(MadeActions, aia_LookLeft, 0, 200, 0, 0)
-                                       else AddAction(MadeActions, aia_LookRight, 0, 200, 0, 0);
-                  end;
-       if (BotLevel < 3) and (GoInfo.JumpType = jmpLJump) then // ljump support
-          if Push(ticks, Actions, AltMe, Me^.Message) then
-             with Stack.States[Pred(Stack.Count)] do
-                  AddAction(MadeActions, aia_LJump, 0, 305 + random(50), 0, 0);
+        if (BotLevel < 5) and (GoInfo.JumpType = jmpHJump) then // hjump support
+            if Push(ticks, Actions, AltMe, Me^.Message) then
+                with Stack.States[Pred(Stack.Count)] do
+                    begin
+                    if Me^.dX.isNegative then
+                        AddAction(MadeActions, aia_LookRight, 0, 200, 0, 0)
+                    else
+                        AddAction(MadeActions, aia_LookLeft, 0, 200, 0, 0);
+                        
+                    AddAction(MadeActions, aia_HJump, 0, 305 + random(50), 0, 0);
+                    AddAction(MadeActions, aia_HJump, 0, 350, 0, 0);
+                    
+                    if Me^.dX.isNegative then
+                        AddAction(MadeActions, aia_LookLeft, 0, 200, 0, 0)
+                    else
+                        AddAction(MadeActions, aia_LookRight, 0, 200, 0, 0);
+                    end;
+        if (BotLevel < 3) and (GoInfo.JumpType = jmpLJump) then // ljump support
+            if Push(ticks, Actions, AltMe, Me^.Message) then
+                with Stack.States[Pred(Stack.Count)] do
+                    AddAction(MadeActions, aia_LJump, 0, 305 + random(50), 0, 0);
 
-       if not CanGo then break;
-       inc(steps);
-       Actions.actions[Pred(Actions.Count)].Param:= hwRound(Me^.X);
-       Rate:= RatePlace(Me);
-       if Rate > BestRate then
-          begin
-          BestActions:= Actions;
-          BestActions.isWalkingToABetterPlace:= true;
-          BestRate:= Rate;
-          Me^.State:= Me^.State or gstAttacked // we have better place, go there and do not use ammo
-          end
-       else if Rate < BestRate then break;
-       if ((Me^.State and gstAttacked) = 0)
-           and ((steps mod 4) = 0) then TestAmmos(Actions, Me, true);
-       if GoInfo.FallPix >= FallPixForBranching then
-          Push(ticks, Actions, Me^, Me^.Message xor 3); // aia_Left xor 3 = aia_Right
-       end;
+        if not CanGo then
+            break;
+        inc(steps);
+         Actions.actions[Pred(Actions.Count)].Param:= hwRound(Me^.X);
+         Rate:= RatePlace(Me);
+         if Rate > BestRate then
+            begin
+            BestActions:= Actions;
+            BestActions.isWalkingToABetterPlace:= true;
+            BestRate:= Rate;
+            Me^.State:= Me^.State or gstAttacked // we have better place, go there and do not use ammo
+            end
+        else if Rate < BestRate then
+            break;
+        if ((Me^.State and gstAttacked) = 0) and ((steps mod 4) = 0) then
+            TestAmmos(Actions, Me, true);
+        if GoInfo.FallPix >= FallPixForBranching then
+            Push(ticks, Actions, Me^, Me^.Message xor 3); // aia_Left xor 3 = aia_Right
+        end;
 
-    if BestRate > BaseRate then exit
-    end
+    if BestRate > BaseRate then
+        exit
+        end
 end;
 
 function Think(Me: Pointer): ptrint;
@@ -283,8 +305,8 @@
 switchAvailable:= HHHasAmmo(PGear(Me)^.Hedgehog^, amSwitch);
 
 if (PGear(Me)^.State and gstAttacked) = 0 then
-   if Targets.Count > 0 then
-      begin
+    if Targets.Count > 0 then
+        begin
         // iterate over current team hedgehogs
         repeat
             WalkMe:= CurrentTeam^.Hedgehogs[itHedgehog].Gear^;
@@ -318,7 +340,8 @@
             or (itHedgehog = currHedgehogIndex)
             or BestActions.isWalkingToABetterPlace;
 
-        if (StartTicks > GameTicks - 1500) and (not StopThinking) then SDL_Delay(1000);
+        if (StartTicks > GameTicks - 1500) and (not StopThinking) then
+            SDL_Delay(1000);
 
         if (BestActions.Score < -1023) and (not BestActions.isWalkingToABetterPlace) then
             begin
@@ -326,8 +349,9 @@
             AddAction(BestActions, aia_Skip, 0, 250, 0, 0);
             end;
 
-      end else
-else begin
+        end else
+else
+    begin
     BackMe:= PGear(Me)^;
     while (not StopThinking) and (BestActions.Count = 0) do
         begin
@@ -337,7 +361,8 @@
         Actions.Pos:= 0;
         Actions.Score:= 0;
         Walk(@WalkMe, Actions);
-        if not StopThinking then SDL_Delay(100)
+        if not StopThinking then
+            SDL_Delay(100)
         end
     end;
 
@@ -349,7 +374,8 @@
 procedure StartThink(Me: PGear);
 begin
 if ((Me^.State and (gstAttacking or gstHHJumping or gstMoving)) <> 0)
-   or isInMultiShoot then exit;
+or isInMultiShoot then
+    exit;
 
 //DeleteCI(Me); // this might break demo
 Me^.State:= Me^.State or gstHHThinking;
@@ -365,10 +391,10 @@
 
 FillTargets;
 if Targets.Count = 0 then
-   begin
-   OutError('AI: no targets!?', false);
-   exit
-   end;
+    begin
+    OutError('AI: no targets!?', false);
+    exit
+    end;
 
 FillBonuses((Me^.State and gstAttacked) <> 0);
 AddFileLog('Enter Think Thread');
@@ -385,24 +411,28 @@
       cStopThinkTime = 40;
 begin
 with CurrentHedgehog^ do
-     if (Gear <> nil)
-        and ((Gear^.State and gstHHDriven) <> 0)
-        and (TurnTimeLeft < cHedgehogTurnTime - 50) then
+    if (Gear <> nil)
+    and ((Gear^.State and gstHHDriven) <> 0)
+    and (TurnTimeLeft < cHedgehogTurnTime - 50) then
         if ((Gear^.State and gstHHThinking) = 0) then
-           if (BestActions.Pos >= BestActions.Count)
-              and (TurnTimeLeft > cStopThinkTime) then
-              begin
-              if Gear^.Message <> 0 then
-                 begin
-                 StopMessages(Gear^.Message);
-                 TryDo((Gear^.Message and gmAllStoppable) = 0, 'Engine bug: AI may break demos playing', true);
-                 end;
-              if Gear^.Message <> 0 then exit;
-              StartThink(Gear);
-              StartTicks:= GameTicks
-              end else ProcessAction(BestActions, Gear)
+            if (BestActions.Pos >= BestActions.Count)
+            and (TurnTimeLeft > cStopThinkTime) then
+                begin
+                if Gear^.Message <> 0 then
+                    begin
+                    StopMessages(Gear^.Message);
+                    TryDo((Gear^.Message and gmAllStoppable) = 0, 'Engine bug: AI may break demos playing', true);
+                    end;
+                if Gear^.Message <> 0 then
+                    exit;
+                StartThink(Gear);
+                StartTicks:= GameTicks
+                
+                end else
+                    ProcessAction(BestActions, Gear)
         else if ((GameTicks - StartTicks) > cMaxAIThinkTime)
-                or (TurnTimeLeft <= cStopThinkTime) then StopThinking:= true
+        or (TurnTimeLeft <= cStopThinkTime) then
+            StopThinking:= true
 end;
 
 procedure initModule;
--- a/hedgewars/uAIActions.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uAIActions.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -23,42 +23,43 @@
 uses uFloat, uTypes;
 
 const MAXACTIONS     = 96;
-      aia_none       = 0;
-      aia_Left       = 1;
-      aia_Right      = 2;
-      aia_Timer      = 3;
-      aia_attack     = 4;
-      aia_Up         = 5;
-      aia_Down       = 6;
-      aia_Switch     = 7;
+    aia_none       = 0;
+    aia_Left       = 1;
+    aia_Right      = 2;
+    aia_Timer      = 3;
+    aia_attack     = 4;
+    aia_Up         = 5;
+    aia_Down       = 6;
+    aia_Switch     = 7;
 
-      aia_Weapon     = $8000;
-      aia_WaitXL     = $8001;
-      aia_WaitXR     = $8002;
-      aia_LookLeft   = $8003;
-      aia_LookRight  = $8004;
-      aia_AwareExpl  = $8005;
-      aia_HJump      = $8006;
-      aia_LJump      = $8007;
-      aia_Skip       = $8008;
-      aia_Wait       = $8009;
-      aia_Put        = $800A;
-
-      aim_push       = $8000;
-      aim_release    = $8001;
-      ai_specmask    = $8000;
+    aia_Weapon     = $8000;
+    aia_WaitXL     = $8001;
+    aia_WaitXR     = $8002;
+    aia_LookLeft   = $8003;
+    aia_LookRight  = $8004;
+    aia_AwareExpl  = $8005;
+    aia_HJump      = $8006;
+    aia_LJump      = $8007;
+    aia_Skip       = $8008;
+    aia_Wait       = $8009;
+    aia_Put        = $800A;
+    
+    aim_push       = $8000;
+    aim_release    = $8001;
+    ai_specmask    = $8000;
 
 type TAction = record
-               Action: Longword;
-               X, Y, Param: LongInt;
-               Time: Longword;
-               end;
-     TActions = record
-                Count, Pos: Longword;
-                actions: array[0..Pred(MAXACTIONS)] of TAction;
-                Score: LongInt;
-                isWalkingToABetterPlace: boolean;
-                end;
+        Action: Longword;
+        X, Y, Param: LongInt;
+        Time: Longword;
+        end;
+        
+    TActions = record
+        Count, Pos: Longword;
+        actions: array[0..Pred(MAXACTIONS)] of TAction;
+        Score: LongInt;
+        isWalkingToABetterPlace: boolean;
+        end;
 
 procedure AddAction(var Actions: TActions; Action: Longword; Param: LongInt; TimeDelta: Longword; X, Y: LongInt);
 procedure ProcessAction(var Actions: TActions; Me: PGear);
@@ -94,29 +95,34 @@
 procedure DumpAction(Action: TAction; Me: PGear);
 begin
 if (Action.Action and ai_specmask) = 0 then
-   WriteLnToConsole('AI action: '+ActionIdToStr[Action.Action])
-else begin
-   WriteLnToConsole('AI action: '+SpecActionIdToStr[Action.Action]);
-   if (Action.Action = aia_WaitXL) or (Action.Action = aia_WaitXR) then
-      WriteLnToConsole('AI action Wait X = '+IntToStr(Action.Param)+', current X = '+IntToStr(hwRound(Me^.X)))
-   else if (Action.Action = aia_AwareExpl) then WriteLnToConsole('Aware X = ' + IntToStr(Action.X) + ', Y = ' + IntToStr(Action.Y));
-   end
+    WriteLnToConsole('AI action: '+ActionIdToStr[Action.Action])
+else
+    begin
+    WriteLnToConsole('AI action: '+SpecActionIdToStr[Action.Action]);
+    if (Action.Action = aia_WaitXL) or (Action.Action = aia_WaitXR) then
+        WriteLnToConsole('AI action Wait X = '+IntToStr(Action.Param)+', current X = '+IntToStr(hwRound(Me^.X)))
+        
+    else if (Action.Action = aia_AwareExpl) then
+        WriteLnToConsole('Aware X = ' + IntToStr(Action.X) + ', Y = ' + IntToStr(Action.Y));
+    end
 end;
 {$ENDIF}
 
 procedure AddAction(var Actions: TActions; Action: Longword; Param: LongInt; TimeDelta: Longword; X, Y: LongInt);
 begin
 with Actions do
-     begin
-     actions[Count].Action:= Action;
-     actions[Count].Param:= Param;
-     actions[Count].X:= X;
-     actions[Count].Y:= Y;
-     if Count > 0 then actions[Count].Time:= TimeDelta
-                  else actions[Count].Time:= GameTicks + TimeDelta;
-     inc(Count);
-     TryDo(Count < MAXACTIONS, 'AI: actions overflow', true);
-     end
+    begin
+    actions[Count].Action:= Action;
+    actions[Count].Param:= Param;
+    actions[Count].X:= X;
+    actions[Count].Y:= Y;
+    if Count > 0 then
+        actions[Count].Time:= TimeDelta
+    else
+        actions[Count].Time:= GameTicks + TimeDelta;
+    inc(Count);
+    TryDo(Count < MAXACTIONS, 'AI: actions overflow', true);
+    end
 end;
 
 procedure CheckHang(Me: PGear);
@@ -124,18 +130,18 @@
       timedelta: Longword = 0;
 begin
 if hwRound(Me^.X) <> PrevX then
-   begin
-   PrevX:= hwRound(Me^.X);
-   timedelta:= 0
-   end else
-   begin
-   inc(timedelta);
-   if timedelta > 1700 then
-      begin
-      timedelta:= 0;
-      FreeActionsList
-      end
-   end
+    begin
+    PrevX:= hwRound(Me^.X);
+    timedelta:= 0
+    end else
+        begin
+        inc(timedelta);
+        if timedelta > 1700 then
+            begin
+            timedelta:= 0;
+            FreeActionsList
+            end
+        end
 end;
 
 procedure ProcessAction(var Actions: TActions; Me: PGear);
@@ -144,70 +150,101 @@
 repeat
 if Actions.Pos >= Actions.Count then exit;
 with Actions.actions[Actions.Pos] do
-     begin
-     if Time > GameTicks then exit;
-     {$IFDEF TRACEAIACTIONS}
-     DumpAction(Actions.actions[Actions.Pos], Me);
-     {$ENDIF}
-     if (Action and ai_specmask) <> 0 then
+    begin
+    if Time > GameTicks then
+        exit;
+    {$IFDEF TRACEAIACTIONS}
+    DumpAction(Actions.actions[Actions.Pos], Me);
+    {$ENDIF}
+    if (Action and ai_specmask) <> 0 then
         case Action of
-           aia_Weapon: SetWeapon(TAmmoType(Param));
-           aia_WaitXL: if hwRound(Me^.X) = Param then
-                          begin
-                          Action:= aia_LookLeft;
-                          Time:= GameTicks;
-                          exit
-                          end
-                          else if hwRound(Me^.X) < Param then
-                               begin
-                               //OutError('AI: WaitXL assert (' + IntToStr(hwRound(Me^.X)) + ' < ' + IntToStr(Param) + ')', false);
-                               FreeActionsList;
-                               exit
-                               end
-                          else begin CheckHang(Me); exit end;
-           aia_WaitXR: if hwRound(Me^.X) = Param then
-                          begin
-                          Action:= aia_LookRight;
-                          Time:= GameTicks;
-                          exit
-                          end
-                          else if hwRound(Me^.X) > Param then
-                               begin
-                               //OutError('AI: WaitXR assert (' + IntToStr(hwRound(Me^.X)) + ' > ' + IntToStr(Param) + ')', false);
-                               FreeActionsList;
-                               exit
-                               end
-                          else begin CheckHang(Me); exit end;
-         aia_LookLeft: if not Me^.dX.isNegative then
-                          begin
-                          ParseCommand('+left', true);
-                          exit
-                          end else ParseCommand('-left', true);
-        aia_LookRight: if Me^.dX.isNegative then
-                          begin
-                          ParseCommand('+right', true);
-                          exit
-                          end else ParseCommand('-right', true);
-        aia_AwareExpl: AwareOfExplosion(X, Y, Param);
-            aia_HJump: ParseCommand('hjump', true);
-            aia_LJump: ParseCommand('ljump', true);
-             aia_Skip: ParseCommand('skip', true);
-              aia_Put: doPut(X, Y, true);
-             end else
-        begin
-        s:= ActionIdToStr[Action];
-        if (Param and ai_specmask) <> 0 then
-           case Param of
-             aim_push: s:= '+' + s;
-          aim_release: s:= '-' + s;
-             end
-          else if Param <> 0 then s:= s + ' ' + IntToStr(Param);
+            aia_Weapon: 
+            SetWeapon(TAmmoType(Param));
+            
+            aia_WaitXL: 
+            if hwRound(Me^.X) = Param then
+                begin
+                Action:= aia_LookLeft;
+                Time:= GameTicks;
+                exit
+                end
+                else if hwRound(Me^.X) < Param then
+                    begin
+                    //OutError('AI: WaitXL assert (' + IntToStr(hwRound(Me^.X)) + ' < ' + IntToStr(Param) + ')', false);
+                    FreeActionsList;
+                    exit
+                    end
+                else
+                    begin CheckHang(Me);
+                    exit
+                    end;
+                            
+            aia_WaitXR: 
+            if hwRound(Me^.X) = Param then
+                begin
+                Action:= aia_LookRight;
+                Time:= GameTicks;
+                exit
+                end
+                else if hwRound(Me^.X) > Param then
+                    begin
+                    //OutError('AI: WaitXR assert (' + IntToStr(hwRound(Me^.X)) + ' > ' + IntToStr(Param) + ')', false);
+                    FreeActionsList;
+                    exit
+                    end
+                else
+                    begin CheckHang(Me);
+                    exit
+                    end;
+            aia_LookLeft:
+            if not Me^.dX.isNegative then
+                begin
+                ParseCommand('+left', true);
+                exit
+                end
+            else
+                ParseCommand('-left', true);
+            aia_LookRight:
+            if Me^.dX.isNegative then
+                begin
+                ParseCommand('+right', true);
+                exit
+                end
+            else ParseCommand('-right', true);
+            aia_AwareExpl:
+            AwareOfExplosion(X, Y, Param);
+            
+            aia_HJump:
+            ParseCommand('hjump', true);
+            
+            aia_LJump:
+            ParseCommand('ljump', true);
+            
+            aia_Skip:
+            ParseCommand('skip', true);
+            
+            aia_Put:
+            doPut(X, Y, true);
+            end
+        else
+            begin
+            s:= ActionIdToStr[Action];
+            if (Param and ai_specmask) <> 0 then
+                case Param of
+                aim_push:
+                s:= '+' + s;
+                
+                aim_release:
+                s:= '-' + s;
+            end
+        else if Param <> 0 then
+            s:= s + ' ' + IntToStr(Param);
         ParseCommand(s, true)
         end
-     end;
+    end;
 inc(Actions.Pos);
 if Actions.Pos <= Actions.Count then
-   inc(Actions.actions[Actions.Pos].Time, GameTicks);
+    inc(Actions.actions[Actions.Pos].Time, GameTicks);
 until false
 end;
 
--- a/hedgewars/uAIAmmoTests.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uAIAmmoTests.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -24,11 +24,11 @@
 const amtest_OnTurn = $00000001;
 
 type TAttackParams = record
-            Time: Longword;
-            Angle, Power: LongInt;
-            ExplX, ExplY, ExplR: LongInt;
-            AttackPutX, AttackPutY: LongInt;
-            end;
+        Time: Longword;
+        Angle, Power: LongInt;
+        ExplX, ExplY, ExplR: LongInt;
+        AttackPutX, AttackPutY: LongInt;
+        end;
 
 function TestBazooka(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
 function TestSnowball(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
@@ -137,29 +137,31 @@
 ap.ExplR:= 0;
 valueResult:= BadTurn;
 repeat
-  rTime:= rTime + 300 + Level * 50 + random(300);
-  Vx:= - cWindSpeedf * rTime * 0.5 + (Targ.X + AIrndSign(2) - mX) / rTime;
-  Vy:= cGravityf * rTime * 0.5 - (Targ.Y - mY) / rTime;
-  r:= sqrt(sqr(Vx) + sqr(Vy));
-  if not (r > 1) then
-     begin
+    rTime:= rTime + 300 + Level * 50 + random(300);
+    Vx:= - cWindSpeedf * rTime * 0.5 + (Targ.X + AIrndSign(2) - mX) / rTime;
+    Vy:= cGravityf * rTime * 0.5 - (Targ.Y - mY) / rTime;
+    r:= sqrt(sqr(Vx) + sqr(Vy));
+    if not (r > 1) then
+        begin
         x:= mX;
         y:= mY;
         dX:= Vx;
         dY:= -Vy;
         t:= rTime;
         repeat
-              x:= x + dX;
-              y:= y + dY;
-              dX:= dX + cWindSpeedf;
-              dY:= dY + cGravityf;
-              dec(t)
+            x:= x + dX;
+            y:= y + dY;
+            dX:= dX + cWindSpeedf;
+            dY:= dY + cGravityf;
+            dec(t)
         until TestCollExcludingMe(Me, trunc(x), trunc(y), 5) or (t <= 0);
+        
         EX:= trunc(x);
         EY:= trunc(y);
         value:= RateExplosion(Me, EX, EY, 101);
-        if value = 0 then value:= - Metric(Targ.X, Targ.Y, EX, EY) div 64;
-     if valueResult <= value then
+        if value = 0 then
+            value:= - Metric(Targ.X, Targ.Y, EX, EY) div 64;
+    if valueResult <= value then
         begin
         ap.Angle:= DxDy2AttackAngle(Vx, Vy) + AIrndSign(random((Level - 1) * 9));
         ap.Power:= trunc(r * cMaxPower) - random((Level - 1) * 17 + 1);
@@ -168,7 +170,7 @@
         ap.ExplY:= EY;
         valueResult:= value
         end;
-     end
+    end
 until (rTime > 4250);
 TestBazooka:= valueResult
 end;
@@ -188,28 +190,29 @@
 ap.ExplR:= 0;
 valueResult:= BadTurn;
 repeat
-  rTime:= rTime + 300 + Level * 50 + random(300);
-  Vx:= - cWindSpeed * rTime * _0_5 + (int2hwFloat(Targ.X + AIrndSign(2)) - Me^.X) / int2hwFloat(rTime);
-  Vy:= cGravity * rTime * _0_5 - (int2hwFloat(Targ.Y) - Me^.Y) / int2hwFloat(rTime);
-  r:= Distance(Vx, Vy);
-  if not (r > _1) then
-     begin
+    rTime:= rTime + 300 + Level * 50 + random(300);
+    Vx:= - cWindSpeed * rTime * _0_5 + (int2hwFloat(Targ.X + AIrndSign(2)) - Me^.X) / int2hwFloat(rTime);
+    Vy:= cGravity * rTime * _0_5 - (int2hwFloat(Targ.Y) - Me^.Y) / int2hwFloat(rTime);
+    r:= Distance(Vx, Vy);
+    if not (r > _1) then
+        begin
         x:= Me^.X;
         y:= Me^.Y;
         dX:= Vx;
         dY:= -Vy;
         t:= rTime;
         repeat
-          x:= x + dX;
-          y:= y + dY;
-          dX:= dX + cWindSpeed;
-          dY:= dY + cGravity;
-          dec(t)
+            x:= x + dX;
+            y:= y + dY;
+            dX:= dX + cWindSpeed;
+            dY:= dY + cGravity;
+            dec(t)
         until TestCollExcludingMe(Me, hwRound(x), hwRound(y), 5) or (t <= 0);
         EX:= hwRound(x);
         EY:= hwRound(y);
         value:= RateExplosion(Me, EX, EY, 5);
-        if value = 0 then value:= - Metric(Targ.X, Targ.Y, EX, EY) div 64;
+        if value = 0 then
+            value:= - Metric(Targ.X, Targ.Y, EX, EY) div 64;
 
         if valueResult <= value then
             begin
@@ -236,26 +239,28 @@
 TestTime:= 0;
 ap.ExplR:= 0;
 repeat
-  inc(TestTime, 300);
-  Vx:= (int2hwFloat(Targ.X) - Me^.X) / int2hwFloat(TestTime);
-  Vy:= cGravity * (TestTime div 2) - (int2hwFloat(Targ.Y) - Me^.Y) / int2hwFloat(TestTime);
-  r:= Distance(Vx, Vy);
-  if not (r > _1) then
-     begin
+    inc(TestTime, 300);
+    Vx:= (int2hwFloat(Targ.X) - Me^.X) / int2hwFloat(TestTime);
+    Vy:= cGravity * (TestTime div 2) - (int2hwFloat(Targ.Y) - Me^.Y) / int2hwFloat(TestTime);
+    r:= Distance(Vx, Vy);
+    if not (r > _1) then
+        begin
         x:= Me^.X;
         y:= Me^.Y;
         dY:= -Vy;
         t:= TestTime;
         repeat
-          x:= x + Vx;
-          y:= y + dY;
-          dY:= dY + cGravity;
-          dec(t)
+            x:= x + Vx;
+            y:= y + dY;
+            dY:= dY + cGravity;
+            dec(t)
         until TestCollExcludingMe(Me, hwRound(x), hwRound(y), 7) or (t = 0);
         EX:= hwRound(x);
         EY:= hwRound(y);
-        if t < 50 then Score:= RateExplosion(Me, EX, EY, 97)  // average of 17 attempts, most good, but some failing spectacularly
-                  else Score:= BadTurn;
+        if t < 50 then
+            Score:= RateExplosion(Me, EX, EY, 97)  // average of 17 attempts, most good, but some failing spectacularly
+        else
+            Score:= BadTurn;
                   
         if valueResult < Score then
             begin
@@ -267,7 +272,7 @@
             ap.ExplY:= EY;
             valueResult:= Score
             end;
-     end
+        end
 until (TestTime > 4250);
 TestMolotov:= valueResult
 end;
@@ -284,22 +289,22 @@
 TestTime:= 0;
 ap.ExplR:= 0;
 repeat
-  inc(TestTime, 1000);
-  Vx:= (int2hwFloat(Targ.X) - Me^.X) / int2hwFloat(TestTime + tDelta);
-  Vy:= cGravity * ((TestTime + tDelta) div 2) - (int2hwFloat(Targ.Y) - Me^.Y) / int2hwFloat(TestTime + tDelta);
-  r:= Distance(Vx, Vy);
-  if not (r > _1) then
-    begin
-    x:= Me^.X;
-    y:= Me^.Y;
-    dY:= -Vy;
-    t:= TestTime;
-    repeat
-        x:= x + Vx;
-        y:= y + dY;
-        dY:= dY + cGravity;
-        dec(t)
-    until TestCollExcludingMe(Me, hwRound(x), hwRound(y), 5) or (t = 0);
+    inc(TestTime, 1000);
+    Vx:= (int2hwFloat(Targ.X) - Me^.X) / int2hwFloat(TestTime + tDelta);
+    Vy:= cGravity * ((TestTime + tDelta) div 2) - (int2hwFloat(Targ.Y) - Me^.Y) / int2hwFloat(TestTime + tDelta);
+    r:= Distance(Vx, Vy);
+    if not (r > _1) then
+        begin
+        x:= Me^.X;
+        y:= Me^.Y;
+        dY:= -Vy;
+        t:= TestTime;
+        repeat
+            x:= x + Vx;
+            y:= y + dY;
+            dY:= dY + cGravity;
+            dec(t)
+        until TestCollExcludingMe(Me, hwRound(x), hwRound(y), 5) or (t = 0);
     EX:= hwRound(x);
     EY:= hwRound(y);
     if t < 50 then 
@@ -334,20 +339,20 @@
 TestTime:= 0;
 ap.ExplR:= 0;
 repeat
-  inc(TestTime, 1000);
-  // Try to overshoot slightly, seems to pay slightly better dividends in terms of hitting cluster
-  if Me^.X<int2hwFloat(Targ.X) then
-      Vx:= (int2hwFloat(Targ.X+10) - Me^.X) / int2hwFloat(TestTime + tDelta)
-  else
-      Vx:= (int2hwFloat(Targ.X-10) - Me^.X) / int2hwFloat(TestTime + tDelta);
-  Vy:= cGravity * ((TestTime + tDelta) div 2) - (int2hwFloat(Targ.Y-150) - Me^.Y) / int2hwFloat(TestTime + tDelta);
-  r:= Distance(Vx, Vy);
-  if not (r > _1) then
-     begin
-    x:= Me^.X;
-    y:= Me^.Y;
-    dY:= -Vy;
-    t:= TestTime;
+    inc(TestTime, 1000);
+    // Try to overshoot slightly, seems to pay slightly better dividends in terms of hitting cluster
+    if Me^.X<int2hwFloat(Targ.X) then
+        Vx:= (int2hwFloat(Targ.X+10) - Me^.X) / int2hwFloat(TestTime + tDelta)
+    else
+        Vx:= (int2hwFloat(Targ.X-10) - Me^.X) / int2hwFloat(TestTime + tDelta);
+    Vy:= cGravity * ((TestTime + tDelta) div 2) - (int2hwFloat(Targ.Y-150) - Me^.Y) / int2hwFloat(TestTime + tDelta);
+    r:= Distance(Vx, Vy);
+    if not (r > _1) then
+        begin
+        x:= Me^.X;
+        y:= Me^.Y;
+        dY:= -Vy;
+        t:= TestTime;
     repeat
         x:= x + Vx;
         y:= y + dY;
@@ -388,16 +393,16 @@
 TestTime:= 0;
 ap.ExplR:= 0;
 repeat
-  inc(TestTime, 1000);
-  Vx:= (int2hwFloat(Targ.X) - Me^.X) / int2hwFloat(TestTime + tDelta);
-  Vy:= cGravity * ((TestTime + tDelta) div 2) - (int2hwFloat(Targ.Y-200) - Me^.Y) / int2hwFloat(TestTime + tDelta);
-  r:= Distance(Vx, Vy);
-  if not (r > _1) then
-    begin
-    x:= Me^.X;
-    y:= Me^.Y;
-    dY:= -Vy;
-    t:= TestTime;
+    inc(TestTime, 1000);
+    Vx:= (int2hwFloat(Targ.X) - Me^.X) / int2hwFloat(TestTime + tDelta);
+    Vy:= cGravity * ((TestTime + tDelta) div 2) - (int2hwFloat(Targ.Y-200) - Me^.Y) / int2hwFloat(TestTime + tDelta);
+    r:= Distance(Vx, Vy);
+    if not (r > _1) then
+        begin
+        x:= Me^.X;
+        y:= Me^.Y;
+        dY:= -Vy;
+        t:= TestTime;
     repeat
         x:= x + Vx;
         y:= y + dY;
@@ -443,7 +448,9 @@
             else
                 T:= _0;
             Solve:= hwRound(T)
-            end else Solve:= 0
+            end
+            else
+                Solve:= 0
     end;
     
 function TestMortar(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
@@ -456,11 +463,13 @@
 valueResult:= BadTurn;
 ap.ExplR:= 0;
 
-if (Level > 2) then exit(BadTurn);
+if (Level > 2) then
+    exit(BadTurn);
 
 TestTime:= Solve(Targ.X, Targ.Y, hwRound(Me^.X), hwRound(Me^.Y));
 
-if TestTime = 0 then exit(BadTurn);
+if TestTime = 0 then
+    exit(BadTurn);
 
     Vx:= (int2hwFloat(Targ.X) - Me^.X) / int2hwFloat(TestTime);
     Vy:= cGravity * (TestTime div 2) - (int2hwFloat(Targ.Y) - Me^.Y) / int2hwFloat(TestTime);
@@ -485,7 +494,8 @@
                 Score:= - abs(Targ.Y - EY) div 32
             else
                 Score:= BadTurn
-        else if (Score < 0) then Score:= BadTurn
+        else if (Score < 0) then
+            Score:= BadTurn
         end
     else
         Score:= BadTurn;
@@ -505,8 +515,8 @@
 
 function TestShotgun(Me: PGear; Targ: TPoint; Level: LongInt; var ap: TAttackParams): LongInt;
 const
-  MIN_RANGE =  80;
-  MAX_RANGE = 400;
+    MIN_RANGE =  80;
+    MAX_RANGE = 400;
 var Vx, Vy, x, y: hwFloat;
     rx, ry, valueResult: LongInt;
     range: integer;
@@ -517,27 +527,28 @@
 x:= Me^.X;
 y:= Me^.Y;
 range:= Metric(hwRound(x), hwRound(y), Targ.X, Targ.Y);
-if ( range < MIN_RANGE ) or ( range > MAX_RANGE ) then exit(BadTurn);
+if ( range < MIN_RANGE ) or ( range > MAX_RANGE ) then
+    exit(BadTurn);
 Vx:= (int2hwFloat(Targ.X) - x) * _1div1024;
 Vy:= (int2hwFloat(Targ.Y) - y) * _1div1024;
 ap.Angle:= DxDy2AttackAngle(Vx, -Vy);
 repeat
-  x:= x + vX;
-  y:= y + vY;
-  rx:= hwRound(x);
-  ry:= hwRound(y);
-  if TestCollExcludingMe(Me, rx, ry, 2) then
-     begin
-     x:= x + vX * 8;
-     y:= y + vY * 8;
-     valueResult:= RateShotgun(Me, rx, ry);
+    x:= x + vX;
+    y:= y + vY;
+    rx:= hwRound(x);
+    ry:= hwRound(y);
+    if TestCollExcludingMe(Me, rx, ry, 2) then
+        begin
+        x:= x + vX * 8;
+        y:= y + vY * 8;
+        valueResult:= RateShotgun(Me, rx, ry);
      
-     if valueResult = 0 then 
+    if valueResult = 0 then 
         valueResult:= - Metric(Targ.X, Targ.Y, rx, ry) div 64
-        else 
+    else 
         dec(valueResult, Level * 4000);
-     exit(valueResult * 27 div 20) // 27/20 is reuse bonus
-     end
+    exit(valueResult * 27 div 20) // 27/20 is reuse bonus
+    end
 until (Abs(Targ.X - hwRound(x)) + Abs(Targ.Y - hwRound(y)) < 4)
     or (x.isNegative)
     or (y.isNegative)
@@ -567,10 +578,11 @@
 d:= 0;
 
 repeat
-  x:= x + vX;
-  y:= y + vY;
-  if ((hwRound(x) and LAND_WIDTH_MASK) = 0)and((hwRound(y) and LAND_HEIGHT_MASK) = 0)
-     and (Land[hwRound(y), hwRound(x)] <> 0) then inc(d);
+    x:= x + vX;
+    y:= y + vY;
+    if ((hwRound(x) and LAND_WIDTH_MASK) = 0)and((hwRound(y) and LAND_HEIGHT_MASK) = 0)
+    and (Land[hwRound(y), hwRound(x)] <> 0) then
+        inc(d);
 until (Abs(Targ.X - hwRound(x)) + Abs(Targ.Y - hwRound(y)) < 4)
     or (x.isNegative)
     or (y.isNegative)
@@ -578,8 +590,10 @@
     or (y.Round > LongWord(LAND_HEIGHT))
     or (d > 200);
 
-if Abs(Targ.X - hwRound(x)) + Abs(Targ.Y - hwRound(y)) < 3 then valueResult:= Max(0, (4 - d div 50) * 7 * 1024)
-                                                           else valueResult:= BadTurn;
+if Abs(Targ.X - hwRound(x)) + Abs(Targ.Y - hwRound(y)) < 3 then
+    valueResult:= Max(0, (4 - d div 50) * 7 * 1024)
+else
+    valueResult:= BadTurn;
 TestDesertEagle:= valueResult
 end;
 
@@ -590,16 +604,21 @@
 Level:= Level; // avoid compiler hint
 ap.ExplR:= 0;
 if (Level > 2) or (Abs(hwRound(Me^.X) - Targ.X) + Abs(hwRound(Me^.Y) - Targ.Y) > 25) then
-   exit(BadTurn);
+    exit(BadTurn);
 
 ap.Time:= 0;
 ap.Power:= 1;
 x:= Me^.X;
 y:= Me^.Y;
-if (Targ.X) - hwRound(x) >= 0 then ap.Angle:=   cMaxAngle div 4
-                              else ap.Angle:= - cMaxAngle div 4;
+if (Targ.X) - hwRound(x) >= 0 then
+    ap.Angle:=   cMaxAngle div 4
+else
+    ap.Angle:= - cMaxAngle div 4;
 valueResult:= RateShove(Me, hwRound(x) + 10 * hwSign(int2hwFloat(Targ.X) - x), hwRound(y), 15, 30);
-if valueResult <= 0 then valueResult:= BadTurn else inc(valueResult);
+if valueResult <= 0 then
+    valueResult:= BadTurn
+else
+    inc(valueResult);
 TestBaseballBat:= valueResult;
 end;
 
@@ -648,9 +667,10 @@
          
 if (Abs(hwRound(Me^.X) + hwSign(Me^.dX) * 10 - Targ.X) + Abs(hwRound(Me^.Y) - Targ.Y) > 20) then
     rate:= 0
-    else
+else
     rate:= RateHammer(Me);
-if rate = 0 then rate:= BadTurn;
+if rate = 0 then
+    rate:= BadTurn;
 TestHammer:= rate;
 end;
 
@@ -664,7 +684,8 @@
 begin
 ap.ExplR:= 0;
 ap.Time:= 0;
-if (Level > 3) then exit(BadTurn);
+if (Level > 3) then
+    exit(BadTurn);
 
 ap.AttackPutX:= Targ.X;
 ap.AttackPutY:= Targ.Y;
@@ -682,22 +703,22 @@
 valueResult:= 0;
 
 repeat
-  X:= X + cBombsSpeed;
-  Y:= Y + dY;
-  dY:= dY + cGravity;
-  fexit:= true;
+    X:= X + cBombsSpeed;
+    Y:= Y + dY;
+    dY:= dY + cGravity;
+    fexit:= true;
 
-  for i:= 0 to 9 do
-    if b[i] then
-       begin
-       fexit:= false;
-       if TestColl(hwRound(X) + i * 30, hwRound(Y), 4) then
-          begin
-          b[i]:= false;
-          dmg[i]:= RateExplosion(Me, hwRound(X) + i * 30, hwRound(Y), 58)
-          // 58 (instead of 60) for better prediction (hh moves after explosion of one of the rockets)
-          end
-       end;
+    for i:= 0 to 9 do
+        if b[i] then
+            begin
+            fexit:= false;
+            if TestColl(hwRound(X) + i * 30, hwRound(Y), 4) then
+                begin
+                b[i]:= false;
+                dmg[i]:= RateExplosion(Me, hwRound(X) + i * 30, hwRound(Y), 58)
+                // 58 (instead of 60) for better prediction (hh moves after explosion of one of the rockets)
+                end
+            end;
 until fexit or (Y.Round > cWaterLine);
 
 for i:= 0 to 5 do inc(valueResult, dmg[i]);
@@ -709,13 +730,14 @@
     dec(t, dmg[i]);
     inc(t, dmg[i + 6]);
     if t > valueResult then
-       begin
-       valueResult:= t;
-       ap.AttackPutX:= Targ.X - 30 - cShift + i * 30
-       end
+        begin
+        valueResult:= t;
+        ap.AttackPutX:= Targ.X - 30 - cShift + i * 30
+        end
     end;
 
-if valueResult <= 0 then valueResult:= BadTurn;
+if valueResult <= 0 then
+    valueResult:= BadTurn;
 TestAirAttack:= valueResult;
 end;
 
@@ -728,30 +750,38 @@
     TestTeleport := BadTurn;
     Level:= Level; // avoid compiler hint
     FillBonuses(true, [gtCase]);
-    if bonuses.Count = 0 then begin
-        if Me^.Health <= 100  then begin
+    if bonuses.Count = 0 then
+        begin
+        if Me^.Health <= 100  then
+            begin
             maxTop := Targ.Y - cHHRadius * 2;
+            
             while not TestColl(Targ.X, maxTop, cHHRadius) and (maxTop > topY + cHHRadius * 2 + 1) do
-            dec(maxTop, cHHRadius*2);
-            if not TestColl(Targ.X, maxTop + cHHRadius, cHHRadius) then begin
+                dec(maxTop, cHHRadius*2);
+            if not TestColl(Targ.X, maxTop + cHHRadius, cHHRadius) then
+                begin
                 ap.AttackPutX := Targ.X;
                 ap.AttackPutY := maxTop + cHHRadius;
                 TestTeleport := Targ.Y - maxTop;
+                end;
             end;
-        end;
-    end
-    else begin
+        end
+    else
+        begin
         failNum := 0;
         repeat
             i := random(bonuses.Count);
             inc(failNum);
-        until not TestColl(bonuses.ar[i].X, bonuses.ar[i].Y - cHHRadius - bonuses.ar[i].Radius, cHHRadius) or (failNum = bonuses.Count*2);
-        if failNum < bonuses.Count*2 then begin
+        until not TestColl(bonuses.ar[i].X, bonuses.ar[i].Y - cHHRadius - bonuses.ar[i].Radius, cHHRadius)
+        or (failNum = bonuses.Count*2);
+        
+        if failNum < bonuses.Count*2 then
+            begin
             ap.AttackPutX := bonuses.ar[i].X;
             ap.AttackPutY := bonuses.ar[i].Y - cHHRadius - bonuses.ar[i].Radius;
             TestTeleport := 0;
+            end;
         end;
-    end;
 end;
 
 end.
--- a/hedgewars/uAIMisc.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uAIMisc.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -25,24 +25,24 @@
 const MAXBONUS = 1024;
 
 type TTarget = record
-               Point: TPoint;
-               Score: LongInt;
-               end;
-     TTargets = record
-                Count: Longword;
-                ar: array[0..Pred(cMaxHHs)] of TTarget;
-                end;
-     TJumpType = (jmpNone, jmpHJump, jmpLJump);
-     TGoInfo = record
-               Ticks: Longword;
-               FallPix: Longword;
-               JumpType: TJumpType;
-               end;
-     TBonus = record
-              X, Y: LongInt;
-              Radius: LongInt;
-              Score: LongInt;
-              end;
+    Point: TPoint;
+    Score: LongInt;
+    end;
+TTargets = record
+    Count: Longword;
+    ar: array[0..Pred(cMaxHHs)] of TTarget;
+    end;
+TJumpType = (jmpNone, jmpHJump, jmpLJump);
+TGoInfo = record
+    Ticks: Longword;
+    FallPix: Longword;
+    JumpType: TJumpType;
+    end;
+TBonus = record
+    X, Y: LongInt;
+    Radius: LongInt;
+    Score: LongInt;
+    end;
 
 procedure initModule;
 procedure freeModule;
@@ -64,9 +64,9 @@
     Targets: TTargets;
 
     bonuses: record
-             Count: Longword;
-             ar: array[0..Pred(MAXBONUS)] of TBonus;
-             end;
+        Count: Longword;
+        ar: array[0..Pred(MAXBONUS)] of TBonus;
+        end;
 
 implementation
 uses uCollisions, uVariables, uUtils, uDebug;
@@ -75,8 +75,8 @@
 
 var friendlyfactor: LongInt = 300;
     KnownExplosion: record
-                    X, Y, Radius: LongInt
-                    end = (X: 0; Y: 0; Radius: 0);
+        X, Y, Radius: LongInt
+        end = (X: 0; Y: 0; Radius: 0);
 
 procedure FillTargets;
 var i, t: Longword;
@@ -135,35 +135,46 @@
 while Gear <> nil do
     begin
     if (filter = []) or (Gear^.Kind in filter) then
-      case Gear^.Kind of
-          gtCase: AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 33, 25);
-          gtFlame: if (Gear^.State and gsttmpFlag) <> 0 then
-                  AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 20, -50);
+        case Gear^.Kind of
+            gtCase:
+            AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 33, 25);
+            gtFlame:
+                if (Gear^.State and gsttmpFlag) <> 0 then
+                    AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 20, -50);
 // avoid mines unless they are very likely to be duds, or are duds. also avoid if they are about to blow 
-          gtMine:  if ((Gear^.State and gstAttacking) = 0) and 
-                      (((cMineDudPercent < 90) and (Gear^.Health <> 0)) or
-                       (isAfterAttack and (Gear^.Health = 0) and (Gear^.Damage > 30))) then
-                          AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 50, -50)
-                      else if (Gear^.State and gstAttacking) <> 0 then
-                          AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, -50); // mine is on
-          gtExplosives: if isAfterAttack then AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 75, -60+Gear^.Health);
-          gtSMine:    AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 50, -30);
-          gtDynamite: AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -75);
-          gtHedgehog: begin
-                      if Gear^.Damage >= Gear^.Health then
-                          AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 60, -25)
-                      else
-                          if isAfterAttack and (ThinkingHH^.Hedgehog <> Gear^.Hedgehog) then
-                              if (ClansCount > 2) or (MyClan = Gear^.Hedgehog^.Team^.Clan) then
-                                  AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -3) // hedgehog-friend
-                              else
-                                  AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, 3)
-                      end;
-          end;
+            gtMine:
+                if ((Gear^.State and gstAttacking) = 0) and (((cMineDudPercent < 90) and (Gear^.Health <> 0))
+                or (isAfterAttack and (Gear^.Health = 0) and (Gear^.Damage > 30))) then
+                    AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 50, -50)
+                else if (Gear^.State and gstAttacking) <> 0 then
+                    AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, -50); // mine is on
+                    
+            gtExplosives:
+            if isAfterAttack then
+                AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 75, -60+Gear^.Health);
+                
+            gtSMine:
+                AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 50, -30);
+                
+            gtDynamite:
+                AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -75);
+                
+            gtHedgehog:
+                begin
+                if Gear^.Damage >= Gear^.Health then
+                    AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 60, -25)
+                else
+                    if isAfterAttack and (ThinkingHH^.Hedgehog <> Gear^.Hedgehog) then
+                        if (ClansCount > 2) or (MyClan = Gear^.Hedgehog^.Team^.Clan) then
+                            AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 150, -3) // hedgehog-friend
+                        else
+                            AddBonus(hwRound(Gear^.X), hwRound(Gear^.Y), 100, 3)
+                end;
+            end;
     Gear:= Gear^.NextGear
     end;
 if isAfterAttack and (KnownExplosion.Radius > 0) then
-   with KnownExplosion do
+    with KnownExplosion do
         AddBonus(X, Y, Radius + 10, -Radius);
 end;
 
@@ -199,8 +210,8 @@
         MeX:= hwRound(Me^.X);
         MeY:= hwRound(Me^.Y);
         // We are still inside the hog. Skip radius test
-        if ((((x-MeX)*(x-MeX)) + ((y-MeY)*(y-MeY))) < 256) and
-           ((Land[y, x] and $FF00) = 0) then exit(false);
+        if ((((x-MeX)*(x-MeX)) + ((y-MeY)*(y-MeY))) < 256) and ((Land[y, x] and $FF00) = 0) then
+            exit(false);
         end;
     exit(TestColl(x, y, r))
 end;
@@ -209,11 +220,17 @@
 var b: boolean;
 begin
 b:= (((x-r) and LAND_WIDTH_MASK) = 0)and(((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x-r] <> 0);
-if b then exit(true);
+if b then
+    exit(true);
+    
 b:=(((x-r) and LAND_WIDTH_MASK) = 0)and(((y+r) and LAND_HEIGHT_MASK) = 0) and (Land[y+r, x-r] <> 0);
-if b then exit(true);
+if b then
+    exit(true);
+    
 b:=(((x+r) and LAND_WIDTH_MASK) = 0)and(((y-r) and LAND_HEIGHT_MASK) = 0) and (Land[y-r, x+r] <> 0);
-if b then exit(true);
+if b then
+    exit(true);
+    
 TestColl:=(((x+r) and LAND_WIDTH_MASK) = 0)and(((y+r) and LAND_HEIGHT_MASK) = 0) and (Land[y+r, x+r] <> 0)
 end;
 
@@ -223,28 +240,31 @@
 rate:= 0;
 // add our virtual position
 with Targets.ar[Targets.Count] do
-     begin
-     Point.x:= hwRound(Me^.X);
-     Point.y:= hwRound(Me^.Y);
-     Score:= - ThinkingHH^.Health
-     end;
+    begin
+    Point.x:= hwRound(Me^.X);
+    Point.y:= hwRound(Me^.Y);
+    Score:= - ThinkingHH^.Health
+    end;
 // rate explosion
 for i:= 0 to Targets.Count do
     with Targets.ar[i] do
-         begin
-         dmg:= hwRound(_0_01 * cDamageModifier
-            * min((r + cHHRadius div 2 - LongInt(DistanceI(Point.x - x, Point.y - y).Round)) div 2, r) * cDamagePercent);
+        begin
+        dmg:= hwRound(_0_01 * cDamageModifier * min((r + cHHRadius div 2 - LongInt(DistanceI(Point.x - x, Point.y - y).Round)) div 2, r) * cDamagePercent);
 
-         if dmg > 0 then
+        if dmg > 0 then
             begin
             if dmg >= abs(Score) then
-               if Score > 0 then inc(rate, KillScore)
-                            else dec(rate, KillScore * friendlyfactor div 100)
+                if Score > 0 then
+                    inc(rate, KillScore)
+                else
+                    dec(rate, KillScore * friendlyfactor div 100)
             else
-               if Score > 0 then inc(rate, dmg)
-                            else dec(rate, dmg * friendlyfactor div 100)
+                if Score > 0 then
+                    inc(rate, dmg)
+            else
+                dec(rate, dmg * friendlyfactor div 100)
             end;
-         end;
+        end;
 RateExplosion:= rate * 1024;
 end;
 
@@ -255,19 +275,23 @@
 rate:= 0;
 for i:= 0 to Pred(Targets.Count) do
     with Targets.ar[i] do
-         begin
-         dmg:= r - hwRound(DistanceI(Point.x - x, Point.y - y));
-         dmg:= hwRound(_0_01 * cDamageModifier * dmg * cDamagePercent);
-         if dmg > 0 then
+        begin
+        dmg:= r - hwRound(DistanceI(Point.x - x, Point.y - y));
+        dmg:= hwRound(_0_01 * cDamageModifier * dmg * cDamagePercent);
+        if dmg > 0 then
             begin
             if power >= abs(Score) then
-               if Score > 0 then inc(rate, KillScore)
-                            else dec(rate, KillScore * friendlyfactor div 100)
+                if Score > 0 then
+                    inc(rate, KillScore)
+                else
+                    dec(rate, KillScore * friendlyfactor div 100)
             else
-               if Score > 0 then inc(rate, power)
-                            else dec(rate, power * friendlyfactor div 100)
+                if Score > 0 then
+                    inc(rate, power)
+                else
+                    dec(rate, power * friendlyfactor div 100)
             end;
-         end;
+        end;
 RateShove:= rate * 1024
 end;
 
@@ -277,24 +301,27 @@
 rate:= 0;
 // add our virtual position
 with Targets.ar[Targets.Count] do
-     begin
-     Point.x:= hwRound(Me^.X);
-     Point.y:= hwRound(Me^.Y);
-     Score:= - ThinkingHH^.Health
-     end;
+    begin
+    Point.x:= hwRound(Me^.X);
+    Point.y:= hwRound(Me^.Y);
+    Score:= - ThinkingHH^.Health
+    end;
 // rate shot
 for i:= 0 to Targets.Count do
     with Targets.ar[i] do
-         begin
-         dmg:= min(cHHRadius + cShotgunRadius + 4 - hwRound(DistanceI(Point.x - x, Point.y - y)), 25);
-         dmg:= hwRound(_0_01 * cDamageModifier * dmg * cDamagePercent);
-         if dmg > 0 then
+        begin
+        dmg:= min(cHHRadius + cShotgunRadius + 4 - hwRound(DistanceI(Point.x - x, Point.y - y)), 25);
+        dmg:= hwRound(_0_01 * cDamageModifier * dmg * cDamagePercent);
+        if dmg > 0 then
             begin
-                if dmg >= abs(Score) then dmg := KillScore;
-                if Score > 0 then inc(rate, dmg)
-                else dec(rate, dmg * friendlyfactor div 100);
+                if dmg >= abs(Score) then
+                    dmg := KillScore;
+                if Score > 0 then
+                    inc(rate, dmg)
+                else
+                    dec(rate, dmg * friendlyfactor div 100);
             end;
-         end;        
+        end;        
 RateShotgun:= rate * 1024;
 end;
 
@@ -308,16 +335,16 @@
 
 for i:= 0 to Pred(Targets.Count) do
     with Targets.ar[i] do
-         begin
+        begin
          // hammer hit radius is 8, shift is 10
-         r:= hwRound(DistanceI(Point.x - x, Point.y - y));
+        r:= hwRound(DistanceI(Point.x - x, Point.y - y));
 
-         if r <= 18 then
+        if r <= 18 then
             if Score > 0 then 
                 inc(rate, Score div 3)
-                else 
+            else 
                 inc(rate, Score div 3 * friendlyfactor div 100)
-         end;
+        end;
 RateHammer:= rate * 1024;
 end;
 
@@ -331,65 +358,81 @@
 bX:= hwRound(Gear^.X);
 bY:= hwRound(Gear^.Y);
 case JumpType of
-     jmpNone: exit(bRes);
-    jmpHJump: if TestCollisionYwithGear(Gear, -1) = 0 then
-                 begin
-                 Gear^.dY:= -_0_2;
-                 SetLittle(Gear^.dX);
-                 Gear^.State:= Gear^.State or gstMoving or gstHHJumping;
-                 end else exit(bRes);
-    jmpLJump: begin
-              if TestCollisionYwithGear(Gear, -1) <> 0 then
-                 if not TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX)) then Gear^.Y:= Gear^.Y - int2hwFloat(2) else
-                 if not TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX)) then Gear^.Y:= Gear^.Y - _1;
-              if not (TestCollisionXwithGear(Gear, hwSign(Gear^.dX))
-                 or   (TestCollisionYwithGear(Gear, -1) <> 0)) then
-                 begin
-                 Gear^.dY:= -_0_15;
-                 Gear^.dX:= SignAs(_0_15, Gear^.dX);
-                 Gear^.State:= Gear^.State or gstMoving or gstHHJumping
-                 end else exit(bRes)
-              end
+    jmpNone:
+    exit(bRes);
+    
+    jmpHJump:
+    if TestCollisionYwithGear(Gear, -1) = 0 then
+        begin
+        Gear^.dY:= -_0_2;
+        SetLittle(Gear^.dX);
+        Gear^.State:= Gear^.State or gstMoving or gstHHJumping;
+        end
+    else
+        exit(bRes);
+        
+    jmpLJump:
+    begin
+    if TestCollisionYwithGear(Gear, -1) <> 0 then
+          if not TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX)) then
+            Gear^.Y:= Gear^.Y - int2hwFloat(2)
+        else
+            if not TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX)) then
+                Gear^.Y:= Gear^.Y - _1;
+        if not (TestCollisionXwithGear(Gear, hwSign(Gear^.dX))
+        or (TestCollisionYwithGear(Gear, -1) <> 0)) then
+            begin
+            Gear^.dY:= -_0_15;
+            Gear^.dX:= SignAs(_0_15, Gear^.dX);
+            Gear^.State:= Gear^.State or gstMoving or gstHHJumping
+            end
+        else
+            exit(bRes)
+    end
     end;
 
 repeat
-if not (hwRound(Gear^.Y) + cHHRadius < cWaterLine) then exit(bRes);
-if (Gear^.State and gstMoving) <> 0 then
-   begin
-   if (GoInfo.Ticks = 350) then
-      if (not (hwAbs(Gear^.dX) > cLittle)) and (Gear^.dY < -_0_02) then
-         begin
-         Gear^.dY:= -_0_25;
-         Gear^.dX:= SignAs(_0_02, Gear^.dX)
-         end;
-   if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then SetLittle(Gear^.dX);
-   Gear^.X:= Gear^.X + Gear^.dX;
-   inc(GoInfo.Ticks);
-   Gear^.dY:= Gear^.dY + cGravity;
-   if Gear^.dY > _0_4 then exit(bRes);
-   if (Gear^.dY.isNegative)and (TestCollisionYwithGear(Gear, -1) <> 0) then Gear^.dY:= _0;
-   Gear^.Y:= Gear^.Y + Gear^.dY;
-   if (not Gear^.dY.isNegative)and (TestCollisionYwithGear(Gear, 1) <> 0) then
-      begin
-      Gear^.State:= Gear^.State and not (gstMoving or gstHHJumping);
-      Gear^.dY:= _0;
-      case JumpType of
-           jmpHJump: if bY - hwRound(Gear^.Y) > 5 then
-                        begin
-                        bRes:= true;
-                        GoInfo.JumpType:= jmpHJump;
-                        inc(GoInfo.Ticks, 300 + 300) // 300 before jump, 300 after
-                        end;
-           jmpLJump: if abs(bX - hwRound(Gear^.X)) > 30 then
-                        begin
-                        bRes:= true;
-                        GoInfo.JumpType:= jmpLJump;
-                        inc(GoInfo.Ticks, 300 + 300) // 300 before jump, 300 after
-                        end;
-           end;
-      exit(bRes)
-      end;
-   end;
+    if not (hwRound(Gear^.Y) + cHHRadius < cWaterLine) then
+        exit(bRes);
+    if (Gear^.State and gstMoving) <> 0 then
+        begin
+        if (GoInfo.Ticks = 350) then
+            if (not (hwAbs(Gear^.dX) > cLittle)) and (Gear^.dY < -_0_02) then
+                begin
+                Gear^.dY:= -_0_25;
+                Gear^.dX:= SignAs(_0_02, Gear^.dX)
+                end;
+    if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then SetLittle(Gear^.dX);
+        Gear^.X:= Gear^.X + Gear^.dX;
+    inc(GoInfo.Ticks);
+    Gear^.dY:= Gear^.dY + cGravity;
+    if Gear^.dY > _0_4 then
+        exit(bRes);
+    if (Gear^.dY.isNegative)and (TestCollisionYwithGear(Gear, -1) <> 0) then
+        Gear^.dY:= _0;
+    Gear^.Y:= Gear^.Y + Gear^.dY;
+    if (not Gear^.dY.isNegative)and (TestCollisionYwithGear(Gear, 1) <> 0) then
+        begin
+        Gear^.State:= Gear^.State and not (gstMoving or gstHHJumping);
+        Gear^.dY:= _0;
+        case JumpType of
+            jmpHJump:
+            if bY - hwRound(Gear^.Y) > 5 then
+                begin
+                bRes:= true;
+                GoInfo.JumpType:= jmpHJump;
+                inc(GoInfo.Ticks, 300 + 300) // 300 before jump, 300 after
+                end;
+            jmpLJump: if abs(bX - hwRound(Gear^.X)) > 30 then
+                begin
+                bRes:= true;
+                GoInfo.JumpType:= jmpLJump;
+                inc(GoInfo.Ticks, 300 + 300) // 300 before jump, 300 after
+                end
+                end;
+            exit(bRes)
+            end;
+        end;
 until false
 end;
 
@@ -404,84 +447,108 @@
 repeat
 pX:= hwRound(Gear^.X);
 pY:= hwRound(Gear^.Y);
-if pY + cHHRadius >= cWaterLine then exit(false);
+if pY + cHHRadius >= cWaterLine then
+    exit(false);
 if (Gear^.State and gstMoving) <> 0 then
-   begin
-   inc(GoInfo.Ticks);
-   Gear^.dY:= Gear^.dY + cGravity;
-   if Gear^.dY > _0_4 then
-      begin
-      Goinfo.FallPix:= 0;
-      HHJump(AltGear, jmpLJump, GoInfo); // try ljump instead of fall with damage
-      exit(false)
-      end;
-   Gear^.Y:= Gear^.Y + Gear^.dY;
-   if hwRound(Gear^.Y) > pY then inc(GoInfo.FallPix);
-   if TestCollisionYwithGear(Gear, 1) <> 0 then
-      begin
-      inc(GoInfo.Ticks, 410);
-      Gear^.State:= Gear^.State and not (gstMoving or gstHHJumping);
-      Gear^.dY:= _0;
-      HHJump(AltGear, jmpLJump, GoInfo); // try ljump instead of fall
-      exit(true)
-      end;
-   continue
-   end;
-   if (Gear^.Message and gmLeft  )<>0 then Gear^.dX:= -cLittle else
-   if (Gear^.Message and gmRight )<>0 then Gear^.dX:=  cLittle else exit(false);
-   if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then
-      begin
-      if not (TestCollisionXwithXYShift(Gear, _0, -6, hwSign(Gear^.dX))
-         or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1;
-      if not (TestCollisionXwithXYShift(Gear, _0, -5, hwSign(Gear^.dX))
-         or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1;
-      if not (TestCollisionXwithXYShift(Gear, _0, -4, hwSign(Gear^.dX))
-         or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1;
-      if not (TestCollisionXwithXYShift(Gear, _0, -3, hwSign(Gear^.dX))
-         or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1;
-      if not (TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX))
-         or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1;
-      if not (TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX))
-         or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1;
-      end;
+    begin
+    inc(GoInfo.Ticks);
+    Gear^.dY:= Gear^.dY + cGravity;
+    if Gear^.dY > _0_4 then
+        begin
+        Goinfo.FallPix:= 0;
+        HHJump(AltGear, jmpLJump, GoInfo); // try ljump instead of fall with damage
+        exit(false)
+        end;
+    Gear^.Y:= Gear^.Y + Gear^.dY;
+    if hwRound(Gear^.Y) > pY then
+        inc(GoInfo.FallPix);
+    if TestCollisionYwithGear(Gear, 1) <> 0 then
+        begin
+        inc(GoInfo.Ticks, 410);
+        Gear^.State:= Gear^.State and not (gstMoving or gstHHJumping);
+        Gear^.dY:= _0;
+        HHJump(AltGear, jmpLJump, GoInfo); // try ljump instead of fall
+        exit(true)
+        end;
+    continue
+    end;
+    if (Gear^.Message and gmLeft  )<>0 then
+        Gear^.dX:= -cLittle
+    else
+        if (Gear^.Message and gmRight )<>0 then
+             Gear^.dX:=  cLittle
+        else
+                exit(false);
+    if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then
+        begin
+        if not (TestCollisionXwithXYShift(Gear, _0, -6, hwSign(Gear^.dX))
+        or (TestCollisionYwithGear(Gear, -1) <> 0)) then
+            Gear^.Y:= Gear^.Y - _1;
+            
+        if not (TestCollisionXwithXYShift(Gear, _0, -5, hwSign(Gear^.dX))
+        or (TestCollisionYwithGear(Gear, -1) <> 0)) then
+            Gear^.Y:= Gear^.Y - _1;
+            
+        if not (TestCollisionXwithXYShift(Gear, _0, -4, hwSign(Gear^.dX))
+        or (TestCollisionYwithGear(Gear, -1) <> 0)) then
+            Gear^.Y:= Gear^.Y - _1;
+            
+        if not (TestCollisionXwithXYShift(Gear, _0, -3, hwSign(Gear^.dX))
+        or (TestCollisionYwithGear(Gear, -1) <> 0)) then
+            Gear^.Y:= Gear^.Y - _1;
+        if not (TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX))
+        or (TestCollisionYwithGear(Gear, -1) <> 0)) then
+            Gear^.Y:= Gear^.Y - _1;
+            
+        if not (TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX))
+        or (TestCollisionYwithGear(Gear, -1) <> 0)) then
+            Gear^.Y:= Gear^.Y - _1;
+        end;
 
-   if not TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then
-      begin
-      Gear^.X:= Gear^.X + int2hwFloat(hwSign(Gear^.dX));
-      inc(GoInfo.Ticks, cHHStepTicks)
-      end;
-   if TestCollisionYwithGear(Gear, 1) = 0 then
-   begin
-   Gear^.Y:= Gear^.Y + _1;
-   if TestCollisionYwithGear(Gear, 1) = 0 then
-   begin
-   Gear^.Y:= Gear^.Y + _1;
-   if TestCollisionYwithGear(Gear, 1) = 0 then
-   begin
-   Gear^.Y:= Gear^.Y + _1;
-   if TestCollisionYwithGear(Gear, 1) = 0 then
-   begin
-   Gear^.Y:= Gear^.Y + _1;
-   if TestCollisionYwithGear(Gear, 1) = 0 then
-   begin
-   Gear^.Y:= Gear^.Y + _1;
-   if TestCollisionYwithGear(Gear, 1) = 0 then
-   begin
-   Gear^.Y:= Gear^.Y + _1;
-   if TestCollisionYwithGear(Gear, 1) = 0 then
-      begin
-      Gear^.Y:= Gear^.Y - _6;
-      Gear^.dY:= _0;
-      Gear^.State:= Gear^.State or gstMoving
-      end
-   end
-   end
-   end
-   end
-   end
-   end;
+    if not TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then
+        begin
+        Gear^.X:= Gear^.X + int2hwFloat(hwSign(Gear^.dX));
+        inc(GoInfo.Ticks, cHHStepTicks)
+        end;
+        
+    if TestCollisionYwithGear(Gear, 1) = 0 then
+        begin
+        Gear^.Y:= Gear^.Y + _1;
+        
+    if TestCollisionYwithGear(Gear, 1) = 0 then
+          begin
+        Gear^.Y:= Gear^.Y + _1;
+        
+    if TestCollisionYwithGear(Gear, 1) = 0 then
+        begin
+        Gear^.Y:= Gear^.Y + _1;
+
+    if TestCollisionYwithGear(Gear, 1) = 0 then
+        begin
+        Gear^.Y:= Gear^.Y + _1;
+
+    if TestCollisionYwithGear(Gear, 1) = 0 then
+        begin
+        Gear^.Y:= Gear^.Y + _1;
+
+    if TestCollisionYwithGear(Gear, 1) = 0 then
+        begin
+        Gear^.Y:= Gear^.Y + _1;
+
+    if TestCollisionYwithGear(Gear, 1) = 0 then
+        begin
+        Gear^.Y:= Gear^.Y - _6;
+        Gear^.dY:= _0;
+        Gear^.State:= Gear^.State or gstMoving
+        end
+    end
+    end
+    end
+    end
+    end
+    end;
 if (pX <> hwRound(Gear^.X)) and ((Gear^.State and gstMoving) = 0) then
-   exit(true);
+    exit(true);
 until (pX = hwRound(Gear^.X)) and (pY = hwRound(Gear^.Y)) and ((Gear^.State and gstMoving) = 0);
 HHJump(AltGear, jmpHJump, GoInfo);
 HHGo:= false;
@@ -489,8 +556,10 @@
 
 function AIrndSign(num: LongInt): LongInt;
 begin
-if random(2) = 0 then AIrndSign:=   num
-                 else AIrndSign:= - num
+if random(2) = 0 then
+    AIrndSign:=   num
+else
+    AIrndSign:= - num
 end;
 
 procedure initModule;
--- a/hedgewars/uAmmos.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uAmmos.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -67,12 +67,13 @@
 for a:= Low(TAmmoType) to High(TAmmoType) do
     begin
     if cnts[a] > 0 then
-       begin
-       TryDo(mi[Ammoz[a].Slot] <= cMaxSlotAmmoIndex, 'Ammo slot overflow', true);
-       Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]]:= Ammoz[a].Ammo;
-       with Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]] do Count:= cnts[a];
-       inc(mi[Ammoz[a].Slot])
-       end
+        begin
+        TryDo(mi[Ammoz[a].Slot] <= cMaxSlotAmmoIndex, 'Ammo slot overflow', true);
+        Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]]:= Ammoz[a].Ammo;
+        with Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]] do
+            Count:= cnts[a];
+        inc(mi[Ammoz[a].Slot])
+        end
     end
 end;
 
@@ -103,30 +104,36 @@
             cnt:= AMMO_INFINITE;
             Ammoz[a].Probability:= 0
             end;
-        if Ammoz[a].NumberInCase = 0 then Ammoz[a].Probability:= 0;
+        if Ammoz[a].NumberInCase = 0 then
+            Ammoz[a].Probability:= 0;
 
         // avoid things we already have by scheme
         // merge this into DisableSomeWeapons ?
-        if ((a = amLowGravity) and ((GameFlags and gfLowGravity) <> 0)) or
-           ((a = amInvulnerable) and ((GameFlags and gfInvulnerable) <> 0)) or
-           ((a = amLaserSight) and ((GameFlags and gfLaserSight) <> 0)) or
-           ((a = amVampiric) and ((GameFlags and gfVampiric) <> 0)) or
-           ((a = amExtraTime) and (cHedgehogTurnTime >= 1000000)) then
+        if ((a = amLowGravity) and ((GameFlags and gfLowGravity) <> 0))
+        or ((a = amInvulnerable) and ((GameFlags and gfInvulnerable) <> 0))
+        or ((a = amLaserSight) and ((GameFlags and gfLaserSight) <> 0))
+        or ((a = amVampiric) and ((GameFlags and gfVampiric) <> 0))
+        or ((a = amExtraTime) and (cHedgehogTurnTime >= 1000000)) then
             begin
             cnt:= 0;
             Ammoz[a].Probability:= 0
             end;
         ammos[a]:= cnt;
 
-        if ((GameFlags and gfKing) <> 0) and ((GameFlags and gfPlaceHog) = 0) and (Ammoz[a].SkipTurns = 0) and (a <> amTeleport) and (a <> amSkip) then
+        if ((GameFlags and gfKing) <> 0) and ((GameFlags and gfPlaceHog) = 0)
+        and (Ammoz[a].SkipTurns = 0) and (a <> amTeleport) and (a <> amSkip) then
             Ammoz[a].SkipTurns:= 1;
 
-        if ((GameFlags and gfPlaceHog) <> 0) and
-            (a <> amTeleport) and (a <> amSkip) and
-            (Ammoz[a].SkipTurns < 10000) then inc(Ammoz[a].SkipTurns,10000);
-    if ((GameFlags and gfPlaceHog) <> 0) and (a = amTeleport) then ammos[a]:= AMMO_INFINITE
+        if ((GameFlags and gfPlaceHog) <> 0)
+        and (a <> amTeleport) and (a <> amSkip)
+        and (Ammoz[a].SkipTurns < 10000) then
+            inc(Ammoz[a].SkipTurns,10000);
+    if ((GameFlags and gfPlaceHog) <> 0) and (a = amTeleport) then
+        ammos[a]:= AMMO_INFINITE
         end 
-    else ammos[a]:= AMMO_INFINITE;
+        
+    else
+        ammos[a]:= AMMO_INFINITE;
     if ((GameFlags and gfPlaceHog) <> 0) and (a = amTeleport) then 
         InitialCounts[Pred(StoreCnt)][a]:= cnt
     else
@@ -153,9 +160,11 @@
     begin
     slot:= Ammoz[am].Slot;
     ammoidx:= 0;
-    while (ammoidx < cMaxSlotAmmoIndex) and (Ammo^[slot, ammoidx].AmmoType <> am) do inc(ammoidx);
+    while (ammoidx < cMaxSlotAmmoIndex) and (Ammo^[slot, ammoidx].AmmoType <> am) do
+        inc(ammoidx);
     GetAmmoEntry:= @Ammo^[slot, ammoidx];
-    if (Ammo^[slot, ammoidx].AmmoType <> am) then GetAmmoEntry:= GetAmmoEntry(Hedgehog, amNothing)
+    if (Ammo^[slot, ammoidx].AmmoType <> am) then
+        GetAmmoEntry:= GetAmmoEntry(Hedgehog, amNothing)
     end;
 end;
 
@@ -164,18 +173,18 @@
     i: Longword;
 begin
 for t:= 0 to Pred(TeamsCount) do
-   with TeamsArray[t]^ do
-      begin
-      for i:= 0 to cMaxHHIndex do
-          if Hedgehogs[i].Gear <> nil then
-             begin
-             Hedgehogs[i].Ammo:= GetAmmoByNum(Hedgehogs[i].AmmoStore);
-             if (GameFlags and gfPlaceHog) <> 0 then
-                Hedgehogs[i].CurAmmoType:= amTeleport
-             else
-                Hedgehogs[i].CurAmmoType:= amNothing
-             end
-      end
+    with TeamsArray[t]^ do
+        begin
+        for i:= 0 to cMaxHHIndex do
+            if Hedgehogs[i].Gear <> nil then
+                begin
+                Hedgehogs[i].Ammo:= GetAmmoByNum(Hedgehogs[i].AmmoStore);
+                if (GameFlags and gfPlaceHog) <> 0 then
+                    Hedgehogs[i].CurAmmoType:= amTeleport
+                else
+                    Hedgehogs[i].CurAmmoType:= amNothing
+                end
+        end
 end;
 
 procedure AddAmmo(var Hedgehog: THedgehog; ammo: TAmmoType);
@@ -183,8 +192,10 @@
     a: PAmmo;
 begin
 a:= GetAmmoEntry(Hedgehog, ammo);
-if (a^.AmmoType <> amNothing) then cnt:= a^.Count
-else cnt:= 0;
+if (a^.AmmoType <> amNothing) then
+    cnt:= a^.Count
+else
+    cnt:= 0;
 if (cnt <> AMMO_INFINITE) then
     begin
     inc(cnt, Ammoz[ammo].NumberInCase);
@@ -206,7 +217,7 @@
 for slot:= 0 to cMaxSlotIndex do
     for ami:= 0 to cMaxSlotAmmoIndex do
         if hhammo^[slot, ami].Count > 0 then
-           ammos[hhammo^[slot, ami].AmmoType]:= hhammo^[slot, ami].Count;
+            ammos[hhammo^[slot, ami].AmmoType]:= hhammo^[slot, ami].Count;
 
 ammos[ammo]:= cnt;
 if ammos[ammo] > AMMO_INFINITE then ammos[ammo]:= AMMO_INFINITE;
@@ -214,11 +225,11 @@
 FillAmmoStore(hhammo, ammos);
 CurWeapon:= GetAmmoEntry(Hedgehog);
 with Hedgehog, CurWeapon^ do
-        if (Count = 0) or (AmmoType = amNothing) then
-            begin
-            PackAmmo(Ammo, Ammoz[AmmoType].Slot);
-            CurAmmoType:= amNothing
-            end
+    if (Count = 0) or (AmmoType = amNothing) then
+        begin
+        PackAmmo(Ammo, Ammoz[AmmoType].Slot);
+        CurAmmoType:= amNothing
+        end
 end;
 
 procedure PackAmmo(Ammo: PHHAmmo; Slot: LongInt);
@@ -226,17 +237,19 @@
     b: boolean;
 begin
     repeat
-      b:= false;
-      ami:= 0;
-      while (not b) and (ami < cMaxSlotAmmoIndex) do
-          if (Ammo^[Slot, ami].Count = 0)
-             and (Ammo^[Slot, ami + 1].Count > 0) then b:= true
-                                                  else inc(ami);
-      if b then // there is a free item in ammo stack
-         begin
-         Ammo^[Slot, ami]:= Ammo^[Slot, ami + 1];
-         Ammo^[Slot, ami + 1].Count:= 0
-         end;
+        b:= false;
+        ami:= 0;
+        while (not b) and (ami < cMaxSlotAmmoIndex) do
+            if (Ammo^[Slot, ami].Count = 0)
+            and (Ammo^[Slot, ami + 1].Count > 0) then
+                b:= true
+            else
+                inc(ami);
+        if b then // there is a free item in ammo stack
+            begin
+            Ammo^[Slot, ami]:= Ammo^[Slot, ami + 1];
+            Ammo^[Slot, ami + 1].Count:= 0
+            end;
     until not b;
 end;
 
@@ -269,10 +282,10 @@
 Slot:= Ammoz[Ammo].Slot;
 ami:= 0;
 while (ami <= cMaxSlotAmmoIndex) do
-      begin
-      with Hedgehog.Ammo^[Slot, ami] do
+        begin
+        with Hedgehog.Ammo^[Slot, ami] do
             if (AmmoType = Ammo) then
-               exit((Count > 0) and (Hedgehog.Team^.Clan^.TurnNumber > Ammoz[AmmoType].SkipTurns));
+                exit((Count > 0) and (Hedgehog.Team^.Clan^.TurnNumber > Ammoz[AmmoType].SkipTurns));
       inc(ami)
       end;
 HHHasAmmo:= false
@@ -290,8 +303,10 @@
 
     with Hedgehog.Gear^ do
         begin
-        if Angle < CurMinAngle then Angle:= CurMinAngle;
-        if Angle > CurMaxAngle then Angle:= CurMaxAngle;
+        if Angle < CurMinAngle then
+            Angle:= CurMinAngle;
+        if Angle > CurMaxAngle then
+            Angle:= CurMaxAngle;
         end
     end
 end;
@@ -308,11 +323,10 @@
         ((Ammo^[slot, ammoidx].Count = 0) or
         (Ammoz[Ammo^[slot, ammoidx].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber >= 0))
         do
-        begin
-        while (ammoidx <= cMaxSlotAmmoIndex) and
-            ((Ammo^[slot, ammoidx].Count = 0) or
-            (Ammoz[Ammo^[slot, ammoidx].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber >= 0))
-            do inc(ammoidx);
+            begin
+            while (ammoidx <= cMaxSlotAmmoIndex)
+            and ((Ammo^[slot, ammoidx].Count = 0) or (Ammoz[Ammo^[slot, ammoidx].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber >= 0))
+                do inc(ammoidx);
 
         if (ammoidx > cMaxSlotAmmoIndex) then
             begin
@@ -339,7 +353,8 @@
 
     if (CurWeapon^.Count = 0) then
         SwitchToFirstLegalAmmo(Hedgehog)
-    else if CurWeapon^.AmmoType = amNothing then Hedgehog.CurAmmoType:= amNothing;
+    else if CurWeapon^.AmmoType = amNothing then
+        Hedgehog.CurAmmoType:= amNothing;
 
     CurWeapon:= GetAmmoEntry(Hedgehog);
 
@@ -353,11 +368,13 @@
         if (Propz and ammoprop_Timerable) <> 0 then
             s:= s + ', ' + IntToStr(Timer div 1000) + ' ' + trammo[sidSeconds];
         AddCaption(s, Team^.Clan^.Color, capgrpAmmoinfo);
-        if (Propz and ammoprop_NeedTarget) <> 0
-            then begin
+        if (Propz and ammoprop_NeedTarget) <> 0 then
+            begin
             Gear^.State:= Gear^.State or      gstHHChooseTarget;
             isCursorVisible:= true
-            end else begin
+            end
+        else
+            begin
             Gear^.State:= Gear^.State and not gstHHChooseTarget;
             isCursorVisible:= false
             end;
@@ -368,8 +385,8 @@
 procedure SwitchNotHeldAmmo(var Hedgehog: THedgehog);
 begin
 with Hedgehog do
-    if ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_DontHold) <> 0) or
-        (Ammoz[CurAmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber >= 0) then
+    if ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_DontHold) <> 0)
+    or (Ammoz[CurAmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber >= 0) then
         SwitchToFirstLegalAmmo(Hedgehog);
 end;
 
@@ -397,7 +414,8 @@
         end;
 
 for t:= Low(TAmmoType) to High(TAmmoType) do
-    if (Ammoz[t].Ammo.Propz and ammoprop_NotBorder) <> 0 then Ammoz[t].Probability:= 0
+    if (Ammoz[t].Ammo.Propz and ammoprop_NotBorder) <> 0 then
+        Ammoz[t].Probability:= 0
 end;
 
 procedure SetAmmoLoadout(s: shortstring);
@@ -426,14 +444,16 @@
     a: TAmmoType;
 begin
 for t:= 0 to Pred(TeamsCount) do
-   with TeamsArray[t]^ do
-      for i:= 0 to cMaxHHIndex do
-         Hedgehogs[i].CurAmmoType:= amNothing;
+    with TeamsArray[t]^ do
+        for i:= 0 to cMaxHHIndex do
+            Hedgehogs[i].CurAmmoType:= amNothing;
 
-for i:= 0 to Pred(StoreCnt) do FillAmmoStore(StoresList[i], InitialCounts[i]);
+for i:= 0 to Pred(StoreCnt) do
+    FillAmmoStore(StoresList[i], InitialCounts[i]);
 
 for a:= Low(TAmmoType) to High(TAmmoType) do
-    if Ammoz[a].SkipTurns >= 10000 then dec(Ammoz[a].SkipTurns,10000)
+    if Ammoz[a].SkipTurns >= 10000 then
+        dec(Ammoz[a].SkipTurns,10000)
 end;
 
 
@@ -464,7 +484,8 @@
 var i: LongWord;
 begin
     if StoreCnt > 0 then
-        for i:= 0 to Pred(StoreCnt) do Dispose(StoresList[i])
+        for i:= 0 to Pred(StoreCnt) do
+            Dispose(StoresList[i])
 end;
 
 end.
--- a/hedgewars/uCaptions.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uCaptions.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -34,11 +34,11 @@
 uses uTextures, uRenderUtils, uVariables, uRender;
 
 type TCaptionStr = record
-                   Tex: PTexture;
-                   EndTime: LongWord;
-                   Text: shortstring;
-                   Color: Longword
-                   end;
+    Tex: PTexture;
+    EndTime: LongWord;
+    Text: shortstring;
+    Color: Longword
+    end;
 var
     Captions: array[TCapGroup] of TCaptionStr;
 
@@ -69,7 +69,8 @@
 var Group: TCapGroup;
 begin
 for Group:= Low(TCapGroup) to High(TCapGroup) do
-    if unload then FreeTexture(Captions[Group].Tex)
+    if unload then
+        FreeTexture(Captions[Group].Tex)
     else if Captions[Group].Text <> '' then
         Captions[Group].Tex:= RenderStringTex(Captions[Group].Text, Captions[Group].Color, fntBig)
 end;
--- a/hedgewars/uChat.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uChat.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -36,11 +36,11 @@
 const MaxStrIndex = 27;
 
 type TChatLine = record
-        Tex: PTexture;
-        Time: Longword;
-        Width: LongInt;
-        s: shortstring;
-        end;
+    Tex: PTexture;
+    Time: Longword;
+    Width: LongInt;
+    s: shortstring;
+    end;
 
 var Strs: array[0 .. MaxStrIndex] of TChatLine;
     MStrs: array[0 .. MaxStrIndex] of shortstring;
@@ -104,7 +104,8 @@
 procedure ReloadLines;
 var i, t: LongWord;
 begin
-    if InputStr.s <> '' then SetLine(InputStr, InputStr.s, true);
+    if InputStr.s <> '' then
+        SetLine(InputStr, InputStr.s, true);
     for i:= 0 to MaxStrIndex do
         if Strs[i].s <> '' then
             begin
@@ -152,8 +153,7 @@
 r.y:= (visibleCount - t) * 16 + 10;
 r.h:= 16;
 
-if (GameState = gsChat)
-    and (InputStr.Tex <> nil) then
+if (GameState = gsChat) and (InputStr.Tex <> nil) then
     begin
     r.w:= InputStr.Width;
     DrawFillRect(r);
@@ -165,9 +165,8 @@
 
 dec(r.y, 16);
 
-while (((t < 7) and (Strs[i].Time > RealTicks)) or
-       ((t < MaxStrIndex) and showAll)) and
-      (Strs[i].Tex <> nil) do
+while (((t < 7) and (Strs[i].Time > RealTicks)) or ((t < MaxStrIndex) and showAll))
+and (Strs[i].Tex <> nil) do
     begin
     r.w:= Strs[i].Width;
     DrawFillRect(r);
@@ -177,7 +176,11 @@
     DrawTexture(8 - cScreenWidth div 2, (visibleCount - t) * 16 - 6, Strs[i].Tex);
     dec(r.y, 16);
 
-    if i = 0 then i:= MaxStrIndex else dec(i);
+    if i = 0 then
+        i:= MaxStrIndex
+    else
+        dec(i);
+        
     inc(cnt);
     inc(t)
     end;
@@ -198,12 +201,19 @@
 begin
 t:= LocalTeam;
 x:= 0;
-if (s[1] = '"') and (s[Length(s)] = '"') then x:= 1
-else if (s[1] = '''') and (s[Length(s)] = '''') then x:= 2
-else if (s[1] = '-') and (s[Length(s)] = '-') then x:= 3;
+if (s[1] = '"') and (s[Length(s)] = '"')
+    then x:= 1
+    
+else if (s[1] = '''') and (s[Length(s)] = '''') then
+    x:= 2
+    
+else if (s[1] = '-') and (s[Length(s)] = '-') then
+    x:= 3;
+    
 if not CurrentTeam^.ExtDriven and (x <> 0) then
     for c:= 0 to Pred(TeamsCount) do
-        if (TeamsArray[c] = CurrentTeam) then t:= c;
+        if (TeamsArray[c] = CurrentTeam) then
+            t:= c;
 
 if x <> 0 then
     begin
@@ -295,10 +305,14 @@
             GameState:= gsGame;
             end;
     else
-    if (Key < $80) then btw:= 1
-    else if (Key < $800) then btw:= 2
-    else if (Key < $10000) then btw:= 3
-    else btw:= 4;
+        if (Key < $80) then
+            btw:= 1
+        else if (Key < $800) then
+            btw:= 2
+        else if (Key < $10000) then
+            btw:= 3
+        else
+            btw:= 4;
 
     utf8:= '';
 
@@ -310,7 +324,8 @@
 
     utf8:= char(Key or firstByteMark[btw]) + utf8;
 
-    if byte(InputStr.s[0]) + btw > 240 then exit;
+    if byte(InputStr.s[0]) + btw > 240 then
+        exit;
 
     InputStrL[byte(InputStr.s[0]) + btw]:= InputStr.s[0];
     SetLine(InputStr, InputStr.s + utf8, true)
@@ -385,14 +400,16 @@
     missedCount:= 0;
 
     inputStr.Tex := nil;
-    for i:= 0 to MaxStrIndex do Strs[i].Tex := nil;
+    for i:= 0 to MaxStrIndex do
+        Strs[i].Tex := nil;
 end;
 
 procedure freeModule;
 var i: ShortInt;
 begin
     FreeTexture(InputStr.Tex);
-    for i:= 0 to MaxStrIndex do FreeTexture(Strs[i].Tex);
+    for i:= 0 to MaxStrIndex do
+        FreeTexture(Strs[i].Tex);
 end;
 
 end.
--- a/hedgewars/uCollisions.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uCollisions.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -26,9 +26,9 @@
 
 type PGearArray = ^TGearArray;
     TGearArray = record
-            ar: array[0..cMaxGearArrayInd] of PGear;
-            Count: Longword
-            end;
+        ar: array[0..cMaxGearArrayInd] of PGear;
+        Count: Longword
+        end;
 
 procedure initModule;
 procedure freeModule;
@@ -60,9 +60,9 @@
 uses uConsts, uLandGraphics, uVariables, uDebug, uGears, uGearsList;
 
 type TCollisionEntry = record
-            X, Y, Radius: LongInt;
-            cGear: PGear;
-            end;
+    X, Y, Radius: LongInt;
+    cGear: PGear;
+    end;
 
 const MAXRECTSINDEX = 1023;
 var Count: Longword;
@@ -72,7 +72,8 @@
 procedure AddGearCI(Gear: PGear);
 var t: PGear;
 begin
-if Gear^.CollisionIndex >= 0 then exit;
+if Gear^.CollisionIndex >= 0 then
+    exit;
 TryDo(Count <= MAXRECTSINDEX, 'Collision rects array overflow', true);
 with cinfos[Count] do
     begin
@@ -90,7 +91,8 @@
     t:= GearsList;
     while (t <> nil) and (t^.Kind <> gtMine) do 
         t:= t^.NextGear;
-    if (t <> nil) then DeleteGear(t)
+    if (t <> nil) then
+        DeleteGear(t)
     end;
 end;
 
@@ -113,7 +115,8 @@
 begin
 CheckGearsCollision:= @ga;
 ga.Count:= 0;
-if Count = 0 then exit;
+if Count = 0 then
+    exit;
 mx:= hwRound(Gear^.X);
 my:= hwRound(Gear^.Y);
 
@@ -134,29 +137,33 @@
     TestWord: LongWord;
 begin
 if Gear^.IntersectGear <> nil then
-   with Gear^ do
-        if (hwRound(IntersectGear^.X) + IntersectGear^.Radius < hwRound(X) - Radius) or
-           (hwRound(IntersectGear^.X) - IntersectGear^.Radius > hwRound(X) + Radius) then
-           begin
-           IntersectGear:= nil;
-           TestWord:= 0
-           end else
-           TestWord:= 255
-   else TestWord:= 0;
+    with Gear^ do
+        if (hwRound(IntersectGear^.X) + IntersectGear^.Radius < hwRound(X) - Radius)
+        or (hwRound(IntersectGear^.X) - IntersectGear^.Radius > hwRound(X) + Radius) then
+            begin
+            IntersectGear:= nil;
+            TestWord:= 0
+            end
+        else
+            TestWord:= 255
+    else TestWord:= 0;
 
 x:= hwRound(Gear^.X);
-if Dir < 0 then x:= x - Gear^.Radius
-           else x:= x + Gear^.Radius;
+if Dir < 0 then
+    x:= x - Gear^.Radius
+else
+    x:= x + Gear^.Radius;
 if (x and LAND_WIDTH_MASK) = 0 then
-   begin
-   y:= hwRound(Gear^.Y) - Gear^.Radius + 1;
-   i:= y + Gear^.Radius * 2 - 2;
-   repeat
-     if (y and LAND_HEIGHT_MASK) = 0 then
-        if Land[y, x] > TestWord then exit(true);
-     inc(y)
-   until (y > i);
-   end;
+    begin
+    y:= hwRound(Gear^.Y) - Gear^.Radius + 1;
+    i:= y + Gear^.Radius * 2 - 2;
+    repeat
+        if (y and LAND_HEIGHT_MASK) = 0 then
+            if Land[y, x] > TestWord then
+                exit(true);
+        inc(y)
+    until (y > i);
+    end;
 TestCollisionXwithGear:= false
 end;
 
@@ -165,29 +172,34 @@
     TestWord: LongWord;
 begin
 if Gear^.IntersectGear <> nil then
-   with Gear^ do
+    with Gear^ do
         if (hwRound(IntersectGear^.Y) + IntersectGear^.Radius < hwRound(Y) - Radius) or
-           (hwRound(IntersectGear^.Y) - IntersectGear^.Radius > hwRound(Y) + Radius) then
-           begin
-           IntersectGear:= nil;
-           TestWord:= 0
-           end else
-           TestWord:= 255
-   else TestWord:= 0;
+            (hwRound(IntersectGear^.Y) - IntersectGear^.Radius > hwRound(Y) + Radius) then
+                begin
+                IntersectGear:= nil;
+                TestWord:= 0
+                end
+        else
+            TestWord:= 255
+else
+    TestWord:= 0;
 
 y:= hwRound(Gear^.Y);
-if Dir < 0 then y:= y - Gear^.Radius
-           else y:= y + Gear^.Radius;
+if Dir < 0 then
+    y:= y - Gear^.Radius
+else
+    y:= y + Gear^.Radius;
 if (y and LAND_HEIGHT_MASK) = 0 then
-   begin
-   x:= hwRound(Gear^.X) - Gear^.Radius + 1;
-   i:= x + Gear^.Radius * 2 - 2;
-   repeat
-     if (x and LAND_WIDTH_MASK) = 0 then
-        if Land[y, x] > TestWord then exit(Land[y, x]);
+    begin
+    x:= hwRound(Gear^.X) - Gear^.Radius + 1;
+    i:= x + Gear^.Radius * 2 - 2;
+    repeat
+        if (x and LAND_WIDTH_MASK) = 0 then
+            if Land[y, x] > TestWord then
+                exit(Land[y, x]);
      inc(x)
-   until (x > i);
-   end;
+    until (x > i);
+    end;
 TestCollisionYwithGear:= 0
 end;
 
@@ -197,50 +209,55 @@
 begin
 flag:= false;
 x:= hwRound(Gear^.X);
-if Dir < 0 then x:= x - Gear^.Radius
-           else x:= x + Gear^.Radius;
+if Dir < 0 then
+    x:= x - Gear^.Radius
+else
+    x:= x + Gear^.Radius;
 if (x and LAND_WIDTH_MASK) = 0 then
-   begin
-   y:= hwRound(Gear^.Y) - Gear^.Radius + 1;
-   i:= y + Gear^.Radius * 2 - 2;
-   repeat
-     if (y and LAND_HEIGHT_MASK) = 0 then
-           if Land[y, x] > 255 then exit(true)
-           else if Land[y, x] <> 0 then flag:= true;
-     inc(y)
-   until (y > i);
-   end;
+    begin
+    y:= hwRound(Gear^.Y) - Gear^.Radius + 1;
+    i:= y + Gear^.Radius * 2 - 2;
+    repeat
+        if (y and LAND_HEIGHT_MASK) = 0 then
+            if Land[y, x] > 255 then
+                exit(true)
+            else if Land[y, x] <> 0 then
+                flag:= true;
+    inc(y)
+    until (y > i);
+    end;
 TestCollisionXKick:= flag;
 
 if flag then
-   begin
-   if hwAbs(Gear^.dX) < cHHKick then exit;
-   if (Gear^.State and gstHHJumping <> 0)
-   and (hwAbs(Gear^.dX) < _0_4) then exit;
+    begin
+    if hwAbs(Gear^.dX) < cHHKick then
+        exit;
+    if (Gear^.State and gstHHJumping <> 0)
+    and (hwAbs(Gear^.dX) < _0_4) then
+        exit;
 
-   mx:= hwRound(Gear^.X);
-   my:= hwRound(Gear^.Y);
+    mx:= hwRound(Gear^.X);
+    my:= hwRound(Gear^.Y);
 
-   for i:= 0 to Pred(Count) do
-    with cinfos[i] do
-      if (Gear <> cGear) and
-         (sqr(mx - x) + sqr(my - y) <= sqr(Radius + Gear^.Radius + 2)) and
-         ((mx > x) xor (Dir > 0)) then
-         if ((cGear^.Kind in [gtHedgehog, gtMine]) and ((Gear^.State and gstNotKickable) = 0)) or
-            // only apply X kick if the barrel is knocked over
-            ((cGear^.Kind = gtExplosives) and ((cGear^.State and gsttmpflag) <> 0)) then
-             begin
-             with cGear^ do
-                  begin
-                  dX:= Gear^.dX;
-                  dY:= Gear^.dY * _0_5;
-                  State:= State or gstMoving;
-                  Active:= true
-                  end;
-             DeleteCI(cGear);
-             exit(false)
-             end
-   end
+    for i:= 0 to Pred(Count) do
+        with cinfos[i] do
+            if (Gear <> cGear) and (sqr(mx - x) + sqr(my - y) <= sqr(Radius + Gear^.Radius + 2))
+            and ((mx > x) xor (Dir > 0)) then
+                if ((cGear^.Kind in [gtHedgehog, gtMine]) and ((Gear^.State and gstNotKickable) = 0)) or
+                // only apply X kick if the barrel is knocked over
+                ((cGear^.Kind = gtExplosives) and ((cGear^.State and gsttmpflag) <> 0)) then
+                    begin
+                    with cGear^ do
+                        begin
+                        dX:= Gear^.dX;
+                        dY:= Gear^.dY * _0_5;
+                        State:= State or gstMoving;
+                        Active:= true
+                        end;
+                    DeleteCI(cGear);
+                    exit(false)
+                    end
+    end
 end;
 
 function TestCollisionYKick(Gear: PGear; Dir: LongInt): boolean;
@@ -249,50 +266,56 @@
 begin
 flag:= false;
 y:= hwRound(Gear^.Y);
-if Dir < 0 then y:= y - Gear^.Radius
-           else y:= y + Gear^.Radius;
+if Dir < 0 then
+    y:= y - Gear^.Radius
+else
+    y:= y + Gear^.Radius;
 if (y and LAND_HEIGHT_MASK) = 0 then
-   begin
-   x:= hwRound(Gear^.X) - Gear^.Radius + 1;
-   i:= x + Gear^.Radius * 2 - 2;
-   repeat
-     if (x and LAND_WIDTH_MASK) = 0 then
+    begin
+    x:= hwRound(Gear^.X) - Gear^.Radius + 1;
+    i:= x + Gear^.Radius * 2 - 2;
+    repeat
+    if (x and LAND_WIDTH_MASK) = 0 then
         if Land[y, x] > 0 then
-           if Land[y, x] > 255 then exit(true)
-           else if Land[y, x] <> 0 then flag:= true;
-     inc(x)
-   until (x > i);
-   end;
+            if Land[y, x] > 255 then
+                exit(true)
+            else if Land[y, x] <> 0 then
+                flag:= true;
+    inc(x)
+    until (x > i);
+    end;
 TestCollisionYKick:= flag;
 
 if flag then
-   begin
-   if hwAbs(Gear^.dY) < cHHKick then exit(true);
-   if (Gear^.State and gstHHJumping <> 0)
-   and (not Gear^.dY.isNegative)
-   and (Gear^.dY < _0_4) then exit;
+    begin
+    if hwAbs(Gear^.dY) < cHHKick then
+        exit(true);
+    if (Gear^.State and gstHHJumping <> 0)
+    and (not Gear^.dY.isNegative)
+    and (Gear^.dY < _0_4) then
+        exit;
 
-   mx:= hwRound(Gear^.X);
-   my:= hwRound(Gear^.Y);
+    mx:= hwRound(Gear^.X);
+    my:= hwRound(Gear^.Y);
 
-   for i:= 0 to Pred(Count) do
-    with cinfos[i] do
-      if (Gear <> cGear) and
-         (sqr(mx - x) + sqr(my - y) <= sqr(Radius + Gear^.Radius + 2)) and
-         ((my > y) xor (Dir > 0)) then
-         if (cGear^.Kind in [gtHedgehog, gtMine, gtExplosives]) and ((Gear^.State and gstNotKickable) = 0) then
-             begin
-             with cGear^ do
-                  begin
-                  if (Kind <> gtExplosives) or ((State and gsttmpflag) <> 0) then dX:= Gear^.dX * _0_5;
-                  dY:= Gear^.dY;
-                  State:= State or gstMoving;
-                  Active:= true
-                  end;
-             DeleteCI(cGear);
-             exit(false)
-             end
-   end
+    for i:= 0 to Pred(Count) do
+        with cinfos[i] do
+            if (Gear <> cGear) and (sqr(mx - x) + sqr(my - y) <= sqr(Radius + Gear^.Radius + 2))
+            and ((my > y) xor (Dir > 0)) then
+                if (cGear^.Kind in [gtHedgehog, gtMine, gtExplosives]) and ((Gear^.State and gstNotKickable) = 0) then
+                    begin
+                    with cGear^ do
+                        begin
+                        if (Kind <> gtExplosives) or ((State and gsttmpflag) <> 0) then
+                            dX:= Gear^.dX * _0_5;
+                        dY:= Gear^.dY;
+                        State:= State or gstMoving;
+                        Active:= true
+                        end;
+                    DeleteCI(cGear);
+                    exit(false)
+                    end
+    end
 end;
 
 function TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt; withGear: boolean = true): boolean;
@@ -309,18 +332,21 @@
 var x, y, i: LongInt;
 begin
 x:= hwRound(Gear^.X);
-if Dir < 0 then x:= x - Gear^.Radius
-           else x:= x + Gear^.Radius;
+if Dir < 0 then
+    x:= x - Gear^.Radius
+else
+    x:= x + Gear^.Radius;
 if (x and LAND_WIDTH_MASK) = 0 then
-   begin
-   y:= hwRound(Gear^.Y) - Gear^.Radius + 1;
-   i:= y + Gear^.Radius * 2 - 2;
-   repeat
-     if (y and LAND_HEIGHT_MASK) = 0 then
-        if Land[y, x] > 255 then exit(true);
-     inc(y)
-   until (y > i);
-   end;
+    begin
+    y:= hwRound(Gear^.Y) - Gear^.Radius + 1;
+    i:= y + Gear^.Radius * 2 - 2;
+    repeat
+        if (y and LAND_HEIGHT_MASK) = 0 then
+            if Land[y, x] > 255 then
+                exit(true);
+    inc(y)
+    until (y > i);
+    end;
 TestCollisionX:= false
 end;
 
@@ -328,18 +354,21 @@
 var x, y, i: LongInt;
 begin
 y:= hwRound(Gear^.Y);
-if Dir < 0 then y:= y - Gear^.Radius
-           else y:= y + Gear^.Radius;
+if Dir < 0 then
+    y:= y - Gear^.Radius
+else
+    y:= y + Gear^.Radius;
 if (y and LAND_HEIGHT_MASK) = 0 then
-   begin
-   x:= hwRound(Gear^.X) - Gear^.Radius + 1;
-   i:= x + Gear^.Radius * 2 - 2;
-   repeat
-     if (x and LAND_WIDTH_MASK) = 0 then
-        if Land[y, x] > 255 then exit(true);
-     inc(x)
-   until (x > i);
-   end;
+    begin
+    x:= hwRound(Gear^.X) - Gear^.Radius + 1;
+    i:= x + Gear^.Radius * 2 - 2;
+    repeat
+        if (x and LAND_WIDTH_MASK) = 0 then
+            if Land[y, x] > 255 then
+                exit(true);
+    inc(x)
+    until (x > i);
+    end;
 TestCollisionY:= false
 end;
 
@@ -347,8 +376,12 @@
 begin
 Gear^.X:= Gear^.X + int2hwFloat(ShiftX);
 Gear^.Y:= Gear^.Y + int2hwFloat(ShiftY);
-if withGear then TestCollisionYwithXYShift:= TestCollisionYwithGear(Gear, Dir) <> 0
-else TestCollisionYwithXYShift:= TestCollisionY(Gear, Dir);
+
+if withGear then
+  TestCollisionYwithXYShift:= TestCollisionYwithGear(Gear, Dir) <> 0
+else
+  TestCollisionYwithXYShift:= TestCollisionY(Gear, Dir);
+  
 Gear^.X:= Gear^.X - int2hwFloat(ShiftX);
 Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY)
 end;
@@ -363,18 +396,18 @@
     TestWord:= 0;
 
 if x1 > x2 then
-begin
+    begin
     x  := x1;
     x1 := x2;
     x2 := x;
-end;
+  end;
 
 if y1 > y2 then
-begin
+    begin
     y  := y1;
     y1 := y2;
     y2 := y;
-end;
+  end;
 
 if (hasBorder and ((y1 < 0) or (x1 < 0) or (x2 > LAND_WIDTH))) then
     exit(true);
@@ -382,7 +415,7 @@
 for y := y1 to y2 do
     for x := x1 to x2 do
         if ((y and LAND_HEIGHT_MASK) = 0) and ((x and LAND_WIDTH_MASK) = 0)
-          and (Land[y, x] > TestWord) then
+        and (Land[y, x] > TestWord) then
             exit(true);
 
 TestRectancleForObstacle:= false
@@ -442,13 +475,18 @@
                     end;
             end;
 
-        if i = 7 then break;
+        if i = 7 then
+            break;
 
         // prepare offset for next check (clockwise)
-        if (mx = -1) and (my <> -1) then my:= my - 1
-        else if (my = -1) and (mx <> 1) then mx:= mx + 1
-        else if (mx = 1) and (my <> 1) then my:= my + 1
-        else mx:= mx - 1;
+        if (mx = -1) and (my <> -1) then
+            my:= my - 1
+        else if (my = -1) and (mx <> 1) then
+            mx:= mx + 1
+        else if (mx = 1) and (my <> 1) then
+            my:= my + 1
+        else
+            mx:= mx - 1;
 
         end;
 
@@ -475,15 +513,16 @@
                 tmpx:= ldx + k * offset[tmpo,0];
                 tmpy:= ldy + k * offset[tmpo,1];
                 if (((tmpy) and LAND_HEIGHT_MASK) = 0) and (((tmpx) and LAND_WIDTH_MASK)  = 0)
-                    and (Land[tmpy,tmpx] > TestWord) then
-                        begin
-                        ldx:= tmpx;
-                        ldy:= tmpy;
-                        isColl:= true;
-                        break;
-                        end;
+                and (Land[tmpy,tmpx] > TestWord) then
+                    begin
+                    ldx:= tmpx;
+                    ldy:= tmpy;
+                    isColl:= true;
+                    break;
+                    end;
                 end;
-            if isColl then break;
+            if isColl then
+                break;
             end;
 
         jfr:= 8+ri-1;
@@ -498,22 +537,24 @@
                 tmpx:= rdx + k * offset[tmpo,0];
                 tmpy:= rdy + k * offset[tmpo,1];
                 if (((tmpy) and LAND_HEIGHT_MASK) = 0) and (((tmpx) and LAND_WIDTH_MASK)  = 0)
-                    and (Land[tmpy,tmpx] > TestWord) then
-                        begin
-                        rdx:= tmpx;
-                        rdy:= tmpy;
-                        isColl:= true;
-                        break;
-                        end;
+                and (Land[tmpy,tmpx] > TestWord) then
+                    begin
+                    rdx:= tmpx;
+                    rdy:= tmpy;
+                    isColl:= true;
+                    break;
+                    end;
                 end;
-            if isColl then break;
+            if isColl then
+                break;
             end;
         end;
 
     ldx:= rdx - ldx;
     ldy:= rdy - ldy;
 
-    if ((ldx = 0) and (ldy = 0)) then EXIT(false);
+    if ((ldx = 0) and (ldy = 0)) then
+        EXIT(false);
 
 outDeltaX:= ldx;
 outDeltaY:= ldy;
@@ -533,20 +574,20 @@
 isColl:= false;
 
 if (y and LAND_HEIGHT_MASK) = 0 then
-   begin
-   x:= hwRound(Gear^.X) - Gear^.Radius + 1;
-   i:= x + Gear^.Radius * 2 - 2;
-   repeat
-     if (x and LAND_WIDTH_MASK) = 0 then
+    begin
+    x:= hwRound(Gear^.X) - Gear^.Radius + 1;
+    i:= x + Gear^.Radius * 2 - 2;
+    repeat
+    if (x and LAND_WIDTH_MASK) = 0 then
         if Land[y, x] > 255 then
             if not isColl or (abs(x-gx) < abs(collX-gx)) then
                 begin
                 isColl:= true;
                 collX := x;
                 end;
-     inc(x)
-   until (x > i);
-   end;
+    inc(x)
+    until (x > i);
+    end;
 
 if isColl then
     begin
--- a/hedgewars/uCommandHandlers.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uCommandHandlers.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -31,11 +31,12 @@
 procedure chGenCmd(var s: shortstring);
 begin
 case s[1] of
-     'R': if ReadyTimeLeft > 1 then 
-          begin
-          ReadyTimeLeft:= 1;
-          if not CurrentTeam^.ExtDriven then SendIPC('c'+s);
-          end
+    'R': if ReadyTimeLeft > 1 then 
+        begin
+        ReadyTimeLeft:= 1;
+        if not CurrentTeam^.ExtDriven then
+            SendIPC('c'+s);
+        end
     end
 end;
 
@@ -48,7 +49,8 @@
         prevGState:= GameState;
         GameState:= gsConfirm;
         SDL_ShowCursor(1)
-        end else
+        end
+    else
         if GameState = gsConfirm then
             begin
             GameState:= prevGState;
@@ -88,7 +90,8 @@
     if isDeveloperMode then
         begin
         val(s, i, c);
-        if (c <> 0) or (i = 0) then exit;
+        if (c <> 0) or (i = 0) then
+            exit;
         TryDo(i <= cNetProtoVersion, 'Protocol version mismatch: engine is too old (got '+intToStr(i)+', expecting '+intToStr(cNetProtoVersion)+')', true);
         TryDo(i >= cNetProtoVersion, 'Protocol version mismatch: engine is too new (got '+intToStr(i)+', expecting '+intToStr(cNetProtoVersion)+')', true);
     end
@@ -97,39 +100,52 @@
 procedure chTeamLocal(var s: shortstring);
 begin
 s:= s; // avoid compiler hint
-if not isDeveloperMode then exit;
-if CurrentTeam = nil then OutError(errmsgIncorrectUse + ' "/rdriven"', true);
+if not isDeveloperMode then
+    exit;
+if CurrentTeam = nil then
+    OutError(errmsgIncorrectUse + ' "/rdriven"', true);
 CurrentTeam^.ExtDriven:= true
 end;
 
 procedure chGrave(var s: shortstring);
 begin
-if CurrentTeam = nil then OutError(errmsgIncorrectUse + ' "/grave"', true);
-if s[1]='"' then Delete(s, 1, 1);
-if s[byte(s[0])]='"' then Delete(s, byte(s[0]), 1);
+if CurrentTeam = nil then
+    OutError(errmsgIncorrectUse + ' "/grave"', true);
+if s[1]='"' then
+    Delete(s, 1, 1);
+if s[byte(s[0])]='"' then
+    Delete(s, byte(s[0]), 1);
 CurrentTeam^.GraveName:= s
 end;
 
 procedure chFort(var s: shortstring);
 begin
-if CurrentTeam = nil then OutError(errmsgIncorrectUse + ' "/fort"', true);
-if s[1]='"' then Delete(s, 1, 1);
-if s[byte(s[0])]='"' then Delete(s, byte(s[0]), 1);
+if CurrentTeam = nil then
+    OutError(errmsgIncorrectUse + ' "/fort"', true);
+if s[1]='"' then
+    Delete(s, 1, 1);
+if s[byte(s[0])]='"' then
+    Delete(s, byte(s[0]), 1);
 CurrentTeam^.FortName:= s
 end;
 
 procedure chFlag(var s: shortstring);
 begin
-if CurrentTeam = nil then OutError(errmsgIncorrectUse + ' "/flag"', true);
-if s[1]='"' then Delete(s, 1, 1);
-if s[byte(s[0])]='"' then Delete(s, byte(s[0]), 1);
+if CurrentTeam = nil then
+    OutError(errmsgIncorrectUse + ' "/flag"', true);
+if s[1]='"' then
+    Delete(s, 1, 1);
+if s[byte(s[0])]='"' then
+    Delete(s, byte(s[0]), 1);
 CurrentTeam^.flag:= s
 end;
 
 procedure chScript(var s: shortstring);
 begin
-if s[1]='"' then Delete(s, 1, 1);
-if s[byte(s[0])]='"' then Delete(s, byte(s[0]), 1);
+if s[1]='"' then
+    Delete(s, 1, 1);
+if s[byte(s[0])]='"' then
+    Delete(s, byte(s[0]), 1);
 cScriptName:= s;
 ScriptLoad(s)
 end;
@@ -140,9 +156,9 @@
 with CurrentTeam^ do
     begin
     if not CurrentHedgehog^.King then
-    if (s = '') or
-        (((GameFlags and gfKing) <> 0) and (s = 'crown')) or
-        ((Length(s) > 39) and (Copy(s,1,8) = 'Reserved') and (Copy(s,9,32) <> PlayerHash)) then
+    if (s = '')
+    or (((GameFlags and gfKing) <> 0) and (s = 'crown'))
+    or ((Length(s) > 39) and (Copy(s,1,8) = 'Reserved') and (Copy(s,9,32) <> PlayerHash)) then
         CurrentHedgehog^.Hat:= 'NoHat'
     else
         CurrentHedgehog^.Hat:= s
@@ -200,8 +216,10 @@
 procedure chLeft_p(var s: shortstring);
 begin
 s:= s; // avoid compiler hint
-if CheckNoTeamOrHH or isPaused then exit;
-if not CurrentTeam^.ExtDriven then SendIPC('L');
+if CheckNoTeamOrHH or isPaused then
+    exit;
+if not CurrentTeam^.ExtDriven then
+    SendIPC('L');
 bShowFinger:= false;
 with CurrentHedgehog^.Gear^ do
     Message:= Message or (gmLeft and InputMask);
@@ -211,8 +229,10 @@
 procedure chLeft_m(var s: shortstring);
 begin
 s:= s; // avoid compiler hint
-if CheckNoTeamOrHH then exit;
-if not CurrentTeam^.ExtDriven then SendIPC('l');
+if CheckNoTeamOrHH then
+    exit;
+if not CurrentTeam^.ExtDriven then
+    SendIPC('l');
 with CurrentHedgehog^.Gear^ do
     Message:= Message and (not (gmLeft and InputMask));
     ScriptCall('onLeftUp');
@@ -221,8 +241,10 @@
 procedure chRight_p(var s: shortstring);
 begin
 s:= s; // avoid compiler hint
-if CheckNoTeamOrHH or isPaused then exit;
-if not CurrentTeam^.ExtDriven then SendIPC('R');
+if CheckNoTeamOrHH or isPaused then
+    exit;
+if not CurrentTeam^.ExtDriven then
+    SendIPC('R');
 bShowFinger:= false;
 with CurrentHedgehog^.Gear^ do
     Message:= Message or (gmRight and InputMask);
@@ -232,8 +254,10 @@
 procedure chRight_m(var s: shortstring);
 begin
 s:= s; // avoid compiler hint
-if CheckNoTeamOrHH then exit;
-if not CurrentTeam^.ExtDriven then SendIPC('r');
+if CheckNoTeamOrHH then
+    exit;
+if not CurrentTeam^.ExtDriven then
+    SendIPC('r');
 with CurrentHedgehog^.Gear^ do
     Message:= Message and (not (gmRight and InputMask));
     ScriptCall('onRightUp');
@@ -242,8 +266,10 @@
 procedure chUp_p(var s: shortstring);
 begin
 s:= s; // avoid compiler hint
-if CheckNoTeamOrHH or isPaused then exit;
-if not CurrentTeam^.ExtDriven then SendIPC('U');
+if CheckNoTeamOrHH or isPaused then
+    exit;
+if not CurrentTeam^.ExtDriven then
+    SendIPC('U');
 bShowFinger:= false;
 with CurrentHedgehog^.Gear^ do
     Message:= Message or (gmUp and InputMask);
@@ -253,8 +279,10 @@
 procedure chUp_m(var s: shortstring);
 begin
 s:= s; // avoid compiler hint
-if CheckNoTeamOrHH then exit;
-if not CurrentTeam^.ExtDriven then SendIPC('u');
+if CheckNoTeamOrHH then
+    exit;
+if not CurrentTeam^.ExtDriven then
+    SendIPC('u');
 with CurrentHedgehog^.Gear^ do
     Message:= Message and (not (gmUp and InputMask));
     ScriptCall('onUpUp');
@@ -263,8 +291,10 @@
 procedure chDown_p(var s: shortstring);
 begin
 s:= s; // avoid compiler hint
-if CheckNoTeamOrHH or isPaused then exit;
-if not CurrentTeam^.ExtDriven then SendIPC('D');
+if CheckNoTeamOrHH or isPaused then
+    exit;
+if not CurrentTeam^.ExtDriven then
+    SendIPC('D');
 bShowFinger:= false;
 with CurrentHedgehog^.Gear^ do
     Message:= Message or (gmDown and InputMask);
@@ -274,8 +304,10 @@
 procedure chDown_m(var s: shortstring);
 begin
 s:= s; // avoid compiler hint
-if CheckNoTeamOrHH then exit;
-if not CurrentTeam^.ExtDriven then SendIPC('d');
+if CheckNoTeamOrHH then
+    exit;
+if not CurrentTeam^.ExtDriven then
+    SendIPC('d');
 with CurrentHedgehog^.Gear^ do
     Message:= Message and (not (gmDown and InputMask));
     ScriptCall('onDownUp');
@@ -284,8 +316,10 @@
 procedure chPrecise_p(var s: shortstring);
 begin
 s:= s; // avoid compiler hint
-if CheckNoTeamOrHH or isPaused then exit;
-if not CurrentTeam^.ExtDriven then SendIPC('Z');
+if CheckNoTeamOrHH or isPaused then
+    exit;
+if not CurrentTeam^.ExtDriven then
+    SendIPC('Z');
 bShowFinger:= false;
 with CurrentHedgehog^.Gear^ do
     Message:= Message or (gmPrecise and InputMask);
@@ -295,8 +329,10 @@
 procedure chPrecise_m(var s: shortstring);
 begin
 s:= s; // avoid compiler hint
-if CheckNoTeamOrHH then exit;
-if not CurrentTeam^.ExtDriven then SendIPC('z');
+if CheckNoTeamOrHH then
+    exit;
+if not CurrentTeam^.ExtDriven then
+    SendIPC('z');
 with CurrentHedgehog^.Gear^ do
     Message:= Message and (not (gmPrecise and InputMask));
     ScriptCall('onPreciseUp');
@@ -305,8 +341,10 @@
 procedure chLJump(var s: shortstring);
 begin
 s:= s; // avoid compiler hint
-if CheckNoTeamOrHH or isPaused then exit;
-if not CurrentTeam^.ExtDriven then SendIPC('j');
+if CheckNoTeamOrHH or isPaused then
+    exit;
+if not CurrentTeam^.ExtDriven then
+    SendIPC('j');
 bShowFinger:= false;
 with CurrentHedgehog^.Gear^ do
     Message:= Message or (gmLJump and InputMask);
@@ -316,8 +354,10 @@
 procedure chHJump(var s: shortstring);
 begin
 s:= s; // avoid compiler hint
-if CheckNoTeamOrHH or isPaused then exit;
-if not CurrentTeam^.ExtDriven then SendIPC('J');
+if CheckNoTeamOrHH or isPaused then
+    exit;
+if not CurrentTeam^.ExtDriven then
+    SendIPC('J');
 bShowFinger:= false;
 with CurrentHedgehog^.Gear^ do
     Message:= Message or (gmHJump and InputMask);
@@ -327,7 +367,8 @@
 procedure chAttack_p(var s: shortstring);
 begin
 s:= s; // avoid compiler hint
-if CheckNoTeamOrHH or isPaused then exit;
+if CheckNoTeamOrHH or isPaused then
+    exit;
 bShowFinger:= false;
 with CurrentHedgehog^.Gear^ do
     begin
@@ -335,7 +376,8 @@
     if ((State and gstHHDriven) <> 0) then
         begin
         FollowGear:= CurrentHedgehog^.Gear;
-        if not CurrentTeam^.ExtDriven then SendIPC('A');
+        if not CurrentTeam^.ExtDriven then
+            SendIPC('A');
         Message:= Message or (gmAttack and InputMask);
         ScriptCall('onAttack');
         end
@@ -345,11 +387,13 @@
 procedure chAttack_m(var s: shortstring);
 begin
 s:= s; // avoid compiler hint
-if CheckNoTeamOrHH then exit;
+if CheckNoTeamOrHH then
+    exit;
 with CurrentHedgehog^.Gear^ do
     begin
     if not CurrentTeam^.ExtDriven and
-        ((Message and gmAttack) <> 0) then SendIPC('a');
+        ((Message and gmAttack) <> 0) then
+            SendIPC('a');
     Message:= Message and (not (gmAttack and InputMask));
     ScriptCall('onAttackUp');
     end
@@ -358,8 +402,10 @@
 procedure chSwitch(var s: shortstring);
 begin
 s:= s; // avoid compiler hint
-if CheckNoTeamOrHH or isPaused then exit;
-if not CurrentTeam^.ExtDriven then SendIPC('S');
+if CheckNoTeamOrHH or isPaused then
+    exit;
+if not CurrentTeam^.ExtDriven then
+    SendIPC('S');
 bShowFinger:= false;
 with CurrentHedgehog^.Gear^ do
     Message:= Message or (gmSwitch and InputMask);
@@ -371,15 +417,18 @@
     s:= s; // avoid compiler hint
     TryDo(AllInactive, '/nextturn called when not all gears are inactive', true);
 
-    if not CurrentTeam^.ExtDriven then SendIPC('N');
+    if not CurrentTeam^.ExtDriven then
+        SendIPC('N');
     AddFileLog('Doing SwitchHedgehog: time '+inttostr(GameTicks));
 end;
 
 procedure chTimer(var s: shortstring);
 begin
-if (s[0] <> #1) or (s[1] < '1') or (s[1] > '5') or CheckNoTeamOrHH then exit;
+if (s[0] <> #1) or (s[1] < '1') or (s[1] > '5') or CheckNoTeamOrHH then
+    exit;
 
-if not CurrentTeam^.ExtDriven then SendIPC(s);
+if not CurrentTeam^.ExtDriven then
+    SendIPC(s);
 bShowFinger:= false;
 with CurrentHedgehog^.Gear^ do
     begin
@@ -392,10 +441,13 @@
 procedure chSlot(var s: shortstring);
 var slot: LongWord;
 begin
-if (s[0] <> #1) or CheckNoTeamOrHH then exit;
+if (s[0] <> #1) or CheckNoTeamOrHH then
+    exit;
 slot:= byte(s[1]) - 49;
-if slot > cMaxSlotIndex then exit;
-if not CurrentTeam^.ExtDriven then SendIPC(char(byte(s[1]) + 79));
+if slot > cMaxSlotIndex then
+    exit;
+if not CurrentTeam^.ExtDriven then
+    SendIPC(char(byte(s[1]) + 79));
 bShowFinger:= false;
 with CurrentHedgehog^.Gear^ do
     begin
@@ -407,27 +459,33 @@
 
 procedure chSetWeapon(var s: shortstring);
 begin
-    if (s[0] <> #1) or CheckNoTeamOrHH then exit;
+    if (s[0] <> #1) or CheckNoTeamOrHH then
+        exit;
 
-    if TAmmoType(s[1]) > High(TAmmoType) then exit;
+    if TAmmoType(s[1]) > High(TAmmoType) then
+        exit;
 
-    if not CurrentTeam^.ExtDriven then SendIPC('w' + s);
+    if not CurrentTeam^.ExtDriven then
+        SendIPC('w' + s);
 
     with CurrentHedgehog^.Gear^ do
-    begin
+        begin
         Message:= Message or (gmWeapon and InputMask);
         MsgParam:= byte(s[1]);
-    ScriptCall('onSetWeapon');
-    end;
+        ScriptCall('onSetWeapon');
+        end;
 end;
 
 procedure chTaunt(var s: shortstring);
 begin
-if (s[0] <> #1) or CheckNoTeamOrHH then exit;
+if (s[0] <> #1) or CheckNoTeamOrHH then
+    exit;
 
-if TWave(s[1]) > High(TWave) then exit;
+if TWave(s[1]) > High(TWave) then
+    exit;
 
-if not CurrentTeam^.ExtDriven then SendIPC('t' + s);
+if not CurrentTeam^.ExtDriven then
+    SendIPC('t' + s);
 
 with CurrentHedgehog^.Gear^ do
     begin
@@ -472,23 +530,23 @@
 procedure chSetTheme(var s: shortstring);
 begin
 if isDeveloperMode then
-begin
-UserPathz[ptCurrTheme]:= UserPathz[ptThemes] + '/' + s;
-Pathz[ptCurrTheme]:= Pathz[ptThemes] + '/' + s;
-Theme:= s;
-InitStepsFlags:= InitStepsFlags or cifTheme
-end
+    begin
+    UserPathz[ptCurrTheme]:= UserPathz[ptThemes] + '/' + s;
+    Pathz[ptCurrTheme]:= Pathz[ptThemes] + '/' + s;
+    Theme:= s;
+    InitStepsFlags:= InitStepsFlags or cifTheme
+    end
 end;
 
 procedure chSetSeed(var s: shortstring);
 begin
 if isDeveloperMode then
-begin
-SetRandomSeed(s);
-cSeed:= s;
-InitStepsFlags:= InitStepsFlags or cifRandomize
-end
-end;
+    begin
+    SetRandomSeed(s);
+    cSeed:= s;
+    InitStepsFlags:= InitStepsFlags or cifRandomize
+    end
+    end;
 
 procedure chAmmoMenu(var s: shortstring);
 begin
@@ -502,10 +560,15 @@
             begin
             bSelected:= false;
 
-            if bShowAmmoMenu then bShowAmmoMenu:= false
-            else if ((Gear^.State and (gstAttacking or gstAttacked)) <> 0) or
-                    ((MultiShootAttacks > 0) and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_NoRoundEnd) = 0)) or
-                    ((Gear^.State and gstHHDriven) = 0) then begin end else bShowAmmoMenu:= true
+            if bShowAmmoMenu then
+                bShowAmmoMenu:= false
+            else if ((Gear^.State and (gstAttacking or gstAttacked)) <> 0)
+            or ((MultiShootAttacks > 0) and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_NoRoundEnd) = 0))
+            or ((Gear^.State and gstHHDriven) = 0) then
+                begin
+                end
+            else
+                bShowAmmoMenu:= true
             end;
     end
 end;
@@ -525,17 +588,20 @@
 procedure chFindhh(var s: shortstring);
 begin
 s:= s; // avoid compiler hint
-if CheckNoTeamOrHH or isPaused then exit;
+if CheckNoTeamOrHH or isPaused then
+    exit;
 
 if FollowGear <> nil then
     begin
     AddCaption('Auto Camera Off', $CCCCCC, capgrpVolume);
     autoCameraOn:= false
     end
-    else begin
+    else
+        begin
     AddCaption('Auto Camera On', $CCCCCC, capgrpVolume);
     bShowFinger:= true;
-    if not CurrentHedgehog^.Unplaced then FollowGear:= CurrentHedgehog^.Gear;
+    if not CurrentHedgehog^.Unplaced then
+        FollowGear:= CurrentHedgehog^.Gear;
     autoCameraOn:= true
     end
 end;
@@ -555,7 +621,10 @@
 procedure chRotateMask(var s: shortstring);
 begin
 s:= s; // avoid compiler hint
-if ((GameFlags and gfInvulnerable) = 0) then cTagsMask:= cTagsMasks[cTagsMask] else cTagsMask:= cTagsMasksNoHealth[cTagsMask];
+if ((GameFlags and gfInvulnerable) = 0) then
+    cTagsMask:= cTagsMasks[cTagsMask]
+else
+    cTagsMask:= cTagsMasksNoHealth[cTagsMask];
 end;
 
 procedure chSpeedup_p(var s: shortstring);
--- a/hedgewars/uCommands.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uCommands.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -24,7 +24,7 @@
 
 var isDeveloperMode: boolean;
 type TVariableType = (vtCommand, vtLongInt, vtBoolean);
-     TCommandHandler = procedure (var params: shortstring);
+    TCommandHandler = procedure (var params: shortstring);
 
 procedure initModule;
 procedure freeModule;
@@ -36,19 +36,20 @@
 uses Types, uConsts, uVariables, uConsole, uUtils, uDebug;
 
 type  PVariable = ^TVariable;
-      TVariable = record
-                     Next: PVariable;
-                     Name: string[15];
-                    VType: TVariableType;
-                  Handler: pointer;
-                  Trusted: boolean;
-                  end;
+    TVariable = record
+        Next: PVariable;
+        Name: string[15];
+        VType: TVariableType;
+        Handler: pointer;
+        Trusted: boolean;
+        end;
 
 var
-      Variables: PVariable;
+    Variables: PVariable;
 
 procedure RegisterVariable(Name: shortstring; VType: TVariableType; p: pointer; Trusted: boolean);
-var value: PVariable;
+var
+    value: PVariable;
 begin
 New(value);
 TryDo(value <> nil, 'RegisterVariable: value = nil', true);
@@ -58,11 +59,13 @@
 value^.Handler:= p;
 value^.Trusted:= Trusted;
 
-if Variables = nil then Variables:= value
-                   else begin
-                        value^.Next:= Variables;
-                        Variables:= value
-                        end;
+if Variables = nil then
+    Variables:= value
+else
+    begin
+    value^.Next:= Variables;
+    Variables:= value
+    end;
 end;
 
 
@@ -73,56 +76,71 @@
     c: char;
 begin
 //WriteLnToConsole(CmdStr);
-if CmdStr[0]=#0 then exit;
+if CmdStr[0]=#0 then
+    exit;
 c:= CmdStr[1];
-if (c = '/') or (c = '$') then Delete(CmdStr, 1, 1) else c:= '/';
+if (c = '/') or (c = '$') then
+    Delete(CmdStr, 1, 1)
+else
+    c:= '/';
 s:= '';
 SplitBySpace(CmdStr, s);
 AddFileLog('[Cmd] ' + c + CmdStr + ' (' + inttostr(length(s)) + ')');
 t:= Variables;
 while t <> nil do
-      begin
-      if t^.Name = CmdStr then
-         begin
-         if TrustedSource or t^.Trusted then
+    begin
+    if t^.Name = CmdStr then
+        begin
+        if TrustedSource or t^.Trusted then
             case t^.VType of
-              vtCommand: if c='/' then
-                         begin
-                         TCommandHandler(t^.Handler)(s);
-                         end;
-              vtLongInt: if c='$' then
-                         if s[0]=#0 then
-                            begin
-                            str(PLongInt(t^.Handler)^, s);
-                            WriteLnToConsole('$' + CmdStr + ' is "' + s + '"');
-                            end else val(s, PLongInt(t^.Handler)^);
-             vtBoolean: if c='$' then
-                         if s[0]=#0 then
-                            begin
-                            str(ord(boolean(t^.Handler^)), s);
-                            WriteLnToConsole('$' + CmdStr + ' is "' + s + '"');
-                            end else
-                            begin
-                            val(s, ii);
-                            boolean(t^.Handler^):= not (ii = 0)
-                            end;
-              end;
-         exit
-         end else t:= t^.Next
-      end;
+                vtCommand: if c='/' then
+                    begin
+                    TCommandHandler(t^.Handler)(s);
+                    end;
+                vtLongInt: if c='$' then
+                    if s[0]=#0 then
+                        begin
+                        str(PLongInt(t^.Handler)^, s);
+                        WriteLnToConsole('$' + CmdStr + ' is "' + s + '"');
+                        end
+                    else
+                        val(s, PLongInt(t^.Handler)^);
+                vtBoolean: if c='$' then
+                    if s[0]=#0 then
+                        begin
+                        str(ord(boolean(t^.Handler^)), s);
+                        WriteLnToConsole('$' + CmdStr + ' is "' + s + '"');
+                        end
+                    else
+                        begin
+                        val(s, ii);
+                        boolean(t^.Handler^):= not (ii = 0)
+                        end;
+                end;
+            exit
+            end
+        else
+            t:= t^.Next
+        end;
 case c of
-     '$': WriteLnToConsole(errmsgUnknownVariable + ': "$' + CmdStr + '"')
-     else WriteLnToConsole(errmsgUnknownCommand  + ': "/' + CmdStr + '"') end
+    '$': WriteLnToConsole(errmsgUnknownVariable + ': "$' + CmdStr + '"')
+    else
+        WriteLnToConsole(errmsgUnknownCommand  + ': "/' + CmdStr + '"') end
 end;
 
 
 procedure StopMessages(Message: Longword);
 begin
-if (Message and gmLeft) <> 0 then ParseCommand('/-left', true) else
-if (Message and gmRight) <> 0 then ParseCommand('/-right', true) else
-if (Message and gmUp) <> 0 then ParseCommand('/-up', true) else
-if (Message and gmDown) <> 0 then ParseCommand('/-down', true) else
-if (Message and gmAttack) <> 0 then ParseCommand('/-attack', true)
+if (Message and gmLeft) <> 0 then
+    ParseCommand('/-left', true)
+else if (Message and gmRight) <> 0 then
+    ParseCommand('/-right', true) 
+else if (Message and gmUp) <> 0 then
+    ParseCommand('/-up', true)
+else if (Message and gmDown) <> 0 then
+    ParseCommand('/-down', true)
+else if (Message and gmAttack) <> 0 then
+    ParseCommand('/-attack', true)
 end;
 
 procedure initModule;
--- a/hedgewars/uConsole.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uConsole.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -32,12 +32,12 @@
 uses Types, uVariables, uUtils {$IFDEF ANDROID}, log in 'log.pas'{$ENDIF};
 
 const cLineWidth: LongInt = 0;
-      cLinesCount = 8;
+    cLinesCount = 8;
 
 type
-      TTextLine = record
-                  s: shortstring;
-                  end;
+    TTextLine = record
+        s: shortstring
+        end;
 
 var   ConsoleLines: array[byte] of TTextLine;
       CurrLine: LongInt;
@@ -45,7 +45,7 @@
 procedure SetLine(var tl: TTextLine; str: shortstring);
 begin
 with tl do
-     s:= str;
+    s:= str;
 end;
 
 procedure WriteToConsole(s: shortstring);
@@ -55,7 +55,7 @@
 {$IFNDEF NOCONSOLE}
 AddFileLog('[Con] ' + s);
 {$IFDEF ANDROID}
-  Log.__android_log_write(Log.Android_LOG_DEBUG, 'HW_Engine', ShortStringAsPChar('[Con]' + s));
+    Log.__android_log_write(Log.Android_LOG_DEBUG, 'HW_Engine', ShortStringAsPChar('[Con]' + s));
 {$ELSE}
 Write(stderr, s);
 done:= false;
@@ -68,7 +68,8 @@
     if byte(ConsoleLines[CurrLine].s[0]) = cLineWidth then
         begin
         inc(CurrLine);
-        if CurrLine = cLinesCount then CurrLine:= 0;
+        if CurrLine = cLinesCount then
+            CurrLine:= 0;
         PByte(@ConsoleLines[CurrLine].s)^:= 0
         end;
     done:= (Length(s) = 0);
@@ -93,7 +94,8 @@
 
 function ShortStringAsPChar(s: shortstring) : PChar;
 begin
-    if Length(s) = High(s) then Dec(s[0]);
+    if Length(s) = High(s) then
+        Dec(s[0]);
     s[Ord(Length(s))+1] := #0;
     exit(@s[1]);
 end;
--- a/hedgewars/uCursor.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uCursor.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -24,7 +24,8 @@
         CursorPoint.X:= CursorPoint.X + x - cScreenWidth div 2;
         CursorPoint.Y:= CursorPoint.Y - y + cScreenHeight div 2;
 
-        if cHasFocus then SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2);
+        if cHasFocus then
+            SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2);
         end
 end;
 
--- a/hedgewars/uDebug.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uDebug.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -42,12 +42,14 @@
 
 procedure TryDo(Assert: boolean; Msg: shortstring; isFatal: boolean);
 begin
-if not Assert then OutError(Msg, isFatal)
+if not Assert then
+    OutError(Msg, isFatal)
 end;
 
 procedure SDLTry(Assert: boolean; isFatal: boolean);
 begin
-if not Assert then OutError(SDL_GetError, isFatal)
+if not Assert then
+    OutError(SDL_GetError, isFatal)
 end;
 
 end.
--- a/hedgewars/uFloat.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uFloat.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -42,18 +42,18 @@
 {$IFDEF FPC}
 {$IFDEF ENDIAN_LITTLE}
 type hwFloat = record
-               isNegative: boolean;
-               case byte of
-               0: (Frac, Round: Longword);
-               1: (QWordValue : QWord);
-               end;
+    isNegative: boolean;
+    case byte of
+        0: (Frac, Round: Longword);
+        1: (QWordValue : QWord);
+        end;
 {$ELSE}
 type hwFloat = record
-               isNegative: boolean;
-               case byte of
-               0: (Round, Frac: Longword);
-               1: (QWordValue : QWord);
-               end;
+    isNegative: boolean;
+    case byte of
+    0: (Round, Frac: Longword);
+    1: (QWordValue : QWord);
+    end;
 {$ENDIF}
 
 // Returns an hwFloat that represents the value of integer parameter i
@@ -200,7 +200,8 @@
 function hwFloat2Float (const i: hwFloat) : extended;
 begin
 hwFloat2Float:= i.QWordValue / $100000000;
-if i.isNegative then hwFloat2Float:= -hwFloat2Float;
+if i.isNegative then
+    hwFloat2Float:= -hwFloat2Float;
 end;
 
 operator = (const z1, z2: hwFloat) z : boolean; inline;
@@ -212,38 +213,41 @@
 operator + (const z1, z2: hwFloat) z : hwFloat;
 begin
 if z1.isNegative = z2.isNegative then
-   begin
-   z.isNegative:= z1.isNegative;
-   z.QWordValue:= z1.QWordValue + z2.QWordValue
-   end
+    begin
+    z.isNegative:= z1.isNegative;
+    z.QWordValue:= z1.QWordValue + z2.QWordValue
+    end
 else
-   if z1.QWordValue > z2.QWordValue then
-      begin
-      z.isNegative:= z1.isNegative;
-      z.QWordValue:= z1.QWordValue - z2.QWordValue
-      end else
-      begin
-      z.isNegative:= z2.isNegative;
-      z.QWordValue:= z2.QWordValue - z1.QWordValue
-      end
+    if z1.QWordValue > z2.QWordValue then
+        begin
+        z.isNegative:= z1.isNegative;
+        z.QWordValue:= z1.QWordValue - z2.QWordValue
+        end
+    else
+        begin
+        z.isNegative:= z2.isNegative;
+        z.QWordValue:= z2.QWordValue - z1.QWordValue
+        end
 end;
 
 operator - (const z1, z2: hwFloat) z : hwFloat;
 begin
 if z1.isNegative = z2.isNegative then
-   if z1.QWordValue > z2.QWordValue then
-      begin
-      z.isNegative:= z1.isNegative;
-      z.QWordValue:= z1.QWordValue - z2.QWordValue
-      end else
-      begin
-      z.isNegative:= not z2.isNegative;
-      z.QWordValue:= z2.QWordValue - z1.QWordValue
-      end
-else begin
-     z.isNegative:= z1.isNegative;
-     z.QWordValue:= z1.QWordValue + z2.QWordValue
-     end
+    if z1.QWordValue > z2.QWordValue then
+        begin
+        z.isNegative:= z1.isNegative;
+        z.QWordValue:= z1.QWordValue - z2.QWordValue
+        end
+    else
+        begin
+        z.isNegative:= not z2.isNegative;
+        z.QWordValue:= z2.QWordValue - z1.QWordValue
+        end
+else
+    begin
+    z.isNegative:= z1.isNegative;
+    z.QWordValue:= z1.QWordValue + z2.QWordValue
+    end
 end;
 
 operator - (const z1: hwFloat) z : hwFloat;
@@ -256,9 +260,7 @@
 operator * (const z1, z2: hwFloat) z : hwFloat;
 begin
 z.isNegative:= z1.isNegative xor z2.isNegative;
-z.QWordValue:= QWord(z1.Round) * z2.Frac +
-               QWord(z1.Frac) * z2.Round +
-               ((QWord(z1.Frac) * z2.Frac) shr 32);
+z.QWordValue:= QWord(z1.Round) * z2.Frac + QWord(z1.Frac) * z2.Round + ((QWord(z1.Frac) * z2.Frac) shr 32);
 z.Round:= z.Round + QWord(z1.Round) * z2.Round;
 end;
 
@@ -275,18 +277,19 @@
 z.Round:= z1.QWordValue div z2.QWordValue;
 t:= z1 - z2 * z.Round;
 if t.QWordValue = 0 then
-   z.Frac:= 0
+    z.Frac:= 0
 else
-   begin
-   while ((t.QWordValue and $8000000000000000) = 0) and
-         ((z2.QWordValue and $8000000000000000) = 0) do
-         begin
-         t.QWordValue:= t.QWordValue shl 1;
-         z2.QWordValue:= z2.QWordValue shl 1
-         end;
-   if z2.Round > 0 then z.Frac:= (t.QWordValue) div (z2.Round)
-                   else z.Frac:= 0
-   end
+    begin
+    while ((t.QWordValue and $8000000000000000) = 0) and ((z2.QWordValue and $8000000000000000) = 0) do
+        begin
+        t.QWordValue:= t.QWordValue shl 1;
+        z2.QWordValue:= z2.QWordValue shl 1
+        end;
+    if z2.Round > 0 then
+        z.Frac:= (t.QWordValue) div (z2.Round)
+    else
+        z.Frac:= 0
+    end
 end;
 
 operator / (const z1: hwFloat; const z2: LongInt) z : hwFloat;
@@ -298,23 +301,23 @@
 operator < (const z1, z2: hwFloat) b : boolean;
 begin
 if z1.isNegative xor z2.isNegative then
-   b:= z1.isNegative
+    b:= z1.isNegative
 else
-   if z1.QWordValue = z2.QWordValue then
-      b:= false
-   else
-      b:= (z1.QWordValue < z2.QWordValue) xor z1.isNegative
+    if z1.QWordValue = z2.QWordValue then
+        b:= false
+    else
+        b:= (z1.QWordValue < z2.QWordValue) xor z1.isNegative
 end;
 
 operator > (const z1, z2: hwFloat) b : boolean;
 begin
 if z1.isNegative xor z2.isNegative then
-   b:= z2.isNegative
+    b:= z2.isNegative
 else
-   if z1.QWordValue = z2.QWordValue then
-      b:= false
-   else
-      b:= (z1.QWordValue > z2.QWordValue) xor z2.isNegative
+    if z1.QWordValue = z2.QWordValue then
+        b:= false
+    else
+        b:= (z1.QWordValue > z2.QWordValue) xor z2.isNegative
 end;
 
 function cstr(const z: hwFloat): shortstring;
@@ -322,18 +325,21 @@
 begin
 str(z.Round, cstr);
 if z.Frac <> 0 then
-   begin
-   str(z.Frac / $100000000, tmpstr);
-   delete(tmpstr, 1, 2);
-   cstr:= cstr + '.' + copy(tmpstr, 1, 10)
-   end;
-if z.isNegative then cstr:= '-' + cstr
+    begin
+    str(z.Frac / $100000000, tmpstr);
+    delete(tmpstr, 1, 2);
+    cstr:= cstr + '.' + copy(tmpstr, 1, 10)
+    end;
+if z.isNegative then
+    cstr:= '-' + cstr
 end;
 
 function hwRound(const t: hwFloat): LongInt;
 begin
-if t.isNegative then hwRound:= -(t.Round and $7FFFFFFF)
-                else hwRound:= t.Round and $7FFFFFFF
+if t.isNegative then
+    hwRound:= -(t.Round and $7FFFFFFF)
+else
+    hwRound:= t.Round and $7FFFFFFF
 end;
 
 function hwAbs(const t: hwFloat): hwFloat;
@@ -345,10 +351,7 @@
 function hwSqr(const t: hwFloat): hwFloat;
 begin
 hwSqr.isNegative:= false;
-hwSqr.QWordValue:=
-      ((QWord(t.Round) * t.Round) shl 32)
-    + QWord(t.Round) * t.Frac * 2
-    + ((QWord(t.Frac) * t.Frac) shr 32);
+hwSqr.QWordValue:= ((QWord(t.Round) * t.Round) shl 32) + QWord(t.Round) * t.Frac * 2 + ((QWord(t.Frac) * t.Frac) shr 32);
 end;
 
 function hwSqrt(const t: hwFloat): hwFloat;
@@ -358,19 +361,24 @@
 hwSqrt.isNegative:= false;
 
 if t.Round = 0 then
-   begin
-   l:= t.QWordValue;
-   r:= $100000000
-   end else
-   begin
-   l:= $100000000;
-   r:= t.QWordValue div 2 + $80000000; // r:= t / 2 + 0.5
-   if r > $FFFFFFFFFFFF then r:= $FFFFFFFFFFFF
-   end;
+    begin
+    l:= t.QWordValue;
+    r:= $100000000
+    end
+else
+    begin
+    l:= $100000000;
+    r:= t.QWordValue div 2 + $80000000; // r:= t / 2 + 0.5
+    if r > $FFFFFFFFFFFF then
+        r:= $FFFFFFFFFFFF
+    end;
 
 repeat
-  c.QWordValue:= (l + r) div 2;
-  if hwSqr(c).QWordValue > t.QWordValue then r:= c.QWordValue else l:= c.QWordValue
+    c.QWordValue:= (l + r) div 2;
+    if hwSqr(c).QWordValue > t.QWordValue then
+        r:= c.QWordValue
+    else
+        l:= c.QWordValue
 until r - l <= 1;
 
 hwSqrt.QWordValue:= l
@@ -395,7 +403,10 @@
 function hwSign(r: hwFloat): LongInt;
 begin
 // yes, we have negative zero for a reason
-if r.isNegative then hwSign:= -1 else hwSign:= 1
+if r.isNegative then
+    hwSign:= -1
+else
+    hwSign:= 1
 end;
 
 
@@ -403,21 +414,25 @@
 begin
 //TryDo((Angle >= 0) and (Angle <= 2048), 'Sin param exceeds limits', true);
 AngleSin.isNegative:= false;
-if Angle < 1024 then AngleSin.QWordValue:= SinTable[Angle]
-                else AngleSin.QWordValue:= SinTable[2048 - Angle]
+if Angle < 1024 then
+    AngleSin.QWordValue:= SinTable[Angle]
+else
+    AngleSin.QWordValue:= SinTable[2048 - Angle]
 end;
 
 function AngleCos(const Angle: Longword): hwFloat;
 begin
 //TryDo((Angle >= 0) and (Angle <= 2048), 'Cos param exceeds limits', true);
 AngleCos.isNegative:= Angle > 1024;
-if Angle < 1024 then AngleCos.QWordValue:= SinTable[1024 - Angle]
-                else AngleCos.QWordValue:= SinTable[Angle - 1024]
+if Angle < 1024 then
+    AngleCos.QWordValue:= SinTable[1024 - Angle]
+else
+    AngleCos.QWordValue:= SinTable[Angle - 1024]
 end;
 
 function isZero(const z: hwFloat): boolean; inline; 
 begin
-    isZero := z.QWordValue = 0;
+isZero := z.QWordValue = 0;
 end;
 {$ENDIF}
 
--- a/hedgewars/uGame.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uGame.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -24,51 +24,58 @@
 procedure DoGameTick(Lag: LongInt);
 
 ////////////////////
-   implementation
+    implementation
 ////////////////////
 uses uKeys, uTeams, uIO, uAI, uGears, uSound, uMobile, uVisualGears, uTypes, uVariables{$IFDEF SDL13}, uTouch{$ENDIF};
 
 procedure DoGameTick(Lag: LongInt);
 var i: LongInt;
 begin
-if isPaused then exit;
+if isPaused then
+    exit;
 if (not CurrentTeam^.ExtDriven) then
     begin
     NetGetNextCmd; // its for the case of receiving "/say" message
     isInLag:= false;
     SendKeepAliveMessage(Lag)
     end;
-if Lag > 100 then Lag:= 100
-else if (GameType = gmtSave) or (fastUntilLag and (GameType = gmtNet)) then Lag:= 2500;
+if Lag > 100 then
+    Lag:= 100
+else if (GameType = gmtSave) or (fastUntilLag and (GameType = gmtNet)) then
+    Lag:= 2500;
 
 if (GameType = gmtDemo) then 
-    if isSpeed then Lag:= Lag * 10
+    if isSpeed then
+        Lag:= Lag * 10
     else
-        if cOnlyStats then Lag:= High(LongInt);
+        if cOnlyStats then
+            Lag:= High(LongInt);
 PlayNextVoice;
 i:= 1;
 while (GameState <> gsExit) and (i <= Lag) do
     begin
     if not CurrentTeam^.ExtDriven then
-       begin
-       if CurrentHedgehog^.BotLevel <> 0 then ProcessBot;
-       ProcessGears;
-       {$IFDEF SDL13}ProcessTouch;{$ENDIF}
-       end else
-       begin
-       NetGetNextCmd;
-       if isInLag then
-          case GameType of
+        begin
+        if CurrentHedgehog^.BotLevel <> 0 then
+            ProcessBot;
+        ProcessGears;
+        {$IFDEF SDL13}ProcessTouch;{$ENDIF}
+        end
+    else
+        begin
+        NetGetNextCmd;
+        if isInLag then
+            case GameType of
                 gmtNet: begin
                         // just update the health bars
                         AddVisualGear(0, 0, vgtTeamHealthSorter);
                         break;
                         end;
-               gmtDemo: begin
+                gmtDemo: begin
                         GameState:= gsExit;
                         exit
                         end;
-               gmtSave: begin
+                gmtSave: begin
                         RestoreTeamsFromSave;
                         SetBinds(CurrentTeam^.Binds);
                         //CurrentHedgehog^.Gear^.Message:= 0; <- produces bugs with further save restoring and demos
@@ -80,9 +87,9 @@
                         {$IFDEF IPHONEOS}InitIPC;{$ENDIF}
                         uMobile.SaveLoadingEnded();
                         end;
-               end
-          else ProcessGears
-       end;
+                end
+        else ProcessGears
+        end;
     inc(i)
     end
 end;
--- a/hedgewars/uGears.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uGears.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -57,9 +57,9 @@
 
 implementation
 uses uStore, uSound, uTeams, uRandom, uCollisions, uIO, uLandGraphics,
-     uAIMisc, uLocale, uAI, uAmmos, uStats, uVisualGears, uScript, GLunit, uMobile, uVariables,
-     uCommands, uUtils, uTextures, uRenderUtils, uGearsRender, uCaptions, uDebug, uLandTexture,
-     uGearsHedgehog, uGearsUtils, uGearsList;
+    uAIMisc, uLocale, uAI, uAmmos, uStats, uVisualGears, uScript, GLunit, uMobile, uVariables,
+    uCommands, uUtils, uTextures, uRenderUtils, uGearsRender, uCaptions, uDebug, uLandTexture,
+    uGearsHedgehog, uGearsUtils, uGearsList;
 
 
 procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt); forward;
@@ -83,11 +83,12 @@
 Gear:= GearsList;
 while Gear <> nil do
     begin
-    if (Gear^.Kind = gtHedgehog) and (((GameFlags and gfInfAttack) = 0) or ((Gear^.dX.QWordValue < _0_000004.QWordValue) and (Gear^.dY.QWordValue < _0_000004.QWordValue))) then
+    if (Gear^.Kind = gtHedgehog) and (((GameFlags and gfInfAttack) = 0) or ((Gear^.dX.QWordValue < _0_000004.QWordValue)
+    and (Gear^.dY.QWordValue < _0_000004.QWordValue))) then
         begin
-        if (not isInMultiShoot) then inc(Gear^.Damage, Gear^.Karma);
-        if (Gear^.Damage <> 0) and
-        (not Gear^.Invulnerable) then
+        if (not isInMultiShoot) then
+            inc(Gear^.Damage, Gear^.Karma);
+        if (Gear^.Damage <> 0) and (not Gear^.Invulnerable) then
             begin
             CheckNoDamage:= false;
 
@@ -100,11 +101,8 @@
             else
                 dec(Gear^.Health, dmg);
 
-            if (Gear^.Hedgehog^.Team = CurrentTeam) and
-               (Gear^.Damage <> Gear^.Karma) and
-                (not Gear^.Hedgehog^.King) and
-                (not Gear^.Hedgehog^.Effects[hePoisoned]) and
-                (not SuddenDeathDmg) then
+            if (Gear^.Hedgehog^.Team = CurrentTeam) and (Gear^.Damage <> Gear^.Karma)
+            and (not Gear^.Hedgehog^.King) and (not Gear^.Hedgehog^.Effects[hePoisoned]) and (not SuddenDeathDmg) then
                 Gear^.State:= Gear^.State or gstLoser;
 
             spawnHealthTagForHH(Gear, dmg);
@@ -113,7 +111,8 @@
             RecountTeamHealth(Gear^.Hedgehog^.Team);
 
             end;
-        if (not isInMultiShoot) then Gear^.Karma:= 0;
+        if (not isInMultiShoot) then
+            Gear^.Karma:= 0;
         Gear^.Damage:= 0
         end;
     Gear:= Gear^.NextGear
@@ -123,9 +122,9 @@
 procedure HealthMachine;
 var Gear: PGear;
     team: PTeam;
-       i: LongWord;
+    i: LongWord;
     flag: Boolean;
-     tmp: LongWord;
+    tmp: LongWord;
 begin
     Gear:= GearsList;
 
@@ -137,26 +136,28 @@
             if Gear^.Hedgehog^.Effects[hePoisoned] then
                 begin
                 inc(tmp, ModifyDamage(5, Gear));
-                if (GameFlags and gfResetHealth) <> 0 then dec(Gear^.Hedgehog^.InitialHealth)  // does not need a minimum check since <= 1 basically disables it
+                if (GameFlags and gfResetHealth) <> 0 then
+                    dec(Gear^.Hedgehog^.InitialHealth)  // does not need a minimum check since <= 1 basically disables it
                 end;
             if (TotalRounds > cSuddenDTurns - 1) then
                 begin
                 inc(tmp, cHealthDecrease);
-                if (GameFlags and gfResetHealth) <> 0 then dec(Gear^.Hedgehog^.InitialHealth, cHealthDecrease)
+                if (GameFlags and gfResetHealth) <> 0 then
+                    dec(Gear^.Hedgehog^.InitialHealth, cHealthDecrease)
                 end;
             if Gear^.Hedgehog^.King then
                 begin
                 flag:= false;
                 team:= Gear^.Hedgehog^.Team;
                 for i:= 0 to Pred(team^.HedgehogsNumber) do
-                    if (team^.Hedgehogs[i].Gear <> nil) and
-                        (not team^.Hedgehogs[i].King) and
-                        (team^.Hedgehogs[i].Gear^.Health > team^.Hedgehogs[i].Gear^.Damage)
-                    then flag:= true;
+                    if (team^.Hedgehogs[i].Gear <> nil) and (not team^.Hedgehogs[i].King)
+                    and (team^.Hedgehogs[i].Gear^.Health > team^.Hedgehogs[i].Gear^.Damage) then
+                        flag:= true;
                 if not flag then
                     begin
                     inc(tmp, 5);
-                    if (GameFlags and gfResetHealth) <> 0 then dec(Gear^.Hedgehog^.InitialHealth, 5)
+                    if (GameFlags and gfResetHealth) <> 0 then
+                        dec(Gear^.Hedgehog^.InitialHealth, 5)
                     end
                 end;
             if tmp > 0 then 
@@ -172,10 +173,10 @@
 
 procedure ProcessGears;
 const delay: LongWord = 0;
-      delay2: LongWord = 0;
+    delay2: LongWord = 0;
     step: (stDelay, stChDmg, stSweep, stTurnReact,
-            stAfterDelay, stChWin, stWater, stChWin2, stHealth,
-            stSpawn, stNTurn) = stDelay;
+    stAfterDelay, stChWin, stWater, stChWin2, stHealth,
+    stSpawn, stNTurn) = stDelay;
 var Gear, t: PGear;
     i, AliveCount: LongInt;
     s: shortstring;
@@ -215,7 +216,8 @@
 
 if AllInactive then
 case step of
-    stDelay: begin
+    stDelay:
+        begin
         if delay = 0 then
             delay:= cInactDelay
         else
@@ -224,70 +226,90 @@
         if delay = 0 then
             inc(step)
         end;
-    stChDmg: if CheckNoDamage then inc(step) else step:= stDelay;
-    stSweep: if SweepDirty then
-                begin
-                SetAllToActive;
-                step:= stChDmg
-                end else inc(step);
-    stTurnReact: begin
+        
+    stChDmg:
+    if CheckNoDamage then
+        inc(step)
+    else
+        step:= stDelay;
+        
+    stSweep:
+    if SweepDirty then
+        begin
+        SetAllToActive;
+        step:= stChDmg
+        end
+    else
+        inc(step);
+        
+    stTurnReact:
+        begin
         if (not bBetweenTurns) and (not isInMultiShoot) then
             begin
             uStats.TurnReaction;
             inc(step)
-        end else
+            end
+        else
             inc(step, 2);
         end;
-    stAfterDelay: begin
+        
+    stAfterDelay:
+        begin
         if delay = 0 then
             delay:= cInactDelay
         else
             dec(delay);
 
         if delay = 0 then
-        inc(step)
-        end;
-    stChWin: begin
-            CheckForWin;
-            inc(step)
-            end;
-    stWater: if (not bBetweenTurns) and (not isInMultiShoot) then
-                begin
-                if TotalRounds = cSuddenDTurns + 1 then bWaterRising:= true;
-
-                if bWaterRising and (cWaterRise > 0) then
-                    AddGear(0, 0, gtWaterUp, 0, _0, _0, 0)^.Tag:= cWaterRise;
-
-                inc(step)
-                end else inc(step);
-    stChWin2: begin
-            CheckForWin;
             inc(step)
             end;
-    stHealth: begin
-            if (cWaterRise <> 0) or (cHealthDecrease <> 0) then
+    stChWin:
+        begin
+        CheckForWin;
+        inc(step)
+        end;
+    stWater:
+    if (not bBetweenTurns) and (not isInMultiShoot) then
+        begin
+        if TotalRounds = cSuddenDTurns + 1 then
+            bWaterRising:= true;
+        if bWaterRising and (cWaterRise > 0) then
+            AddGear(0, 0, gtWaterUp, 0, _0, _0, 0)^.Tag:= cWaterRise;
+        inc(step)
+        end
+    else
+        inc(step);
+    stChWin2:
+        begin
+        CheckForWin;
+        inc(step)
+        end;
+
+    stHealth:
+        begin
+        if (cWaterRise <> 0) or (cHealthDecrease <> 0) then
+             begin
+            if (TotalRounds = cSuddenDTurns) and (not SuddenDeath) and (not isInMultiShoot) then
                 begin
-                if (TotalRounds = cSuddenDTurns) and (not SuddenDeath) and (not isInMultiShoot) then
+                SuddenDeath:= true;
+                if cHealthDecrease <> 0 then
                     begin
-                    SuddenDeath:= true;
-                    if cHealthDecrease <> 0 then
-                        begin
-                        SuddenDeathDmg:= true;
+                    SuddenDeathDmg:= true;
                         
-                        // flash
-                        ScreenFade:= sfFromWhite;
-                        ScreenFadeValue:= sfMax;
-                        ScreenFadeSpeed:= 1;
-                        
-                        ChangeToSDClouds;
-                        ChangeToSDFlakes;
-                        glClearColor(SDSkyColor.r * (SDTint/255) / 255, SDSkyColor.g * (SDTint/255) / 255, SDSkyColor.b * (SDTint/255) / 255, 0.99);
-                        Ammoz[amTardis].SkipTurns:= 9999;
-                        Ammoz[amTardis].Probability:= 0;
-                        end;
-                    AddCaption(trmsg[sidSuddenDeath], cWhiteColor, capgrpGameState);
-                    playSound(sndSuddenDeath);
-                    StopMusic //No SDMusic for now
+                    // flash
+                    ScreenFade:= sfFromWhite;
+                    ScreenFadeValue:= sfMax;
+                    ScreenFadeSpeed:= 1;
+                    
+                    ChangeToSDClouds;
+                    ChangeToSDFlakes;
+                    glClearColor(SDSkyColor.r * (SDTint/255) / 255, SDSkyColor.g * (SDTint/255) / 255, SDSkyColor.b * (SDTint/255) / 255, 0.99);
+                    Ammoz[amTardis].SkipTurns:= 9999;
+                    Ammoz[amTardis].Probability:= 0;
+                    end;
+                AddCaption(trmsg[sidSuddenDeath], cWhiteColor, capgrpGameState);
+                playSound(sndSuddenDeath);
+                StopMusic //No SDMusic for now
                     //MusicFN:= SDMusic;
                     //ChangeMusic
                     end
@@ -302,29 +324,36 @@
                     end;
                 end;
             if bBetweenTurns
-                or isInMultiShoot
-                or (TotalRounds = -1) then inc(step)
-            else begin
+            or isInMultiShoot
+            or (TotalRounds = -1) then
+                inc(step)
+            else
+                begin
                 bBetweenTurns:= true;
                 HealthMachine;
                 step:= stChDmg
                 end
             end;
-    stSpawn: begin
-            if not isInMultiShoot then SpawnBoxOfSmth;
-            inc(step)
-            end;
-    stNTurn: begin
-            if isInMultiShoot then
-                isInMultiShoot:= false
-            else begin
-                // delayed till after 0.9.12
-                // reset to default zoom
-                //ZoomValue:= ZoomDefault;
-                with CurrentHedgehog^ do
-                    if (Gear <> nil)
-                        and ((Gear^.State and gstAttacked) = 0)
-                        and (MultiShootAttacks > 0) then OnUsedAmmo(CurrentHedgehog^);
+    stSpawn:
+        begin
+        if not isInMultiShoot then
+            SpawnBoxOfSmth;
+        inc(step)
+        end;
+    stNTurn:
+        begin
+        if isInMultiShoot then
+            isInMultiShoot:= false
+        else
+            begin
+            // delayed till after 0.9.12
+            // reset to default zoom
+            //ZoomValue:= ZoomDefault;
+            with CurrentHedgehog^ do
+                if (Gear <> nil)
+                and ((Gear^.State and gstAttacked) = 0)
+                and (MultiShootAttacks > 0) then
+                    OnUsedAmmo(CurrentHedgehog^);
 
                 EndTurnCleanup;
 
@@ -347,9 +376,11 @@
         begin
         dec(delay2);
 
-        if ((delay2 mod cInactDelay) = 0) and (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil) and (not CurrentHedgehog^.Unplaced) then
+        if ((delay2 mod cInactDelay) = 0) and (CurrentHedgehog <> nil) and (CurrentHedgehog^.Gear <> nil)
+        and (not CurrentHedgehog^.Unplaced) then
             begin
-            if (CurrentHedgehog^.Gear^.State and gstAttacked <> 0) and (Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NeedTarget <> 0) then
+            if (CurrentHedgehog^.Gear^.State and gstAttacked <> 0)
+            and (Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NeedTarget <> 0) then
                 begin
                 CurrentHedgehog^.Gear^.State:= CurrentHedgehog^.Gear^.State or gstHHChooseTarget;
                 isCursorVisible := true
@@ -358,15 +389,19 @@
             end;
         if delay2 = 0 then
             begin
-            if (CurrentHedgehog^.Gear <> nil) and (CurrentHedgehog^.Gear^.State and gstAttacked = 0) and (CurAmmoGear = nil) then SweepDirty;
+            if (CurrentHedgehog^.Gear <> nil) and (CurrentHedgehog^.Gear^.State and gstAttacked = 0)
+            and (CurAmmoGear = nil) then
+                SweepDirty;
             CheckNoDamage;
             AliveCount:= 0; // shorter version of check for win to allow typical step activity to proceed
             for i:= 0 to Pred(ClansCount) do
-                if ClansArray[i]^.ClanHealth > 0 then inc(AliveCount);
+                if ClansArray[i]^.ClanHealth > 0 then
+                    inc(AliveCount);
             if (AliveCount <= 1) and ((GameFlags and gfOneClanMode) = 0) then
                 begin
                 step:= stChDmg;
-                if TagTurnTimeLeft = 0 then TagTurnTimeLeft:= TurnTimeLeft;
+                if TagTurnTimeLeft = 0 then
+                    TagTurnTimeLeft:= TurnTimeLeft;
                 TurnTimeLeft:= 0
                 end
             end
@@ -374,29 +409,30 @@
     end;
 
 if TurnTimeLeft > 0 then
-        if CurrentHedgehog^.Gear <> nil then
-            if ((CurrentHedgehog^.Gear^.State and gstAttacking) = 0)
-                and (not isInMultiShoot) then
+    if CurrentHedgehog^.Gear <> nil then
+        if ((CurrentHedgehog^.Gear^.State and gstAttacking) = 0)
+            and (not isInMultiShoot) then
                 begin
                 if (TurnTimeLeft = 5000)
-                    and (cHedgehogTurnTime >= 10000)
-                    and (not PlacingHogs)
-                    and (CurrentHedgehog^.Gear <> nil)
-                    and ((CurrentHedgehog^.Gear^.State and gstAttacked) = 0) then
-                        AddVoice(sndHurry, CurrentTeam^.voicepack);
-                if ReadyTimeLeft > 0 then
-                    begin
-                    if ReadyTimeLeft = 2000 then
-                        AddVoice(sndComeonthen, CurrentTeam^.voicepack);
-                    dec(ReadyTimeLeft)
-                    end
-                else
-                    dec(TurnTimeLeft)
-                end;
+                and (cHedgehogTurnTime >= 10000)
+                and (not PlacingHogs)
+                and (CurrentHedgehog^.Gear <> nil)
+                and ((CurrentHedgehog^.Gear^.State and gstAttacked) = 0) then
+                    AddVoice(sndHurry, CurrentTeam^.voicepack);
+            if ReadyTimeLeft > 0 then
+                begin
+                if ReadyTimeLeft = 2000 then
+                    AddVoice(sndComeonthen, CurrentTeam^.voicepack);
+                dec(ReadyTimeLeft)
+                end
+            else
+                dec(TurnTimeLeft)
+            end;
 
 if skipFlag then
     begin
-    if TagTurnTimeLeft = 0 then TagTurnTimeLeft:= TurnTimeLeft;
+    if TagTurnTimeLeft = 0 then
+        TagTurnTimeLeft:= TurnTimeLeft;
     TurnTimeLeft:= 0;
     skipFlag:= false;
     inc(CurrentHedgehog^.Team^.stats.TurnSkips);
@@ -501,7 +537,8 @@
 t:= GearsList;
 while t <> nil do
     begin
-    if (t^.Kind = gtHedgehog) or (t^.Kind = gtExplosives) then t^.Active:= true;
+    if (t^.Kind = gtHedgehog) or (t^.Kind = gtExplosives) then
+        t^.Active:= true;
     t:= t^.NextGear
     end
 end;
@@ -572,11 +609,11 @@
 
 Gear:= GearsList;
 if (GameFlags and gfInvulnerable) <> 0 then
-   while Gear <> nil do
-       begin
-       Gear^.Invulnerable:= true;  // this is only checked on hogs right now, so no need for gear type check
-       Gear:= Gear^.NextGear
-       end;
+    while Gear <> nil do
+        begin
+        Gear^.Invulnerable:= true;  // this is only checked on hogs right now, so no need for gear type check
+        Gear:= Gear^.NextGear
+        end;
 
 if (GameFlags and gfLaserSight) <> 0 then
     cLaserSighting:= true;
@@ -655,7 +692,8 @@
         end;
     t:= t^.NextGear
     end;
-if (GameFlags and gfSolidLand) = 0 then DrawExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), cShotgunRadius)
+if (GameFlags and gfSolidLand) = 0 then
+    DrawExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), cShotgunRadius)
 end;
 
 procedure AmmoShove(Ammo: PGear; Damage, Power: LongInt);
@@ -666,9 +704,9 @@
 begin
 t:= CheckGearsCollision(Ammo);
 // Just to avoid hogs on rope dodging fire.
-if (CurAmmoGear <> nil) and ((CurAmmoGear^.Kind = gtRope) or (CurAmmoGear^.Kind = gtJetpack) or (CurAmmoGear^.Kind = gtBirdy)) and
-   (CurrentHedgehog^.Gear <> nil) and (CurrentHedgehog^.Gear^.CollisionIndex = -1) and
-   (sqr(hwRound(Ammo^.X) - hwRound(CurrentHedgehog^.Gear^.X)) + sqr(hwRound(Ammo^.Y) - hwRound(CurrentHedgehog^.Gear^.Y)) <= sqr(cHHRadius + Ammo^.Radius)) then
+if (CurAmmoGear <> nil) and ((CurAmmoGear^.Kind = gtRope) or (CurAmmoGear^.Kind = gtJetpack) or (CurAmmoGear^.Kind = gtBirdy))
+and (CurrentHedgehog^.Gear <> nil) and (CurrentHedgehog^.Gear^.CollisionIndex = -1)
+and (sqr(hwRound(Ammo^.X) - hwRound(CurrentHedgehog^.Gear^.X)) + sqr(hwRound(Ammo^.Y) - hwRound(CurrentHedgehog^.Gear^.Y)) <= sqr(cHHRadius + Ammo^.Radius)) then
     begin
     t^.ar[t^.Count]:= CurrentHedgehog^.Gear;
     inc(t^.Count)
@@ -676,7 +714,8 @@
 
 i:= t^.Count;
 
-if (Ammo^.Kind = gtFlame) and (i > 0) then Ammo^.Health:= 0;
+if (Ammo^.Kind = gtFlame) and (i > 0) then
+    Ammo^.Health:= 0;
 while i > 0 do
     begin
     dec(i);
@@ -688,10 +727,12 @@
         if (Ammo^.Kind = gtDEagleShot) or (Ammo^.Kind = gtSniperRifleShot) then 
             begin
             VGear := AddVisualGear(hwround(Ammo^.X), hwround(Ammo^.Y), vgtBulletHit);
-            if VGear <> nil then VGear^.Angle := DxDy2Angle(-Ammo^.dX, Ammo^.dY);
+            if VGear <> nil then
+                VGear^.Angle := DxDy2Angle(-Ammo^.dX, Ammo^.dY);
             end;
 
-        if (Gear^.Kind = gtHedgehog) and (Ammo^.State and gsttmpFlag <> 0) and (Ammo^.Kind = gtShover) then Gear^.FlightTime:= 1;
+        if (Gear^.Kind = gtHedgehog) and (Ammo^.State and gsttmpFlag <> 0) and (Ammo^.Kind = gtShover) then
+            Gear^.FlightTime:= 1;
 
         case Gear^.Kind of
             gtHedgehog,
@@ -700,49 +741,60 @@
             gtTarget,
             gtCase,
             gtExplosives,
-            gtStructure: begin
-                    if (Ammo^.Kind = gtDrill) then begin Ammo^.Timer:= 0; exit; end;
-                    if (not Gear^.Invulnerable) then
-                        ApplyDamage(Gear, Ammo^.Hedgehog, tmpDmg, dsShove)
-                    else
-                        Gear^.State:= Gear^.State or gstWinner;
-                    if (Gear^.Kind = gtExplosives) and (Ammo^.Kind = gtBlowtorch) then 
-                        begin
-                        if (Ammo^.Hedgehog^.Gear <> nil) then Ammo^.Hedgehog^.Gear^.State:= Ammo^.Hedgehog^.Gear^.State and (not gstNotKickable);
-                        ApplyDamage(Gear, Ammo^.Hedgehog, tmpDmg * 100, dsUnknown); // crank up damage for explosives + blowtorch
-                        end;
+            gtStructure:
+            begin
+            if (Ammo^.Kind = gtDrill) then
+                begin
+                Ammo^.Timer:= 0;
+                exit;
+                end;
+            if (not Gear^.Invulnerable) then
+                ApplyDamage(Gear, Ammo^.Hedgehog, tmpDmg, dsShove)
+            else
+                Gear^.State:= Gear^.State or gstWinner;
+            if (Gear^.Kind = gtExplosives) and (Ammo^.Kind = gtBlowtorch) then 
+                begin
+                if (Ammo^.Hedgehog^.Gear <> nil) then
+                    Ammo^.Hedgehog^.Gear^.State:= Ammo^.Hedgehog^.Gear^.State and (not gstNotKickable);
+                ApplyDamage(Gear, Ammo^.Hedgehog, tmpDmg * 100, dsUnknown); // crank up damage for explosives + blowtorch
+                end;
 
-                    DeleteCI(Gear);
-                    if (Gear^.Kind = gtHedgehog) and Gear^.Hedgehog^.King then
-                        begin
-                        Gear^.dX:= Ammo^.dX * Power * _0_005;
-                        Gear^.dY:= Ammo^.dY * Power * _0_005
-                        end
-                    else
-                        begin
-                        Gear^.dX:= Ammo^.dX * Power * _0_01;
-                        Gear^.dY:= Ammo^.dY * Power * _0_01
-                        end;
+            DeleteCI(Gear);
+            if (Gear^.Kind = gtHedgehog) and Gear^.Hedgehog^.King then
+                begin
+                Gear^.dX:= Ammo^.dX * Power * _0_005;
+                Gear^.dY:= Ammo^.dY * Power * _0_005
+                end
+            else
+                begin
+                Gear^.dX:= Ammo^.dX * Power * _0_01;
+                Gear^.dY:= Ammo^.dY * Power * _0_01
+                end;
+
+            Gear^.Active:= true;
+            Gear^.State:= Gear^.State or gstMoving;
 
-                    Gear^.Active:= true;
-                    Gear^.State:= Gear^.State or gstMoving;
+            if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then
+                begin
+                if not (TestCollisionXwithXYShift(Gear, _0, -3, hwSign(Gear^.dX))
+                or (TestCollisionYwithGear(Gear, -1) <> 0)) then
+                    Gear^.Y:= Gear^.Y - _1;
+                if not (TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX))
+                or (TestCollisionYwithGear(Gear, -1) <> 0)) then
+                    Gear^.Y:= Gear^.Y - _1;
+                if not (TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX))
+                or (TestCollisionYwithGear(Gear, -1) <> 0)) then
+                    Gear^.Y:= Gear^.Y - _1;
+                end;
 
-                    if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then
-                        begin
-                        if not (TestCollisionXwithXYShift(Gear, _0, -3, hwSign(Gear^.dX))
-                            or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1;
-                        if not (TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX))
-                            or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1;
-                        if not (TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX))
-                            or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1;
-                        end;
-
-                    if (Ammo^.Kind <> gtFlame) or ((Ammo^.State and gsttmpFlag) = 0) then FollowGear:= Gear
-                    end;
+            if (Ammo^.Kind <> gtFlame) or ((Ammo^.State and gsttmpFlag) = 0) then
+                FollowGear:= Gear
+            end;
         end
         end;
     end;
-if i <> 0 then SetAllToActive
+if i <> 0 then
+    SetAllToActive
 end;
 
 procedure AssignHHCoords;
@@ -750,7 +802,8 @@
     ar: array[0..Pred(cMaxHHs)] of PHedgehog;
     Count: Longword;
 begin
-if (GameFlags and gfPlaceHog) <> 0 then PlacingHogs:= true;
+if (GameFlags and gfPlaceHog) <> 0 then
+    PlacingHogs:= true;
 if (GameFlags and gfDivideTeams) <> 0 then
     begin
     t:= 0;
@@ -764,8 +817,10 @@
                         with Hedgehogs[i] do
                             if (Gear <> nil) and (Gear^.X.QWordValue = 0) then
                                 begin
-                                if PlacingHogs then Unplaced:= true
-                                else FindPlace(Gear, false, t, t + LAND_WIDTH div 2);// could make Gear == nil;
+                                if PlacingHogs then
+                                    Unplaced:= true
+                                else
+                                    FindPlace(Gear, false, t, t + LAND_WIDTH div 2);// could make Gear == nil;
                                 if Gear <> nil then
                                     begin
                                     Gear^.Pos:= GetRandom(49);
@@ -795,8 +850,10 @@
     while (Count > 0) do
         begin
         i:= GetRandom(Count);
-        if PlacingHogs then ar[i]^.Unplaced:= true
-        else FindPlace(ar[i]^.Gear, false, 0, LAND_WIDTH);
+        if PlacingHogs then
+            ar[i]^.Unplaced:= true
+        else
+            FindPlace(ar[i]^.Gear, false, 0, LAND_WIDTH);
         if ar[i]^.Gear <> nil then
             begin
             ar[i]^.Gear^.dX.isNegative:= hwRound(ar[i]^.Gear^.X) > LAND_WIDTH div 2;
@@ -858,7 +915,8 @@
 t:= GearsList;
 while t <> nil do
     begin
-    if t^.Kind = Kind then inc(count);
+    if t^.Kind = Kind then
+        inc(count);
     t:= t^.NextGear
     end;
 CountGears:= count;
@@ -869,27 +927,32 @@
     FollowGear := AddGear(x, y, gtCase, 0, _0, _0, 0);
     cCaseFactor := 0;
 
-    if (crate <> HealthCrate) and (content > ord(High(TAmmoType))) then content := ord(High(TAmmoType));
+    if (crate <> HealthCrate) and (content > ord(High(TAmmoType))) then
+        content := ord(High(TAmmoType));
 
     case crate of
-        HealthCrate: begin
+        HealthCrate:
+            begin
             FollowGear^.Pos := posCaseHealth;
             FollowGear^.Health := content;
             AddCaption(GetEventString(eidNewHealthPack), cWhiteColor, capgrpAmmoInfo);
             end;
-        AmmoCrate: begin
+        AmmoCrate:
+            begin
             FollowGear^.Pos := posCaseAmmo;
             FollowGear^.AmmoType := TAmmoType(content);
             AddCaption(GetEventString(eidNewAmmoPack), cWhiteColor, capgrpAmmoInfo);
             end;
-        UtilityCrate: begin
+        UtilityCrate:
+            begin
             FollowGear^.Pos := posCaseUtility;
             FollowGear^.AmmoType := TAmmoType(content);
             AddCaption(GetEventString(eidNewUtilityPack), cWhiteColor, capgrpAmmoInfo);
             end;
     end;
 
-    if ( (x = 0) and (y = 0) ) then FindPlace(FollowGear, true, 0, LAND_WIDTH);
+    if ( (x = 0) and (y = 0) ) then
+        FindPlace(FollowGear, true, 0, LAND_WIDTH);
 
     SpawnCustomCrateAt := FollowGear;
 end;
@@ -900,25 +963,31 @@
     cCaseFactor := 0;
     FollowGear^.Pos := posCaseDummy;
     
-    if explode then FollowGear^.Pos := FollowGear^.Pos + posCaseExplode;
-    if poison then FollowGear^.Pos := FollowGear^.Pos + posCasePoison;
+    if explode then
+        FollowGear^.Pos := FollowGear^.Pos + posCaseExplode;
+    if poison then
+        FollowGear^.Pos := FollowGear^.Pos + posCasePoison;
 
     case crate of
-        HealthCrate: begin
+        HealthCrate:
+            begin
             FollowGear^.Pos := FollowGear^.Pos + posCaseHealth;
             AddCaption(GetEventString(eidNewHealthPack), cWhiteColor, capgrpAmmoInfo);
             end;
-        AmmoCrate: begin
+        AmmoCrate:
+            begin
             FollowGear^.Pos := FollowGear^.Pos + posCaseAmmo;
             AddCaption(GetEventString(eidNewAmmoPack), cWhiteColor, capgrpAmmoInfo);
             end;
-        UtilityCrate: begin
+        UtilityCrate:
+            begin
             FollowGear^.Pos := FollowGear^.Pos + posCaseUtility;
             AddCaption(GetEventString(eidNewUtilityPack), cWhiteColor, capgrpAmmoInfo);
             end;
     end;
 
-    if ( (x = 0) and (y = 0) ) then FindPlace(FollowGear, true, 0, LAND_WIDTH);
+    if ( (x = 0) and (y = 0) ) then
+        FindPlace(FollowGear, true, 0, LAND_WIDTH);
 
     SpawnFakeCrateAt := FollowGear;
 end;
@@ -939,11 +1008,11 @@
     begin
     t:= GetRandom(t);
     while t >= 0 do
-      begin
-      inc(i);
-      if (Ammoz[i].Ammo.Propz and ammoprop_Utility) = 0 then
-          dec(t, Ammoz[i].Probability)
-      end
+        begin
+        inc(i);
+        if (Ammoz[i].Ammo.Propz and ammoprop_Utility) = 0 then
+            dec(t, Ammoz[i].Probability)
+        end
     end;
 GetAmmo:= i
 end;
@@ -955,7 +1024,8 @@
 
 uTot:= 0;
 for i:= Low(TAmmoType) to High(TAmmoType) do
-    if ((Ammoz[i].Ammo.Propz and ammoprop_Utility) <> 0) and ((Hedgehog^.Team^.HedgehogsNumber > 1) or (Ammoz[i].Ammo.AmmoType <> amSwitch)) then
+    if ((Ammoz[i].Ammo.Propz and ammoprop_Utility) <> 0)
+    and ((Hedgehog^.Team^.HedgehogsNumber > 1) or (Ammoz[i].Ammo.AmmoType <> amSwitch)) then
         inc(uTot, Ammoz[i].Probability);
 
 t:= uTot;
@@ -964,11 +1034,12 @@
     begin
     t:= GetRandom(t);
     while t >= 0 do
-      begin
-      inc(i);
-      if ((Ammoz[i].Ammo.Propz and ammoprop_Utility) <> 0) and ((Hedgehog^.Team^.HedgehogsNumber > 1) or (Ammoz[i].Ammo.AmmoType <> amSwitch)) then
-          dec(t, Ammoz[i].Probability)
-      end
+        begin
+        inc(i);
+        if ((Ammoz[i].Ammo.Propz and ammoprop_Utility) <> 0) and ((Hedgehog^.Team^.HedgehogsNumber > 1)
+        or (Ammoz[i].Ammo.AmmoType <> amSwitch)) then
+            dec(t, Ammoz[i].Probability)
+        end
     end;
 GetUtility:= i
 end;
@@ -980,9 +1051,10 @@
     i: TAmmoType;
 begin
 if (PlacingHogs) or
-   (cCaseFactor = 0) or
-   (CountGears(gtCase) >= 5) or
-   (GetRandom(cCaseFactor) <> 0) then exit;
+    (cCaseFactor = 0)
+    or (CountGears(gtCase) >= 5)
+    or (GetRandom(cCaseFactor) <> 0) then
+       exit;
 
 FollowGear:= nil;
 aTot:= 0;
@@ -1083,7 +1155,8 @@
 procedure chSkip(var s: shortstring);
 begin
 s:= s; // avoid compiler hint
-if not CurrentTeam^.ExtDriven then SendIPC(',');
+if not CurrentTeam^.ExtDriven then
+    SendIPC(',');
 uStats.Skipped;
 skipFlag:= true
 end;
@@ -1102,12 +1175,16 @@
     if x < 4 then
         begin
         t:= byte(s[2]);  // team
-        if Length(s) > 2 then h:= byte(s[3])  // target hog
+        if Length(s) > 2 then
+            h:= byte(s[3])  // target hog
         end;
     // allow targetting a hog by specifying a number as the first portion of the text
-    if (x < 4) and (h > byte('0')) and (h < byte('9')) then i:= h - 48;
-    if i <> 0 then text:= copy(s, 4, Length(s) - 1)
-    else if x < 4 then text:= copy(s, 3, Length(s) - 1)
+    if (x < 4) and (h > byte('0')) and (h < byte('9')) then
+        i:= h - 48;
+    if i <> 0 then
+        text:= copy(s, 4, Length(s) - 1)
+    else if x < 4 then
+        text:= copy(s, 3, Length(s) - 1)
     else text:= copy(s, 2, Length(s) - 1);
 
     (*
@@ -1121,7 +1198,8 @@
     if (x < 4) and (TeamsArray[t] <> nil) then
         begin
             // if team matches current hedgehog team, default to current hedgehog
-            if (i = 0) and (CurrentHedgehog <> nil) and (CurrentHedgehog^.Team = TeamsArray[t]) then hh:= CurrentHedgehog
+            if (i = 0) and (CurrentHedgehog <> nil) and (CurrentHedgehog^.Team = TeamsArray[t]) then
+                hh:= CurrentHedgehog
             else 
                 begin
             // otherwise use the first living hog or the hog amongs the remaining ones indicated by i
--- a/hedgewars/uGearsHedgehog.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uGearsHedgehog.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -1,1153 +1,1258 @@
-(*
- * Hedgewars, a free turn based strategy game
- * Copyright (c) 2004-2011 Andrey Korotaev <unC0Rr@gmail.com>
- *
- * 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
- * the Free Software Foundation; version 2 of the License
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- *)
-
-{$INCLUDE "options.inc"}
-
-unit uGearsHedgehog;
-interface
-uses uTypes;
-
-procedure doStepHedgehog(Gear: PGear);
-procedure AfterAttack; 
-procedure HedgehogStep(Gear: PGear); 
-procedure doStepHedgehogMoving(Gear: PGear); 
-procedure HedgehogChAngle(HHGear: PGear); 
-procedure PickUp(HH, Gear: PGear);
-
-implementation
-uses uConsts, uVariables, uFloat, uAmmos, uSound, uCaptions, uMisc, 
-    uCommands, uLocale, uUtils, uVisualGears, uStats, uIO, uScript,
-    uGearsList, uGears, uCollisions, uRandom, uStore, uTeams, 
-    uGearsUtils;
-
-// Shouldn't more of this ammo switching stuff be moved to uAmmos ?
-function ChangeAmmo(HHGear: PGear): boolean;
-var slot, i: Longword;
-    ammoidx: LongInt;
-begin
-ChangeAmmo:= false;
-slot:= HHGear^.MsgParam;
-
-with HHGear^.Hedgehog^ do
-    begin
-    HHGear^.Message:= HHGear^.Message and (not gmSlot);
-    ammoidx:= 0;
-    if ((HHGear^.State and (gstAttacking or gstAttacked)) <> 0) or
-       ((MultiShootAttacks > 0) and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_NoRoundEnd) = 0)) or
-       ((HHGear^.State and gstHHDriven) = 0) then exit;
-    ChangeAmmo:= true;
-
-    while (ammoidx < cMaxSlotAmmoIndex) and (Ammo^[slot, ammoidx].AmmoType <> CurAmmoType) do inc(ammoidx);
-
-    if ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_NoRoundEnd) <> 0) and (MultiShootAttacks > 0) then OnUsedAmmo(HHGear^.Hedgehog^);
-
-    MultiShootAttacks:= 0;
-    HHGear^.Message:= HHGear^.Message and (not (gmLJump or gmHJump));
-    
-    if Ammoz[CurAmmoType].Slot = slot then
-        begin
-        i:= 0;
-        repeat
-        inc(ammoidx);
-        if (ammoidx > cMaxSlotAmmoIndex) then
-            begin
-            inc(i);
-            CurAmmoType:= amNothing;
-            ammoidx:= -1;
-            //TryDo(i < 2, 'Engine bug: no ammo in current slot', true)
-            end;
-        until (i = 1) or ((Ammo^[slot, ammoidx].Count > 0) and (Team^.Clan^.TurnNumber > Ammoz[Ammo^[slot, ammoidx].AmmoType].SkipTurns))
-        end 
-    else
-        begin
-        i:= 0;
-        // check whether there is ammo in slot
-        while (i <= cMaxSlotAmmoIndex)
-          and ((Ammo^[slot, i].Count = 0)
-               or (Team^.Clan^.TurnNumber <= Ammoz[Ammo^[slot, i].AmmoType].SkipTurns)) do inc(i);
-
-        if i <= cMaxSlotAmmoIndex then ammoidx:= i
-        else ammoidx:= -1
-        end;
-        if ammoidx >= 0 then CurAmmoType:= Ammo^[slot, ammoidx].AmmoType;
-    end
-end;
-
-procedure HHSetWeapon(HHGear: PGear);
-var t: LongInt;
-    weap: TAmmoType;
-    Hedgehog: PHedgehog;
-    s: boolean;
-begin
-s:= false;
-
-weap:= TAmmoType(HHGear^.MsgParam);
-Hedgehog:= HHGear^.Hedgehog;
-
-if Hedgehog^.Team^.Clan^.TurnNumber <= Ammoz[weap].SkipTurns then exit; // weapon is not activated yet
-
-HHGear^.MsgParam:= Ammoz[weap].Slot;
-
-t:= cMaxSlotAmmoIndex;
-
-HHGear^.Message:= HHGear^.Message and (not gmWeapon);
-
-with Hedgehog^ do
-    while (CurAmmoType <> weap) and (t >= 0) do
-        begin
-        s:= ChangeAmmo(HHGear);
-        dec(t)
-        end;
-
-if s then ApplyAmmoChanges(HHGear^.Hedgehog^)
-end;
-
-procedure HHSetTimer(Gear: PGear);
-var CurWeapon: PAmmo;
-    color: LongWord;
-begin
-Gear^.Message:= Gear^.Message and (not gmTimer);
-CurWeapon:= GetAmmoEntry(Gear^.Hedgehog^);
-with Gear^.Hedgehog^ do
-    if ((Gear^.Message and gmPrecise) <> 0) and ((CurWeapon^.Propz and ammoprop_SetBounce) <> 0) then
-        begin
-        color:= Gear^.Hedgehog^.Team^.Clan^.Color;
-        case Gear^.MsgParam of
-            1: begin
-               AddCaption(format(trmsg[sidBounce], trmsg[sidBounce1]), color, capgrpAmmostate);
-               CurWeapon^.Bounciness:= 350;
-               end;
-            2: begin
-               AddCaption(format(trmsg[sidBounce], trmsg[sidBounce2]), color, capgrpAmmostate);
-               CurWeapon^.Bounciness:= 700;
-               end;
-            3: begin
-               AddCaption(format(trmsg[sidBounce], trmsg[sidBounce3]), color, capgrpAmmostate);
-               CurWeapon^.Bounciness:= 1000;
-               end;
-            4: begin
-               AddCaption(format(trmsg[sidBounce], trmsg[sidBounce4]), color, capgrpAmmostate);
-               CurWeapon^.Bounciness:= 2000;
-               end;
-            5: begin
-               AddCaption(format(trmsg[sidBounce], trmsg[sidBounce5]), color, capgrpAmmostate);
-               CurWeapon^.Bounciness:= 4000;
-               end
-            end
-        end
-    else if (CurWeapon^.Propz and ammoprop_Timerable) <> 0 then
-        begin
-        CurWeapon^.Timer:= 1000 * Gear^.MsgParam;
-        with CurrentTeam^ do
-            ApplyAmmoChanges(Hedgehogs[CurrHedgehog]);
-        end;
-end;
-
-
-procedure Attack(Gear: PGear);
-var xx, yy, newDx, newDy, lx, ly: hwFloat;
-    speech: PVisualGear;
-    newGear:  PGear;
-    CurWeapon: PAmmo;
-    altUse: boolean;
-    elastic: hwFloat;
-begin
-newGear:= nil;
-bShowFinger:= false;
-CurWeapon:= GetAmmoEntry(Gear^.Hedgehog^);
-with Gear^,
-     Gear^.Hedgehog^ do
-     begin
-     if ((State and gstHHDriven) <> 0)and
-        ((State and (gstAttacked or gstHHChooseTarget)) = 0) and
-        (((State and gstMoving) = 0) or
-            (Power > 0) or
-            (CurAmmoType = amTeleport) or 
-            // Allow attacks while moving on ammo with AltAttack
-            ((CurAmmoGear <> nil) and ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) <> 0)) or
-            ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_AttackInMove) <> 0)) and
-        ((TargetPoint.X <> NoPointX) or ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_NeedTarget) = 0)) then
-        begin
-        State:= State or gstAttacking;
-        if Power = cMaxPower then Message:= Message and (not gmAttack)
-        else if (Ammoz[CurAmmoType].Ammo.Propz and ammoprop_Power) = 0 then Message:= Message and (not gmAttack)
-        else begin
-             if Power = 0 then
-                begin
-                AttackBar:= CurrentTeam^.AttackBar;
-                PlaySound(sndThrowPowerUp)
-                end;
-             inc(Power)
-             end;
-        if ((Message and gmAttack) <> 0) then exit;
-
-        if (Ammoz[CurAmmoType].Ammo.Propz and ammoprop_Power) <> 0 then
-           begin
-           StopSound(sndThrowPowerUp);
-           PlaySound(sndThrowRelease);
-           end;
-
-        xx:= SignAs(AngleSin(Angle), dX);
-        yy:= -AngleCos(Angle);
-
-        lx:= X + int2hwfloat(round(GetLaunchX(CurAmmoType, hwSign(dX), Angle)));
-        ly:= Y + int2hwfloat(round(GetLaunchY(CurAmmoType, Angle)));
-
-        if ((Gear^.State and gstHHHJump) <> 0) and (not cArtillery) then xx:= - xx;
-        if Ammoz[CurAmmoType].Ammo.AttackVoice <> sndNone then
-           AddVoice(Ammoz[CurAmmoType].Ammo.AttackVoice, CurrentTeam^.voicepack);
-
-// Initiating alt attack
-        if  (CurAmmoGear <> nil) and
-            ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) <> 0) and
-            ((Gear^.Message and gmLJump) <> 0) and
-            ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_AltUse) <> 0) then
-            begin
-            newDx:= dX / _2; 
-            newDy:= dY / _2;
-            altUse:= true;
-            end
-        else
-            begin
-            newDx:= xx*Power/cPowerDivisor;
-            newDy:= yy*Power/cPowerDivisor;
-            altUse:= false
-            end;
-
-             case CurAmmoType of
-                      amGrenade: newGear:= AddGear(hwRound(lx), hwRound(ly), gtGrenade,         0, newDx, newDy, CurWeapon^.Timer);
-                      amMolotov: newGear:= AddGear(hwRound(lx), hwRound(ly), gtMolotov,      0, newDx, newDy, 0);
-                  amClusterBomb: newGear:= AddGear(hwRound(lx), hwRound(ly), gtClusterBomb,  0, newDx, newDy, CurWeapon^.Timer);
-                      amGasBomb: newGear:= AddGear(hwRound(lx), hwRound(ly), gtGasBomb,      0, newDx, newDy, CurWeapon^.Timer);
-                      amBazooka: newGear:= AddGear(hwRound(lx), hwRound(ly), gtShell,        0, newDx, newDy, 0);
-                     amSnowball: newGear:= AddGear(hwRound(lx), hwRound(ly), gtSnowball,     0, newDx, newDy, 0);
-                          amBee: newGear:= AddGear(hwRound(lx), hwRound(ly), gtBee,          0, newDx, newDy, 0);
-                      amShotgun: begin
-                                 PlaySound(sndShotgunReload);
-                                 newGear:= AddGear(hwRound(lx), hwRound(ly), gtShotgunShot,  0, xx * _0_5, yy * _0_5, 0);
-                                 end;
-                   amPickHammer: newGear:= AddGear(hwRound(lx), hwRound(ly) + cHHRadius, gtPickHammer, 0, _0, _0, 0);
-                         amSkip: ParseCommand('/skip', true);
-                         amRope: newGear:= AddGear(hwRound(lx), hwRound(ly), gtRope, 0, xx, yy, 0);
-                         amMine: if altUse then
-                                    newGear:= AddGear(hwRound(lx) + hwSign(dX) * 7, hwRound(ly), gtMine, gstWait, newDx, newDy, 3000)
-                                 else
-                                    newGear:= AddGear(hwRound(lx) + hwSign(dX) * 7, hwRound(ly), gtMine, gstWait, SignAs(_0_02, dX), _0, 3000);
-                        amSMine: newGear:= AddGear(hwRound(lx), hwRound(ly), gtSMine,    0, xx*Power/cPowerDivisor, yy*Power/cPowerDivisor, 0);
-                       amDEagle: newGear:= AddGear(hwRound(lx + xx * cHHRadius), hwRound(ly + yy * cHHRadius), gtDEagleShot, 0, xx * _0_5, yy * _0_5, 0);
-                      amSineGun: newGear:= AddGear(hwRound(lx + xx * cHHRadius), hwRound(ly + yy * cHHRadius), gtSineGunShot, 0, xx * _0_5, yy * _0_5, 0);
-                    amPortalGun: begin
-                                 newGear:= AddGear(hwRound(lx + xx * cHHRadius), hwRound(ly + yy * cHHRadius), gtPortal, 0, xx * _0_6, yy * _0_6, 
-                                 // set selected color
-                                 CurWeapon^.Pos);
-                                 end;
-                  amSniperRifle: begin
-                                 PlaySound(sndSniperReload);
-                                 newGear:= AddGear(hwRound(lx + xx * cHHRadius), hwRound(ly + yy * cHHRadius), gtSniperRifleShot, 0, xx * _0_5, yy * _0_5, 0);
-                                 end;
-                     amDynamite: newGear:= AddGear(hwRound(lx) + hwSign(dX) * 7, hwRound(ly), gtDynamite, 0, SignAs(_0_03, dX), _0, 5000);
-                    amFirePunch: newGear:= AddGear(hwRound(lx) + hwSign(dX) * 10, hwRound(ly), gtFirePunch, 0, xx, _0, 0);
-                         amWhip: begin
-                                 newGear:= AddGear(hwRound(lx) + hwSign(dX) * 10, hwRound(ly), gtWhip, 0, SignAs(_1, dX), - _0_8, 0);
-                                 PlaySound(sndWhipCrack)
-                                 end;
-                       amHammer: begin
-                                 newGear:= AddGear(hwRound(lx) + hwSign(dX) * 10, hwRound(ly), gtHammer, 0, SignAs(_1, dX), - _0_8, 0);
-                                 PlaySound(sndWhack)
-                                 end;
-                  amBaseballBat: begin
-                                 newGear:= AddGear(hwRound(lx) + hwSign(dX) * 10, hwRound(ly), gtShover, gsttmpFlag, xx * _0_5, yy * _0_5, 0);
-                                 PlaySound(sndBaseballBat) // TODO: Only play if something is hit?
-                                 end;
-                    amParachute: begin
-                                 newGear:= AddGear(hwRound(lx), hwRound(ly), gtParachute, 0, _0, _0, 0);
-                                 PlaySound(sndParachute)
-                                 end;
-                    // we save CurWeapon^.Pos (in this case: cursor direction) by using it as (otherwise irrelevant) X value of the new gear.
-                    amAirAttack: newGear:= AddGear(CurWeapon^.Pos, 0, gtAirAttack, 0, _0, _0, 0);
-                   amMineStrike: newGear:= AddGear(CurWeapon^.Pos, 0, gtAirAttack, 1, _0, _0, 0);
-                  amDrillStrike: newGear:= AddGear(CurWeapon^.Pos, 0, gtAirAttack, 3, _0, _0, CurWeapon^.Timer);
-                       amNapalm: newGear:= AddGear(CurWeapon^.Pos, 0, gtAirAttack, 2, _0, _0, 0);
-                    amBlowTorch: newGear:= AddGear(hwRound(lx), hwRound(ly), gtBlowTorch, 0, SignAs(_0_5, dX), _0, 0);
-                       amGirder: newGear:= AddGear(0, 0, gtGirder, CurWeapon^.Pos, _0, _0, 0);
-                     amTeleport: newGear:= AddGear(CurWeapon^.Pos, 0, gtTeleport, 0, _0, _0, 0);
-                       amSwitch: newGear:= AddGear(hwRound(lx), hwRound(ly), gtSwitcher, 0, _0, _0, 0);
-                       amMortar: begin
-                                 playSound(sndMortar);
-                                 newGear:= AddGear(hwRound(lx), hwRound(ly), gtMortar,  0, xx*cMaxPower/cPowerDivisor, yy*cMaxPower/cPowerDivisor, 0);
-                                 end;
-                      amRCPlane: begin
-                                 newGear:= AddGear(hwRound(lx), hwRound(ly), gtRCPlane,  0, xx * cMaxPower / cPowerDivisor / 4, yy * cMaxPower / cPowerDivisor / 4, 0);
-                                 newGear^.SoundChannel:= LoopSound(sndRCPlane, nil)
-                                 end;
-                       amKamikaze: newGear:= AddGear(hwRound(lx), hwRound(ly), gtKamikaze, 0, xx * _0_5, yy * _0_5, 0);
-                         amCake: newGear:= AddGear(hwRound(lx) + hwSign(dX) * 3, hwRound(ly), gtCake, 0, xx, _0, 0);
-                    amSeduction: newGear:= AddGear(hwRound(lx), hwRound(ly), gtSeduction, 0, _0, _0, 0);
-                   amWatermelon: newGear:= AddGear(hwRound(lx), hwRound(ly), gtWatermelon,  0, newDx, newDy, CurWeapon^.Timer);
-                  amHellishBomb: newGear:= AddGear(hwRound(lx), hwRound(ly), gtHellishBomb,    0, newDx, newDy, 0);
-                        amDrill: newGear:= AddGear(hwRound(lx), hwRound(ly), gtDrill, 0, newDx, newDy, 0);
-                      amBallgun: newGear:= AddGear(hwRound(X), hwRound(Y), gtBallgun,  0, xx * _0_5, yy * _0_5, 0);
-                    amJetpack: newGear:= AddGear(hwRound(lx), hwRound(ly), gtJetpack, 0, _0, _0, 0);
-                    amBirdy: begin
-                             PlaySound(sndWhistle);
-                             newGear:= AddGear(hwRound(lx), hwRound(ly) - 32, gtBirdy, 0, _0, _0, 0);
-                             end;
-                      amLowGravity: begin
-                                    PlaySound(sndLowGravity);
-                                    cGravity:= cMaxWindSpeed;
-                                    cGravityf:= 0.00025
-                                    end;
-                      amExtraDamage:begin 
-                                    PlaySound(sndHellishImpact4);
-                                    cDamageModifier:= _1_5
-                                    end;
-                      amInvulnerable: Invulnerable:= true;
-                      amExtraTime:  begin
-                                    PlaySound(sndSwitchHog);
-                                    TurnTimeLeft:= TurnTimeLeft + 30000
-                                    end;
-                      amLaserSight: cLaserSighting:= true;
-                      amVampiric: begin
-                                  PlaySound(sndOw1, Team^.voicepack);
-                                  cVampiric:= true;
-                                  end;
-                      amPiano: begin
-                               // Tuck the hedgehog away until the piano attack is completed
-                               Unplaced:= true;
-                               X:= _0;
-                               Y:= _0;
-                               newGear:= AddGear(TargetPoint.X, 0, gtPiano, 0, _0, _0, 0);
-                               PauseMusic
-                               end;
-                      amFlamethrower: newGear:= AddGear(hwRound(X), hwRound(Y), gtFlamethrower,  0, xx * _0_5, yy * _0_5, 0);
-                      amLandGun: newGear:= AddGear(hwRound(X), hwRound(Y), gtLandGun,  0, xx * _0_5, yy * _0_5, 0);
-                    amResurrector: begin
-                        newGear:= AddGear(hwRound(lx), hwRound(ly),
-                                gtResurrector, 0, _0, _0, 0);
-                        newGear^.SoundChannel := LoopSound(sndResurrector);
-                    end;
-                   //amMelonStrike: AddGear(CurWeapon^.Pos, 0, gtAirAttack, 4, _0, _0, 0);
-                     amStructure: newGear:= AddGear(hwRound(lx) + hwSign(dX) * 7, hwRound(ly), gtStructure, gstWait, SignAs(_0_02, dX), _0, 3000);
-                        amTardis: newGear:= AddGear(hwRound(X), hwRound(Y), gtTardis, 0, _0, _0, 5000);
-                  end;
-             case CurAmmoType of
-                      amGrenade, amMolotov, 
-                  amClusterBomb, amGasBomb, 
-                      amBazooka, amSnowball, 
-                          amBee, amSMine,
-                       amMortar, amWatermelon,
-                  amHellishBomb, amDrill: FollowGear:= newGear;
-
-                      amShotgun, amPickHammer,
-                         amRope, amDEagle,
-                      amSineGun, amSniperRifle,
-                    amFirePunch, amWhip,
-                       amHammer, amBaseballBat,
-                    amParachute, amBlowTorch,
-                       amGirder, amTeleport,
-                       amSwitch, amRCPlane,
-                     amKamikaze, amCake,
-                    amSeduction, amBallgun,
-                      amJetpack, amBirdy,
-                 amFlamethrower, amLandGun,
-                  amResurrector, amStructure,
-                       amTardis, amPiano: CurAmmoGear:= newGear;
-                  end;
-              if ((CurAmmoType = amMine) or (CurAmmoType = amSMine)) and (GameFlags and gfInfAttack <> 0) then
-                 newGear^.FlightTime:= GameTicks + 1000
-              else if CurAmmoType = amDrill then newGear^.FlightTime:= GameTicks + 250;
-        if Ammoz[CurAmmoType].Ammo.Propz and ammoprop_NeedTarget <> 0 then
-            begin
-            newGear^.Target.X:= TargetPoint.X;
-            newGear^.Target.Y:= TargetPoint.Y
-            end;
-
-        // Clear FollowGear if using on a rope/parachute/saucer etc so focus stays with the hog's movement
-        if altUse then FollowGear:= nil;
-
-        if (newGear <> nil) and ((Ammoz[newGear^.AmmoType].Ammo.Propz and ammoprop_SetBounce) <> 0) then
-            begin
-            elastic:=  int2hwfloat(CurWeapon^.Bounciness) / _1000;
-
-            if elastic < _1 then newGear^.Elasticity:= newGear^.Elasticity * elastic
-            else if elastic > _1 then newGear^.Elasticity:= _1 - ((_1-newGear^.Elasticity) / elastic);
-(* Experimented with friction modifier. Didn't seem helpful 
-            fric:= int2hwfloat(CurWeapon^.Bounciness) / _250;
-            if fric < _1 then newGear^.Friction:= newGear^.Friction * fric
-            else if fric > _1 then newGear^.Friction:= _1 - ((_1-newGear^.Friction) / fric)*)
-            end;
-
-
-        uStats.AmmoUsed(CurAmmoType);
-
-        if not (SpeechText = '') then
-            begin
-            speech:= AddVisualGear(0, 0, vgtSpeechBubble);
-            if speech <> nil then
-               begin
-               speech^.Text:= SpeechText;
-               speech^.Hedgehog:= Gear^.Hedgehog;
-               speech^.FrameTicks:= SpeechType;
-               end;
-            SpeechText:= ''
-            end;
-
-        Power:= 0;
-        if (CurAmmoGear <> nil)
-           and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_AltUse) = 0){check for dropping ammo from rope} then
-           begin
-           Message:= Message or gmAttack;
-           CurAmmoGear^.Message:= Message
-           end else begin
-           if not CurrentTeam^.ExtDriven and
-             ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_Power) <> 0) then SendIPC('a');
-           AfterAttack;
-           end
-        end else Message:= Message and (not gmAttack);
-     end;
-     TargetPoint.X := NoPointX;
-     ScriptCall('onHogAttack');
-end;
-
-procedure AfterAttack;
-var s: shortstring;
-    a: TAmmoType;
-begin
-with CurrentHedgehog^.Gear^,
-        CurrentHedgehog^ do
-    begin
-    a:= CurAmmoType;
-    State:= State and (not gstAttacking);
-    if (Ammoz[a].Ammo.Propz and ammoprop_Effect) = 0 then
-        begin
-        Inc(MultiShootAttacks);
-        
-        if (Ammoz[a].Ammo.NumPerTurn >= MultiShootAttacks) then
-            begin
-            s:= inttostr(Ammoz[a].Ammo.NumPerTurn - MultiShootAttacks + 1);
-            AddCaption(format(trmsg[sidRemaining], s), cWhiteColor, capgrpAmmostate);
-            end;
-        
-        if (Ammoz[a].Ammo.NumPerTurn >= MultiShootAttacks) or
-            ((GameFlags and gfMultiWeapon) <> 0) then
-            begin
-            isInMultiShoot:= true
-            end
-        else
-            begin
-            OnUsedAmmo(CurrentHedgehog^);
-            if ((Ammoz[a].Ammo.Propz and ammoprop_NoRoundEnd) = 0) and (((GameFlags and gfInfAttack) = 0) or PlacingHogs) then
-                begin
-                if TagTurnTimeLeft = 0 then TagTurnTimeLeft:= TurnTimeLeft;
-                TurnTimeLeft:=(Ammoz[a].TimeAfterTurn * cGetAwayTime) div 100;
-                end;
-            if ((Ammoz[a].Ammo.Propz and ammoprop_NoRoundEnd) = 0) then State:= State or gstAttacked;
-            if (Ammoz[a].Ammo.Propz and ammoprop_NoRoundEnd) <> 0 then ApplyAmmoChanges(CurrentHedgehog^)
-            end;
-        end
-    else
-        begin
-        OnUsedAmmo(CurrentHedgehog^);
-        ApplyAmmoChanges(CurrentHedgehog^);
-        end;
-    AttackBar:= 0
-    end
-end;
-
-////////////////////////////////////////////////////////////////////////////////
-procedure doStepHedgehogDead(Gear: PGear);
-const frametime = 200;
-      timertime = frametime * 6;
-begin
-if Gear^.Hedgehog^.Unplaced then exit;
-if Gear^.Timer > 1 then
-    begin
-    AllInactive:= false;
-    dec(Gear^.Timer);
-    if (Gear^.Timer mod frametime) = 0 then inc(Gear^.Pos)
-    end 
-else if Gear^.Timer = 1 then
-    begin
-    Gear^.State:= Gear^.State or gstNoDamage;
-    doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 30, CurrentHedgehog, EXPLAutoSound);
-    AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtGrave, 0, _0, _0, 0)^.Hedgehog:= Gear^.Hedgehog;
-    DeleteGear(Gear);
-    SetAllToActive
-    end 
-else // Gear^.Timer = 0
-    begin
-    AllInactive:= false;
-    Gear^.Z:= cCurrHHZ;
-    RemoveGearFromList(Gear);
-    InsertGearToList(Gear);
-    PlaySound(sndByeBye, Gear^.Hedgehog^.Team^.voicepack);
-    Gear^.Pos:= 0;
-    Gear^.Timer:= timertime
-    end
-end;
-
-////////////////////////////////////////////////////////////////////////////////
-procedure doStepHedgehogGone(Gear: PGear);
-const frametime = 65;
-      timertime = frametime * 11;
-begin
-if Gear^.Hedgehog^.Unplaced then exit;
-if Gear^.Timer > 1 then
-    begin
-    AllInactive:= false;
-    dec(Gear^.Timer);
-    if (Gear^.Timer mod frametime) = 0 then inc(Gear^.Pos)
-    end else
-if Gear^.Timer = 1 then
-    begin
-    DeleteGear(Gear);
-    SetAllToActive
-    end else // Gear^.Timer = 0
-    begin
-    AllInactive:= false;
-    Gear^.Z:= cCurrHHZ;
-    RemoveGearFromList(Gear);
-    InsertGearToList(Gear);
-    PlaySound(sndByeBye, Gear^.Hedgehog^.Team^.voicepack);
-    PlaySound(sndWarp);
-    Gear^.Pos:= 0;
-    Gear^.Timer:= timertime
-    end
-end;
-
-////////////////////////////////////////////////////////////////////////////////
-procedure PickUp(HH, Gear: PGear);
-var s: shortstring;
-    a: TAmmoType;
-    i: LongInt;
-    vga: PVisualGear;
-begin
-Gear^.Message:= gmDestroy;
-PlaySound(sndShotgunReload);
-if (Gear^.Pos and posCaseExplode) <> 0 then
-    if (Gear^.Pos and posCasePoison) <> 0 then
-        doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 25, HH^.Hedgehog, EXPLAutoSound + EXPLPoisoned)
-    else
-        doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 25, HH^.Hedgehog, EXPLAutoSound)
-else if (Gear^.Pos and posCasePoison) <> 0 then
-    doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 25, HH^.Hedgehog, EXPLAutoSound + EXPLPoisoned + EXPLNoDamage)
-else
-case Gear^.Pos of
-       posCaseUtility,
-       posCaseAmmo: begin
-                    if Gear^.AmmoType <> amNothing then a:= Gear^.AmmoType 
-                    else
-                        begin
-                        for i:= 0 to GameTicks and $7F do GetRandom(2); // Burn some random numbers
-                        if Gear^.Pos = posCaseUtility then a:= GetUtility(HH^.Hedgehog)
-                        else a:= GetAmmo(HH^.Hedgehog)
-                        end;
-                    AddAmmo(HH^.Hedgehog^, a);
-// Possibly needs to check shared clan ammo game flag once added.
-// On the other hand, no obvious reason that clan members shouldn't know what ammo another clan member picked up
-                    if (not (HH^.Hedgehog^.Team^.ExtDriven 
-                      or (HH^.Hedgehog^.BotLevel > 0)))
-                      or (HH^.Hedgehog^.Team^.Clan^.ClanIndex = LocalClan)
-                      or (GameType = gmtDemo)  then
-                        begin
-                        s:= trammo[Ammoz[a].NameId] + ' (+' + IntToStr(Ammoz[a].NumberInCase) + ')';
-                        AddCaption(s, HH^.Hedgehog^.Team^.Clan^.Color, capgrpAmmoinfo);
-
-                        // show ammo icon
-                        vga:= AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtAmmo);
-                        if vga <> nil then
-                            vga^.Frame:= Longword(a);
-                        end;
-
-                    end;
-     posCaseHealth: begin
-                    inc(HH^.Health, Gear^.Health);
-                    HH^.Hedgehog^.Effects[hePoisoned] := false;
-                    str(Gear^.Health, s);
-                    s:= '+' + s;
-                    AddCaption(s, HH^.Hedgehog^.Team^.Clan^.Color, capgrpAmmoinfo);
-                    RenderHealth(HH^.Hedgehog^);
-                    RecountTeamHealth(HH^.Hedgehog^.Team);
-
-                    i:= 0;
-                    while i < Gear^.Health do
-                        begin
-                        vga:= AddVisualGear(hwRound(HH^.X), hwRound(HH^.Y), vgtStraightShot);
-                        if vga <> nil then
-                            with vga^ do
-                                begin
-                                Tint:= $00FF00FF;
-                                State:= ord(sprHealth)
-                                end;
-                        inc(i, 5);
-                        end;
-                    end;
-     end
-end;
-
-const StepTicks: LongWord = 0;
-
-procedure HedgehogStep(Gear: PGear);
-var PrevdX: LongInt;
-    CurWeapon: PAmmo;
-begin
-CurWeapon:= GetAmmoEntry(Gear^.Hedgehog^);
-if ((Gear^.State and (gstAttacking or gstMoving)) = 0) then
-   begin
-   if isCursorVisible then
-      with Gear^.Hedgehog^ do
-        with CurWeapon^ do
-          begin
-          if (Gear^.Message and gmLeft  ) <> 0 then
-             Pos:= (Pos - 1 + Ammoz[AmmoType].PosCount) mod Ammoz[AmmoType].PosCount
-          else
-          if (Gear^.Message and gmRight ) <> 0 then
-             Pos:= (Pos + 1) mod Ammoz[AmmoType].PosCount
-          else exit;
-          StepTicks:= 200;
-          exit
-          end;
-
-    if ((Gear^.Message and gmAnimate) <> 0) then
-        begin
-        Gear^.Message:= 0;
-        Gear^.State:= Gear^.State or gstAnimation;
-        Gear^.Tag:= Gear^.MsgParam;
-        Gear^.Timer:= 0;
-        Gear^.Pos:= 0
-        end;
-
-   if ((Gear^.Message and gmLJump ) <> 0) then
-      begin
-      Gear^.Message:= Gear^.Message and (not gmLJump);
-      DeleteCI(Gear);
-      if TestCollisionYwithGear(Gear, -1) = 0 then
-         if not TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX)) then Gear^.Y:= Gear^.Y - _2 else
-         if not TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX)) then Gear^.Y:= Gear^.Y - _1;
-      if not (TestCollisionXwithGear(Gear, hwSign(Gear^.dX))
-         or   (TestCollisionYwithGear(Gear, -1) <> 0)) then
-         begin
-         Gear^.dY:= -_0_15;
-         if not cArtillery then Gear^.dX:= SignAs(_0_15, Gear^.dX);
-         Gear^.State:= Gear^.State or gstMoving or gstHHJumping;
-         PlaySound(sndJump1, Gear^.Hedgehog^.Team^.voicepack);
-         exit
-         end;
-      end;
-
-   if ((Gear^.Message and gmHJump ) <> 0) then
-      begin
-      DeleteCI(Gear);
-      Gear^.Message:= Gear^.Message and (not gmHJump);
-
-      Gear^.dY:= -_0_2;
-      SetLittle(Gear^.dX);
-      Gear^.State:= Gear^.State or gstMoving or gstHHJumping;
-      PlaySound(sndJump3, Gear^.Hedgehog^.Team^.voicepack);
-      exit
-      end;
-
-   PrevdX:= hwSign(Gear^.dX);
-   if (Gear^.Message and gmLeft  )<>0 then Gear^.dX:= -cLittle else
-   if (Gear^.Message and gmRight )<>0 then Gear^.dX:=  cLittle else exit;
-
-   if (Gear^.Message and (gmLeft or gmRight)) <> 0 then
-      begin
-      StepSoundTimer:= cHHStepTicks;
-      end;
-   
-   StepTicks:= cHHStepTicks;
-   if PrevdX <> hwSign(Gear^.dX) then
-      begin
-      FollowGear:= Gear;
-      exit
-      end;
-   DeleteCI(Gear); // must be after exit!! (see previous line)
-
-   Gear^.Hedgehog^.visStepPos:= (Gear^.Hedgehog^.visStepPos + 1) and 7;
-   if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then
-      begin
-      if not (TestCollisionXwithXYShift(Gear, _0, -6, hwSign(Gear^.dX))
-         or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1;
-      if not (TestCollisionXwithXYShift(Gear, _0, -5, hwSign(Gear^.dX))
-         or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1;
-      if not (TestCollisionXwithXYShift(Gear, _0, -4, hwSign(Gear^.dX))
-         or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1;
-      if not (TestCollisionXwithXYShift(Gear, _0, -3, hwSign(Gear^.dX))
-         or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1;
-      if not (TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX))
-         or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1;
-      if not (TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX))
-         or (TestCollisionYwithGear(Gear, -1) <> 0)) then Gear^.Y:= Gear^.Y - _1;
-      end;
-
-   if (not cArtillery) and ((Gear^.Message and gmPrecise) = 0) and (not TestCollisionXwithGear(Gear, hwSign(Gear^.dX))) then
-      Gear^.X:= Gear^.X + SignAs(_1, Gear^.dX);
-
-   SetAllHHToActive;
-
-   if TestCollisionYwithGear(Gear, 1) = 0 then
-   begin
-   Gear^.Y:= Gear^.Y + _1;
-   if TestCollisionYwithGear(Gear, 1) = 0 then
-   begin
-   Gear^.Y:= Gear^.Y + _1;
-   if TestCollisionYwithGear(Gear, 1) = 0 then
-   begin
-   Gear^.Y:= Gear^.Y + _1;
-   if TestCollisionYwithGear(Gear, 1) = 0 then
-   begin
-   Gear^.Y:= Gear^.Y + _1;
-   if TestCollisionYwithGear(Gear, 1) = 0 then
-   begin
-   Gear^.Y:= Gear^.Y + _1;
-   if TestCollisionYwithGear(Gear, 1) = 0 then
-   begin
-   Gear^.Y:= Gear^.Y + _1;
-   if TestCollisionYwithGear(Gear, 1) = 0 then
-      begin
-      Gear^.Y:= Gear^.Y - _6;
-      Gear^.dY:= _0;
-      Gear^.State:= Gear^.State or gstMoving;
-      exit
-      end;
-   end
-   end
-   end
-   end
-   end
-   end;
-   AddGearCI(Gear)
-   end
-end;
-
-procedure HedgehogChAngle(HHGear: PGear);
-var da: LongWord;
-begin
-with HHGear^.Hedgehog^ do
-    if ((CurAmmoType = amRope) and 
-        ((HHGear^.State and (gstMoving or gstHHJumping)) = gstMoving)) or
-       ((CurAmmoType = amPortalGun) and 
-        ((HHGear^.State and gstMoving) <> 0)) then da:= 2
-    else da:= 1;
-
-if (((HHGear^.Message and gmPrecise) = 0) or ((GameTicks mod 5) = 1)) then
-    if ((HHGear^.Message and gmUp) <> 0) and (HHGear^.Angle >= CurMinAngle + da) then dec(HHGear^.Angle, da)
-    else
-    if ((HHGear^.Message and gmDown) <> 0) and (HHGear^.Angle + da <= CurMaxAngle) then inc(HHGear^.Angle, da)
-end;
-
-
-////////////////////////////////////////////////////////////////////////////////
-procedure doStepHedgehogMoving(Gear: PGear);
-var isFalling, isUnderwater: boolean;
-    land: Word;
-begin
-land:= 0;
-isUnderwater:= cWaterLine < hwRound(Gear^.Y) + Gear^.Radius;
-if Gear^.dX.QWordValue > 8160437862 then Gear^.dX.QWordValue:= 8160437862;
-if Gear^.dY.QWordValue > 8160437862 then Gear^.dY.QWordValue:= 8160437862;
-
-if Gear^.Hedgehog^.Unplaced then
-   begin
-   Gear^.dY:= _0;
-   Gear^.dX:= _0;
-   Gear^.State:= Gear^.State and (not gstMoving);
-   exit
-   end;
-isFalling:= (Gear^.dY.isNegative) or not TestCollisionYKick(Gear, 1);
-if isFalling then
-   begin
-   if (Gear^.dY.isNegative) and TestCollisionYKick(Gear, -1) then Gear^.dY:= _0;
-   Gear^.State:= Gear^.State or gstMoving;
-   if (CurrentHedgehog^.Gear = Gear)
-        and (hwSqr(Gear^.dX) + hwSqr(Gear^.dY) > _0_003) then 
-        begin
-        FollowGear:= Gear;
-        end;
-   if isUnderwater then Gear^.dY:= Gear^.dY + cGravity / _2
-   else
-       begin
-       Gear^.dY:= Gear^.dY + cGravity;
-// this set of circumstances could be less complex if jumping was more clearly identified
-       if ((GameFlags and gfMoreWind) <> 0) and 
-          (((Gear^.Damage <> 0) or
-          ((CurAmmoGear <> nil) and
-            ((CurAmmoGear^.AmmoType = amJetpack) or
-            (CurAmmoGear^.AmmoType = amBirdy))) or
-          ((Gear^.dY.QWordValue + Gear^.dX.QWordValue) > _0_55.QWordValue)))
-          then Gear^.dX := Gear^.dX + cWindSpeed / Gear^.Density
-       end
-   end 
-else
-   begin
-   land:= TestCollisionYwithGear(Gear, 1);
-   if ((Gear^.dX.QWordValue + Gear^.dY.QWordValue) < _0_55.QWordValue) and ((land and lfIce) = 0)
-      and ((Gear^.State and gstHHJumping) <> 0) then SetLittle(Gear^.dX);
-
-   if not Gear^.dY.isNegative then
-      begin
-      CheckHHDamage(Gear);
-
-      if ((Gear^.State and gstHHHJump) <> 0) and (not cArtillery) and
-         (Gear^.dX.QWordValue < _0_02.QWordValue) then Gear^.dX.isNegative:= not Gear^.dX.isNegative; // landing after high jump
-
-      Gear^.State:= Gear^.State and (not (gstHHJumping or gstHHHJump));
-      Gear^.dY:= _0;
-      end else Gear^.dY:= Gear^.dY + cGravity;
-
-   if ((Gear^.State and gstMoving) <> 0) then
-       begin
-       if land and lfIce <> 0 then
-           begin
-           Gear^.dX:= Gear^.dX * (_1 - (_1 - Gear^.Friction) / _2)
-           end
-       else Gear^.dX:= Gear^.dX * Gear^.Friction;
-       end
-   end;
-
-if (Gear^.State <> 0) then DeleteCI(Gear);
-
-if isUnderwater then
-   begin
-   Gear^.dY:= Gear^.dY * _0_999;
-   Gear^.dX:= Gear^.dX * _0_999;
-   end;
-
-if (Gear^.State and gstMoving) <> 0 then
-   if TestCollisionXKick(Gear, hwSign(Gear^.dX)) then
-      if not isFalling then
-         if hwAbs(Gear^.dX) > _0_01 then
-            if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX)) - Gear^.dX, -1, hwSign(Gear^.dX)) then begin Gear^.X:= Gear^.X + Gear^.dX; Gear^.dX:= Gear^.dX * _0_96; Gear^.Y:= Gear^.Y - _1 end else
-            if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX)) - Gear^.dX, -2, hwSign(Gear^.dX)) then begin Gear^.X:= Gear^.X + Gear^.dX; Gear^.dX:= Gear^.dX * _0_93; Gear^.Y:= Gear^.Y - _2 end else
-            if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX)) - Gear^.dX, -3, hwSign(Gear^.dX)) then begin Gear^.X:= Gear^.X + Gear^.dX; Gear^.dX:= Gear^.dX * _0_9 ; Gear^.Y:= Gear^.Y - _3 end else
-            if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX)) - Gear^.dX, -4, hwSign(Gear^.dX)) then begin Gear^.X:= Gear^.X + Gear^.dX; Gear^.dX:= Gear^.dX * _0_87; Gear^.Y:= Gear^.Y - _4 end else
-            if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX)) - Gear^.dX, -5, hwSign(Gear^.dX)) then begin Gear^.X:= Gear^.X + Gear^.dX; Gear^.dX:= Gear^.dX * _0_84; Gear^.Y:= Gear^.Y - _5 end else
-            if hwAbs(Gear^.dX) > _0_02 then Gear^.dX:= -Gear^.Elasticity * Gear^.dX
-                                   else begin
-                                        Gear^.State:= Gear^.State and (not gstMoving);
-                                        while TestCollisionYWithGear(Gear,1) = 0 do Gear^.Y:= Gear^.Y+_1;
-                                        SetLittle(Gear^.dX)
-                                        end
-            else begin
-                 Gear^.State:= Gear^.State and (not gstMoving);
-                 while TestCollisionYWithGear(Gear,1) = 0 do Gear^.Y:= Gear^.Y+_1;
-                 SetLittle(Gear^.dX)
-                 end
-         else if (hwAbs(Gear^.dX) > cLittle)
-                and ((Gear^.State and gstHHJumping) = 0)
-                then Gear^.dX:= -Gear^.Elasticity * Gear^.dX
-                else SetLittle(Gear^.dX);
-
-if (not isFalling) and
-   (hwAbs(Gear^.dX) + hwAbs(Gear^.dY) < _0_03) then
-   begin
-   Gear^.State:= Gear^.State and (not gstWinner);
-   Gear^.State:= Gear^.State and (not gstMoving);
-   while TestCollisionYWithGear(Gear,1) = 0 do Gear^.Y:= Gear^.Y+_1;
-   SetLittle(Gear^.dX);
-   Gear^.dY:= _0
-   end else Gear^.State:= Gear^.State or gstMoving;
-
-if (Gear^.State and gstMoving) <> 0 then
-   begin
-   Gear^.State:= Gear^.State and (not gstAnimation);
-// ARTILLERY but not being moved by explosions
-   Gear^.X:= Gear^.X + Gear^.dX;
-   Gear^.Y:= Gear^.Y + Gear^.dY;
-   if (not Gear^.dY.isNegative) and
-      (not TestCollisionYKick(Gear, 1)) and
-       TestCollisionYwithXYShift(Gear, 0, 1, 1) then
-      begin
-      CheckHHDamage(Gear);
-      Gear^.dY:= _0;
-      Gear^.Y:= Gear^.Y + _1
-      end;
-   CheckGearDrowning(Gear);
-   // hide target cursor if current hog is drowning
-   if (Gear^.State and gstDrowning) <> 0 then
-       if (CurrentHedgehog^.Gear = Gear) then
-          isCursorVisible:= false
-   end;
-
-if (hwAbs(Gear^.dY) > _0) and (Gear^.FlightTime > 0) and ((GameFlags and gfLowGravity) = 0) then
-    begin
-    inc(Gear^.FlightTime);
-    if Gear^.FlightTime = 3000 then
-        begin
-        AddCaption(GetEventString(eidHomerun), cWhiteColor, capgrpMessage);
-        PlaySound(sndHomerun)
-        end;
-    end
-else
-    begin
-    uStats.hedgehogFlight(Gear, Gear^.FlightTime);
-    Gear^.FlightTime:= 0;
-    end;
-
-end;
-
-procedure doStepHedgehogDriven(HHGear: PGear);
-var t: PGear;
-    wasJumping: boolean;
-    Hedgehog: PHedgehog;
-begin
-Hedgehog:= HHGear^.Hedgehog;
-if isInMultiShoot then
-   HHGear^.Message:= 0;
-
-if ((Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_Utility) <> 0) and isInMultiShoot then 
-    AllInactive:= true
-else if not isInMultiShoot then AllInactive:= false;
-
-if (TurnTimeLeft = 0) or (HHGear^.Damage > 0) then
-    begin
-    if TagTurnTimeLeft = 0 then TagTurnTimeLeft:= TurnTimeLeft;
-    TurnTimeLeft:= 0;
-    isCursorVisible:= false;
-    HHGear^.State:= HHGear^.State and (not (gstHHDriven or gstAnimation or gstAttacking));
-    AttackBar:= 0;
-    if HHGear^.Damage > 0 then
-        HHGear^.State:= HHGear^.State and (not (gstHHJumping or gstHHHJump));
-    exit
-    end;
-
-if (HHGear^.State and gstAnimation) <> 0 then
-    begin
-    HHGear^.Message:= 0;
-    if (HHGear^.Pos = Wavez[TWave(HHGear^.Tag)].VoiceDelay) and (HHGear^.Timer = 0) then PlaySound(Wavez[TWave(HHGear^.Tag)].Voice, Hedgehog^.Team^.voicepack);
-    inc(HHGear^.Timer);
-    if HHGear^.Timer = Wavez[TWave(HHGear^.Tag)].Interval then
-        begin
-        HHGear^.Timer:= 0;
-        inc(HHGear^.Pos);
-        if HHGear^.Pos = Wavez[TWave(HHGear^.Tag)].FramesCount then
-            HHGear^.State:= HHGear^.State and (not gstAnimation)
-        end;
-    exit
-    end;
-
-if ((HHGear^.State and gstMoving) <> 0)
-    or (StepTicks = cHHStepTicks)
-    or (CurAmmoGear <> nil) then // we are moving
-    begin
-    with Hedgehog^ do
-        if (CurAmmoGear = nil)
-        and (HHGear^.dY > _0_39)
-        and (CurAmmoType = amParachute) then HHGear^.Message:= HHGear^.Message or gmAttack;
-    // check for case with ammo
-    t:= CheckGearNear(HHGear, gtCase, 36, 36);
-    if t <> nil then
-        PickUp(HHGear, t)
-    end;
-
-if (CurAmmoGear = nil) then
-    if (((HHGear^.Message and gmAttack) <> 0)
-        or ((HHGear^.State and gstAttacking) <> 0)) then
-        Attack(HHGear) // should be before others to avoid desync with '/put' msg and changing weapon msgs
-    else
-else 
-    with Hedgehog^ do
-        if ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) <> 0)
-            and ((HHGear^.Message and gmLJump) <> 0)
-            and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_AltUse) <> 0) then
-            begin
-            Attack(HHGear);
-            HHGear^.Message:= HHGear^.Message and (not gmLJump)
-            end;
-
-if (CurAmmoGear = nil)
-    or ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) <> 0) 
-    or ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_NoRoundEnd) <> 0) then
-    begin
-    if ((HHGear^.Message and gmSlot) <> 0) then
-        if ChangeAmmo(HHGear) then ApplyAmmoChanges(Hedgehog^);
-
-    if ((HHGear^.Message and gmWeapon) <> 0) then HHSetWeapon(HHGear);
-
-    if ((HHGear^.Message and gmTimer) <> 0) then HHSetTimer(HHGear);
-    end;
-
-if CurAmmoGear <> nil then
-   begin
-   CurAmmoGear^.Message:= HHGear^.Message;
-   exit
-   end;
-
-if not isInMultiShoot then
-   HedgehogChAngle(HHGear);
-
-if (HHGear^.State and gstMoving) <> 0 then
-    begin
-    wasJumping:= ((HHGear^.State and gstHHJumping) <> 0);
-
-    if ((HHGear^.Message and gmHJump) <> 0) and
-        wasJumping and
-        ((HHGear^.State and gstHHHJump) = 0) then
-        if (not (hwAbs(HHGear^.dX) > cLittle)) and (HHGear^.dY < -_0_02) then
-            begin
-            HHGear^.State:= HHGear^.State or gstHHHJump;
-            HHGear^.dY:= -_0_25;
-            if not cArtillery then HHGear^.dX:= -SignAs(_0_02, HHGear^.dX);
-            PlaySound(sndJump2, Hedgehog^.Team^.voicepack)
-            end;
-
-    HHGear^.Message:= HHGear^.Message and (not (gmLJump or gmHJump));
-
-    if (not cArtillery) and wasJumping and
-        TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then SetLittle(HHGear^.dX);
-
-    if Hedgehog^.Gear <> nil then doStepHedgehogMoving(HHGear);
-
-    if ((HHGear^.State and (gstMoving or gstDrowning)) = 0) then
-        begin
-        AddGearCI(HHGear);
-        if wasJumping then
-            StepTicks:= 410
-        else
-            StepTicks:= 95
-        end;
-    exit
-    end;
-
-    if not isInMultiShoot and (Hedgehog^.Gear <> nil) then
-        begin
-        if StepTicks > 0 then dec(StepTicks);
-        if (StepTicks = 0) then HedgehogStep(HHGear)
-        end
-end;
-
-////////////////////////////////////////////////////////////////////////////////
-procedure doStepHedgehogFree(Gear: PGear);
-var prevState: Longword;
-begin
-prevState:= Gear^.State;
-
-doStepHedgehogMoving(Gear);
-
-if (Gear^.State and (gstMoving or gstDrowning)) <> 0 then
-    begin
-    if Gear^.Damage > 0 then CalcRotationDirAngle(Gear);
-    AllInactive:= false;
-    exit
-    end;
-
-if (Gear^.Health = 0) then
-    begin
-    if PrvInactive or ((GameFlags and gfInfAttack) <> 0) then
-        begin
-        Gear^.Timer:= 0;
-        FollowGear:= Gear;
-        PrvInactive:= false;
-        AllInactive:= false;
-
-        if (Gear^.State and gstHHGone) = 0 then
-            begin
-            Gear^.Hedgehog^.Effects[hePoisoned] := false;
-            if Gear^.Hedgehog^.Effects[heResurrectable] then begin
-                ResurrectHedgehog(Gear);
-            end else 
-                begin
-                Gear^.State:= (Gear^.State or gstHHDeath) and (not gstAnimation);
-                Gear^.doStep:= @doStepHedgehogDead;
-                // Death message
-                AddCaption(Format(GetEventString(eidDied), Gear^.Hedgehog^.Name), cWhiteColor, capgrpMessage);
-                end;
-            end
-        else
-            begin
-            Gear^.State:= Gear^.State and (not gstAnimation);
-            Gear^.doStep:= @doStepHedgehogGone;
-
-            // Gone message
-            AddCaption(Format(GetEventString(eidGone), Gear^.Hedgehog^.Name), cWhiteColor, capgrpMessage);
-            end
-        end;
-    exit
-    end;
-
-if ((Gear^.State and gstWait) = 0) and
-    (prevState <> Gear^.State) then
-    begin
-    Gear^.State:= Gear^.State or gstWait;
-    Gear^.Timer:= 150
-    end else
-    begin
-    if Gear^.Timer = 0 then
-        begin
-        Gear^.State:= Gear^.State and (not (gstWait or gstLoser or gstWinner or gstAttacked or gstNotKickable or gstHHChooseTarget));
-        Gear^.Active:= false;
-        AddGearCI(Gear);
-        exit
-        end else dec(Gear^.Timer)
-    end;
-
-AllInactive:= false
-end;
-
-////////////////////////////////////////////////////////////////////////////////
-procedure doStepHedgehog(Gear: PGear);
-(*
-var x,y,tx,ty: LongInt;
-    tdX, tdY, slope: hwFloat; 
-    land: Word; *)
-var slope: hwFloat; 
-begin
-if (Gear^.Message and gmDestroy) <> 0 then
-    begin
-    DeleteGear(Gear);
-    exit
-    end;
-
-if (Gear^.State and gstHHDriven) = 0 then
-    doStepHedgehogFree(Gear)
-else
-    begin
-    with Gear^.Hedgehog^ do
-        if Team^.hasGone then
-            TeamGoneEffect(Team^)
-        else
-            doStepHedgehogDriven(Gear)
-    end;
-if (Gear^.Message and (gmAllStoppable or gmLJump or gmHJump) = 0) and
-   (Gear^.State and (gstHHJumping or gstHHHJump or gstAttacking) = 0) and
-   (not Gear^.dY.isNegative) and
-   (GameTicks mod (100*LongWOrd(hwRound(cMaxWindSpeed*2/cGravity))) = 0) and
-   (TestCollisionYwithGear(Gear, 1) and lfIce <> 0) then
-    begin
-    slope:= CalcSlopeBelowGear(Gear);
-    Gear^.dX:=Gear^.dX+slope*_0_07;
-    if slope.QWordValue <> 0 then Gear^.State:= Gear^.State or gstMoving;
-(*
-    x:= hwRound(Gear^.X);
-    y:= hwRound(Gear^.Y);
-    AddVisualGear(x, y, vgtSmokeTrace);
-    AddVisualGear(x - hwRound(_5*slope), y + hwRound(_5*slope), vgtSmokeTrace);
-    AddVisualGear(x + hwRound(_5*slope), y - hwRound(_5*slope), vgtSmokeTrace);
-    AddVisualGear(x - hwRound(_20 * slope), y + hwRound(_20 * slope), vgtSmokeTrace);
-    AddVisualGear(x + hwRound(_20 * slope), y - hwRound(_20 * slope), vgtSmokeTrace);
-    AddVisualGear(x - hwRound(_30 * slope), y + hwRound(_30 * slope), vgtSmokeTrace);
-    AddVisualGear(x + hwRound(_30 * slope), y - hwRound(_30 * slope), vgtSmokeTrace);
-    AddVisualGear(x - hwRound(_40 * slope), y + hwRound(_40 * slope), vgtSmokeTrace);
-    AddVisualGear(x + hwRound(_40 * slope), y - hwRound(_40 * slope), vgtSmokeTrace);
-    AddVisualGear(x - hwRound(_50 * slope), y + hwRound(_50 * slope), vgtSmokeTrace);
-    AddVisualGear(x + hwRound(_50 * slope), y - hwRound(_50 * slope), vgtSmokeTrace); *)
-    end
-end;
-
-end.
+(*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (c) 2004-2011 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * 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
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *)
+
+{$INCLUDE "options.inc"}
+
+unit uGearsHedgehog;
+interface
+uses uTypes;
+
+procedure doStepHedgehog(Gear: PGear);
+procedure AfterAttack; 
+procedure HedgehogStep(Gear: PGear); 
+procedure doStepHedgehogMoving(Gear: PGear); 
+procedure HedgehogChAngle(HHGear: PGear); 
+procedure PickUp(HH, Gear: PGear);
+
+implementation
+uses uConsts, uVariables, uFloat, uAmmos, uSound, uCaptions, uMisc, 
+    uCommands, uLocale, uUtils, uVisualGears, uStats, uIO, uScript,
+    uGearsList, uGears, uCollisions, uRandom, uStore, uTeams, 
+    uGearsUtils;
+
+// Shouldn't more of this ammo switching stuff be moved to uAmmos ?
+function ChangeAmmo(HHGear: PGear): boolean;
+var slot, i: Longword;
+    ammoidx: LongInt;
+begin
+ChangeAmmo:= false;
+slot:= HHGear^.MsgParam;
+
+with HHGear^.Hedgehog^ do
+    begin
+    HHGear^.Message:= HHGear^.Message and (not gmSlot);
+    ammoidx:= 0;
+    if ((HHGear^.State and (gstAttacking or gstAttacked)) <> 0)
+    or ((MultiShootAttacks > 0) and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_NoRoundEnd) = 0))
+    or ((HHGear^.State and gstHHDriven) = 0) then
+        exit;
+    ChangeAmmo:= true;
+
+    while (ammoidx < cMaxSlotAmmoIndex) and (Ammo^[slot, ammoidx].AmmoType <> CurAmmoType) do
+        inc(ammoidx);
+
+    if ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_NoRoundEnd) <> 0) and (MultiShootAttacks > 0) then
+        OnUsedAmmo(HHGear^.Hedgehog^);
+
+    MultiShootAttacks:= 0;
+    HHGear^.Message:= HHGear^.Message and (not (gmLJump or gmHJump));
+    
+    if Ammoz[CurAmmoType].Slot = slot then
+        begin
+        i:= 0;
+        repeat
+        inc(ammoidx);
+        if (ammoidx > cMaxSlotAmmoIndex) then
+            begin
+            inc(i);
+            CurAmmoType:= amNothing;
+            ammoidx:= -1;
+            //TryDo(i < 2, 'Engine bug: no ammo in current slot', true)
+            end;
+        until (i = 1) or ((Ammo^[slot, ammoidx].Count > 0)
+        and (Team^.Clan^.TurnNumber > Ammoz[Ammo^[slot, ammoidx].AmmoType].SkipTurns))
+        
+        end 
+    else
+        begin
+        i:= 0;
+        // check whether there is ammo in slot
+        while (i <= cMaxSlotAmmoIndex) and ((Ammo^[slot, i].Count = 0)
+        or (Team^.Clan^.TurnNumber <= Ammoz[Ammo^[slot, i].AmmoType].SkipTurns))
+            do inc(i);
+
+        if i <= cMaxSlotAmmoIndex then
+            ammoidx:= i
+        else ammoidx:= -1
+        end;
+        if ammoidx >= 0 then
+            CurAmmoType:= Ammo^[slot, ammoidx].AmmoType;
+    end
+end;
+
+procedure HHSetWeapon(HHGear: PGear);
+var t: LongInt;
+    weap: TAmmoType;
+    Hedgehog: PHedgehog;
+    s: boolean;
+begin
+s:= false;
+
+weap:= TAmmoType(HHGear^.MsgParam);
+Hedgehog:= HHGear^.Hedgehog;
+
+if Hedgehog^.Team^.Clan^.TurnNumber <= Ammoz[weap].SkipTurns then
+    exit; // weapon is not activated yet
+
+HHGear^.MsgParam:= Ammoz[weap].Slot;
+
+t:= cMaxSlotAmmoIndex;
+
+HHGear^.Message:= HHGear^.Message and (not gmWeapon);
+
+with Hedgehog^ do
+    while (CurAmmoType <> weap) and (t >= 0) do
+        begin
+        s:= ChangeAmmo(HHGear);
+        dec(t)
+        end;
+
+if s then
+    ApplyAmmoChanges(HHGear^.Hedgehog^)
+end;
+
+procedure HHSetTimer(Gear: PGear);
+var CurWeapon: PAmmo;
+    color: LongWord;
+begin
+Gear^.Message:= Gear^.Message and (not gmTimer);
+CurWeapon:= GetAmmoEntry(Gear^.Hedgehog^);
+with Gear^.Hedgehog^ do
+    if ((Gear^.Message and gmPrecise) <> 0) and ((CurWeapon^.Propz and ammoprop_SetBounce) <> 0) then
+        begin
+        color:= Gear^.Hedgehog^.Team^.Clan^.Color;
+        case Gear^.MsgParam of
+            1: begin
+               AddCaption(format(trmsg[sidBounce], trmsg[sidBounce1]), color, capgrpAmmostate);
+               CurWeapon^.Bounciness:= 350;
+               end;
+            2: begin
+               AddCaption(format(trmsg[sidBounce], trmsg[sidBounce2]), color, capgrpAmmostate);
+               CurWeapon^.Bounciness:= 700;
+               end;
+            3: begin
+               AddCaption(format(trmsg[sidBounce], trmsg[sidBounce3]), color, capgrpAmmostate);
+               CurWeapon^.Bounciness:= 1000;
+               end;
+            4: begin
+               AddCaption(format(trmsg[sidBounce], trmsg[sidBounce4]), color, capgrpAmmostate);
+               CurWeapon^.Bounciness:= 2000;
+               end;
+            5: begin
+               AddCaption(format(trmsg[sidBounce], trmsg[sidBounce5]), color, capgrpAmmostate);
+               CurWeapon^.Bounciness:= 4000;
+               end
+            end
+        end
+    else if (CurWeapon^.Propz and ammoprop_Timerable) <> 0 then
+        begin
+        CurWeapon^.Timer:= 1000 * Gear^.MsgParam;
+        with CurrentTeam^ do
+            ApplyAmmoChanges(Hedgehogs[CurrHedgehog]);
+        end;
+end;
+
+
+procedure Attack(Gear: PGear);
+var xx, yy, newDx, newDy, lx, ly: hwFloat;
+    speech: PVisualGear;
+    newGear:  PGear;
+    CurWeapon: PAmmo;
+    altUse: boolean;
+    elastic: hwFloat;
+begin
+newGear:= nil;
+bShowFinger:= false;
+CurWeapon:= GetAmmoEntry(Gear^.Hedgehog^);
+with Gear^,
+    Gear^.Hedgehog^ do
+        begin
+        if ((State and gstHHDriven) <> 0) and ((State and (gstAttacked or gstHHChooseTarget)) = 0) and (((State and gstMoving) = 0)
+        or (Power > 0)
+        or (CurAmmoType = amTeleport)
+        or 
+        // Allow attacks while moving on ammo with AltAttack
+        ((CurAmmoGear <> nil) and ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) <> 0))
+        or ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_AttackInMove) <> 0))
+        and ((TargetPoint.X <> NoPointX) or ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_NeedTarget) = 0)) then
+            begin
+            State:= State or gstAttacking;
+            if Power = cMaxPower then
+                Message:= Message and (not gmAttack)
+            else if (Ammoz[CurAmmoType].Ammo.Propz and ammoprop_Power) = 0 then
+                Message:= Message and (not gmAttack)
+            else
+                begin
+                if Power = 0 then
+                    begin
+                    AttackBar:= CurrentTeam^.AttackBar;
+                    PlaySound(sndThrowPowerUp)
+                    end;
+                inc(Power)
+                end;
+        if ((Message and gmAttack) <> 0) then
+            exit;
+
+        if (Ammoz[CurAmmoType].Ammo.Propz and ammoprop_Power) <> 0 then
+            begin
+            StopSound(sndThrowPowerUp);
+            PlaySound(sndThrowRelease);
+            end;
+
+        xx:= SignAs(AngleSin(Angle), dX);
+        yy:= -AngleCos(Angle);
+
+        lx:= X + int2hwfloat(round(GetLaunchX(CurAmmoType, hwSign(dX), Angle)));
+        ly:= Y + int2hwfloat(round(GetLaunchY(CurAmmoType, Angle)));
+
+        if ((Gear^.State and gstHHHJump) <> 0) and (not cArtillery) then
+            xx:= - xx;
+        if Ammoz[CurAmmoType].Ammo.AttackVoice <> sndNone then
+            AddVoice(Ammoz[CurAmmoType].Ammo.AttackVoice, CurrentTeam^.voicepack);
+
+// Initiating alt attack
+        if  (CurAmmoGear <> nil)
+        and ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) <> 0)
+        and ((Gear^.Message and gmLJump) <> 0)
+        and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_AltUse) <> 0) then
+            begin
+            newDx:= dX / _2; 
+            newDy:= dY / _2;
+            altUse:= true;
+            end
+        else
+            begin
+            newDx:= xx*Power/cPowerDivisor;
+            newDy:= yy*Power/cPowerDivisor;
+            altUse:= false
+            end;
+
+             case CurAmmoType of
+                      amGrenade: newGear:= AddGear(hwRound(lx), hwRound(ly), gtGrenade,         0, newDx, newDy, CurWeapon^.Timer);
+                      amMolotov: newGear:= AddGear(hwRound(lx), hwRound(ly), gtMolotov,      0, newDx, newDy, 0);
+                  amClusterBomb: newGear:= AddGear(hwRound(lx), hwRound(ly), gtClusterBomb,  0, newDx, newDy, CurWeapon^.Timer);
+                      amGasBomb: newGear:= AddGear(hwRound(lx), hwRound(ly), gtGasBomb,      0, newDx, newDy, CurWeapon^.Timer);
+                      amBazooka: newGear:= AddGear(hwRound(lx), hwRound(ly), gtShell,        0, newDx, newDy, 0);
+                     amSnowball: newGear:= AddGear(hwRound(lx), hwRound(ly), gtSnowball,     0, newDx, newDy, 0);
+                          amBee: newGear:= AddGear(hwRound(lx), hwRound(ly), gtBee,          0, newDx, newDy, 0);
+                      amShotgun: begin
+                                 PlaySound(sndShotgunReload);
+                                 newGear:= AddGear(hwRound(lx), hwRound(ly), gtShotgunShot,  0, xx * _0_5, yy * _0_5, 0);
+                                 end;
+                   amPickHammer: newGear:= AddGear(hwRound(lx), hwRound(ly) + cHHRadius, gtPickHammer, 0, _0, _0, 0);
+                         amSkip: ParseCommand('/skip', true);
+                         amRope: newGear:= AddGear(hwRound(lx), hwRound(ly), gtRope, 0, xx, yy, 0);
+                         amMine: if altUse then
+                                     newGear:= AddGear(hwRound(lx) + hwSign(dX) * 7, hwRound(ly), gtMine, gstWait, newDx, newDy, 3000)
+                                 else
+                                     newGear:= AddGear(hwRound(lx) + hwSign(dX) * 7, hwRound(ly), gtMine, gstWait, SignAs(_0_02, dX), _0, 3000);
+                        amSMine: newGear:= AddGear(hwRound(lx), hwRound(ly), gtSMine,    0, xx*Power/cPowerDivisor, yy*Power/cPowerDivisor, 0);
+                       amDEagle: newGear:= AddGear(hwRound(lx + xx * cHHRadius), hwRound(ly + yy * cHHRadius), gtDEagleShot, 0, xx * _0_5, yy * _0_5, 0);
+                      amSineGun: newGear:= AddGear(hwRound(lx + xx * cHHRadius), hwRound(ly + yy * cHHRadius), gtSineGunShot, 0, xx * _0_5, yy * _0_5, 0);
+                    amPortalGun: begin
+                                 newGear:= AddGear(hwRound(lx + xx * cHHRadius), hwRound(ly + yy * cHHRadius), gtPortal, 0, xx * _0_6, yy * _0_6, 
+                                 // set selected color
+                                 CurWeapon^.Pos);
+                                 end;
+                  amSniperRifle: begin
+                                 PlaySound(sndSniperReload);
+                                 newGear:= AddGear(hwRound(lx + xx * cHHRadius), hwRound(ly + yy * cHHRadius), gtSniperRifleShot, 0, xx * _0_5, yy * _0_5, 0);
+                                 end;
+                     amDynamite: newGear:= AddGear(hwRound(lx) + hwSign(dX) * 7, hwRound(ly), gtDynamite, 0, SignAs(_0_03, dX), _0, 5000);
+                    amFirePunch: newGear:= AddGear(hwRound(lx) + hwSign(dX) * 10, hwRound(ly), gtFirePunch, 0, xx, _0, 0);
+                         amWhip: begin
+                                 newGear:= AddGear(hwRound(lx) + hwSign(dX) * 10, hwRound(ly), gtWhip, 0, SignAs(_1, dX), - _0_8, 0);
+                                 PlaySound(sndWhipCrack)
+                                 end;
+                       amHammer: begin
+                                 newGear:= AddGear(hwRound(lx) + hwSign(dX) * 10, hwRound(ly), gtHammer, 0, SignAs(_1, dX), - _0_8, 0);
+                                 PlaySound(sndWhack)
+                                 end;
+                  amBaseballBat: begin
+                                 newGear:= AddGear(hwRound(lx) + hwSign(dX) * 10, hwRound(ly), gtShover, gsttmpFlag, xx * _0_5, yy * _0_5, 0);
+                                 PlaySound(sndBaseballBat) // TODO: Only play if something is hit?
+                                 end;
+                    amParachute: begin
+                                 newGear:= AddGear(hwRound(lx), hwRound(ly), gtParachute, 0, _0, _0, 0);
+                                 PlaySound(sndParachute)
+                                 end;
+                    // we save CurWeapon^.Pos (in this case: cursor direction) by using it as (otherwise irrelevant) X value of the new gear.
+                    amAirAttack: newGear:= AddGear(CurWeapon^.Pos, 0, gtAirAttack, 0, _0, _0, 0);
+                   amMineStrike: newGear:= AddGear(CurWeapon^.Pos, 0, gtAirAttack, 1, _0, _0, 0);
+                  amDrillStrike: newGear:= AddGear(CurWeapon^.Pos, 0, gtAirAttack, 3, _0, _0, CurWeapon^.Timer);
+                       amNapalm: newGear:= AddGear(CurWeapon^.Pos, 0, gtAirAttack, 2, _0, _0, 0);
+                    amBlowTorch: newGear:= AddGear(hwRound(lx), hwRound(ly), gtBlowTorch, 0, SignAs(_0_5, dX), _0, 0);
+                       amGirder: newGear:= AddGear(0, 0, gtGirder, CurWeapon^.Pos, _0, _0, 0);
+                     amTeleport: newGear:= AddGear(CurWeapon^.Pos, 0, gtTeleport, 0, _0, _0, 0);
+                       amSwitch: newGear:= AddGear(hwRound(lx), hwRound(ly), gtSwitcher, 0, _0, _0, 0);
+                       amMortar: begin
+                                 playSound(sndMortar);
+                                 newGear:= AddGear(hwRound(lx), hwRound(ly), gtMortar,  0, xx*cMaxPower/cPowerDivisor, yy*cMaxPower/cPowerDivisor, 0);
+                                 end;
+                      amRCPlane: begin
+                                 newGear:= AddGear(hwRound(lx), hwRound(ly), gtRCPlane,  0, xx * cMaxPower / cPowerDivisor / 4, yy * cMaxPower / cPowerDivisor / 4, 0);
+                                 newGear^.SoundChannel:= LoopSound(sndRCPlane, nil)
+                                 end;
+                     amKamikaze: newGear:= AddGear(hwRound(lx), hwRound(ly), gtKamikaze, 0, xx * _0_5, yy * _0_5, 0);
+                         amCake: newGear:= AddGear(hwRound(lx) + hwSign(dX) * 3, hwRound(ly), gtCake, 0, xx, _0, 0);
+                    amSeduction: newGear:= AddGear(hwRound(lx), hwRound(ly), gtSeduction, 0, _0, _0, 0);
+                   amWatermelon: newGear:= AddGear(hwRound(lx), hwRound(ly), gtWatermelon,  0, newDx, newDy, CurWeapon^.Timer);
+                  amHellishBomb: newGear:= AddGear(hwRound(lx), hwRound(ly), gtHellishBomb,    0, newDx, newDy, 0);
+                        amDrill: newGear:= AddGear(hwRound(lx), hwRound(ly), gtDrill, 0, newDx, newDy, 0);
+                      amBallgun: newGear:= AddGear(hwRound(X), hwRound(Y), gtBallgun,  0, xx * _0_5, yy * _0_5, 0);
+                      amJetpack: newGear:= AddGear(hwRound(lx), hwRound(ly), gtJetpack, 0, _0, _0, 0);
+                        amBirdy: begin
+                             PlaySound(sndWhistle);
+                             newGear:= AddGear(hwRound(lx), hwRound(ly) - 32, gtBirdy, 0, _0, _0, 0);
+                             end;
+                   amLowGravity: begin
+                                 PlaySound(sndLowGravity);
+                                 cGravity:= cMaxWindSpeed;
+                                 cGravityf:= 0.00025
+                                 end;
+                  amExtraDamage: begin 
+                                 PlaySound(sndHellishImpact4);
+                                 cDamageModifier:= _1_5
+                                 end;
+                 amInvulnerable: Invulnerable:= true;
+                    amExtraTime: begin
+                                 PlaySound(sndSwitchHog);
+                                 TurnTimeLeft:= TurnTimeLeft + 30000
+                                 end;
+                   amLaserSight: cLaserSighting:= true;
+                     amVampiric: begin
+                                 PlaySound(sndOw1, Team^.voicepack);
+                                 cVampiric:= true;
+                                 end;
+                        amPiano: begin
+                                 // Tuck the hedgehog away until the piano attack is completed
+                                 Unplaced:= true;
+                                 X:= _0;
+                                 Y:= _0;
+                                 newGear:= AddGear(TargetPoint.X, 0, gtPiano, 0, _0, _0, 0);
+                                 PauseMusic
+                                 end;
+                 amFlamethrower: newGear:= AddGear(hwRound(X), hwRound(Y), gtFlamethrower,  0, xx * _0_5, yy * _0_5, 0);
+                      amLandGun: newGear:= AddGear(hwRound(X), hwRound(Y), gtLandGun,  0, xx * _0_5, yy * _0_5, 0);
+                  amResurrector: begin
+                                 newGear:= AddGear(hwRound(lx), hwRound(ly), gtResurrector, 0, _0, _0, 0);
+                                 newGear^.SoundChannel := LoopSound(sndResurrector);
+                                 end;
+                                 //amMelonStrike: AddGear(CurWeapon^.Pos, 0, gtAirAttack, 4, _0, _0, 0);
+                    amStructure: newGear:= AddGear(hwRound(lx) + hwSign(dX) * 7, hwRound(ly), gtStructure, gstWait, SignAs(_0_02, dX), _0, 3000);
+                       amTardis: newGear:= AddGear(hwRound(X), hwRound(Y), gtTardis, 0, _0, _0, 5000);
+             end;
+             
+             case CurAmmoType of
+                      amGrenade, amMolotov, 
+                  amClusterBomb, amGasBomb, 
+                      amBazooka, amSnowball, 
+                          amBee, amSMine,
+                       amMortar, amWatermelon,
+                  amHellishBomb, amDrill: FollowGear:= newGear;
+
+                      amShotgun, amPickHammer,
+                         amRope, amDEagle,
+                      amSineGun, amSniperRifle,
+                    amFirePunch, amWhip,
+                       amHammer, amBaseballBat,
+                    amParachute, amBlowTorch,
+                       amGirder, amTeleport,
+                       amSwitch, amRCPlane,
+                     amKamikaze, amCake,
+                    amSeduction, amBallgun,
+                      amJetpack, amBirdy,
+                 amFlamethrower, amLandGun,
+                  amResurrector, amStructure,
+                       amTardis, amPiano: CurAmmoGear:= newGear;
+             end;
+             
+            if ((CurAmmoType = amMine) or (CurAmmoType = amSMine)) and (GameFlags and gfInfAttack <> 0) then
+                newGear^.FlightTime:= GameTicks + 1000
+            else if CurAmmoType = amDrill then
+                newGear^.FlightTime:= GameTicks + 250;
+        if Ammoz[CurAmmoType].Ammo.Propz and ammoprop_NeedTarget <> 0 then
+            begin
+            newGear^.Target.X:= TargetPoint.X;
+            newGear^.Target.Y:= TargetPoint.Y
+            end;
+
+        // Clear FollowGear if using on a rope/parachute/saucer etc so focus stays with the hog's movement
+        if altUse then
+            FollowGear:= nil;
+
+        if (newGear <> nil) and ((Ammoz[newGear^.AmmoType].Ammo.Propz and ammoprop_SetBounce) <> 0) then
+            begin
+            elastic:=  int2hwfloat(CurWeapon^.Bounciness) / _1000;
+
+            if elastic < _1 then
+                newGear^.Elasticity:= newGear^.Elasticity * elastic
+            else if elastic > _1 then
+                newGear^.Elasticity:= _1 - ((_1-newGear^.Elasticity) / elastic);
+(* Experimented with friction modifier. Didn't seem helpful 
+            fric:= int2hwfloat(CurWeapon^.Bounciness) / _250;
+            if fric < _1 then newGear^.Friction:= newGear^.Friction * fric
+            else if fric > _1 then newGear^.Friction:= _1 - ((_1-newGear^.Friction) / fric)*)
+            end;
+
+
+        uStats.AmmoUsed(CurAmmoType);
+
+        if not (SpeechText = '') then
+            begin
+            speech:= AddVisualGear(0, 0, vgtSpeechBubble);
+            if speech <> nil then
+                begin
+                speech^.Text:= SpeechText;
+                speech^.Hedgehog:= Gear^.Hedgehog;
+                speech^.FrameTicks:= SpeechType;
+                end;
+            SpeechText:= ''
+            end;
+
+        Power:= 0;
+        if (CurAmmoGear <> nil)
+            and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_AltUse) = 0){check for dropping ammo from rope} then
+            begin
+            Message:= Message or gmAttack;
+            CurAmmoGear^.Message:= Message
+            end
+        else
+            begin
+            if not CurrentTeam^.ExtDriven
+            and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_Power) <> 0) then
+                SendIPC('a');
+            AfterAttack;
+            end
+        end
+    else 
+        Message:= Message and (not gmAttack);
+    end;
+    TargetPoint.X := NoPointX;
+    ScriptCall('onHogAttack');
+end;
+
+procedure AfterAttack;
+var s: shortstring;
+    a: TAmmoType;
+begin
+with CurrentHedgehog^.Gear^, CurrentHedgehog^ do
+    begin
+    a:= CurAmmoType;
+    State:= State and (not gstAttacking);
+    if (Ammoz[a].Ammo.Propz and ammoprop_Effect) = 0 then
+        begin
+        Inc(MultiShootAttacks);
+        
+        if (Ammoz[a].Ammo.NumPerTurn >= MultiShootAttacks) then
+            begin
+            s:= inttostr(Ammoz[a].Ammo.NumPerTurn - MultiShootAttacks + 1);
+            AddCaption(format(trmsg[sidRemaining], s), cWhiteColor, capgrpAmmostate);
+            end;
+        
+        if (Ammoz[a].Ammo.NumPerTurn >= MultiShootAttacks)
+        or ((GameFlags and gfMultiWeapon) <> 0) then
+            begin
+            isInMultiShoot:= true
+            end
+        else
+            begin
+            OnUsedAmmo(CurrentHedgehog^);
+            if ((Ammoz[a].Ammo.Propz and ammoprop_NoRoundEnd) = 0) and (((GameFlags and gfInfAttack) = 0) or PlacingHogs) then
+                begin
+                if TagTurnTimeLeft = 0 then
+                    TagTurnTimeLeft:= TurnTimeLeft;
+                TurnTimeLeft:=(Ammoz[a].TimeAfterTurn * cGetAwayTime) div 100;
+                end;
+            if ((Ammoz[a].Ammo.Propz and ammoprop_NoRoundEnd) = 0) then
+                State:= State or gstAttacked;
+            if (Ammoz[a].Ammo.Propz and ammoprop_NoRoundEnd) <> 0 then
+                ApplyAmmoChanges(CurrentHedgehog^)
+            end;
+        end
+    else
+        begin
+        OnUsedAmmo(CurrentHedgehog^);
+        ApplyAmmoChanges(CurrentHedgehog^);
+        end;
+    AttackBar:= 0
+    end
+end;
+
+////////////////////////////////////////////////////////////////////////////////
+procedure doStepHedgehogDead(Gear: PGear);
+const frametime = 200;
+      timertime = frametime * 6;
+begin
+if Gear^.Hedgehog^.Unplaced then
+    exit;
+if Gear^.Timer > 1 then
+    begin
+    AllInactive:= false;
+    dec(Gear^.Timer);
+    if (Gear^.Timer mod frametime) = 0 then
+        inc(Gear^.Pos)
+    end 
+else if Gear^.Timer = 1 then
+    begin
+    Gear^.State:= Gear^.State or gstNoDamage;
+    doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 30, CurrentHedgehog, EXPLAutoSound);
+    AddGear(hwRound(Gear^.X), hwRound(Gear^.Y), gtGrave, 0, _0, _0, 0)^.Hedgehog:= Gear^.Hedgehog;
+    DeleteGear(Gear);
+    SetAllToActive
+    end 
+else // Gear^.Timer = 0
+    begin
+    AllInactive:= false;
+    Gear^.Z:= cCurrHHZ;
+    RemoveGearFromList(Gear);
+    InsertGearToList(Gear);
+    PlaySound(sndByeBye, Gear^.Hedgehog^.Team^.voicepack);
+    Gear^.Pos:= 0;
+    Gear^.Timer:= timertime
+    end
+end;
+
+////////////////////////////////////////////////////////////////////////////////
+procedure doStepHedgehogGone(Gear: PGear);
+const frametime = 65;
+      timertime = frametime * 11;
+begin
+if Gear^.Hedgehog^.Unplaced then
+    exit;
+if Gear^.Timer > 1 then
+    begin
+    AllInactive:= false;
+    dec(Gear^.Timer);
+    if (Gear^.Timer mod frametime) = 0 then
+        inc(Gear^.Pos)
+    end
+else
+if Gear^.Timer = 1 then
+    begin
+    DeleteGear(Gear);
+    SetAllToActive
+    end
+else // Gear^.Timer = 0
+    begin
+    AllInactive:= false;
+    Gear^.Z:= cCurrHHZ;
+    RemoveGearFromList(Gear);
+    InsertGearToList(Gear);
+    PlaySound(sndByeBye, Gear^.Hedgehog^.Team^.voicepack);
+    PlaySound(sndWarp);
+    Gear^.Pos:= 0;
+    Gear^.Timer:= timertime
+    end
+end;
+
+////////////////////////////////////////////////////////////////////////////////
+procedure PickUp(HH, Gear: PGear);
+var s: shortstring;
+    a: TAmmoType;
+    i: LongInt;
+    vga: PVisualGear;
+begin
+Gear^.Message:= gmDestroy;
+PlaySound(sndShotgunReload);
+if (Gear^.Pos and posCaseExplode) <> 0 then
+    if (Gear^.Pos and posCasePoison) <> 0 then
+        doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 25, HH^.Hedgehog, EXPLAutoSound + EXPLPoisoned)
+    else
+        doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 25, HH^.Hedgehog, EXPLAutoSound)
+else if (Gear^.Pos and posCasePoison) <> 0 then
+    doMakeExplosion(hwRound(Gear^.X), hwRound(Gear^.Y), 25, HH^.Hedgehog, EXPLAutoSound + EXPLPoisoned + EXPLNoDamage)
+else
+case Gear^.Pos of
+       posCaseUtility,
+       posCaseAmmo: begin
+                    if Gear^.AmmoType <> amNothing then a:= Gear^.AmmoType 
+                    else
+                        begin
+                        for i:= 0 to GameTicks and $7F do
+                            GetRandom(2); // Burn some random numbers
+                        if Gear^.Pos = posCaseUtility then
+                            a:= GetUtility(HH^.Hedgehog)
+                        else
+                            a:= GetAmmo(HH^.Hedgehog)
+                        end;
+                    AddAmmo(HH^.Hedgehog^, a);
+// Possibly needs to check shared clan ammo game flag once added.
+// On the other hand, no obvious reason that clan members shouldn't know what ammo another clan member picked up
+                    if (not (HH^.Hedgehog^.Team^.ExtDriven 
+                    or (HH^.Hedgehog^.BotLevel > 0)))
+                    or (HH^.Hedgehog^.Team^.Clan^.ClanIndex = LocalClan)
+                    or (GameType = gmtDemo)  then
+                        begin
+                        s:= trammo[Ammoz[a].NameId] + ' (+' + IntToStr(Ammoz[a].NumberInCase) + ')';
+                        AddCaption(s, HH^.Hedgehog^.Team^.Clan^.Color, capgrpAmmoinfo);
+
+                        // show ammo icon
+                        vga:= AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtAmmo);
+                        if vga <> nil then
+                            vga^.Frame:= Longword(a);
+                        end;
+
+                    end;
+     posCaseHealth: begin
+                    inc(HH^.Health, Gear^.Health);
+                    HH^.Hedgehog^.Effects[hePoisoned] := false;
+                    str(Gear^.Health, s);
+                    s:= '+' + s;
+                    AddCaption(s, HH^.Hedgehog^.Team^.Clan^.Color, capgrpAmmoinfo);
+                    RenderHealth(HH^.Hedgehog^);
+                    RecountTeamHealth(HH^.Hedgehog^.Team);
+
+                    i:= 0;
+                    while i < Gear^.Health do
+                        begin
+                        vga:= AddVisualGear(hwRound(HH^.X), hwRound(HH^.Y), vgtStraightShot);
+                        if vga <> nil then
+                            with vga^ do
+                                begin
+                                Tint:= $00FF00FF;
+                                State:= ord(sprHealth)
+                                end;
+                        inc(i, 5);
+                        end;
+                    end;
+     end
+end;
+
+const StepTicks: LongWord = 0;
+
+procedure HedgehogStep(Gear: PGear);
+var PrevdX: LongInt;
+    CurWeapon: PAmmo;
+begin
+CurWeapon:= GetAmmoEntry(Gear^.Hedgehog^);
+if ((Gear^.State and (gstAttacking or gstMoving)) = 0) then
+    begin
+    if isCursorVisible then
+        with Gear^.Hedgehog^ do
+            with CurWeapon^ do
+                begin
+                if (Gear^.Message and gmLeft  ) <> 0 then
+                    Pos:= (Pos - 1 + Ammoz[AmmoType].PosCount) mod Ammoz[AmmoType].PosCount
+                else
+                    if (Gear^.Message and gmRight ) <> 0 then
+                        Pos:= (Pos + 1) mod Ammoz[AmmoType].PosCount
+    else
+        exit;
+    StepTicks:= 200;
+    exit
+    end;
+
+    if ((Gear^.Message and gmAnimate) <> 0) then
+        begin
+        Gear^.Message:= 0;
+        Gear^.State:= Gear^.State or gstAnimation;
+        Gear^.Tag:= Gear^.MsgParam;
+        Gear^.Timer:= 0;
+        Gear^.Pos:= 0
+        end;
+
+    if ((Gear^.Message and gmLJump ) <> 0) then
+        begin
+        Gear^.Message:= Gear^.Message and (not gmLJump);
+        DeleteCI(Gear);
+        if TestCollisionYwithGear(Gear, -1) = 0 then
+            if not TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX)) then
+                Gear^.Y:= Gear^.Y - _2
+            else
+                if not TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX)) then
+                    Gear^.Y:= Gear^.Y - _1;
+            if not (TestCollisionXwithGear(Gear, hwSign(Gear^.dX))
+            or   (TestCollisionYwithGear(Gear, -1) <> 0)) then
+                begin
+                Gear^.dY:= -_0_15;
+                if not cArtillery then
+                    Gear^.dX:= SignAs(_0_15, Gear^.dX);
+                Gear^.State:= Gear^.State or gstMoving or gstHHJumping;
+                PlaySound(sndJump1, Gear^.Hedgehog^.Team^.voicepack);
+        exit
+        end;
+    end;
+
+    if ((Gear^.Message and gmHJump ) <> 0) then
+        begin
+        DeleteCI(Gear);
+        Gear^.Message:= Gear^.Message and (not gmHJump);
+
+        Gear^.dY:= -_0_2;
+        SetLittle(Gear^.dX);
+        Gear^.State:= Gear^.State or gstMoving or gstHHJumping;
+        PlaySound(sndJump3, Gear^.Hedgehog^.Team^.voicepack);
+        exit
+        end;
+
+    PrevdX:= hwSign(Gear^.dX);
+    if (Gear^.Message and gmLeft  )<>0 then
+        Gear^.dX:= -cLittle else
+    if (Gear^.Message and gmRight )<>0 then
+        Gear^.dX:=  cLittle else exit;
+
+    if (Gear^.Message and (gmLeft or gmRight)) <> 0 then
+        begin
+        StepSoundTimer:= cHHStepTicks;
+        end;
+   
+    StepTicks:= cHHStepTicks;
+    if PrevdX <> hwSign(Gear^.dX) then
+        begin
+        FollowGear:= Gear;
+        exit
+        end;
+    DeleteCI(Gear); // must be after exit!! (see previous line)
+
+    Gear^.Hedgehog^.visStepPos:= (Gear^.Hedgehog^.visStepPos + 1) and 7;
+    if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then
+        begin
+        if not (TestCollisionXwithXYShift(Gear, _0, -6, hwSign(Gear^.dX))
+        or (TestCollisionYwithGear(Gear, -1) <> 0)) then
+            Gear^.Y:= Gear^.Y - _1;
+        if not (TestCollisionXwithXYShift(Gear, _0, -5, hwSign(Gear^.dX))
+        or (TestCollisionYwithGear(Gear, -1) <> 0)) then
+            Gear^.Y:= Gear^.Y - _1;
+        if not (TestCollisionXwithXYShift(Gear, _0, -4, hwSign(Gear^.dX))
+        or (TestCollisionYwithGear(Gear, -1) <> 0)) then
+            Gear^.Y:= Gear^.Y - _1;
+        if not (TestCollisionXwithXYShift(Gear, _0, -3, hwSign(Gear^.dX))
+        or (TestCollisionYwithGear(Gear, -1) <> 0)) then
+            Gear^.Y:= Gear^.Y - _1;
+        if not (TestCollisionXwithXYShift(Gear, _0, -2, hwSign(Gear^.dX))
+        or (TestCollisionYwithGear(Gear, -1) <> 0)) then
+            Gear^.Y:= Gear^.Y - _1;
+        if not (TestCollisionXwithXYShift(Gear, _0, -1, hwSign(Gear^.dX))
+        or (TestCollisionYwithGear(Gear, -1) <> 0)) then
+            Gear^.Y:= Gear^.Y - _1;
+        end;
+
+    if (not cArtillery) and ((Gear^.Message and gmPrecise) = 0) and (not TestCollisionXwithGear(Gear, hwSign(Gear^.dX))) then
+        Gear^.X:= Gear^.X + SignAs(_1, Gear^.dX);
+
+   SetAllHHToActive;
+
+    if TestCollisionYwithGear(Gear, 1) = 0 then
+        begin
+        Gear^.Y:= Gear^.Y + _1;
+    if TestCollisionYwithGear(Gear, 1) = 0 then
+        begin
+        Gear^.Y:= Gear^.Y + _1;
+    if TestCollisionYwithGear(Gear, 1) = 0 then
+        begin
+        Gear^.Y:= Gear^.Y + _1;
+    if TestCollisionYwithGear(Gear, 1) = 0 then
+        begin
+        Gear^.Y:= Gear^.Y + _1;
+    if TestCollisionYwithGear(Gear, 1) = 0 then
+        begin
+        Gear^.Y:= Gear^.Y + _1;
+    if TestCollisionYwithGear(Gear, 1) = 0 then
+        begin
+        Gear^.Y:= Gear^.Y + _1;
+    if TestCollisionYwithGear(Gear, 1) = 0 then
+        begin
+        Gear^.Y:= Gear^.Y - _6;
+        Gear^.dY:= _0;
+        Gear^.State:= Gear^.State or gstMoving;
+        exit
+        end;
+        end
+        end
+        end
+        end
+        end
+        end;
+    AddGearCI(Gear)
+    end
+end;
+
+procedure HedgehogChAngle(HHGear: PGear);
+var da: LongWord;
+begin
+with HHGear^.Hedgehog^ do
+    if ((CurAmmoType = amRope) and ((HHGear^.State and (gstMoving or gstHHJumping)) = gstMoving))
+    or ((CurAmmoType = amPortalGun) and ((HHGear^.State and gstMoving) <> 0)) then
+        da:= 2
+    else da:= 1;
+
+if (((HHGear^.Message and gmPrecise) = 0) or ((GameTicks mod 5) = 1)) then
+    if ((HHGear^.Message and gmUp) <> 0) and (HHGear^.Angle >= CurMinAngle + da) then
+        dec(HHGear^.Angle, da)
+    else
+        if ((HHGear^.Message and gmDown) <> 0) and (HHGear^.Angle + da <= CurMaxAngle) then
+            inc(HHGear^.Angle, da)
+end;
+
+
+////////////////////////////////////////////////////////////////////////////////
+procedure doStepHedgehogMoving(Gear: PGear);
+var isFalling, isUnderwater: boolean;
+    land: Word;
+begin
+land:= 0;
+isUnderwater:= cWaterLine < hwRound(Gear^.Y) + Gear^.Radius;
+if Gear^.dX.QWordValue > 8160437862 then
+    Gear^.dX.QWordValue:= 8160437862;
+if Gear^.dY.QWordValue > 8160437862 then
+    Gear^.dY.QWordValue:= 8160437862;
+
+if Gear^.Hedgehog^.Unplaced then
+    begin
+    Gear^.dY:= _0;
+    Gear^.dX:= _0;
+    Gear^.State:= Gear^.State and (not gstMoving);
+    exit
+    end;
+isFalling:= (Gear^.dY.isNegative) or not TestCollisionYKick(Gear, 1);
+if isFalling then
+    begin
+    if (Gear^.dY.isNegative) and TestCollisionYKick(Gear, -1) then
+        Gear^.dY:= _0;
+    Gear^.State:= Gear^.State or gstMoving;
+    if (CurrentHedgehog^.Gear = Gear)
+        and (hwSqr(Gear^.dX) + hwSqr(Gear^.dY) > _0_003) then 
+        begin
+        FollowGear:= Gear;
+        end;
+    if isUnderwater then
+       Gear^.dY:= Gear^.dY + cGravity / _2
+    else
+        begin
+        Gear^.dY:= Gear^.dY + cGravity;
+// this set of circumstances could be less complex if jumping was more clearly identified
+        if ((GameFlags and gfMoreWind) <> 0) and (((Gear^.Damage <> 0)
+        or ((CurAmmoGear <> nil) and ((CurAmmoGear^.AmmoType = amJetpack) or (CurAmmoGear^.AmmoType = amBirdy)))
+        or ((Gear^.dY.QWordValue + Gear^.dX.QWordValue) > _0_55.QWordValue))) then
+            Gear^.dX := Gear^.dX + cWindSpeed / Gear^.Density
+        end
+    end 
+else
+    begin
+    land:= TestCollisionYwithGear(Gear, 1);
+    if ((Gear^.dX.QWordValue + Gear^.dY.QWordValue) < _0_55.QWordValue) and ((land and lfIce) = 0)
+    and ((Gear^.State and gstHHJumping) <> 0) then
+        SetLittle(Gear^.dX);
+
+    if not Gear^.dY.isNegative then
+        begin
+        CheckHHDamage(Gear);
+
+        if ((Gear^.State and gstHHHJump) <> 0) and (not cArtillery)
+        and (Gear^.dX.QWordValue < _0_02.QWordValue) then
+            Gear^.dX.isNegative:= not Gear^.dX.isNegative; // landing after high jump
+        Gear^.State:= Gear^.State and (not (gstHHJumping or gstHHHJump));
+        Gear^.dY:= _0;
+        end
+    else
+        Gear^.dY:= Gear^.dY + cGravity;
+
+    if ((Gear^.State and gstMoving) <> 0) then
+        begin
+        if land and lfIce <> 0 then
+            begin
+            Gear^.dX:= Gear^.dX * (_1 - (_1 - Gear^.Friction) / _2)
+            end
+        else
+            Gear^.dX:= Gear^.dX * Gear^.Friction;
+        end
+    end;
+
+if (Gear^.State <> 0) then
+    DeleteCI(Gear);
+
+if isUnderwater then
+   begin
+   Gear^.dY:= Gear^.dY * _0_999;
+   Gear^.dX:= Gear^.dX * _0_999;
+   end;
+
+if (Gear^.State and gstMoving) <> 0 then
+    if TestCollisionXKick(Gear, hwSign(Gear^.dX)) then
+        if not isFalling then
+            if hwAbs(Gear^.dX) > _0_01 then
+                if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX)) - Gear^.dX, -1, hwSign(Gear^.dX)) then
+                    begin
+                    Gear^.X:= Gear^.X + Gear^.dX;
+                    Gear^.dX:= Gear^.dX * _0_96;
+                    Gear^.Y:= Gear^.Y - _1
+                    end
+                else
+                    if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX)) - Gear^.dX, -2, hwSign(Gear^.dX)) then
+                        begin
+                        Gear^.X:= Gear^.X + Gear^.dX;
+                        Gear^.dX:= Gear^.dX * _0_93;
+                        Gear^.Y:= Gear^.Y - _2
+                        end 
+                    else
+                        if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX)) - Gear^.dX, -3, hwSign(Gear^.dX)) then
+                        begin
+                        Gear^.X:= Gear^.X + Gear^.dX;
+                        Gear^.dX:= Gear^.dX * _0_9 ;
+                        Gear^.Y:= Gear^.Y - _3
+                        end
+                    else
+                        if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX)) - Gear^.dX, -4, hwSign(Gear^.dX)) then
+                            begin
+                            Gear^.X:= Gear^.X + Gear^.dX;
+                            Gear^.dX:= Gear^.dX * _0_87;
+                            Gear^.Y:= Gear^.Y - _4
+                            end
+                    else
+                        if not TestCollisionXwithXYShift(Gear, int2hwFloat(hwSign(Gear^.dX)) - Gear^.dX, -5, hwSign(Gear^.dX)) then
+                            begin
+                            Gear^.X:= Gear^.X + Gear^.dX;
+                            Gear^.dX:= Gear^.dX * _0_84;
+                            Gear^.Y:= Gear^.Y - _5
+                            end
+                    else
+                        if hwAbs(Gear^.dX) > _0_02 then
+                            Gear^.dX:= -Gear^.Elasticity * Gear^.dX
+                        else
+                            begin
+                            Gear^.State:= Gear^.State and (not gstMoving);
+                            while TestCollisionYWithGear(Gear,1) = 0 do
+                                Gear^.Y:= Gear^.Y+_1;
+                            SetLittle(Gear^.dX)
+                            end
+            else
+                begin
+                Gear^.State:= Gear^.State and (not gstMoving);
+                while TestCollisionYWithGear(Gear,1) = 0 do
+                    Gear^.Y:= Gear^.Y+_1;
+                SetLittle(Gear^.dX)
+                end
+        else if (hwAbs(Gear^.dX) > cLittle)
+        and ((Gear^.State and gstHHJumping) = 0) then
+            Gear^.dX:= -Gear^.Elasticity * Gear^.dX
+        else
+            SetLittle(Gear^.dX);
+
+if (not isFalling)
+and (hwAbs(Gear^.dX) + hwAbs(Gear^.dY) < _0_03) then
+    begin
+    Gear^.State:= Gear^.State and (not gstWinner);
+    Gear^.State:= Gear^.State and (not gstMoving);
+    while TestCollisionYWithGear(Gear,1) = 0 do
+        Gear^.Y:= Gear^.Y+_1;
+    SetLittle(Gear^.dX);
+    Gear^.dY:= _0
+    end
+else
+    Gear^.State:= Gear^.State or gstMoving;
+
+if (Gear^.State and gstMoving) <> 0 then
+    begin
+    Gear^.State:= Gear^.State and (not gstAnimation);
+// ARTILLERY but not being moved by explosions
+    Gear^.X:= Gear^.X + Gear^.dX;
+    Gear^.Y:= Gear^.Y + Gear^.dY;
+    if (not Gear^.dY.isNegative) and (not TestCollisionYKick(Gear, 1)) 
+    and TestCollisionYwithXYShift(Gear, 0, 1, 1) then
+        begin
+        CheckHHDamage(Gear);
+        Gear^.dY:= _0;
+        Gear^.Y:= Gear^.Y + _1
+        end;
+    CheckGearDrowning(Gear);
+    // hide target cursor if current hog is drowning
+    if (Gear^.State and gstDrowning) <> 0 then
+        if (CurrentHedgehog^.Gear = Gear) then
+            isCursorVisible:= false
+    end;
+
+if (hwAbs(Gear^.dY) > _0) and (Gear^.FlightTime > 0) and ((GameFlags and gfLowGravity) = 0) then
+    begin
+    inc(Gear^.FlightTime);
+    if Gear^.FlightTime = 3000 then
+        begin
+        AddCaption(GetEventString(eidHomerun), cWhiteColor, capgrpMessage);
+        PlaySound(sndHomerun)
+        end;
+    end
+else
+    begin
+    uStats.hedgehogFlight(Gear, Gear^.FlightTime);
+    Gear^.FlightTime:= 0;
+    end;
+
+end;
+
+procedure doStepHedgehogDriven(HHGear: PGear);
+var t: PGear;
+    wasJumping: boolean;
+    Hedgehog: PHedgehog;
+begin
+Hedgehog:= HHGear^.Hedgehog;
+if isInMultiShoot then
+    HHGear^.Message:= 0;
+
+if ((Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_Utility) <> 0) and isInMultiShoot then 
+    AllInactive:= true
+else if not isInMultiShoot then
+    AllInactive:= false;
+
+if (TurnTimeLeft = 0) or (HHGear^.Damage > 0) then
+    begin
+    if TagTurnTimeLeft = 0 then
+        TagTurnTimeLeft:= TurnTimeLeft;
+    TurnTimeLeft:= 0;
+    isCursorVisible:= false;
+    HHGear^.State:= HHGear^.State and (not (gstHHDriven or gstAnimation or gstAttacking));
+    AttackBar:= 0;
+    if HHGear^.Damage > 0 then
+        HHGear^.State:= HHGear^.State and (not (gstHHJumping or gstHHHJump));
+    exit
+    end;
+
+if (HHGear^.State and gstAnimation) <> 0 then
+    begin
+    HHGear^.Message:= 0;
+    if (HHGear^.Pos = Wavez[TWave(HHGear^.Tag)].VoiceDelay) and (HHGear^.Timer = 0) then
+        PlaySound(Wavez[TWave(HHGear^.Tag)].Voice, Hedgehog^.Team^.voicepack);
+    inc(HHGear^.Timer);
+    if HHGear^.Timer = Wavez[TWave(HHGear^.Tag)].Interval then
+        begin
+        HHGear^.Timer:= 0;
+        inc(HHGear^.Pos);
+        if HHGear^.Pos = Wavez[TWave(HHGear^.Tag)].FramesCount then
+            HHGear^.State:= HHGear^.State and (not gstAnimation)
+        end;
+    exit
+    end;
+
+if ((HHGear^.State and gstMoving) <> 0)
+or (StepTicks = cHHStepTicks)
+or (CurAmmoGear <> nil) then // we are moving
+    begin
+    with Hedgehog^ do
+        if (CurAmmoGear = nil)
+        and (HHGear^.dY > _0_39)
+        and (CurAmmoType = amParachute) then
+            HHGear^.Message:= HHGear^.Message or gmAttack;
+    // check for case with ammo
+    t:= CheckGearNear(HHGear, gtCase, 36, 36);
+    if t <> nil then
+        PickUp(HHGear, t)
+    end;
+
+if (CurAmmoGear = nil) then
+    if (((HHGear^.Message and gmAttack) <> 0)
+    or ((HHGear^.State and gstAttacking) <> 0)) then
+        Attack(HHGear) // should be before others to avoid desync with '/put' msg and changing weapon msgs
+    else
+else 
+    with Hedgehog^ do
+        if ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) <> 0)
+        and ((HHGear^.Message and gmLJump) <> 0)
+        and ((Ammoz[CurAmmoType].Ammo.Propz and ammoprop_AltUse) <> 0) then
+            begin
+            Attack(HHGear);
+            HHGear^.Message:= HHGear^.Message and (not gmLJump)
+            end;
+
+if (CurAmmoGear = nil)
+or ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) <> 0) 
+or ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_NoRoundEnd) <> 0) then
+    begin
+    if ((HHGear^.Message and gmSlot) <> 0) then
+        if ChangeAmmo(HHGear) then ApplyAmmoChanges(Hedgehog^);
+
+    if ((HHGear^.Message and gmWeapon) <> 0) then
+        HHSetWeapon(HHGear);
+
+    if ((HHGear^.Message and gmTimer) <> 0) then
+        HHSetTimer(HHGear);
+    end;
+
+if CurAmmoGear <> nil then
+    begin
+    CurAmmoGear^.Message:= HHGear^.Message;
+    exit
+    end;
+
+if not isInMultiShoot then
+    HedgehogChAngle(HHGear);
+
+if (HHGear^.State and gstMoving) <> 0 then
+    begin
+    wasJumping:= ((HHGear^.State and gstHHJumping) <> 0);
+
+    if ((HHGear^.Message and gmHJump) <> 0) and wasJumping and ((HHGear^.State and gstHHHJump) = 0) then
+        if (not (hwAbs(HHGear^.dX) > cLittle)) and (HHGear^.dY < -_0_02) then
+            begin
+            HHGear^.State:= HHGear^.State or gstHHHJump;
+            HHGear^.dY:= -_0_25;
+            if not cArtillery then
+                HHGear^.dX:= -SignAs(_0_02, HHGear^.dX);
+            PlaySound(sndJump2, Hedgehog^.Team^.voicepack)
+            end;
+
+    HHGear^.Message:= HHGear^.Message and (not (gmLJump or gmHJump));
+
+    if (not cArtillery) and wasJumping and TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then
+        SetLittle(HHGear^.dX);
+
+    if Hedgehog^.Gear <> nil then
+        doStepHedgehogMoving(HHGear);
+
+    if ((HHGear^.State and (gstMoving or gstDrowning)) = 0) then
+        begin
+        AddGearCI(HHGear);
+        if wasJumping then
+            StepTicks:= 410
+        else
+            StepTicks:= 95
+        end;
+    exit
+    end;
+
+    if not isInMultiShoot and (Hedgehog^.Gear <> nil) then
+        begin
+        if StepTicks > 0 then
+            dec(StepTicks);
+        if (StepTicks = 0) then
+            HedgehogStep(HHGear)
+        end
+end;
+
+////////////////////////////////////////////////////////////////////////////////
+procedure doStepHedgehogFree(Gear: PGear);
+var prevState: Longword;
+begin
+prevState:= Gear^.State;
+
+doStepHedgehogMoving(Gear);
+
+if (Gear^.State and (gstMoving or gstDrowning)) <> 0 then
+    begin
+    if Gear^.Damage > 0 then
+        CalcRotationDirAngle(Gear);
+    AllInactive:= false;
+    exit
+    end;
+
+if (Gear^.Health = 0) then
+    begin
+    if PrvInactive or ((GameFlags and gfInfAttack) <> 0) then
+        begin
+        Gear^.Timer:= 0;
+        FollowGear:= Gear;
+        PrvInactive:= false;
+        AllInactive:= false;
+
+        if (Gear^.State and gstHHGone) = 0 then
+            begin
+            Gear^.Hedgehog^.Effects[hePoisoned] := false;
+            if Gear^.Hedgehog^.Effects[heResurrectable] then
+                begin
+                ResurrectHedgehog(Gear);
+                end
+            else 
+                begin
+                Gear^.State:= (Gear^.State or gstHHDeath) and (not gstAnimation);
+                Gear^.doStep:= @doStepHedgehogDead;
+                // Death message
+                AddCaption(Format(GetEventString(eidDied), Gear^.Hedgehog^.Name), cWhiteColor, capgrpMessage);
+                end;
+            end
+        else
+            begin
+            Gear^.State:= Gear^.State and (not gstAnimation);
+            Gear^.doStep:= @doStepHedgehogGone;
+
+            // Gone message
+            AddCaption(Format(GetEventString(eidGone), Gear^.Hedgehog^.Name), cWhiteColor, capgrpMessage);
+            end
+        end;
+    exit
+    end;
+
+if ((Gear^.State and gstWait) = 0) and
+    (prevState <> Gear^.State) then
+    begin
+    Gear^.State:= Gear^.State or gstWait;
+    Gear^.Timer:= 150
+    end
+else
+    begin
+    if Gear^.Timer = 0 then
+        begin
+        Gear^.State:= Gear^.State and (not (gstWait or gstLoser or gstWinner or gstAttacked or gstNotKickable or gstHHChooseTarget));
+        Gear^.Active:= false;
+        AddGearCI(Gear);
+        exit
+        end
+    else dec(Gear^.Timer)
+    end;
+
+AllInactive:= false
+end;
+
+////////////////////////////////////////////////////////////////////////////////
+procedure doStepHedgehog(Gear: PGear);
+(*
+var x,y,tx,ty: LongInt;
+    tdX, tdY, slope: hwFloat; 
+    land: Word; *)
+var slope: hwFloat; 
+begin
+if (Gear^.Message and gmDestroy) <> 0 then
+    begin
+    DeleteGear(Gear);
+    exit
+    end;
+
+if (Gear^.State and gstHHDriven) = 0 then
+    doStepHedgehogFree(Gear)
+else
+    begin
+    with Gear^.Hedgehog^ do
+        if Team^.hasGone then
+            TeamGoneEffect(Team^)
+        else
+            doStepHedgehogDriven(Gear)
+    end;
+if (Gear^.Message and (gmAllStoppable or gmLJump or gmHJump) = 0)
+and (Gear^.State and (gstHHJumping or gstHHHJump or gstAttacking) = 0)
+and (not Gear^.dY.isNegative) and (GameTicks mod (100*LongWOrd(hwRound(cMaxWindSpeed*2/cGravity))) = 0)
+and (TestCollisionYwithGear(Gear, 1) and lfIce <> 0) then
+    begin
+    slope:= CalcSlopeBelowGear(Gear);
+    Gear^.dX:=Gear^.dX+slope*_0_07;
+    if slope.QWordValue <> 0 then
+        Gear^.State:= Gear^.State or gstMoving;
+(*
+    x:= hwRound(Gear^.X);
+    y:= hwRound(Gear^.Y);
+    AddVisualGear(x, y, vgtSmokeTrace);
+    AddVisualGear(x - hwRound(_5*slope), y + hwRound(_5*slope), vgtSmokeTrace);
+    AddVisualGear(x + hwRound(_5*slope), y - hwRound(_5*slope), vgtSmokeTrace);
+    AddVisualGear(x - hwRound(_20 * slope), y + hwRound(_20 * slope), vgtSmokeTrace);
+    AddVisualGear(x + hwRound(_20 * slope), y - hwRound(_20 * slope), vgtSmokeTrace);
+    AddVisualGear(x - hwRound(_30 * slope), y + hwRound(_30 * slope), vgtSmokeTrace);
+    AddVisualGear(x + hwRound(_30 * slope), y - hwRound(_30 * slope), vgtSmokeTrace);
+    AddVisualGear(x - hwRound(_40 * slope), y + hwRound(_40 * slope), vgtSmokeTrace);
+    AddVisualGear(x + hwRound(_40 * slope), y - hwRound(_40 * slope), vgtSmokeTrace);
+    AddVisualGear(x - hwRound(_50 * slope), y + hwRound(_50 * slope), vgtSmokeTrace);
+    AddVisualGear(x + hwRound(_50 * slope), y - hwRound(_50 * slope), vgtSmokeTrace); *)
+    end
+end;
+
+end.
--- a/hedgewars/uGearsList.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uGearsList.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -1,545 +1,565 @@
-(*
- * Hedgewars, a free turn based strategy game
- * Copyright (c) 2004-2011 Andrey Korotaev <unC0Rr@gmail.com>
- *
- * 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
- * the Free Software Foundation; version 2 of the License
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- *)
-
-{$INCLUDE "options.inc"}
-unit uGearsList;
-
-interface
-uses uFloat, uTypes;
-
-function  AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear;
-procedure DeleteGear(Gear: PGear);
-procedure InsertGearToList(Gear: PGear);
-procedure RemoveGearFromList(Gear: PGear);
-
-implementation
-
-uses uRandom, uUtils, uConsts, uVariables, uAmmos, uTeams, uStats,
-    uTextures, uScript, uRenderUtils, uAI, uCollisions,
-    uGearsRender, uGearsUtils;
-
-procedure InsertGearToList(Gear: PGear);
-var tmp, ptmp: PGear;
-begin
-    tmp:= GearsList;
-    ptmp:= GearsList;
-    while (tmp <> nil) and (tmp^.Z <= Gear^.Z) do
-        begin
-        ptmp:= tmp;
-        tmp:= tmp^.NextGear
-        end;
-
-    if ptmp <> tmp then
-        begin
-        Gear^.NextGear:= ptmp^.NextGear;
-        Gear^.PrevGear:= ptmp;
-        if ptmp^.NextGear <> nil then ptmp^.NextGear^.PrevGear:= Gear;
-        ptmp^.NextGear:= Gear
-        end
-    else
-        begin
-        Gear^.NextGear:= GearsList;
-        if Gear^.NextGear <> nil then Gear^.NextGear^.PrevGear:= Gear;
-        GearsList:= Gear;
-        end;
-end;
-
-procedure RemoveGearFromList(Gear: PGear);
-begin
-if Gear^.NextGear <> nil then Gear^.NextGear^.PrevGear:= Gear^.PrevGear;
-if Gear^.PrevGear <> nil then
-    Gear^.PrevGear^.NextGear:= Gear^.NextGear
-else
-    GearsList:= Gear^.NextGear
-end;
-    
-function AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear;
-const Counter: Longword = 0;
-var gear: PGear;
-begin
-inc(Counter);
-AddFileLog('AddGear: #' + inttostr(Counter) + ' (' + inttostr(x) + ',' + inttostr(y) + '), d(' + floattostr(dX) + ',' + floattostr(dY) + ') type = ' + EnumToStr(Kind));
-
-New(gear);
-FillChar(gear^, sizeof(TGear), 0);
-gear^.X:= int2hwFloat(X);
-gear^.Y:= int2hwFloat(Y);
-gear^.Target.X:= NoPointX;
-gear^.Kind := Kind;
-gear^.State:= State;
-gear^.Active:= true;
-gear^.dX:= dX;
-gear^.dY:= dY;
-gear^.doStep:= doStepHandlers[Kind];
-gear^.CollisionIndex:= -1;
-gear^.Timer:= Timer;
-gear^.FlightTime:= 0;
-gear^.uid:= Counter;
-gear^.SoundChannel:= -1;
-gear^.ImpactSound:= sndNone;
-gear^.nImpactSounds:= 0;
-gear^.Density:= _1;
-// Define ammo association, if any.
-gear^.AmmoType:= GearKindAmmoTypeMap[Kind];
-if Ammoz[Gear^.AmmoType].Ammo.Propz and ammoprop_NeedTarget <> 0 then gear^.Z:= cHHZ+1
-else gear^.Z:= cUsualZ;
-
-if CurrentHedgehog <> nil then
-    begin
-    gear^.Hedgehog:= CurrentHedgehog;
-    gear^.IntersectGear:= CurrentHedgehog^.Gear
-    end;
-    
-case Kind of
-     gtGrenade,
-     gtClusterBomb,
-     gtGasBomb: begin
-                gear^.ImpactSound:= sndGrenadeImpact;
-                gear^.nImpactSounds:= 1;
-                gear^.AdvBounce:= 1;
-                gear^.Radius:= 5;
-                gear^.Elasticity:= _0_8;
-                gear^.Friction:= _0_8;
-                gear^.Density:= _1_5;
-                gear^.RenderTimer:= true;
-                if gear^.Timer = 0 then gear^.Timer:= 3000
-                end;
-  gtWatermelon: begin
-                gear^.ImpactSound:= sndMelonImpact;
-                gear^.nImpactSounds:= 1;
-                gear^.AdvBounce:= 1;
-                gear^.Radius:= 6;
-                gear^.Elasticity:= _0_8;
-                gear^.Friction:= _0_995;
-                gear^.Density:= _2;
-                gear^.RenderTimer:= true;
-                if gear^.Timer = 0 then gear^.Timer:= 3000
-                end;
-  gtMelonPiece: begin
-                gear^.Density:= _2;
-                end;
-    gtHedgehog: begin
-                gear^.AdvBounce:= 1;
-                gear^.Radius:= cHHRadius;
-                gear^.Elasticity:= _0_35;
-                gear^.Friction:= _0_999;
-                gear^.Angle:= cMaxAngle div 2;
-                gear^.Density:= _3;
-                gear^.Z:= cHHZ;
-                if (GameFlags and gfAISurvival) <> 0 then
-                    if gear^.Hedgehog^.BotLevel > 0 then
-                        gear^.Hedgehog^.Effects[heResurrectable] := true;
-                end;
-       gtShell: begin
-                gear^.Radius:= 4;
-                gear^.Density:= _1;
-                end;
-       gtSnowball: begin
-                gear^.ImpactSound:= sndMudballImpact;
-                gear^.nImpactSounds:= 1;
-                gear^.Radius:= 4;
-                gear^.Elasticity:= _1;
-                gear^.Friction:= _1;
-                gear^.Density:= _0_5;
-                end;
-
-     gtFlake: begin
-                with Gear^ do
-                    begin
-                    Pos:= 0;
-                    Radius:= 1;
-                    DirAngle:= random * 360;
-                    if State and gstTmpFlag = 0 then
-                        begin
-                        dx.isNegative:= GetRandom(2) = 0;
-                        dx.QWordValue:= GetRandom(100000000);
-                        dy.isNegative:= false;
-                        dy.QWordValue:= GetRandom(70000000);
-                        if GetRandom(2) = 0 then dx := -dx
-                        end;
-                    State:= State or gstInvisible;
-                    Health:= random(vobFrameTicks);
-                    Timer:= random(vobFramesCount);
-                    Angle:= (random(2) * 2 - 1) * (1 + random(10000)) * vobVelocity
-                    end
-                end;
-       gtGrave: begin
-                gear^.ImpactSound:= sndGraveImpact;
-                gear^.nImpactSounds:= 1;
-                gear^.Radius:= 10;
-                gear^.Elasticity:= _0_6;
-                end;
-         gtBee: begin
-                gear^.Radius:= 5;
-                gear^.Timer:= 500;
-                gear^.RenderTimer:= true;
-                gear^.Elasticity:= _0_9;
-                gear^.Tag:= 0;
-                end;
-   gtSeduction: begin
-                gear^.Radius:= 250;
-                end;
- gtShotgunShot: begin
-                gear^.Timer:= 900;
-                gear^.Radius:= 2
-                end;
-  gtPickHammer: begin
-                gear^.Radius:= 10;
-                gear^.Timer:= 4000
-                end;
-   gtHammerHit: begin
-                gear^.Radius:= 8;
-                gear^.Timer:= 125
-                end;
-        gtRope: begin
-                gear^.Radius:= 3;
-                gear^.Friction:= _450 * _0_01 * cRopePercent;
-                RopePoints.Count:= 0;
-                end;
-        gtMine: begin
-                gear^.ImpactSound:= sndMineImpact;
-                gear^.nImpactSounds:= 1;
-                gear^.Health:= 10;
-                gear^.State:= gear^.State or gstMoving;
-                gear^.Radius:= 2;
-                gear^.Elasticity:= _0_55;
-                gear^.Friction:= _0_995;
-                gear^.Density:= _0_9;
-                if cMinesTime < 0 then
-                    gear^.Timer:= getrandom(51)*100
-                else
-                    gear^.Timer:= cMinesTime;
-                end;
-       gtSMine: begin
-                gear^.Health:= 10;
-                gear^.State:= gear^.State or gstMoving;
-                gear^.Radius:= 2;
-                gear^.Elasticity:= _0_55;
-                gear^.Friction:= _0_995;
-                gear^.Density:= _0_9;
-                gear^.Timer:= 500;
-                end;
-        gtCase: begin
-                gear^.ImpactSound:= sndGraveImpact;
-                gear^.nImpactSounds:= 1;
-                gear^.Radius:= 16;
-                gear^.Elasticity:= _0_3
-                end;
-  gtExplosives: begin
-                gear^.ImpactSound:= sndGrenadeImpact;
-                gear^.nImpactSounds:= 1;
-                gear^.Radius:= 16;
-                gear^.Elasticity:= _0_4;
-                gear^.Friction:= _0_995;
-                gear^.Density:= _6;
-                gear^.Health:= cBarrelHealth;
-                gear^.Z:= cHHZ-1
-                end;
-  gtDEagleShot: begin
-                gear^.Radius:= 1;
-                gear^.Health:= 50
-                end;
-  gtSniperRifleShot: begin
-                gear^.Radius:= 1;
-                gear^.Health:= 50
-                end;
-    gtDynamite: begin
-                gear^.Radius:= 3;
-                gear^.Elasticity:= _0_55;
-                gear^.Friction:= _0_03;
-                gear^.Density:= _2;
-                gear^.Timer:= 5000;
-                end;
-     gtCluster: begin
-                gear^.Radius:= 2;
-                gear^.Density:= _1_5;
-                gear^.RenderTimer:= true
-                end;
-      gtShover: gear^.Radius:= 20;
-       gtFlame: begin
-                gear^.Tag:= GetRandom(32);
-                gear^.Radius:= 1;
-                gear^.Health:= 5;
-                gear^.Density:= _1;
-                if (gear^.dY.QWordValue = 0) and (gear^.dX.QWordValue = 0) then
-                    begin
-                    gear^.dY:= (getrandom - _0_8) * _0_03;
-                    gear^.dX:= (getrandom - _0_5) * _0_4
-                    end
-                end;
-   gtFirePunch: begin
-                gear^.Radius:= 15;
-                gear^.Tag:= Y
-                end;
-     gtAirBomb: begin
-                gear^.Radius:= 5;
-                gear^.Density:= _2;
-                end;
-   gtBlowTorch: begin
-                gear^.Radius:= cHHRadius + cBlowTorchC;
-                gear^.Timer:= 7500
-                end;
-    gtSwitcher: begin
-                gear^.Z:= cCurrHHZ
-                end;
-      gtTarget: begin
-                gear^.ImpactSound:= sndGrenadeImpact;
-                gear^.nImpactSounds:= 1;
-                gear^.Radius:= 10;
-                gear^.Elasticity:= _0_3;
-                gear^.Timer:= 0
-                end;
-      gtTardis: begin
-                gear^.Timer:= 0;
-                gear^.Pos:= 1;
-                gear^.Z:= cCurrHHZ+1;
-                end;
-      gtMortar: begin
-                gear^.Radius:= 4;
-                gear^.Elasticity:= _0_2;
-                gear^.Friction:= _0_08;
-                gear^.Density:= _1;
-                end;
-        gtWhip: gear^.Radius:= 20;
-      gtHammer: gear^.Radius:= 20;
-    gtKamikaze: begin
-                gear^.Health:= 2048;
-                gear^.Radius:= 20
-                end;
-        gtCake: begin
-                gear^.Health:= 2048;
-                gear^.Radius:= 7;
-                gear^.Z:= cOnHHZ;
-                gear^.RenderTimer:= true;
-                gear^.DirAngle:= -90 * hwSign(Gear^.dX);
-                if not dX.isNegative then gear^.Angle:= 1 else gear^.Angle:= 3
-                end;
- gtHellishBomb: begin
-                gear^.ImpactSound:= sndHellishImpact1;
-                gear^.nImpactSounds:= 4;
-                gear^.AdvBounce:= 1;
-                gear^.Radius:= 4;
-                gear^.Elasticity:= _0_5;
-                gear^.Friction:= _0_96;
-                gear^.Density:= _1_5;
-                gear^.RenderTimer:= true;
-                gear^.Timer:= 5000
-                end;
-       gtDrill: begin
-                if gear^.Timer = 0 then gear^.Timer:= 5000;
-                // Tag for drill strike. if 1 then first impact occured already
-                gear^.Tag := 0;
-                gear^.Radius:= 4;
-                gear^.Density:= _1;
-                end;
-        gtBall: begin
-                gear^.ImpactSound:= sndGrenadeImpact;
-                gear^.nImpactSounds:= 1;
-                gear^.AdvBounce:= 1;
-                gear^.Radius:= 5;
-                gear^.Tag:= random(8);
-                gear^.Timer:= 5000;
-                gear^.Elasticity:= _0_7;
-                gear^.Friction:= _0_995;
-                gear^.Density:= _1_5;
-                end;
-     gtBallgun: begin
-                gear^.Timer:= 5001;
-                end;
-     gtRCPlane: begin
-                gear^.Timer:= 15000;
-                gear^.Health:= 3;
-                gear^.Radius:= 8
-                end;
-     gtJetpack: begin
-                gear^.Health:= 2000;
-                gear^.Damage:= 100
-                end;
-     gtMolotov: begin
-                gear^.Radius:= 6;
-                gear^.Density:= _2;
-                end;
-       gtBirdy: begin
-                gear^.Radius:= 16; // todo: check
-                gear^.Timer:= 0;
-                gear^.Health := 2000;
-                gear^.FlightTime := 2;
-                end;
-         gtEgg: begin
-                gear^.Radius:= 4;
-                gear^.Elasticity:= _0_6;
-                gear^.Friction:= _0_96;
-                gear^.Density:= _1;
-                if gear^.Timer = 0 then gear^.Timer:= 3000
-                end;
-      gtPortal: begin
-                gear^.ImpactSound:= sndMelonImpact;
-                gear^.nImpactSounds:= 1;
-                gear^.AdvBounce:= 0;
-                gear^.Radius:= 17;
-                // set color
-                gear^.Tag:= 2 * gear^.Timer;
-                gear^.Timer:= 15000;
-                gear^.RenderTimer:= false;
-                gear^.Health:= 100;
-                end;
-       gtPiano: begin
-                gear^.Radius:= 32;
-                gear^.Density:= _50;
-                end;
- gtSineGunShot: begin
-                gear^.Radius:= 5;
-                gear^.Health:= 6000;
-                end;
-gtFlamethrower: begin
-                gear^.Tag:= 10;
-                gear^.Timer:= 10;
-                gear^.Health:= 500;
-                gear^.Damage:= 100;
-                end;
-     gtLandGun: begin
-                gear^.Tag:= 10;
-                gear^.Timer:= 10;
-                gear^.Health:= 1000;
-                gear^.Damage:= 100;
-                end;
- gtPoisonCloud: begin
-                gear^.Timer:= 5000;
-                gear^.dY:= int2hwfloat(-4 + longint(getRandom(8))) / 1000;
-                end;
- gtResurrector: begin
-                gear^.Radius := 100;
-                gear^.Tag := 0
-                end;
-     gtWaterUp: begin
-                gear^.Tag := 47;
-                end;
-  gtNapalmBomb: begin
-                gear^.Timer:= 1000;
-                gear^.Radius:= 5;
-                gear^.Density:= _1_5;
-                end;
-   gtStructure: begin
-                gear^.Elasticity:= _0_55;
-                gear^.Friction:= _0_995;
-                gear^.Density:= _0_9;
-                gear^.Radius:= 13;
-                gear^.Health:= 200;
-                gear^.Timer:= 0;
-                gear^.Tag:= TotalRounds + 3;
-                gear^.Pos:= 1;
-                end;
-    end;
-
-InsertGearToList(gear);
-AddGear:= gear;
-
-ScriptCall('onGearAdd', gear^.uid);
-end;
-
-procedure DeleteGear(Gear: PGear);
-var team: PTeam;
-    t,i: Longword;
-    k: boolean;
-begin
-
-ScriptCall('onGearDelete', gear^.uid);
-
-DeleteCI(Gear);
-
-FreeTexture(Gear^.Tex);
-Gear^.Tex:= nil;
-
-// make sure that portals have their link removed before deletion
-if (Gear^.Kind = gtPortal) then
-    begin
-    if (Gear^.IntersectGear <> nil) then
-        if (Gear^.IntersectGear^.IntersectGear = Gear) then
-            Gear^.IntersectGear^.IntersectGear:= nil;
-    end
-else if Gear^.Kind = gtHedgehog then
-    (*
-    This behaviour dates back to revision 4, and I accidentally encountered it with TARDIS.  I don't think it must apply to any modern weapon, since if it was actually hit, the best the gear could do would be to destroy itself immediately, and you'd still end up with two graves.  I believe it should be removed
-     if (CurAmmoGear <> nil) and (CurrentHedgehog^.Gear = Gear) then
-        begin
-        AttackBar:= 0;
-        Gear^.Message:= gmDestroy;
-        CurAmmoGear^.Message:= gmDestroy;
-        exit
-        end
-    else*)
-        begin
-        if (hwRound(Gear^.Y) >= cWaterLine) then
-            begin
-            t:= max(Gear^.Damage, Gear^.Health);
-            Gear^.Damage:= t;
-            if ((not SuddenDeathDmg and (cWaterOpacity < $FF)) or (SuddenDeathDmg and (cWaterOpacity < $FF))) and (hwRound(Gear^.Y) < cWaterLine + 256) then
-                spawnHealthTagForHH(Gear, t);
-            end;
-
-        team:= Gear^.Hedgehog^.Team;
-        if CurrentHedgehog^.Gear = Gear then
-            begin
-            AttackBar:= 0;
-            FreeActionsList; // to avoid ThinkThread on drawned gear
-            if ((Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NoRoundEnd) <> 0) and (CurrentHedgehog^.MultiShootAttacks > 0) then OnUsedAmmo(CurrentHedgehog^);
-            end;
-
-        Gear^.Hedgehog^.Gear:= nil;
-        if Gear^.Hedgehog^.King then
-            begin
-            // are there any other kings left? Just doing nil check.  Presumably a mortally wounded king will get reaped soon enough
-            k:= false;
-            for i:= 0 to Pred(team^.Clan^.TeamsNumber) do
-                if (team^.Clan^.Teams[i]^.Hedgehogs[0].Gear <> nil) then k:= true;
-            if not k then
-                for i:= 0 to Pred(team^.Clan^.TeamsNumber) do
-                    begin
-                    team^.Clan^.Teams[i]^.hasGone:= true;
-                    TeamGoneEffect(team^.Clan^.Teams[i]^)
-                    end
-            end;
-
-        // should be not CurrentHedgehog, but hedgehog of the last gear which caused damage to this hog
-        // same stand for CheckHHDamage
-        if (Gear^.LastDamage <> nil) then
-            uStats.HedgehogDamaged(Gear, Gear^.LastDamage, 0, true)
-        else
-            uStats.HedgehogDamaged(Gear, CurrentHedgehog, 0, true);
-
-        inc(KilledHHs);
-        RecountTeamHealth(team);
-        if (CurrentHedgehog <> nil) and CurrentHedgehog^.Effects[heResurrectable] and (not Gear^.Hedgehog^.Effects[heResurrectable]) then
-            with CurrentHedgehog^ do 
-                begin
-                inc(Team^.stats.AIKills);
-                FreeTexture(Team^.AIKillsTex);
-                Team^.AIKillsTex := RenderStringTex(inttostr(Team^.stats.AIKills), Team^.Clan^.Color, fnt16);
-                end
-        end;
-with Gear^ do
-    AddFileLog('Delete: #' + inttostr(uid) + ' (' + inttostr(hwRound(x)) + ',' + inttostr(hwRound(y)) + '), d(' + floattostr(dX) + ',' + floattostr(dY) + ') type = ' + EnumToStr(Kind));
-
-if CurAmmoGear = Gear then CurAmmoGear:= nil;
-if FollowGear = Gear then FollowGear:= nil;
-if lastGearByUID = Gear then lastGearByUID := nil;
-RemoveGearFromList(Gear);
-Dispose(Gear)
-end;
-
-end.
+(*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (c) 2004-2011 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * 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
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *)
+
+{$INCLUDE "options.inc"}
+unit uGearsList;
+
+interface
+uses uFloat, uTypes;
+
+function  AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear;
+procedure DeleteGear(Gear: PGear);
+procedure InsertGearToList(Gear: PGear);
+procedure RemoveGearFromList(Gear: PGear);
+
+implementation
+
+uses uRandom, uUtils, uConsts, uVariables, uAmmos, uTeams, uStats,
+    uTextures, uScript, uRenderUtils, uAI, uCollisions,
+    uGearsRender, uGearsUtils;
+
+procedure InsertGearToList(Gear: PGear);
+var tmp, ptmp: PGear;
+begin
+    tmp:= GearsList;
+    ptmp:= GearsList;
+    while (tmp <> nil) and (tmp^.Z <= Gear^.Z) do
+        begin
+        ptmp:= tmp;
+        tmp:= tmp^.NextGear
+        end;
+
+    if ptmp <> tmp then
+        begin
+        Gear^.NextGear:= ptmp^.NextGear;
+        Gear^.PrevGear:= ptmp;
+        if ptmp^.NextGear <> nil then
+            ptmp^.NextGear^.PrevGear:= Gear;
+        ptmp^.NextGear:= Gear
+        end
+    else
+        begin
+        Gear^.NextGear:= GearsList;
+        if Gear^.NextGear <> nil then
+            Gear^.NextGear^.PrevGear:= Gear;
+        GearsList:= Gear;
+        end;
+end;
+
+procedure RemoveGearFromList(Gear: PGear);
+begin
+if Gear^.NextGear <> nil then
+    Gear^.NextGear^.PrevGear:= Gear^.PrevGear;
+if Gear^.PrevGear <> nil then
+    Gear^.PrevGear^.NextGear:= Gear^.NextGear
+else
+    GearsList:= Gear^.NextGear
+end;
+    
+function AddGear(X, Y: LongInt; Kind: TGearType; State: Longword; dX, dY: hwFloat; Timer: LongWord): PGear;
+const Counter: Longword = 0;
+var gear: PGear;
+begin
+inc(Counter);
+AddFileLog('AddGear: #' + inttostr(Counter) + ' (' + inttostr(x) + ',' + inttostr(y) + '), d(' + floattostr(dX) + ',' + floattostr(dY) + ') type = ' + EnumToStr(Kind));
+
+New(gear);
+FillChar(gear^, sizeof(TGear), 0);
+gear^.X:= int2hwFloat(X);
+gear^.Y:= int2hwFloat(Y);
+gear^.Target.X:= NoPointX;
+gear^.Kind := Kind;
+gear^.State:= State;
+gear^.Active:= true;
+gear^.dX:= dX;
+gear^.dY:= dY;
+gear^.doStep:= doStepHandlers[Kind];
+gear^.CollisionIndex:= -1;
+gear^.Timer:= Timer;
+gear^.FlightTime:= 0;
+gear^.uid:= Counter;
+gear^.SoundChannel:= -1;
+gear^.ImpactSound:= sndNone;
+gear^.nImpactSounds:= 0;
+gear^.Density:= _1;
+// Define ammo association, if any.
+gear^.AmmoType:= GearKindAmmoTypeMap[Kind];
+if Ammoz[Gear^.AmmoType].Ammo.Propz and ammoprop_NeedTarget <> 0 then
+    gear^.Z:= cHHZ+1
+else gear^.Z:= cUsualZ;
+
+if CurrentHedgehog <> nil then
+    begin
+    gear^.Hedgehog:= CurrentHedgehog;
+    gear^.IntersectGear:= CurrentHedgehog^.Gear
+    end;
+    
+case Kind of
+     gtGrenade,
+     gtClusterBomb,
+     gtGasBomb: begin
+                gear^.ImpactSound:= sndGrenadeImpact;
+                gear^.nImpactSounds:= 1;
+                gear^.AdvBounce:= 1;
+                gear^.Radius:= 5;
+                gear^.Elasticity:= _0_8;
+                gear^.Friction:= _0_8;
+                gear^.Density:= _1_5;
+                gear^.RenderTimer:= true;
+                if gear^.Timer = 0 then
+                    gear^.Timer:= 3000
+                end;
+  gtWatermelon: begin
+                gear^.ImpactSound:= sndMelonImpact;
+                gear^.nImpactSounds:= 1;
+                gear^.AdvBounce:= 1;
+                gear^.Radius:= 6;
+                gear^.Elasticity:= _0_8;
+                gear^.Friction:= _0_995;
+                gear^.Density:= _2;
+                gear^.RenderTimer:= true;
+                if gear^.Timer = 0 then
+                    gear^.Timer:= 3000
+                end;
+  gtMelonPiece: begin
+                gear^.Density:= _2;
+                end;
+    gtHedgehog: begin
+                gear^.AdvBounce:= 1;
+                gear^.Radius:= cHHRadius;
+                gear^.Elasticity:= _0_35;
+                gear^.Friction:= _0_999;
+                gear^.Angle:= cMaxAngle div 2;
+                gear^.Density:= _3;
+                gear^.Z:= cHHZ;
+                if (GameFlags and gfAISurvival) <> 0 then
+                    if gear^.Hedgehog^.BotLevel > 0 then
+                        gear^.Hedgehog^.Effects[heResurrectable] := true;
+                end;
+       gtShell: begin
+                gear^.Radius:= 4;
+                gear^.Density:= _1;
+                end;
+       gtSnowball: begin
+                gear^.ImpactSound:= sndMudballImpact;
+                gear^.nImpactSounds:= 1;
+                gear^.Radius:= 4;
+                gear^.Elasticity:= _1;
+                gear^.Friction:= _1;
+                gear^.Density:= _0_5;
+                end;
+
+     gtFlake: begin
+                with Gear^ do
+                    begin
+                    Pos:= 0;
+                    Radius:= 1;
+                    DirAngle:= random * 360;
+                    if State and gstTmpFlag = 0 then
+                        begin
+                        dx.isNegative:= GetRandom(2) = 0;
+                        dx.QWordValue:= GetRandom(100000000);
+                        dy.isNegative:= false;
+                        dy.QWordValue:= GetRandom(70000000);
+                        if GetRandom(2) = 0 then
+                            dx := -dx
+                        end;
+                    State:= State or gstInvisible;
+                    Health:= random(vobFrameTicks);
+                    Timer:= random(vobFramesCount);
+                    Angle:= (random(2) * 2 - 1) * (1 + random(10000)) * vobVelocity
+                    end
+                end;
+       gtGrave: begin
+                gear^.ImpactSound:= sndGraveImpact;
+                gear^.nImpactSounds:= 1;
+                gear^.Radius:= 10;
+                gear^.Elasticity:= _0_6;
+                end;
+         gtBee: begin
+                gear^.Radius:= 5;
+                gear^.Timer:= 500;
+                gear^.RenderTimer:= true;
+                gear^.Elasticity:= _0_9;
+                gear^.Tag:= 0;
+                end;
+   gtSeduction: begin
+                gear^.Radius:= 250;
+                end;
+ gtShotgunShot: begin
+                gear^.Timer:= 900;
+                gear^.Radius:= 2
+                end;
+  gtPickHammer: begin
+                gear^.Radius:= 10;
+                gear^.Timer:= 4000
+                end;
+   gtHammerHit: begin
+                gear^.Radius:= 8;
+                gear^.Timer:= 125
+                end;
+        gtRope: begin
+                gear^.Radius:= 3;
+                gear^.Friction:= _450 * _0_01 * cRopePercent;
+                RopePoints.Count:= 0;
+                end;
+        gtMine: begin
+                gear^.ImpactSound:= sndMineImpact;
+                gear^.nImpactSounds:= 1;
+                gear^.Health:= 10;
+                gear^.State:= gear^.State or gstMoving;
+                gear^.Radius:= 2;
+                gear^.Elasticity:= _0_55;
+                gear^.Friction:= _0_995;
+                gear^.Density:= _0_9;
+                if cMinesTime < 0 then
+                    gear^.Timer:= getrandom(51)*100
+                else
+                    gear^.Timer:= cMinesTime;
+                end;
+       gtSMine: begin
+                gear^.Health:= 10;
+                gear^.State:= gear^.State or gstMoving;
+                gear^.Radius:= 2;
+                gear^.Elasticity:= _0_55;
+                gear^.Friction:= _0_995;
+                gear^.Density:= _0_9;
+                gear^.Timer:= 500;
+                end;
+        gtCase: begin
+                gear^.ImpactSound:= sndGraveImpact;
+                gear^.nImpactSounds:= 1;
+                gear^.Radius:= 16;
+                gear^.Elasticity:= _0_3
+                end;
+  gtExplosives: begin
+                gear^.ImpactSound:= sndGrenadeImpact;
+                gear^.nImpactSounds:= 1;
+                gear^.Radius:= 16;
+                gear^.Elasticity:= _0_4;
+                gear^.Friction:= _0_995;
+                gear^.Density:= _6;
+                gear^.Health:= cBarrelHealth;
+                gear^.Z:= cHHZ-1
+                end;
+  gtDEagleShot: begin
+                gear^.Radius:= 1;
+                gear^.Health:= 50
+                end;
+  gtSniperRifleShot: begin
+                gear^.Radius:= 1;
+                gear^.Health:= 50
+                end;
+    gtDynamite: begin
+                gear^.Radius:= 3;
+                gear^.Elasticity:= _0_55;
+                gear^.Friction:= _0_03;
+                gear^.Density:= _2;
+                gear^.Timer:= 5000;
+                end;
+     gtCluster: begin
+                gear^.Radius:= 2;
+                gear^.Density:= _1_5;
+                gear^.RenderTimer:= true
+                end;
+      gtShover: gear^.Radius:= 20;
+       gtFlame: begin
+                gear^.Tag:= GetRandom(32);
+                gear^.Radius:= 1;
+                gear^.Health:= 5;
+                gear^.Density:= _1;
+                if (gear^.dY.QWordValue = 0) and (gear^.dX.QWordValue = 0) then
+                    begin
+                    gear^.dY:= (getrandom - _0_8) * _0_03;
+                    gear^.dX:= (getrandom - _0_5) * _0_4
+                    end
+                end;
+   gtFirePunch: begin
+                gear^.Radius:= 15;
+                gear^.Tag:= Y
+                end;
+     gtAirBomb: begin
+                gear^.Radius:= 5;
+                gear^.Density:= _2;
+                end;
+   gtBlowTorch: begin
+                gear^.Radius:= cHHRadius + cBlowTorchC;
+                gear^.Timer:= 7500
+                end;
+    gtSwitcher: begin
+                gear^.Z:= cCurrHHZ
+                end;
+      gtTarget: begin
+                gear^.ImpactSound:= sndGrenadeImpact;
+                gear^.nImpactSounds:= 1;
+                gear^.Radius:= 10;
+                gear^.Elasticity:= _0_3;
+                gear^.Timer:= 0
+                end;
+      gtTardis: begin
+                gear^.Timer:= 0;
+                gear^.Pos:= 1;
+                gear^.Z:= cCurrHHZ+1;
+                end;
+      gtMortar: begin
+                gear^.Radius:= 4;
+                gear^.Elasticity:= _0_2;
+                gear^.Friction:= _0_08;
+                gear^.Density:= _1;
+                end;
+        gtWhip: gear^.Radius:= 20;
+      gtHammer: gear^.Radius:= 20;
+    gtKamikaze: begin
+                gear^.Health:= 2048;
+                gear^.Radius:= 20
+                end;
+        gtCake: begin
+                gear^.Health:= 2048;
+                gear^.Radius:= 7;
+                gear^.Z:= cOnHHZ;
+                gear^.RenderTimer:= true;
+                gear^.DirAngle:= -90 * hwSign(Gear^.dX);
+                if not dX.isNegative then
+                    gear^.Angle:= 1
+                else
+                    gear^.Angle:= 3
+                end;
+ gtHellishBomb: begin
+                gear^.ImpactSound:= sndHellishImpact1;
+                gear^.nImpactSounds:= 4;
+                gear^.AdvBounce:= 1;
+                gear^.Radius:= 4;
+                gear^.Elasticity:= _0_5;
+                gear^.Friction:= _0_96;
+                gear^.Density:= _1_5;
+                gear^.RenderTimer:= true;
+                gear^.Timer:= 5000
+                end;
+       gtDrill: begin
+                if gear^.Timer = 0 then
+                    gear^.Timer:= 5000;
+                // Tag for drill strike. if 1 then first impact occured already
+                gear^.Tag := 0;
+                gear^.Radius:= 4;
+                gear^.Density:= _1;
+                end;
+        gtBall: begin
+                gear^.ImpactSound:= sndGrenadeImpact;
+                gear^.nImpactSounds:= 1;
+                gear^.AdvBounce:= 1;
+                gear^.Radius:= 5;
+                gear^.Tag:= random(8);
+                gear^.Timer:= 5000;
+                gear^.Elasticity:= _0_7;
+                gear^.Friction:= _0_995;
+                gear^.Density:= _1_5;
+                end;
+     gtBallgun: begin
+                gear^.Timer:= 5001;
+                end;
+     gtRCPlane: begin
+                gear^.Timer:= 15000;
+                gear^.Health:= 3;
+                gear^.Radius:= 8
+                end;
+     gtJetpack: begin
+                gear^.Health:= 2000;
+                gear^.Damage:= 100
+                end;
+     gtMolotov: begin
+                gear^.Radius:= 6;
+                gear^.Density:= _2;
+                end;
+       gtBirdy: begin
+                gear^.Radius:= 16; // todo: check
+                gear^.Timer:= 0;
+                gear^.Health := 2000;
+                gear^.FlightTime := 2;
+                end;
+         gtEgg: begin
+                gear^.Radius:= 4;
+                gear^.Elasticity:= _0_6;
+                gear^.Friction:= _0_96;
+                gear^.Density:= _1;
+                if gear^.Timer = 0 then
+                    gear^.Timer:= 3000
+                end;
+      gtPortal: begin
+                gear^.ImpactSound:= sndMelonImpact;
+                gear^.nImpactSounds:= 1;
+                gear^.AdvBounce:= 0;
+                gear^.Radius:= 17;
+                // set color
+                gear^.Tag:= 2 * gear^.Timer;
+                gear^.Timer:= 15000;
+                gear^.RenderTimer:= false;
+                gear^.Health:= 100;
+                end;
+       gtPiano: begin
+                gear^.Radius:= 32;
+                gear^.Density:= _50;
+                end;
+ gtSineGunShot: begin
+                gear^.Radius:= 5;
+                gear^.Health:= 6000;
+                end;
+gtFlamethrower: begin
+                gear^.Tag:= 10;
+                gear^.Timer:= 10;
+                gear^.Health:= 500;
+                gear^.Damage:= 100;
+                end;
+     gtLandGun: begin
+                gear^.Tag:= 10;
+                gear^.Timer:= 10;
+                gear^.Health:= 1000;
+                gear^.Damage:= 100;
+                end;
+ gtPoisonCloud: begin
+                gear^.Timer:= 5000;
+                gear^.dY:= int2hwfloat(-4 + longint(getRandom(8))) / 1000;
+                end;
+ gtResurrector: begin
+                gear^.Radius := 100;
+                gear^.Tag := 0
+                end;
+     gtWaterUp: begin
+                gear^.Tag := 47;
+                end;
+  gtNapalmBomb: begin
+                gear^.Timer:= 1000;
+                gear^.Radius:= 5;
+                gear^.Density:= _1_5;
+                end;
+   gtStructure: begin
+                gear^.Elasticity:= _0_55;
+                gear^.Friction:= _0_995;
+                gear^.Density:= _0_9;
+                gear^.Radius:= 13;
+                gear^.Health:= 200;
+                gear^.Timer:= 0;
+                gear^.Tag:= TotalRounds + 3;
+                gear^.Pos:= 1;
+                end;
+    end;
+
+InsertGearToList(gear);
+AddGear:= gear;
+
+ScriptCall('onGearAdd', gear^.uid);
+end;
+
+procedure DeleteGear(Gear: PGear);
+var team: PTeam;
+    t,i: Longword;
+    k: boolean;
+begin
+
+ScriptCall('onGearDelete', gear^.uid);
+
+DeleteCI(Gear);
+
+FreeTexture(Gear^.Tex);
+Gear^.Tex:= nil;
+
+// make sure that portals have their link removed before deletion
+if (Gear^.Kind = gtPortal) then
+    begin
+    if (Gear^.IntersectGear <> nil) then
+        if (Gear^.IntersectGear^.IntersectGear = Gear) then
+            Gear^.IntersectGear^.IntersectGear:= nil;
+    end
+else if Gear^.Kind = gtHedgehog then
+    (*
+    This behaviour dates back to revision 4, and I accidentally encountered it with TARDIS.  I don't think it must apply to any modern weapon, since if it was actually hit, the best the gear could do would be to destroy itself immediately, and you'd still end up with two graves.  I believe it should be removed
+     if (CurAmmoGear <> nil) and (CurrentHedgehog^.Gear = Gear) then
+        begin
+        AttackBar:= 0;
+        Gear^.Message:= gmDestroy;
+        CurAmmoGear^.Message:= gmDestroy;
+        exit
+        end
+    else*)
+        begin
+        if (hwRound(Gear^.Y) >= cWaterLine) then
+            begin
+            t:= max(Gear^.Damage, Gear^.Health);
+            Gear^.Damage:= t;
+            if ((not SuddenDeathDmg and (cWaterOpacity < $FF)) or (SuddenDeathDmg and (cWaterOpacity < $FF)))
+            and (hwRound(Gear^.Y) < cWaterLine + 256) then
+                spawnHealthTagForHH(Gear, t);
+            end;
+
+        team:= Gear^.Hedgehog^.Team;
+        if CurrentHedgehog^.Gear = Gear then
+            begin
+            AttackBar:= 0;
+            FreeActionsList; // to avoid ThinkThread on drawned gear
+            if ((Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_NoRoundEnd) <> 0)
+            and (CurrentHedgehog^.MultiShootAttacks > 0) then
+                OnUsedAmmo(CurrentHedgehog^);
+            end;
+
+        Gear^.Hedgehog^.Gear:= nil;
+        if Gear^.Hedgehog^.King then
+            begin
+            // are there any other kings left? Just doing nil check.  Presumably a mortally wounded king will get reaped soon enough
+            k:= false;
+            for i:= 0 to Pred(team^.Clan^.TeamsNumber) do
+                if (team^.Clan^.Teams[i]^.Hedgehogs[0].Gear <> nil) then
+                    k:= true;
+            if not k then
+                for i:= 0 to Pred(team^.Clan^.TeamsNumber) do
+                    begin
+                    team^.Clan^.Teams[i]^.hasGone:= true;
+                    TeamGoneEffect(team^.Clan^.Teams[i]^)
+                    end
+            end;
+
+        // should be not CurrentHedgehog, but hedgehog of the last gear which caused damage to this hog
+        // same stand for CheckHHDamage
+        if (Gear^.LastDamage <> nil) then
+            uStats.HedgehogDamaged(Gear, Gear^.LastDamage, 0, true)
+        else
+            uStats.HedgehogDamaged(Gear, CurrentHedgehog, 0, true);
+
+        inc(KilledHHs);
+        RecountTeamHealth(team);
+        if (CurrentHedgehog <> nil) and CurrentHedgehog^.Effects[heResurrectable] and
+        (not Gear^.Hedgehog^.Effects[heResurrectable]) then
+            with CurrentHedgehog^ do 
+                begin
+                inc(Team^.stats.AIKills);
+                FreeTexture(Team^.AIKillsTex);
+                Team^.AIKillsTex := RenderStringTex(inttostr(Team^.stats.AIKills), Team^.Clan^.Color, fnt16);
+                end
+        end;
+with Gear^ do
+    AddFileLog('Delete: #' + inttostr(uid) + ' (' + inttostr(hwRound(x)) + ',' + inttostr(hwRound(y)) + '), d(' + floattostr(dX) + ',' + floattostr(dY) + ') type = ' + EnumToStr(Kind));
+
+if CurAmmoGear = Gear then
+    CurAmmoGear:= nil;
+if FollowGear = Gear then
+    FollowGear:= nil;
+if lastGearByUID = Gear then
+    lastGearByUID := nil;
+RemoveGearFromList(Gear);
+Dispose(Gear)
+end;
+
+end.
--- a/hedgewars/uGearsRender.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uGearsRender.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -29,10 +29,10 @@
                 Count: Longword;
                 HookAngle: GLfloat;
                 ar: array[0..MAXROPEPOINTS] of record
-                                  X, Y: hwFloat;
-                                  dLen: hwFloat;
-                                  b: boolean;
-                                  end;
+                                X, Y: hwFloat;
+                                dLen: hwFloat;
+                                b: boolean;
+                                end;
                 rounded: array[0..MAXROPEPOINTS + 2] of TVertex2f;
                 end;
 
@@ -89,13 +89,15 @@
     dX:= X2 - X1;
     dY:= Y2 - Y1;
 
-    if (dX > 0) then sX:= 1
+    if (dX > 0) then
+        sX:= 1
     else
-    if (dX < 0) then
-        begin
-        sX:= -1;
-        dX:= -dX
-        end else sX:= dX;
+        if (dX < 0) then
+            begin
+            sX:= -1;
+            dX:= -dX
+            end
+        else sX:= dX;
 
     if (dY > 0) then 
         sY:= 1
@@ -104,11 +106,14 @@
             begin
             sY:= -1;
             dY:= -dY
-            end else 
+            end
+        else 
             sY:= dY;
 
-    if (dX > dY) then d:= dX
-                else d:= dY;
+    if (dX > dY) then
+        d:= dX
+    else
+        d:= dY;
 
     x:= X1;
     y:= Y1;
@@ -133,7 +138,8 @@
         if b then
             begin
             inc(roplen);
-            if (roplen mod 4) = 0 then DrawSprite(sprRopeNode, x - 2, y - 2, 0)
+            if (roplen mod 4) = 0 then
+                DrawSprite(sprRopeNode, x - 2, y - 2, 0)
             end
     end;
 DrawRopeLine:= roplen;
@@ -161,7 +167,8 @@
                         hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, roplen);
             roplen:= DrawRopeLine(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy,
                         hwRound(Gear^.Hedgehog^.Gear^.X) + WorldDx, hwRound(Gear^.Hedgehog^.Gear^.Y) + WorldDy, roplen);
-            end else
+            end
+        else
             if Gear^.Elasticity.QWordValue > 0 then
             roplen:= DrawRopeLine(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy,
                         hwRound(Gear^.Hedgehog^.Gear^.X) + WorldDx, hwRound(Gear^.Hedgehog^.Gear^.Y) + WorldDy, roplen);
@@ -170,7 +177,7 @@
 
 if RopePoints.Count > 0 then
     DrawRotated(sprRopeHook, hwRound(RopePoints.ar[0].X) + WorldDx, hwRound(RopePoints.ar[0].Y) + WorldDy, 1, RopePoints.HookAngle)
-    else
+else
     if Gear^.Elasticity.QWordValue > 0 then
         DrawRotated(sprRopeHook, hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, 0, DxDy2Angle(Gear^.dY, Gear^.dX));
 end;
@@ -198,9 +205,11 @@
     CurWeapon: PAmmo;
 begin
     HH:= Gear^.Hedgehog;
-    if HH^.Unplaced then exit;
+    if HH^.Unplaced then
+        exit;
     m:= 1;
-    if ((Gear^.State and gstHHHJump) <> 0) and (not cArtillery) then m:= -1;
+    if ((Gear^.State and gstHHHJump) <> 0) and (not cArtillery) then
+        m:= -1;
     sx:= ox + 1; // this offset is very common
     sy:= oy - 3;
     sign:= hwSign(Gear^.dX);
@@ -263,10 +272,10 @@
         begin
         if ((Gear^.State and (gstHHThinking or gstAnimation)) = 0) and
 /// If current ammo is active, and current ammo has alt attack and uses a crosshair  (rope, basically, right now, with no crosshair for parachute/saucer
-           (((CurAmmoGear <> nil) and //((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) <> 0) and
+            (((CurAmmoGear <> nil) and //((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) <> 0) and
              ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_NoCrossHair) = 0)) or
 /// If no current ammo is active, and the selected ammo uses a crosshair
-             ((CurAmmoGear = nil) and ((Ammoz[HH^.CurAmmoType].Ammo.Propz and ammoprop_NoCrosshair) = 0) and ((Gear^.State and gstAttacked) = 0))) then
+            ((CurAmmoGear = nil) and ((Ammoz[HH^.CurAmmoType].Ammo.Propz and ammoprop_NoCrosshair) = 0) and ((Gear^.State and gstAttacked) = 0))) then
             begin
     (* These calculations are a little complex for a few reasons:
     1: I need to draw the laser from weapon origin to nearest land
@@ -360,7 +369,8 @@
                         dAngle:= 0;
                         hAngle:= 180;
                         i:= 1
-                        end else
+                        end
+                    else
                         begin
                         dAngle:= 180;
                         hAngle:= 0;
@@ -390,7 +400,8 @@
                     DrawAltWeapon(Gear, ox, oy);
                     defaultPos:= false
                     end;
-                gtBlowTorch: begin
+                gtBlowTorch:
+                    begin
                     DrawRotated(sprBlowTorch, hx, hy, sign, aangle);
                     DrawHedgehog(sx, sy,
                             sign,
@@ -425,7 +436,8 @@
                     defaultPos:= false
                     end;
                 gtShover: DrawRotated(sprHandBaseball, hx, hy, sign, aangle + 180);
-                gtFirePunch: begin
+                gtFirePunch:
+                    begin
                     DrawHedgehog(sx, sy,
                             sign,
                             1,
@@ -433,12 +445,14 @@
                             0);
                     defaultPos:= false
                     end;
-                gtPickHammer: begin
+                gtPickHammer:
+                    begin
                     defaultPos:= false;
                     dec(sy,20);
                     end;
                 gtTeleport: defaultPos:= false;
-                gtWhip: begin
+                gtWhip:
+                    begin
                     DrawRotatedF(sprWhip,
                             sx,
                             sy,
@@ -447,7 +461,8 @@
                             0);
                     defaultPos:= false
                     end;
-                gtHammer: begin
+                gtHammer:
+                    begin
                     DrawRotatedF(sprHammer,
                             sx,
                             sy,
@@ -456,11 +471,13 @@
                             0);
                     defaultPos:= false
                     end;
-                gtResurrector: begin
+                gtResurrector:
+                    begin
                     DrawRotated(sprHandResurrector, sx, sy, 0, 0);
                     defaultPos:= false
                     end;
-                gtKamikaze: begin
+                gtKamikaze:
+                    begin
                     if CurAmmoGear^.Pos = 0 then
                         DrawHedgehog(sx, sy,
                                 sign,
@@ -475,7 +492,8 @@
                                 aangle);
                     defaultPos:= false
                     end;
-                gtSeduction: begin
+                gtSeduction:
+                    begin
                     if CurAmmoGear^.Pos >= 6 then
                         DrawHedgehog(sx, sy,
                                 sign,
@@ -493,12 +511,16 @@
                         end;
                     defaultPos:= false
                     end;
-                gtFlamethrower: begin
+                gtFlamethrower:
+                    begin
                     DrawRotatedF(sprHandFlamethrower, hx, hy, (RealTicks div 125) mod 4, sign, aangle);
-                    if CurAmmoGear^.Tex <> nil then DrawCentered(sx, sy - 40, CurAmmoGear^.Tex)
+                    if CurAmmoGear^.Tex <> nil then
+                        DrawCentered(sx, sy - 40, CurAmmoGear^.Tex)
                     end;
-                gtLandGun: begin DrawRotated(sprHandBallgun, hx, hy, sign, aangle);
-                    if CurAmmoGear^.Tex <> nil then DrawCentered(sx, sy - 40, CurAmmoGear^.Tex)
+                gtLandGun:
+                    begin DrawRotated(sprHandBallgun, hx, hy, sign, aangle);
+                    if CurAmmoGear^.Tex <> nil then
+                        DrawCentered(sx, sy - 40, CurAmmoGear^.Tex)
                     end;
             end;
 
@@ -506,12 +528,9 @@
                 gtShotgunShot,
                 gtDEagleShot,
                 gtSniperRifleShot,
-                gtShover: begin
-                    DrawHedgehog(sx, sy,
-                            sign,
-                            0,
-                            4,
-                            0);
+                gtShover:
+                    begin
+                    DrawHedgehog(sx, sy, sign, 0, 4, 0);
                     defaultPos:= false;
                     HatVisible:= true
                 end
@@ -564,9 +583,12 @@
             if HH^.Timer > 0 then
                 begin
                 // There must be a tidier way to do this. Anyone?
-                if aangle <= 90 then aangle:= aangle+360;
-                if Gear^.dX > _0 then aangle:= aangle-((aangle-240)*HH^.Timer/10)
-                else aangle:= aangle+((240-aangle)*HH^.Timer/10);
+                if aangle <= 90 then
+                    aangle:= aangle+360;
+                if Gear^.dX > _0 then
+                    aangle:= aangle-((aangle-240)*HH^.Timer/10)
+                else
+                    aangle:= aangle+((240-aangle)*HH^.Timer/10);
                 dec(HH^.Timer)
                 end;
             amt:= CurrentHedgehog^.CurAmmoType;
@@ -582,10 +604,13 @@
                 amShotgun: DrawRotated(sprHandShotgun, hx, hy, sign, aangle);
                 amDEagle: DrawRotated(sprHandDEagle, hx, hy, sign, aangle);
                 amSineGun: DrawRotatedF(sprHandSinegun, hx, hy, 73 + (sign * LongInt(RealTicks div 73)) mod 8, sign, aangle);
-                amPortalGun: if (CurWeapon^.Timer and 2) <> 0 then // Add a new Hedgehog value instead of abusing timer?
-                                DrawRotatedF(sprPortalGun, hx, hy, 0, sign, aangle)
-                        else
-                                DrawRotatedF(sprPortalGun, hx, hy, 1+CurWeapon^.Pos, sign, aangle);
+                
+                amPortalGun:
+                    if (CurWeapon^.Timer and 2) <> 0 then // Add a new Hedgehog value instead of abusing timer?
+                        DrawRotatedF(sprPortalGun, hx, hy, 0, sign, aangle)
+                    else
+                        DrawRotatedF(sprPortalGun, hx, hy, 1+CurWeapon^.Pos, sign, aangle);
+                        
                 amSniperRifle: DrawRotatedF(sprSniperRifle, hx, hy, 0, sign, aangle);
                 amBlowTorch: DrawRotated(sprHandBlowTorch, hx, hy, sign, aangle);
                 amCake: DrawRotated(sprHandCake, hx, hy, sign, aangle);
@@ -795,11 +820,15 @@
                         DrawSprite(sprJetpack, sx-32, sy-32, 0);
                         if cWaterLine > hwRound(Gear^.Y) + Gear^.Radius then
                             begin
-                            if (CurAmmoGear^.MsgParam and gmUp) <> 0 then DrawSprite(sprJetpack, sx-32, sy-28, 1);
-                            if (CurAmmoGear^.MsgParam and gmLeft) <> 0 then DrawSprite(sprJetpack, sx-28, sy-28, 2);
-                            if (CurAmmoGear^.MsgParam and gmRight) <> 0 then DrawSprite(sprJetpack, sx-36, sy-28, 3)
+                            if (CurAmmoGear^.MsgParam and gmUp) <> 0 then
+                                DrawSprite(sprJetpack, sx-32, sy-28, 1);
+                            if (CurAmmoGear^.MsgParam and gmLeft) <> 0 then
+                                DrawSprite(sprJetpack, sx-28, sy-28, 2);
+                            if (CurAmmoGear^.MsgParam and gmRight) <> 0 then
+                                DrawSprite(sprJetpack, sx-36, sy-28, 3)
                             end;
-                        if CurAmmoGear^.Tex <> nil then DrawCentered(sx, sy - 40, CurAmmoGear^.Tex);
+                        if CurAmmoGear^.Tex <> nil then
+                            DrawCentered(sx, sy - 40, CurAmmoGear^.Tex);
                         DrawAltWeapon(Gear, sx, sy)
                         end;
                 end;
@@ -942,30 +971,38 @@
              gtBee: DrawRotatedF(sprBee, x, y, (GameTicks shr 5) mod 2, 0, DxDy2Angle(Gear^.dY, Gear^.dX));
       gtPickHammer: DrawSprite(sprPHammer, x - 16, y - 50 + LongInt(((GameTicks shr 5) and 1) * 2), 0);
             gtRope: DrawRope(Gear);
+            
             gtMine: if (((Gear^.State and gstAttacking) = 0)or((Gear^.Timer and $3FF) < 420)) and (Gear^.Health <> 0) then
                            DrawRotated(sprMineOff, x, y, 0, Gear^.DirAngle)
-                       else if Gear^.Health <> 0 then DrawRotated(sprMineOn, x, y, 0, Gear^.DirAngle)
+                       else if Gear^.Health <> 0 then
+                           DrawRotated(sprMineOn, x, y, 0, Gear^.DirAngle)
                        else DrawRotated(sprMineDead, x, y, 0, Gear^.DirAngle);
+                       
            gtSMine: if (((Gear^.State and gstAttacking) = 0)or((Gear^.Timer and $3FF) < 420)) and (Gear^.Health <> 0) then
                            DrawRotated(sprSMineOff, x, y, 0, Gear^.DirAngle)
-                       else if Gear^.Health <> 0 then DrawRotated(sprSMineOn, x, y, 0, Gear^.DirAngle)
+                       else if Gear^.Health <> 0 then
+                           DrawRotated(sprSMineOn, x, y, 0, Gear^.DirAngle)
                        else DrawRotated(sprMineDead, x, y, 0, Gear^.DirAngle);
+                       
             gtCase: if ((Gear^.Pos and posCaseAmmo) <> 0) then
                         begin
                         i:= (GameTicks shr 6) mod 64;
-                        if i > 18 then i:= 0;
+                        if i > 18 then
+                            i:= 0;
                         DrawSprite(sprCase, x - 24, y - 24, i);
                         end
                     else if ((Gear^.Pos and posCaseHealth) <> 0) then
                         begin
                         i:= ((GameTicks shr 6) + 38) mod 64;
-                        if i > 13 then i:= 0;
+                        if i > 13 then
+                            i:= 0;
                         DrawSprite(sprFAid, x - 24, y - 24, i);
                         end
                     else if ((Gear^.Pos and posCaseUtility) <> 0) then
                         begin
                         i:= (GameTicks shr 6) mod 70;
-                        if i > 23 then i:= 0;
+                        if i > 23 then
+                            i:= 0;
                         i:= i mod 12;
                         DrawSprite(sprUtility, x - 24, y - 24, i);
                         end;
@@ -975,7 +1012,8 @@
                     else if Gear^.State and gstAnimation = 0 then
                         begin
                         i:= (GameTicks shr 6 + Gear^.uid*3) mod 64;
-                        if i > 18 then i:= 0;
+                        if i > 18 then
+                            i:= 0;
                         DrawSprite(sprExplosives, x - 24, y - 24, i)
                         end
                     else if Gear^.State and gsttmpFlag = 0 then
@@ -1002,7 +1040,8 @@
          gtAirBomb: DrawRotated(sprAirBomb, x, y, 0, DxDy2Angle(Gear^.dY, Gear^.dX));
         gtTeleport: begin
                     HHGear:= Gear^.Hedgehog^.Gear;
-                    if not Gear^.Hedgehog^.Unplaced then DrawRotatedF(sprTeleport, x + 1, y - 3, Gear^.Pos, hwSign(Gear^.dX), 0);
+                    if not Gear^.Hedgehog^.Unplaced then
+                        DrawRotatedF(sprTeleport, x + 1, y - 3, Gear^.Pos, hwSign(Gear^.dX), 0);
                     DrawRotatedF(sprTeleport, hwRound(HHGear^.X) + 1 + WorldDx, hwRound(HHGear^.Y) - 3 + WorldDy, 11 - Gear^.Pos, hwSign(HHGear^.dX), 0);
                     end;
         gtSwitcher: DrawSprite(sprSwitch, x - 16, y - 56, (GameTicks shr 6) mod 12);
@@ -1016,7 +1055,9 @@
                      DrawRotatedf(sprCakeWalk, x, y, (GameTicks div 40) mod 6, hwSign(Gear^.dX), Gear^.DirAngle * hwSign(Gear^.dX) + 90)
                   else
                      DrawRotatedf(sprCakeDown, x, y, 5 - Gear^.Pos, hwSign(Gear^.dX), Gear^.DirAngle * hwSign(Gear^.dX) + 90);
-       gtSeduction: if Gear^.Pos >= 14 then DrawSprite(sprSeduction, x - 16, y - 16, 0);
+       gtSeduction: if Gear^.Pos >= 14 then
+           DrawSprite(sprSeduction, x - 16, y - 16, 0);
+           
       gtWatermelon: DrawRotatedf(sprWatermelon, x, y, 0, 0, Gear^.DirAngle);
       gtMelonPiece: DrawRotatedf(sprWatermelon, x, y, 1, 0, Gear^.DirAngle);
      gtHellishBomb: DrawRotated(sprHellishBomb, x, y, 0, Gear^.DirAngle);
@@ -1096,27 +1137,36 @@
                         end
                     else //if not isInLag then
                         begin
-                        if isInLag and (Gear^.FlightTime < 256) then inc(Gear^.FlightTime, 8)
-                        else if not isInLag and (Gear^.FlightTime > 0) then dec(Gear^.FlightTime, 8);
-                        if Gear^.FlightTime > 0 then Tint($FF, $FF, $FF, $FF-min(255,Gear^.FlightTime));
+                        if isInLag and (Gear^.FlightTime < 256) then
+                            inc(Gear^.FlightTime, 8)
+                        else if not isInLag and (Gear^.FlightTime > 0) then
+                            dec(Gear^.FlightTime, 8);
+                        if Gear^.FlightTime > 0 then
+                            Tint($FF, $FF, $FF, $FF-min(255,Gear^.FlightTime));
                         if vobVelocity = 0 then
                             DrawSprite(sprFlake, x, y, Gear^.Timer)
                         else
                             DrawRotatedF(sprFlake, x, y, Gear^.Timer, 1, Gear^.DirAngle);
 //DrawSprite(sprFlake, x-SpritesData[sprFlake].Width div 2, y-SpritesData[sprFlake].Height div 2, Gear^.Timer)
 //DrawRotatedF(sprFlake, x-SpritesData[sprFlake].Width div 2, y-SpritesData[sprFlake].Height div 2, Gear^.Timer, 1, Gear^.DirAngle);
-                        if Gear^.FlightTime > 0 then Tint($FF, $FF, $FF, $FF);
+                        if Gear^.FlightTime > 0 then
+                            Tint($FF, $FF, $FF, $FF);
                         end;
        gtStructure: DrawSprite(sprTarget, x - 16, y - 16, 0);
           gtTardis: if Gear^.Pos <> 4 then
                         begin
-                        if Gear^.Pos = 2 then Tint(Gear^.Hedgehog^.Team^.Clan^.Color shl 8 or $FF)
-                        else Tint(Gear^.Hedgehog^.Team^.Clan^.Color shl 8 or max($00, round(Gear^.Power * (1-abs(0.5 - (GameTicks mod 2000) / 2000)))));
+                        if Gear^.Pos = 2 then
+                            Tint(Gear^.Hedgehog^.Team^.Clan^.Color shl 8 or $FF)
+                        else 
+                            Tint(Gear^.Hedgehog^.Team^.Clan^.Color shl 8 or max($00, round(Gear^.Power * (1-abs(0.5 - (GameTicks mod 2000) / 2000)))));
                         DrawSprite(sprTardis, x-24, y-63,0);
-                        if Gear^.Pos = 2 then Tint($FF, $FF, $FF, $FF)
-			else Tint($FF,$FF,$FF,max($00, round(Gear^.Power * (1-abs(0.5 - (GameTicks mod 2000) / 2000)))));
+                        if Gear^.Pos = 2 then
+                            Tint($FF, $FF, $FF, $FF)
+                        else
+                            Tint($FF,$FF,$FF,max($00, round(Gear^.Power * (1-abs(0.5 - (GameTicks mod 2000) / 2000)))));
                         DrawSprite(sprTardis, x-24, y-63,1);
-                        if Gear^.Pos <> 2 then Tint($FF, $FF, $FF, $FF)
+                        if Gear^.Pos <> 2 then
+                            Tint($FF, $FF, $FF, $FF)
 (*
                         Tint(Gear^.Hedgehog^.Team^.Clan^.Color shl 8 or max($00, round(Gear^.Power * abs(1 - (RealTicks mod 500) / 250))));
                         DrawTexture(x-6, y-70, SpritesData[sprVampiric].Texture, 0.25);
@@ -1126,7 +1176,8 @@
 
 
          end;
-      if Gear^.RenderTimer and (Gear^.Tex <> nil) then DrawCentered(x + 8, y + 8, Gear^.Tex);
+      if Gear^.RenderTimer and (Gear^.Tex <> nil) then
+          DrawCentered(x + 8, y + 8, Gear^.Tex);
 end;
 
 end.
--- a/hedgewars/uGearsUtils.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uGearsUtils.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -1,553 +1,573 @@
-(*
- * Hedgewars, a free turn based strategy game
- * Copyright (c) 2004-2011 Andrey Korotaev <unC0Rr@gmail.com>
- *
- * 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
- * the Free Software Foundation; version 2 of the License
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- *)
-
-{$INCLUDE "options.inc"}
-
-unit uGearsUtils;
-interface
-uses uTypes;
-
-procedure doMakeExplosion(X, Y, Radius: LongInt; AttackingHog: PHedgehog; Mask: Longword; const Tint: LongWord = $FFFFFFFF); 
-function  ModifyDamage(dmg: Longword; Gear: PGear): Longword;
-procedure ApplyDamage(Gear: PGear; AttackerHog: PHedgehog; Damage: Longword; Source: TDamageSource);
-procedure spawnHealthTagForHH(HHGear: PGear; dmg: Longword);
-procedure HHHurt(Hedgehog: PHedgehog; Source: TDamageSource);
-procedure CheckHHDamage(Gear: PGear);
-procedure CalcRotationDirAngle(Gear: PGear);
-procedure ResurrectHedgehog(gear: PGear);
-procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt; skipProximity: boolean = false);
-function  CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear;
-function  CheckGearsNear(mX, mY: LongInt; Kind: TGearsType; rX, rY: LongInt): PGear;
-function  CheckGearDrowning(Gear: PGear): boolean;
-
-var doStepHandlers: array[TGearType] of TGearStepProcedure;
-
-
-implementation
-uses uFloat, uSound, uCollisions, uUtils, uConsts, uVisualGears, uAIMisc,
-    uVariables, uLandGraphics, uScript, uStats, uCaptions, uTeams, uStore,
-    uLocale, uTextures, uRenderUtils, uRandom, SDLh, uDebug, uGears,
-    uGearsList;
-
-procedure doMakeExplosion(X, Y, Radius: LongInt; AttackingHog: PHedgehog; Mask: Longword; const Tint: LongWord);
-var Gear: PGear;
-    dmg, dmgRadius, dmgBase: LongInt;
-    fX, fY: hwFloat;
-    vg: PVisualGear;
-    i, cnt: LongInt;
-begin
-if Radius > 4 then AddFileLog('Explosion: at (' + inttostr(x) + ',' + inttostr(y) + ')');
-if Radius > 25 then KickFlakes(Radius, X, Y);
-
-if ((Mask and EXPLNoGfx) = 0) then
-    begin
-    vg:= nil;
-    if Radius > 50 then vg:= AddVisualGear(X, Y, vgtBigExplosion)
-    else if Radius > 10 then vg:= AddVisualGear(X, Y, vgtExplosion);
-    if vg <> nil then
-        vg^.Tint:= Tint;
-    end;
-if (Mask and EXPLAutoSound) <> 0 then PlaySound(sndExplosion);
-
-if (Mask and EXPLAllDamageInRadius) = 0 then
-    dmgRadius:= Radius shl 1
-else
-    dmgRadius:= Radius;
-dmgBase:= dmgRadius + cHHRadius div 2;
-fX:= int2hwFloat(X);
-fY:= int2hwFloat(Y);
-Gear:= GearsList;
-while Gear <> nil do
-    begin
-    dmg:= 0;
-    //dmg:= dmgRadius  + cHHRadius div 2 - hwRound(Distance(Gear^.X - int2hwFloat(X), Gear^.Y - int2hwFloat(Y)));
-    //if (dmg > 1) and
-    if (Gear^.State and gstNoDamage) = 0 then
-        begin
-        case Gear^.Kind of
-            gtHedgehog,
-                gtMine,
-                gtBall,
-                gtMelonPiece,
-                gtGrenade,
-                gtClusterBomb,
-            //    gtCluster, too game breaking I think
-                gtSMine,
-                gtCase,
-                gtTarget,
-                gtFlame,
-                gtExplosives,
-                gtStructure: begin
-// Run the calcs only once we know we have a type that will need damage
-                        if hwRound(hwAbs(Gear^.X-fX)+hwAbs(Gear^.Y-fY)) < dmgBase then
-                            dmg:= dmgBase - max(hwRound(Distance(Gear^.X - fX, Gear^.Y - fY)),Gear^.Radius);
-                        if dmg > 1 then
-                            begin
-                            dmg:= ModifyDamage(min(dmg div 2, Radius), Gear);
-                            //AddFileLog('Damage: ' + inttostr(dmg));
-                            if (Mask and EXPLNoDamage) = 0 then
-                                begin
-                                if not Gear^.Invulnerable then
-                                    ApplyDamage(Gear, AttackingHog, dmg, dsExplosion)
-                                else
-                                    Gear^.State:= Gear^.State or gstWinner;
-                                end;
-                            if ((Mask and EXPLDoNotTouchAny) = 0) and (((Mask and EXPLDoNotTouchHH) = 0) or (Gear^.Kind <> gtHedgehog)) then
-                                begin
-                                DeleteCI(Gear);
-                                Gear^.dX:= Gear^.dX + SignAs(_0_005 * dmg + cHHKick, Gear^.X - fX)/(Gear^.Density/_3);
-                                Gear^.dY:= Gear^.dY + SignAs(_0_005 * dmg + cHHKick, Gear^.Y - fY)/(Gear^.Density/_3);
-
-                                Gear^.State:= (Gear^.State or gstMoving) and (not gstLoser);
-                                if not Gear^.Invulnerable then
-                                    Gear^.State:= (Gear^.State or gstMoving) and (not gstWinner);
-                                Gear^.Active:= true;
-                                if Gear^.Kind <> gtFlame then FollowGear:= Gear
-                                end;
-                            if ((Mask and EXPLPoisoned) <> 0) and (Gear^.Kind = gtHedgehog) and (not Gear^.Invulnerable) then
-                                Gear^.Hedgehog^.Effects[hePoisoned] := true;
-                            end;
-
-                        end;
-                gtGrave: begin
-// Run the calcs only once we know we have a type that will need damage
-                        if hwRound(hwAbs(Gear^.X-fX)+hwAbs(Gear^.Y-fY)) < dmgBase then
-                            dmg:= dmgBase - hwRound(Distance(Gear^.X - fX, Gear^.Y - fY));
-                        if dmg > 1 then
-                            begin
-                            dmg:= ModifyDamage(min(dmg div 2, Radius), Gear);
-                            Gear^.dY:= - _0_004 * dmg;
-                            Gear^.Active:= true
-                            end
-                        end;
-            end;
-        end;
-    Gear:= Gear^.NextGear
-    end;
-
-if (Mask and EXPLDontDraw) = 0 then
-    if (GameFlags and gfSolidLand) = 0 then
-        begin
-        cnt:= DrawExplosion(X, Y, Radius) div 1608; // approx 2 16x16 circles to erase per chunk
-        if (cnt > 0) and (SpritesData[sprChunk].Texture <> nil) then
-            for i:= 0 to cnt do
-                AddVisualGear(X, Y, vgtChunk)
-        end;
-
-uAIMisc.AwareOfExplosion(0, 0, 0)
-end;
-
-function ModifyDamage(dmg: Longword; Gear: PGear): Longword;
-var i: hwFloat;
-begin
-(* Invulnerability cannot be placed in here due to still needing kicks
-   Not without a new damage machine.
-   King check should be in here instead of ApplyDamage since Tiy wants them kicked less
-*)
-i:= _1;
-if (CurrentHedgehog <> nil) and CurrentHedgehog^.King then i:= _1_5;
-if (Gear^.Hedgehog <> nil) and (Gear^.Hedgehog^.King) then
-   ModifyDamage:= hwRound(_0_01 * cDamageModifier * dmg * i * cDamagePercent * _0_5)
-else
-   ModifyDamage:= hwRound(_0_01 * cDamageModifier * dmg * i * cDamagePercent)
-end;
-
-procedure ApplyDamage(Gear: PGear; AttackerHog: PHedgehog; Damage: Longword; Source: TDamageSource);
-var s: shortstring;
-    vampDmg, tmpDmg, i: Longword;
-    vg: PVisualGear;
-begin
-  if Damage = 0 then exit; // nothing to apply
-
-    if (Gear^.Kind = gtHedgehog) then
-    begin
-    Gear^.LastDamage := AttackerHog;
-
-    Gear^.Hedgehog^.Team^.Clan^.Flawless:= false;
-    HHHurt(Gear^.Hedgehog, Source);
-    AddDamageTag(hwRound(Gear^.X), hwRound(Gear^.Y), Damage, Gear^.Hedgehog^.Team^.Clan^.Color);
-    tmpDmg:= min(Damage, max(0,Gear^.Health-Gear^.Damage));
-    if (Gear <> CurrentHedgehog^.Gear) and (CurrentHedgehog^.Gear <> nil) and (tmpDmg >= 1) then
-        begin
-        if cVampiric then
-            begin
-            vampDmg:= hwRound(int2hwFloat(tmpDmg)*_0_8);
-            if vampDmg >= 1 then
-                begin
-                // was considering pulsing on attack, Tiy thinks it should be permanent while in play
-                //CurrentHedgehog^.Gear^.State:= CurrentHedgehog^.Gear^.State or gstVampiric;
-                inc(CurrentHedgehog^.Gear^.Health,vampDmg);
-                str(vampDmg, s);
-                s:= '+' + s;
-                AddCaption(s, CurrentHedgehog^.Team^.Clan^.Color, capgrpAmmoinfo);
-                RenderHealth(CurrentHedgehog^);
-                RecountTeamHealth(CurrentHedgehog^.Team);
-                i:= 0;
-                while i < vampDmg do
-                    begin
-                    vg:= AddVisualGear(hwRound(CurrentHedgehog^.Gear^.X), hwRound(CurrentHedgehog^.Gear^.Y), vgtStraightShot);
-                    if vg <> nil then
-                        with vg^ do
-                            begin
-                            Tint:= $FF0000FF;
-                            State:= ord(sprHealth)
-                            end;
-                    inc(i, 5);
-                    end;
-                end
-            end;
-        if ((GameFlags and gfKarma) <> 0) and
-           ((GameFlags and gfInvulnerable) = 0) and
-           (not CurrentHedgehog^.Gear^.Invulnerable) then
-           begin // this cannot just use Damage or it interrupts shotgun and gets you called stupid
-           inc(CurrentHedgehog^.Gear^.Karma, tmpDmg);
-           CurrentHedgehog^.Gear^.LastDamage := CurrentHedgehog;
-           spawnHealthTagForHH(CurrentHedgehog^.Gear, tmpDmg);
-           end;
-        uStats.HedgehogDamaged(Gear, AttackerHog, Damage, false);    
-        end;
-    end else if Gear^.Kind <> gtStructure then // not gtHedgehog nor gtStructure
-        begin
-        Gear^.Hedgehog:= AttackerHog;
-        end;
-    inc(Gear^.Damage, Damage);
-    
-    ScriptCall('onGearDamage', Gear^.UID, Damage);
-end;
-
-procedure spawnHealthTagForHH(HHGear: PGear; dmg: Longword);
-var tag: PVisualGear;
-begin
-tag:= AddVisualGear(hwRound(HHGear^.X), hwRound(HHGear^.Y), vgtHealthTag, dmg);
-if (tag <> nil) then
-    tag^.Hedgehog:= HHGear^.Hedgehog; // the tag needs the tag to determine the text color
-AllInactive:= false;
-HHGear^.Active:= true;
-end;
-    
-procedure HHHurt(Hedgehog: PHedgehog; Source: TDamageSource);
-begin
-if (Source = dsFall) or (Source = dsExplosion) then
-    case random(3) of
-        0: PlaySound(sndOoff1, Hedgehog^.Team^.voicepack);
-        1: PlaySound(sndOoff2, Hedgehog^.Team^.voicepack);
-        2: PlaySound(sndOoff3, Hedgehog^.Team^.voicepack);
-    end
-else if (Source = dsPoison) then
-    case random(2) of
-        0: PlaySound(sndPoisonCough, Hedgehog^.Team^.voicepack);
-        1: PlaySound(sndPoisonMoan, Hedgehog^.Team^.voicepack);
-    end
-else
-    case random(4) of
-        0: PlaySound(sndOw1, Hedgehog^.Team^.voicepack);
-        1: PlaySound(sndOw2, Hedgehog^.Team^.voicepack);
-        2: PlaySound(sndOw3, Hedgehog^.Team^.voicepack);
-        3: PlaySound(sndOw4, Hedgehog^.Team^.voicepack);
-    end
-end;
-
-procedure CheckHHDamage(Gear: PGear);
-var 
-    dmg: Longword;
-    i: LongInt;
-    particle: PVisualGear;
-begin
-    if _0_4 < Gear^.dY then
-        begin
-        dmg := ModifyDamage(1 + hwRound((hwAbs(Gear^.dY) - _0_4) * 70), Gear);
-        PlaySound(sndBump);
-        if dmg < 1 then exit;
-
-        for i:= min(12, (3 + dmg div 10)) downto 0 do
-            begin
-            particle := AddVisualGear(hwRound(Gear^.X) - 5 + Random(10), hwRound(Gear^.Y) + 12, vgtDust);
-            if particle <> nil then particle^.dX := particle^.dX + (Gear^.dX.QWordValue / 21474836480);
-            end;
-
-        if (Gear^.Invulnerable) then exit;
-
-        //if _0_6 < Gear^.dY then
-        //    PlaySound(sndOw4, Gear^.Hedgehog^.Team^.voicepack)
-        //else
-        //    PlaySound(sndOw1, Gear^.Hedgehog^.Team^.voicepack);
-
-        if Gear^.LastDamage <> nil then
-            ApplyDamage(Gear, Gear^.LastDamage, dmg, dsFall)
-            else
-            ApplyDamage(Gear, CurrentHedgehog, dmg, dsFall);
-    end
-end;
-
-
-procedure CalcRotationDirAngle(Gear: PGear);
-var 
-    dAngle: real;
-begin
-    dAngle := (Gear^.dX.QWordValue + Gear^.dY.QWordValue) / $80000000;
-    if not Gear^.dX.isNegative then
-        Gear^.DirAngle := Gear^.DirAngle + dAngle
-    else
-        Gear^.DirAngle := Gear^.DirAngle - dAngle;
-
-    if Gear^.DirAngle < 0 then Gear^.DirAngle := Gear^.DirAngle + 360
-    else if 360 < Gear^.DirAngle then Gear^.DirAngle := Gear^.DirAngle - 360
-end;
-
-function CheckGearDrowning(Gear: PGear): boolean;
-var 
-    skipSpeed, skipAngle, skipDecay: hwFloat;
-    i, maxDrops, X, Y: LongInt;
-    vdX, vdY: real;
-    particle: PVisualGear;
-    isSubmersible: boolean;
-begin
-    // probably needs tweaking. might need to be in a case statement based upon gear type
-    Y:= hwRound(Gear^.Y);
-    if cWaterLine < Y + Gear^.Radius then
-        begin
-        isSubmersible:= (Gear = CurrentHedgehog^.Gear) and (CurAmmoGear <> nil) and (CurAmmoGear^.AmmoType = amJetpack);
-        skipSpeed := _0_25;
-        skipAngle := _1_9;
-        skipDecay := _0_87;
-        X:= hwRound(Gear^.X);
-        vdX:= hwFloat2Float(Gear^.dX);
-        vdY:= hwFloat2Float(Gear^.dY);
-        // this could perhaps be a tiny bit higher.
-        if  (hwSqr(Gear^.dX) + hwSqr(Gear^.dY) > skipSpeed) and
-           (hwAbs(Gear^.dX) > skipAngle * hwAbs(Gear^.dY)) then
-            begin
-            Gear^.dY.isNegative := true;
-            Gear^.dY := Gear^.dY * skipDecay;
-            Gear^.dX := Gear^.dX * skipDecay;
-            CheckGearDrowning := false;
-            PlaySound(sndSkip)
-            end
-        else
-            begin
-            if not isSubmersible then
-                begin
-                CheckGearDrowning := true;
-                Gear^.State := gstDrowning;
-                Gear^.RenderTimer := false;
-                if (Gear^.Kind <> gtSniperRifleShot) and (Gear^.Kind <> gtShotgunShot) and 
-                   (Gear^.Kind <> gtDEagleShot) and (Gear^.Kind <> gtSineGunShot) then
-                    if Gear^.Kind = gtHedgehog then
-                        begin
-                        if Gear^.Hedgehog^.Effects[heResurrectable] then
-                            ResurrectHedgehog(Gear)
-                        else
-                            begin
-                            Gear^.doStep := @doStepDrowningGear;
-                            Gear^.State := Gear^.State and (not gstHHDriven);
-                            AddCaption(Format(GetEventString(eidDrowned), Gear^.Hedgehog^.Name), cWhiteColor, capgrpMessage);
-                            end
-                        end
-                    else Gear^.doStep := @doStepDrowningGear;
-                    if Gear^.Kind = gtFlake then exit // skip splashes 
-                end;
-            if ((not isSubmersible) and (Y < cWaterLine + 64 + Gear^.Radius)) or
-               (isSubmersible and (Y < cWaterLine + 2 + Gear^.Radius) and ((CurAmmoGear^.Pos = 0) and (CurAmmoGear^.dY < _0_01))) then
-                // don't play splash if they are already way past the surface
-                PlaySound(sndSplash)
-            end;
-
-        if ((cReducedQuality and rqPlainSplash) = 0) and 
-           (((not isSubmersible) and (Y < cWaterLine + 64 + Gear^.Radius)) or
-             (isSubmersible and (Y < cWaterLine + 2 + Gear^.Radius) and ((CurAmmoGear^.Pos = 0) and (CurAmmoGear^.dY < _0_01)))) then
-            begin
-            AddVisualGear(X, cWaterLine, vgtSplash);
-
-            maxDrops := (Gear^.Radius div 2) + round(vdX * Gear^.Radius * 2) + round(vdY * Gear^.Radius * 2);
-            for i:= max(maxDrops div 3, min(32, Random(maxDrops))) downto 0 do
-                begin
-                particle := AddVisualGear(X - 3 + Random(6), cWaterLine, vgtDroplet);
-                if particle <> nil then
-                    begin
-                    particle^.dX := particle^.dX - vdX / 10;
-                    particle^.dY := particle^.dY - vdY / 5;
-                    end
-                end
-            end;
-        if isSubmersible and (CurAmmoGear^.Pos = 0) then CurAmmoGear^.Pos := 1000
-        end
-    else
-        CheckGearDrowning := false;
-end;
-
-
-procedure ResurrectHedgehog(gear: PGear);
-var tempTeam : PTeam;
-begin
-    AttackBar:= 0;
-    gear^.dX := _0;
-    gear^.dY := _0;
-    gear^.Damage := 0;
-    gear^.Health := gear^.Hedgehog^.InitialHealth;
-    gear^.Hedgehog^.Effects[hePoisoned] := false;
-    if not CurrentHedgehog^.Effects[heResurrectable] then
-        with CurrentHedgehog^ do 
-            begin
-            inc(Team^.stats.AIKills);
-            FreeTexture(Team^.AIKillsTex);
-            Team^.AIKillsTex := RenderStringTex(inttostr(Team^.stats.AIKills), Team^.Clan^.Color, fnt16);
-            end;
-    tempTeam := gear^.Hedgehog^.Team;
-    DeleteCI(gear);
-    FindPlace(gear, false, 0, LAND_WIDTH, true); 
-    if gear <> nil then begin
-        RenderHealth(gear^.Hedgehog^);
-        ScriptCall('onGearResurrect', gear^.uid);
-        gear^.State := gstWait;
-    end;
-    RecountTeamHealth(tempTeam);
-end;
-
-function CountNonZeroz(x, y, r, c: LongInt): LongInt;
-var i: LongInt;
-    count: LongInt = 0;
-begin
-if (y and LAND_HEIGHT_MASK) = 0 then
-    for i:= max(x - r, 0) to min(x + r, LAND_WIDTH - 4) do
-        if Land[y, i] <> 0 then
-            begin
-            inc(count);
-            if count = c then exit(count)
-            end;
-CountNonZeroz:= count;
-end;
-
-procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt; skipProximity: boolean);
-var x: LongInt;
-    y, sy: LongInt;
-    ar: array[0..511] of TPoint;
-    ar2: array[0..1023] of TPoint;
-    cnt, cnt2: Longword;
-    delta: LongInt;
-    reallySkip, tryAgain: boolean;
-begin
-reallySkip:= false; // try not skipping proximity at first
-tryAgain:= true;
-while tryAgain do
-    begin
-    delta:= 250;
-    cnt2:= 0;
-    repeat
-        x:= Left + LongInt(GetRandom(Delta));
-        repeat
-            inc(x, Delta);
-            cnt:= 0;
-            y:= min(1024, topY) - 2 * Gear^.Radius;
-            while y < cWaterLine do
-                begin
-                repeat
-                    inc(y, 2);
-                until (y >= cWaterLine) or (CountNonZeroz(x, y, Gear^.Radius - 1, 1) = 0);
-
-                sy:= y;
-
-                repeat
-                    inc(y);
-                until (y >= cWaterLine) or (CountNonZeroz(x, y, Gear^.Radius - 1, 1) <> 0);
-
-                if (y - sy > Gear^.Radius * 2) and
-                   (((Gear^.Kind = gtExplosives)
-                       and (y < cWaterLine)
-                       and (reallySkip or (CheckGearsNear(x, y - Gear^.Radius, [gtFlame, gtHedgehog, gtMine, gtCase, gtExplosives], 60, 60) = nil))
-                       and (CountNonZeroz(x, y+1, Gear^.Radius - 1, Gear^.Radius+1) > Gear^.Radius))
-                   or
-                     ((Gear^.Kind <> gtExplosives)
-                       and (y < cWaterLine)
-                       and (reallySkip or (CheckGearsNear(x, y - Gear^.Radius, [gtFlame, gtHedgehog, gtMine, gtCase, gtExplosives], 110, 110) = nil)))) then
-                    begin
-                    ar[cnt].X:= x;
-                    if withFall then ar[cnt].Y:= sy + Gear^.Radius
-                                else ar[cnt].Y:= y - Gear^.Radius;
-                    inc(cnt)
-                    end;
-
-                inc(y, 45)
-                end;
-
-            if cnt > 0 then
-                with ar[GetRandom(cnt)] do
-                    begin
-                    ar2[cnt2].x:= x;
-                    ar2[cnt2].y:= y;
-                    inc(cnt2)
-                    end
-        until (x + Delta > Right);
-
-        dec(Delta, 60)
-    until (cnt2 > 0) or (Delta < 70);
-    if (cnt2 = 0) and skipProximity and (not reallySkip) then tryAgain:= true
-    else tryAgain:= false;
-    reallySkip:= true;
-    end;
-
-if cnt2 > 0 then
-    with ar2[GetRandom(cnt2)] do
-        begin
-        Gear^.X:= int2hwFloat(x);
-        Gear^.Y:= int2hwFloat(y);
-        AddFileLog('Assigned Gear coordinates (' + inttostr(x) + ',' + inttostr(y) + ')');
-        end
-    else
-    begin
-    OutError('Can''t find place for Gear', false);
-    if Gear^.Kind = gtHedgehog then Gear^.Hedgehog^.Effects[heResurrectable] := false;
-    DeleteGear(Gear);
-    Gear:= nil
-    end
-end;
-
-function CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear;
-var t: PGear;
-begin
-t:= GearsList;
-rX:= sqr(rX);
-rY:= sqr(rY);
-
-while t <> nil do
-    begin
-    if (t <> Gear) and (t^.Kind = Kind) then
-        if not((hwSqr(Gear^.X - t^.X) / rX + hwSqr(Gear^.Y - t^.Y) / rY) > _1) then
-        exit(t);
-    t:= t^.NextGear
-    end;
-
-CheckGearNear:= nil
-end;
-
-
-function CheckGearsNear(mX, mY: LongInt; Kind: TGearsType; rX, rY: LongInt): PGear;
-var t: PGear;
-begin
-t:= GearsList;
-rX:= sqr(rX);
-rY:= sqr(rY);
-while t <> nil do
-    begin
-    if t^.Kind in Kind then
-        if not (hwSqr(int2hwFloat(mX) - t^.X) / rX + hwSqr(int2hwFloat(mY) - t^.Y) / rY > _1) then
-            exit(t);
-    t:= t^.NextGear
-    end;
-CheckGearsNear:= nil
-end;
-end.
+(*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (c) 2004-2011 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * 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
+ * the Free Software Foundation; version 2 of the License
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *)
+
+{$INCLUDE "options.inc"}
+
+unit uGearsUtils;
+interface
+uses uTypes;
+
+procedure doMakeExplosion(X, Y, Radius: LongInt; AttackingHog: PHedgehog; Mask: Longword; const Tint: LongWord = $FFFFFFFF); 
+function  ModifyDamage(dmg: Longword; Gear: PGear): Longword;
+procedure ApplyDamage(Gear: PGear; AttackerHog: PHedgehog; Damage: Longword; Source: TDamageSource);
+procedure spawnHealthTagForHH(HHGear: PGear; dmg: Longword);
+procedure HHHurt(Hedgehog: PHedgehog; Source: TDamageSource);
+procedure CheckHHDamage(Gear: PGear);
+procedure CalcRotationDirAngle(Gear: PGear);
+procedure ResurrectHedgehog(gear: PGear);
+procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt; skipProximity: boolean = false);
+function  CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear;
+function  CheckGearsNear(mX, mY: LongInt; Kind: TGearsType; rX, rY: LongInt): PGear;
+function  CheckGearDrowning(Gear: PGear): boolean;
+
+var doStepHandlers: array[TGearType] of TGearStepProcedure;
+
+
+implementation
+uses uFloat, uSound, uCollisions, uUtils, uConsts, uVisualGears, uAIMisc,
+    uVariables, uLandGraphics, uScript, uStats, uCaptions, uTeams, uStore,
+    uLocale, uTextures, uRenderUtils, uRandom, SDLh, uDebug, uGears,
+    uGearsList;
+
+procedure doMakeExplosion(X, Y, Radius: LongInt; AttackingHog: PHedgehog; Mask: Longword; const Tint: LongWord);
+var Gear: PGear;
+    dmg, dmgRadius, dmgBase: LongInt;
+    fX, fY: hwFloat;
+    vg: PVisualGear;
+    i, cnt: LongInt;
+begin
+if Radius > 4 then AddFileLog('Explosion: at (' + inttostr(x) + ',' + inttostr(y) + ')');
+if Radius > 25 then KickFlakes(Radius, X, Y);
+
+if ((Mask and EXPLNoGfx) = 0) then
+    begin
+    vg:= nil;
+    if Radius > 50 then vg:= AddVisualGear(X, Y, vgtBigExplosion)
+    else if Radius > 10 then vg:= AddVisualGear(X, Y, vgtExplosion);
+    if vg <> nil then
+        vg^.Tint:= Tint;
+    end;
+if (Mask and EXPLAutoSound) <> 0 then PlaySound(sndExplosion);
+
+if (Mask and EXPLAllDamageInRadius) = 0 then
+    dmgRadius:= Radius shl 1
+else
+    dmgRadius:= Radius;
+dmgBase:= dmgRadius + cHHRadius div 2;
+fX:= int2hwFloat(X);
+fY:= int2hwFloat(Y);
+Gear:= GearsList;
+while Gear <> nil do
+    begin
+    dmg:= 0;
+    //dmg:= dmgRadius  + cHHRadius div 2 - hwRound(Distance(Gear^.X - int2hwFloat(X), Gear^.Y - int2hwFloat(Y)));
+    //if (dmg > 1) and
+    if (Gear^.State and gstNoDamage) = 0 then
+        begin
+        case Gear^.Kind of
+            gtHedgehog,
+                gtMine,
+                gtBall,
+                gtMelonPiece,
+                gtGrenade,
+                gtClusterBomb,
+            //    gtCluster, too game breaking I think
+                gtSMine,
+                gtCase,
+                gtTarget,
+                gtFlame,
+                gtExplosives,
+                gtStructure: begin
+// Run the calcs only once we know we have a type that will need damage
+                        if hwRound(hwAbs(Gear^.X-fX)+hwAbs(Gear^.Y-fY)) < dmgBase then
+                            dmg:= dmgBase - max(hwRound(Distance(Gear^.X - fX, Gear^.Y - fY)),Gear^.Radius);
+                        if dmg > 1 then
+                            begin
+                            dmg:= ModifyDamage(min(dmg div 2, Radius), Gear);
+                            //AddFileLog('Damage: ' + inttostr(dmg));
+                            if (Mask and EXPLNoDamage) = 0 then
+                                begin
+                                if not Gear^.Invulnerable then
+                                    ApplyDamage(Gear, AttackingHog, dmg, dsExplosion)
+                                else
+                                    Gear^.State:= Gear^.State or gstWinner;
+                                end;
+                            if ((Mask and EXPLDoNotTouchAny) = 0) and (((Mask and EXPLDoNotTouchHH) = 0) or (Gear^.Kind <> gtHedgehog)) then
+                                begin
+                                DeleteCI(Gear);
+                                Gear^.dX:= Gear^.dX + SignAs(_0_005 * dmg + cHHKick, Gear^.X - fX)/(Gear^.Density/_3);
+                                Gear^.dY:= Gear^.dY + SignAs(_0_005 * dmg + cHHKick, Gear^.Y - fY)/(Gear^.Density/_3);
+
+                                Gear^.State:= (Gear^.State or gstMoving) and (not gstLoser);
+                                if not Gear^.Invulnerable then
+                                    Gear^.State:= (Gear^.State or gstMoving) and (not gstWinner);
+                                Gear^.Active:= true;
+                                if Gear^.Kind <> gtFlame then FollowGear:= Gear
+                                end;
+                            if ((Mask and EXPLPoisoned) <> 0) and (Gear^.Kind = gtHedgehog) and (not Gear^.Invulnerable) then
+                                Gear^.Hedgehog^.Effects[hePoisoned] := true;
+                            end;
+
+                        end;
+                gtGrave: begin
+// Run the calcs only once we know we have a type that will need damage
+                        if hwRound(hwAbs(Gear^.X-fX)+hwAbs(Gear^.Y-fY)) < dmgBase then
+                            dmg:= dmgBase - hwRound(Distance(Gear^.X - fX, Gear^.Y - fY));
+                        if dmg > 1 then
+                            begin
+                            dmg:= ModifyDamage(min(dmg div 2, Radius), Gear);
+                            Gear^.dY:= - _0_004 * dmg;
+                            Gear^.Active:= true
+                            end
+                        end;
+            end;
+        end;
+    Gear:= Gear^.NextGear
+    end;
+
+if (Mask and EXPLDontDraw) = 0 then
+    if (GameFlags and gfSolidLand) = 0 then
+        begin
+        cnt:= DrawExplosion(X, Y, Radius) div 1608; // approx 2 16x16 circles to erase per chunk
+        if (cnt > 0) and (SpritesData[sprChunk].Texture <> nil) then
+            for i:= 0 to cnt do
+                AddVisualGear(X, Y, vgtChunk)
+        end;
+
+uAIMisc.AwareOfExplosion(0, 0, 0)
+end;
+
+function ModifyDamage(dmg: Longword; Gear: PGear): Longword;
+var i: hwFloat;
+begin
+(* Invulnerability cannot be placed in here due to still needing kicks
+   Not without a new damage machine.
+   King check should be in here instead of ApplyDamage since Tiy wants them kicked less
+*)
+i:= _1;
+if (CurrentHedgehog <> nil) and CurrentHedgehog^.King then
+    i:= _1_5;
+if (Gear^.Hedgehog <> nil) and (Gear^.Hedgehog^.King) then
+    ModifyDamage:= hwRound(_0_01 * cDamageModifier * dmg * i * cDamagePercent * _0_5)
+else
+    ModifyDamage:= hwRound(_0_01 * cDamageModifier * dmg * i * cDamagePercent)
+end;
+
+procedure ApplyDamage(Gear: PGear; AttackerHog: PHedgehog; Damage: Longword; Source: TDamageSource);
+var s: shortstring;
+    vampDmg, tmpDmg, i: Longword;
+    vg: PVisualGear;
+begin
+    if Damage = 0 then
+        exit; // nothing to apply
+
+    if (Gear^.Kind = gtHedgehog) then
+        begin
+        Gear^.LastDamage := AttackerHog;
+
+        Gear^.Hedgehog^.Team^.Clan^.Flawless:= false;
+        HHHurt(Gear^.Hedgehog, Source);
+        AddDamageTag(hwRound(Gear^.X), hwRound(Gear^.Y), Damage, Gear^.Hedgehog^.Team^.Clan^.Color);
+        tmpDmg:= min(Damage, max(0,Gear^.Health-Gear^.Damage));
+        if (Gear <> CurrentHedgehog^.Gear) and (CurrentHedgehog^.Gear <> nil) and (tmpDmg >= 1) then
+            begin
+            if cVampiric then
+                begin
+                vampDmg:= hwRound(int2hwFloat(tmpDmg)*_0_8);
+                if vampDmg >= 1 then
+                    begin
+                    // was considering pulsing on attack, Tiy thinks it should be permanent while in play
+                    //CurrentHedgehog^.Gear^.State:= CurrentHedgehog^.Gear^.State or gstVampiric;
+                    inc(CurrentHedgehog^.Gear^.Health,vampDmg);
+                    str(vampDmg, s);
+                    s:= '+' + s;
+                    AddCaption(s, CurrentHedgehog^.Team^.Clan^.Color, capgrpAmmoinfo);
+                    RenderHealth(CurrentHedgehog^);
+                    RecountTeamHealth(CurrentHedgehog^.Team);
+                    i:= 0;
+                    while i < vampDmg do
+                        begin
+                        vg:= AddVisualGear(hwRound(CurrentHedgehog^.Gear^.X), hwRound(CurrentHedgehog^.Gear^.Y), vgtStraightShot);
+                        if vg <> nil then
+                            with vg^ do
+                                begin
+                                Tint:= $FF0000FF;
+                                State:= ord(sprHealth)
+                                end;
+                        inc(i, 5);
+                        end;
+                    end
+                end;
+        if ((GameFlags and gfKarma) <> 0) and 
+        ((GameFlags and gfInvulnerable) = 0)
+        and (not CurrentHedgehog^.Gear^.Invulnerable) then
+            begin // this cannot just use Damage or it interrupts shotgun and gets you called stupid
+            inc(CurrentHedgehog^.Gear^.Karma, tmpDmg);
+            CurrentHedgehog^.Gear^.LastDamage := CurrentHedgehog;
+            spawnHealthTagForHH(CurrentHedgehog^.Gear, tmpDmg);
+            end;
+        uStats.HedgehogDamaged(Gear, AttackerHog, Damage, false);    
+        end;
+    end
+    else if Gear^.Kind <> gtStructure then // not gtHedgehog nor gtStructure
+        begin
+        Gear^.Hedgehog:= AttackerHog;
+        end;
+    inc(Gear^.Damage, Damage);
+    
+    ScriptCall('onGearDamage', Gear^.UID, Damage);
+end;
+
+procedure spawnHealthTagForHH(HHGear: PGear; dmg: Longword);
+var tag: PVisualGear;
+begin
+tag:= AddVisualGear(hwRound(HHGear^.X), hwRound(HHGear^.Y), vgtHealthTag, dmg);
+if (tag <> nil) then
+    tag^.Hedgehog:= HHGear^.Hedgehog; // the tag needs the tag to determine the text color
+AllInactive:= false;
+HHGear^.Active:= true;
+end;
+    
+procedure HHHurt(Hedgehog: PHedgehog; Source: TDamageSource);
+begin
+if (Source = dsFall) or (Source = dsExplosion) then
+    case random(3) of
+        0: PlaySound(sndOoff1, Hedgehog^.Team^.voicepack);
+        1: PlaySound(sndOoff2, Hedgehog^.Team^.voicepack);
+        2: PlaySound(sndOoff3, Hedgehog^.Team^.voicepack);
+    end
+else if (Source = dsPoison) then
+    case random(2) of
+        0: PlaySound(sndPoisonCough, Hedgehog^.Team^.voicepack);
+        1: PlaySound(sndPoisonMoan, Hedgehog^.Team^.voicepack);
+    end
+else
+    case random(4) of
+        0: PlaySound(sndOw1, Hedgehog^.Team^.voicepack);
+        1: PlaySound(sndOw2, Hedgehog^.Team^.voicepack);
+        2: PlaySound(sndOw3, Hedgehog^.Team^.voicepack);
+        3: PlaySound(sndOw4, Hedgehog^.Team^.voicepack);
+    end
+end;
+
+procedure CheckHHDamage(Gear: PGear);
+var 
+    dmg: Longword;
+    i: LongInt;
+    particle: PVisualGear;
+begin
+    if _0_4 < Gear^.dY then
+        begin
+        dmg := ModifyDamage(1 + hwRound((hwAbs(Gear^.dY) - _0_4) * 70), Gear);
+        PlaySound(sndBump);
+        if dmg < 1 then
+            exit;
+
+        for i:= min(12, (3 + dmg div 10)) downto 0 do
+            begin
+            particle := AddVisualGear(hwRound(Gear^.X) - 5 + Random(10), hwRound(Gear^.Y) + 12, vgtDust);
+            if particle <> nil then
+                particle^.dX := particle^.dX + (Gear^.dX.QWordValue / 21474836480);
+            end;
+
+        if (Gear^.Invulnerable) then
+            exit;
+
+        //if _0_6 < Gear^.dY then
+        //    PlaySound(sndOw4, Gear^.Hedgehog^.Team^.voicepack)
+        //else
+        //    PlaySound(sndOw1, Gear^.Hedgehog^.Team^.voicepack);
+
+        if Gear^.LastDamage <> nil then
+            ApplyDamage(Gear, Gear^.LastDamage, dmg, dsFall)
+        else
+            ApplyDamage(Gear, CurrentHedgehog, dmg, dsFall);
+    end
+end;
+
+
+procedure CalcRotationDirAngle(Gear: PGear);
+var 
+    dAngle: real;
+begin
+    dAngle := (Gear^.dX.QWordValue + Gear^.dY.QWordValue) / $80000000;
+    if not Gear^.dX.isNegative then
+        Gear^.DirAngle := Gear^.DirAngle + dAngle
+    else
+        Gear^.DirAngle := Gear^.DirAngle - dAngle;
+
+    if Gear^.DirAngle < 0 then
+        Gear^.DirAngle := Gear^.DirAngle + 360
+    else if 360 < Gear^.DirAngle then
+        Gear^.DirAngle := Gear^.DirAngle - 360
+end;
+
+function CheckGearDrowning(Gear: PGear): boolean;
+var 
+    skipSpeed, skipAngle, skipDecay: hwFloat;
+    i, maxDrops, X, Y: LongInt;
+    vdX, vdY: real;
+    particle: PVisualGear;
+    isSubmersible: boolean;
+begin
+    // probably needs tweaking. might need to be in a case statement based upon gear type
+    Y:= hwRound(Gear^.Y);
+    if cWaterLine < Y + Gear^.Radius then
+        begin
+        isSubmersible:= (Gear = CurrentHedgehog^.Gear) and (CurAmmoGear <> nil) and (CurAmmoGear^.AmmoType = amJetpack);
+        skipSpeed := _0_25;
+        skipAngle := _1_9;
+        skipDecay := _0_87;
+        X:= hwRound(Gear^.X);
+        vdX:= hwFloat2Float(Gear^.dX);
+        vdY:= hwFloat2Float(Gear^.dY);
+        // this could perhaps be a tiny bit higher.
+        if  (hwSqr(Gear^.dX) + hwSqr(Gear^.dY) > skipSpeed)
+        and (hwAbs(Gear^.dX) > skipAngle * hwAbs(Gear^.dY)) then
+            begin
+            Gear^.dY.isNegative := true;
+            Gear^.dY := Gear^.dY * skipDecay;
+            Gear^.dX := Gear^.dX * skipDecay;
+            CheckGearDrowning := false;
+            PlaySound(sndSkip)
+            end
+        else
+            begin
+            if not isSubmersible then
+                begin
+                CheckGearDrowning := true;
+                Gear^.State := gstDrowning;
+                Gear^.RenderTimer := false;
+                if (Gear^.Kind <> gtSniperRifleShot) and (Gear^.Kind <> gtShotgunShot)
+                and (Gear^.Kind <> gtDEagleShot) and (Gear^.Kind <> gtSineGunShot) then
+                    if Gear^.Kind = gtHedgehog then
+                        begin
+                        if Gear^.Hedgehog^.Effects[heResurrectable] then
+                            ResurrectHedgehog(Gear)
+                        else
+                            begin
+                            Gear^.doStep := @doStepDrowningGear;
+                            Gear^.State := Gear^.State and (not gstHHDriven);
+                            AddCaption(Format(GetEventString(eidDrowned), Gear^.Hedgehog^.Name), cWhiteColor, capgrpMessage);
+                            end
+                        end
+                    else
+                        Gear^.doStep := @doStepDrowningGear;
+                        if Gear^.Kind = gtFlake then
+                            exit // skip splashes 
+                end;
+            if ((not isSubmersible) and (Y < cWaterLine + 64 + Gear^.Radius))
+            or (isSubmersible and (Y < cWaterLine + 2 + Gear^.Radius) and ((CurAmmoGear^.Pos = 0)
+            and (CurAmmoGear^.dY < _0_01))) then
+                // don't play splash if they are already way past the surface
+                PlaySound(sndSplash)
+            end;
+
+        if ((cReducedQuality and rqPlainSplash) = 0)
+        and (((not isSubmersible) and (Y < cWaterLine + 64 + Gear^.Radius))
+        or (isSubmersible and (Y < cWaterLine + 2 + Gear^.Radius) and ((CurAmmoGear^.Pos = 0)
+        and (CurAmmoGear^.dY < _0_01)))) then
+            begin
+            AddVisualGear(X, cWaterLine, vgtSplash);
+
+            maxDrops := (Gear^.Radius div 2) + round(vdX * Gear^.Radius * 2) + round(vdY * Gear^.Radius * 2);
+            for i:= max(maxDrops div 3, min(32, Random(maxDrops))) downto 0 do
+                begin
+                particle := AddVisualGear(X - 3 + Random(6), cWaterLine, vgtDroplet);
+                if particle <> nil then
+                    begin
+                    particle^.dX := particle^.dX - vdX / 10;
+                    particle^.dY := particle^.dY - vdY / 5;
+                    end
+                end
+            end;
+        if isSubmersible and (CurAmmoGear^.Pos = 0) then
+            CurAmmoGear^.Pos := 1000
+        end
+    else
+        CheckGearDrowning := false;
+end;
+
+
+procedure ResurrectHedgehog(gear: PGear);
+var tempTeam : PTeam;
+begin
+    AttackBar:= 0;
+    gear^.dX := _0;
+    gear^.dY := _0;
+    gear^.Damage := 0;
+    gear^.Health := gear^.Hedgehog^.InitialHealth;
+    gear^.Hedgehog^.Effects[hePoisoned] := false;
+    if not CurrentHedgehog^.Effects[heResurrectable] then
+        with CurrentHedgehog^ do 
+            begin
+            inc(Team^.stats.AIKills);
+            FreeTexture(Team^.AIKillsTex);
+            Team^.AIKillsTex := RenderStringTex(inttostr(Team^.stats.AIKills), Team^.Clan^.Color, fnt16);
+            end;
+    tempTeam := gear^.Hedgehog^.Team;
+    DeleteCI(gear);
+    FindPlace(gear, false, 0, LAND_WIDTH, true); 
+    if gear <> nil then
+        begin
+        RenderHealth(gear^.Hedgehog^);
+        ScriptCall('onGearResurrect', gear^.uid);
+        gear^.State := gstWait;
+    end;
+    RecountTeamHealth(tempTeam);
+end;
+
+function CountNonZeroz(x, y, r, c: LongInt): LongInt;
+var i: LongInt;
+    count: LongInt = 0;
+begin
+if (y and LAND_HEIGHT_MASK) = 0 then
+    for i:= max(x - r, 0) to min(x + r, LAND_WIDTH - 4) do
+        if Land[y, i] <> 0 then
+            begin
+            inc(count);
+            if count = c then
+                exit(count)
+            end;
+CountNonZeroz:= count;
+end;
+
+procedure FindPlace(var Gear: PGear; withFall: boolean; Left, Right: LongInt; skipProximity: boolean);
+var x: LongInt;
+    y, sy: LongInt;
+    ar: array[0..511] of TPoint;
+    ar2: array[0..1023] of TPoint;
+    cnt, cnt2: Longword;
+    delta: LongInt;
+    reallySkip, tryAgain: boolean;
+begin
+reallySkip:= false; // try not skipping proximity at first
+tryAgain:= true;
+while tryAgain do
+    begin
+    delta:= 250;
+    cnt2:= 0;
+    repeat
+        x:= Left + LongInt(GetRandom(Delta));
+        repeat
+            inc(x, Delta);
+            cnt:= 0;
+            y:= min(1024, topY) - 2 * Gear^.Radius;
+            while y < cWaterLine do
+                begin
+                repeat
+                    inc(y, 2);
+                until (y >= cWaterLine) or (CountNonZeroz(x, y, Gear^.Radius - 1, 1) = 0);
+
+                sy:= y;
+
+                repeat
+                    inc(y);
+                until (y >= cWaterLine) or (CountNonZeroz(x, y, Gear^.Radius - 1, 1) <> 0);
+
+                if (y - sy > Gear^.Radius * 2)
+                    and (((Gear^.Kind = gtExplosives)
+                    and (y < cWaterLine)
+                    and (reallySkip or (CheckGearsNear(x, y - Gear^.Radius, [gtFlame, gtHedgehog, gtMine, gtCase, gtExplosives], 60, 60) = nil))
+                    and (CountNonZeroz(x, y+1, Gear^.Radius - 1, Gear^.Radius+1) > Gear^.Radius))
+                or
+                    ((Gear^.Kind <> gtExplosives)
+                    and (y < cWaterLine)
+                    and (reallySkip or (CheckGearsNear(x, y - Gear^.Radius, [gtFlame, gtHedgehog, gtMine, gtCase, gtExplosives], 110, 110) = nil)))) then
+                 
+                          begin
+                    ar[cnt].X:= x;
+                    if withFall then
+                        ar[cnt].Y:= sy + Gear^.Radius
+                    else
+                        ar[cnt].Y:= y - Gear^.Radius;
+                    inc(cnt)
+                    end;
+
+                inc(y, 45)
+                end;
+
+            if cnt > 0 then
+                with ar[GetRandom(cnt)] do
+                    begin
+                    ar2[cnt2].x:= x;
+                    ar2[cnt2].y:= y;
+                    inc(cnt2)
+                    end
+        until (x + Delta > Right);
+
+        dec(Delta, 60)
+    until (cnt2 > 0) or (Delta < 70);
+    if (cnt2 = 0) and skipProximity and (not reallySkip) then
+        tryAgain:= true
+    else tryAgain:= false;
+    reallySkip:= true;
+    end;
+
+if cnt2 > 0 then
+    with ar2[GetRandom(cnt2)] do
+        begin
+        Gear^.X:= int2hwFloat(x);
+        Gear^.Y:= int2hwFloat(y);
+        AddFileLog('Assigned Gear coordinates (' + inttostr(x) + ',' + inttostr(y) + ')');
+        end
+    else
+    begin
+    OutError('Can''t find place for Gear', false);
+    if Gear^.Kind = gtHedgehog then
+        Gear^.Hedgehog^.Effects[heResurrectable] := false;
+    DeleteGear(Gear);
+    Gear:= nil
+    end
+end;
+
+function CheckGearNear(Gear: PGear; Kind: TGearType; rX, rY: LongInt): PGear;
+var t: PGear;
+begin
+t:= GearsList;
+rX:= sqr(rX);
+rY:= sqr(rY);
+
+while t <> nil do
+    begin
+    if (t <> Gear) and (t^.Kind = Kind) then
+        if not((hwSqr(Gear^.X - t^.X) / rX + hwSqr(Gear^.Y - t^.Y) / rY) > _1) then
+        exit(t);
+    t:= t^.NextGear
+    end;
+
+CheckGearNear:= nil
+end;
+
+
+function CheckGearsNear(mX, mY: LongInt; Kind: TGearsType; rX, rY: LongInt): PGear;
+var t: PGear;
+begin
+t:= GearsList;
+rX:= sqr(rX);
+rY:= sqr(rY);
+while t <> nil do
+    begin
+    if t^.Kind in Kind then
+        if not (hwSqr(int2hwFloat(mX) - t^.X) / rX + hwSqr(int2hwFloat(mY) - t^.Y) / rY > _1) then
+            exit(t);
+    t:= t^.NextGear
+    end;
+CheckGearsNear:= nil
+end;
+end.
--- a/hedgewars/uIO.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uIO.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -71,14 +71,15 @@
 command^.str:= str;
 if command^.cmd <> 'F' then dec(command^.len, 2); // cut timestamp
 if headcmd = nil then
-   begin
-   headcmd:= command;
-   lastcmd:= command
-   end else
-   begin
-   lastcmd^.Next:= command;
-   lastcmd:= command
-   end;
+    begin
+    headcmd:= command;
+    lastcmd:= command
+    end
+else
+    begin
+    lastcmd^.Next:= command;
+    lastcmd:= command
+    end;
 AddCmd:= command;
 end;
 
@@ -88,7 +89,8 @@
 TryDo(headcmd <> nil, 'Engine bug: headcmd = nil', true);
 tmp:= headcmd;
 headcmd:= headcmd^.Next;
-if headcmd = nil then lastcmd:= nil;
+if headcmd = nil then
+    lastcmd:= nil;
 dispose(tmp)
 end;
 
@@ -145,7 +147,7 @@
     s: shortstring;
 begin
 if IPCSock = nil then
-   exit;
+    exit;
 
 fds^.numsockets:= 0;
 SDLNet_AddSocket(fds, IPCSock);
@@ -162,7 +164,9 @@
             ParseIPCCommand(copy(ss, 2, byte(ss[1])));
             Delete(ss, 1, Succ(byte(ss[1])))
             end
-        end else OutError('IPC connection lost', true)
+        end
+    else
+        OutError('IPC connection lost', true)
     end;
 end;
 
@@ -215,7 +219,9 @@
 if IPCSock <> nil then
     begin
     SendEmptyPacketTicks:= 0;
-    if s[0]>#251 then s[0]:= #251;
+    if s[0]>#251 then
+        s[0]:= #251;
+        
     SDLNet_Write16(GameTicks, @s[Succ(byte(s[0]))]);
     AddFileLog('[IPC out] '+ s[1]);
     inc(s[0], 2);
@@ -226,9 +232,9 @@
 procedure SendIPCRaw(p: pointer; len: Longword);
 begin
 if IPCSock <> nil then
-   begin
-   SDLNet_TCP_Send(IPCSock, p, len)
-   end
+    begin
+    SDLNet_TCP_Send(IPCSock, p, len)
+    end
 end;
 
 procedure SendIPCXY(cmd: char; X, Y: SmallInt);
@@ -245,8 +251,8 @@
 begin
 isPonged:= false;
 repeat
-   IPCCheckSock;
-   SDL_Delay(1)
+    IPCCheckSock;
+    SDL_Delay(1)
 until isPonged
 end;
 
@@ -305,28 +311,28 @@
         'c': begin
             s:= copy(headcmd^.str, 2, Pred(headcmd^.len));
             ParseCommand('gencmd ' + s, true);
-            end;
+             end;
         's': begin
             s:= copy(headcmd^.str, 2, Pred(headcmd^.len));
             ParseCommand('chatmsg ' + s, true);
             WriteLnToConsole(s)
-            end;
+             end;
         'b': begin
             s:= copy(headcmd^.str, 2, Pred(headcmd^.len));
             ParseCommand('chatmsg ' + #4 + s, true);
             WriteLnToConsole(s)
-            end;
+             end;
 // TODO: deprecate 'F'
         'F': ParseCommand('teamgone ' + copy(headcmd^.str, 2, Pred(headcmd^.len)), true);
         'N': begin
             tmpflag:= false;
             AddFileLog('got cmd "N": time '+IntToStr(hiTicks shl 16 + headcmd^.loTime))
-            end;
+             end;
         'p': begin
             x16:= SDLNet_Read16(@(headcmd^.X));
             y16:= SDLNet_Read16(@(headcmd^.Y));
             doPut(x16, y16, false)
-            end;
+             end;
         'P': begin
             // these are equations solved for CursorPoint
             // SDLNet_Read16(@(headcmd^.X)) == CursorPoint.X - WorldDx;
@@ -336,7 +342,7 @@
                CursorPoint.X:= SmallInt(SDLNet_Read16(@(headcmd^.X))) + WorldDx;
                CursorPoint.Y:= cScreenHeight - SmallInt(SDLNet_Read16(@(headcmd^.Y))) - WorldDy
                end
-            end;
+             end;
         'w': ParseCommand('setweap ' + headcmd^.str[2], true);
         't': ParseCommand('taunt ' + headcmd^.str[2], true);
         'h': ParseCommand('hogsay ' + copy(headcmd^.str, 2, Pred(headcmd^.len)), true);
@@ -367,7 +373,8 @@
 
 procedure doPut(putX, putY: LongInt; fromAI: boolean);
 begin
-if CheckNoTeamOrHH or isPaused then exit;
+if CheckNoTeamOrHH or isPaused then
+    exit;
 bShowFinger:= false;
 if not CurrentTeam^.ExtDriven and bShowAmmoMenu then
     begin
@@ -386,7 +393,8 @@
                 begin
                 TargetPoint.X:= putX;
                 TargetPoint.Y:= putY
-                end else
+                end
+            else
                 begin
                 TargetPoint.X:= CursorPoint.X - WorldDx;
                 TargetPoint.Y:= cScreenHeight - CursorPoint.Y - WorldDy;
--- a/hedgewars/uKeys.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uKeys.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -109,8 +109,14 @@
     begin
     for i:= 0 to Pred(ControllerNumAxes[j]) do
         begin
-        if ControllerAxes[j][i] > 20000 then tkbdn[k + 0]:= 1 else tkbdn[k + 0]:= 0;
-        if ControllerAxes[j][i] < -20000 then tkbdn[k + 1]:= 1 else tkbdn[k + 1]:= 0;
+        if ControllerAxes[j][i] > 20000 then
+            tkbdn[k + 0]:= 1
+        else
+            tkbdn[k + 0]:= 0;
+        if ControllerAxes[j][i] < -20000 then
+            tkbdn[k + 1]:= 1
+        else
+            tkbdn[k + 1]:= 0;
         inc(k, 2);
         end;
     for i:= 0 to Pred(ControllerNumHats[j]) do
@@ -132,9 +138,9 @@
 // ctrl/cmd + q to close engine and frontend
 {$IFDEF DARWIN}
     if ((tkbdn[KeyNameToCode('left_meta')] = 1) or (tkbdn[KeyNameToCode('right_meta')] = 1)) then
-{$ELSE}
+        {$ELSE}
     if ((tkbdn[KeyNameToCode('left_ctrl')] = 1) or (tkbdn[KeyNameToCode('right_ctrl')] = 1)) then
-{$ENDIF}
+        {$ENDIF}
     begin
         if tkbdn[KeyNameToCode('q')] = 1 then ParseCommand ('halt', true)
     end;
@@ -145,19 +151,19 @@
     begin
     if (i > 3) and (tkbdn[i] <> 0) and not ((CurrentBinds[i] = 'put') or (CurrentBinds[i] = 'ammomenu') or (CurrentBinds[i] = '+cur_u') or (CurrentBinds[i] = '+cur_d') or (CurrentBinds[i] = '+cur_l') or (CurrentBinds[i] = '+cur_r')) then hideAmmoMenu:= true;
     if (tkbd[i] = 0) and (tkbdn[i] <> 0) then
-         begin
-         ParseCommand(CurrentBinds[i], Trusted);
-         if (CurrentTeam <> nil) and (not CurrentTeam^.ExtDriven) and (ReadyTimeLeft > 1) then ParseCommand('gencmd R', true)
-         end
-    else if (CurrentBinds[i][1] = '+')
-            and (tkbdn[i] = 0)
-            and (tkbd[i] <> 0) then
-            begin
-            s:= CurrentBinds[i];
-            s[1]:= '-';
-            ParseCommand(s, Trusted);
-            if (CurrentTeam <> nil) and (not CurrentTeam^.ExtDriven) and (ReadyTimeLeft > 1) then ParseCommand('gencmd R', true)
-            end;
+        begin
+        ParseCommand(CurrentBinds[i], Trusted);
+        if (CurrentTeam <> nil) and (not CurrentTeam^.ExtDriven) and (ReadyTimeLeft > 1) then
+            ParseCommand('gencmd R', true)
+        end
+    else if (CurrentBinds[i][1] = '+') and (tkbdn[i] = 0) and (tkbd[i] <> 0) then
+        begin
+        s:= CurrentBinds[i];
+        s[1]:= '-';
+        ParseCommand(s, Trusted);
+        if (CurrentTeam <> nil) and (not CurrentTeam^.ExtDriven) and (ReadyTimeLeft > 1) then
+            ParseCommand('gencmd R', true)
+        end;
     tkbd[i]:= tkbdn[i]
     end
 end;
@@ -205,8 +211,14 @@
     begin
     for i:= 0 to Pred(ControllerNumAxes[j]) do
         begin
-        if ControllerAxes[j][i] > 20000 then tkbdn[k + 0]:= 1 else tkbdn[k + 0]:= 0;
-        if ControllerAxes[j][i] < -20000 then tkbdn[k + 1]:= 1 else tkbdn[k + 1]:= 0;
+        if ControllerAxes[j][i] > 20000 then
+            tkbdn[k + 0]:= 1
+        else
+            tkbdn[k + 0]:= 0;
+        if ControllerAxes[j][i] < -20000 then
+            tkbdn[k + 1]:= 1
+        else
+            tkbdn[k + 1]:= 0;
         inc(k, 2);
         end;
     for i:= 0 to Pred(ControllerNumHats[j]) do
@@ -248,7 +260,8 @@
     else 
         begin
         for t:= 1 to Length(s) do
-            if s[t] = ' ' then s[t]:= '_';
+            if s[t] = ' ' then
+                s[t]:= '_';
         KeyNames[i]:= s
         end;
     end;
@@ -404,7 +417,9 @@
 
 SDL_InitSubSystem(SDL_INIT_JOYSTICK);
 ControllerNumControllers:= SDL_NumJoysticks();
-if ControllerNumControllers > 6 then ControllerNumControllers:= 6;
+
+if ControllerNumControllers > 6 then
+    ControllerNumControllers:= 6;
 
 WriteLnToConsole('Number of game controllers: ' + IntToStr(ControllerNumControllers));
 
@@ -428,10 +443,15 @@
             WriteLnToConsole('* Number of buttons: ' + IntToStr(ControllerNumButtons[j]));
             ControllerEnabled:= 1;
 
-            if ControllerNumAxes[j] > 20 then ControllerNumAxes[j]:= 20;
+            if ControllerNumAxes[j] > 20 then
+                ControllerNumAxes[j]:= 20;
             //if ControllerNumBalls[j] > 20 then ControllerNumBalls[j]:= 20;
-            if ControllerNumHats[j] > 20 then ControllerNumHats[j]:= 20;
-            if ControllerNumButtons[j] > 20 then ControllerNumButtons[j]:= 20;
+            
+            if ControllerNumHats[j] > 20 then
+                ControllerNumHats[j]:= 20;
+                
+            if ControllerNumButtons[j] > 20 then
+                ControllerNumButtons[j]:= 20;
 
             // reset all buttons/axes
             for i:= 0 to pred(ControllerNumAxes[j]) do
@@ -474,8 +494,10 @@
 
 procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean);
 begin
-    if pressed then ControllerButtons[joy][button]:= 1
-    else ControllerButtons[joy][button]:= 0;
+    if pressed then
+        ControllerButtons[joy][button]:= 1
+    else
+        ControllerButtons[joy][button]:= 0;
 end;
 
 procedure initModule;
--- a/hedgewars/uLand.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uLand.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -67,9 +67,11 @@
         repeat
             while (yd > 0) and (Land[yd, x] =  0) do dec(yd);
 
-            if (yd < 0) then yd:= 0;
+            if (yd < 0) then
+                yd:= 0;
 
-            while (yd < LAND_HEIGHT) and (Land[yd, x] <> 0) do inc(yd);
+            while (yd < LAND_HEIGHT) and (Land[yd, x] <> 0) do
+                inc(yd);
             dec(yd);
             yu:= yd;
 
@@ -77,7 +79,7 @@
             while (yu < yd ) and (Land[yu, x] =  0) do inc(yu);
 
             if (yd < LAND_HEIGHT - 1) and ((yd - yu) >= 16) then
-            begin
+                begin
                 rr.x:= x;
                 rr.y:= yd - 15;
                 r.x:= x mod tmpsurf^.w;
@@ -85,9 +87,9 @@
                 r.w:= 1;
                 r.h:= 16;
                 SDL_UpperBlit(tmpsurf, @r, Surface, @rr);
-            end;
+                end;
             if (yu > 0) then
-            begin
+                begin
                 rr.x:= x;
                 rr.y:= yu;
                 r.x:= x mod tmpsurf^.w;
@@ -95,7 +97,7 @@
                 r.w:= 1;
                 r.h:= Min(16, yd - yu + 1);
                 SDL_UpperBlit(tmpsurf, @r, Surface, @rr);
-            end;
+                end;
             yd:= yu - 1;
         until yd < 0;
     end;
@@ -106,25 +108,25 @@
 var i: LongInt;
 begin
 with Template do
-     begin
-     pa.Count:= BasePointsCount;
-     for i:= 0 to pred(pa.Count) do
-         begin
-         pa.ar[i].x:= BasePoints^[i].x + LongInt(GetRandom(BasePoints^[i].w));
-         if pa.ar[i].x <> NTPX then
-            pa.ar[i].x:= pa.ar[i].x + ((LAND_WIDTH - Template.TemplateWidth) div 2);
-         pa.ar[i].y:= BasePoints^[i].y + LongInt(GetRandom(BasePoints^[i].h)) + LAND_HEIGHT - LongInt(Template.TemplateHeight)
-         end;
+    begin
+    pa.Count:= BasePointsCount;
+    for i:= 0 to pred(pa.Count) do
+        begin
+        pa.ar[i].x:= BasePoints^[i].x + LongInt(GetRandom(BasePoints^[i].w));
+        if pa.ar[i].x <> NTPX then
+           pa.ar[i].x:= pa.ar[i].x + ((LAND_WIDTH - Template.TemplateWidth) div 2);
+        pa.ar[i].y:= BasePoints^[i].y + LongInt(GetRandom(BasePoints^[i].h)) + LAND_HEIGHT - LongInt(Template.TemplateHeight)
+        end;
 
-     if canMirror then
+    if canMirror then
         if getrandom(2) = 0 then
-           begin
-           for i:= 0 to pred(BasePointsCount) do
-             if pa.ar[i].x <> NTPX then
-               pa.ar[i].x:= LAND_WIDTH - 1 - pa.ar[i].x;
-           for i:= 0 to pred(FillPointsCount) do
-               FillPoints^[i].x:= LAND_WIDTH - 1 - FillPoints^[i].x;
-           end;
+            begin
+            for i:= 0 to pred(BasePointsCount) do
+               if pa.ar[i].x <> NTPX then
+                   pa.ar[i].x:= LAND_WIDTH - 1 - pa.ar[i].x;
+            for i:= 0 to pred(FillPointsCount) do
+                FillPoints^[i].x:= LAND_WIDTH - 1 - FillPoints^[i].x;
+            end;
 
 (*  Experiment in making this option more useful
      if ((not isNegative) and (cTemplateFilter = 4)) or
@@ -146,30 +148,30 @@
      end
 *)
 // template recycling.  Pull these off the floor a bit
-     if (not isNegative) and (cTemplateFilter = 4) then
-           begin
-           for i:= 0 to pred(BasePointsCount) do
-               begin
-               dec(pa.ar[i].y, 100);
-               if pa.ar[i].y < 0 then
-                   pa.ar[i].y:= 0;
-               end;
-           for i:= 0 to pred(FillPointsCount) do
-               begin
-               dec(FillPoints^[i].y, 100);
-               if FillPoints^[i].y < 0 then
-                   FillPoints^[i].y:= 0;
-               end;
-           end;
+    if (not isNegative) and (cTemplateFilter = 4) then
+        begin
+        for i:= 0 to pred(BasePointsCount) do
+            begin
+            dec(pa.ar[i].y, 100);
+            if pa.ar[i].y < 0 then
+                pa.ar[i].y:= 0;
+            end;
+        for i:= 0 to pred(FillPointsCount) do
+            begin
+            dec(FillPoints^[i].y, 100);
+            if FillPoints^[i].y < 0 then
+                FillPoints^[i].y:= 0;
+            end;
+        end;
 
-     if (canFlip and (getrandom(2) = 0)) then
-           begin
-           for i:= 0 to pred(BasePointsCount) do
-               pa.ar[i].y:= LAND_HEIGHT - 1 - pa.ar[i].y;
-           for i:= 0 to pred(FillPointsCount) do
-               FillPoints^[i].y:= LAND_HEIGHT - 1 - FillPoints^[i].y;
-           end;
-     end
+    if (canFlip and (getrandom(2) = 0)) then
+        begin
+        for i:= 0 to pred(BasePointsCount) do
+            pa.ar[i].y:= LAND_HEIGHT - 1 - pa.ar[i].y;
+        for i:= 0 to pred(FillPointsCount) do
+            FillPoints^[i].y:= LAND_HEIGHT - 1 - FillPoints^[i].y;
+        end;
+    end
 end;
 
 
@@ -190,7 +192,8 @@
         RandomizePoints(pa);
         RandomizePoints(pa)
         end;
-    for i:= 1 to Template.RandPassesCount do RandomizePoints(pa);
+    for i:= 1 to Template.RandPassesCount do
+        RandomizePoints(pa);
     BezierizeEdge(pa, _0_1);
 
 
@@ -212,9 +215,9 @@
     topY:= LAND_HEIGHT - playHeight;
 
     // HACK: force to only cavern even if a cavern map is invertable if cTemplateFilter = 4 ?
-    if (cTemplateFilter = 4) or
-    (Template.canInvert and (getrandom(2) = 0)) or
-        (not Template.canInvert and Template.isNegative) then
+    if (cTemplateFilter = 4)
+    or (Template.canInvert and (getrandom(2) = 0))
+    or (not Template.canInvert and Template.isNegative) then
         begin
         hasBorder:= true;
         for y:= 0 to LAND_HEIGHT - 1 do
@@ -222,12 +225,12 @@
                 if (y < topY) or (x < leftX) or (x > rightX) then
                     Land[y, x]:= 0
                 else
-                begin
-                if Land[y, x] = 0 then
-                    Land[y, x]:= lfBasic
-                else if Land[y, x] = lfBasic then
-                    Land[y, x]:= 0;
-                end;
+                    begin
+                    if Land[y, x] = 0 then
+                        Land[y, x]:= lfBasic
+                    else if Land[y, x] = lfBasic then
+                        Land[y, x]:= 0;
+                    end;
         end;
 end;
 
@@ -276,9 +279,9 @@
     for x:= 0 to LAND_WIDTH - 1 do
     if Land[y, x] <> 0 then
         if (cReducedQuality and rqBlurryLand) = 0 then
-             LandPixels[y, x]:= p^[x] or AMask
+            LandPixels[y, x]:= p^[x] or AMask
         else
-             LandPixels[y div 2, x div 2]:= p^[x] or AMask;
+            LandPixels[y div 2, x div 2]:= p^[x] or AMask;
 
     p:= @(p^[Surface^.pitch div 4]);
     end;
@@ -318,11 +321,20 @@
             begin
                 if (cReducedQuality and rqBlurryLand) = 0 then
                     begin
-                    if (Land[y, x-1] = lfBasic) and (LandPixels[y, x-1] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y, x-1]
-                    else if (Land[y, x+1] = lfBasic) and (LandPixels[y, x+1] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y, x+1]
-                    else if (Land[y-1, x] = lfBasic) and (LandPixels[y-1, x] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y-1, x]
-                    else if (Land[y+1, x] = lfBasic) and (LandPixels[y+1, x] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y+1, x];
-                    if (((LandPixels[y,x] and AMask) shr AShift) > 10) then LandPixels[y,x]:= (LandPixels[y,x] and (not AMask)) or (128 shl AShift)
+                    if (Land[y, x-1] = lfBasic) and (LandPixels[y, x-1] and AMask <> 0) then
+                        LandPixels[y, x]:= LandPixels[y, x-1]
+                        
+                    else if (Land[y, x+1] = lfBasic) and (LandPixels[y, x+1] and AMask <> 0) then
+                        LandPixels[y, x]:= LandPixels[y, x+1]
+                        
+                    else if (Land[y-1, x] = lfBasic) and (LandPixels[y-1, x] and AMask <> 0) then
+                        LandPixels[y, x]:= LandPixels[y-1, x]
+                        
+                    else if (Land[y+1, x] = lfBasic) and (LandPixels[y+1, x] and AMask <> 0) then
+                        LandPixels[y, x]:= LandPixels[y+1, x];
+                        
+                    if (((LandPixels[y,x] and AMask) shr AShift) > 10) then
+                        LandPixels[y,x]:= (LandPixels[y,x] and (not AMask)) or (128 shl AShift)
                     end;
                 Land[y,x]:= lfObject
             end
@@ -335,14 +347,27 @@
                     ((Land[y-1, x] = lfBasic) and (Land[y-1,x+1] = lfBasic) and (Land[y,x+2] = lfBasic)) or
                     ((Land[y+1, x] = lfBasic) and (Land[y+1,x-1] = lfBasic) and (Land[y,x-2] = lfBasic)) or
                     ((Land[y-1, x] = lfBasic) and (Land[y-1,x-1] = lfBasic) and (Land[y,x-2] = lfBasic))) then
-            begin
+                    
+                begin
+                
                 if (cReducedQuality and rqBlurryLand) = 0 then
+                
                     begin
-                    if (Land[y, x-1] = lfBasic) and (LandPixels[y,x-1] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y, x-1]
-                    else if (Land[y, x+1] = lfBasic) and (LandPixels[y,x+1] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y, x+1]
-                    else if (Land[y+1, x] = lfBasic) and (LandPixels[y+1,x] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y+1, x]
-                    else if (Land[y-1, x] = lfBasic) and (LandPixels[y-1,x] and AMask <> 0) then LandPixels[y, x]:= LandPixels[y-1, x];
-                    if (((LandPixels[y,x] and AMask) shr AShift) > 10) then LandPixels[y,x]:= (LandPixels[y,x] and (not AMask)) or (64 shl AShift)
+                    
+                    if (Land[y, x-1] = lfBasic) and (LandPixels[y,x-1] and AMask <> 0) then
+                        LandPixels[y, x]:= LandPixels[y, x-1]
+                        
+                    else if (Land[y, x+1] = lfBasic) and (LandPixels[y,x+1] and AMask <> 0) then
+                        LandPixels[y, x]:= LandPixels[y, x+1]
+                        
+                    else if (Land[y+1, x] = lfBasic) and (LandPixels[y+1,x] and AMask <> 0) then
+                        LandPixels[y, x]:= LandPixels[y+1, x]
+                        
+                    else if (Land[y-1, x] = lfBasic) and (LandPixels[y-1,x] and AMask <> 0) then
+                        LandPixels[y, x]:= LandPixels[y-1, x];
+                        
+                    if (((LandPixels[y,x] and AMask) shr AShift) > 10) then
+                        LandPixels[y,x]:= (LandPixels[y,x] and (not AMask)) or (64 shl AShift)
                     end;
                 Land[y,x]:= lfObject
             end;
@@ -364,12 +389,14 @@
 WriteLnToConsole('Generating forts land...');
 
 tmpsurf:= LoadImage(UserPathz[ptForts] + '/' + ClansArray[0]^.Teams[0]^.FortName + 'L', ifAlpha or ifTransparent or ifIgnoreCaps);
-if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptForts] + '/' + ClansArray[0]^.Teams[0]^.FortName + 'L', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
+if tmpsurf = nil then
+    tmpsurf:= LoadImage(Pathz[ptForts] + '/' + ClansArray[0]^.Teams[0]^.FortName + 'L', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
 BlitImageAndGenerateCollisionInfo(leftX+150, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf);
 SDL_FreeSurface(tmpsurf);
 
 tmpsurf:= LoadImage(UserPathz[ptForts] + '/' + ClansArray[1]^.Teams[0]^.FortName + 'R', ifAlpha or ifTransparent or ifIgnoreCaps);
-if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptForts] + '/' + ClansArray[1]^.Teams[0]^.FortName + 'R', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
+if tmpsurf = nil then
+    tmpsurf:= LoadImage(Pathz[ptForts] + '/' + ClansArray[1]^.Teams[0]^.FortName + 'R', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
 BlitImageAndGenerateCollisionInfo(rightX - 150 - tmpsurf^.w, LAND_HEIGHT - tmpsurf^.h, tmpsurf^.w, tmpsurf);
 SDL_FreeSurface(tmpsurf);
 end;
@@ -381,17 +408,19 @@
     x, y, cpX, cpY: Longword;
 begin
 tmpsurf:= LoadImage(UserPathz[ptMapCurrent] + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps);
-if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptMapCurrent] + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps);
+if tmpsurf = nil then
+    tmpsurf:= LoadImage(Pathz[ptMapCurrent] + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps);
 if tmpsurf = nil then
     begin
     mapName:= ExtractFileName(Pathz[ptMapCurrent]);
     tmpsurf:= LoadImage(UserPathz[ptMissionMaps] + '/' + mapName + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps);
-    if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptMissionMaps] + '/' + mapName + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps);
+    if tmpsurf = nil then
+        tmpsurf:= LoadImage(Pathz[ptMissionMaps] + '/' + mapName + '/mask', ifAlpha or ifTransparent or ifIgnoreCaps);
     end;
 
 
 if (tmpsurf <> nil) and (tmpsurf^.w <= LAND_WIDTH) and (tmpsurf^.h <= LAND_HEIGHT) and (tmpsurf^.format^.BytesPerPixel = 4) then
-begin
+    begin
     disableLandBack:= true;
 
     cpX:= (LAND_WIDTH - tmpsurf^.w) div 2;
@@ -427,8 +456,10 @@
         begin
         // freed in freeModule() below
         LandBackSurface:= LoadImage(UserPathz[ptCurrTheme] + '/LandBackTex', ifIgnoreCaps or ifTransparent);
-        if LandBackSurface = nil then LandBackSurface:= LoadImage(Pathz[ptCurrTheme] + '/LandBackTex', ifIgnoreCaps or ifTransparent);
-        if (LandBackSurface <> nil) and cGrayScale then Surface2GrayScale(LandBackSurface)
+        if LandBackSurface = nil then
+            LandBackSurface:= LoadImage(Pathz[ptCurrTheme] + '/LandBackTex', ifIgnoreCaps or ifTransparent);
+        if (LandBackSurface <> nil) and cGrayScale then
+            Surface2GrayScale(LandBackSurface)
         end;
 end;
 if (tmpsurf <> nil) then
@@ -446,33 +477,38 @@
 WriteLnToConsole('Loading land from file...');
 AddProgress;
 tmpsurf:= LoadImage(UserPathz[ptMapCurrent] + '/map', ifAlpha or ifTransparent or ifIgnoreCaps);
-if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptMapCurrent] + '/map', ifAlpha or ifTransparent or ifIgnoreCaps);
+if tmpsurf = nil then
+    tmpsurf:= LoadImage(Pathz[ptMapCurrent] + '/map', ifAlpha or ifTransparent or ifIgnoreCaps);
 if tmpsurf = nil then
     begin
     mapName:= ExtractFileName(Pathz[ptMapCurrent]);
     tmpsurf:= LoadImage(UserPathz[ptMissionMaps] + '/' + mapName + '/map', ifAlpha or ifTransparent or ifIgnoreCaps);
-    if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptMissionMaps] + '/' + mapName + '/map', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
+    if tmpsurf = nil then
+        tmpsurf:= LoadImage(Pathz[ptMissionMaps] + '/' + mapName + '/map', ifAlpha or ifCritical or ifTransparent or ifIgnoreCaps);
     end;
 TryDo((tmpsurf^.w <= LAND_WIDTH) and (tmpsurf^.h <= LAND_HEIGHT), 'Map dimensions too big!', true);
 
 // unC0Rr - should this be passed from the GUI? I am not sure which layer does what
 s:= UserPathz[ptMapCurrent] + '/map.cfg';
-if not FileExists(s) then s:= Pathz[ptMapCurrent] + '/map.cfg';
+if not FileExists(s) then
+    s:= Pathz[ptMapCurrent] + '/map.cfg';
 WriteLnToConsole('Fetching map HH limit');
 {$I-}
 Assign(f, s);
 filemode:= 0; // readonly
 Reset(f);
 if IOResult <> 0 then
-begin
+    begin
     s:= Pathz[ptMissionMaps] + '/' + mapName + '/map.cfg';
     Assign(f, s);
     Reset(f);
-end;
+    end;
 Readln(f);
-if not eof(f) then Readln(f, MaxHedgehogs);
+if not eof(f) then
+    Readln(f, MaxHedgehogs);
 {$I+}
-if (MaxHedgehogs = 0) then MaxHedgehogs:= 18;
+if (MaxHedgehogs = 0) then
+    MaxHedgehogs:= 18;
 
 playHeight:= tmpsurf^.h;
 playWidth:= tmpsurf^.w;
@@ -597,14 +633,17 @@
         end;
     end;
 
-if (GameFlags and gfBottomBorder) <> 0 then DrawBottomBorder;
+if (GameFlags and gfBottomBorder) <> 0 then
+    DrawBottomBorder;
 
-if (GameFlags and gfDisableGirders) <> 0 then hasGirders:= false;
+if (GameFlags and gfDisableGirders) <> 0 then
+    hasGirders:= false;
 
-if ((GameFlags and gfForts) = 0)
-    and (Pathz[ptMapCurrent] = '')
-    then AddObjects
-else AddProgress();
+if ((GameFlags and gfForts) = 0) and (Pathz[ptMapCurrent] = '') then
+    AddObjects
+    
+else
+    AddProgress();
 
 FreeLandObjects;
 
@@ -618,7 +657,8 @@
                 w:= round(((w shr RShift and $FF) * RGB_LUMINANCE_RED +
                       (w shr BShift and $FF) * RGB_LUMINANCE_GREEN +
                       (w shr GShift and $FF) * RGB_LUMINANCE_BLUE));
-                if w > 255 then w:= 255;
+                if w > 255 then
+                    w:= 255;
                 w:= (w and $FF shl RShift) or (w and $FF shl BShift) or (w and $FF shl GShift) or (LandPixels[y,x] and AMask);
                 LandPixels[y,x]:= w or (LandPixels[y, x] and AMask)
                 end
@@ -628,8 +668,9 @@
                 begin
                 w:= LandPixels[y div 2,x div 2];
                 w:= ((w shr RShift and $FF) +  (w shr BShift and $FF) + (w shr GShift and $FF)) div 3;
-                if w > 255 then w:= 255;
-               w:= (w and $FF shl RShift) or (w and $FF shl BShift) or (w and $FF shl GShift) or (LandPixels[y div 2,x div 2] and AMask);
+                if w > 255 then
+                    w:= 255;
+                w:= (w and $FF shl RShift) or (w and $FF shl BShift) or (w and $FF shl GShift) or (LandPixels[y div 2,x div 2] and AMask);
                 LandPixels[y,x]:= w or (LandPixels[y div 2, x div 2] and AMask)
                 end
     end;
@@ -662,7 +703,8 @@
                 cbit:= bit * 8;
                 for yy:= y * lh to y * lh + 7 do
                     for xx:= x * lw + cbit to x * lw + cbit + 7 do
-                        if Land[yy, xx] <> 0 then inc(t);
+                        if Land[yy, xx] <> 0 then
+                            inc(t);
                 if t > 8 then
                     Preview[y, x]:= Preview[y, x] or ($80 shr bit);
             end;
--- a/hedgewars/uLandGenMaze.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uLandGenMaze.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -91,8 +91,10 @@
 end;
 tries := 0;
 found_cell := false;
-if getrandom(2) = 1 then next_dir_clockwise := true
-else next_dir_clockwise := false;
+if getrandom(2) = 1 then
+    next_dir_clockwise := true
+else
+    next_dir_clockwise := false;
 
 while (tries < 5) and (not found_cell) do
 begin
@@ -104,12 +106,21 @@
         //or just warn that inverted+braid+indestructible terrain != good idea
         begin
             case dir.x of
-                -1: if x > 0 then ywalls[x-1, y] := false;
-                1: if x < seen_cells_x - 1 then ywalls[x, y] := false;
+            
+                -1:
+                if x > 0 then
+                    ywalls[x-1, y] := false;
+                1:
+                if x < seen_cells_x - 1 then
+                    ywalls[x, y] := false;
             end;
             case dir.y of
-                -1: if y > 0 then xwalls[x, y-1] := false;
-                1: if y < seen_cells_y - 1 then xwalls[x, y] := false;
+                -1:
+                if y > 0 then
+                    xwalls[x, y-1] := false;
+                1:
+                if y < seen_cells_y - 1 then
+                    xwalls[x, y] := false;
             end;
         end;
         if next_dir_clockwise then
@@ -136,7 +147,7 @@
         end
     end
     else if when_seen(x + dir.x, y + dir.y) = -1 then //cell was not seen yet, go there
-    begin
+        begin
         case dir.y of
             -1: xwalls[x, y-1] := false;
             1: xwalls[x, y] := false;
@@ -151,23 +162,27 @@
         came_from[current_step, came_from_pos[current_step]].x := x;
         came_from[current_step, came_from_pos[current_step]].y := y;
         found_cell := true;
-    end
+        end
     else //we are seeing someone else, quit
-    begin
+        begin
         step_done[current_step] := true;
         found_cell := true;
-    end;
+        end;
 
     tries := tries + 1;
 end;
 if not found_cell then
-begin
+    begin
     last_cell[current_step].x := came_from[current_step, came_from_pos[current_step]].x;
     last_cell[current_step].y := came_from[current_step, came_from_pos[current_step]].y;
     came_from_pos[current_step] := came_from_pos[current_step] - 1;
-    if came_from_pos[current_step] >= 0 then see_cell
-    else step_done[current_step] := true;
-end;
+    
+    if came_from_pos[current_step] >= 0 then
+        see_cell
+        
+    else
+        step_done[current_step] := true;
+    end;
 end;
 
 procedure add_vertex(x, y: LongInt);
@@ -187,10 +202,15 @@
 end
 else
 begin
-    if maze_inverted or (x mod 2 = 0) then tmp_x := cellsize
-    else tmp_x := cellsize * 2 div 3;
-    if maze_inverted or (y mod 2 = 0) then tmp_y := cellsize
-    else tmp_y := cellsize * 2 div 3;
+    if maze_inverted or (x mod 2 = 0) then
+        tmp_x := cellsize
+    else
+        tmp_x := cellsize * 2 div 3;
+        
+    if maze_inverted or (y mod 2 = 0) then
+        tmp_y := cellsize
+    else
+        tmp_y := cellsize * 2 div 3;
 
     pa.ar[num_vertices].x := (x-1)*cellsize + tmp_x;
     pa.ar[num_vertices].y := (y-1)*cellsize + tmp_y + off_y;
@@ -202,64 +222,64 @@
 var i: LongInt;
 begin
 if dir = DIR_N then
-begin
+    begin
     dir := DIR_W
-end
+    end
 else if dir = DIR_E then
-begin
+    begin
     dir := DIR_N
-end
+    end
 else if dir = DIR_S then
-begin
+    begin
     dir := DIR_E
-end
+    end
 else
-begin
+    begin
     dir := DIR_S;
-end;
+    end;
 
 for i := 0 to 3 do
-begin
-        if dir = DIR_N then
-            dir := DIR_E
-        else if dir = DIR_E then
-            dir := DIR_S
-        else if dir = DIR_S then
-            dir := DIR_W
-        else
-            dir := DIR_N;
+    begin
+    if dir = DIR_N then
+        dir := DIR_E
+    else if dir = DIR_E then
+        dir := DIR_S
+    else if dir = DIR_S then
+        dir := DIR_W
+    else
+        dir := DIR_N;
 
-    if (dir = DIR_N) and is_x_edge(x, y) then
-        begin
-            x_edge_list[x, y] := false;
-            add_vertex(x+1, y);
-            add_edge(x, y-1, DIR_N);
-            break;
-        end;
+if (dir = DIR_N) and is_x_edge(x, y) then
+    begin
+        x_edge_list[x, y] := false;
+        add_vertex(x+1, y);
+        add_edge(x, y-1, DIR_N);
+        break;
+    end;
 
-    if (dir = DIR_E) and is_y_edge(x+1, y) then
-        begin
-            y_edge_list[x+1, y] := false;
-            add_vertex(x+2, y+1);
-            add_edge(x+1, y, DIR_E);
-            break;
-        end;
+if (dir = DIR_E) and is_y_edge(x+1, y) then
+    begin
+        y_edge_list[x+1, y] := false;
+        add_vertex(x+2, y+1);
+        add_edge(x+1, y, DIR_E);
+        break;
+    end;
 
-    if (dir = DIR_S) and is_x_edge(x, y+1) then
-        begin
-            x_edge_list[x, y+1] := false;
-            add_vertex(x+1, y+2);
-            add_edge(x, y+1, DIR_S);
-            break;
-        end;
+if (dir = DIR_S) and is_x_edge(x, y+1) then
+    begin
+        x_edge_list[x, y+1] := false;
+        add_vertex(x+1, y+2);
+        add_edge(x, y+1, DIR_S);
+        break;
+    end;
 
-    if (dir = DIR_W) and is_y_edge(x, y) then
-        begin
-            y_edge_list[x, y] := false;
-            add_vertex(x, y+1);
-            add_edge(x-1, y, DIR_W);
-            break;
-        end;
+if (dir = DIR_W) and is_y_edge(x, y) then
+    begin
+        y_edge_list[x, y] := false;
+        add_vertex(x, y+1);
+        add_edge(x-1, y, DIR_W);
+        break;
+    end;
 end;
 
 end;
@@ -294,11 +314,16 @@
 end;
 
 num_cells_x := LAND_WIDTH div cellsize;
-if not odd(num_cells_x) then num_cells_x := num_cells_x - 1; //needs to be odd
+if not odd(num_cells_x) then
+    num_cells_x := num_cells_x - 1; //needs to be odd
+    
 num_cells_y := LAND_HEIGHT div cellsize;
-if not odd(num_cells_y) then num_cells_y := num_cells_y - 1;
+if not odd(num_cells_y) then
+    num_cells_y := num_cells_y - 1;
+    
 num_edges_x := num_cells_x - 1;
 num_edges_y := num_cells_y - 1;
+
 seen_cells_x := num_cells_x div 2;
 seen_cells_y := num_cells_y div 2;
 
@@ -306,14 +331,17 @@
     num_steps := 3 //TODO randomize, between 3 and 5?
 else
     num_steps := 1;
+    
 SetLength(step_done, num_steps);
 SetLength(last_cell, num_steps);
 SetLength(came_from_pos, num_steps);
 SetLength(came_from, num_steps, num_cells_x*num_cells_y);
 done := false;
+
 for current_step := 0 to num_steps - 1 do
     step_done[current_step] := false;
     came_from_pos[current_step] := 0;
+    
 current_step := 0;
 
 SetLength(seen_list, seen_cells_x, seen_cells_y);
@@ -362,14 +390,14 @@
         y_edge_list[x, y] := false;
 
 for current_step := 0 to num_steps-1 do
-begin
+    begin
     x := GetRandom(seen_cells_x - 1) div LongWord(num_steps);
     last_cell[current_step].x := x + current_step * seen_cells_x div num_steps;
     last_cell[current_step].y := GetRandom(seen_cells_y);
 end;
 
 while not done do
-begin
+    begin
     done := true;
     for current_step := 0 to num_steps-1 do
     begin
@@ -414,13 +442,13 @@
 for x := 0 to num_edges_x - 1 do
     for y := 0 to num_cells_y - 1 do
         if x_edge_list[x, y] then
-        begin
+            begin
             x_edge_list[x, y] := false;
             add_vertex(x+1, y+1);
             add_vertex(x+1, y);
             add_edge(x, y-1, DIR_N);
             add_vertex(NTPX, 0);
-        end;
+            end;
 
 pa.count := num_vertices;
 
@@ -434,18 +462,20 @@
 if maze_inverted then
     FillLand(1, 1+off_y)
 else
-begin
+    begin
     x := 0;
     while Land[cellsize div 2 + cellsize + off_y, x] = lfBasic do
         x := x + 1;
     while Land[cellsize div 2 + cellsize + off_y, x] = 0 do
         x := x + 1;
     FillLand(x+1, cellsize div 2 + cellsize + off_y);
-end;
+    end;
 
 MaxHedgehogs:= 32;
-if (GameFlags and gfDisableGirders) <> 0 then hasGirders:= false
-else hasGirders := true;
+if (GameFlags and gfDisableGirders) <> 0 then
+    hasGirders:= false
+else
+    hasGirders := true;
 leftX:= 0;
 rightX:= playWidth;
 topY:= off_y;
--- a/hedgewars/uLandGraphics.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uLandGraphics.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -84,7 +84,7 @@
         if (Land[y + dy, i] and lfIndestructible) = 0 then
             Land[y + dy, i]:= Value;
 if ((y - dy) and LAND_HEIGHT_MASK) = 0 then
-   for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
+    for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
         if (Land[y - dy, i] and lfIndestructible) = 0 then
             Land[y - dy, i]:= Value;
 if ((y + dx) and LAND_HEIGHT_MASK) = 0 then
@@ -101,78 +101,87 @@
 var i: LongInt;
 begin
 if not doSet then
-   begin
-   if ((y + dy) and LAND_HEIGHT_MASK) = 0 then
-      for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
-          if (Land[y + dy, i] > 0) and (Land[y + dy, i] < 256) then dec(Land[y + dy, i]); // check > 0 because explosion can erase collision data
-   if ((y - dy) and LAND_HEIGHT_MASK) = 0 then
-      for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
-          if (Land[y - dy, i] > 0) and (Land[y - dy, i] < 256) then dec(Land[y - dy, i]);
-   if ((y + dx) and LAND_HEIGHT_MASK) = 0 then
-      for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
-          if (Land[y + dx, i] > 0) and (Land[y + dx, i] < 256) then dec(Land[y + dx, i]);
-   if ((y - dx) and LAND_HEIGHT_MASK) = 0 then
-      for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
-          if (Land[y - dx, i] > 0) and (Land[y - dx, i] < 256) then dec(Land[y - dx, i]);
-   end else
-   begin
-   if ((y + dy) and LAND_HEIGHT_MASK) = 0 then
-      for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
-          if (Land[y + dy, i] < 256) then
-              inc(Land[y + dy, i]);
-   if ((y - dy) and LAND_HEIGHT_MASK) = 0 then
-      for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
-          if (Land[y - dy, i] < 256) then
-              inc(Land[y - dy, i]);
-   if ((y + dx) and LAND_HEIGHT_MASK) = 0 then
-      for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
-          if (Land[y + dx, i] < 256) then
-              inc(Land[y + dx, i]);
-   if ((y - dx) and LAND_HEIGHT_MASK) = 0 then
-      for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
-          if (Land[y - dx, i] < 256) then
-              inc(Land[y - dx, i]);
-   end
+    begin
+    if ((y + dy) and LAND_HEIGHT_MASK) = 0 then
+        for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
+            if (Land[y + dy, i] > 0) and (Land[y + dy, i] < 256) then
+                dec(Land[y + dy, i]); // check > 0 because explosion can erase collision data
+    if ((y - dy) and LAND_HEIGHT_MASK) = 0 then
+        for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
+            if (Land[y - dy, i] > 0) and (Land[y - dy, i] < 256) then
+                dec(Land[y - dy, i]);
+    if ((y + dx) and LAND_HEIGHT_MASK) = 0 then
+        for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
+            if (Land[y + dx, i] > 0) and (Land[y + dx, i] < 256) then
+                dec(Land[y + dx, i]);
+    if ((y - dx) and LAND_HEIGHT_MASK) = 0 then
+        for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
+            if (Land[y - dx, i] > 0) and (Land[y - dx, i] < 256) then
+                dec(Land[y - dx, i]);
+    end
+else
+    begin
+    if ((y + dy) and LAND_HEIGHT_MASK) = 0 then
+        for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
+            if (Land[y + dy, i] < 256) then
+                inc(Land[y + dy, i]);
+    if ((y - dy) and LAND_HEIGHT_MASK) = 0 then
+        for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
+            if (Land[y - dy, i] < 256) then
+                inc(Land[y - dy, i]);
+    if ((y + dx) and LAND_HEIGHT_MASK) = 0 then
+        for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
+            if (Land[y + dx, i] < 256) then
+                inc(Land[y + dx, i]);
+    if ((y - dx) and LAND_HEIGHT_MASK) = 0 then
+        for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
+            if (Land[y - dx, i] < 256) then
+                inc(Land[y - dx, i]);
+    end
 end;
 
 procedure FillRoundInLand(X, Y, Radius: LongInt; Value: Longword);
 var dx, dy, d: LongInt;
 begin
-  dx:= 0;
-  dy:= Radius;
-  d:= 3 - 2 * Radius;
-  while (dx < dy) do
-     begin
-     FillCircleLines(x, y, dx, dy, Value);
-     if (d < 0)
-     then d:= d + 4 * dx + 6
-     else begin
-          d:= d + 4 * (dx - dy) + 10;
-          dec(dy)
-          end;
-     inc(dx)
-     end;
-  if (dx = dy) then FillCircleLines(x, y, dx, dy, Value);
+dx:= 0;
+dy:= Radius;
+d:= 3 - 2 * Radius;
+while (dx < dy) do
+    begin
+    FillCircleLines(x, y, dx, dy, Value);
+    if (d < 0) then
+        d:= d + 4 * dx + 6
+    else
+        begin
+        d:= d + 4 * (dx - dy) + 10;
+        dec(dy)
+        end;
+    inc(dx)
+    end;
+if (dx = dy) then
+    FillCircleLines(x, y, dx, dy, Value);
 end;
 
 procedure ChangeRoundInLand(X, Y, Radius: LongInt; doSet: boolean);
 var dx, dy, d: LongInt;
 begin
-  dx:= 0;
-  dy:= Radius;
-  d:= 3 - 2 * Radius;
-  while (dx < dy) do
-     begin
-     ChangeCircleLines(x, y, dx, dy, doSet);
-     if (d < 0)
-     then d:= d + 4 * dx + 6
-     else begin
-          d:= d + 4 * (dx - dy) + 10;
-          dec(dy)
-          end;
-     inc(dx)
-     end;
-  if (dx = dy) then ChangeCircleLines(x, y, dx, dy, doSet)
+dx:= 0;
+dy:= Radius;
+d:= 3 - 2 * Radius;
+while (dx < dy) do
+    begin
+    ChangeCircleLines(x, y, dx, dy, doSet);
+    if (d < 0) then
+        d:= d + 4 * dx + 6
+    else
+        begin
+        d:= d + 4 * (dx - dy) + 10;
+        dec(dy)
+        end;
+    inc(dx)
+    end;
+if (dx = dy) then
+    ChangeCircleLines(x, y, dx, dy, doSet)
 end;
 
 procedure FillLandCircleLines0(x, y, dx, dy: LongInt);
@@ -223,90 +232,90 @@
 cnt:= 0;
 t:= y + dy;
 if (t and LAND_HEIGHT_MASK) = 0 then
-   for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
-       if (Land[t, i] and lfIndestructible) = 0 then
-           begin
-           if (cReducedQuality and rqBlurryLand) = 0 then
-               begin
-               by:= t; bx:= i;
-               end
-           else
-               begin
-               by:= t div 2; bx:= i div 2;
-               end;
-           if ((Land[t, i] and lfBasic) <> 0) and (((LandPixels[by,bx] and AMask) shr AShift) = 255) and (not disableLandBack) then
-               begin
-               inc(cnt);
-               LandPixels[by, bx]:= LandBackPixel(i, t)
-               end
-           else if ((Land[t, i] and lfObject) <> 0) or (((LandPixels[by,bx] and AMask) shr AShift) < 255) then 
-               LandPixels[by, bx]:= 0
-           end;
+    for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
+        if (Land[t, i] and lfIndestructible) = 0 then
+            begin
+            if (cReducedQuality and rqBlurryLand) = 0 then
+                begin
+                by:= t; bx:= i;
+                end
+            else
+                begin
+                by:= t div 2; bx:= i div 2;
+                end;
+            if ((Land[t, i] and lfBasic) <> 0) and (((LandPixels[by,bx] and AMask) shr AShift) = 255) and (not disableLandBack) then
+                begin
+                inc(cnt);
+                LandPixels[by, bx]:= LandBackPixel(i, t)
+                end
+            else if ((Land[t, i] and lfObject) <> 0) or (((LandPixels[by,bx] and AMask) shr AShift) < 255) then 
+                LandPixels[by, bx]:= 0
+            end;
 
 t:= y - dy;
 if (t and LAND_HEIGHT_MASK) = 0 then
-   for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
-       if (Land[t, i] and lfIndestructible) = 0 then
-           begin
-           if (cReducedQuality and rqBlurryLand) = 0 then
-               begin
-               by:= t; bx:= i;
-               end
-           else
-               begin
-               by:= t div 2; bx:= i div 2;
-               end;
-           if ((Land[t, i] and lfBasic) <> 0) and (((LandPixels[by,bx] and AMask) shr AShift) = 255) and (not disableLandBack) then
-               begin
-               inc(cnt);
-               LandPixels[by, bx]:= LandBackPixel(i, t)
-               end
-           else if ((Land[t, i] and lfObject) <> 0) or (((LandPixels[by,bx] and AMask) shr AShift) < 255) then 
-               LandPixels[by, bx]:= 0
-           end;
+    for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
+        if (Land[t, i] and lfIndestructible) = 0 then
+            begin
+            if (cReducedQuality and rqBlurryLand) = 0 then
+                begin
+                by:= t; bx:= i;
+                end
+            else
+                begin
+                by:= t div 2; bx:= i div 2;
+                end;
+            if ((Land[t, i] and lfBasic) <> 0) and (((LandPixels[by,bx] and AMask) shr AShift) = 255) and (not disableLandBack) then
+                begin
+                inc(cnt);
+                LandPixels[by, bx]:= LandBackPixel(i, t)
+                end
+            else if ((Land[t, i] and lfObject) <> 0) or (((LandPixels[by,bx] and AMask) shr AShift) < 255) then 
+                LandPixels[by, bx]:= 0
+            end;
 
 t:= y + dx;
 if (t and LAND_HEIGHT_MASK) = 0 then
-   for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
-       if (Land[t, i] and lfIndestructible) = 0 then
-           begin
-           if (cReducedQuality and rqBlurryLand) = 0 then
-               begin
-               by:= t; bx:= i;
-               end
-           else
-               begin
-               by:= t div 2; bx:= i div 2;
-               end;
-           if ((Land[t, i] and lfBasic) <> 0) and (((LandPixels[by,bx] and AMask) shr AShift) = 255) and (not disableLandBack) then
-               begin
-               inc(cnt);
-               LandPixels[by, bx]:= LandBackPixel(i, t)
-               end
-           else if ((Land[t, i] and lfObject) <> 0) or (((LandPixels[by,bx] and AMask) shr AShift) < 255) then 
-               LandPixels[by, bx]:= 0
-           end;
+    for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
+        if (Land[t, i] and lfIndestructible) = 0 then
+            begin
+            if (cReducedQuality and rqBlurryLand) = 0 then
+                begin
+                by:= t; bx:= i;
+                end
+            else
+                begin
+                by:= t div 2; bx:= i div 2;
+                end;
+            if ((Land[t, i] and lfBasic) <> 0) and (((LandPixels[by,bx] and AMask) shr AShift) = 255) and (not disableLandBack) then
+                begin
+                inc(cnt);
+                LandPixels[by, bx]:= LandBackPixel(i, t)
+                end
+            else if ((Land[t, i] and lfObject) <> 0) or (((LandPixels[by,bx] and AMask) shr AShift) < 255) then 
+                LandPixels[by, bx]:= 0
+            end;
 t:= y - dx;
 if (t and LAND_HEIGHT_MASK) = 0 then
-   for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
-       if (Land[t, i] and lfIndestructible) = 0 then
-           begin
-           if (cReducedQuality and rqBlurryLand) = 0 then
-               begin
-               by:= t; bx:= i;
-               end
-           else
-               begin
-               by:= t div 2; bx:= i div 2;
-               end;
-           if ((Land[t, i] and lfBasic) <> 0) and (((LandPixels[by,bx] and AMask) shr AShift) = 255) and (not disableLandBack) then
-               begin
-               inc(cnt);
-               LandPixels[by, bx]:= LandBackPixel(i, t)
-               end
-           else if ((Land[t, i] and lfObject) <> 0) or (((LandPixels[by,bx] and AMask) shr AShift) < 255) then 
-               LandPixels[by, bx]:= 0
-           end;
+    for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
+        if (Land[t, i] and lfIndestructible) = 0 then
+            begin
+            if (cReducedQuality and rqBlurryLand) = 0 then
+                begin
+                by:= t; bx:= i;
+                end
+            else
+                begin
+                by:= t div 2; bx:= i div 2;
+                end;
+            if ((Land[t, i] and lfBasic) <> 0) and (((LandPixels[by,bx] and AMask) shr AShift) = 255) and (not disableLandBack) then
+                begin
+                inc(cnt);
+                LandPixels[by, bx]:= LandBackPixel(i, t)
+                end
+            else if ((Land[t, i] and lfObject) <> 0) or (((LandPixels[by,bx] and AMask) shr AShift) < 255) then 
+                LandPixels[by, bx]:= 0
+            end;
 FillLandCircleLinesBG:= cnt;
 end;
 
@@ -315,62 +324,62 @@
 begin
 t:= y + dy;
 if (t and LAND_HEIGHT_MASK) = 0 then
-   for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
-       if ((Land[t, i] and lfBasic) <> 0) or ((Land[t, i] and lfObject) <> 0) then
-          begin
-           if (cReducedQuality and rqBlurryLand) = 0 then
-            LandPixels[t, i]:= cExplosionBorderColor
-          else
-            LandPixels[t div 2, i div 2]:= cExplosionBorderColor;
+    for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
+        if ((Land[t, i] and lfBasic) <> 0) or ((Land[t, i] and lfObject) <> 0) then
+            begin
+            if (cReducedQuality and rqBlurryLand) = 0 then
+                LandPixels[t, i]:= cExplosionBorderColor
+            else
+                LandPixels[t div 2, i div 2]:= cExplosionBorderColor;
 
-          Land[t, i]:= Land[t, i] or lfDamaged;
-          //Despeckle(i, t);
-          LandDirty[t div 32, i div 32]:= 1;
-          end;
+            Land[t, i]:= Land[t, i] or lfDamaged;
+            //Despeckle(i, t);
+            LandDirty[t div 32, i div 32]:= 1;
+            end;
 
 t:= y - dy;
 if (t and LAND_HEIGHT_MASK) = 0 then
-   for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
-       if ((Land[t, i] and lfBasic) <> 0) or ((Land[t, i] and lfObject) <> 0) then
-          begin
-           if (cReducedQuality and rqBlurryLand) = 0 then
-              LandPixels[t, i]:= cExplosionBorderColor
+    for i:= Max(x - dx, 0) to Min(x + dx, LAND_WIDTH - 1) do
+        if ((Land[t, i] and lfBasic) <> 0) or ((Land[t, i] and lfObject) <> 0) then
+            begin
+            if (cReducedQuality and rqBlurryLand) = 0 then
+                LandPixels[t, i]:= cExplosionBorderColor
             else
-              LandPixels[t div 2, i div 2]:= cExplosionBorderColor;
-          Land[t, i]:= Land[t, i] or lfDamaged;
-          //Despeckle(i, t);
-          LandDirty[t div 32, i div 32]:= 1;
-          end;
+                LandPixels[t div 2, i div 2]:= cExplosionBorderColor;
+            Land[t, i]:= Land[t, i] or lfDamaged;
+            //Despeckle(i, t);
+            LandDirty[t div 32, i div 32]:= 1;
+            end;
 
 t:= y + dx;
 if (t and LAND_HEIGHT_MASK) = 0 then
-   for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
-       if ((Land[t, i] and lfBasic) <> 0) or ((Land[t, i] and lfObject) <> 0) then
-           begin
-           if (cReducedQuality and rqBlurryLand) = 0 then
-           LandPixels[t, i]:= cExplosionBorderColor
+    for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
+        if ((Land[t, i] and lfBasic) <> 0) or ((Land[t, i] and lfObject) <> 0) then
+            begin
+            if (cReducedQuality and rqBlurryLand) = 0 then
+                LandPixels[t, i]:= cExplosionBorderColor
             else
-           LandPixels[t div 2, i div 2]:= cExplosionBorderColor;
+               LandPixels[t div 2, i div 2]:= cExplosionBorderColor;
 
-           Land[t, i]:= Land[t, i] or lfDamaged;
-           //Despeckle(i, t);
-           LandDirty[t div 32, i div 32]:= 1;
-           end;
+            Land[t, i]:= Land[t, i] or lfDamaged;
+            //Despeckle(i, t);
+            LandDirty[t div 32, i div 32]:= 1;
+            end;
 
 t:= y - dx;
 if (t and LAND_HEIGHT_MASK) = 0 then
-   for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
-       if ((Land[t, i] and lfBasic) <> 0) or ((Land[t, i] and lfObject) <> 0) then
-          begin
-           if (cReducedQuality and rqBlurryLand) = 0 then
-          LandPixels[t, i]:= cExplosionBorderColor
+    for i:= Max(x - dy, 0) to Min(x + dy, LAND_WIDTH - 1) do
+        if ((Land[t, i] and lfBasic) <> 0) or ((Land[t, i] and lfObject) <> 0) then
+            begin
+            if (cReducedQuality and rqBlurryLand) = 0 then
+                LandPixels[t, i]:= cExplosionBorderColor
             else
-          LandPixels[t div 2, i div 2]:= cExplosionBorderColor;
+                LandPixels[t div 2, i div 2]:= cExplosionBorderColor;
 
-          Land[t, i]:= Land[t, i] or lfDamaged;
-          //Despeckle(i, y - dy);
-          LandDirty[t div 32, i div 32]:= 1;
-          end;
+            Land[t, i]:= Land[t, i] or lfDamaged;
+            //Despeckle(i, y - dy);
+            LandDirty[t div 32, i div 32]:= 1;
+            end;
 end;
 
 function DrawExplosion(X, Y, Radius: LongInt): Longword;
@@ -388,15 +397,17 @@
     while (dx < dy) do
         begin
         inc(cnt, FillLandCircleLinesBG(x, y, dx, dy));
-        if (d < 0)
-        then d:= d + 4 * dx + 6
-        else begin
+        if (d < 0) then
+            d:= d + 4 * dx + 6
+        else
+            begin
             d:= d + 4 * (dx - dy) + 10;
             dec(dy)
             end;
         inc(dx)
         end;
-    if (dx = dy) then inc(cnt, FillLandCircleLinesBG(x, y, dx, dy));
+    if (dx = dy) then
+        inc(cnt, FillLandCircleLinesBG(x, y, dx, dy));
     end;
 
 // draw a hole in land
@@ -409,15 +420,17 @@
     while (dx < dy) do
         begin
         FillLandCircleLines0(x, y, dx, dy);
-        if (d < 0)
-        then d:= d + 4 * dx + 6
-        else begin
+        if (d < 0) then
+            d:= d + 4 * dx + 6
+        else
+            begin
             d:= d + 4 * (dx - dy) + 10;
             dec(dy)
             end;
         inc(dx)
         end;
-    if (dx = dy) then FillLandCircleLines0(x, y, dx, dy);
+    if (dx = dy) then
+        FillLandCircleLines0(x, y, dx, dy);
     end;
 
   // FillRoundInLand after erasing land pixels to allow Land 0 check for mask.png to function
@@ -432,15 +445,17 @@
     while (dx < dy) do
         begin
         FillLandCircleLinesEBC(x, y, dx, dy);
-        if (d < 0)
-        then d:= d + 4 * dx + 6
-        else begin
+        if (d < 0) then
+            d:= d + 4 * dx + 6
+        else
+            begin
             d:= d + 4 * (dx - dy) + 10;
             dec(dy)
             end;
         inc(dx)
         end;
-    if (dx = dy) then FillLandCircleLinesEBC(x, y, dx, dy);
+    if (dx = dy) then
+        FillLandCircleLinesEBC(x, y, dx, dy);
     end;
 
 tx:= Max(X - Radius - 1, 0);
@@ -487,10 +502,10 @@
         for tx:= Max(0, ar^[i].Left - Radius) to Min(LAND_WIDTH, ar^[i].Right + Radius) do
             if ((Land[ty, tx] and lfBasic) <> 0) or ((Land[ty, tx] and lfObject) <> 0) then
                 begin
-                    if (cReducedQuality and rqBlurryLand) = 0 then
-                        LandPixels[ty, tx]:= cExplosionBorderColor
-                    else
-                        LandPixels[ty div 2, tx div 2]:= cExplosionBorderColor;
+                 if (cReducedQuality and rqBlurryLand) = 0 then
+                    LandPixels[ty, tx]:= cExplosionBorderColor
+                else
+                    LandPixels[ty div 2, tx div 2]:= cExplosionBorderColor;
 
                 Land[ty, tx]:= Land[ty, tx] or lfDamaged;
                 LandDirty[ty div 32, tx div 32]:= 1;
@@ -530,10 +545,9 @@
     Y:= Y + dY;
     tx:= hwRound(X);
     ty:= hwRound(Y);
-    if ((ty and LAND_HEIGHT_MASK) = 0) and
-       ((tx and LAND_WIDTH_MASK) = 0) and
-       (((Land[ty, tx] and lfBasic) <> 0) or
-       ((Land[ty, tx] and lfObject) <> 0)) then
+    if ((ty and LAND_HEIGHT_MASK) = 0)
+    and ((tx and LAND_WIDTH_MASK) = 0)
+    and (((Land[ty, tx] and lfBasic) <> 0) or ((Land[ty, tx] and lfObject) <> 0)) then
         begin
         if despeckle then 
             begin
@@ -542,7 +556,8 @@
             end;
         if (cReducedQuality and rqBlurryLand) = 0 then
             LandPixels[ty, tx]:= cExplosionBorderColor
-        else LandPixels[ty div 2, tx div 2]:= cExplosionBorderColor
+        else
+            LandPixels[ty div 2, tx div 2]:= cExplosionBorderColor
         end
     end;
     nx:= nx - dY;
@@ -554,23 +569,23 @@
     X:= nx - dX8;
     Y:= ny - dY8;
     for t:= 0 to 7 do
-    begin
-    X:= X + dX;
-    Y:= Y + dY;
-    tx:= hwRound(X);
-    ty:= hwRound(Y);
-    if ((ty and LAND_HEIGHT_MASK) = 0) and
-       ((tx and LAND_WIDTH_MASK) = 0) and
-       (((Land[ty, tx] and lfBasic) <> 0) or
-       ((Land[ty, tx] and lfObject) <> 0)) then
         begin
-        Land[ty, tx]:= Land[ty, tx] or lfDamaged;
-        if despeckle then LandDirty[ty div 32, tx div 32]:= 1;
-        if (cReducedQuality and rqBlurryLand) = 0 then
-            LandPixels[ty, tx]:= cExplosionBorderColor
-        else LandPixels[ty div 2, tx div 2]:= cExplosionBorderColor
-        end
-    end;
+        X:= X + dX;
+        Y:= Y + dY;
+        tx:= hwRound(X);
+        ty:= hwRound(Y);
+        if ((ty and LAND_HEIGHT_MASK) = 0) and ((tx and LAND_WIDTH_MASK) = 0) and (((Land[ty, tx] and lfBasic) <> 0)
+        or ((Land[ty, tx] and lfObject) <> 0)) then
+            begin
+            Land[ty, tx]:= Land[ty, tx] or lfDamaged;
+            if despeckle then
+                LandDirty[ty div 32, tx div 32]:= 1;
+            if (cReducedQuality and rqBlurryLand) = 0 then
+                LandPixels[ty, tx]:= cExplosionBorderColor
+            else
+                LandPixels[ty div 2, tx div 2]:= cExplosionBorderColor
+            end
+        end;
     X:= nx;
     Y:= ny;
     for t:= 0 to ticks do
@@ -602,18 +617,18 @@
     Y:= Y + dY;
     tx:= hwRound(X);
     ty:= hwRound(Y);
-    if ((ty and LAND_HEIGHT_MASK) = 0) and
-       ((tx and LAND_WIDTH_MASK) = 0) and
-       (((Land[ty, tx] and lfBasic) <> 0) or
-       ((Land[ty, tx] and lfObject) <> 0)) then
+    if ((ty and LAND_HEIGHT_MASK) = 0) and ((tx and LAND_WIDTH_MASK) = 0) and (((Land[ty, tx] and lfBasic) <> 0)
+    or ((Land[ty, tx] and lfObject) <> 0)) then
         begin
         Land[ty, tx]:= Land[ty, tx] or lfDamaged;
-        if despeckle then LandDirty[ty div 32, tx div 32]:= 1;
+        if despeckle then
+            LandDirty[ty div 32, tx div 32]:= 1;
         if (cReducedQuality and rqBlurryLand) = 0 then
             LandPixels[ty, tx]:= cExplosionBorderColor
-        else LandPixels[ty div 2, tx div 2]:= cExplosionBorderColor
+        else
+            LandPixels[ty div 2, tx div 2]:= cExplosionBorderColor
         end
-    end;
+        end;
     nx:= nx - dY;
     ny:= ny + dX;
     end;
@@ -628,16 +643,16 @@
     Y:= Y + dY;
     tx:= hwRound(X);
     ty:= hwRound(Y);
-    if ((ty and LAND_HEIGHT_MASK) = 0) and
-       ((tx and LAND_WIDTH_MASK) = 0) and
-       (((Land[ty, tx] and lfBasic) <> 0) or
-       ((Land[ty, tx] and lfObject) <> 0)) then
+    if ((ty and LAND_HEIGHT_MASK) = 0) and ((tx and LAND_WIDTH_MASK) = 0) and (((Land[ty, tx] and lfBasic) <> 0)
+    or ((Land[ty, tx] and lfObject) <> 0)) then
         begin
         Land[ty, tx]:= Land[ty, tx] or lfDamaged;
-        if despeckle then LandDirty[ty div 32, tx div 32]:= 1;
+        if despeckle then
+            LandDirty[ty div 32, tx div 32]:= 1;
         if (cReducedQuality and rqBlurryLand) = 0 then
             LandPixels[ty, tx]:= cExplosionBorderColor
-        else LandPixels[ty div 2, tx div 2]:= cExplosionBorderColor
+        else
+            LandPixels[ty div 2, tx div 2]:= cExplosionBorderColor
         end
     end;
     nx:= nx - dY;
@@ -667,72 +682,70 @@
 col:= Frame div numFramesFirstCol;
 
 if SDL_MustLock(Image) then
-   SDLTry(SDL_LockSurface(Image) >= 0, true);
+    SDLTry(SDL_LockSurface(Image) >= 0, true);
 
 bpp:= Image^.format^.BytesPerPixel;
 TryDo(bpp = 4, 'It should be 32 bpp sprite', true);
 // Check that sprite fits free space
 p:= @(PByteArray(Image^.pixels)^[ Image^.pitch * row * h + col * w * 4 ]);
 case bpp of
-     4: for y:= 0 to Pred(h) do
-            begin
-            for x:= 0 to Pred(w) do
-                if (PLongword(@(p^[x * 4]))^) <> 0 then
-                   if ((cpY + y) <= Longint(topY)) or
-                      ((cpY + y) >= LAND_HEIGHT) or
-                      ((cpX + x) <= Longint(leftX)) or
-                      ((cpX + x) >= Longint(rightX)) or
-                      (Land[cpY + y, cpX + x] <> 0) then
-                      begin
-                      if SDL_MustLock(Image) then
-                         SDL_UnlockSurface(Image);
-                      exit(false)
-                      end;
-            p:= @(p^[Image^.pitch]);
-            end;
-     end;
+    4: for y:= 0 to Pred(h) do
+        begin
+        for x:= 0 to Pred(w) do
+            if (PLongword(@(p^[x * 4]))^) <> 0 then
+                if ((cpY + y) <= Longint(topY)) or ((cpY + y) >= LAND_HEIGHT)
+                or ((cpX + x) <= Longint(leftX)) or ((cpX + x) >= Longint(rightX)) or (Land[cpY + y, cpX + x] <> 0) then
+                    begin
+                    if SDL_MustLock(Image) then
+                        SDL_UnlockSurface(Image);
+                    exit(false)
+                    end;
+        p:= @(p^[Image^.pitch]);
+        end;
+    end;
 
 TryPlaceOnLand:= true;
 if not doPlace then
-   begin
-   if SDL_MustLock(Image) then
-      SDL_UnlockSurface(Image);
-   exit
-   end;
+    begin
+    if SDL_MustLock(Image) then
+        SDL_UnlockSurface(Image);
+    exit
+    end;
 
 // Checked, now place
 p:= @(PByteArray(Image^.pixels)^[ Image^.pitch * row * h + col * w * 4 ]);
 case bpp of
-     4: for y:= 0 to Pred(h) do
-            begin
-            for x:= 0 to Pred(w) do
-                if (PLongword(@(p^[x * 4]))^) <> 0 then
+    4: for y:= 0 to Pred(h) do
+        begin
+        for x:= 0 to Pred(w) do
+            if (PLongword(@(p^[x * 4]))^) <> 0 then
                    begin
-                   if (cReducedQuality and rqBlurryLand) = 0 then
-                       begin
-                       gX:= cpX + x;
-                       gY:= cpY + y;
-                       end
-                   else
-                       begin
-                       gX:= (cpX + x) div 2;
-                       gY:= (cpY + y) div 2;
-                       end;
-                   if indestructible then
-                       Land[cpY + y, cpX + x]:= lfIndestructible
-                   else if (LandPixels[gY, gX] and AMask) shr AShift = 255 then  // This test assumes lfBasic and lfObject differ only graphically
-                       Land[cpY + y, cpX + x]:= lfBasic
-                   else
-                       Land[cpY + y, cpX + x]:= lfObject;
-                   // For testing only. Intent is to flag this on objects with masks, or use it for an ice ray gun
-                   if (Theme = 'Snow') or (Theme = 'Christmas') then Land[cpY + y, cpX + x]:= Land[cpY + y, cpX + x] or lfIce;
-                   LandPixels[gY, gX]:= PLongword(@(p^[x * 4]))^
-                   end;
-            p:= @(p^[Image^.pitch]);
-            end;
-     end;
+                if (cReducedQuality and rqBlurryLand) = 0 then
+                    begin
+                    gX:= cpX + x;
+                    gY:= cpY + y;
+                    end
+                else
+                     begin
+                     gX:= (cpX + x) div 2;
+                     gY:= (cpY + y) div 2;
+                    end;
+                if indestructible then
+                    Land[cpY + y, cpX + x]:= lfIndestructible
+                else if (LandPixels[gY, gX] and AMask) shr AShift = 255 then  // This test assumes lfBasic and lfObject differ only graphically
+                    Land[cpY + y, cpX + x]:= lfBasic
+                else
+                    Land[cpY + y, cpX + x]:= lfObject;
+                // For testing only. Intent is to flag this on objects with masks, or use it for an ice ray gun
+                if (Theme = 'Snow') or (Theme = 'Christmas') then
+                    Land[cpY + y, cpX + x]:= Land[cpY + y, cpX + x] or lfIce;
+                    LandPixels[gY, gX]:= PLongword(@(p^[x * 4]))^
+                end;
+        p:= @(p^[Image^.pitch]);
+        end;
+    end;
 if SDL_MustLock(Image) then
-   SDL_UnlockSurface(Image);
+    SDL_UnlockSurface(Image);
 
 x:= Max(cpX, leftX);
 w:= Min(cpX + Image^.w, LAND_WIDTH) - x;
@@ -746,15 +759,15 @@
     pixelsweep: boolean;
 begin
 if (cReducedQuality and rqBlurryLand) = 0 then
-   begin
-   xx:= X;
-   yy:= Y;
-   end
+    begin
+    xx:= X;
+    yy:= Y;
+    end
 else
-   begin
-   xx:= X div 2;
-   yy:= Y div 2;
-   end;
+    begin
+    xx:= X div 2;
+    yy:= Y div 2;
+    end;
 pixelsweep:= ((Land[Y, X] and $FF00) = 0) and (LandPixels[yy, xx] <> 0);
 if (((Land[Y, X] and lfDamaged) <> 0) and ((Land[Y, X] and lfIndestructible) = 0)) or pixelsweep then
     begin
@@ -774,9 +787,11 @@
                             nx:= nx div 2;
                             ny:= ny div 2
                             end;
-                        if LandPixels[ny, nx] <> 0 then inc(c);
+                        if LandPixels[ny, nx] <> 0 then
+                            inc(c);
                         end
-                    else if Land[ny, nx] > 255 then inc(c);
+                    else if Land[ny, nx] > 255 then
+                        inc(c);
                     end
                 end;
 
@@ -788,7 +803,8 @@
             LandPixels[yy, xx]:= 0;
 
         Land[Y, X]:= 0;
-        if not pixelsweep then exit(true);
+        if not pixelsweep then
+            exit(true);
         end;
     end;
 Despeckle:= false
@@ -798,69 +814,78 @@
 begin
 // a bit of AA for explosions
 if (Land[Y, X] = 0) and (Y > LongInt(topY) + 1) and 
-   (Y < LAND_HEIGHT-2) and (X > LongInt(leftX) + 1) and (X < LongInt(rightX) - 1) then
+    (Y < LAND_HEIGHT-2) and (X > LongInt(leftX) + 1) and (X < LongInt(rightX) - 1) then
     begin
-    if ((((Land[y, x-1] and lfDamaged) <> 0) and (((Land[y+1,x] and lfDamaged) <> 0)) or ((Land[y-1,x] and lfDamaged) <> 0)) or
-       (((Land[y, x+1] and lfDamaged) <> 0) and (((Land[y-1,x] and lfDamaged) <> 0) or ((Land[y+1,x] and lfDamaged) <> 0)))) then
+    if ((((Land[y, x-1] and lfDamaged) <> 0) and (((Land[y+1,x] and lfDamaged) <> 0)) or ((Land[y-1,x] and lfDamaged) <> 0))
+    or (((Land[y, x+1] and lfDamaged) <> 0) and (((Land[y-1,x] and lfDamaged) <> 0) or ((Land[y+1,x] and lfDamaged) <> 0)))) then
         begin
         if (cReducedQuality and rqBlurryLand) = 0 then
             begin
-            if ((LandPixels[y,x] and AMask) shr AShift) < 10 then LandPixels[y,x]:= (cExplosionBorderColor and (not AMask)) or (128 shl AShift)
+            if ((LandPixels[y,x] and AMask) shr AShift) < 10 then
+                LandPixels[y,x]:= (cExplosionBorderColor and (not AMask)) or (128 shl AShift)
             else
                 LandPixels[y,x]:=
                                 (((((LandPixels[y,x] and RMask shr RShift) div 2)+((cExplosionBorderColor and RMask) shr RShift) div 2) and $FF) shl RShift) or
                                 (((((LandPixels[y,x] and GMask shr GShift) div 2)+((cExplosionBorderColor and GMask) shr GShift) div 2) and $FF) shl GShift) or
                                 (((((LandPixels[y,x] and BMask shr BShift) div 2)+((cExplosionBorderColor and BMask) shr BShift) div 2) and $FF) shl BShift) or ($FF shl AShift)
             end;
-        if (Land[y, x-1] = lfObject) then Land[y,x]:= lfObject
-        else if (Land[y, x+1] = lfObject) then Land[y,x]:= lfObject
-        else Land[y,x]:= lfBasic;
+        if (Land[y, x-1] = lfObject) then
+            Land[y,x]:= lfObject
+        else if (Land[y, x+1] = lfObject) then
+            Land[y,x]:= lfObject
+        else
+            Land[y,x]:= lfBasic;
         end
-    else if ((((Land[y, x-1] and lfDamaged) <> 0) and ((Land[y+1,x-1] and lfDamaged) <> 0) and ((Land[y+2,x] and lfDamaged) <> 0)) or
-            (((Land[y, x-1] and lfDamaged) <> 0) and ((Land[y-1,x-1] and lfDamaged) <> 0) and ((Land[y-2,x] and lfDamaged) <> 0)) or
-            (((Land[y, x+1] and lfDamaged) <> 0) and ((Land[y+1,x+1] and lfDamaged) <> 0) and ((Land[y+2,x] and lfDamaged) <> 0)) or
-            (((Land[y, x+1] and lfDamaged) <> 0) and ((Land[y-1,x+1] and lfDamaged) <> 0) and ((Land[y-2,x] and lfDamaged) <> 0)) or
-            (((Land[y+1, x] and lfDamaged) <> 0) and ((Land[y+1,x+1] and lfDamaged) <> 0) and ((Land[y,x+2] and lfDamaged) <> 0)) or
-            (((Land[y-1, x] and lfDamaged) <> 0) and ((Land[y-1,x+1] and lfDamaged) <> 0) and ((Land[y,x+2] and lfDamaged) <> 0)) or
-            (((Land[y+1, x] and lfDamaged) <> 0) and ((Land[y+1,x-1] and lfDamaged) <> 0) and ((Land[y,x-2] and lfDamaged) <> 0)) or
-            (((Land[y-1, x] and lfDamaged) <> 0) and ((Land[y-1,x-1] and lfDamaged) <> 0) and ((Land[y,x-2] and lfDamaged) <> 0))) then
+    else if ((((Land[y, x-1] and lfDamaged) <> 0) and ((Land[y+1,x-1] and lfDamaged) <> 0) and ((Land[y+2,x] and lfDamaged) <> 0))
+    or (((Land[y, x-1] and lfDamaged) <> 0) and ((Land[y-1,x-1] and lfDamaged) <> 0) and ((Land[y-2,x] and lfDamaged) <> 0))
+    or (((Land[y, x+1] and lfDamaged) <> 0) and ((Land[y+1,x+1] and lfDamaged) <> 0) and ((Land[y+2,x] and lfDamaged) <> 0))
+    or (((Land[y, x+1] and lfDamaged) <> 0) and ((Land[y-1,x+1] and lfDamaged) <> 0) and ((Land[y-2,x] and lfDamaged) <> 0))
+    or (((Land[y+1, x] and lfDamaged) <> 0) and ((Land[y+1,x+1] and lfDamaged) <> 0) and ((Land[y,x+2] and lfDamaged) <> 0))
+    or (((Land[y-1, x] and lfDamaged) <> 0) and ((Land[y-1,x+1] and lfDamaged) <> 0) and ((Land[y,x+2] and lfDamaged) <> 0))
+    or (((Land[y+1, x] and lfDamaged) <> 0) and ((Land[y+1,x-1] and lfDamaged) <> 0) and ((Land[y,x-2] and lfDamaged) <> 0))
+    or (((Land[y-1, x] and lfDamaged) <> 0) and ((Land[y-1,x-1] and lfDamaged) <> 0) and ((Land[y,x-2] and lfDamaged) <> 0))) then
         begin
         if (cReducedQuality and rqBlurryLand) = 0 then
             begin
-            if ((LandPixels[y,x] and AMask) shr AShift) < 10 then LandPixels[y,x]:= (cExplosionBorderColor and (not AMask)) or (64 shl AShift)
+            if ((LandPixels[y,x] and AMask) shr AShift) < 10 then
+                LandPixels[y,x]:= (cExplosionBorderColor and (not AMask)) or (64 shl AShift)
             else
                 LandPixels[y,x]:=
                                 (((((LandPixels[y,x] and RMask shr RShift) * 3 div 4)+((cExplosionBorderColor and RMask) shr RShift) div 4) and $FF) shl RShift) or
                                 (((((LandPixels[y,x] and GMask shr GShift) * 3 div 4)+((cExplosionBorderColor and GMask) shr GShift) div 4) and $FF) shl GShift) or
                                 (((((LandPixels[y,x] and BMask shr BShift) * 3 div 4)+((cExplosionBorderColor and BMask) shr BShift) div 4) and $FF) shl BShift) or ($FF shl AShift)
             end;
-        if (Land[y, x-1] = lfObject) then Land[y, x]:= lfObject
-        else if (Land[y, x+1] = lfObject) then Land[y, x]:= lfObject
-        else if (Land[y+1, x] = lfObject) then Land[y, x]:= lfObject
-        else if (Land[y-1, x] = lfObject) then Land[y, x]:= lfObject
+        if (Land[y, x-1] = lfObject) then
+            Land[y, x]:= lfObject
+        else if (Land[y, x+1] = lfObject) then
+            Land[y, x]:= lfObject
+        else if (Land[y+1, x] = lfObject) then
+            Land[y, x]:= lfObject
+        else if (Land[y-1, x] = lfObject) then
+        Land[y, x]:= lfObject
         else Land[y,x]:= lfBasic
         end
     end
-else if ((cReducedQuality and rqBlurryLand) = 0) and (LandPixels[Y, X] and AMask = 255) and
-    ((Land[Y, X] and (lfDamaged or lfBasic) = lfBasic) or (Land[Y, X] and (lfDamaged or lfBasic) = lfBasic)) and 
-    (Y > LongInt(topY) + 1) and (Y < LAND_HEIGHT-2) and (X > LongInt(leftX) + 1) and (X < LongInt(rightX) - 1) then
+else if ((cReducedQuality and rqBlurryLand) = 0) and (LandPixels[Y, X] and AMask = 255)
+and ((Land[Y, X] and (lfDamaged or lfBasic) = lfBasic) or (Land[Y, X] and (lfDamaged or lfBasic) = lfBasic))
+and (Y > LongInt(topY) + 1) and (Y < LAND_HEIGHT-2) and (X > LongInt(leftX) + 1) and (X < LongInt(rightX) - 1) then
     begin
-    if ((((Land[y, x-1] and lfDamaged) <> 0) and (((Land[y+1,x] and lfDamaged) <> 0)) or ((Land[y-1,x] and lfDamaged) <> 0)) or
-       (((Land[y, x+1] and lfDamaged) <> 0) and (((Land[y-1,x] and lfDamaged) <> 0) or ((Land[y+1,x] and lfDamaged) <> 0)))) then
+    if ((((Land[y, x-1] and lfDamaged) <> 0) and (((Land[y+1,x] and lfDamaged) <> 0)) or ((Land[y-1,x] and lfDamaged) <> 0))
+    or (((Land[y, x+1] and lfDamaged) <> 0) and (((Land[y-1,x] and lfDamaged) <> 0) or ((Land[y+1,x] and lfDamaged) <> 0)))) then
         begin
         LandPixels[y,x]:=
                         (((((LandPixels[y,x] and RMask shr RShift) div 2)+((cExplosionBorderColor and RMask) shr RShift) div 2) and $FF) shl RShift) or
                         (((((LandPixels[y,x] and GMask shr GShift) div 2)+((cExplosionBorderColor and GMask) shr GShift) div 2) and $FF) shl GShift) or
                         (((((LandPixels[y,x] and BMask shr BShift) div 2)+((cExplosionBorderColor and BMask) shr BShift) div 2) and $FF) shl BShift) or ($FF shl AShift)
         end
-    else if ((((Land[y, x-1] and lfDamaged) <> 0) and ((Land[y+1,x-1] and lfDamaged) <> 0) and ((Land[y+2,x] and lfDamaged) <> 0)) or
-            (((Land[y, x-1] and lfDamaged) <> 0) and ((Land[y-1,x-1] and lfDamaged) <> 0) and ((Land[y-2,x] and lfDamaged) <> 0)) or
-            (((Land[y, x+1] and lfDamaged) <> 0) and ((Land[y+1,x+1] and lfDamaged) <> 0) and ((Land[y+2,x] and lfDamaged) <> 0)) or
-            (((Land[y, x+1] and lfDamaged) <> 0) and ((Land[y-1,x+1] and lfDamaged) <> 0) and ((Land[y-2,x] and lfDamaged) <> 0)) or
-            (((Land[y+1, x] and lfDamaged) <> 0) and ((Land[y+1,x+1] and lfDamaged) <> 0) and ((Land[y,x+2] and lfDamaged) <> 0)) or
-            (((Land[y-1, x] and lfDamaged) <> 0) and ((Land[y-1,x+1] and lfDamaged) <> 0) and ((Land[y,x+2] and lfDamaged) <> 0)) or
-            (((Land[y+1, x] and lfDamaged) <> 0) and ((Land[y+1,x-1] and lfDamaged) <> 0) and ((Land[y,x-2] and lfDamaged) <> 0)) or
-            (((Land[y-1, x] and lfDamaged) <> 0) and ((Land[y-1,x-1] and lfDamaged) <> 0) and ((Land[y,x-2] and lfDamaged) <> 0))) then
+    else if ((((Land[y, x-1] and lfDamaged) <> 0) and ((Land[y+1,x-1] and lfDamaged) <> 0) and ((Land[y+2,x] and lfDamaged) <> 0))
+    or (((Land[y, x-1] and lfDamaged) <> 0) and ((Land[y-1,x-1] and lfDamaged) <> 0) and ((Land[y-2,x] and lfDamaged) <> 0))
+    or (((Land[y, x+1] and lfDamaged) <> 0) and ((Land[y+1,x+1] and lfDamaged) <> 0) and ((Land[y+2,x] and lfDamaged) <> 0))
+    or (((Land[y, x+1] and lfDamaged) <> 0) and ((Land[y-1,x+1] and lfDamaged) <> 0) and ((Land[y-2,x] and lfDamaged) <> 0))
+    or (((Land[y+1, x] and lfDamaged) <> 0) and ((Land[y+1,x+1] and lfDamaged) <> 0) and ((Land[y,x+2] and lfDamaged) <> 0))
+    or (((Land[y-1, x] and lfDamaged) <> 0) and ((Land[y-1,x+1] and lfDamaged) <> 0) and ((Land[y,x+2] and lfDamaged) <> 0))
+    or (((Land[y+1, x] and lfDamaged) <> 0) and ((Land[y+1,x-1] and lfDamaged) <> 0) and ((Land[y,x-2] and lfDamaged) <> 0))
+    or (((Land[y-1, x] and lfDamaged) <> 0) and ((Land[y-1,x-1] and lfDamaged) <> 0) and ((Land[y,x-2] and lfDamaged) <> 0))) then
         begin
         LandPixels[y,x]:=
                         (((((LandPixels[y,x] and RMask shr RShift) * 3 div 4)+((cExplosionBorderColor and RMask) shr RShift) div 4) and $FF) shl RShift) or
@@ -922,7 +947,8 @@
                                     end
                                 end;
                     end;
-                if updateBlock then UpdateLandTexture(tx, 32, ty, 32);
+                if updateBlock then
+                    UpdateLandTexture(tx, 32, ty, 32);
                 LandDirty[y, x]:= 2;
                 end;
             end;
@@ -948,18 +974,19 @@
 // Return true if outside of land or not the value tested, used right now for some X/Y movement that does not use normal hedgehog movement in GSHandlers.inc
 function CheckLandValue(X, Y: LongInt; LandFlag: Word): boolean; inline;
 begin
-     CheckLandValue:= ((X and LAND_WIDTH_MASK <> 0) or (Y and LAND_HEIGHT_MASK <> 0)) or ((Land[Y, X] and LandFlag) = 0)
+    CheckLandValue:= ((X and LAND_WIDTH_MASK <> 0) or (Y and LAND_HEIGHT_MASK <> 0)) or ((Land[Y, X] and LandFlag) = 0)
 end;
 
 function LandBackPixel(x, y: LongInt): LongWord; inline;
 var p: PLongWordArray;
 begin
-    if LandBackSurface = nil then LandBackPixel:= 0
+    if LandBackSurface = nil then
+        LandBackPixel:= 0
     else
-    begin
+        begin
         p:= LandBackSurface^.pixels;
         LandBackPixel:= p^[LandBackSurface^.w * (y mod LandBackSurface^.h) + (x mod LandBackSurface^.w)];// or $FF000000;
-    end
+        end
 end;
 
 
@@ -973,24 +1000,32 @@
 dX:= X2 - X1;
 dY:= Y2 - Y1;
 
-if (dX > 0) then sX:= 1
+if (dX > 0) then
+    sX:= 1
 else
-  if (dX < 0) then
-     begin
-     sX:= -1;
-     dX:= -dX
-     end else sX:= dX;
+    if (dX < 0) then
+        begin
+        sX:= -1;
+        dX:= -dX
+        end
+    else
+        sX:= dX;
 
-if (dY > 0) then sY:= 1
-  else
-  if (dY < 0) then
-     begin
-     sY:= -1;
-     dY:= -dY
-     end else sY:= dY;
+if (dY > 0) then
+    sY:= 1
+else
+    if (dY < 0) then
+        begin
+        sY:= -1;
+        dY:= -dY
+        end
+    else
+        sY:= dY;
 
-if (dX > dY) then d:= dX
-             else d:= dY;
+if (dX > dY) then
+    d:= dX
+else
+    d:= dY;
 
 x:= X1;
 y:= Y1;
@@ -1000,18 +1035,18 @@
     inc(eX, dX);
     inc(eY, dY);
     if (eX > d) then
-       begin
-       dec(eX, d);
-       inc(x, sX);
-       end;
+        begin
+        dec(eX, d);
+        inc(x, sX);
+        end;
     if (eY > d) then
-       begin
-       dec(eY, d);
-       inc(y, sY);
-       end;
+        begin
+        dec(eY, d);
+        inc(y, sY);
+        end;
 
     if ((x and LAND_WIDTH_MASK) = 0) and ((y and LAND_HEIGHT_MASK) = 0) then
-       Land[y, x]:= Color;
+        Land[y, x]:= Color;
     end
 end;
 
--- a/hedgewars/uLandObjects.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uLandObjects.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -39,22 +39,22 @@
 type PRectArray = ^TRectsArray;
      TRectsArray = array[0..MaxRects] of TSDL_Rect;
      TThemeObject = record
-                    Surf: PSDL_Surface;
-                    inland: TSDL_Rect;
-                    outland: array[0..Pred(MAXOBJECTRECTS)] of TSDL_Rect;
-                    rectcnt: Longword;
-                    Width, Height: Longword;
-                    Maxcnt: Longword;
-                    end;
+                     Surf: PSDL_Surface;
+                     inland: TSDL_Rect;
+                     outland: array[0..Pred(MAXOBJECTRECTS)] of TSDL_Rect;
+                     rectcnt: Longword;
+                     Width, Height: Longword;
+                     Maxcnt: Longword;
+                     end;
      TThemeObjects = record
                      Count: LongInt;
                      objs: array[0..Pred(MAXTHEMEOBJECTS)] of TThemeObject;
                      end;
      TSprayObject = record
-                    Surf: PSDL_Surface;
-                    Width, Height: Longword;
-                    Maxcnt: Longword;
-                    end;
+                     Surf: PSDL_Surface;
+                     Width, Height: Longword;
+                     Maxcnt: Longword;
+                     end;
      TSprayObjects = record
                      Count: LongInt;
                      objs: array[0..Pred(MAXTHEMEOBJECTS)] of TSprayObject
@@ -74,12 +74,13 @@
 WriteToConsole('Generating collision info... ');
 
 if SDL_MustLock(Image) then
-   SDLTry(SDL_LockSurface(Image) >= 0, true);
+    SDLTry(SDL_LockSurface(Image) >= 0, true);
 
 bpp:= Image^.format^.BytesPerPixel;
 TryDo(bpp = 4, 'Land object should be 32bit', true);
 
-if Width = 0 then Width:= Image^.w;
+if Width = 0 then
+    Width:= Image^.w;
 
 p:= Image^.pixels;
 for y:= 0 to Pred(Image^.h) do
@@ -89,8 +90,8 @@
             begin
             if (cReducedQuality and rqBlurryLand) = 0 then
                 begin
-                if (LandPixels[cpY + y, cpX + x] = 0) or 
-		   (((p^[x] and AMask) <> 0) and (((LandPixels[cpY + y, cpX + x] and AMask) shr AShift) < 255)) then
+                if (LandPixels[cpY + y, cpX + x] = 0)
+                or (((p^[x] and AMask) <> 0) and (((LandPixels[cpY + y, cpX + x] and AMask) shr AShift) < 255)) then
                     LandPixels[cpY + y, cpX + x]:= p^[x];
                 end
             else
@@ -107,19 +108,19 @@
     end;
 
 if SDL_MustLock(Image) then
-   SDL_UnlockSurface(Image);
+    SDL_UnlockSurface(Image);
 WriteLnToConsole(msgOK)
 end;
 
 procedure AddRect(x1, y1, w1, h1: LongInt);
 begin
 with Rects^[RectCount] do
-     begin
-     x:= x1;
-     y:= y1;
-     w:= w1;
-     h:= h1
-     end;
+    begin
+    x:= x1;
+    y:= y1;
+    w:= w1;
+    h:= h1
+    end;
 inc(RectCount);
 TryDo(RectCount < MaxRects, 'AddRect: overflow', true)
 end;
@@ -142,12 +143,11 @@
 
 i:= 0;
 if RectCount > 0 then
-   repeat
-   with Rects^[i] do
-        res:= (x < x1 + w1) and (x1 < x + w) and
-                 (y < y1 + h1) and (y1 < y + h);
-   inc(i)
-   until (i = RectCount) or (res);
+    repeat
+    with Rects^[i] do
+        res:= (x < x1 + w1) and (x1 < x + w) and (y < y1 + h1) and (y1 < y + h);
+    inc(i)
+    until (i = RectCount) or (res);
 CheckIntersect:= res;
 end;
 
@@ -158,7 +158,8 @@
 begin
     lRes:= 0;
     for i:= y to y + 15 do
-        if Land[i, x] <> 0 then inc(lRes);
+        if Land[i, x] <> 0 then
+            inc(lRes);
     CountNonZeroz:= lRes;
 end;
 
@@ -174,7 +175,8 @@
     x1:= gX;
     x2:= gX;
 
-    while (x1 > Longint(leftX)+150) and (CountNonZeroz(x1, y) = 0) do dec(x1, 2);
+    while (x1 > Longint(leftX)+150) and (CountNonZeroz(x1, y) = 0) do
+        dec(x1, 2);
 
     i:= x1 - 12;
     repeat
@@ -185,14 +187,17 @@
     inc(x1, 2);
     if k = 16 then
         begin
-        while (x2 < (rightX-150)) and (CountNonZeroz(x2, y) = 0) do inc(x2, 2);
+        while (x2 < (rightX-150)) and (CountNonZeroz(x2, y) = 0) do
+            inc(x2, 2);
         i:= x2 + 12;
         repeat
         inc(x2, 2);
         k:= CountNonZeroz(x2, y)
         until (x2 >= (rightX-150)) or (k = 0) or (k = 16) or (x2 > i) or (x2 - x1 >= 768);
+        
         if (x2 < (rightX - 150)) and (k = 16) and (x2 - x1 > 250) and (x2 - x1 < 768)
-            and (not CheckIntersect(x1 - 32, y - 64, x2 - x1 + 64, 144)) then break;
+        and (not CheckIntersect(x1 - 32, y - 64, x2 - x1 + 64, 144)) then
+                break;
         end;
 x1:= 0;
 until y > (LAND_HEIGHT-125);
@@ -201,9 +206,12 @@
 begin
     bRes:= true;
     tmpsurf:= LoadImage(UserPathz[ptCurrTheme] + '/Girder', ifTransparent or ifIgnoreCaps);
-    if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptCurrTheme] + '/Girder', ifTransparent or ifIgnoreCaps);
-    if tmpsurf = nil then tmpsurf:= LoadImage(UserPathz[ptGraphics] + '/Girder', ifTransparent or ifIgnoreCaps);
-    if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptGraphics] + '/Girder', ifCritical or ifTransparent or ifIgnoreCaps);
+    if tmpsurf = nil then
+        tmpsurf:= LoadImage(Pathz[ptCurrTheme] + '/Girder', ifTransparent or ifIgnoreCaps);
+    if tmpsurf = nil then
+        tmpsurf:= LoadImage(UserPathz[ptGraphics] + '/Girder', ifTransparent or ifIgnoreCaps);
+    if tmpsurf = nil then
+        tmpsurf:= LoadImage(Pathz[ptGraphics] + '/Girder', ifCritical or ifTransparent or ifIgnoreCaps);
 
     rr.x:= x1;
     while rr.x < x2 do
@@ -236,25 +244,25 @@
 tmpx:= rect.x;
 tmpx2:= bx;
 while (tmpx <= bx - rect.w div 2 - 1) and bRes do
-      begin
-      bRes:= ((rect.y and LAND_HEIGHT_MASK) = 0) and ((by and LAND_HEIGHT_MASK) = 0) and
-             ((tmpx and LAND_WIDTH_MASK) = 0) and ((tmpx2 and LAND_WIDTH_MASK) = 0) and
-             (Land[rect.y, tmpx] = Color) and (Land[by, tmpx] = Color) and
-             (Land[rect.y, tmpx2] = Color) and (Land[by, tmpx2] = Color);
-      inc(tmpx);
-      dec(tmpx2)
-      end;
+    begin
+    bRes:= ((rect.y and LAND_HEIGHT_MASK) = 0) and ((by and LAND_HEIGHT_MASK) = 0)
+    and ((tmpx and LAND_WIDTH_MASK) = 0) and ((tmpx2 and LAND_WIDTH_MASK) = 0)
+    and (Land[rect.y, tmpx] = Color) and (Land[by, tmpx] = Color)
+    and (Land[rect.y, tmpx2] = Color) and (Land[by, tmpx2] = Color);
+    inc(tmpx);
+    dec(tmpx2)
+    end;
 tmpy:= rect.y+1;
 tmpy2:= by-1;
 while (tmpy <= by - rect.h div 2 - 1) and bRes do
-      begin
-      bRes:= ((tmpy and LAND_HEIGHT_MASK) = 0) and ((tmpy2 and LAND_HEIGHT_MASK) = 0) and
-             ((rect.x and LAND_WIDTH_MASK) = 0) and ((bx and LAND_WIDTH_MASK) = 0) and
-             (Land[tmpy, rect.x] = Color) and (Land[tmpy, bx] = Color) and
-             (Land[tmpy2, rect.x] = Color) and (Land[tmpy2, bx] = Color);
-      inc(tmpy);
-      dec(tmpy2)
-      end;
+    begin
+    bRes:= ((tmpy and LAND_HEIGHT_MASK) = 0) and ((tmpy2 and LAND_HEIGHT_MASK) = 0)
+    and ((rect.x and LAND_WIDTH_MASK) = 0) and ((bx and LAND_WIDTH_MASK) = 0)
+    and (Land[tmpy, rect.x] = Color) and (Land[tmpy, bx] = Color)
+    and (Land[tmpy2, rect.x] = Color) and (Land[tmpy2, bx] = Color);
+    inc(tmpy);
+    dec(tmpy2)
+    end;
 {$WARNINGS ON}
 CheckLand:= bRes;
 end;
@@ -264,18 +272,19 @@
     bRes: boolean;
 begin
 with Obj do
-     if CheckLand(inland, x, y, lfBasic) then
+    if CheckLand(inland, x, y, lfBasic) then
         begin
         bRes:= true;
         i:= 1;
         while bRes and (i <= rectcnt) do
-              begin
-              bRes:= CheckLand(outland[i], x, y, 0);
-              inc(i)
-              end;
+            begin
+            bRes:= CheckLand(outland[i], x, y, 0);
+            inc(i)
+            end;
         if bRes then
-           bRes:= not CheckIntersect(x, y, Width, Height)
-        end else
+            bRes:= not CheckIntersect(x, y, Width, Height)
+        end
+    else
         bRes:= false;
 CheckCanPlace:= bRes;
 end;
@@ -289,37 +298,38 @@
 begin
 cnt:= 0;
 with Obj do
-     begin
-     if Maxcnt = 0 then
+    begin
+    if Maxcnt = 0 then
         exit(false);
-     x:= 0;
-     repeat
-         y:= topY+32; // leave room for a hedgie to teleport in
-         repeat
-             if CheckCanPlace(x, y, Obj) then
+    x:= 0;
+    repeat
+        y:= topY+32; // leave room for a hedgie to teleport in
+        repeat
+            if CheckCanPlace(x, y, Obj) then
                 begin
                 ar[cnt].x:= x;
                 ar[cnt].y:= y;
                 inc(cnt);
                 if cnt > MaxPointsIndex then // buffer is full, do not check the rest land
-                   begin
-                   y:= 5000;
-                   x:= 5000;
-                   end
+                    begin
+                    y:= 5000;
+                    x:= 5000;
+                    end
                 end;
-             inc(y, 3);
-         until y >= LAND_HEIGHT - Height;
-         inc(x, getrandom(6) + 3)
-     until x >= LAND_WIDTH - Width;
-     bRes:= cnt <> 0;
-     if bRes then
+            inc(y, 3);
+        until y >= LAND_HEIGHT - Height;
+        inc(x, getrandom(6) + 3)
+    until x >= LAND_WIDTH - Width;
+    bRes:= cnt <> 0;
+    if bRes then
         begin
         i:= getrandom(cnt);
         BlitImageAndGenerateCollisionInfo(ar[i].x, ar[i].y, 0, Obj.Surf);
         AddRect(ar[i].x, ar[i].y, Width, Height);
         dec(Maxcnt)
-        end else Maxcnt:= 0
-     end;
+        end
+    else Maxcnt:= 0
+    end;
 TryPut:= bRes;
 end;
 
@@ -346,16 +356,16 @@
         repeat
             if CheckLand(r, x, y - 8, lfBasic)
             and (not CheckIntersect(x, y, Width, Height)) then
-            begin
-            ar[cnt].x:= x;
-            ar[cnt].y:= y;
-            inc(cnt);
-            if cnt > MaxPointsIndex then // buffer is full, do not check the rest land
                 begin
-                y:= 5000;
-                x:= 5000;
-                end
-            end;
+                ar[cnt].x:= x;
+                ar[cnt].y:= y;
+                inc(cnt);
+                if cnt > MaxPointsIndex then // buffer is full, do not check the rest land
+                    begin
+                    y:= 5000;
+                    x:= 5000;
+                    end
+                end;
             inc(y, 12);
         until y >= LAND_HEIGHT - Height - 8;
         inc(x, getrandom(12) + 12)
@@ -371,7 +381,8 @@
         SDL_UpperBlit(Obj.Surf, nil, Surface, @r);
         AddRect(ar[i].x - 32, ar[i].y - 32, Width + 64, Height + 64);
         dec(Maxcnt)
-        end else Maxcnt:= 0
+        end
+    else Maxcnt:= 0
     end;
 TryPut:= bRes;
 end;
@@ -400,7 +411,8 @@
     for i:= 0 to 3 do
         begin
         t:= round(SDWaterColorArray[i].r * RGB_LUMINANCE_RED + SDWaterColorArray[i].g * RGB_LUMINANCE_GREEN + SDWaterColorArray[i].b * RGB_LUMINANCE_BLUE);
-        if t > 255 then t:= 255;
+        if t > 255 then
+            t:= 255;
         SDWaterColorArray[i].r:= t;
         SDWaterColorArray[i].g:= t;
         SDWaterColorArray[i].b:= t
@@ -408,7 +420,8 @@
     for i:= 0 to 1 do
         begin
         t:= round(WaterColorArray[i].r * RGB_LUMINANCE_RED + WaterColorArray[i].g * RGB_LUMINANCE_GREEN + WaterColorArray[i].b * RGB_LUMINANCE_BLUE);
-        if t > 255 then t:= 255;
+        if t > 255 then
+            t:= 255;
         WaterColorArray[i].r:= t;
         WaterColorArray[i].g:= t;
         WaterColorArray[i].b:= t
@@ -416,7 +429,8 @@
     end;
 
 s:= UserPathz[ptCurrTheme] + '/' + cThemeCFGFilename;
-if not FileExists(s) then s:= Pathz[ptCurrTheme] + '/' + cThemeCFGFilename;
+if not FileExists(s) then
+    s:= Pathz[ptCurrTheme] + '/' + cThemeCFGFilename;
 WriteLnToConsole('Reading objects info...');
 Assign(f, s);
 {$I-}
@@ -429,8 +443,10 @@
 while not eof(f) do
     begin
     Readln(f, s);
-    if Length(s) = 0 then continue;
-    if s[1] = ';' then continue;
+    if Length(s) = 0 then
+        continue;
+    if s[1] = ';' then
+        continue;
 
     i:= Pos('=', s);
     key:= Trim(Copy(s, 1, Pred(i)));
@@ -445,10 +461,12 @@
         SkyColor.g:= StrToInt(Trim(Copy(s, 1, Pred(i))));
         Delete(s, 1, i);
         SkyColor.b:= StrToInt(Trim(s));
-        if cGrayScale then
+        if cGrayScale
+            then
             begin
             t:= round(SkyColor.r * RGB_LUMINANCE_RED + SkyColor.g * RGB_LUMINANCE_GREEN + SkyColor.b * RGB_LUMINANCE_BLUE);
-            if t > 255 then t:= 255;
+            if t > 255 then
+                t:= 255;
             SkyColor.r:= t;
             SkyColor.g:= t;
             SkyColor.b:= t
@@ -470,7 +488,8 @@
         if cGrayScale then
             begin
             t:= round(SkyColor.r * RGB_LUMINANCE_RED + SkyColor.g * RGB_LUMINANCE_GREEN + SkyColor.b * RGB_LUMINANCE_BLUE);
-            if t > 255 then t:= 255;
+            if t > 255 then
+                t:= 255;
             c2.r:= t;
             c2.g:= t;
             c2.b:= t
@@ -490,7 +509,8 @@
         if cGrayScale then
             begin
             t:= round(WaterColorArray[0].r * RGB_LUMINANCE_RED + WaterColorArray[0].g * RGB_LUMINANCE_GREEN + WaterColorArray[0].b * RGB_LUMINANCE_BLUE);
-            if t > 255 then t:= 255;
+            if t > 255 then
+                t:= 255;
             WaterColorArray[0].r:= t;
             WaterColorArray[0].g:= t;
             WaterColorArray[0].b:= t
@@ -510,7 +530,8 @@
         if cGrayScale then
             begin
             t:= round(WaterColorArray[2].r * RGB_LUMINANCE_RED + WaterColorArray[2].g * RGB_LUMINANCE_GREEN + WaterColorArray[2].b * RGB_LUMINANCE_BLUE);
-            if t > 255 then t:= 255;
+            if t > 255 then
+                t:= 255;
             WaterColorArray[2].r:= t;
             WaterColorArray[2].g:= t;
             WaterColorArray[2].b:= t
@@ -522,7 +543,8 @@
         cWaterOpacity:= StrToInt(Trim(s));
         cSDWaterOpacity:= cWaterOpacity
         end
-    else if key = 'music' then MusicFN:= Trim(s)
+    else if key = 'music' then
+        MusicFN:= Trim(s)
     else if key = 'clouds' then
         begin
         cCloudsNumber:= Word(StrToInt(Trim(s))) * cScreenSpace div LAND_WIDTH;
@@ -535,14 +557,16 @@
             begin
             i:= Pos(',', s);
             Surf:= LoadImage(UserPathz[ptCurrTheme] + '/' + Trim(Copy(s, 1, Pred(i))), ifTransparent or ifIgnoreCaps);
-            if Surf = nil then Surf:= LoadImage(Pathz[ptCurrTheme] + '/' + Trim(Copy(s, 1, Pred(i))), ifCritical or ifTransparent or ifIgnoreCaps);
+            if Surf = nil then
+                Surf:= LoadImage(Pathz[ptCurrTheme] + '/' + Trim(Copy(s, 1, Pred(i))), ifCritical or ifTransparent or ifIgnoreCaps);
             Width:= Surf^.w;
             Height:= Surf^.h;
             Delete(s, 1, i);
             i:= Pos(',', s);
             Maxcnt:= StrToInt(Trim(Copy(s, 1, Pred(i))));
             Delete(s, 1, i);
-            if (Maxcnt < 1) or (Maxcnt > MAXTHEMEOBJECTS) then OutError('Object''s max count should be between 1 and '+ inttostr(MAXTHEMEOBJECTS) +' (it was '+ inttostr(Maxcnt) +').', true);
+            if (Maxcnt < 1) or (Maxcnt > MAXTHEMEOBJECTS) then
+                OutError('Object''s max count should be between 1 and '+ inttostr(MAXTHEMEOBJECTS) +' (it was '+ inttostr(Maxcnt) +').', true);
             with inland do
                 begin
                 i:= Pos(',', s);
@@ -574,7 +598,8 @@
                     i:= Pos(',', s);
                     w:= StrToInt(Trim(Copy(s, 1, Pred(i))));
                     Delete(s, 1, i);
-                    if ii = rectcnt then h:= StrToInt(Trim(s))
+                    if ii = rectcnt then
+                        h:= StrToInt(Trim(s))
                     else
                         begin
                         i:= Pos(',', s);
@@ -592,7 +617,8 @@
             begin
             i:= Pos(',', s);
             Surf:= LoadImage(UserPathz[ptCurrTheme] + '/' + Trim(Copy(s, 1, Pred(i))), ifTransparent or ifIgnoreCaps);
-            if Surf = nil then Surf:= LoadImage(Pathz[ptCurrTheme] + '/' + Trim(Copy(s, 1, Pred(i))), ifCritical or ifTransparent or ifIgnoreCaps);
+            if Surf = nil then
+                Surf:= LoadImage(Pathz[ptCurrTheme] + '/' + Trim(Copy(s, 1, Pred(i))), ifCritical or ifTransparent or ifIgnoreCaps);
             Width:= Surf^.w;
             Height:= Surf^.h;
             Delete(s, 1, i);
@@ -618,8 +644,10 @@
             vobFallSpeed:= StrToInt(Trim(s));
             end;
         end
-    else if key = 'flatten-flakes' then cFlattenFlakes:= true
-    else if key = 'flatten-clouds' then cFlattenClouds:= true
+    else if key = 'flatten-flakes' then
+        cFlattenFlakes:= true
+    else if key = 'flatten-clouds' then
+        cFlattenClouds:= true
     else if key = 'sd-water-top' then
         begin
         i:= Pos(',', s);
@@ -633,7 +661,8 @@
         if cGrayScale then
             begin
             t:= round(SDWaterColorArray[0].r * RGB_LUMINANCE_RED + SDWaterColorArray[0].g * RGB_LUMINANCE_GREEN + SDWaterColorArray[0].b * RGB_LUMINANCE_BLUE);
-            if t > 255 then t:= 255;
+            if t > 255 then
+                t:= 255;
             SDWaterColorArray[0].r:= t;
             SDWaterColorArray[0].g:= t;
             SDWaterColorArray[0].b:= t
@@ -653,15 +682,18 @@
         if cGrayScale then
             begin
             t:= round(SDWaterColorArray[2].r * RGB_LUMINANCE_RED + SDWaterColorArray[2].g * RGB_LUMINANCE_GREEN + SDWaterColorArray[2].b * RGB_LUMINANCE_BLUE);
-            if t > 255 then t:= 255;
+            if t > 255 then
+                t:= 255;
             SDWaterColorArray[2].r:= t;
             SDWaterColorArray[2].g:= t;
             SDWaterColorArray[2].b:= t
             end;
         SDWaterColorArray[3]:= SDWaterColorArray[2];
         end
-    else if key = 'sd-water-opacity' then cSDWaterOpacity:= StrToInt(Trim(s))
-    else if key = 'sd-clouds' then cSDCloudsNumber:= Word(StrToInt(Trim(s))) * cScreenSpace div LAND_WIDTH
+    else if key = 'sd-water-opacity' then
+        cSDWaterOpacity:= StrToInt(Trim(s))
+    else if key = 'sd-clouds' then
+        cSDCloudsNumber:= Word(StrToInt(Trim(s))) * cScreenSpace div LAND_WIDTH
     else if key = 'sd-flakes' then
         begin
         i:= Pos(',', s);
@@ -695,7 +727,8 @@
             if cGrayScale then
                 begin
                 t:= round(RQSkyColor.r * RGB_LUMINANCE_RED + RQSkyColor.g * RGB_LUMINANCE_GREEN + RQSkyColor.b * RGB_LUMINANCE_BLUE);
-                if t > 255 then t:= 255;
+                if t > 255 then
+                    t:= 255;
                 RQSkyColor.r:= t;
                 RQSkyColor.g:= t;
                 RQSkyColor.b:= t
@@ -718,7 +751,8 @@
 var i, ii, t: LongInt;
     b: boolean;
 begin
-    if ThemeObjects.Count = 0 then exit;
+    if ThemeObjects.Count = 0 then
+        exit;
     WriteLnToConsole('Adding theme objects...');
 
     for i:=0 to ThemeObjects.Count do
@@ -741,7 +775,8 @@
 var i, ii, t: LongInt;
     b: boolean;
 begin
-    if SprayObjects.Count = 0 then exit;
+    if SprayObjects.Count = 0 then
+        exit;
     WriteLnToConsole('Adding spray objects...');
 
     for i:=0 to SprayObjects.Count do
@@ -773,7 +808,8 @@
         i:=i+int;
     until (i>rightX-int);
     end;
-if (GameFlags and gfDisableLandObjects) = 0 then AddThemeObjects(ThemeObjects);
+if (GameFlags and gfDisableLandObjects) = 0 then
+    AddThemeObjects(ThemeObjects);
 AddProgress();
 FreeRects();
 end;
--- a/hedgewars/uLandOutline.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uLandOutline.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -31,14 +31,15 @@
 begin
     TryDo(Stack.Count <= 8192, 'FillLand: stack overflow', true);
     _y:= _y + _dir;
-    if (_y < 0) or (_y >= LAND_HEIGHT) then exit;
+    if (_y < 0) or (_y >= LAND_HEIGHT) then
+        exit;
     with Stack.points[Stack.Count] do
-            begin
-            xl:= _xl;
-            xr:= _xr;
-            y:= _y;
-            dir:= _dir
-            end;
+        begin
+        xl:= _xl;
+        xr:= _xr;
+        y:= _y;
+        dir:= _dir
+        end;
     inc(Stack.Count)
 end;
 
@@ -66,11 +67,14 @@
     while Stack.Count > 0 do
         begin
         Pop(xl, xr, y, dir);
-        while (xl > 0) and (Land[y, xl] <> 0) do dec(xl);
-        while (xr < LAND_WIDTH - 1) and (Land[y, xr] <> 0) do inc(xr);
+        while (xl > 0) and (Land[y, xl] <> 0) do
+            dec(xl);
+        while (xr < LAND_WIDTH - 1) and (Land[y, xr] <> 0) do
+            inc(xr);
         while (xl < xr) do
             begin
-            while (xl <= xr) and (Land[y, xl] = 0) do inc(xl);
+            while (xl <= xr) and (Land[y, xl] = 0) do
+                inc(xl);
             x:= xl;
             while (xl <= xr) and (Land[y, xl] <> 0) do
                 begin
@@ -112,8 +116,10 @@
     d1:= DistanceI(p2.X - p3.X, p2.Y - p3.Y);
     d2:= Distance(Vx, Vy);
 
-    if d1 < d then d:= d1;
-    if d2 < d then d:= d2;
+    if d1 < d then
+        d:= d1;
+    if d2 < d then
+        d:= d2;
 
     d:= d * _1div3;
 
@@ -148,11 +154,14 @@
 {$HINTS ON}
 repeat
     inc(pi);
-    if pi > EndI then pi:= StartI;
+    if pi > EndI then
+        pi:= StartI;
     inc(i);
-    if i > EndI then i:= StartI;
+    if i > EndI then
+        i:= StartI;
     inc(ni);
-    if ni > EndI then ni:= StartI;
+    if ni > EndI then
+        ni:= StartI;
     PVx:= NVx;
     PVy:= NVy;
     Vector(opa.ar[pi], opa.ar[i], opa.ar[ni], NVx, NVy);
@@ -167,20 +176,20 @@
     cy2:= int2hwFloat(y2) + NVy;
     t:= _0;
     while t.Round = 0 do
-          begin
-          tsq:= t * t;
-          tcb:= tsq * t;
-          r1:= (_1 - t*3 + tsq*3 - tcb);
-          r2:= (     t*3 - tsq*6 + tcb*3);
-          r3:= (           tsq*3 - tcb*3);
-          X:= hwRound(r1 * x1 + r2 * cx1 + r3 * cx2 + tcb * x2);
-          Y:= hwRound(r1 * y1 + r2 * cy1 + r3 * cy2 + tcb * y2);
-          t:= t + Delta;
-          pa.ar[pa.Count].x:= X;
-          pa.ar[pa.Count].y:= Y;
-          inc(pa.Count);
-          TryDo(pa.Count <= cMaxEdgePoints, 'Edge points overflow', true)
-          end;
+        begin
+        tsq:= t * t;
+        tcb:= tsq * t;
+        r1:= (_1 - t*3 + tsq*3 - tcb);
+        r2:= (     t*3 - tsq*6 + tcb*3);
+        r3:= (           tsq*3 - tcb*3);
+        X:= hwRound(r1 * x1 + r2 * cx1 + r3 * cx2 + tcb * x2);
+        Y:= hwRound(r1 * y1 + r2 * cy1 + r3 * cy2 + tcb * y2);
+        t:= t + Delta;
+        pa.ar[pa.Count].x:= X;
+        pa.ar[pa.Count].y:= Y;
+        inc(pa.Count);
+        TryDo(pa.Count <= cMaxEdgePoints, 'Edge points overflow', true)
+        end;
 until i = StartI;
 pa.ar[pa.Count].x:= opa.ar[StartI].X;
 pa.ar[pa.Count].y:= opa.ar[StartI].Y;
@@ -197,14 +206,14 @@
 StartLoop:= 0;
 while i < LongInt(opa.Count) do
     if (opa.ar[i + 1].X = NTPX) then
-       begin
-       AddLoopPoints(pa, opa, StartLoop, i, Delta);
-       inc(i, 2);
-       StartLoop:= i;
-       pa.ar[pa.Count].X:= NTPX;
-       pa.ar[pa.Count].Y:= 0;
-       inc(pa.Count);
-       end else inc(i)
+        begin
+        AddLoopPoints(pa, opa, StartLoop, i, Delta);
+        inc(i, 2);
+        StartLoop:= i;
+        pa.ar[pa.Count].X:= NTPX;
+        pa.ar[pa.Count].Y:= 0;
+        inc(pa.Count);
+        end else inc(i)
 end;
 
 
@@ -213,18 +222,23 @@
 begin
     dm:= (V4.y - V3.y) * (V2.x - V1.x) - (V4.x - V3.x) * (V2.y - V1.y);
     c1:= (V4.x - V3.x) * (V1.y - V3.y) - (V4.y - V3.y) * (V1.x - V3.x);
-    if dm = 0 then exit(false);
+    if dm = 0 then
+            exit(false);
 
     c2:= (V2.x - V3.x) * (V1.y - V3.y) - (V2.y - V3.y) * (V1.x - V3.x);
     if dm > 0 then
         begin
-        if (c1 < 0) or (c1 > dm) then exit(false);
-        if (c2 < 0) or (c2 > dm) then exit(false)
+        if (c1 < 0) or (c1 > dm) then
+            exit(false);
+        if (c2 < 0) or (c2 > dm) then
+            exit(false)
         end 
     else
         begin
-        if (c1 > 0) or (c1 < dm) then exit(false);
-        if (c2 > 0) or (c2 < dm) then exit(false)
+        if (c1 > 0) or (c1 < dm) then
+            exit(false);
+        if (c2 > 0) or (c2 < dm) then
+            exit(false)
         end;
 
     //AddFileLog('1  (' + inttostr(V1.x) + ',' + inttostr(V1.y) + ')x(' + inttostr(V2.x) + ',' + inttostr(V2.y) + ')');
@@ -236,14 +250,17 @@
 function CheckSelfIntersect(var pa: TPixAr; ind: Longword): boolean;
 var i: Longword;
 begin
-    if (ind <= 0) or (ind >= Pred(pa.Count)) then exit(false);
+    if (ind <= 0) or (ind >= Pred(pa.Count)) then
+                exit(false);
     for i:= 1 to pa.Count - 3 do
         if (i <= ind - 1) or (i >= ind + 2) then
         begin
         if (i <> ind - 1) and
-            CheckIntersect(pa.ar[ind], pa.ar[ind - 1], pa.ar[i], pa.ar[i - 1]) then exit(true);
+            CheckIntersect(pa.ar[ind], pa.ar[ind - 1], pa.ar[i], pa.ar[i - 1]) then
+                exit(true);
         if (i <> ind + 2) and
-            CheckIntersect(pa.ar[ind], pa.ar[ind + 1], pa.ar[i], pa.ar[i - 1]) then exit(true);
+            CheckIntersect(pa.ar[ind], pa.ar[ind + 1], pa.ar[i], pa.ar[i - 1]) then
+                exit(true);
         end;
     CheckSelfIntersect:= false
 end;
@@ -289,4 +306,4 @@
 end;
 
 
-end.
\ No newline at end of file
+end.
--- a/hedgewars/uLandPainted.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uLandPainted.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -59,24 +59,32 @@
     dX:= X2 - X1;
     dY:= Y2 - Y1;
 
-    if (dX > 0) then sX:= 1
+    if (dX > 0) then
+        sX:= 1
     else
-    if (dX < 0) then
-        begin
-        sX:= -1;
-        dX:= -dX
-        end else sX:= dX;
+        if (dX < 0) then
+            begin
+            sX:= -1;
+            dX:= -dX
+            end
+        else
+            sX:= dX;
 
-    if (dY > 0) then sY:= 1
+    if (dY > 0) then
+        sY:= 1
     else
-    if (dY < 0) then
-        begin
-        sY:= -1;
-        dY:= -dY
-        end else sY:= dY;
+        if (dY < 0) then
+            begin
+            sY:= -1;
+            dY:= -dY
+            end
+        else
+            sY:= dY;
 
-        if (dX > dY) then d:= dX
-                    else d:= dY;
+        if (dX > dY) then
+            d:= dX
+        else
+            d:= dY;
 
         x:= X1;
         y:= Y1;
@@ -101,7 +109,8 @@
             if b then
                 begin
                 inc(len);
-                if (len mod 4) = 0 then FillRoundInLand(X, Y, 34, lfBasic)
+                if (len mod 4) = 0 then
+                    FillRoundInLand(X, Y, 34, lfBasic)
                 end
         end
 end;
--- a/hedgewars/uLandTexture.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uLandTexture.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -65,7 +65,8 @@
 procedure UpdateLandTexture(X, Width, Y, Height: LongInt);
 var tx, ty: Longword;
 begin
-    if (Width <= 0) or (Height <= 0) then exit;
+    if (Width <= 0) or (Height <= 0) then
+        exit;
     TryDo((X >= 0) and (X < LAND_WIDTH), 'UpdateLandTexture: wrong X parameter', true);
     TryDo(X + Width <= LAND_WIDTH, 'UpdateLandTexture: wrong Width parameter', true);
     TryDo((Y >= 0) and (Y < LAND_HEIGHT), 'UpdateLandTexture: wrong Y parameter', true);
@@ -89,9 +90,9 @@
         for y:= 0 to LANDTEXARH - 1 do
             with LandTextures[x, y] do
                 begin
-                    tex:= NewTexture(TEXSIZE, TEXSIZE, Pixels(x, y));
-                    glBindTexture(GL_TEXTURE_2D, tex^.id);
-                    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY, tpHigh);
+                tex:= NewTexture(TEXSIZE, TEXSIZE, Pixels(x, y));
+                glBindTexture(GL_TEXTURE_2D, tex^.id);
+                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY, tpHigh);
                 end
 else
     for x:= 0 to LANDTEXARW -1 do
--- a/hedgewars/uLocale.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uLocale.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -44,45 +44,55 @@
     loaded: boolean;
 begin
 loaded:= false;
-for e:= Low(TEventId) to High(TEventId) do first[e]:= true;
+for e:= Low(TEventId) to High(TEventId) do
+    first[e]:= true;
 
 {$I-} // iochecks off
 Assign(f, FileName);
 filemode:= 0; // readonly
 Reset(f);
-if IOResult = 0 then loaded:= true;
+if IOResult = 0 then
+    loaded:= true;
 TryDo(loaded, 'Cannot load locale "' + FileName + '"', false);
 if loaded then
-   begin
-   while not eof(f) do
-       begin
-       readln(f, s);
-       if Length(s) = 0 then continue;
-       if (s[1] < '0') or (s[1] > '9') then continue;
-       TryDo(Length(s) > 6, 'Load locale: empty string', true);
-       val(s[1]+s[2], a, c);
-       TryDo(c = 0, 'Load locale: numbers should be two-digit: ' + s, true);
-       TryDo(s[3] = ':', 'Load locale: ":" expected', true);
-       val(s[4]+s[5], b, c);
-       TryDo(c = 0, 'Load locale: numbers should be two-digit' + s, true);
-       TryDo(s[6] = '=', 'Load locale: "=" expected', true);
-       Delete(s, 1, 6);
-       case a of
-           0: if (b >=0) and (b <= ord(High(TAmmoStrId))) then trammo[TAmmoStrId(b)]:= s;
-           1: if (b >=0) and (b <= ord(High(TMsgStrId))) then trmsg[TMsgStrId(b)]:= s;
-           2: if (b >=0) and (b <= ord(High(TEventId))) then begin
-               TryDo(trevt_n[TEventId(b)] < MAX_EVENT_STRINGS, 'Too many event strings in ' + IntToStr(a) + ':' + IntToStr(b), false);
-               if first[TEventId(b)] then
-                   begin
-                   trevt_n[TEventId(b)]:= 0;
-                   first[TEventId(b)]:= false;
-                   end;
-               trevt[TEventId(b)][trevt_n[TEventId(b)]]:= s;
-               inc(trevt_n[TEventId(b)]);
-               end;
-           3: if (b >=0) and (b <= ord(High(TAmmoStrId))) then trammoc[TAmmoStrId(b)]:= s;
-           4: if (b >=0) and (b <= ord(High(TAmmoStrId))) then trammod[TAmmoStrId(b)]:= s;
-           5: if (b >=0) and (b <= ord(High(TGoalStrId))) then trgoal[TGoalStrId(b)]:= s;
+    begin
+    while not eof(f) do
+        begin
+        readln(f, s);
+        if Length(s) = 0 then
+            continue;
+        if (s[1] < '0') or (s[1] > '9') then
+            continue;
+        TryDo(Length(s) > 6, 'Load locale: empty string', true);
+        val(s[1]+s[2], a, c);
+        TryDo(c = 0, 'Load locale: numbers should be two-digit: ' + s, true);
+        TryDo(s[3] = ':', 'Load locale: ":" expected', true);
+        val(s[4]+s[5], b, c);
+        TryDo(c = 0, 'Load locale: numbers should be two-digit' + s, true);
+        TryDo(s[6] = '=', 'Load locale: "=" expected', true);
+        Delete(s, 1, 6);
+        case a of
+            0: if (b >=0) and (b <= ord(High(TAmmoStrId))) then
+                trammo[TAmmoStrId(b)]:= s;
+            1: if (b >=0) and (b <= ord(High(TMsgStrId))) then
+                trmsg[TMsgStrId(b)]:= s;
+            2: if (b >=0) and (b <= ord(High(TEventId))) then
+                begin
+                TryDo(trevt_n[TEventId(b)] < MAX_EVENT_STRINGS, 'Too many event strings in ' + IntToStr(a) + ':' + IntToStr(b), false);
+                if first[TEventId(b)] then
+                    begin
+                    trevt_n[TEventId(b)]:= 0;
+                    first[TEventId(b)]:= false;
+                    end;
+                trevt[TEventId(b)][trevt_n[TEventId(b)]]:= s;
+                inc(trevt_n[TEventId(b)]);
+                end;
+            3: if (b >=0) and (b <= ord(High(TAmmoStrId))) then
+                trammoc[TAmmoStrId(b)]:= s;
+            4: if (b >=0) and (b <= ord(High(TAmmoStrId))) then
+                trammod[TAmmoStrId(b)]:= s;
+            5: if (b >=0) and (b <= ord(High(TGoalStrId))) then
+                trgoal[TGoalStrId(b)]:= s;
            end;
        end;
    Close(f);
@@ -103,16 +113,20 @@
 var i: LongInt;
 begin
 i:= Pos('%1', fmt);
-if i = 0 then Format:= fmt
-         else Format:= copy(fmt, 1, i - 1) + arg + Format(copy(fmt, i + 2, Length(fmt) - i - 1), arg)
+if i = 0 then
+    Format:= fmt
+else
+    Format:= copy(fmt, 1, i - 1) + arg + Format(copy(fmt, i + 2, Length(fmt) - i - 1), arg)
 end;
 
 function Format(fmt: ansistring; var arg: ansistring): ansistring;
 var i: LongInt;
 begin
 i:= Pos('%1', fmt);
-if i = 0 then Format:= fmt
-         else Format:= copy(fmt, 1, i - 1) + arg + Format(copy(fmt, i + 2, Length(fmt) - i - 1), arg)
+if i = 0 then
+    Format:= fmt
+else
+    Format:= copy(fmt, 1, i - 1) + arg + Format(copy(fmt, i + 2, Length(fmt) - i - 1), arg)
 end;
 
 procedure LoadLocaleWrapper(str: pchar); cdecl; export;
--- a/hedgewars/uMobile.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uMobile.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -82,9 +82,7 @@
 procedure AmmoUpdate; // do not inline
 begin
 {$IFDEF IPHONEOS}
-    if (CurrentTeam = nil) or
-       (CurrentTeam^.ExtDriven) or
-       (CurrentTeam^.Hedgehogs[0].BotLevel <> 0) then
+    if (CurrentTeam = nil) or (CurrentTeam^.ExtDriven) or (CurrentTeam^.Hedgehogs[0].BotLevel <> 0) then
         exit(); // the other way around throws a compiler error
     updateVisualsNewTurn();
 {$ENDIF}
--- a/hedgewars/uRandom.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uRandom.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -60,7 +60,8 @@
 begin
 n:= 54;
 
-if Length(Seed) > 54 then Seed:= copy(Seed, 1, 54); // not 55 to ensure we have odd numbers in cirbuf
+if Length(Seed) > 54 then
+    Seed:= copy(Seed, 1, 54); // not 55 to ensure we have odd numbers in cirbuf
 
 for i:= 0 to Pred(Length(Seed)) do
     cirbuf[i]:= byte(Seed[i + 1]);
@@ -68,7 +69,8 @@
 for i:= Length(Seed) to 54 do
     cirbuf[i]:= $A98765 + 68; // odd number
 
-for i:= 0 to 1023 do GetNext
+for i:= 0 to 1023 do
+    GetNext
 end;
 
 function GetRandom: hwFloat;
--- a/hedgewars/uRender.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uRender.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -66,7 +66,8 @@
     _l, _r, _t, _b: real;
     VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
 begin
-if (SourceTexture^.h = 0) or (SourceTexture^.w = 0) then exit;
+if (SourceTexture^.h = 0) or (SourceTexture^.w = 0) then
+    exit;
 
 // do not draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs)
 if (abs(X) > W) and ((abs(X + W / 2) - W / 2) > cScreenWidth / cScaleFactor) then
@@ -206,10 +207,11 @@
 glTranslatef(X, Y, 0);
 
 if Dir < 0 then
-   glRotatef(Angle, 0, 0, -1)
+    glRotatef(Angle, 0, 0, -1)
 else
-   glRotatef(Angle, 0, 0,  1);
-if Dir < 0 then glScalef(-1.0, 1.0, 1.0);
+    glRotatef(Angle, 0, 0,  1);
+if Dir < 0 then
+    glScalef(-1.0, 1.0, 1.0);
 
 DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame);
 
@@ -229,11 +231,12 @@
 glTranslatef(X, Y, 0);
 
 if Dir < 0 then
-   begin
-   hw:= - hw;
-   glRotatef(Angle, 0, 0, -1);
-   end else
-   glRotatef(Angle, 0, 0,  1);
+    begin
+    hw:= - hw;
+    glRotatef(Angle, 0, 0, -1);
+    end
+else
+    glRotatef(Angle, 0, 0,  1);
 
 
 glBindTexture(GL_TEXTURE_2D, Tex^.id);
@@ -257,7 +260,8 @@
 procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt);
 var row, col, numFramesFirstCol: LongInt;
 begin
-if SpritesData[Sprite].imageHeight = 0 then exit;
+if SpritesData[Sprite].imageHeight = 0 then
+    exit;
 numFramesFirstCol:= SpritesData[Sprite].imageHeight div SpritesData[Sprite].Height;
 row:= Frame mod numFramesFirstCol;
 col:= Frame div numFramesFirstCol;
@@ -410,13 +414,14 @@
     b:= (Pos + 1) * 32 / HHTexture^.h;
 
     if Dir = -1 then
-    begin
-    l:= (Step + 1) * 32 / HHTexture^.w;
-    r:= Step * 32 / HHTexture^.w
-    end else
-    begin
-    l:= Step * 32 / HHTexture^.w;
-    r:= (Step + 1) * 32 / HHTexture^.w
+        begin
+        l:= (Step + 1) * 32 / HHTexture^.w;
+        r:= Step * 32 / HHTexture^.w
+        end
+    else
+        begin
+        l:= Step * 32 / HHTexture^.w;
+        r:= (Step + 1) * 32 / HHTexture^.w
     end;
 
 
@@ -457,7 +462,8 @@
 if cGrayScale then
     begin
     tw:= round(r * RGB_LUMINANCE_RED + g * RGB_LUMINANCE_GREEN + b * RGB_LUMINANCE_BLUE);
-    if tw > 255 then tw:= 255;
+    if tw > 255 then
+        tw:= 255;
     r:= tw;
     g:= tw;
     b:= tw
--- a/hedgewars/uRenderUtils.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uRenderUtils.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -37,7 +37,8 @@
 var r: TSDL_Rect;
 begin
     r:= rect^;
-    if Clear then SDL_FillRect(Surface, @r, 0);
+    if Clear then
+        SDL_FillRect(Surface, @r, 0);
 
     BorderColor:= SDL_MapRGB(Surface^.format, BorderColor shr 16, BorderColor shr 8, BorderColor and $FF);
     FillColor:= SDL_MapRGB(Surface^.format, FillColor shr 16, FillColor shr 8, FillColor and $FF);
@@ -226,11 +227,13 @@
 
     numLines:= 0;
 
-    if length(s) = 0 then s:= '...';
+    if length(s) = 0 then
+        s:= '...';
     font:= CheckCJKFont(s, font);
     w:= 0; h:= 0; // avoid compiler hints
     TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), @w, @h);
-    if w<8 then w:= 8;
+    if w<8 then
+        w:= 8;
     j:= 0;
     if (length(s) > 20) then
         begin
@@ -249,7 +252,8 @@
                 substr:= copy(s, prevpos+1, pos-prevpos-1);
                 i:= 0; j:= 0;
                 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(substr), @i, @j);
-                if i > w then w:= i;
+                if i > w then
+                    w:= i;
                 prevpos:= pos;
                 end;
             inc(pos);
@@ -347,22 +351,24 @@
         begin
         if (s[pos] = #1) or (pos = length(s)) then
             begin
-            if s[pos] <> #1 then inc(pos);
-            while s[prevpos+1] = ' 'do inc(prevpos);
+            if s[pos] <> #1 then
+                inc(pos);
+            while s[prevpos+1] = ' 'do
+                inc(prevpos);
             substr:= copy(s, prevpos+1, pos-prevpos-1);
             if Length(substr) <> 0 then
-            begin
-            tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(substr), cNearBlackColorChannels);
-            rect.x:= edgeHeight + 1 + ((i - w) div 2);
-            // trying to more evenly position the text, vertically
-            rect.y:= edgeHeight + ((j-(numLines*h)) div 2) + line * h;
-            SDLTry(tmpsurf <> nil, true);
-            SDL_UpperBlit(tmpsurf, nil, finalSurface, @rect);
-            SDL_FreeSurface(tmpsurf);
-            inc(line);
-            prevpos:= pos;
-            end;
-            end;
+                begin
+                tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(substr), cNearBlackColorChannels);
+                rect.x:= edgeHeight + 1 + ((i - w) div 2);
+                // trying to more evenly position the text, vertically
+                rect.y:= edgeHeight + ((j-(numLines*h)) div 2) + line * h;
+                SDLTry(tmpsurf <> nil, true);
+                SDL_UpperBlit(tmpsurf, nil, finalSurface, @rect);
+                SDL_FreeSurface(tmpsurf);
+                inc(line);
+                prevpos:= pos;
+                end;
+                end;
         inc(pos);
         end;
 
--- a/hedgewars/uScript.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uScript.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -112,7 +112,8 @@
         LuaError('Lua: Wrong number of parameters passed to band!');
         lua_pushnil(L);
         end
-    else lua_pushinteger(L, lua_tointeger(L, 2) and lua_tointeger(L, 1));
+    else
+        lua_pushinteger(L, lua_tointeger(L, 2) and lua_tointeger(L, 1));
     lc_band := 1;
 end;
 
@@ -123,7 +124,8 @@
         LuaError('Lua: Wrong number of parameters passed to bor!');
         lua_pushnil(L);
         end
-    else lua_pushinteger(L, lua_tointeger(L, 2) or lua_tointeger(L, 1));
+    else
+        lua_pushinteger(L, lua_tointeger(L, 2) or lua_tointeger(L, 1));
     lc_bor := 1;
 end;
 
@@ -134,7 +136,8 @@
         LuaError('Lua: Wrong number of parameters passed to bnot!');
         lua_pushnil(L);
         end
-    else lua_pushinteger(L, not lua_tointeger(L, 1));
+    else
+        lua_pushinteger(L, not lua_tointeger(L, 1));
     lc_bnot := 1;
 end;
 
@@ -142,7 +145,8 @@
 begin
     if lua_gettop(L) <> 0 then
         LuaError('Lua: Wrong number of parameters passed to GetInputMask!')
-    else lua_pushinteger(L, InputMask);
+    else
+        lua_pushinteger(L, InputMask);
     lc_getinputmask:= 1
 end;
 
@@ -150,7 +154,8 @@
 begin
     if lua_gettop(L) <> 1 then
         LuaError('Lua: Wrong number of parameters passed to SetInputMask!')
-    else InputMask:= lua_tointeger(L, 1);
+    else
+        InputMask:= lua_tointeger(L, 1);
     lc_setinputmask:= 0
 end;
 
@@ -232,45 +237,51 @@
 function lc_spawnfakehealthcrate(L: Plua_State) : LongInt; Cdecl;
 var gear: PGear;
 begin
-    if lua_gettop(L) <> 4 then begin
+    if lua_gettop(L) <> 4 then
+        begin
         LuaError('Lua: Wrong number of parameters passed to SpawnFakeHealthCrate!');
         lua_pushnil(L);
-    end
-    else begin
+        end
+    else
+        begin
         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
-            HealthCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
+        HealthCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
         lua_pushinteger(L, gear^.uid);
-    end;
+        end;
     lc_spawnfakehealthcrate := 1;        
 end;
 
 function lc_spawnfakeammocrate(L: PLua_State): LongInt; Cdecl;
 var gear: PGear;
 begin
-    if lua_gettop(L) <> 4 then begin
+    if lua_gettop(L) <> 4 then
+        begin
         LuaError('Lua: Wrong number of parameters passed to SpawnFakeAmmoCrate!');
         lua_pushnil(L);
-    end
-    else begin
+        end
+    else
+        begin
         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
-            AmmoCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
+        AmmoCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
         lua_pushinteger(L, gear^.uid);
-    end;
+        end;
     lc_spawnfakeammocrate := 1;
 end;
 
 function lc_spawnfakeutilitycrate(L: PLua_State): LongInt; Cdecl;
 var gear: PGear;
 begin
-    if lua_gettop(L) <> 4 then begin
+    if lua_gettop(L) <> 4 then
+        begin
         LuaError('Lua: Wrong number of parameters passed to SpawnFakeUtilityCrate!');
         lua_pushnil(L);
-    end
-    else begin  
+        end
+    else
+        begin  
         gear := SpawnFakeCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
-            UtilityCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
+        UtilityCrate, lua_toboolean(L, 3), lua_toboolean(L, 4));
         lua_pushinteger(L, gear^.uid);
-    end;
+        end;
     lc_spawnfakeutilitycrate := 1;
 end;
 
@@ -278,48 +289,62 @@
 var gear: PGear;
 var health: LongInt;
 begin
-    if (lua_gettop(L) < 2) or (lua_gettop(L) > 3) then begin
+    if (lua_gettop(L) < 2) or (lua_gettop(L) > 3) then
+        begin
         LuaError('Lua: Wrong number of parameters passed to SpawnHealthCrate!');
         lua_pushnil(L);
-    end
-    else begin
-        if lua_gettop(L) = 3 then health:= lua_tointeger(L, 3)
-        else health:= cHealthCaseAmount;
+        end
+    else
+        begin
+        if lua_gettop(L) = 3 then
+            health:= lua_tointeger(L, 3)
+        else
+            health:= cHealthCaseAmount;
         gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), HealthCrate, health);
-        if gear <> nil then lua_pushinteger(L, gear^.uid)
-        else lua_pushnil(L);
-    end;
+        if gear <> nil then
+            lua_pushinteger(L, gear^.uid)
+        else
+            lua_pushnil(L);
+        end;
     lc_spawnhealthcrate := 1;        
 end;
 
 function lc_spawnammocrate(L: PLua_State): LongInt; Cdecl;
 var gear: PGear;
 begin
-    if lua_gettop(L) <> 3 then begin
+    if lua_gettop(L) <> 3 then
+        begin
         LuaError('Lua: Wrong number of parameters passed to SpawnAmmoCrate!');
         lua_pushnil(L);
-    end
-    else begin
+        end
+    else
+        begin
         gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2), AmmoCrate, lua_tointeger(L, 3));
-        if gear <> nil then lua_pushinteger(L, gear^.uid)
-        else lua_pushnil(L);
-    end;
+        if gear <> nil then
+            lua_pushinteger(L, gear^.uid)
+        else
+            lua_pushnil(L);
+        end;
     lc_spawnammocrate := 1;
 end;
 
 function lc_spawnutilitycrate(L: PLua_State): LongInt; Cdecl;
 var gear: PGear;
 begin
-    if lua_gettop(L) <> 3 then begin
+    if lua_gettop(L) <> 3 then
+        begin
         LuaError('Lua: Wrong number of parameters passed to SpawnUtilityCrate!');
         lua_pushnil(L);
-    end
-    else begin  
+        end
+    else
+        begin  
         gear := SpawnCustomCrateAt(lua_tointeger(L, 1), lua_tointeger(L, 2),
-            UtilityCrate, lua_tointeger(L, 3));
-        if gear <> nil then lua_pushinteger(L, gear^.uid)
-        else lua_pushnil(L);
-    end;
+        UtilityCrate, lua_tointeger(L, 3));
+        if gear <> nil then
+            lua_pushinteger(L, gear^.uid)
+        else
+            lua_pushnil(L);
+       end;
     lc_spawnutilitycrate := 1;
 end;
 
@@ -361,7 +386,8 @@
     else
         begin
         gear:= GearByUID(lua_tointeger(L, 1));
-        if gear <> nil then DeleteGear(gear);
+        if gear <> nil then
+            DeleteGear(gear);
         end;
     lc_deletegear:= 0
 end;
@@ -391,7 +417,8 @@
             lastVisualGearByUID:= vg;
             lua_pushinteger(L, vg^.uid)
             end
-        else lua_pushinteger(L, 0)
+        else
+            lua_pushinteger(L, 0)
         end;
     lc_addvisualgear:= 1; // 1 return value
 end;
@@ -406,7 +433,8 @@
     else
         begin
         vg:= VisualGearByUID(lua_tointeger(L, 1));
-        if vg <> nil then DeleteVisualGear(vg);
+        if vg <> nil then
+            DeleteVisualGear(vg);
         end;
     lc_deletevisualgear:= 0
 end;
@@ -464,7 +492,8 @@
             vg^.dY:= lua_tonumber(L, 5);
             vg^.Angle:= lua_tonumber(L, 6);
             vg^.Frame:= lua_tointeger(L, 7);
-            if lua_tointeger(L, 8) <> 0 then vg^.FrameTicks:= lua_tointeger(L, 8);  // find a better way to do this. maybe need to break all these up.
+            if lua_tointeger(L, 8) <> 0 then
+                vg^.FrameTicks:= lua_tointeger(L, 8);  // find a better way to do this. maybe need to break all these up.
             vg^.State:= lua_tointeger(L, 9);
             vg^.Timer:= lua_tointeger(L, 10);
             vg^.Tint:= lua_tointeger(L, 11);
@@ -597,7 +626,8 @@
 begin
     if lua_gettop(L) <> 1 then
         LuaError('Lua: Wrong number of parameters passed to GetHogLevel!')
-    else begin
+    else
+        begin
         gear := GearByUID(lua_tointeger(L, 1));
         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
             lua_pushinteger(L, gear^.Hedgehog^.BotLevel)
@@ -759,10 +789,10 @@
         gear:= GearByUID(lua_tointeger(L, 1));
         if (gear <> nil) and (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
 
-	    hogName:= lua_tostring(L, 2);
+        hogName:= lua_tostring(L, 2);
             gear^.Hedgehog^.Name:= hogName;
 
-	    FreeTexture(gear^.Hedgehog^.NameTagTex);
+        FreeTexture(gear^.Hedgehog^.NameTagTex);
         gear^.Hedgehog^.NameTagTex:= RenderStringTex(gear^.Hedgehog^.Name, gear^.Hedgehog^.Team^.Clan^.Color, fnt16);
 
         end;
@@ -885,8 +915,10 @@
    vgear : PVisualGear;
        s : LongWord;
 begin
-    if lua_gettop(L) = 4 then s:= lua_tointeger(L, 4)
-    else s:= 0;
+    if lua_gettop(L) = 4 then
+        s:= lua_tointeger(L, 4)
+    else
+        s:= 0;
 
     if (lua_gettop(L) = 4) or (lua_gettop(L) = 3) then
         begin
@@ -899,11 +931,13 @@
                vgear^.Text:= lua_tostring(L, 2);
                vgear^.Hedgehog:= gear^.Hedgehog;
                vgear^.FrameTicks:= lua_tointeger(L, 3);
-               if (vgear^.FrameTicks < 1) or (vgear^.FrameTicks > 3) then vgear^.FrameTicks:= 1;
+               if (vgear^.FrameTicks < 1) or (vgear^.FrameTicks > 3) then
+                   vgear^.FrameTicks:= 1;
                lua_pushinteger(L, vgear^.Uid)
                end
             end
-            else lua_pushnil(L)
+            else
+                lua_pushnil(L)
         end
     else LuaError('Lua: Wrong number of parameters passed to HogSay!');
     lc_hogsay:= 1
@@ -947,19 +981,19 @@
 
     if lua_gettop(L) = 3 then
     begin
-	gear:= GearByUID(lua_tointeger(L, 1));
+    gear:= GearByUID(lua_tointeger(L, 1));
         if (gear <> nil) and (gear^.Hedgehog <> nil) then
             AddAmmoAmount(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2)), lua_tointeger(L,3) );
     end else
     
     if lua_gettop(L) = 2 then
     begin
-	gear:= GearByUID(lua_tointeger(L, 1));
+    gear:= GearByUID(lua_tointeger(L, 1));
         if (gear <> nil) and (gear^.Hedgehog <> nil) then
             AddAmmo(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2)));
     end else
     begin
-    	LuaError('Lua: Wrong number of parameters passed to AddAmmo!');
+        LuaError('Lua: Wrong number of parameters passed to AddAmmo!');
     end;
 
     lc_addammo:= 0;
@@ -973,8 +1007,10 @@
         begin
         gear:= GearByUID(lua_tointeger(L, 1));
         if (gear <> nil) and (gear^.Hedgehog <> nil) then
-            if lua_gettop(L) = 2 then AddAmmo(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2)))
-            else AddAmmo(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2)), lua_tointeger(L, 3))
+            if lua_gettop(L) = 2 then
+                AddAmmo(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2)))
+            else
+                AddAmmo(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2)), lua_tointeger(L, 3))
         end
     else LuaError('Lua: Wrong number of parameters passed to AddAmmo!');
     lc_addammo:= 0
@@ -990,8 +1026,10 @@
         if (gear <> nil) and (gear^.Hedgehog <> nil) then 
             begin
             ammo:= GetAmmoEntry(gear^.Hedgehog^, TAmmoType(lua_tointeger(L, 2)));
-            if ammo^.AmmoType = amNothing then lua_pushinteger(L, 0)
-            else lua_pushinteger(L, ammo^.Count)
+            if ammo^.AmmoType = amNothing then
+                lua_pushinteger(L, 0)
+            else
+                lua_pushinteger(L, ammo^.Count)
             end
         else lua_pushinteger(L, 0)
         end
@@ -1017,9 +1055,9 @@
             begin
             gear^.Health:= lua_tointeger(L, 2);
 
-	    if (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
+        if (gear^.Kind = gtHedgehog) and (gear^.Hedgehog <> nil) then
             begin  
-		RenderHealth(gear^.Hedgehog^);
+        RenderHealth(gear^.Hedgehog^);
             end;
 
             SetAllToActive;
@@ -1151,11 +1189,14 @@
         fall:= lua_toboolean(L, 2);
         left:= lua_tointeger(L, 3);
         right:= lua_tointeger(L, 4);
-        if lua_gettop(L) = 5 then tryhard:= lua_toboolean(L, 5);
+        if lua_gettop(L) = 5 then
+            tryhard:= lua_toboolean(L, 5);
         if gear <> nil then
             FindPlace(gear, fall, left, right, tryhard);
-        if gear <> nil then lua_pushinteger(L, gear^.uid)
-        else lua_pushnil(L);
+        if gear <> nil then
+            lua_pushinteger(L, gear^.uid)
+        else
+            lua_pushnil(L);
         end;
     lc_findplace:= 1
 end;
@@ -1273,10 +1314,12 @@
             col:= gear^.CollisionIndex >= 0;
             x:= lua_tointeger(L, 2);
             y:= lua_tointeger(L, 3);
-            if col then DeleteCI(gear);
+            if col then
+                DeleteCI(gear);
             gear^.X:= int2hwfloat(x);
             gear^.Y:= int2hwfloat(y);
-            if col then AddGearCI(gear);
+            if col then
+                AddGearCI(gear);
             SetAllToActive
             end
         end;
@@ -1372,8 +1415,10 @@
     else
         begin
         ZoomValue:= lua_tonumber(L, 1);
-        if ZoomValue < cMaxZoomLevel then ZoomValue:= cMaxZoomLevel;
-        if ZoomValue > cMinZoomLevel then ZoomValue:= cMinZoomLevel;
+        if ZoomValue < cMaxZoomLevel then
+            ZoomValue:= cMaxZoomLevel;
+        if ZoomValue > cMinZoomLevel then
+            ZoomValue:= cMinZoomLevel;
         end;
     lc_setzoom:= 0
 end;
@@ -1607,42 +1652,43 @@
 
 procedure ScriptClearStack;
 begin
-lua_settop(luaState, 0)
+    lua_settop(luaState, 0)
 end;
 
 procedure ScriptSetNil(name : shortstring);
 begin
-lua_pushnil(luaState);
-lua_setglobal(luaState, Str2PChar(name));
+    lua_pushnil(luaState);
+    lua_setglobal(luaState, Str2PChar(name));
 end;
 
 procedure ScriptSetInteger(name : shortstring; value : LongInt);
 begin
-lua_pushinteger(luaState, value);
-lua_setglobal(luaState, Str2PChar(name));
+    lua_pushinteger(luaState, value);
+    lua_setglobal(luaState, Str2PChar(name));
 end;
 
 procedure ScriptSetString(name : shortstring; value : shortstring);
 begin
-lua_pushstring(luaState, Str2PChar(value));
-lua_setglobal(luaState, Str2PChar(name));
+    lua_pushstring(luaState, Str2PChar(value));
+    lua_setglobal(luaState, Str2PChar(name));
 end;
 
 function ScriptGetInteger(name : shortstring) : LongInt;
 begin
-lua_getglobal(luaState, Str2PChar(name));
-ScriptGetInteger:= lua_tointeger(luaState, -1);
-lua_pop(luaState, 1);
+    lua_getglobal(luaState, Str2PChar(name));
+    ScriptGetInteger:= lua_tointeger(luaState, -1);
+    lua_pop(luaState, 1);
 end;
 
 function ScriptGetString(name : shortstring) : shortstring;
 begin
-lua_getglobal(luaState, Str2PChar(name));
-ScriptGetString:= lua_tostring(luaState, -1);
-lua_pop(luaState, 1);
+    lua_getglobal(luaState, Str2PChar(name));
+    ScriptGetString:= lua_tostring(luaState, -1);
+    lua_pop(luaState, 1);
 end;
 
 procedure ScriptOnGameInit;
+var i, j, k: LongInt;
 begin
 // not required if there is no script to run
 if not ScriptLoaded then
@@ -1704,6 +1750,29 @@
     ParseCommand('theme ' + ScriptGetString('Theme'), true);
 LuaGoals:= ScriptGetString('Goals');
 
+// Support lua changing the ammo layout - assume all hogs have same ammo, note this might leave a few ammo stores lying around.
+k:= 0;
+if (GameFlags and gfSharedAmmo) <> 0 then
+    for i:= 0 to Pred(ClansCount) do
+        for j:= 0 to Pred(ClansArray[i]^.TeamsNumber) do
+            for k:= 0 to Pred(ClansArray[i]^.Teams[j]^.HedgehogsNumber) do
+                ClansArray[i]^.Teams[j]^.Hedgehogs[k].AmmoStore:= i
+else if (GameFlags and gfPerHogAmmo) <> 0 then
+    for i:= 0 to Pred(TeamsCount) do
+        for j:= 0 to Pred(TeamsArray[i]^.HedgehogsNumber) do
+            begin
+            TeamsArray[i]^.Hedgehogs[j].AmmoStore:= k;
+            if StoreCnt-1 < k then AddAmmoStore;
+            inc(k)
+            end
+else 
+    for i:= 0 to Pred(TeamsCount) do
+        begin
+        for j:= 0 to Pred(TeamsArray[i]^.HedgehogsNumber) do
+            TeamsArray[i]^.Hedgehogs[j].AmmoStore:= k;
+        if StoreCnt-1 < k then AddAmmoStore;
+        inc(k)
+        end;
 if ScriptExists('onAmmoStoreInit') then
     begin
     ScriptPrepareAmmoStore;
@@ -1730,8 +1799,10 @@
       s : shortstring;
 begin
 s:= UserPathz[ptData] + '/' + name;
-if not FileExists(s) then s:= Pathz[ptData] + '/' + name;
-if not FileExists(s) then exit;
+if not FileExists(s) then
+    s:= Pathz[ptData] + '/' + name;
+if not FileExists(s) then
+    exit;
 
 ret:= luaL_loadfile(luaState, Str2PChar(s));
 if ret <> 0 then
@@ -1783,7 +1854,8 @@
 function ParseCommandOverride(key, value : shortstring) : shortstring;
 begin
 ParseCommandOverride:= value;
-if not ScriptExists('ParseCommandOverride') then exit;
+if not ScriptExists('ParseCommandOverride') then
+    exit;
 lua_getglobal(luaState, Str2PChar('ParseCommandOverride'));
 lua_pushstring(luaState, Str2PChar(key));
 lua_pushstring(luaState, Str2PChar(value));
--- a/hedgewars/uSinTable.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uSinTable.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -1045,7 +1045,7 @@
      $FFFF4E59,
      $FFFFB10B,
      $FFFFEC43,
-    $100000000
+     $100000000
      );
 
 implementation
--- a/hedgewars/uSound.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uSound.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -111,20 +111,25 @@
         begin
         locName:= name+'_'+cLocale;
         path:= UserPathz[ptVoices] + '/' + locName;
-        if DirectoryExists(path) then name:= locName
+        if DirectoryExists(path) then
+            name:= locName
         else
             begin
             path:= Pathz[ptVoices] + '/' + locName;
-            if DirectoryExists(path) then name:= locName
-            else if Length(cLocale) > 2 then
+            if DirectoryExists(path) then
+                name:= locName
+            else if Length(cLocale) > 2
+                then
                 begin
                 locName:= name+'_'+Copy(cLocale,1,2);
                 path:= UserPathz[ptVoices] + '/' + locName;
-                if DirectoryExists(path) then name:= locName
+                if DirectoryExists(path) then
+                    name:= locName
                 else
                     begin
                     path:= Pathz[ptVoices] + '/' + locName;
-                    if DirectoryExists(path) then name:= locName
+                    if DirectoryExists(path) then
+                        name:= locName
                     end
                 end
             end
@@ -145,7 +150,8 @@
 var i: TSound;
     channels: LongInt;
 begin
-    if not isSoundEnabled then exit;
+    if not isSoundEnabled then
+        exit;
     WriteToConsole('Init sound...');
     isSoundEnabled:= SDL_InitSubSystem(SDL_INIT_AUDIO) >= 0;
 
@@ -218,7 +224,8 @@
 var i: TSound;
     t: Longword;
 begin
-    if not isSoundEnabled then exit;
+    if not isSoundEnabled then
+        exit;
 
     defVoicepack:= AskForVoicepack('Default');
 
@@ -277,7 +284,8 @@
         if (voicepack^.chunks[snd] = nil) and (Soundz[snd].Path = ptVoices) and (Soundz[snd].FileName <> '') then
             begin
             s:= UserPathz[Soundz[snd].Path] + '/' + voicepack^.name + '/' + Soundz[snd].FileName;
-            if not FileExists(s) then s:= Pathz[Soundz[snd].Path] + '/' + voicepack^.name + '/' + Soundz[snd].FileName;
+            if not FileExists(s) then
+                s:= Pathz[Soundz[snd].Path] + '/' + voicepack^.name + '/' + Soundz[snd].FileName;
             WriteToConsole(msgLoading + s + ' ');
             voicepack^.chunks[snd]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1);
             if voicepack^.chunks[snd] = nil then
@@ -292,7 +300,8 @@
         if (defVoicepack^.chunks[snd] = nil) and (Soundz[snd].Path <> ptVoices) and (Soundz[snd].FileName <> '') then
             begin
             s:= UserPathz[Soundz[snd].Path] + '/' + Soundz[snd].FileName;
-            if not FileExists(s) then s:= Pathz[Soundz[snd].Path] + '/' + Soundz[snd].FileName;
+            if not FileExists(s) then
+                s:= Pathz[Soundz[snd].Path] + '/' + Soundz[snd].FileName;
             WriteToConsole(msgLoading + s + ' ');
             defVoicepack^.chunks[snd]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1);
             SDLTry(defVoicepack^.chunks[snd] <> nil, true);
@@ -305,19 +314,23 @@
 procedure AddVoice(snd: TSound; voicepack: PVoicepack);
 var i : LongInt;
 begin
-    if (not isSoundEnabled) or fastUntilLag or ((LastVoice.snd = snd) and  (LastVoice.voicepack = voicepack)) then exit;
+    if (not isSoundEnabled) or fastUntilLag or ((LastVoice.snd = snd) and  (LastVoice.voicepack = voicepack)) then
+        exit;
     if (snd = sndVictory) or (snd = sndFlawless) then
         begin
         Mix_FadeOutChannel(-1, 800);
-        for i:= 0 to 7 do VoiceList[i].snd:= sndNone;
+        for i:= 0 to 7 do
+            VoiceList[i].snd:= sndNone;
         LastVoice.snd:= sndNone;
         end;
 
     i:= 0;
-    while (i<8) and (VoiceList[i].snd <> sndNone) do inc(i);
+    while (i<8) and (VoiceList[i].snd <> sndNone) do
+        inc(i);
 
     // skip playing same sound for same hog twice
-    if (i>0) and (VoiceList[i-1].snd = snd) and (VoiceList[i-1].voicepack = voicepack) then exit;
+    if (i>0) and (VoiceList[i-1].snd = snd) and (VoiceList[i-1].voicepack = voicepack) then
+        exit;
     VoiceList[i].snd:= snd;
     VoiceList[i].voicepack:= voicepack;
 end;
@@ -325,9 +338,11 @@
 procedure PlayNextVoice;
 var i : LongInt;
 begin
-    if (not isSoundEnabled) or fastUntilLag or ((LastVoice.snd <> sndNone) and (lastChan[LastVoice.snd] <> -1) and (Mix_Playing(lastChan[LastVoice.snd]) <> 0)) then exit;
+    if (not isSoundEnabled) or fastUntilLag or ((LastVoice.snd <> sndNone) and (lastChan[LastVoice.snd] <> -1) and (Mix_Playing(lastChan[LastVoice.snd]) <> 0)) then
+        exit;
     i:= 0;
-    while (i<8) and (VoiceList[i].snd = sndNone) do inc(i);
+    while (i<8) and (VoiceList[i].snd = sndNone) do
+        inc(i);
     
     if (VoiceList[i].snd <> sndNone) then
         begin
@@ -359,58 +374,62 @@
 var s: shortstring;
 begin
     if (not isSoundEnabled) or fastUntilLag then
-    begin
+        begin
         LoopSound:= -1;
         exit
-    end;
+        end;
 
     if (voicepack <> nil) then
-    begin
+        begin
         if (voicepack^.chunks[snd] = nil) and (Soundz[snd].Path = ptVoices) and (Soundz[snd].FileName <> '') then
-        begin
+           begin
             s:= UserPathz[Soundz[snd].Path] + '/' + voicepack^.name + '/' + Soundz[snd].FileName;
-            if not FileExists(s) then s:= Pathz[Soundz[snd].Path] + '/' + voicepack^.name + '/' + Soundz[snd].FileName;
+            if not FileExists(s) then
+                s:= Pathz[Soundz[snd].Path] + '/' + voicepack^.name + '/' + Soundz[snd].FileName;
             WriteToConsole(msgLoading + s + ' ');
             voicepack^.chunks[snd]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1);
             if voicepack^.chunks[snd] = nil then
                 WriteLnToConsole(msgFailed)
             else
                 WriteLnToConsole(msgOK)
-        end;
+            end;
         LoopSound:= Mix_PlayChannelTimed(-1, voicepack^.chunks[snd], -1, -1)
-    end
+        end
     else
-    begin
+        begin
         if (defVoicepack^.chunks[snd] = nil) and (Soundz[snd].Path <> ptVoices) and (Soundz[snd].FileName <> '') then
-        begin
+            begin
             s:= UserPathz[Soundz[snd].Path] + '/' + Soundz[snd].FileName;
-            if not FileExists(s) then s:= Pathz[Soundz[snd].Path] + '/' + Soundz[snd].FileName;
+            if not FileExists(s) then
+                s:= Pathz[Soundz[snd].Path] + '/' + Soundz[snd].FileName;
             WriteToConsole(msgLoading + s + ' ');
             defVoicepack^.chunks[snd]:= Mix_LoadWAV_RW(SDL_RWFromFile(Str2PChar(s), 'rb'), 1);
             SDLTry(defVoicepack^.chunks[snd] <> nil, true);
             WriteLnToConsole(msgOK);
-        end;
+            end;
         if fadems > 0 then
             LoopSound:= Mix_FadeInChannelTimed(-1, defVoicepack^.chunks[snd], -1, fadems, -1)
         else
             LoopSound:= Mix_PlayChannelTimed(-1, defVoicepack^.chunks[snd], -1, -1);
-    end;
+        end;
 end;
 
 procedure StopSound(snd: TSound);
 begin
-    if not isSoundEnabled then exit;
+    if not isSoundEnabled then
+        exit;
 
     if (lastChan[snd] <> -1) and (Mix_Playing(lastChan[snd]) <> 0) then
-    begin
+        begin
         Mix_HaltChannel(lastChan[snd]);
         lastChan[snd]:= -1;
-    end;
+        end;
 end;
 
 procedure StopSound(chn: LongInt);
 begin
-    if not isSoundEnabled then exit;
+    if not isSoundEnabled then
+        exit;
 
     if (chn <> -1) and (Mix_Playing(chn) <> 0) then
         Mix_HaltChannel(chn);
@@ -418,7 +437,8 @@
 
 procedure StopSound(chn, fadems: LongInt);
 begin
-    if not isSoundEnabled then exit;
+    if not isSoundEnabled then
+        exit;
 
     if (chn <> -1) and (Mix_Playing(chn) <> 0) then
         Mix_FadeOutChannel(chn, fadems);
@@ -431,7 +451,8 @@
         exit;
 
     s:= UserPathPrefix + '/Data/Music/' + MusicFN;
-    if not FileExists(s) then s:= PathPrefix + '/Music/' + MusicFN;
+    if not FileExists(s) then
+        s:= PathPrefix + '/Music/' + MusicFN;
     WriteToConsole(msgLoading + s + ' ');
 
     Mus:= Mix_LoadMUS(Str2PChar(s));
@@ -447,10 +468,12 @@
         exit(0);
 
     inc(Volume, voldelta);
-    if Volume < 0 then Volume:= 0;
+    if Volume < 0 then
+        Volume:= 0;
     Mix_Volume(-1, Volume);
     Volume:= Mix_Volume(-1, -1);
-    if isMusicEnabled then Mix_VolumeMusic(Volume * 4 div 8);
+    if isMusicEnabled then
+        Mix_VolumeMusic(Volume * 4 div 8);
     ChangeVolume:= Volume * 100 div MIX_MAX_VOLUME
 end;
 
@@ -460,7 +483,7 @@
         exit;
 
     if Mus <> nil then
-    	Mix_PauseMusic(Mus);
+        Mix_PauseMusic(Mus);
 end;
 
 procedure ResumeMusic;
@@ -469,7 +492,7 @@
         exit;
 
     if Mus <> nil then
-    	Mix_ResumeMusic(Mus);
+        Mix_ResumeMusic(Mus);
 end;
 
 procedure ChangeMusic;
@@ -495,9 +518,11 @@
 
 procedure chVoicepack(var s: shortstring);
 begin
-    if CurrentTeam = nil then OutError(errmsgIncorrectUse + ' "/voicepack"', true);
+    if CurrentTeam = nil then
+        OutError(errmsgIncorrectUse + ' "/voicepack"', true);
     if s[1]='"' then Delete(s, 1, 1);
-    if s[byte(s[0])]='"' then Delete(s, byte(s[0]), 1);
+    if s[byte(s[0])]='"' then
+        Delete(s, byte(s[0]), 1);
     CurrentTeam^.voicepack:= AskForVoicepack(s)
 end;
 
--- a/hedgewars/uStats.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uStats.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -71,13 +71,15 @@
     inc(Kills);
     inc(KillsTotal);
     inc(Attacker^.Team^.stats.Kills);
-    if (Attacker^.Team^.TeamName =
-            Gear^.Hedgehog^.Team^.TeamName) then begin
+    if (Attacker^.Team^.TeamName = Gear^.Hedgehog^.Team^.TeamName) then
+        begin
         inc(Attacker^.Team^.stats.TeamKills);
         inc(Attacker^.Team^.stats.TeamDamage, Gear^.Damage);
     end;
-    if Gear = Attacker^.Gear then inc(Attacker^.Team^.stats.Suicides);
-    if Attacker^.Team^.Clan = Gear^.Hedgehog^.Team^.Clan then inc(KillsClan);
+    if Gear = Attacker^.Gear then
+        inc(Attacker^.Team^.stats.Suicides);
+    if Attacker^.Team^.Clan = Gear^.Hedgehog^.Team^.Clan then
+        inc(KillsClan);
     end;
 
 inc(DamageTotal, Damage)
@@ -148,9 +150,12 @@
                 begin
                 inc(DamageRecv, StepDamageRecv);
                 inc(DamageGiven, StepDamageGiven);
-                if StepDamageRecv > MaxStepDamageRecv then MaxStepDamageRecv:= StepDamageRecv;
-                if StepDamageGiven > MaxStepDamageGiven then MaxStepDamageGiven:= StepDamageGiven;
-                if StepKills > MaxStepKills then MaxStepKills:= StepKills;
+                if StepDamageRecv > MaxStepDamageRecv then
+                    MaxStepDamageRecv:= StepDamageRecv;
+                if StepDamageGiven > MaxStepDamageGiven then
+                    MaxStepDamageGiven:= StepDamageGiven;
+                if StepKills > MaxStepKills then
+                    MaxStepKills:= StepKills;
                 StepKills:= 0;
                 StepDamageRecv:= 0;
                 StepDamageGiven:= 0
@@ -212,7 +217,8 @@
     begin
         if not ExtDriven then
             SendStat(siTeamStats, GetTeamStatString(TeamsArray[t]));
-        for i:= 0 to cMaxHHIndex do begin
+        for i:= 0 to cMaxHHIndex do
+            begin
             if Hedgehogs[i].stats.MaxStepDamageGiven > msd then
                 begin
                 msdhh:= @Hedgehogs[i];
@@ -230,22 +236,26 @@
         end;
 
         { send player stats for winner teams }
-        if Clan^.ClanHealth > 0 then begin
+        if Clan^.ClanHealth > 0 then
+            begin
             winnersClan:= Clan;
             SendStat(siPlayerKills, IntToStr(Clan^.Color) + ' ' +
                 IntToStr(stats.Kills) + ' ' + TeamName);
         end;
 
         { determine maximum values of TeamKills, TurnSkips, TeamDamage }
-        if stats.TeamKills > maxTeamKills then begin
+        if stats.TeamKills > maxTeamKills then
+            begin
             maxTeamKills := stats.TeamKills;
             maxTeamKillsName := TeamName;
         end;
-        if stats.TurnSkips > maxTurnSkips then begin
+        if stats.TurnSkips > maxTurnSkips then
+            begin
             maxTurnSkips := stats.TurnSkips;
             maxTurnSkipsName := TeamName;
         end;
-        if stats.TeamDamage > maxTeamDamage then begin
+        if stats.TeamDamage > maxTeamDamage then
+            begin
             maxTeamDamage := stats.TeamDamage;
             maxTeamDamageName := TeamName;
         end;
@@ -253,9 +263,12 @@
     end;
 
 { now send player stats for loser teams }
-for t:= 0 to Pred(TeamsCount) do begin
-    with TeamsArray[t]^ do begin
-        if Clan^.ClanHealth = 0 then begin
+for t:= 0 to Pred(TeamsCount) do
+    begin
+    with TeamsArray[t]^ do
+        begin
+        if Clan^.ClanHealth = 0 then
+            begin
             SendStat(siPlayerKills, IntToStr(Clan^.Color) + ' ' +
                 IntToStr(stats.Kills) + ' ' + TeamName);
         end;
@@ -274,7 +287,8 @@
 if maxTeamDamage > 30 then
     SendStat(siMaxTeamDamage, IntToStr(maxTeamDamage) + ' ' + maxTeamDamageName);
 
-if KilledHHs > 0 then SendStat(siKilledHHs, IntToStr(KilledHHs));
+if KilledHHs > 0 then
+    SendStat(siKilledHHs, IntToStr(KilledHHs));
 
 // now to console
 if winnersClan <> nil then 
@@ -282,7 +296,8 @@
     writeln('WINNERS');
     for t:= 0 to winnersClan^.TeamsNumber - 1 do
         writeln(winnersClan^.Teams[t]^.TeamName);
-    end else
+    end
+else
     writeln('DRAW');
 
 writeln;
--- a/hedgewars/uStore.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uStore.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -80,7 +80,7 @@
 var t: LongInt;
     tmpsurf, texsurf: PSDL_Surface;
     Color, i: Longword;
-    s : shortstring;
+    s: shortstring;
 begin
 s:= UserPathz[ptGraphics] + '/' + cCHFileName;
 if not FileExists(s+'.png') then s:= Pathz[ptGraphics] + '/' + cCHFileName;
@@ -105,7 +105,8 @@
 
     // make black pixel be alpha-transparent
     for i:= 0 to texsurf^.w * texsurf^.h - 1 do
-        if PLongwordArray(texsurf^.pixels)^[i] = AMask then PLongwordArray(texsurf^.pixels)^[i]:= (RMask or GMask or BMask) and Color;
+        if PLongwordArray(texsurf^.pixels)^[i] = AMask then
+            PLongwordArray(texsurf^.pixels)^[i]:= (RMask or GMask or BMask) and Color;
 
     if SDL_MustLock(texsurf) then
         SDL_UnlockSurface(texsurf);
@@ -127,11 +128,11 @@
     texsurf, flagsurf, iconsurf: PSDL_Surface;
     s: shortstring;
 begin
-    r.x:= 0;
-    r.y:= 0;
-    drY:= - 4;
-    for t:= 0 to Pred(TeamsCount) do
-        with TeamsArray[t]^ do
+r.x:= 0;
+r.y:= 0;
+drY:= - 4;
+for t:= 0 to Pred(TeamsCount) do
+    with TeamsArray[t]^ do
         begin
         NameTagTex:= RenderStringTex(TeamName, Clan^.Color, Font);
 
@@ -164,14 +165,18 @@
 
         // overwrite flag for cpu teams and keep players from using it
         if (Hedgehogs[0].Gear <> nil) and (Hedgehogs[0].BotLevel > 0) then
-            if Flag = 'hedgewars' then Flag:= 'cpu'
+            if Flag = 'hedgewars' then
+                Flag:= 'cpu'
         else if Flag = 'cpu' then
             Flag:= 'hedgewars';
 
         flagsurf:= LoadImage(UserPathz[ptFlags] + '/' + Flag, ifNone);
-        if flagsurf = nil then flagsurf:= LoadImage(Pathz[ptFlags] + '/' + Flag, ifNone);
-        if flagsurf = nil then flagsurf:= LoadImage(UserPathz[ptFlags] + '/hedgewars', ifNone);
-        if flagsurf = nil then flagsurf:= LoadImage(Pathz[ptFlags] + '/hedgewars', ifNone);
+        if flagsurf = nil then
+            flagsurf:= LoadImage(Pathz[ptFlags] + '/' + Flag, ifNone);
+        if flagsurf = nil then
+            flagsurf:= LoadImage(UserPathz[ptFlags] + '/hedgewars', ifNone);
+        if flagsurf = nil then
+            flagsurf:= LoadImage(Pathz[ptFlags] + '/hedgewars', ifNone);
         TryDo(flagsurf <> nil, 'Failed to load flag "' + Flag + '" as well as the default flag', true);
         copyToXY(flagsurf, texsurf, 2, 2);
         SDL_FreeSurface(flagsurf);
@@ -206,7 +211,8 @@
                     end;
         end;
     MissionIcons:= LoadImage(UserPathz[ptGraphics] + '/missions', ifNone);
-    if MissionIcons = nil then MissionIcons:= LoadImage(Pathz[ptGraphics] + '/missions', ifCritical);
+    if MissionIcons = nil then
+        MissionIcons:= LoadImage(Pathz[ptGraphics] + '/missions', ifCritical);
     iconsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, 28, 28, 32, RMask, GMask, BMask, AMask);
     if iconsurf <> nil then
         begin
@@ -224,29 +230,33 @@
 procedure InitHealth;
 var i, t: LongInt;
 begin
-    for t:= 0 to Pred(TeamsCount) do
-        if TeamsArray[t] <> nil then
-            with TeamsArray[t]^ do
-                begin
-                for i:= 0 to cMaxHHIndex do
-                    if Hedgehogs[i].Gear <> nil then
-                        RenderHealth(Hedgehogs[i]);
-                end
+for t:= 0 to Pred(TeamsCount) do
+    if TeamsArray[t] <> nil then
+        with TeamsArray[t]^ do
+            begin
+            for i:= 0 to cMaxHHIndex do
+                if Hedgehogs[i].Gear <> nil then
+                    RenderHealth(Hedgehogs[i]);
+            end
 end;
 
 procedure LoadGraves;
 var t: LongInt;
     texsurf: PSDL_Surface;
 begin
-    for t:= 0 to Pred(TeamsCount) do
+for t:= 0 to Pred(TeamsCount) do
     if TeamsArray[t] <> nil then
         with TeamsArray[t]^ do
             begin
-            if GraveName = '' then GraveName:= 'Statue';
+            if GraveName = '' then
+                GraveName:= 'Statue';
             texsurf:= LoadImage(UserPathz[ptGraves] + '/' + GraveName, ifTransparent);
-            if texsurf = nil then texsurf:= LoadImage(Pathz[ptGraves] + '/' + GraveName, ifTransparent);
-            if texsurf = nil then texsurf:= LoadImage(UserPathz[ptGraves] + '/Statue', ifTransparent);
-            if texsurf = nil then texsurf:= LoadImage(Pathz[ptGraves] + '/Statue', ifCritical or ifTransparent);
+            if texsurf = nil then
+                texsurf:= LoadImage(Pathz[ptGraves] + '/' + GraveName, ifTransparent);
+            if texsurf = nil then
+                texsurf:= LoadImage(UserPathz[ptGraves] + '/Statue', ifTransparent);
+            if texsurf = nil then
+                texsurf:= LoadImage(Pathz[ptGraves] + '/Statue', ifCritical or ifTransparent);
             GraveTex:= Surface2Tex(texsurf, false);
             SDL_FreeSurface(texsurf)
             end
@@ -267,7 +277,8 @@
         with Fontz[fi] do
             begin
             s:= UserPathz[ptFonts] + '/' + Name;
-            if not FileExists(s) then s:= Pathz[ptFonts] + '/' + Name;
+            if not FileExists(s) then
+                s:= Pathz[ptFonts] + '/' + Name;
             WriteToConsole(msgLoading + s + ' (' + inttostr(Height) + 'pt)... ');
             Handle:= TTF_OpenFont(Str2PChar(s), Height);
             SDLTry(Handle <> nil, true);
@@ -290,35 +301,44 @@
            (((cReducedQuality and rqKillFlakes) = 0) or (Theme = 'Snow') or (Theme = 'Christmas') or ((not (ii in [sprFlake, sprSDFlake])))) and
            ((cCloudsNumber > 0) or (ii <> sprCloud)) and
            ((vobCount > 0) or (ii <> sprFlake)) then
-        begin
+            begin
             if AltPath = ptNone then
                 if ii in [sprHorizont, sprHorizontL, sprHorizontR, sprSky, sprSkyL, sprSkyR, sprChunk, sprFireButton] then // FIXME: hack
                     begin
                     if not reload then
                         begin
                         tmpsurf:= LoadImage(UserPathz[Path] + '/' + FileName, ifAlpha or ifTransparent);
-                        if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent)
+                        if tmpsurf = nil then
+                           tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent)
                         end
-                    else tmpsurf:= Surface
+                    else
+                           tmpsurf:= Surface
                     end
                 else
                     begin
                     if not reload then
                         begin
-                        tmpsurf:= LoadImage(UserPathz[Path] + '/' + FileName, ifAlpha or ifTransparent);
-                        if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent or ifCritical)
+                           tmpsurf:= LoadImage(UserPathz[Path] + '/' + FileName, ifAlpha or ifTransparent);
+                        if tmpsurf = nil then
+                           tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent or ifCritical)
                         end
-                    else tmpsurf:= Surface
+                    else
+                           tmpsurf:= Surface
                     end
-            else begin
+            else
+                begin
                 if not reload then
                     begin
                     tmpsurf:= LoadImage(UserPathz[Path] + '/' + FileName, ifAlpha or ifTransparent);
-                    if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent);
-                    if tmpsurf = nil then tmpsurf:= LoadImage(UserPathz[AltPath] + '/' + FileName, ifAlpha or ifTransparent);
-                    if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[AltPath] + '/' + FileName, ifAlpha or ifCritical or ifTransparent)
+                    if tmpsurf = nil then
+                        tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent);
+                    if tmpsurf = nil then
+                        tmpsurf:= LoadImage(UserPathz[AltPath] + '/' + FileName, ifAlpha or ifTransparent);
+                    if tmpsurf = nil then
+                        tmpsurf:= LoadImage(Pathz[AltPath] + '/' + FileName, ifAlpha or ifCritical or ifTransparent)
                     end
-                else tmpsurf:= Surface
+                else
+                        tmpsurf:= Surface
                 end;
 
             if tmpsurf <> nil then
@@ -352,7 +372,10 @@
 {$IF DEFINED(DARWIN) OR DEFINED(WIN32)}
                     Surface:= tmpsurf 
 {$ELSE}
-                    if saveSurf then Surface:= tmpsurf else SDL_FreeSurface(tmpsurf)
+                    if saveSurf then
+                        Surface:= tmpsurf
+                    else
+                        SDL_FreeSurface(tmpsurf)
 {$ENDIF}
                     end
                 end
@@ -363,8 +386,10 @@
 if not reload then
     AddProgress;
 
-tmpsurf:= LoadImage(UserPathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifTransparent);
-if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifCritical or ifTransparent);
+    tmpsurf:= LoadImage(UserPathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifTransparent);
+if tmpsurf = nil then
+    tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifCritical or ifTransparent);
+    
 HHTexture:= Surface2Tex(tmpsurf, false);
 SDL_FreeSurface(tmpsurf);
 
@@ -392,13 +417,13 @@
 
 // number of weapons in ammo menu
 for i:= Low(CountTexz) to High(CountTexz) do
-begin
+    begin
     tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(IntToStr(i) + 'x'), cWhiteColorChannels);
     tmpsurf:= doSurfaceConversion(tmpsurf);
     FreeTexture(CountTexz[i]);
     CountTexz[i]:= Surface2Tex(tmpsurf, false);
     SDL_FreeSurface(tmpsurf)
-end;
+    end;
 
 if not reload then
     AddProgress;
@@ -410,45 +435,45 @@
     ai: TAmmoType;
     i, t: LongInt;
 begin
-    for ii:= Low(TSprite) to High(TSprite) do
+for ii:= Low(TSprite) to High(TSprite) do
+    begin
+    FreeTexture(SpritesData[ii].Texture);
+    SpritesData[ii].Texture:= nil;
+    if (SpritesData[ii].Surface <> nil) and (not reload) then
         begin
-        FreeTexture(SpritesData[ii].Texture);
-        SpritesData[ii].Texture:= nil;
-        if (SpritesData[ii].Surface <> nil) and (not reload) then
-            begin
-            SDL_FreeSurface(SpritesData[ii].Surface);
-            SpritesData[ii].Surface:= nil
-            end
-        end;
-    SDL_FreeSurface(MissionIcons);
+        SDL_FreeSurface(SpritesData[ii].Surface);
+        SpritesData[ii].Surface:= nil
+        end
+    end;
+SDL_FreeSurface(MissionIcons);
 
-    // free the textures declared in uVariables
-    FreeTexture(WeaponTooltipTex);
-    WeaponTooltipTex:= nil;
-    FreeTexture(PauseTexture);
-    PauseTexture:= nil;
-    FreeTexture(SyncTexture);
-    SyncTexture:= nil;
-    FreeTexture(ConfirmTexture);
-    ConfirmTexture:= nil;
-    FreeTexture(ropeIconTex);
-    ropeIconTex:= nil;
-    FreeTexture(HHTexture);
-    HHTexture:= nil;
+// free the textures declared in uVariables
+FreeTexture(WeaponTooltipTex);
+WeaponTooltipTex:= nil;
+FreeTexture(PauseTexture);
+PauseTexture:= nil;
+FreeTexture(SyncTexture);
+SyncTexture:= nil;
+FreeTexture(ConfirmTexture);
+ConfirmTexture:= nil;
+FreeTexture(ropeIconTex);
+ropeIconTex:= nil;
+FreeTexture(HHTexture);
+HHTexture:= nil;
 
-    // free all ammo name textures
-    for ai:= Low(TAmmoType) to High(TAmmoType) do
-        begin
-        FreeTexture(Ammoz[ai].NameTex);
-        Ammoz[ai].NameTex:= nil
-        end;
+// free all ammo name textures
+for ai:= Low(TAmmoType) to High(TAmmoType) do
+    begin
+    FreeTexture(Ammoz[ai].NameTex);
+    Ammoz[ai].NameTex:= nil
+    end;
 
-    // free all count textures
-    for i:= Low(CountTexz) to High(CountTexz) do
-        begin
-        FreeTexture(CountTexz[i]);
-        CountTexz[i]:= nil
-        end;
+// free all count textures
+for i:= Low(CountTexz) to High(CountTexz) do
+    begin
+    FreeTexture(CountTexz[i]);
+    CountTexz[i]:= nil
+    end;
 
     // free all team and hedgehog textures
     for t:= 0 to Pred(TeamsCount) do
@@ -495,19 +520,19 @@
 procedure RenderHealth(var Hedgehog: THedgehog);
 var s: shortstring;
 begin
-    str(Hedgehog.Gear^.Health, s);
-    FreeTexture(Hedgehog.HealthTagTex);
-    Hedgehog.HealthTagTex:= RenderStringTex(s, Hedgehog.Team^.Clan^.Color, fnt16)
+str(Hedgehog.Gear^.Health, s);
+FreeTexture(Hedgehog.HealthTagTex);
+Hedgehog.HealthTagTex:= RenderStringTex(s, Hedgehog.Team^.Clan^.Color, fnt16)
 end;
 
 function  LoadImage(const filename: shortstring; imageFlags: LongInt): PSDL_Surface;
 var tmpsurf: PSDL_Surface;
     s: shortstring;
 begin
-    WriteToConsole(msgLoading + filename + '.png [flags: ' + inttostr(imageFlags) + '] ');
+WriteToConsole(msgLoading + filename + '.png [flags: ' + inttostr(imageFlags) + '] ');
 
-    s:= filename + '.png';
-    tmpsurf:= IMG_Load(Str2PChar(s));
+s:= filename + '.png';
+tmpsurf:= IMG_Load(Str2PChar(s));
 
     if tmpsurf = nil then
         begin
@@ -516,12 +541,12 @@
         end;
 
     if ((imageFlags and ifIgnoreCaps) = 0) and ((tmpsurf^.w > MaxTextureSize) or (tmpsurf^.h > MaxTextureSize)) then
-    begin
+        begin
         SDL_FreeSurface(tmpsurf);
         OutError(msgFailedSize, (imageFlags and ifCritical) <> 0);
         // dummy surface to replace non-critical textures that failed to load due to their size
         exit(SDL_CreateRGBSurface(SDL_SWSURFACE, 2, 2, 32, RMask, GMask, BMask, AMask));
-    end;
+        end;
 
     tmpsurf:= doSurfaceConversion(tmpsurf);
 
@@ -536,8 +561,9 @@
 procedure LoadHedgehogHat(HHGear: PGear; newHat: shortstring);
 var texsurf: PSDL_Surface;
 begin
-    texsurf:= LoadImage(UserPathz[ptHats] + '/' + newHat, ifNone);
-    if texsurf = nil then texsurf:= LoadImage(Pathz[ptHats] + '/' + newHat, ifNone);
+texsurf:= LoadImage(UserPathz[ptHats] + '/' + newHat, ifNone);
+    if texsurf = nil then
+        texsurf:= LoadImage(Pathz[ptHats] + '/' + newHat, ifNone);
 
     // only do something if the hat could be loaded
     if texsurf <> nil then
@@ -646,7 +672,7 @@
     begin
         // prepare left and right frame buffers and associated textures
         if glLoadExtension('GL_EXT_framebuffer_object') then
-        begin
+            begin
             // left
             glGenFramebuffersEXT(1, @framel);
             glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framel);
@@ -677,7 +703,7 @@
 
             // reset
             glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0)
-        end
+            end
         else
             cStereoMode:= smNone;
     end;
@@ -711,19 +737,20 @@
 
 procedure SetScale(f: GLfloat);
 begin
-    // leave immediately if scale factor did not change
-    if f = cScaleFactor then exit;
+// leave immediately if scale factor did not change
+    if f = cScaleFactor then
+        exit;
 
     if f = cDefaultZoomLevel then
         glPopMatrix         // "return" to default scaling
     else                    // other scaling
-    begin
+        begin
         glPushMatrix;       // save default scaling
         glLoadIdentity;
         glRotatef(rotationQt, 0, 0, 1);
         glScalef(f / cScreenWidth, -f / cScreenHeight, 1.0);
         glTranslatef(0, -cScreenHeight / 2, 0);
-    end;
+        end;
 
     cScaleFactor:= f;
 end;
@@ -737,7 +764,8 @@
     begin
         WriteToConsole(msgLoading + 'progress sprite: ');
         texsurf:= LoadImage(UserPathz[ptGraphics] + '/Progress', ifTransparent);
-        if texsurf = nil then texsurf:= LoadImage(Pathz[ptGraphics] + '/Progress', ifCritical or ifTransparent);
+        if texsurf = nil then
+            texsurf:= LoadImage(Pathz[ptGraphics] + '/Progress', ifCritical or ifTransparent);
 
         ProgrTex:= Surface2Tex(texsurf, false);
 
@@ -746,13 +774,15 @@
         SDL_FreeSurface(texsurf);
 
         uMobile.GameLoading();
-    end;
+        end;
 
     TryDo(ProgrTex <> nil, 'Error - Progress Texure is nil!', true);
 
     glClear(GL_COLOR_BUFFER_BIT);
-    if Step < numsquares then r.x:= 0
-    else r.x:= squaresize;
+    if Step < numsquares then
+        r.x:= 0
+    else
+        r.x:= squaresize;
 
     r.y:= (Step mod numsquares) * squaresize;
     r.w:= squaresize;
@@ -786,8 +816,10 @@
     tmpline, tmpline2, tmpdesc: ansistring;
 begin
 // make sure there is a caption as well as a sub caption - description is optional
-if caption = '' then caption:= '???';
-if subcaption = '' then subcaption:= ' ';
+if caption = '' then
+    caption:= '???';
+if subcaption = '' then
+    subcaption:= ' ';
 
 font:= CheckCJKFont(caption,fnt16);
 font:= CheckCJKFont(subcaption,font);
@@ -812,7 +844,8 @@
 // get sub caption's dimensions
 TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(subcaption), @i, @j);
 // width adds 36 px (image + space)
-if w < (i + 36 + wa) then w:= i + 36 + wa;
+if w < (i + 36 + wa) then
+    w:= i + 36 + wa;
 inc(h, j + ha);
 
 // get description's dimensions
@@ -824,7 +857,8 @@
     if tmpline <> '' then
         begin
         TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(tmpline), @i, @j);
-        if w < (i + wa) then w:= i + wa;
+        if w < (i + wa) then
+            w:= i + wa;
         inc(h, j + ha)
         end
     end;
@@ -833,7 +867,8 @@
     begin
     // get extra label's dimensions
     TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(extra), @i, @j);
-    if w < (i + wa) then w:= i + wa;
+    if w < (i + wa) then
+        w:= i + wa;
     inc(h, j + ha);
     end;
 
@@ -895,12 +930,12 @@
     extra: ansistring;
     extracolor: LongInt;
 begin
-    // don't do anything if the window shouldn't be shown
+// don't do anything if the window shouldn't be shown
     if (cReducedQuality and rqTooltipsOff) <> 0 then
-    begin
+        begin
         WeaponTooltipTex:= nil;
         exit
-    end;
+        end;
 
 // free old texture
 FreeWeaponTooltip;
@@ -956,8 +991,10 @@
     {$IFNDEF DARWIN}ico: PSDL_Surface;{$ENDIF}
     {$IFDEF SDL13}x, y: LongInt;{$ENDIF}
 begin
-    if Length(s) = 0 then cFullScreen:= (not cFullScreen)
-    else cFullScreen:= s = '1';
+    if Length(s) = 0 then
+        cFullScreen:= (not cFullScreen)
+    else
+        cFullScreen:= s = '1';
 
     AddFileLog('Preparing to change video parameters...');
 {$IFNDEF IPHONEOS}
@@ -971,7 +1008,8 @@
         // load engine icon
 {$IFNDEF DARWIN}
         ico:= LoadImage(UserPathz[ptGraphics] + '/hwengine', ifIgnoreCaps);
-        if ico = nil then ico:= LoadImage(Pathz[ptGraphics] + '/hwengine', ifIgnoreCaps);
+        if ico = nil then
+            ico:= LoadImage(Pathz[ptGraphics] + '/hwengine', ifIgnoreCaps);
         if ico <> nil then
             begin
             SDL_WM_SetIcon(ico, 0);
@@ -1019,8 +1057,10 @@
 {$ENDIF}
 
     if SDLwindow = nil then
-        if cFullScreen then SDLwindow:= SDL_CreateWindow('Hedgewars', x, y, cOrigScreenWidth, cOrigScreenHeight, flags or SDL_WINDOW_FULLSCREEN)
-        else SDLwindow:= SDL_CreateWindow('Hedgewars', x, y, cScreenWidth, cScreenHeight, flags);
+        if cFullScreen then
+            SDLwindow:= SDL_CreateWindow('Hedgewars', x, y, cOrigScreenWidth, cOrigScreenHeight, flags or SDL_WINDOW_FULLSCREEN)
+        else
+            SDLwindow:= SDL_CreateWindow('Hedgewars', x, y, cScreenWidth, cScreenHeight, flags);
     SDLTry(SDLwindow <> nil, true);
 {$ELSE}
     flags:= SDL_OPENGL or SDL_RESIZABLE;
@@ -1045,10 +1085,11 @@
         // clean the window from any previous content
         glClear(GL_COLOR_BUFFER_BIT);
         if SuddenDeathDmg then
-             glClearColor(SDSkyColor.r * (SDTint/255) / 255, SDSkyColor.g * (SDTint/255) / 255, SDSkyColor.b * (SDTint/255) / 255, 0.99)
+            glClearColor(SDSkyColor.r * (SDTint/255) / 255, SDSkyColor.g * (SDTint/255) / 255, SDSkyColor.b * (SDTint/255) / 255, 0.99)
         else if ((cReducedQuality and rqNoBackground) = 0) then 
-             glClearColor(SkyColor.r / 255, SkyColor.g / 255, SkyColor.b / 255, 0.99)
-        else glClearColor(RQSkyColor.r / 255, RQSkyColor.g / 255, RQSkyColor.b / 255, 0.99);
+            glClearColor(SkyColor.r / 255, SkyColor.g / 255, SkyColor.b / 255, 0.99)
+        else
+            glClearColor(RQSkyColor.r / 255, RQSkyColor.g / 255, RQSkyColor.b / 255, 0.99);
 
         // reload everything we had before
         ReloadCaptions(false);
--- a/hedgewars/uTeams.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uTeams.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -55,7 +55,8 @@
         end;
 
 if (AliveCount > 1)
-or ((AliveCount = 1) and ((GameFlags and gfOneClanMode) <> 0)) then exit(false);
+or ((AliveCount = 1) and ((GameFlags and gfOneClanMode) <> 0)) then
+    exit(false);
 CheckForWin:= true;
 
 TurnTimeLeft:= 0;
@@ -67,7 +68,8 @@
         AddCaption(trmsg[sidDraw], cWhiteColor, capgrpGameState);
         SendStat(siGameResult, trmsg[sidDraw]);
         AddGear(0, 0, gtATFinishGame, 0, _0, _0, 3000)
-        end else // win
+        end
+    else // win
         with AliveClan^ do
             begin
             if TeamsNumber = 1 then
@@ -109,7 +111,8 @@
            begin
            DeleteCI(Gear);
            FindPlace(Gear, false, 0, LAND_WIDTH);
-           if Gear <> nil then AddGearCI(Gear)
+           if Gear <> nil then
+               AddGearCI(Gear)
            end
         end;
 
@@ -134,7 +137,8 @@
         repeat
             begin
             inc(c);
-            if c > cMaxHHIndex then c:= 0
+            if c > cMaxHHIndex then
+                c:= 0
             end
         until (c = CurrHedgehog) or (Hedgehogs[c].Gear <> nil);
         LocalAmmo:= Hedgehogs[c].AmmoStore
@@ -151,11 +155,13 @@
             NextClan:= true;
             end;
 
-    if (GameFlags and gfTagTeam) = 0 then inc(c);
+    if (GameFlags and gfTagTeam) = 0 then
+        inc(c);
 
     if c = ClansCount then
         begin
-        if not PlacingHogs then inc(TotalRounds);
+        if not PlacingHogs then
+            inc(TotalRounds);
         c:= 0
         end;
 
@@ -185,25 +191,27 @@
 
 begin
 if PlacingHogs then
-   begin
-   PlacingHogs:= false;
-   for t:= 0 to Pred(TeamsCount) do
-      for i:= 0 to cMaxHHIndex do
-          if (TeamsArray[t]^.Hedgehogs[i].Gear <> nil) and (TeamsArray[t]^.Hedgehogs[i].Unplaced) then
-             PlacingHogs:= true;
+    begin
+    PlacingHogs:= false;
+    for t:= 0 to Pred(TeamsCount) do
+        for i:= 0 to cMaxHHIndex do
+            if (TeamsArray[t]^.Hedgehogs[i].Gear <> nil) and (TeamsArray[t]^.Hedgehogs[i].Unplaced) then
+                PlacingHogs:= true;
 
-   if not PlacingHogs then // Reset  various things I mucked with
-      begin
-      for i:= 0 to ClansCount do
-         if ClansArray[i] <> nil then ClansArray[i]^.TurnNumber:= 0;
-      ResetWeapons
-      end
-   end;
+    if not PlacingHogs then // Reset  various things I mucked with
+        begin
+        for i:= 0 to ClansCount do
+            if ClansArray[i] <> nil then
+                ClansArray[i]^.TurnNumber:= 0;
+        ResetWeapons
+        end
+    end;
 
 inc(CurrentTeam^.Clan^.TurnNumber);
 
 CurWeapon:= GetAmmoEntry(CurrentHedgehog^);
-if CurWeapon^.Count = 0 then CurrentHedgehog^.CurAmmoType:= amNothing;
+if CurWeapon^.Count = 0 then
+    CurrentHedgehog^.CurAmmoType:= amNothing;
 
 with CurrentHedgehog^ do
     begin
@@ -235,18 +243,21 @@
 
 ApplyAmmoChanges(CurrentHedgehog^);
 
-if (not CurrentTeam^.ExtDriven) and (CurrentHedgehog^.BotLevel = 0) then SetBinds(CurrentTeam^.Binds);
+if (not CurrentTeam^.ExtDriven) and (CurrentHedgehog^.BotLevel = 0) then
+    SetBinds(CurrentTeam^.Binds);
 
 bShowFinger:= true;
 
 if PlacingHogs then
     begin
-    if CurrentHedgehog^.Unplaced then TurnTimeLeft:= 15000
+    if CurrentHedgehog^.Unplaced then
+        TurnTimeLeft:= 15000
     else TurnTimeLeft:= 0
     end
 else if ((GameFlags and gfTagTeam) <> 0) and (not NextClan) then
     begin
-    if TagTurnTimeLeft <> 0 then TurnTimeLeft:= TagTurnTimeLeft;
+    if TagTurnTimeLeft <> 0 then
+        TurnTimeLeft:= TagTurnTimeLeft;
     TagTurnTimeLeft:= 0;
     end
 else
@@ -261,7 +272,8 @@
         AddVoice(sndIllGetYou, CurrentTeam^.voicepack)
     else
         AddVoice(sndYesSir, CurrentTeam^.voicepack);
-    if PlacingHogs or (cHedgehogTurnTime < 1000000) then ReadyTimeLeft:= cReadyDelay;
+    if PlacingHogs or (cHedgehogTurnTime < 1000000) then
+        ReadyTimeLeft:= cReadyDelay;
     AddCaption(Format(shortstring(trmsg[sidReady]), CurrentTeam^.TeamName), cWhiteColor, capgrpGameState)
     end
 else
@@ -293,22 +305,23 @@
 c:= Pred(ClansCount);
 while (c >= 0) and (ClansArray[c]^.Color <> TeamColor) do dec(c);
 if c < 0 then
-   begin
-   new(team^.Clan);
-   FillChar(team^.Clan^, sizeof(TClan), 0);
-   ClansArray[ClansCount]:= team^.Clan;
-   inc(ClansCount);
-   with team^.Clan^ do
+    begin
+    new(team^.Clan);
+    FillChar(team^.Clan^, sizeof(TClan), 0);
+    ClansArray[ClansCount]:= team^.Clan;
+    inc(ClansCount);
+    with team^.Clan^ do
         begin
         ClanIndex:= Pred(ClansCount);
         Color:= TeamColor;
         TagTeamIndex:= 0;
         Flawless:= true
         end
-   end else
-   begin
-   team^.Clan:= ClansArray[c];
-   end;
+    end
+else
+    begin
+    team^.Clan:= ClansArray[c];
+    end;
 
 with team^.Clan^ do
     begin
@@ -344,8 +357,9 @@
         th:= 0;
         for i:= 0 to cMaxHHIndex do
             if Hedgehogs[i].Gear <> nil then
-               inc(th, Hedgehogs[i].Gear^.Health);
-        if th > MaxTeamHealth then MaxTeamHealth:= th;
+                inc(th, Hedgehogs[i].Gear^.Health);
+        if th > MaxTeamHealth then
+            MaxTeamHealth:= th;
         // Some initial King buffs
         if (GameFlags and gfKing) <> 0 then
             begin
@@ -358,9 +372,11 @@
                 begin
                 dec(th, h);
                 inc(th, Hedgehogs[0].Gear^.Health);
-                if th > MaxTeamHealth then MaxTeamHealth:= th
+                if th > MaxTeamHealth then
+                    MaxTeamHealth:= th
                 end
-            else Hedgehogs[0].Gear^.Health:= h;
+            else
+                Hedgehogs[0].Gear^.Health:= h;
             Hedgehogs[0].InitialHealth:= Hedgehogs[0].Gear^.Health
             end;
         end;
@@ -373,7 +389,8 @@
 begin
 value:= 0;
 for i:= 0 to cMaxHHIndex do
-    if p^.Hedgehogs[i].Gear <> nil then inc(value);
+    if p^.Hedgehogs[i].Gear <> nil then
+        inc(value);
 TeamSize:= value;
 end;
 
@@ -407,7 +424,8 @@
         begin
         MaxTeamHealth:= NewTeamHealthBarWidth;
         RecountAllTeamsHealth;
-        end else if NewTeamHealthBarWidth > 0 then NewTeamHealthBarWidth:= (NewTeamHealthBarWidth * cTeamHealthWidth) div MaxTeamHealth
+        end else if NewTeamHealthBarWidth > 0 then
+            NewTeamHealthBarWidth:= (NewTeamHealthBarWidth * cTeamHealthWidth) div MaxTeamHealth
     end;
 
 RecountClanHealth(team^.Clan);
@@ -445,56 +463,58 @@
 var s: shortstring;
     Gear: PGear;
 begin
-    s:= '';
-    if (not isDeveloperMode) or (CurrentTeam = nil) then exit;
-    with CurrentTeam^ do
+s:= '';
+if (not isDeveloperMode) or (CurrentTeam = nil) then
+    exit;
+with CurrentTeam^ do
+    begin
+    SplitBySpace(id, s);
+    CurrentHedgehog:= @Hedgehogs[HedgehogsNumber];
+    val(id, CurrentHedgehog^.BotLevel);
+    Gear:= AddGear(0, 0, gtHedgehog, 0, _0, _0, 0);
+    SplitBySpace(s, id);
+    val(s, Gear^.Health);
+    TryDo(Gear^.Health > 0, 'Invalid hedgehog health', true);
+    Gear^.Hedgehog^.Team:= CurrentTeam;
+    if (GameFlags and gfSharedAmmo) <> 0 then
+        CurrentHedgehog^.AmmoStore:= Clan^.ClanIndex
+    else if (GameFlags and gfPerHogAmmo) <> 0 then
         begin
-        SplitBySpace(id, s);
-        CurrentHedgehog:= @Hedgehogs[HedgehogsNumber];
-        val(id, CurrentHedgehog^.BotLevel);
-        Gear:= AddGear(0, 0, gtHedgehog, 0, _0, _0, 0);
-        SplitBySpace(s, id);
-        val(s, Gear^.Health);
-        TryDo(Gear^.Health > 0, 'Invalid hedgehog health', true);
-        Gear^.Hedgehog^.Team:= CurrentTeam;
-        if (GameFlags and gfSharedAmmo) <> 0 then CurrentHedgehog^.AmmoStore:= Clan^.ClanIndex
-        else if (GameFlags and gfPerHogAmmo) <> 0 then
-            begin
-            AddAmmoStore;
-            CurrentHedgehog^.AmmoStore:= StoreCnt - 1
-            end
-        else CurrentHedgehog^.AmmoStore:= TeamsCount - 1;
-        CurrentHedgehog^.Gear:= Gear;
-        CurrentHedgehog^.Name:= id;
-        CurrentHedgehog^.InitialHealth:= Gear^.Health;
-        CurrHedgehog:= HedgehogsNumber;
-        inc(HedgehogsNumber)
+        AddAmmoStore;
+        CurrentHedgehog^.AmmoStore:= StoreCnt - 1
         end
+    else CurrentHedgehog^.AmmoStore:= TeamsCount - 1;
+    CurrentHedgehog^.Gear:= Gear;
+    CurrentHedgehog^.Name:= id;
+    CurrentHedgehog^.InitialHealth:= Gear^.Health;
+    CurrHedgehog:= HedgehogsNumber;
+    inc(HedgehogsNumber)
+    end
 end;
 
 procedure chAddTeam(var s: shortstring);
 var Color: Longword;
     ts, cs: shortstring;
 begin
-    cs:= '';
-    ts:= '';
-    if isDeveloperMode then
-        begin
-        SplitBySpace(s, cs);
-        SplitBySpace(cs, ts);
-        val(cs, Color);
-        TryDo(Color <> 0, 'Error: black team color', true);
+cs:= '';
+ts:= '';
+if isDeveloperMode then
+    begin
+    SplitBySpace(s, cs);
+    SplitBySpace(cs, ts);
+    val(cs, Color);
+    TryDo(Color <> 0, 'Error: black team color', true);
 
-        // color is always little endian so the mask must be constant also in big endian archs
-        Color:= Color or $FF000000;
+    // color is always little endian so the mask must be constant also in big endian archs
+    Color:= Color or $FF000000;
+    AddTeam(Color);
+    CurrentTeam^.TeamName:= ts;
+    CurrentTeam^.PlayerHash:= s;
+    if GameType in [gmtDemo, gmtSave] then
+        CurrentTeam^.ExtDriven:= true;
 
-        AddTeam(Color);
-        CurrentTeam^.TeamName:= ts;
-        CurrentTeam^.PlayerHash:= s;
-        if GameType in [gmtDemo, gmtSave] then CurrentTeam^.ExtDriven:= true;
-
-        CurrentTeam^.voicepack:= AskForVoicepack('Default')
-        end
+    CurrentTeam^.voicepack:= AskForVoicepack('Default')
+    end
 end;
 
 procedure chSetHHCoords(var x: shortstring);
@@ -502,7 +522,8 @@
     t: Longint;
 begin
 y:= '';
-if (not isDeveloperMode) or (CurrentHedgehog = nil) or (CurrentHedgehog^.Gear = nil) then exit;
+if (not isDeveloperMode) or (CurrentHedgehog = nil) or (CurrentHedgehog^.Gear = nil) then
+    exit;
 SplitBySpace(x, y);
 val(x, t);
 CurrentHedgehog^.Gear^.X:= int2hwFloat(t);
@@ -515,23 +536,28 @@
     b: LongInt;
 begin
 s:= '';
-if CurrentTeam = nil then exit;
+if CurrentTeam = nil then
+    exit;
 SplitBySpace(id, s);
-if s[1]='"' then Delete(s, 1, 1);
-if s[byte(s[0])]='"' then Delete(s, byte(s[0]), 1);
+if s[1]='"' then
+    Delete(s, 1, 1);
+if s[byte(s[0])]='"' then
+    Delete(s, byte(s[0]), 1);
 b:= KeyNameToCode(id);
-if b = 0 then OutError(errmsgUnknownVariable + ' "' + id + '"', false)
-        else CurrentTeam^.Binds[b]:= s
+if b = 0 then
+    OutError(errmsgUnknownVariable + ' "' + id + '"', false)
+else
+    CurrentTeam^.Binds[b]:= s
 end;
 
 procedure chTeamGone(var s:shortstring);
 var t: LongInt;
 begin
 t:= 0;
-while (t < cMaxTeams)
-    and (TeamsArray[t] <> nil)
-    and (TeamsArray[t]^.TeamName <> s) do inc(t);
-if (t = cMaxTeams) or (TeamsArray[t] = nil) then exit;
+while (t < cMaxTeams) and (TeamsArray[t] <> nil) and (TeamsArray[t]^.TeamName <> s) do
+    inc(t);
+if (t = cMaxTeams) or (TeamsArray[t] = nil) then
+    exit;
 
 with TeamsArray[t]^ do
     begin
@@ -562,41 +588,42 @@
 
 procedure initModule;
 begin
-    RegisterVariable('addhh', vtCommand, @chAddHH, false);
-    RegisterVariable('addteam', vtCommand, @chAddTeam, false);
-    RegisterVariable('hhcoords', vtCommand, @chSetHHCoords, false);
-    RegisterVariable('bind', vtCommand, @chBind, true );
-    RegisterVariable('teamgone', vtCommand, @chTeamGone, true );
-    RegisterVariable('finish', vtCommand, @chFinish, true ); // all teams gone
+RegisterVariable('addhh', vtCommand, @chAddHH, false);
+RegisterVariable('addteam', vtCommand, @chAddTeam, false);
+RegisterVariable('hhcoords', vtCommand, @chSetHHCoords, false);
+RegisterVariable('bind', vtCommand, @chBind, true );
+RegisterVariable('teamgone', vtCommand, @chTeamGone, true );
+RegisterVariable('finish', vtCommand, @chFinish, true ); // all teams gone
 
-    CurrentTeam:= nil;
-    PreviousTeam:= nil;
-    CurrentHedgehog:= nil;
-    TeamsCount:= 0;
-    ClansCount:= 0;
-    LocalClan:= -1;
-    LocalTeam:= -1;
-    LocalAmmo:= -1;
-    GameOver:= false;
-    NextClan:= true;
+CurrentTeam:= nil;
+PreviousTeam:= nil;
+CurrentHedgehog:= nil;
+TeamsCount:= 0;
+ClansCount:= 0;
+LocalClan:= -1;
+LocalTeam:= -1;
+LocalAmmo:= -1;
+GameOver:= false;
+NextClan:= true;
 end;
 
 procedure freeModule;
 var i, h: LongWord;
 begin
-   if TeamsCount > 0 then
-     begin
-     for i:= 0 to Pred(TeamsCount) do
+if TeamsCount > 0 then
+    begin
+    for i:= 0 to Pred(TeamsCount) do
         begin
-            for h:= 0 to cMaxHHIndex do
-                if TeamsArray[i]^.Hedgehogs[h].GearHidden <> nil then
-                    Dispose(TeamsArray[i]^.Hedgehogs[h].GearHidden);
-            Dispose(TeamsArray[i]);
-        end;
-     for i:= 0 to Pred(ClansCount) do Dispose(ClansArray[i]);
-     end;
-   TeamsCount:= 0;
-   ClansCount:= 0;
+        for h:= 0 to cMaxHHIndex do
+            if TeamsArray[i]^.Hedgehogs[h].GearHidden <> nil then
+                Dispose(TeamsArray[i]^.Hedgehogs[h].GearHidden);
+        Dispose(TeamsArray[i]);
+    end;
+for i:= 0 to Pred(ClansCount) do
+    Dispose(ClansArray[i]);
+    end;
+TeamsCount:= 0;
+ClansCount:= 0;
 end;
 
 end.
--- a/hedgewars/uTextures.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uTextures.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -39,10 +39,10 @@
 procedure SetTextureParameters(enableClamp: Boolean);
 begin
     if enableClamp and ((cReducedQuality and rqClampLess) = 0) then
-    begin
+        begin
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
-    end;
+        end;
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
 end;
@@ -156,7 +156,8 @@
 
 fromP4:= Surf^.pixels;
 
-if cGrayScale then Surface2GrayScale(Surf);
+if cGrayScale then
+    Surface2GrayScale(Surf);
 
 if (not SupportNPOTT) and (not (isPowerOf2(Surf^.w) and isPowerOf2(Surf^.h))) then
     begin
@@ -173,15 +174,18 @@
 
     for y:= 0 to Pred(Surf^.h) do
         begin
-        for x:= 0 to Pred(Surf^.w) do toP4^[x]:= fromP4^[x];
-        for x:= Surf^.w to Pred(tw) do toP4^[x]:= 0;
+        for x:= 0 to Pred(Surf^.w) do
+            toP4^[x]:= fromP4^[x];
+        for x:= Surf^.w to Pred(tw) do
+            toP4^[x]:= 0;
         toP4:= @(toP4^[tw]);
         fromP4:= @(fromP4^[Surf^.pitch div 4])
         end;
 
     for y:= Surf^.h to Pred(th) do
         begin
-        for x:= 0 to Pred(tw) do toP4^[x]:= 0;
+        for x:= 0 to Pred(tw) do
+            toP4^[x]:= 0;
         toP4:= @(toP4^[tw])
         end;
 
@@ -208,17 +212,17 @@
 // if nil is passed nothing is done
 procedure FreeTexture(tex: PTexture);
 begin
-    if tex <> nil then
-        begin
-        if tex^.NextTexture <> nil then
-            tex^.NextTexture^.PrevTexture:= tex^.PrevTexture;
-        if tex^.PrevTexture <> nil then
-            tex^.PrevTexture^.NextTexture:= tex^.NextTexture
-        else
-            TextureList:= tex^.NextTexture;
-        glDeleteTextures(1, @tex^.id);
-        Dispose(tex);
-        end
+if tex <> nil then
+    begin
+    if tex^.NextTexture <> nil then
+        tex^.NextTexture^.PrevTexture:= tex^.PrevTexture;
+    if tex^.PrevTexture <> nil then
+        tex^.PrevTexture^.NextTexture:= tex^.NextTexture
+    else
+        TextureList:= tex^.NextTexture;
+    glDeleteTextures(1, @tex^.id);
+    Dispose(tex);
+    end
 end;
 
 procedure initModule;
@@ -228,7 +232,8 @@
 
 procedure freeModule;
 begin
-    if TextureList <> nil then WriteToConsole('FIXME FIXME FIXME. App shutdown without full cleanup of texture list; read game0.log and please report this problem');
+if TextureList <> nil then
+    WriteToConsole('FIXME FIXME FIXME. App shutdown without full cleanup of texture list; read game0.log and please report this problem');
     while TextureList <> nil do 
         begin
         AddFileLog('Texture not freed: width='+inttostr(LongInt(TextureList^.w))+' height='+inttostr(LongInt(TextureList^.h))+' priority='+inttostr(round(TextureList^.priority*1000)));
--- a/hedgewars/uTouch.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uTouch.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -102,8 +102,8 @@
 var 
     finger: PTouch_Finger;
 begin
-    finger := addFinger(x,y,pointerId);
-    case pointerCount of
+finger := addFinger(x,y,pointerId);
+case pointerCount of
         1:
         begin
             moveCursor:= false;
@@ -161,22 +161,22 @@
     currentPinchDelta, zoom : hwFloat;
     tmpX, tmpY: LongInt;
 begin
-    x := x;
-    y := y;
-    dx := dx;
-    dy := dy;
-    finger:= findFinger(pointerId);
-    tmpX := convertToCursor(cScreenWidth, x);
-    tmpY := convertToCursor(cScreenHeight, y);
+x := x;
+y := y;
+dx := dx;
+dy := dy;
+finger:= findFinger(pointerId);
+tmpX := convertToCursor(cScreenWidth, x);
+tmpY := convertToCursor(cScreenHeight, y);
 
-    if moveCursor then
+if moveCursor then
     begin
         if invertCursor then
         begin
             CursorPoint.X := CursorPoint.X + (finger^.x - tmpX);
             CursorPoint.Y := CursorPoint.Y - (finger^.y - tmpY);
         end
-        else
+    else
         begin
             CursorPoint.X := CursorPoint.X - (finger^.x - tmpX);
             CursorPoint.Y := CursorPoint.Y + (finger^.y - tmpY);
@@ -200,20 +200,22 @@
        currentPinchDelta := calculateDelta(finger^, secondFinger^) - pinchSize;
        zoom := currentPinchDelta/cScreenWidth;
        ZoomValue := baseZoomValue - ((hwFloat2Float(zoom) * cMinMaxZoomLevelDelta));
-       if ZoomValue < cMaxZoomLevel then ZoomValue := cMaxZoomLevel;
-       if ZoomValue > cMinZoomLevel then ZoomValue := cMinZoomLevel;
+       if ZoomValue < cMaxZoomLevel then
+           ZoomValue := cMaxZoomLevel;
+       if ZoomValue > cMinZoomLevel then
+           ZoomValue := cMinZoomLevel;
     end;
 end;
 
 procedure onTouchUp(x,y: Longword; pointerId: SDL_FingerId);
 begin
-    x := x;
-    y := y;
-    aiming:= false;
-    stopFiring:= true;
-    deleteFinger(pointerId);
+x := x;
+y := y;
+aiming:= false;
+stopFiring:= true;
+deleteFinger(pointerId);
 
-    if walkingLeft then
+if walkingLeft then
     begin
         ParseCommand('-left', true);
         walkingLeft := false;
@@ -228,18 +230,18 @@
 
 procedure onTouchDoubleClick(finger: Touch_Finger);
 begin
-    finger := finger;//avoid compiler hint
-    ParseCommand('ljump', true);
+finger := finger;//avoid compiler hint
+ParseCommand('ljump', true);
 end;
 
 procedure onTouchClick(finger: Touch_Finger);
 begin
-    if (SDL_GetTicks - timeSinceClick < 300) and (DistanceI(finger.X-xTouchClick, finger.Y-yTouchClick) < _30) then
+if (SDL_GetTicks - timeSinceClick < 300) and (DistanceI(finger.X-xTouchClick, finger.Y-yTouchClick) < _30) then
     begin
     onTouchDoubleClick(finger);
     exit; 
     end
-    else
+else
     begin
         xTouchClick := finger.x;
         yTouchClick := finger.y;
@@ -273,7 +275,8 @@
     if length(fingers) < Integer(pointerCount) then 
     begin
         setLength(fingers, length(fingers)*2);
-        for index := length(fingers) div 2 to length(fingers) do fingers[index].id := nilFingerId;
+        for index := length(fingers) div 2 to length(fingers) do
+            fingers[index].id := nilFingerId;
     end;
     
     
@@ -301,16 +304,16 @@
     dec(pointerCount);
     for index := 0 to pointerCount do
     begin
-         if fingers[index].id = id then
-         begin
-             //Check for onTouchClick event
-             if ((SDL_GetTicks - fingers[index].timeSinceDown) < clickTime) AND  
-                 not(fingerHasMoved(fingers[index])) then onTouchClick(fingers[index]);
-
-             //put the last finger into the spot of the finger to be removed, 
-             //so that all fingers are packed to the far left
-             if  pointerCount <> index then
-             begin
+        if fingers[index].id = id then
+        begin
+            //Check for onTouchClick event
+            if ((SDL_GetTicks - fingers[index].timeSinceDown) < clickTime) AND not(fingerHasMoved(fingers[index])) then
+                onTouchClick(fingers[index]);
+ 
+            //put the last finger into the spot of the finger to be removed, 
+            //so that all fingers are packed to the far left
+            if  pointerCount <> index then
+                begin
                 fingers[index].id := fingers[pointerCount].id;    
                 fingers[index].x := fingers[pointerCount].x;    
                 fingers[index].y := fingers[pointerCount].y;    
@@ -319,10 +322,10 @@
                 fingers[index].timeSinceDown := fingers[pointerCount].timeSinceDown;
 
                 fingers[pointerCount].id := nilFingerId;
-             end
-             else fingers[index].id := nilFingerId;
-             break;
-         end;
+            end
+        else fingers[index].id := nilFingerId;
+            break;
+        end;
     end;
 
 end;
@@ -335,44 +338,44 @@
     if aiming then
     begin
         if CurrentHedgehog^.Gear <> nil then
-        begin
+            begin
             deltaAngle:= CurrentHedgehog^.Gear^.Angle - targetAngle;
             if (deltaAngle <> 0) and not(movingCrosshair) then 
-            begin
+                begin
                 ParseCommand('+' + crosshairCommand, true);
                 movingCrosshair := true;
-            end
+                end
             else 
                 if movingCrosshair then 
-                begin
+                    begin
                     ParseCommand('-' + crosshairCommand, true);
                     movingCrosshair:= false;
-                end;
-        end;
+                   end;
+            end;
     end
     else if movingCrosshair then 
-    begin
+        begin
         ParseCommand('-' + crosshairCommand, true);
         movingCrosshair := false;
-    end;
+        end;
 
     if stopFiring then 
-    begin
+        begin
         ParseCommand('-attack', true);
         stopFiring:= false;
-    end;
+        end;
     
     if stopRight then
-    begin
+        begin
         stopRight := false;
         ParseCommand('-right', true);
-    end;
+        end;
  
     if stopLeft then
-    begin
+        begin
         stopLeft := false;
         ParseCommand('-left', true);
-    end;
+        end;
     
 end;
 
@@ -380,12 +383,12 @@
 var
     index: LongWord;
 begin
-   for index := 0 to High(fingers) do
-       if fingers[index].id = id then 
-       begin
-           findFinger := @fingers[index];
-           break;
-       end;
+    for index := 0 to High(fingers) do
+        if fingers[index].id = id then 
+            begin
+            findFinger := @fingers[index];
+            break;
+            end;
 end;
 
 procedure aim(finger: Touch_Finger);
@@ -408,13 +411,15 @@
         targetAngle:= (hwRound(tmpAngle) + 2048) div 2;
 
         tmp := crosshairCommand;
-        if CurrentHedgehog^.Gear^.Angle - targetAngle < 0 then crosshairCommand := 'down'
-        else crosshairCommand:= 'up';
+        if CurrentHedgehog^.Gear^.Angle - targetAngle < 0 then
+            crosshairCommand := 'down'
+        else
+            crosshairCommand:= 'up';
         if movingCrosshair and (tmp <> crosshairCommand) then 
-        begin
+            begin
             ParseCommand('-' + tmp, true);
             movingCrosshair := false;
-        end;
+            end;
 
     end; //if CurrentHedgehog^.Gear <> nil
 end;
@@ -478,8 +483,10 @@
 // If the pointer to be ignored is not pointerIds[0] the second must be there
 function getSecondFinger(finger: Touch_Finger): PTouch_Finger;
 begin
-    if fingers[0].id = finger.id then getSecondFinger := @fingers[1]
-    else getSecondFinger := @fingers[0];
+    if fingers[0].id = finger.id then
+        getSecondFinger := @fingers[1]
+    else
+        getSecondFinger := @fingers[0];
 end;
 
 procedure printFinger(finger: Touch_Finger);
--- a/hedgewars/uTypes.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uTypes.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -190,12 +190,12 @@
             end;
 
     TVertex2f = record
-        X, Y: GLfloat;
-        end;
+            X, Y: GLfloat;
+            end;
 
     TVertex2i = record
-        X, Y: GLint;
-        end;
+            X, Y: GLint;
+            end;
 
     PTexture = ^TTexture;
     TTexture = record
@@ -255,7 +255,7 @@
             SoundChannel: LongInt;
             PortalCounter: LongWord;  // Hopefully temporary, but avoids infinite portal loops in a guaranteed fashion.
             LastDamage: PHedgehog;
-        end;
+            end;
     TPGearArray = array of PGear;
 
     PVisualGear = ^TVisualGear;
--- a/hedgewars/uUtils.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uUtils.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -82,10 +82,13 @@
 if i > 0 then
     begin
     for t:= 1 to Pred(i) do
-        if (a[t] >= 'A')and(a[t] <= 'Z') then Inc(a[t], 32);
+        if (a[t] >= 'A')and(a[t] <= 'Z') then
+            Inc(a[t], 32);
     b:= copy(a, i + 1, Length(a) - i);
     byte(a[0]):= Pred(i)
-    end else b:= '';
+    end
+else
+    b:= '';
 end;
 
 procedure SplitByChar(var a, b: ansistring; c: char);
@@ -131,12 +134,18 @@
 
 function Min(a, b: LongInt): LongInt;
 begin
-if a < b then Min:= a else Min:= b
+if a < b then
+    Min:= a
+else
+    Min:= b
 end;
 
 function Max(a, b: LongInt): LongInt;
 begin
-if a > b then Max:= a else Max:= b
+if a > b then
+    Max:= a
+else
+    Max:= b
 end;
 
 
@@ -155,9 +164,11 @@
 var dY, dX: Extended;
 begin
 dY:= _dY.QWordValue / $100000000;
-if _dY.isNegative then dY:= - dY;
+if _dY.isNegative then
+    dY:= - dY;
 dX:= _dX.QWordValue / $100000000;
-if _dX.isNegative then dX:= - dX;
+if _dX.isNegative then
+    dX:= - dX;
 DxDy2Angle:= arctan2(dY, dX) * 180 / pi
 end;
 
@@ -166,9 +177,11 @@
 var dY, dX: Extended;
 begin
 dY:= _dY.QWordValue / $100000000;
-if _dY.isNegative then dY:= - dY;
+if _dY.isNegative then
+    dY:= - dY;
 dX:= _dX.QWordValue / $100000000;
-if _dX.isNegative then dX:= - dX;
+if _dX.isNegative then
+    dX:= - dX;
 DxDy2Angle32:= trunc(arctan2(dY, dX) * _16divPI) and $1f
 end;
 
@@ -177,9 +190,11 @@
 var dY, dX: Extended;
 begin
 dY:= _dY.QWordValue / $100000000;
-if _dY.isNegative then dY:= - dY;
+if _dY.isNegative then
+    dY:= - dY;
 dX:= _dX.QWordValue / $100000000;
-if _dX.isNegative then dX:= - dX;
+if _dX.isNegative then
+    dX:= - dX;
 DxDy2AttackAngle:= trunc(arctan2(dY, dX) * MaxAngleDivPI)
 end;
 
@@ -215,8 +230,12 @@
 for i:= 1 to Length(s) do
     begin
     t:= Pos(s[i], table);
-    if s[i] = '=' then inc(c);
-    if t > 0 then byte(s[i]):= t - 1 else byte(s[i]):= 0
+    if s[i] = '=' then
+        inc(c);
+    if t > 0 then
+        byte(s[i]):= t - 1
+    else
+        byte(s[i]):= 0
     end;
 
 i:= 1;
@@ -230,7 +249,8 @@
     inc(i, 4)
     end;
 
-if c < 3 then t:= t - c;
+if c < 3 then
+    t:= t - c;
 
 byte(DecodeBase64[0]):= t - 1
 end;
@@ -309,7 +329,7 @@
 
 function GetLaunchX(at: TAmmoType; dir: LongInt; angle: LongInt): LongInt;
 begin
-    GetLaunchX:= 0
+GetLaunchX:= 0
 (*
     if (Ammoz[at].ejectX <> 0) or (Ammoz[at].ejectY <> 0) then
         GetLaunchX:= sign(dir) * (8 + hwRound(AngleSin(angle) * Ammoz[at].ejectX) + hwRound(AngleCos(angle) * Ammoz[at].ejectY))
@@ -319,7 +339,7 @@
 
 function GetLaunchY(at: TAmmoType; angle: LongInt): LongInt;
 begin
-    GetLaunchY:= 0
+GetLaunchY:= 0
 (*
     if (Ammoz[at].ejectX <> 0) or (Ammoz[at].ejectY <> 0) then
         GetLaunchY:= hwRound(AngleSin(angle) * Ammoz[at].ejectY) - hwRound(AngleCos(angle) * Ammoz[at].ejectX) - 2
@@ -349,10 +369,12 @@
             begin
                 assign(f, UserPathPrefix + '/Logs/' + cLogfileBase + inttostr(i) + '.log');
                 rewrite(f);
-                if IOResult = 0 then break;
+                if IOResult = 0 then
+                    break;
                 inc(i)
             end;
-            if i = 7 then f:= stderr; // if everything fails, write to stderr
+            if i = 7 then
+                f:= stderr; // if everything fails, write to stderr
         end
     else
         f:= stderr;
@@ -364,7 +386,7 @@
 
 procedure freeModule;
 begin
-    recordFileName:= '';
+recordFileName:= '';
 
 {$IFDEF DEBUGFILE}
     writeln(f, 'halt at ', GameTicks, ' ticks. TurnTimeLeft = ', TurnTimeLeft);
--- a/hedgewars/uVisualGears.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uVisualGears.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -120,7 +120,8 @@
 begin
 AddVisualGear:= nil;
 if ((GameType = gmtSave) or (fastUntilLag and (GameType = gmtNet))) and // we are scrolling now
-   ((Kind <> vgtCloud) and (not Critical)) then exit;
+   ((Kind <> vgtCloud) and (not Critical)) then
+       exit;
 
 if ((cReducedQuality and rqAntiBoom) <> 0) and
    (not Critical) and
@@ -133,7 +134,9 @@
     vgtSmokeTrace,
     vgtEvilTrace,
     vgtNote,
-    vgtSmoothWindBar])) then exit;
+    vgtSmoothWindBar])) then
+    
+        exit;
 
 inc(VGCounter);
 New(gear);
@@ -149,7 +152,8 @@
 
 with gear^ do
     case Kind of
-    vgtFlake: begin
+    vgtFlake:
+                begin
                 Timer:= 0;
                 tdX:= 0;
                 tdY:= 0;
@@ -167,103 +171,131 @@
                 Angle:= random * 360;
                 dx:= 0.0000038654705 * random(10000);
                 dy:= 0.000003506096 * random(7000);
-                if random(2) = 0 then dx := -dx;
-                if SuddenDeathDmg then dAngle:= (random(2) * 2 - 1) * (1 + random) * vobSDVelocity / 1000
-                else dAngle:= (random(2) * 2 - 1) * (1 + random) * vobVelocity / 1000
+                if random(2) = 0 then
+                    dx := -dx;
+                if SuddenDeathDmg then
+                    dAngle:= (random(2) * 2 - 1) * (1 + random) * vobSDVelocity / 1000
+                else
+                    dAngle:= (random(2) * 2 - 1) * (1 + random) * vobVelocity / 1000
                 end;
-    vgtCloud: begin
+    vgtCloud:
+                begin
                 Frame:= random(4);
                 dx:= 0.5 + 0.1 * random(5); // how much the cloud will be affected by wind
                 timer:= random(4096);
                 Scale:= 1.0
                 end;
     vgtExplPart,
-    vgtExplPart2: begin
+    vgtExplPart2:
+                begin
                 t:= random(1024);
                 sp:= 0.001 * (random(95) + 70);
                 dx:= hwFloat2Float(AngleSin(t)) * sp;
                 dy:= hwFloat2Float(AngleCos(t)) * sp;
-                if random(2) = 0 then dx := -dx;
-                if random(2) = 0 then dy := -dy;
+                if random(2) = 0 then
+                    dx := -dx;
+                if random(2) = 0 then
+                    dy := -dy;
                 Frame:= 7 - random(3);
                 FrameTicks:= cExplFrameTicks
                 end;
-        vgtFire: begin
+        vgtFire:
+                begin
                 t:= random(1024);
                 sp:= 0.001 * (random(85) + 95);
                 dx:= hwFloat2Float(AngleSin(t)) * sp;
                 dy:= hwFloat2Float(AngleCos(t)) * sp;
-                if random(2) = 0 then dx := -dx;
-                if random(2) = 0 then dy := -dy;
+                if random(2) = 0 then
+                    dx := -dx;
+                if random(2) = 0 then
+                    dy := -dy;
                 FrameTicks:= 650 + random(250);
                 Frame:= random(8)
                 end;
-         vgtEgg: begin
+         vgtEgg:
+                begin
                 t:= random(1024);
                 sp:= 0.001 * (random(85) + 95);
                 dx:= hwFloat2Float(AngleSin(t)) * sp;
                 dy:= hwFloat2Float(AngleCos(t)) * sp;
-                if random(2) = 0 then dx := -dx;
-                if random(2) = 0 then dy := -dy;
+                if random(2) = 0 then
+                    dx := -dx;
+                if random(2) = 0 then
+                    dy := -dy;
                 FrameTicks:= 650 + random(250);
                 Frame:= 1
                 end;
         vgtShell: FrameTicks:= 500;
-    vgtSmallDamageTag: begin
+    vgtSmallDamageTag:
+                begin
                 gear^.FrameTicks:= 1100
                 end;
-    vgtBubble: begin
+    vgtBubble:
+                begin
                 dx:= 0.0000038654705 * random(10000);
                 dy:= 0;
-                if random(2) = 0 then dx := -dx;
+                if random(2) = 0 then
+                    dx := -dx;
                 FrameTicks:= 250 + random(1751);
                 Frame:= random(5)
                 end;
-    vgtSteam: begin
+    vgtSteam:
+                begin
                 dx:= 0.0000038654705 * random(10000);
                 dy:= 0.001 * (random(85) + 95);
-                if random(2) = 0 then dx := -dx;
+                if random(2) = 0 then
+                    dx := -dx;
                 Frame:= 7 - random(3);
                 FrameTicks:= cExplFrameTicks * 2;
                 end;
-    vgtAmmo: begin
+    vgtAmmo:
+                begin
                 alpha:= 1.0;
                 scale:= 1.0
                 end;
   vgtSmokeWhite,
-  vgtSmoke: begin
+  vgtSmoke:
+                begin
                 Scale:= 1.0;
                 dx:= 0.0002 * (random(45) + 10);
                 dy:= 0.0002 * (random(45) + 10);
-                if random(2) = 0 then dx := -dx;
+                if random(2) = 0 then
+                    dx := -dx;
                 Frame:= 7 - random(2);
                 FrameTicks:= cExplFrameTicks * 2;
                 end;
-  vgtDust: begin
+  vgtDust:
+                begin
                 dx:= 0.005 * (random(15) + 10);
                 dy:= 0.001 * (random(40) + 20);
-                if random(2) = 0 then dx := -dx;
+                if random(2) = 0 then
+                    dx := -dx;
                 Frame:= 7 - random(2);
                 FrameTicks:= random(20) + 15;
                 end;
-  vgtSplash: begin
+  vgtSplash:
+                begin
                 dx:= 0;
                 dy:= 0;
                 FrameTicks:= 740;
                 Frame:= 19;
                 end;
-    vgtDroplet: begin
+    vgtDroplet:
+                begin
                 dx:= 0.001 * (random(75) + 15);
                 dy:= -0.001 * (random(80) + 120);
-                if random(2) = 0 then dx := -dx;
+                if random(2) = 0 then
+                    dx := -dx;
                 FrameTicks:= 250 + random(1751);
                 Frame:= random(3)
                 end;
-   vgtBeeTrace: begin
+   vgtBeeTrace:
+                begin
                 FrameTicks:= 1000;
                 Frame:= random(16);
                 end;
-    vgtSmokeRing: begin
+    vgtSmokeRing:
+                begin
                 dx:= 0;
                 dy:= 0;
                 FrameTicks:= 600;
@@ -273,17 +305,21 @@
                 alpha:= 1;
                 angle:= random(360);
                 end;
-     vgtFeather: begin
+     vgtFeather:
+                begin
                 t:= random(1024);
                 sp:= 0.001 * (random(85) + 95);
                 dx:= hwFloat2Float(AngleSin(t)) * sp;
                 dy:= hwFloat2Float(AngleCos(t)) * sp;
-                if random(2) = 0 then dx := -dx;
-                if random(2) = 0 then dy := -dy;
+                if random(2) = 0 then
+                    dx := -dx;
+                if random(2) = 0 then
+                    dy := -dy;
                 FrameTicks:= 650 + random(250);
                 Frame:= 1
                 end;
-  vgtHealthTag: begin
+  vgtHealthTag:
+                begin
                 Frame:= 0;
                 Timer:= 1500;
                 dY:= -0.08;
@@ -291,31 +327,38 @@
                 //gear^.Z:= 2002;
                 end;
   vgtSmokeTrace,
-  vgtEvilTrace: begin
+  vgtEvilTrace:
+                begin
                 gear^.X:= gear^.X - 16;
                 gear^.Y:= gear^.Y - 16;
                 gear^.State:= 8;
                 //gear^.Z:= cSmokeZ
                 end;
-vgtBigExplosion: begin
+vgtBigExplosion:
+                begin
                 gear^.Angle:= random(360);
                 end;
-      vgtChunk: begin
+      vgtChunk:
+                begin
                 gear^.Frame:= random(4);
                 t:= random(1024);
                 sp:= 0.001 * (random(85) + 47);
                 dx:= hwFloat2Float(AngleSin(t)) * sp;
                 dy:= hwFloat2Float(AngleCos(t)) * sp * -2;
-                if random(2) = 0 then dx := -dx;
+                if random(2) = 0 then
+                    dx := -dx;
                 end;
-      vgtNote: begin
+      vgtNote: 
+                begin
                 dx:= 0.005 * (random(15) + 10);
                 dy:= -0.001 * (random(40) + 20);
-                if random(2) = 0 then dx := -dx;
+                if random(2) = 0 then
+                    dx := -dx;
                 Frame:= random(4);
                 FrameTicks:= random(2000) + 1500;
                 end;
-  vgtBulletHit: begin
+  vgtBulletHit:
+                begin
                 dx:= 0;
                 dy:= 0;
                 FrameTicks:= 350;
@@ -323,23 +366,27 @@
                 Angle:= 0;
                 end;
 vgtSmoothWindBar: Tag:= hwRound(cWindSpeed * 72 / cMaxWindSpeed);
- vgtStraightShot: begin
+ vgtStraightShot:
+                begin
                 Angle:= 0;
                 Scale:= 1.0;
                 dx:= 0.001 * random(45);
                 dy:= 0.001 * (random(20) + 25);
                 State:= ord(sprHealth);
-                if random(2) = 0 then dx := -dx;
+                if random(2) = 0 then
+                    dx := -dx;
                 Frame:= 0;
                 FrameTicks:= random(750) + 1250;
                 State:= ord(sprSnowDust);
                 end;
         end;
 
-if State <> 0 then gear^.State:= State;
+if State <> 0 then
+    gear^.State:= State;
 
 case Gear^.Kind of
-    vgtFlake: if cFlattenFlakes then gear^.Layer:= 0
+    vgtFlake: if cFlattenFlakes then
+        gear^.Layer:= 0
               else if random(3) = 0 then 
                   begin
                   gear^.Scale:= 0.5;
@@ -350,12 +397,15 @@
                   gear^.Scale:= 0.8;
                   gear^.Layer:= 4   // 22% - mid-distance
                   end
-              else if random(3) <> 0 then gear^.Layer:= 5  // 30% - just behind land
-              else if random(2) = 0 then gear^.Layer:= 6   // 7% - just in front of land
-              else begin
-                   gear^.Scale:= 1.5;
-                   gear^.Layer:= 2;  // 7% - close up
-                   end;
+              else if random(3) <> 0 then
+                  gear^.Layer:= 5  // 30% - just behind land
+              else if random(2) = 0 then
+                  gear^.Layer:= 6   // 7% - just in front of land
+              else
+                  begin
+                  gear^.Scale:= 1.5;
+                  gear^.Layer:= 2;  // 7% - close up
+                  end;
 
     vgtCloud: if cFlattenClouds then gear^.Layer:= 5
               else if random(3) = 0 then
@@ -363,11 +413,13 @@
                   gear^.Scale:= 0.25;
                   gear^.Layer:= 0
                   end
-              else if random(2) = 0 then gear^.Layer:= 5
-              else begin
-                   gear^.Scale:= 0.4;
-                   gear^.Layer:= 4
-                   end;
+              else if random(2) = 0 then
+                  gear^.Layer:= 5
+              else
+                  begin
+                  gear^.Scale:= 0.4;
+                  gear^.Layer:= 4
+                  end;
 
     // 0: this layer is very distant in the background when in stereo
     vgtTeamHealthSorter,
@@ -425,11 +477,15 @@
     FreeTexture(Gear^.Tex);
     Gear^.Tex:= nil;
 
-    if Gear^.NextGear <> nil then Gear^.NextGear^.PrevGear:= Gear^.PrevGear;
-    if Gear^.PrevGear <> nil then Gear^.PrevGear^.NextGear:= Gear^.NextGear
-    else VisualGearLayers[Gear^.Layer]:= Gear^.NextGear;
+    if Gear^.NextGear <> nil then
+        Gear^.NextGear^.PrevGear:= Gear^.PrevGear;
+    if Gear^.PrevGear <> nil then
+        Gear^.PrevGear^.NextGear:= Gear^.NextGear
+    else
+        VisualGearLayers[Gear^.Layer]:= Gear^.NextGear;
 
-    if lastVisualGearByUID = Gear then lastVisualGearByUID:= nil;
+    if lastVisualGearByUID = Gear then
+        lastVisualGearByUID:= nil;
 
     Dispose(Gear);
 end;
@@ -438,17 +494,18 @@
 var Gear, t: PVisualGear;
     i: LongWord;
 begin
-if Steps = 0 then exit;
+if Steps = 0 then
+    exit;
 
 for i:= 0 to 6 do
     begin
     t:= VisualGearLayers[i];
     while t <> nil do
-          begin
-          Gear:= t;
-          t:= Gear^.NextGear;
-          Gear^.doStep(Gear, Steps)
-          end;
+        begin
+        Gear:= t;
+        t:= Gear^.NextGear;
+        Gear^.doStep(Gear, Steps)
+        end;
     end
 end;
 
@@ -456,30 +513,33 @@
 var Gear, t: PVisualGear;
     dmg, i: LongInt;
 begin
-if (vobCount = 0) or (vobCount > 200) then exit;
+if (vobCount = 0) or (vobCount > 200) then
+    exit;
 for i:= 2 to 6 do
     if i <> 3 then
         begin
         t:= VisualGearLayers[i];
         while t <> nil do
-              begin
-              Gear:= t;
-              if Gear^.Kind = vgtFlake then
-                  begin
-                  // Damage calc from doMakeExplosion
-                  dmg:= Min(101, Radius + cHHRadius div 2 - LongInt(abs(round(Gear^.X) - X) + abs(round(Gear^.Y) - Y)) div 5);
-                  if dmg > 1 then
-                      begin
-                      Gear^.tdX:= 0.02 * dmg + 0.01;
-                      if Gear^.X - X < 0 then Gear^.tdX := -Gear^.tdX;
-                      Gear^.tdY:= 0.02 * dmg + 0.01;
-                      if Gear^.Y - Y < 0 then Gear^.tdY := -Gear^.tdY;
-                      Gear^.Timer:= 200
-                      end
-                  end;
-              t:= Gear^.NextGear
-              end
-         end
+            begin
+            Gear:= t;
+            if Gear^.Kind = vgtFlake then
+                begin
+                // Damage calc from doMakeExplosion
+                dmg:= Min(101, Radius + cHHRadius div 2 - LongInt(abs(round(Gear^.X) - X) + abs(round(Gear^.Y) - Y)) div 5);
+                if dmg > 1 then
+                    begin
+                    Gear^.tdX:= 0.02 * dmg + 0.01;
+                    if Gear^.X - X < 0 then
+                        Gear^.tdX := -Gear^.tdX;
+                    Gear^.tdY:= 0.02 * dmg + 0.01;
+                    if Gear^.Y - Y < 0 then
+                        Gear^.tdY := -Gear^.tdY;
+                    Gear^.Timer:= 200
+                    end
+                end;
+            t:= Gear^.NextGear
+            end
+        end
 end;
 
 procedure DrawVisualGears(Layer: LongWord);
@@ -491,11 +551,11 @@
 case Layer of
     // this layer is very distant in the background when stereo
     0: begin
-       Gear:= VisualGearLayers[0];
-       while Gear <> nil do
-           begin
-           if Gear^.Tint <> $FFFFFFFF then Tint(Gear^.Tint);
-           case Gear^.Kind of
+        Gear:= VisualGearLayers[0];
+        while Gear <> nil do
+            begin
+            if Gear^.Tint <> $FFFFFFFF then Tint(Gear^.Tint);
+            case Gear^.Kind of
               vgtCloud: if SuddenDeathDmg then
                              DrawTextureF(SpritesData[sprSDCloud].Texture, Gear^.Scale, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 2, SpritesData[sprCloud].Width, SpritesData[sprCloud].Height)
                          else
@@ -527,7 +587,8 @@
                                      DrawRotatedTextureF(SpritesData[sprFlake].Texture, Gear^.Scale, 0, 0, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, SpritesData[sprFlake].Width, SpritesData[sprFlake].Height, Gear^.Angle)
                              end;
                end;
-           if Gear^.Tint <> $FFFFFFFF then Tint($FF,$FF,$FF,$FF);
+           if Gear^.Tint <> $FFFFFFFF then
+               Tint($FF,$FF,$FF,$FF);
            Gear:= Gear^.NextGear
            end
        end;
@@ -537,7 +598,8 @@
        while Gear <> nil do
           begin
           //tinted:= false;
-          if Gear^.Tint <> $FFFFFFFF then Tint(Gear^.Tint);
+          if Gear^.Tint <> $FFFFFFFF then
+              Tint(Gear^.Tint);
           case Gear^.Kind of
               vgtFlake: if SuddenDeathDmg then
                              if vobSDVelocity = 0 then
@@ -549,8 +611,10 @@
                                  DrawSprite(sprFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame)
                              else
                                  DrawRotatedF(sprFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, Gear^.Angle);
-              vgtSmokeTrace: if Gear^.State < 8 then DrawSprite(sprSmokeTrace, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.State);
-              vgtEvilTrace: if Gear^.State < 8 then DrawSprite(sprEvilTrace, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.State);
+              vgtSmokeTrace: if Gear^.State < 8 then
+                  DrawSprite(sprSmokeTrace, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.State);
+              vgtEvilTrace: if Gear^.State < 8 then
+                  DrawSprite(sprEvilTrace, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.State);
               vgtLineTrail: DrawLine(Gear^.X, Gear^.Y, Gear^.dX, Gear^.dY, 1.0, $FF, min(Gear^.Timer, $C0), min(Gear^.Timer, $80), min(Gear^.Timer, $FF));
           end;
           if (cReducedQuality and rqAntiBoom) = 0 then
@@ -576,7 +640,8 @@
                   vgtBubble: DrawSprite(sprBubbles, round(Gear^.X) + WorldDx - 8, round(Gear^.Y) + WorldDy - 8, Gear^.Frame);//(RealTicks div 64 + Gear^.Frame) mod 8);
               end;
           //if (Gear^.Tint <> $FFFFFFFF) or tinted then Tint($FF,$FF,$FF,$FF);
-          if (Gear^.Tint <> $FFFFFFFF) then Tint($FF,$FF,$FF,$FF);
+          if (Gear^.Tint <> $FFFFFFFF) then
+              Tint($FF,$FF,$FF,$FF);
           Gear:= Gear^.NextGear
           end
        end;
@@ -586,7 +651,8 @@
        while Gear <> nil do
            begin
            tinted:= false;
-           if Gear^.Tint <> $FFFFFFFF then Tint(Gear^.Tint);
+           if Gear^.Tint <> $FFFFFFFF then
+               Tint(Gear^.Tint);
            case Gear^.Kind of
 (*
               vgtFlake: if SuddenDeathDmg then
@@ -617,13 +683,18 @@
                                else
                                    begin
                                    SetScale(cDefaultZoomLevel);
-                                   if Gear^.Angle = 0 then DrawTexture(round(Gear^.X), round(Gear^.Y), Gear^.Tex)
-                                   else DrawTexture(round(Gear^.X), round(Gear^.Y), Gear^.Tex, Gear^.Angle); 
+                                   if Gear^.Angle = 0 then
+                                       DrawTexture(round(Gear^.X), round(Gear^.Y), Gear^.Tex)
+                                   else
+                                       DrawTexture(round(Gear^.X), round(Gear^.Y), Gear^.Tex, Gear^.Angle); 
                                    SetScale(zoom)
                                    end
                                end;
                vgtStraightShot: begin 
-                                if Gear^.dX < 0 then i:= -1 else i:= 1;
+                                if Gear^.dX < 0 then
+                                    i:= -1
+                                else
+                                    i:= 1;
                                 DrawRotatedTextureF(SpritesData[TSprite(Gear^.State)].Texture, Gear^.Scale, 0, 0, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.Frame, i, SpritesData[TSprite(Gear^.State)].Width, SpritesData[TSprite(Gear^.State)].Height, Gear^.Angle);
                                 end;
            end;
@@ -631,7 +702,8 @@
                case Gear^.Kind of
                    vgtChunk: DrawRotatedF(sprChunk, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.Frame, 1, Gear^.Angle);
                end;
-           if (Gear^.Tint <> $FFFFFFFF) or tinted then Tint($FF,$FF,$FF,$FF);
+           if (Gear^.Tint <> $FFFFFFFF) or tinted then
+               Tint($FF,$FF,$FF,$FF);
            Gear:= Gear^.NextGear
            end
        end;
@@ -641,7 +713,8 @@
        while Gear <> nil do
            begin
            tinted:= false;
-           if Gear^.Tint <> $FFFFFFFF then Tint(Gear^.Tint);
+           if Gear^.Tint <> $FFFFFFFF then
+               Tint(Gear^.Tint);
            case Gear^.Kind of
                vgtExplosion: DrawSprite(sprExplosion50, round(Gear^.X) - 32 + WorldDx, round(Gear^.Y) - 32 + WorldDy, Gear^.State);
                vgtBigExplosion: begin
@@ -710,86 +783,94 @@
                               tmp:= Gear^.State / 100;
                               DrawTexture(round(Gear^.X-24*tmp) + WorldDx, round(Gear^.Y-24*tmp) + WorldDy, SpritesData[sprVampiric].Texture, tmp)
                               end
-                          else DrawCircle(round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.State, Gear^.Timer);
+                          else
+                              DrawCircle(round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy, Gear^.State, Gear^.Timer);
            end;
-           if (Gear^.Tint <> $FFFFFFFF) or tinted then Tint($FF,$FF,$FF,$FF);
-           Gear:= Gear^.NextGear
-           end
-       end;
-    // this layer is half-way between the screen plane (depth = 0) when in stereo, and the land
-    4: begin
-       Gear:= VisualGearLayers[4];
-       while Gear <> nil do
-           begin
-           if Gear^.Tint <> $FFFFFFFF then Tint(Gear^.Tint);
-           case Gear^.Kind of
-              vgtCloud: if SuddenDeathDmg then
-                             DrawTextureF(SpritesData[sprSDCloud].Texture, Gear^.Scale, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 2, SpritesData[sprCloud].Width, SpritesData[sprCloud].Height)
-                         else
-                            DrawTextureF(SpritesData[sprCloud].Texture, Gear^.Scale, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 2, SpritesData[sprCloud].Width, SpritesData[sprCloud].Height);
-              vgtFlake: if SuddenDeathDmg then
-                             if vobSDVelocity = 0 then
-                                 DrawTextureF(SpritesData[sprSDFlake].Texture, Gear^.Scale, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, SpritesData[sprFlake].Width, SpritesData[sprFlake].Height)
-                             else
-                                 DrawRotatedTextureF(SpritesData[sprSDFlake].Texture, Gear^.Scale, 0, 0, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, SpritesData[sprFlake].Width, SpritesData[sprFlake].Height, Gear^.Angle)
-                         else
-                             if vobVelocity = 0 then
-                                 DrawTextureF(SpritesData[sprFlake].Texture, Gear^.Scale, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, SpritesData[sprFlake].Width, SpritesData[sprFlake].Height)
-                             else
-                                 DrawRotatedTextureF(SpritesData[sprFlake].Texture, Gear^.Scale, 0, 0, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, SpritesData[sprFlake].Width, SpritesData[sprFlake].Height, Gear^.Angle);
-               end;
-           if (Gear^.Tint <> $FFFFFFFF) then Tint($FF,$FF,$FF,$FF);
+           if (Gear^.Tint <> $FFFFFFFF) or tinted then
+               Tint($FF,$FF,$FF,$FF);
            Gear:= Gear^.NextGear
            end
        end;
-    // this layer is on the screen plane (depth = 0) when stereo, but just behind the land
-    5: begin
-       Gear:= VisualGearLayers[5];
-       while Gear <> nil do
-           begin
-           if Gear^.Tint <> $FFFFFFFF then Tint(Gear^.Tint);
-           case Gear^.Kind of
+     // this layer is half-way between the screen plane (depth = 0) when in stereo, and the land
+     4: begin
+        Gear:= VisualGearLayers[4];
+        while Gear <> nil do
+            begin
+            if Gear^.Tint <> $FFFFFFFF then
+                Tint(Gear^.Tint);
+            case Gear^.Kind of
                vgtCloud: if SuddenDeathDmg then
-                             DrawSprite(sprSDCloud, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame)
-                         else
-                             DrawSprite(sprCloud, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame);
+                            DrawTextureF(SpritesData[sprSDCloud].Texture, Gear^.Scale, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 2, SpritesData[sprCloud].Width, SpritesData[sprCloud].Height)
+                        else
+                            DrawTextureF(SpritesData[sprCloud].Texture, Gear^.Scale, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 2, SpritesData[sprCloud].Width, SpritesData[sprCloud].Height);
               vgtFlake: if SuddenDeathDmg then
-                             if vobSDVelocity = 0 then
-                                 DrawSprite(sprSDFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame)
-                             else
-                                 DrawRotatedF(sprSDFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, Gear^.Angle)
-                         else
-                             if vobVelocity = 0 then
-                                 DrawSprite(sprFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame)
-                             else
-                                 DrawRotatedF(sprFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, Gear^.Angle);
-               end;
-           if (Gear^.Tint <> $FFFFFFFF) then Tint($FF,$FF,$FF,$FF);
-           Gear:= Gear^.NextGear
-           end
-       end;
-    // this layer is on the screen plane (depth = 0) when stereo, but just in front of the land
+                            if vobSDVelocity = 0 then
+                                DrawTextureF(SpritesData[sprSDFlake].Texture, Gear^.Scale, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, SpritesData[sprFlake].Width, SpritesData[sprFlake].Height)
+                            else
+                                DrawRotatedTextureF(SpritesData[sprSDFlake].Texture, Gear^.Scale, 0, 0, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, SpritesData[sprFlake].Width, SpritesData[sprFlake].Height, Gear^.Angle)
+                        else
+                            if vobVelocity = 0 then
+                                DrawTextureF(SpritesData[sprFlake].Texture, Gear^.Scale, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, SpritesData[sprFlake].Width, SpritesData[sprFlake].Height)
+                            else
+                                DrawRotatedTextureF(SpritesData[sprFlake].Texture, Gear^.Scale, 0, 0, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, SpritesData[sprFlake].Width, SpritesData[sprFlake].Height, Gear^.Angle);
+            end;
+            if (Gear^.Tint <> $FFFFFFFF) then
+                Tint($FF,$FF,$FF,$FF);
+            Gear:= Gear^.NextGear
+            end
+        end;
+     // this layer is on the screen plane (depth = 0) when stereo, but just behind the land
+     5: begin
+        Gear:= VisualGearLayers[5];
+        while Gear <> nil do
+            begin
+            if Gear^.Tint <> $FFFFFFFF then
+                Tint(Gear^.Tint);
+            case Gear^.Kind of
+                vgtCloud: if SuddenDeathDmg then
+                            DrawSprite(sprSDCloud, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame)
+                          else
+                            DrawSprite(sprCloud, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame);
+              vgtFlake: if SuddenDeathDmg then
+                            if vobSDVelocity = 0 then
+                                DrawSprite(sprSDFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame)
+                            else
+                                DrawRotatedF(sprSDFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, Gear^.Angle)
+                          else
+                            if vobVelocity = 0 then
+                                DrawSprite(sprFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame)
+                            else
+                                DrawRotatedF(sprFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, Gear^.Angle);
+                end;
+            if (Gear^.Tint <> $FFFFFFFF) then
+                Tint($FF,$FF,$FF,$FF);
+            Gear:= Gear^.NextGear
+            end
+        end;
+     // this layer is on the screen plane (depth = 0) when stereo, but just in front of the land
     6: begin
-       Gear:= VisualGearLayers[6];
-       while Gear <> nil do
-           begin
-           if Gear^.Tint <> $FFFFFFFF then Tint(Gear^.Tint);
-           case Gear^.Kind of
-              vgtFlake: if SuddenDeathDmg then
-                             if vobSDVelocity = 0 then
-                                 DrawSprite(sprSDFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame)
-                             else
-                                 DrawRotatedF(sprSDFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, Gear^.Angle)
-                         else
-                             if vobVelocity = 0 then
-                                 DrawSprite(sprFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame)
-                             else
-                                 DrawRotatedF(sprFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, Gear^.Angle);
-               end;
-           if (Gear^.Tint <> $FFFFFFFF) then Tint($FF,$FF,$FF,$FF);
-           Gear:= Gear^.NextGear
-           end
-       end;
+        Gear:= VisualGearLayers[6];
+        while Gear <> nil do
+            begin
+            if Gear^.Tint <> $FFFFFFFF then
+                Tint(Gear^.Tint);
+            case Gear^.Kind of
+                vgtFlake: if SuddenDeathDmg then
+                            if vobSDVelocity = 0 then
+                                DrawSprite(sprSDFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame)
+                            else
+                                DrawRotatedF(sprSDFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, Gear^.Angle)
+                          else
+                            if vobVelocity = 0 then
+                                DrawSprite(sprFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame)
+                            else
+                                DrawRotatedF(sprFlake, round(Gear^.X) + WorldDx, round(Gear^.Y) + WorldDy + SkyOffset, Gear^.Frame, 1, Gear^.Angle);
+                end;
+            if (Gear^.Tint <> $FFFFFFFF) then
+                Tint($FF,$FF,$FF,$FF);
+            Gear:= Gear^.NextGear
+            end
+        end;
     end;
 end;
 
@@ -798,7 +879,8 @@
     i: LongWord;
 begin
 VisualGearByUID:= nil;
-if uid = 0 then exit;
+if uid = 0 then
+    exit;
 if (lastVisualGearByUID <> nil) and (lastVisualGearByUID^.uid = uid) then
     begin
     VisualGearByUID:= lastVisualGearByUID;
@@ -811,11 +893,11 @@
     while vg <> nil do
         begin
         if vg^.uid = uid then
-    	    begin
-    	    lastVisualGearByUID:= vg;
-    	    VisualGearByUID:= vg;
-    	    exit
-    	    end;
+            begin
+            lastVisualGearByUID:= vg;
+            VisualGearByUID:= vg;
+            exit
+            end;
         vg:= vg^.NextGear
         end
     end
@@ -832,7 +914,8 @@
 var       i: LongInt;
     vg, tmp: PVisualGear;
 begin
-if cCloudsNumber = cSDCloudsNumber then exit;
+if cCloudsNumber = cSDCloudsNumber then
+    exit;
 vg:= VisualGearLayers[0];
 while vg <> nil do
     if vg^.Kind = vgtCloud then
@@ -849,7 +932,8 @@
 procedure AddFlakes;
 var i: LongInt;
 begin
-if (cReducedQuality and rqKillFlakes) <> 0 then exit;
+if (cReducedQuality and rqKillFlakes) <> 0 then
+    exit;
 
 if hasBorder or ((Theme <> 'Snow') and (Theme <> 'Christmas')) then
     for i:= 0 to Pred(vobCount * cScreenSpace div LAND_WIDTH) do
@@ -863,8 +947,10 @@
 var       i: LongInt;
     vg, tmp: PVisualGear;
 begin
-if (cReducedQuality and rqKillFlakes) <> 0 then exit;
-if vobCount = vobSDCount then exit;
+if (cReducedQuality and rqKillFlakes) <> 0 then
+    exit;
+if vobCount = vobSDCount then
+    exit;
 for i:= 0 to 6 do
     begin
     vg:= VisualGearLayers[i];
--- a/hedgewars/uWorld.pas	Mon Jan 16 00:03:13 2012 +0100
+++ b/hedgewars/uWorld.pas	Wed Jan 18 01:11:09 2012 +0100
@@ -110,29 +110,32 @@
 missionTimer:= 0;
 
 if (GameFlags and gfRandomOrder) <> 0 then  // shuffle them up a bit
-   begin
-   for i:= 0 to ClansCount * 4 do
-      begin
-      t:= GetRandom(ClansCount);
-      if t <> 0 then
-         begin
-         cp:= ClansArray[0];
-         ClansArray[0]:= ClansArray[t];
-         ClansArray[t]:= cp;
-         ClansArray[t]^.ClanIndex:= t;
-         ClansArray[0]^.ClanIndex:= 0;
-         if (LocalClan = t) then LocalClan:= 0
-         else if (LocalClan = 0) then LocalClan:= t
-         end;
-      end;
-   CurrentTeam:= ClansArray[0]^.Teams[0];
-   end;
+    begin
+    for i:= 0 to ClansCount * 4 do
+        begin
+        t:= GetRandom(ClansCount);
+        if t <> 0 then
+            begin
+            cp:= ClansArray[0];
+            ClansArray[0]:= ClansArray[t];
+            ClansArray[t]:= cp;
+            ClansArray[t]^.ClanIndex:= t;
+            ClansArray[0]^.ClanIndex:= 0;
+            if (LocalClan = t) then
+                LocalClan:= 0
+            else if (LocalClan = 0) then
+                LocalClan:= t
+            end;
+        end;
+    CurrentTeam:= ClansArray[0]^.Teams[0];
+    end;
 
 // if special game flags/settings are changed, add them to the game mode notice window and then show it
 g:= ''; // no text/things to note yet
 
 // add custom goals from lua script if there are any
-if LuaGoals <> '' then g:= LuaGoals + '|';
+if LuaGoals <> '' then
+    g:= LuaGoals + '|';
 
 // check different game flags (goals/game modes first for now)
 g:= AddGoal(g, gfKing, gidKing); // king?
@@ -175,7 +178,8 @@
     end;
 
 // if the string has been set, show it for (default timeframe) seconds
-if g <> '' then ShowMission(trgoal[gidCaption], trgoal[gidSubCaption], g, 1, 0);
+if g <> '' then
+    ShowMission(trgoal[gidCaption], trgoal[gidSubCaption], g, 1, 0);
 
 cWaveWidth:= SpritesData[sprWater].Width;
 //cWaveHeight:= SpritesData[sprWater].Height;
@@ -233,19 +237,23 @@
     Slot, Pos, STurns: LongInt;
     Ammo: PHHAmmo;
 begin
-    if (TurnTimeLeft = 0) or (not CurrentTeam^.ExtDriven and (((CurAmmoGear = nil) or
-       ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) = 0)) and hideAmmoMenu)) then
+    if (TurnTimeLeft = 0) or (not CurrentTeam^.ExtDriven and (((CurAmmoGear = nil)
+    or ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) = 0)) and hideAmmoMenu)) then
         bShowAmmoMenu:= false;
 
     if bShowAmmoMenu then
     // show ammo menu
         begin
         FollowGear:= nil;
-        if AMxShift = AMWidth then prevPoint.X:= 0;
-        if (cReducedQuality and rqSlowMenu) <> 0 then AMxShift:= 0
+        if AMxShift = AMWidth then
+            prevPoint.X:= 0;
+        if (cReducedQuality and rqSlowMenu) <> 0 then
+            AMxShift:= 0
         else
-            if AMxShift > MENUSPEED then dec(AMxShift, MENUSPEED)
-            else AMxShift:= 0;
+            if AMxShift > MENUSPEED then
+                dec(AMxShift, MENUSPEED)
+            else
+                AMxShift:= 0;
         end
     else
     // hide ammo menu
@@ -256,16 +264,19 @@
             CursorPoint.Y:= cScreenHeight shr 1;
             prevPoint:= CursorPoint;
             end;
-        if (cReducedQuality and rqSlowMenu) <> 0 then AMxShift:= AMWidth+2
+        if (cReducedQuality and rqSlowMenu) <> 0 then
+            AMxShift:= AMWidth+2
         else
-            if AMxShift < (AMWidth - MENUSPEED) then inc(AMxShift, MENUSPEED)
-            else AMxShift:= AMWidth;
+            if AMxShift < (AMWidth - MENUSPEED) then
+                inc(AMxShift, MENUSPEED)
+            else
+                AMxShift:= AMWidth;
         end;
 
     // give the assigned ammo to hedgehog
     Ammo:= nil;
-    if (CurrentTeam <> nil) and (CurrentHedgehog <> nil) and
-       (not CurrentTeam^.ExtDriven) and (CurrentHedgehog^.BotLevel = 0) then
+    if (CurrentTeam <> nil) and (CurrentHedgehog <> nil)
+    and (not CurrentTeam^.ExtDriven) and (CurrentHedgehog^.BotLevel = 0) then
         Ammo:= CurrentHedgehog^.Ammo
     else if (LocalAmmo <> -1) then
         Ammo:= GetAmmoByNum(LocalAmmo);
@@ -292,7 +303,8 @@
     for i:= 0 to cMaxSlotIndex do
         if ((i = 0) and (Ammo^[i, 1].Count > 0)) or ((i <> 0) and (Ammo^[i, 0].Count > 0)) then
             begin
-            if (cScreenHeight - CursorPoint.Y >= y) and (cScreenHeight - CursorPoint.Y <= y + AMSlotSize) then Slot:= i;
+            if (cScreenHeight - CursorPoint.Y >= y) and (cScreenHeight - CursorPoint.Y <= y + AMSlotSize) then
+                Slot:= i;
             inc(SlotsNum);
             DrawSprite(sprAMBorderVertical, x - BORDERSIZE, y, 0);
             t:= 0;
@@ -307,14 +319,16 @@
                     if STurns >= 0 then
                         begin
                         DrawSprite(sprAMAmmosBW, x + g * AMSlotSize, y + 1, LongInt(Ammo^[i, t].AmmoType)-1);
-                        if STurns < 100 then DrawSprite(sprTurnsLeft, x + (g + 1) * AMSlotSize - 16, y + AMSlotSize - 16, STurns);
+                        if STurns < 100 then
+                            DrawSprite(sprTurnsLeft, x + (g + 1) * AMSlotSize - 16, y + AMSlotSize - 16, STurns);
                         end
                     else
                         DrawSprite(sprAMAmmos, x + g * AMSlotSize, y + 1, LongInt(Ammo^[i, t].AmmoType)-1);
                     if (Slot = i) and (CursorPoint.X >= x + g * AMSlotSize) and
                        (CursorPoint.X <= x + (g + 1) * AMSlotSize) then
                         begin
-                        if (STurns < 0) then DrawSprite(sprAMSlot, x + g * AMSlotSize, y, 0);
+                        if (STurns < 0) then
+                            DrawSprite(sprAMSlot, x + g * AMSlotSize, y, 0);
                         Pos:= t;
                         end;
                     inc(g)
@@ -329,7 +343,7 @@
 
     DrawSprite(sprAMCorners, x - BORDERSIZE, y, 2);
     for i:= 0 to cMaxSlotAmmoIndex do
-	DrawSprite(sprAMBorderHorizontal, x + i * AMSlotSize, y, 1);
+        DrawSprite(sprAMBorderHorizontal, x + i * AMSlotSize, y, 1);
     DrawSprite(sprAMCorners, x + AMWidth - AMxOffset, y, 3);
 {$ELSE}
     Slot:= 0;
@@ -348,7 +362,8 @@
     for i:= cMaxSlotIndex downto 0 do
         if ((i = 0) and (Ammo^[i, 1].Count > 0)) or ((i <> 0) and (Ammo^[i, 0].Count > 0)) then
             begin
-            if (cScreenHeight - CursorPoint.Y >= y - AMSlotSize) and (cScreenHeight - CursorPoint.Y <= y) then Slot:= i;
+            if (cScreenHeight - CursorPoint.Y >= y - AMSlotSize) and (cScreenHeight - CursorPoint.Y <= y) then
+                Slot:= i;
             dec(y, AMSlotSize);
             inc(SlotsNum);
             DrawSprite(sprAMBorderVertical, x - BORDERSIZE, y, 0);
@@ -366,13 +381,15 @@
                     if STurns >= 0 then
                         begin
                         DrawSprite(sprAMAmmosBW, x + g * AMSlotSize, y + 1, LongInt(Ammo^[i, t].AmmoType)-1);
-                        if STurns < 100 then DrawSprite(sprTurnsLeft, x + (g + 1) * AMSlotSize - 16, y + AMSlotSize - 16, STurns);
+                        if STurns < 100 then
+                            DrawSprite(sprTurnsLeft, x + (g + 1) * AMSlotSize - 16, y + AMSlotSize - 16, STurns);
                         end else
                         DrawSprite(sprAMAmmos, x + g * AMSlotSize, y + 1, LongInt(Ammo^[i, t].AmmoType)-1);
                     if (Slot = i) and (CursorPoint.X >= x + g * AMSlotSize) and
                        (CursorPoint.X <= x + (g + 1) * AMSlotSize) then
                         begin
-                        if (STurns < 0) then DrawSprite(sprAMSlot, x + g * AMSlotSize, y, 0);
+                        if (STurns < 0) then
+                            DrawSprite(sprAMSlot, x + g * AMSlotSize, y, 0);
                         Pos:= t;
                         end;
                     inc(g)
@@ -432,7 +449,8 @@
 {$ENDIF}
 
     bSelected:= false;
-    if AMxShift = 0 then DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8)
+    if AMxShift = 0 then
+        DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8)
 end;
 
 procedure DrawWater(Alpha: byte; OffsetY: LongInt);
@@ -440,27 +458,27 @@
     r: TSDL_Rect;
     lw, lh: GLfloat;
 begin
-    if SuddenDeathDmg then
-        begin
-        SDWaterColorArray[0].a := Alpha;
-        SDWaterColorArray[1].a := Alpha;
-        SDWaterColorArray[2].a := Alpha;
-        SDWaterColorArray[3].a := Alpha
-        end
-    else
-        begin
-        WaterColorArray[0].a := Alpha;
-        WaterColorArray[1].a := Alpha;
-        WaterColorArray[2].a := Alpha;
-        WaterColorArray[3].a := Alpha
-        end;
+if SuddenDeathDmg then
+    begin
+    SDWaterColorArray[0].a := Alpha;
+    SDWaterColorArray[1].a := Alpha;
+    SDWaterColorArray[2].a := Alpha;
+    SDWaterColorArray[3].a := Alpha
+    end
+else
+    begin
+    WaterColorArray[0].a := Alpha;
+    WaterColorArray[1].a := Alpha;
+    WaterColorArray[2].a := Alpha;
+    WaterColorArray[3].a := Alpha
+    end;
 
-    lw:= cScreenWidth / cScaleFactor;
-    lh:= trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 + 16;
+lw:= cScreenWidth / cScaleFactor;
+lh:= trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 + 16;
 
     // Water
-    r.y:= OffsetY + WorldDy + cWaterLine;
-    if WorldDy < trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 - cWaterLine then
+r.y:= OffsetY + WorldDy + cWaterLine;
+if WorldDy < trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 - cWaterLine then
     begin
         if r.y < 0 then
             r.y:= 0;
@@ -559,60 +577,61 @@
 procedure DrawRepeated(spr, sprL, sprR: TSprite; Shift, OffsetY: LongInt);
 var i, w, h, lw, lh, rw, rh, sw: LongInt;
 begin
-    sw:= round(cScreenWidth / cScaleFactor);
-    if (SpritesData[sprL].Texture = nil) and (SpritesData[spr].Texture <> nil) then
-        begin
-        w:= SpritesData[spr].Width * SpritesData[spr].Texture^.Scale;
-        h:= SpritesData[spr].Height * SpritesData[spr].Texture^.Scale;
-        i:= Shift mod w;
-        if i > 0 then dec(i, w);
-        dec(i, w * (sw div w + 1));
-        repeat
-            DrawTexture(i, WorldDy + LAND_HEIGHT + OffsetY - h, SpritesData[spr].Texture, SpritesData[spr].Texture^.Scale);
-            inc(i, w)
-        until i > sw
-        end
-    else if SpritesData[spr].Texture <> nil then
+sw:= round(cScreenWidth / cScaleFactor);
+if (SpritesData[sprL].Texture = nil) and (SpritesData[spr].Texture <> nil) then
+    begin
+    w:= SpritesData[spr].Width * SpritesData[spr].Texture^.Scale;
+    h:= SpritesData[spr].Height * SpritesData[spr].Texture^.Scale;
+    i:= Shift mod w;
+    if i > 0 then
+        dec(i, w);
+    dec(i, w * (sw div w + 1));
+    repeat
+    DrawTexture(i, WorldDy + LAND_HEIGHT + OffsetY - h, SpritesData[spr].Texture, SpritesData[spr].Texture^.Scale);
+    inc(i, w)
+    until i > sw
+    end
+else if SpritesData[spr].Texture <> nil then
+    begin
+    w:= SpritesData[spr].Width * SpritesData[spr].Texture^.Scale;
+    h:= SpritesData[spr].Height * SpritesData[spr].Texture^.Scale;
+    lw:= SpritesData[sprL].Width * SpritesData[spr].Texture^.Scale;
+    lh:= SpritesData[sprL].Height * SpritesData[spr].Texture^.Scale;
+    if SpritesData[sprR].Texture <> nil then
         begin
-        w:= SpritesData[spr].Width * SpritesData[spr].Texture^.Scale;
-        h:= SpritesData[spr].Height * SpritesData[spr].Texture^.Scale;
-        lw:= SpritesData[sprL].Width * SpritesData[spr].Texture^.Scale;
-        lh:= SpritesData[sprL].Height * SpritesData[spr].Texture^.Scale;
-        if SpritesData[sprR].Texture <> nil then
+        rw:= SpritesData[sprR].Width * SpritesData[spr].Texture^.Scale;
+        rh:= SpritesData[sprR].Height * SpritesData[spr].Texture^.Scale
+        end;
+    dec(Shift, w div 2);
+    DrawTexture(Shift, WorldDy + LAND_HEIGHT + OffsetY - h, SpritesData[spr].Texture, SpritesData[spr].Texture^.Scale);
+
+    i:= Shift - lw;
+    while i >= -sw - lw do
+        begin
+        DrawTexture(i, WorldDy + LAND_HEIGHT + OffsetY - lh, SpritesData[sprL].Texture, SpritesData[sprL].Texture^.Scale);
+        dec(i, lw);
+        end;
+
+    i:= Shift + w;
+    if SpritesData[sprR].Texture <> nil then
+        while i <= sw do
             begin
-            rw:= SpritesData[sprR].Width * SpritesData[spr].Texture^.Scale;
-            rh:= SpritesData[sprR].Height * SpritesData[spr].Texture^.Scale
-            end;
-        dec(Shift, w div 2);
-        DrawTexture(Shift, WorldDy + LAND_HEIGHT + OffsetY - h, SpritesData[spr].Texture, SpritesData[spr].Texture^.Scale);
-
-        i:= Shift - lw;
-        while i >= -sw - lw do
+            DrawTexture(i, WorldDy + LAND_HEIGHT + OffsetY - rh, SpritesData[sprR].Texture, SpritesData[sprR].Texture^.Scale);
+            inc(i, rw)
+            end
+    else
+        while i <= sw do
             begin
             DrawTexture(i, WorldDy + LAND_HEIGHT + OffsetY - lh, SpritesData[sprL].Texture, SpritesData[sprL].Texture^.Scale);
-            dec(i, lw);
-            end;
-
-        i:= Shift + w;
-        if SpritesData[sprR].Texture <> nil then
-            while i <= sw do
-                begin
-                DrawTexture(i, WorldDy + LAND_HEIGHT + OffsetY - rh, SpritesData[sprR].Texture, SpritesData[sprR].Texture^.Scale);
-                inc(i, rw)
-                end
-        else
-            while i <= sw do
-                begin
-                DrawTexture(i, WorldDy + LAND_HEIGHT + OffsetY - lh, SpritesData[sprL].Texture, SpritesData[sprL].Texture^.Scale);
-                inc(i, lw)
-                end
-        end
+            inc(i, lw)
+            end
+    end
 end;
 
 
 procedure DrawWorld(Lag: LongInt);
 begin
-    if not isPaused then
+if not isPaused then
     begin
         if ZoomValue < zoom then
         begin
@@ -621,8 +640,8 @@
                 zoom:= ZoomValue
         end
         else
-        if ZoomValue > zoom then
-        begin
+            if ZoomValue > zoom then
+            begin
             zoom:= zoom + 0.002 * Lag;
             if ZoomValue < zoom then
                 zoom:= ZoomValue
@@ -762,8 +781,10 @@
     exit;
 {$ELSE}
     d:= d / 5;
-    if rm = rmDefault then exit
-    else if rm = rmLeftEye then d:= -d;
+    if rm = rmDefault then
+        exit
+    else if rm = rmLeftEye then
+        d:= -d;
     stereoDepth:= stereoDepth + d;
     glMatrixMode(GL_PROJECTION);
     glTranslatef(d, 0, 0);
@@ -777,7 +798,8 @@
     rm:= rm; // avoid hint
     exit;
 {$ELSE}
-    if rm = rmDefault then exit;
+    if rm = rmDefault then
+        exit;
     glMatrixMode(GL_PROJECTION);
     glTranslatef(-stereoDepth, 0, 0);
     glMatrixMode(GL_MODELVIEW);
@@ -794,7 +816,7 @@
     smallScreenOffset, offsetX, offsetY, screenBottom: LongInt;
     VertexBuffer: array [0..3] of TVertex2f;
 begin
-    if (cReducedQuality and rqNoBackground) = 0 then
+if (cReducedQuality and rqNoBackground) = 0 then
     begin
         // Offsets relative to camera - spare them to wimpier cpus, no bg or flakes for them anyway
         ScreenBottom:= (WorldDy - trunc(cScreenHeight/cScaleFactor) - (cScreenHeight div 2) + cWaterLine);
@@ -806,18 +828,20 @@
 
         // background
         ChangeDepth(RM, cStereo_Sky);
-        if SuddenDeathDmg then Tint(SDTint, SDTint, SDTint, $FF);
+        if SuddenDeathDmg then
+            Tint(SDTint, SDTint, SDTint, $FF);
         DrawRepeated(sprSky, sprSkyL, sprSkyR, (WorldDx + LAND_WIDTH div 2) * 3 div 8, SkyOffset);
         ChangeDepth(RM, -cStereo_Horizon);
         DrawRepeated(sprHorizont, sprHorizontL, sprHorizontR, (WorldDx + LAND_WIDTH div 2) * 3 div 5, HorizontOffset);
-        if SuddenDeathDmg then Tint($FF, $FF, $FF, $FF);
+        if SuddenDeathDmg then
+            Tint($FF, $FF, $FF, $FF);
     end;
 
-    DrawVisualGears(0);
-    ChangeDepth(RM, -cStereo_MidDistance);
-    DrawVisualGears(4);
+DrawVisualGears(0);
+ChangeDepth(RM, -cStereo_MidDistance);
+DrawVisualGears(4);
 
-    if (cReducedQuality and rq2DWater) = 0 then
+if (cReducedQuality and rq2DWater) = 0 then
     begin
         // Waves
         DrawWater(255, SkyOffset); 
@@ -830,7 +854,7 @@
         ChangeDepth(RM, -cStereo_Water_distant);
         DrawWaves(-1, 100 + WorldDx div 14, - cWaveHeight + offsetY div 70, 24);
     end
-    else
+else
         DrawWaves(-1, 100, - (cWaveHeight + (cWaveHeight shr 1)), 0);
 
     changeDepth(RM, cStereo_Land);
@@ -861,37 +885,37 @@
                 end
         end;
 
-    DrawVisualGears(1);
-    DrawGears;
-    DrawVisualGears(6);
+DrawVisualGears(1);
+DrawGears;
+DrawVisualGears(6);
 
-    if SuddenDeathDmg then
-        DrawWater(cSDWaterOpacity, 0)
-    else
-        DrawWater(cWaterOpacity, 0);
+if SuddenDeathDmg then
+    DrawWater(cSDWaterOpacity, 0)
+else
+    DrawWater(cWaterOpacity, 0);
 
     // Waves
-    ChangeDepth(RM, cStereo_Water_near);
-    DrawWaves( 1, 25 - WorldDx div 9, - cWaveHeight, 12);
+ChangeDepth(RM, cStereo_Water_near);
+DrawWaves( 1, 25 - WorldDx div 9, - cWaveHeight, 12);
 
-    if (cReducedQuality and rq2DWater) = 0 then
+if (cReducedQuality and rq2DWater) = 0 then
     begin
-        //DrawWater(cWaterOpacity, - offsetY div 40);
-        ChangeDepth(RM, cStereo_Water_near);
-        DrawWaves(-1, 50 + WorldDx div 6, - cWaveHeight - offsetY div 40, 8);
-        if SuddenDeathDmg then
-            DrawWater(cSDWaterOpacity, - offsetY div 20)
-        else
-            DrawWater(cWaterOpacity, - offsetY div 20);
-        ChangeDepth(RM, cStereo_Water_near);
-        DrawWaves( 1, 75 - WorldDx div 4, - cWaveHeight - offsetY div 20, 2);
+    //DrawWater(cWaterOpacity, - offsetY div 40);
+    ChangeDepth(RM, cStereo_Water_near);
+    DrawWaves(-1, 50 + WorldDx div 6, - cWaveHeight - offsetY div 40, 8);
+    if SuddenDeathDmg then
+        DrawWater(cSDWaterOpacity, - offsetY div 20)
+    else
+        DrawWater(cWaterOpacity, - offsetY div 20);
+    ChangeDepth(RM, cStereo_Water_near);
+    DrawWaves( 1, 75 - WorldDx div 4, - cWaveHeight - offsetY div 20, 2);
         if SuddenDeathDmg then
             DrawWater(cSDWaterOpacity, - offsetY div 10)
         else
             DrawWater(cWaterOpacity, - offsetY div 10);
         ChangeDepth(RM, cStereo_Water_near);
         DrawWaves( -1, 25 + WorldDx div 3, - cWaveHeight - offsetY div 10, 0);
-    end
+        end
     else
         DrawWaves(-1, 50, - (cWaveHeight shr 1), 0);
 
@@ -936,18 +960,21 @@
     else
         i:= Succ(Pred(TurnTimeLeft) div 1000);
    
-   if i>99 then t:= 112
-      else if i>9 then t:= 96
-                  else t:= 80;
-   DrawSprite(sprFrame, -(cScreenWidth shr 1) + t + offsetY, cScreenHeight - offsetX, 1);
-   while i > 0 do
-         begin
-         dec(t, 32);
-         DrawSprite(sprBigDigit, -(cScreenWidth shr 1) + t + offsetY, cScreenHeight - offsetX, i mod 10);
-         i:= i div 10
-         end;
-   DrawSprite(sprFrame, -(cScreenWidth shr 1) + t - 4 + offsetY, cScreenHeight - offsetX, 0);
-   end;
+    if i>99 then
+        t:= 112
+    else if i>9 then
+        t:= 96
+    else
+        t:= 80;
+    DrawSprite(sprFrame, -(cScreenWidth shr 1) + t + offsetY, cScreenHeight - offsetX, 1);
+    while i > 0 do
+        begin
+        dec(t, 32);
+        DrawSprite(sprBigDigit, -(cScreenWidth shr 1) + t + offsetY, cScreenHeight - offsetX, i mod 10);
+        i:= i div 10
+        end;
+    DrawSprite(sprFrame, -(cScreenWidth shr 1) + t - 4 + offsetY, cScreenHeight - offsetX, 0);
+    end;
 
 // Captions
 DrawCaptions;
@@ -961,72 +988,76 @@
     begin
     SetScale(1.5);
     smallScreenOffset:= cScreenHeight div 6;
-    if TeamsCount * 20 > Longword(cScreenHeight) div 5 then Tint($FF,$FF,$FF,$80);
+    if TeamsCount * 20 > Longword(cScreenHeight) div 5 then
+        Tint($FF,$FF,$FF,$80);
     end
 else smallScreenOffset:= 0;
 for t:= 0 to Pred(TeamsCount) do
-   with TeamsArray[t]^ do
-      begin
-      highlight:= bShowFinger and (CurrentTeam = TeamsArray[t]) and ((RealTicks mod 1000) < 500);
-
-      if highlight then
-         Tint(Clan^.Color shl 8 or $FF);
-
-      // draw name
-      DrawTexture(-NameTagTex^.w - 16, cScreenHeight + DrawHealthY + smallScreenOffset, NameTagTex);
-
-      // draw flag
-      DrawTexture(-14, cScreenHeight + DrawHealthY + smallScreenOffset, FlagTex);
+    with TeamsArray[t]^ do
+        begin
+        highlight:= bShowFinger and (CurrentTeam = TeamsArray[t]) and ((RealTicks mod 1000) < 500);
 
-      // draw health bar
-      r.x:= 0;
-      r.y:= 0;
-      r.w:= 2 + TeamHealthBarWidth;
-      r.h:= HealthTex^.h;
-      DrawFromRect(14, cScreenHeight + DrawHealthY + smallScreenOffset, @r, HealthTex);
-
-      // draw health bars right border
-      inc(r.x, cTeamHealthWidth + 2);
-      r.w:= 3;
-      DrawFromRect(TeamHealthBarWidth + 16, cScreenHeight + DrawHealthY + smallScreenOffset, @r, HealthTex);
-
-      // draw ai kill counter for gfAISurvival
-      if (GameFlags and gfAISurvival) <> 0 then begin
-          DrawTexture(TeamHealthBarWidth + 22, cScreenHeight + DrawHealthY + smallScreenOffset,
-              AIKillsTex);
-      end;
-
-      // if highlighted, draw flag and other contents again to keep their colors
-      // this approach should be faster than drawing all borders one by one tinted or not
-      if highlight then
-         begin
-         if TeamsCount * 20 > Longword(cScreenHeight) div 5 then Tint($FF,$FF,$FF,$80)
-         else Tint($FF, $FF, $FF, $FF);
+        if highlight then
+            Tint(Clan^.Color shl 8 or $FF);
 
          // draw name
-         r.x:= 2;
-         r.y:= 2;
-         r.w:= NameTagTex^.w - 4;
-         r.h:= NameTagTex^.h - 4;
-         DrawFromRect(-NameTagTex^.w - 14, cScreenHeight + DrawHealthY + smallScreenOffset + 2, @r, NameTagTex);
-         // draw flag
-         r.w:= 22;
-         r.h:= 15;
-         DrawFromRect(-12, cScreenHeight + DrawHealthY + smallScreenOffset + 2, @r, FlagTex);
-         // draw health bar
-         r.w:= TeamHealthBarWidth + 1;
-         r.h:= HealthTex^.h - 4;
-         DrawFromRect(16, cScreenHeight + DrawHealthY + smallScreenOffset + 2, @r, HealthTex);
-         end;
-      end;
+        DrawTexture(-NameTagTex^.w - 16, cScreenHeight + DrawHealthY + smallScreenOffset, NameTagTex);
+
+        // draw flag
+        DrawTexture(-14, cScreenHeight + DrawHealthY + smallScreenOffset, FlagTex);
+
+        // draw health bar
+        r.x:= 0;
+        r.y:= 0;
+        r.w:= 2 + TeamHealthBarWidth;
+        r.h:= HealthTex^.h;
+        DrawFromRect(14, cScreenHeight + DrawHealthY + smallScreenOffset, @r, HealthTex);
+
+        // draw health bars right border
+        inc(r.x, cTeamHealthWidth + 2);
+        r.w:= 3;
+        DrawFromRect(TeamHealthBarWidth + 16, cScreenHeight + DrawHealthY + smallScreenOffset, @r, HealthTex);
+
+        // draw ai kill counter for gfAISurvival
+        if (GameFlags and gfAISurvival) <> 0 then
+            begin
+            DrawTexture(TeamHealthBarWidth + 22, cScreenHeight + DrawHealthY + smallScreenOffset, AIKillsTex);
+            end;
+
+        // if highlighted, draw flag and other contents again to keep their colors
+        // this approach should be faster than drawing all borders one by one tinted or not
+        if highlight then
+            begin
+            if TeamsCount * 20 > Longword(cScreenHeight) div 5 then
+                Tint($FF,$FF,$FF,$80)
+            else Tint($FF, $FF, $FF, $FF);
+
+            // draw name
+            r.x:= 2;
+            r.y:= 2;
+            r.w:= NameTagTex^.w - 4;
+            r.h:= NameTagTex^.h - 4;
+            DrawFromRect(-NameTagTex^.w - 14, cScreenHeight + DrawHealthY + smallScreenOffset + 2, @r, NameTagTex);
+            // draw flag
+            r.w:= 22;
+            r.h:= 15;
+            DrawFromRect(-12, cScreenHeight + DrawHealthY + smallScreenOffset + 2, @r, FlagTex);
+            // draw health bar
+            r.w:= TeamHealthBarWidth + 1;
+            r.h:= HealthTex^.h - 4;
+            DrawFromRect(16, cScreenHeight + DrawHealthY + smallScreenOffset + 2, @r, HealthTex);
+            end;
+        end;
 if smallScreenOffset <> 0 then
     begin
     SetScale(cDefaultZoomLevel);
-    if TeamsCount * 20 > Longword(cScreenHeight) div 5 then Tint($FF,$FF,$FF,$FF);
+    if TeamsCount * 20 > Longword(cScreenHeight) div 5 then
+        Tint($FF,$FF,$FF,$FF);
     end;
 
 // Lag alert
-if isInLag then DrawSprite(sprLag, 32 - (cScreenWidth shr 1), 32, (RealTicks shr 7) mod 12);
+if isInLag then
+    DrawSprite(sprLag, 32 - (cScreenWidth shr 1), 32, (RealTicks shr 7) mod 12);
 
 // Wind bar
 {$IFDEF MOBILE}
@@ -1038,7 +1069,7 @@
 {$ENDIF}
     DrawSprite(sprWindBar, (cScreenWidth shr 1) - offsetY, cScreenHeight - offsetX, 0);
     if WindBarWidth > 0 then
-    begin
+        begin
         {$WARNINGS OFF}
         r.x:= 8 - (RealTicks shr 6) mod 8;
         {$WARNINGS ON}
@@ -1046,7 +1077,7 @@
         r.w:= WindBarWidth;
         r.h:= 13;
         DrawSpriteFromRect(sprWindR, r, (cScreenWidth shr 1) - offsetY + 77, cScreenHeight - offsetX + 2, 13, 0);
-    end
+        end
     else
         if WindBarWidth < 0 then
         begin
@@ -1060,22 +1091,27 @@
         end;
 
 // AmmoMenu
-if (AMxShift < AMWidth) or bShowAmmoMenu then ShowAmmoMenu;
+if (AMxShift < AMWidth) or bShowAmmoMenu then
+    ShowAmmoMenu;
 
 // Cursor
 if isCursorVisible and bShowAmmoMenu then
-   DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8);
+    DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8);
 
 // Chat
 DrawChat;
 
 // various captions
-if fastUntilLag then DrawCentered(0, (cScreenHeight shr 1), SyncTexture);
-if isPaused then DrawCentered(0, (cScreenHeight shr 1), PauseTexture);
+if fastUntilLag then
+    DrawCentered(0, (cScreenHeight shr 1), SyncTexture);
+if isPaused then
+    DrawCentered(0, (cScreenHeight shr 1), PauseTexture);
 if not isFirstFrame and (missionTimer <> 0) or isPaused or fastUntilLag or (GameState = gsConfirm) then
     begin
-    if (ReadyTimeLeft = 0) and (missionTimer > 0) then dec(missionTimer, Lag);
-    if missionTimer < 0 then missionTimer:= 0; // avoid subtracting below 0
+    if (ReadyTimeLeft = 0) and (missionTimer > 0) then
+        dec(missionTimer, Lag);
+    if missionTimer < 0 then
+        missionTimer:= 0; // avoid subtracting below 0
     if missionTex <> nil then
         DrawCentered(0, Min((cScreenHeight shr 1) + 100, cScreenHeight - 48 - missionTex^.h), missionTex);
     end;
@@ -1088,21 +1124,23 @@
 {$ENDIF}
 offsetY:= cOffsetY;
 if (RM = rmDefault) or (RM = rmRightEye) then
-begin
+    begin
     inc(Frames);
 
     if cShowFPS or (GameType = gmtDemo) then
         inc(CountTicks, Lag);
     if (GameType = gmtDemo) and (CountTicks >= 1000) then
-    begin
+        begin
         i:=GameTicks div 1000;
         t:= i mod 60;
         s:= inttostr(t);
-        if t < 10 then s:= '0' + s;
+        if t < 10 then
+            s:= '0' + s;
         i:= i div 60;
         t:= i mod 60;
         s:= inttostr(t) + ':' + s;
-        if t < 10 then s:= '0' + s;
+        if t < 10 then
+            s:= '0' + s;
         s:= inttostr(i div 60) + ':' + s;
    
     
@@ -1111,15 +1149,15 @@
         FreeTexture(timeTexture);
         timeTexture:= Surface2Tex(tmpSurface, false);
         SDL_FreeSurface(tmpSurface)
-    end;
+        end;
 
     if timeTexture <> nil then
         DrawTexture((cScreenWidth shr 1) - 20 - timeTexture^.w - offsetY, offsetX + timeTexture^.h+5, timeTexture);
 
     if cShowFPS then
-    begin
+        begin
         if CountTicks >= 1000 then
-        begin
+            begin
             FPS:= Frames;
             Frames:= 0;
             CountTicks:= 0;
@@ -1129,12 +1167,13 @@
             FreeTexture(fpsTexture);
             fpsTexture:= Surface2Tex(tmpSurface, false);
             SDL_FreeSurface(tmpSurface)
-        end;
+            end;
         if fpsTexture <> nil then
             DrawTexture((cScreenWidth shr 1) - 60 - offsetY, offsetX, fpsTexture);
-    end;
+        end;
 
-    if CountTicks >= 1000 then CountTicks:= 0;
+    if CountTicks >= 1000 then
+        CountTicks:= 0;
 
     // lag warning (?)
     inc(SoundTimerTicks, Lag);
@@ -1189,7 +1228,8 @@
 
         glEnable(GL_TEXTURE_2D);
         Tint($FF, $FF, $FF, $FF);
-        if not isFirstFrame and ((ScreenFadeValue = 0) or (ScreenFadeValue = sfMax)) then ScreenFade:= sfNone
+        if not isFirstFrame and ((ScreenFadeValue = 0) or (ScreenFadeValue = sfMax)) then
+            ScreenFade:= sfNone
         end
     end;
 
@@ -1197,22 +1237,22 @@
 
 // Cursor
 if isCursorVisible then
-   begin
-   if not bShowAmmoMenu then
-     begin
-     with CurrentHedgehog^ do
-       if (Gear <> nil) and ((Gear^.State and gstHHChooseTarget) <> 0) then
-         begin
-         if (CurAmmoType = amNapalm) or (CurAmmoType = amMineStrike) then
-           DrawLine(-3000, topY-300, 7000, topY-300, 3.0, (Team^.Clan^.Color shr 16), (Team^.Clan^.Color shr 8) and $FF, Team^.Clan^.Color and $FF, $FF);
-         i:= GetAmmoEntry(CurrentHedgehog^)^.Pos;
-         with Ammoz[CurAmmoType] do
-           if PosCount > 1 then
-             DrawSprite(PosSprite, CursorPoint.X - (SpritesData[PosSprite].Width shr 1), cScreenHeight - CursorPoint.Y - (SpritesData[PosSprite].Height shr 1),i);
-         end;
-     DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8)
-     end
-   end;
+    begin
+    if not bShowAmmoMenu then
+        begin
+        with CurrentHedgehog^ do
+            if (Gear <> nil) and ((Gear^.State and gstHHChooseTarget) <> 0) then
+                begin
+            if (CurAmmoType = amNapalm) or (CurAmmoType = amMineStrike) then
+                DrawLine(-3000, topY-300, 7000, topY-300, 3.0, (Team^.Clan^.Color shr 16), (Team^.Clan^.Color shr 8) and $FF, Team^.Clan^.Color and $FF, $FF);
+            i:= GetAmmoEntry(CurrentHedgehog^)^.Pos;
+            with Ammoz[CurAmmoType] do
+                if PosCount > 1 then
+                    DrawSprite(PosSprite, CursorPoint.X - (SpritesData[PosSprite].Width shr 1), cScreenHeight - CursorPoint.Y - (SpritesData[PosSprite].Height shr 1),i);
+                end;
+        DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8)
+        end
+    end;
 isFirstFrame:= false
 end;
 
@@ -1242,22 +1282,32 @@
         end;
 
 wdy:= trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 - cWaterLine - cVisibleWater;
-if WorldDy < wdy then WorldDy:= wdy;
+if WorldDy < wdy then
+    WorldDy:= wdy;
 
-if ((CursorPoint.X = prevPoint.X) and (CursorPoint.Y = prevpoint.Y)) then exit;
+if ((CursorPoint.X = prevPoint.X) and (CursorPoint.Y = prevpoint.Y)) then
+    exit;
 
 if AMxShift < AMWidth then
 begin
 {$IFDEF MOBILE}
-    if CursorPoint.X < cScreenWidth div 2 + AMxShift - AMWidth then CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMWidth;
-    if CursorPoint.X > cScreenWidth div 2 + AMxShift - AMxOffset then CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMxOffset;
-    if CursorPoint.Y < cScreenHeight - AMyOffset - SlotsNum * AMSlotSize then CursorPoint.Y:= cScreenHeight - AMyOffset - SlotsNum * AMSlotSize;
-    if CursorPoint.Y > cScreenHeight - AMyOffset then CursorPoint.Y:= cScreenHeight - AMyOffset;
+    if CursorPoint.X < cScreenWidth div 2 + AMxShift - AMWidth then
+        CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMWidth;
+    if CursorPoint.X > cScreenWidth div 2 + AMxShift - AMxOffset then
+        CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMxOffset;
+    if CursorPoint.Y < cScreenHeight - AMyOffset - SlotsNum * AMSlotSize then
+        CursorPoint.Y:= cScreenHeight - AMyOffset - SlotsNum * AMSlotSize;
+    if CursorPoint.Y > cScreenHeight - AMyOffset then
+        CursorPoint.Y:= cScreenHeight - AMyOffset;
 {$ELSE}
-    if CursorPoint.X < cScreenWidth div 2 + AMxShift - AMWidth + AMSlotSize then CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMWidth + AMSlotSize;
-    if CursorPoint.X > cScreenWidth div 2 + AMxShift - AMxOffset then CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMxOffset;
-    if CursorPoint.Y > AMyOffset + (SlotsNum + 1) * AMSlotSize then CursorPoint.Y:= AMyOffset + (SlotsNum + 1) * AMSlotSize;
-    if CursorPoint.Y < AMyOffset + AMSlotSize then CursorPoint.Y:= AMyOffset + AMSlotSize;
+    if CursorPoint.X < cScreenWidth div 2 + AMxShift - AMWidth + AMSlotSize then
+        CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMWidth + AMSlotSize;
+    if CursorPoint.X > cScreenWidth div 2 + AMxShift - AMxOffset then
+        CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMxOffset;
+    if CursorPoint.Y > AMyOffset + (SlotsNum + 1) * AMSlotSize then
+        CursorPoint.Y:= AMyOffset + (SlotsNum + 1) * AMSlotSize;
+    if CursorPoint.Y < AMyOffset + AMSlotSize then
+        CursorPoint.Y:= AMyOffset + AMSlotSize;
 {$ENDIF}
     prevPoint:= CursorPoint;
     //if cHasFocus then SDL_WarpMouse(CursorPoint.X + cScreenWidth div 2, cScreenHeight - CursorPoint.Y);
@@ -1265,61 +1315,65 @@
 end;
 
 if isCursorVisible then
-begin
+    begin
     if (not CurrentTeam^.ExtDriven) and (GameTicks >= PrevSentPointTime + cSendCursorPosTime) then
-    begin
+        begin
         SendIPCXY('P', CursorPoint.X - WorldDx, cScreenHeight - CursorPoint.Y - WorldDy);
         PrevSentPointTime:= GameTicks
-    end;
+        end;
     EdgesDist:= cCursorEdgesDist
-end
+    end
 else
     EdgesDist:= cGearScrEdgesDist;
 
 // this generates the border around the screen that moves the camera when cursor is near it
 if isCursorVisible or (FollowGear <> nil) then
-begin
+    begin
     if CursorPoint.X < - cScreenWidth div 2 + EdgesDist then
-    begin
+        begin
         WorldDx:= WorldDx - CursorPoint.X - cScreenWidth div 2 + EdgesDist;
         CursorPoint.X:= - cScreenWidth div 2 + EdgesDist
-    end
+        end
     else
         if CursorPoint.X > cScreenWidth div 2 - EdgesDist then
-        begin
+            begin
             WorldDx:= WorldDx - CursorPoint.X + cScreenWidth div 2 - EdgesDist;
             CursorPoint.X:= cScreenWidth div 2 - EdgesDist
-        end;
+            end;
 
     shs:= min(cScreenHeight div 2 - trunc(cScreenHeight / cScaleFactor) + EdgesDist, cScreenHeight - EdgesDist);
     if CursorPoint.Y < shs then
-    begin
+        begin
         WorldDy:= WorldDy + CursorPoint.Y - shs;
         CursorPoint.Y:= shs;
-    end
+        end
     else
         if (CursorPoint.Y > cScreenHeight - EdgesDist) then
-        begin
+            begin
            WorldDy:= WorldDy + CursorPoint.Y - cScreenHeight + EdgesDist;
            CursorPoint.Y:= cScreenHeight - EdgesDist
-        end;
-end
+            end;
+    end
 else
     if cHasFocus then
-    begin
+        begin
         WorldDx:= WorldDx - CursorPoint.X + prevPoint.X;
         WorldDy:= WorldDy + CursorPoint.Y - prevPoint.Y;
         CursorPoint.X:= 0;
         CursorPoint.Y:= cScreenHeight div 2;
-    end;
+        end;
 
 // this moves the camera according to CursorPoint X and Y
 prevPoint:= CursorPoint;
 //if cHasFocus then SDL_WarpMouse(CursorPoint.X + (cScreenWidth shr 1), cScreenHeight - CursorPoint.Y);
-if WorldDy > LAND_HEIGHT + 1024 then WorldDy:= LAND_HEIGHT + 1024;
-if WorldDy < wdy then WorldDy:= wdy;
-if WorldDx < - LAND_WIDTH - 1024 then WorldDx:= - LAND_WIDTH - 1024;
-if WorldDx > 1024 then WorldDx:= 1024;
+if WorldDy > LAND_HEIGHT + 1024 then
+    WorldDy:= LAND_HEIGHT + 1024;
+if WorldDy < wdy then
+    WorldDy:= wdy;
+if WorldDx < - LAND_WIDTH - 1024 then
+    WorldDx:= - LAND_WIDTH - 1024;
+if WorldDx > 1024 then
+    WorldDx:= 1024;
 end;
 
 procedure ShowMission(caption, subcaption, text: ansistring; icon, time : LongInt);
@@ -1328,7 +1382,8 @@
 r.w:= 32;
 r.h:= 32;
 
-if time = 0 then time:= 5000;
+if time = 0 then
+    time:= 5000;
 missionTimer:= time;
 FreeTexture(missionTex);
 
@@ -1353,12 +1408,13 @@
 
 procedure ShakeCamera(amount: LongInt);
 begin
-    if isCursorVisible then exit;
-    amount:= Max(1, round(amount*zoom/2));
-    WorldDx:= WorldDx - amount + LongInt(random(1 + amount * 2));
-    WorldDy:= WorldDy - amount + LongInt(random(1 + amount * 2));
-    //CursorPoint.X:= CursorPoint.X - amount + LongInt(random(1 + amount * 2));
-    //CursorPoint.Y:= CursorPoint.Y - amount + LongInt(random(1 + amount * 2))
+if isCursorVisible then
+    exit;
+amount:= Max(1, round(amount*zoom/2));
+WorldDx:= WorldDx - amount + LongInt(random(1 + amount * 2));
+WorldDy:= WorldDy - amount + LongInt(random(1 + amount * 2));
+//CursorPoint.X:= CursorPoint.X - amount + LongInt(random(1 + amount * 2));
+//CursorPoint.Y:= CursorPoint.Y - amount + LongInt(random(1 + amount * 2))
 end;
 
 
@@ -1371,36 +1427,36 @@
 
 procedure initModule;
 begin
-    fpsTexture:= nil;
-    FollowGear:= nil;
-    WindBarWidth:= 0;
-    bShowAmmoMenu:= false;
-    bSelected:= false;
-    bShowFinger:= false;
-    Frames:= 0;
-    WorldDx:= -512;
-    WorldDy:= -256;
+fpsTexture:= nil;
+FollowGear:= nil;
+WindBarWidth:= 0;
+bShowAmmoMenu:= false;
+bSelected:= false;
+bShowFinger:= false;
+Frames:= 0;
+WorldDx:= -512;
+WorldDy:= -256;
 
-    FPS:= 0;
-    CountTicks:= 0;
-    SoundTimerTicks:= 0;
-    prevPoint.X:= 0;
-    prevPoint.Y:= 0;
-    missionTimer:= 0;
-    missionTex:= nil;
-    cOffsetY:= 0;
-    stereoDepth:= 0;
+FPS:= 0;
+CountTicks:= 0;
+SoundTimerTicks:= 0;
+prevPoint.X:= 0;
+prevPoint.Y:= 0;
+missionTimer:= 0;
+missionTex:= nil;
+cOffsetY:= 0;
+stereoDepth:= 0;
 end;
 
 procedure freeModule;
 begin
-    stereoDepth:= stereoDepth; // avoid hint
-    FreeTexture(fpsTexture);
-    fpsTexture:= nil;
-    FreeTexture(timeTexture);
-    timeTexture:= nil;
-    FreeTexture(missionTex);
-    missionTex:= nil
+stereoDepth:= stereoDepth; // avoid hint
+FreeTexture(fpsTexture);
+fpsTexture:= nil;
+FreeTexture(timeTexture);
+timeTexture:= nil;
+FreeTexture(missionTex);
+missionTex:= nil
 end;
 
 end.