{
  IF ( INT_GAME_TURN == 0 )
  {
    SET $0                                     0
    DO SET_ATTACK_VARIABLE                     $0
    DO STATE_STATE_BRING_NEW_PEOPLE_BACK       ON
    DO STATE_SHAMAN_GET_WILDS                  ON
    DO STATE_CONSTRUCT_BUILDING                ON
    DO STATE_POPULATE_DRUM_TOWER               ON
    DO STATE_HOUSE_A_PERSON                    ON
    DO STATE_FETCH_FAR_VEHICLE                 ON
    DO STATE_BUILD_VEHICLE                     ON
    DO STATE_FETCH_LOST_PEOPLE                 ON
    SET INT_ATTR_PEOPLE_PER_BOAT               7
    SET INT_ATTR_PREF_BOAT_DRIVERS             8
    SET INT_ATTR_SPY_CHECK_FREQUENCY           128
    SET INT_ATTR_SPY_DISCOVER_CHANCE           35
    SET INT_ATTR_ENEMY_SPY_MAX_STAND           128
    SET INT_ATTR_SHAMEN_BLAST                  64
    SET INT_ATTR_RETREAT_VALUE                 35
    SET INT_ATTR_BASE_UNDER_ATTACK_RETREAT     0
    SET INT_ATTR_RANDOM_BUILD_SIDE             0
    SET INT_ATTR_MAX_TRAIN_AT_ONCE             5
    SET INT_ATTR_GROUP_OPTION                  0
    SET INT_ATTR_PREF_SPY_TRAINS               1
    SET INT_ATTR_PREF_WARRIOR_TRAINS           1
    SET INT_ATTR_PREF_FIREWARRIOR_TRAINS       1
    SET INT_ATTR_PREF_RELIGIOUS_TRAINS         1
    SET INT_ATTR_PREF_BOAT_HUTS                0
    SET INT_ATTR_PREF_BALLOON_HUTS             0
    SET INT_ATTR_MAX_BUILDINGS_ON_GO           5
    SET INT_ATTR_HOUSE_PERCENTAGE              100
    SET INT_ATTR_EXPANSION                     12
    SET INT_ATTR_DEFENSE_RAD_INCR              4
    SET INT_ATTR_MAX_DEFENSIVE_ACTIONS         3
    SET INT_ATTR_ATTACK_PERCENTAGE             100
    SET INT_ATTR_USE_PREACHER_FOR_DEFENCE      1
    DO STATE_PREACH                            ON
    DO STATE_FIREWARRIOR_DEFEND                ON
    DO STATE_TRAIN_PEOPLE                      ON
    SET INT_ATTR_PREF_WARRIOR_PEOPLE           20
    SET INT_ATTR_PREF_FIREWARRIOR_PEOPLE       40
    SET INT_ATTR_PREF_RELIGIOUS_PEOPLE         15
    SET INT_ATTR_PREF_SPY_PEOPLE               5
    DO STATE_DEFEND                            ON
    DO STATE_DEFEND_BASE                       ON
    DO SET_DEFENCE_RADIUS                      7
    DO STATE_AUTO_ATTACK                       ON
    SET INT_ATTR_MAX_ATTACKS                   2
    SET INT_ATTR_AWAY_BRAVE                    0
    SET INT_ATTR_AWAY_WARRIOR                  40
    SET INT_ATTR_AWAY_RELIGIOUS                10
    SET INT_ATTR_AWAY_SPY                      5
    SET INT_ATTR_AWAY_FIREWARRIOR              45
    SET INT_ATTR_AWAY_SHAMAN                   1
    DO GIVE_ONE_SHOT INT_ANGEL_OF_DEATH RED
    DO STATE_SPELL_DEFENCE                     206 246 ON
    DO SET_SPELL_ENTRY 0 INT_LIGHTNING INT_M_SPELL_TORNADO_COST 64 6 0
    DO SET_SPELL_ENTRY 1 INT_SWARM INT_M_SPELL_LIGHTNING_COST 64 2 0
    DO SET_SPELL_ENTRY 2 INT_SWAMP INT_M_SPELL_LAND_BRIDGE_COST 64 5 0
    DO SET_SPELL_ENTRY 3 INT_HYPNOTISM INT_M_SPELL_INVISIBILITY_COST 64 4 0
    DO CREATE_MSG_NARRATIVE                    13
    DO SET_MSG_AUTO_OPEN_DLG
    SET $1                                     10
    SET $2                                     0
    SET $3                                     0
    SET $4                                     0
    SET $5                                     0
    SET $6                                     0
    SET $7                                     0
    SET $8                                     0
    SET $9                                     0
    SET $10                                    0
    SET $11                                    0
    SET $12                                    0
    SET $13                                    0
    SET $14                                    0
    SET $4                                     0
    SET $15                                    0
    SET $16                                    1
    SET $17                                    0
    SET $18                                    650
    SET $19                                    0
    SET $20                                    0
    SET $21                                    0
    SET $22                                    0
    SET $23                                    0
    SET $24                                    0
    SET $25                                    0
    SET $26                                    0
    SET $27                                    0
    SET $28                                    0
    SET $29                                    0
    SET $30                                    0
    SET $31                                    0
  }
  ELSE
  {
    EVERY 256 133
    {
      IF ( INT_MY_NUM_PEOPLE < 80 )
      {
        DO SET_BUCKET_USAGE                      ON
        DO SET_BUCKET_COUNT_FOR_SPELL INT_BLAST                 8
        DO SET_BUCKET_COUNT_FOR_SPELL INT_CONVERT               8
        DO SET_BUCKET_COUNT_FOR_SPELL INT_SWARM                 32
        DO SET_BUCKET_COUNT_FOR_SPELL INT_INVISIBILITY          40
        DO SET_BUCKET_COUNT_FOR_SPELL INT_SHIELD                48
        DO SET_BUCKET_COUNT_FOR_SPELL INT_LAND_BRIDGE           66
        DO SET_BUCKET_COUNT_FOR_SPELL INT_LIGHTNING             64
        DO SET_BUCKET_COUNT_FOR_SPELL INT_HYPNOTISM             70
        DO SET_BUCKET_COUNT_FOR_SPELL INT_TORNADO               72
        DO SET_BUCKET_COUNT_FOR_SPELL INT_SWAMP                 80
        DO SET_BUCKET_COUNT_FOR_SPELL INT_FLATTEN               100
        DO SET_BUCKET_COUNT_FOR_SPELL INT_EARTHQUAKE            140
        DO SET_BUCKET_COUNT_FOR_SPELL INT_EROSION               168
        DO SET_BUCKET_COUNT_FOR_SPELL INT_FIRESTORM             320
        DO SET_BUCKET_COUNT_FOR_SPELL INT_ANGEL_OF_DEATH        408
        DO SET_BUCKET_COUNT_FOR_SPELL INT_VOLCANO               640
      }
      ELSE
      {
        DO SET_BUCKET_USAGE                      ON
        DO SET_BUCKET_COUNT_FOR_SPELL INT_BLAST                 4
        DO SET_BUCKET_COUNT_FOR_SPELL INT_CONVERT               4
        DO SET_BUCKET_COUNT_FOR_SPELL INT_SWARM                 16
        DO SET_BUCKET_COUNT_FOR_SPELL INT_INVISIBILITY          20
        DO SET_BUCKET_COUNT_FOR_SPELL INT_SHIELD                24
        DO SET_BUCKET_COUNT_FOR_SPELL INT_LAND_BRIDGE           33
        DO SET_BUCKET_COUNT_FOR_SPELL INT_LIGHTNING             32
        DO SET_BUCKET_COUNT_FOR_SPELL INT_HYPNOTISM             35
        DO SET_BUCKET_COUNT_FOR_SPELL INT_TORNADO               36
        DO SET_BUCKET_COUNT_FOR_SPELL INT_SWAMP                 40
        DO SET_BUCKET_COUNT_FOR_SPELL INT_FLATTEN               50
        DO SET_BUCKET_COUNT_FOR_SPELL INT_EARTHQUAKE            70
        DO SET_BUCKET_COUNT_FOR_SPELL INT_EROSION               84
        DO SET_BUCKET_COUNT_FOR_SPELL INT_FIRESTORM             180
        DO SET_BUCKET_COUNT_FOR_SPELL INT_ANGEL_OF_DEATH        204
        DO SET_BUCKET_COUNT_FOR_SPELL INT_VOLCANO               320
      }
      ENDIF
    }
    EVERY 64
    {
      IF ( $17 < $16 )
      {
        SET $19                                  $18
        SET $17                                  $16
      }
      ENDIF
    }
    IF ( $19 > 0 )
    {
      DECREMENT $19 1
      IF ( $19 == 0 )
      {
        IF ( $2 == 1 )
        {
          IF ( $25 < 2 )
          {
            IF ( $22 == 0 )
            {
              DO ATTACK $3 $4 ATTACK_BUILDING INT_NO_SPECIFIC_BUILDING $1 $8 $10 $12 ATTACK_NORMAL 0 -1 -1 -1
              INCREMENT $1 10
              INCREMENT $18 600
              INCREMENT $16 1
              INCREMENT $25 1
            }
            ELSE
            {
              MULTIPLY $23 INT_M_VEHICLE_BOAT 5
              DO ATTACK BLUE $23 ATTACK_BUILDING INT_NO_SPECIFIC_BUILDING $1 $8 $10 $12 ATTACK_BY_BOAT 0 -1 -1 -1
              INCREMENT $1 10
              INCREMENT $18 600
              INCREMENT $16 1
              INCREMENT $25 1
            }
            ENDIF
          }
          ELSE
          {
            IF ( $22 == 0 )
            {
              DIVIDE $26 INT_BLUE_PEOPLE 3
              DO ATTACK BLUE $26 ATTACK_BUILDING INT_NO_SPECIFIC_BUILDING $1 $8 $10 $12 ATTACK_NORMAL 0 -1 -1 -1
              SET $25                               0
              INCREMENT $16 1
            }
            ELSE
            {
              MULTIPLY $23 INT_M_VEHICLE_BOAT 5
              DO ATTACK BLUE $23 ATTACK_BUILDING INT_NO_SPECIFIC_BUILDING $1 $8 $10 $12 ATTACK_BY_BOAT 0 -1 -1 -1
              INCREMENT $1 10
              INCREMENT $18 600
              INCREMENT $16 1
              SET $25                               0
            }
            ENDIF
          }
          ENDIF
        }
        ENDIF
      }
      ENDIF
    }
    ENDIF
    EVERY 512
    {
      IF ( INT_BLUE_PEOPLE > INT_YELLOW_PEOPLE )
      {
        IF ( INT_BLUE_PEOPLE > INT_GREEN_PEOPLE )
        {
          SET $20                                 1
          DO NAV_CHECK BLUE ATTACK_BUILDING INT_NO_SPECIFIC_BUILDING 0 $6
          IF ( $6 == 1 )
          {
            SET $3                                 0
            SET $2                                 1
          }
          ELSE
          {
            DO NAV_CHECK GREEN ATTACK_BUILDING INT_NO_SPECIFIC_BUILDING 0 $7
            IF ( $7 == 1 )
            {
              SET $3                                3
              SET $2                                1
            }
            ELSE
            {
              DO NAV_CHECK YELLOW ATTACK_BUILDING INT_NO_SPECIFIC_BUILDING 0 $5
              IF ( $5 == 1 )
              {
                SET $3                               2
                SET $2                               1
              }
              ELSE
              {
                SET $2                               0
              }
              ENDIF
            }
            ENDIF
          }
          ENDIF
        }
        ELSE
        {
          DO NAV_CHECK GREEN ATTACK_BUILDING INT_NO_SPECIFIC_BUILDING 0 $7
          IF ( $7 == 1 )
          {
            SET $3                                 3
            SET $2                                 1
          }
          ELSE
          {
            DO NAV_CHECK BLUE ATTACK_BUILDING INT_NO_SPECIFIC_BUILDING 0 $6
            IF ( $6 == 1 )
            {
              SET $3                                0
              SET $2                                1
            }
            ELSE
            {
              DO NAV_CHECK YELLOW ATTACK_BUILDING INT_NO_SPECIFIC_BUILDING 0 $5
              IF ( $5 == 1 )
              {
                SET $3                               2
                SET $2                               1
              }
              ELSE
              {
                SET $2                               0
              }
              ENDIF
            }
            ENDIF
          }
          ENDIF
        }
        ENDIF
      }
      ELSE
      {
        DO NAV_CHECK YELLOW ATTACK_BUILDING INT_NO_SPECIFIC_BUILDING 0 $5
        IF ( $5 == 1 )
        {
          SET $3                                  2
          SET $2                                  1
        }
        ELSE
        {
          DO NAV_CHECK GREEN ATTACK_BUILDING INT_NO_SPECIFIC_BUILDING 0 $7
          IF ( $7 == 1 )
          {
            SET $3                                 3
            SET $2                                 1
          }
          ELSE
          {
            DO NAV_CHECK BLUE ATTACK_BUILDING INT_NO_SPECIFIC_BUILDING 0 $6
            IF ( $6 == 1 )
            {
              SET $3                                0
              SET $2                                1
            }
            ELSE
            {
              SET $2                                0
            }
            ENDIF
          }
          ENDIF
        }
        ENDIF
      }
      ENDIF
    }
    EVERY 512 15
    {
      IF ( INT_MY_MANA > INT_M_SPELL_VOLCANO_COST )
      {
        SET $8                                   INT_VOLCANO
        SET $9                                   INT_M_SPELL_VOLCANO_COST
      }
      ELSE
      {
        IF ( INT_MY_MANA > INT_M_SPELL_FIRESTORM_COST )
        {
          SET $8                                  INT_FIRESTORM
          SET $9                                  INT_M_SPELL_FIRESTORM_COST
        }
        ELSE
        {
          IF ( INT_MY_MANA > INT_M_SPELL_TORNADO_COST )
          {
            SET $8                                 INT_TORNADO
            SET $9                                 INT_M_SPELL_TORNADO_COST
          }
          ELSE
          {
            IF ( INT_MY_MANA > INT_M_SPELL_LIGHTNING_COST )
            {
              SET $32                               INT_LIGHTNING
              SET $9                                INT_M_SPELL_LIGHTNING_COST
            }
            ELSE
            {
              IF ( INT_MY_MANA > INT_M_SPELL_SHIELD_COST )
              {
                SET $8                               INT_SHIELD
                SET $9                               INT_M_SPELL_SHIELD_COST
              }
              ELSE
              {
                IF ( INT_MY_MANA > INT_M_SPELL_INVISIBILITY_COST )
                {
                  SET $8                              INT_INVISIBILITY
                  SET $9                              INT_M_SPELL_INVISIBILITY_COST
                }
                ELSE
                {
                  SET $32                             INT_BLAST
                  SET $9                              INT_M_SPELL_BLAST_COST
                }
                ENDIF
              }
              ENDIF
            }
            ENDIF
          }
          ENDIF
        }
        ENDIF
      }
      ENDIF
    }
    EVERY 512 59
    {
      SET $13                                   INT_MY_MANA
      DECREMENT $13 $9
      IF ( $13 > 0 )
      {
        IF ( $13 > INT_M_SPELL_FIRESTORM_COST )
        {
          SET $10                                 INT_FIRESTORM
          SET $33                                 INT_M_SPELL_FIRESTORM_COST
        }
        ELSE
        {
          IF ( $13 > INT_M_SPELL_EARTHQUAKE_COST )
          {
            SET $10                                INT_EARTHQUAKE
            SET $33                                INT_M_SPELL_EARTHQUAKE_COST
          }
          ELSE
          {
            IF ( $13 > INT_M_SPELL_TORNADO_COST )
            {
              SET $10                               INT_TORNADO
              SET $33                               INT_M_SPELL_TORNADO_COST
            }
            ELSE
            {
              IF ( $13 > INT_M_SPELL_HYPNOTISM_COST )
              {
                SET $10                              INT_HYPNOTISM
                SET $33                              INT_M_SPELL_HYPNOTISM_COST
              }
              ELSE
              {
                IF ( $13 > INT_M_SPELL_LIGHTNING_COST )
                {
                  SET $10                             INT_LIGHTNING
                  SET $33                             INT_M_SPELL_LIGHTNING_COST
                }
                ELSE
                {
                  IF ( $13 > INT_M_SPELL_SWARM_COST )
                  {
                    SET $10                            INT_SWARM
                    SET $33                            INT_M_SPELL_SWARM_COST
                  }
                  ELSE
                  {
                    SET $34                            INT_BLAST
                    SET $33                            INT_M_SPELL_BLAST_COST
                  }
                  ENDIF
                }
                ENDIF
              }
              ENDIF
            }
            ENDIF
          }
          ENDIF
        }
        ENDIF
      }
      ENDIF
    }
    EVERY 512 97
    {
      SET $14                                   INT_MY_MANA
      DECREMENT $14 $9
      DECREMENT $14 $33
      IF ( $14 > 0 )
      {
        IF ( $14 > INT_M_SPELL_EARTHQUAKE_COST )
        {
          SET $12                                 INT_EARTHQUAKE
        }
        ELSE
        {
          IF ( $14 > INT_M_SPELL_TORNADO_COST )
          {
            SET $12                                INT_TORNADO
          }
          ELSE
          {
            IF ( $14 > INT_M_SPELL_HYPNOTISM_COST )
            {
              SET $12                               INT_HYPNOTISM
            }
            ELSE
            {
              IF ( $14 > INT_M_SPELL_LIGHTNING_COST )
              {
                SET $12                              INT_LIGHTNING
              }
              ELSE
              {
                IF ( $14 > INT_M_SPELL_SWARM_COST )
                {
                  SET $12                             INT_SWARM
                }
                ELSE
                {
                  SET $12                             INT_BLAST
                }
                ENDIF
              }
              ENDIF
            }
            ENDIF
          }
          ENDIF
        }
        ENDIF
      }
      ENDIF
    }
    EVERY 512 74
    {
      DIVIDE $4 INT_MY_NUM_PEOPLE 4
    }
    EVERY 128 99
    {
      DO GET_SPELLS_CAST BLUE INT_FLATTEN $28
      DO GET_SPELLS_CAST BLUE INT_EROSION $27
      SET $29                                   $28
      INCREMENT $29 $27
      IF ( $29 > 1 )
      {
        DO NAV_CHECK BLUE ATTACK_BUILDING INT_NO_SPECIFIC_BUILDING 0 $24
        IF ( $24 == 0 )
        {
          SET INT_ATTR_PEOPLE_PER_BOAT            7
          SET INT_ATTR_PREF_BOAT_DRIVERS          8
          SET INT_ATTR_PREF_BOAT_HUTS             1
          SET $22                                 1
        }
        ENDIF
      }
      ENDIF
    }
    EVERY 1024 67
    {
      IF ( $22 == 1 )
      {
        DO I_HAVE_ONE_SHOT SPELL_TYPE INT_ANGEL_OF_DEATH $31
        IF ( $31 > 0 )
        {
          DO SPELL_ATTACK INT_ANGEL_OF_DEATH 40 0
          DO GIVE_ONE_SHOT INT_ANGEL_OF_DEATH RED
        }
        ENDIF
      }
      ENDIF
    }
    EVERY 64 55
    {
      SET $30                                   INT_M_BUILDING_MEDIUM_HUT
      INCREMENT $30 INT_M_BUILDING_SMALL_HUT
      INCREMENT $30 INT_M_BUILDING_LARGE_HUT
      IF ( INT_MY_NUM_PEOPLE < 8 && INT_MY_NUM_KILLED_BY_BLUE > 5 )
      {
        IF ( $30 == 0 )
        {
          DO GIVE_UP_AND_SULK                     ON
        }
        ENDIF
      }
      ENDIF
    }
  }
  ENDIF
}
SCRIPT_END
