1
0
mirror of https://github.com/blupi-games/planetblupi synced 2024-12-30 10:15:36 +01:00
planetblupi/src/obstacle.cpp

3641 lines
69 KiB
C++
Raw Normal View History

2017-01-21 17:27:46 +01:00
// Obstacle.cpp
//
2017-02-11 21:43:47 +01:00
#include "decor.h"
#include "misc.h"
#include "action.h"
2017-01-21 17:27:46 +01:00
// Cette table indique les obstacles sur les sols.
// 0=passage, 1=obstacle
static char tableObstacleFloor[] =
{
1,1,1,1,1, // 0 (noir pour limites)
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
0,0,0,0,0, // 1
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,1,1,1,1, // 2
0,1,1,1,1,
0,1,1,1,1,
0,1,1,1,1,
0,1,1,1,1,
0,0,0,0,0, // 3
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,0, // 4
1,1,1,1,0,
1,1,1,1,0,
1,1,1,1,0,
1,1,1,1,0,
1,1,1,1,1, // 5
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
0,0,0,0,0,
0,0,0,0,0, // 6
0,0,1,1,1,
0,1,1,1,1,
0,1,1,1,1,
0,1,1,1,1,
0,0,0,0,0, // 7
1,1,1,0,0,
1,1,1,1,0,
1,1,1,1,0,
1,1,1,1,0,
1,1,1,1,0, // 8
1,1,1,1,0,
1,1,1,1,0,
1,1,1,0,0,
0,0,0,0,0,
0,1,1,1,1, // 9
0,1,1,1,1,
0,1,1,1,1,
0,0,1,1,1,
0,0,0,0,0,
0,0,1,1,1, // 10
0,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,0,0, // 11
1,1,1,1,0,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1, // 12
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,0,
1,1,1,0,0,
1,1,1,1,1, // 13
1,1,1,1,1,
1,1,1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,0,0,0,0,
0,0,0,0,0, // 49
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0, // 50
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0, // 51
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0, // 52
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0, // 53
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0, // 54
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0, // 55
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0, // 56
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0, // 57
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0, // 58
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0, // 59 (pont e-o)
0,0,0,0,0,
0,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
0,0,0,0,0, // 60
0,0,0,0,0,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
0,0,0,0,0, // 61
0,0,0,0,0,
1,1,1,1,0,
1,1,1,1,1,
1,1,1,1,1,
0,0,0,1,1, // 62 (pont n-s)
0,0,1,1,1,
0,0,1,1,1,
0,0,1,1,1,
0,0,1,1,1,
0,0,1,1,1, // 63
0,0,1,1,1,
0,0,1,1,1,
0,0,1,1,1,
0,0,1,1,1,
0,0,1,1,1, // 64
0,0,1,1,1,
0,0,1,1,1,
0,0,1,1,1,
0,0,0,1,1,
};
// Cette table indique les obstacles sur les sols pour le bateau.
// 0=passage, 1=obstacle
static char tableObstacleFloorBateau[] =
{
1,1,1,1,1, // 2
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1, // 3
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
0,0,1,1,1, // 4
0,0,1,1,1,
0,0,1,1,1,
0,0,1,1,1,
0,0,1,1,1,
0,0,0,0,0, // 5
0,0,0,0,0,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1, // 6
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1, // 7
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
0,0,1,1,1, // 8
0,0,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1, // 9
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,0,0, // 10
1,1,1,0,0,
1,1,1,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,1,1,1, // 11
0,0,1,1,1,
0,0,1,1,1,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0, // 12
0,0,0,0,0,
0,0,1,1,1,
0,0,1,1,1,
0,0,1,1,1,
0,0,0,0,0, // 13
0,0,0,0,0,
1,1,1,0,0,
1,1,1,0,0,
1,1,1,0,0,
0,0,0,0,0, // 14
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
};
// Cette table indique les obstacles sur les objets.
// 0=passage, 1=obstacle
static char tableObstacleObject[] =
{
0,0,0,0,0, // 0
0,0,0,0,0,
0,0,1,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0, // 1
0,1,0,0,0,
0,1,0,0,0,
0,1,0,0,0,
0,0,0,0,0,
0,0,0,0,0, // 2
0,1,1,1,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0, // 3
0,1,1,1,0,
0,1,1,1,0,
0,1,1,0,0,
0,0,0,0,0,
0,0,0,0,0, // 4
0,0,0,0,0,
0,0,0,0,0,
0,0,0,1,0,
0,0,0,0,0,
1,1,1,1,1, // 5
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
0,0,0,0,0, // 6 (arbre)
0,0,0,0,0,
0,0,1,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0, // 7
0,0,0,0,0,
0,0,0,1,0,
0,0,1,1,1,
0,0,0,1,0,
0,0,0,0,0, // 8
0,1,0,0,0,
0,1,0,0,0,
0,1,0,0,0,
0,0,0,0,0,
0,0,0,0,0, // 9
0,0,0,1,0,
0,0,1,1,0,
0,1,1,1,0,
0,0,0,0,0,
0,1,1,1,1, // 10
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
0,1,1,1,0,
1,1,1,1,0, // 11
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
0,1,1,1,1,
2017-02-12 00:44:46 +01:00
0,1,1,1,0, // 12 (fusée)
2017-01-21 17:27:46 +01:00
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
0,1,1,1,0,
0,0,0,0,0, // 13
0,0,0,0,0,
0,0,1,0,0,
0,0,0,0,0,
0,0,0,0,0,
2017-02-12 00:44:46 +01:00
0,0,0,0,0, // 14 (métal)
2017-01-21 17:27:46 +01:00
0,0,0,0,0,
0,0,1,1,1,
0,0,1,1,1,
0,0,1,1,1,
1,1,1,1,1, // 15 (maison construction)
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
0,0,0,0,0, // 16 (armure)
0,0,0,0,0,
0,0,1,1,1,
0,0,1,1,1,
0,0,1,1,1,
1,1,1,1,1, // 17 (batiment ennemi)
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1, // 18
1,1,1,1,1,
1,1,1,1,1,
1,0,0,0,0,
1,1,1,1,1,
2017-02-12 00:44:46 +01:00
0,0,0,0,0, // 19 (électro piég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// 86
0,0,0,0,0,
0,0,1,1,1,
0,0,1,1,1,
0,0,1,1,1,
0,0,0,0,0, // 87
0,0,0,0,0,
0,0,1,1,1,
0,0,1,1,1,
0,0,1,1,1,
0,0,0,0,0, // 88 (explosion)
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0, // 89
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0, // 90
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0, // 91
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0, // 92 (poison)
0,0,0,0,0,
0,0,1,1,1,
0,0,1,1,1,
0,0,1,1,1,
2017-02-12 00:44:46 +01:00
0,0,0,0,0, // 93 (piège)
2017-01-21 17:27:46 +01:00
0,0,0,0,0,
0,0,0,0,0,
0,0,0,1,0,
0,0,0,0,0,
0,1,1,1,0, // 94 (fleurs)
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
0,1,1,1,0,
0,0,0,0,0, // 95
0,0,0,0,0,
0,0,1,1,1,
0,0,1,1,1,
0,0,1,1,1,
2017-02-12 00:44:46 +01:00
0,0,0,0,0, // 96 (araignée dans piège)
2017-01-21 17:27:46 +01:00
0,0,0,0,0,
0,0,1,1,1,
0,0,1,1,1,
0,0,1,1,1,
2017-02-12 00:44:46 +01:00
0,0,0,0,0, // 97 (tracks dans piège)
2017-01-21 17:27:46 +01:00
0,0,0,0,0,
0,0,1,1,1,
0,0,1,1,1,
0,0,1,1,1,
2017-02-12 00:44:46 +01:00
0,0,0,0,0, // 98 (robot dans piège)
2017-01-21 17:27:46 +01:00
0,0,0,0,0,
0,0,1,1,1,
0,0,1,1,1,
0,0,1,1,1,
1,1,1,1,1, // 99 (recharge)
1,1,1,1,1,
1,1,1,1,1,
1,1,1,0,0,
1,1,1,0,0,
1,1,1,1,1, // 100 (batiment ennemi)
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1, // 101
1,1,1,1,1,
1,1,1,1,1,
1,0,0,0,0,
1,1,1,1,1,
1,1,1,1,1, // 102
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1, // 103
1,1,1,1,1,
1,1,1,1,1,
1,0,0,0,0,
1,1,1,1,1,
1,1,1,1,1, // 104
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1, // 105
1,1,1,1,1,
1,1,1,1,1,
1,0,0,0,0,
1,1,1,1,1,
2017-02-12 00:44:46 +01:00
1,1,1,1,1, // 106 (barrière)
2017-01-21 17:27:46 +01:00
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1, // 107
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1, // 108
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1, // 109
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1, // 110
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1, // 111
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1, // 112
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1, // 113 (maison)
1,1,1,1,1,
1,1,1,1,1,
1,1,1,0,0,
1,1,1,1,1,
2017-02-12 00:44:46 +01:00
0,0,0,0,0, // 114 (bombe dans piège)
2017-01-21 17:27:46 +01:00
0,0,0,0,0,
0,0,1,1,1,
0,0,1,1,1,
0,0,1,1,1,
1,1,1,1,1, // 115 (batiment ennemi)
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1, // 116
1,1,1,1,1,
1,1,1,1,1,
1,0,0,0,0,
1,1,1,1,1,
0,0,0,0,0, // 117 (bateau)
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0, // 118 (jeep)
0,0,0,0,0,
0,0,1,1,1,
0,0,1,1,1,
0,0,1,1,1,
1,1,1,1,1, // 119 (usine)
1,1,1,1,1,
1,1,1,1,1,
1,0,0,0,1,
1,1,1,1,1,
1,1,1,1,1, // 120
1,1,1,1,1,
1,1,1,1,1,
1,0,0,0,0,
1,1,1,1,1,
1,1,1,1,1, // 121 (mine de fer)
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1,
1,1,1,1,1, // 122
1,1,1,1,1,
1,1,1,1,1,
1,1,1,0,0,
1,1,1,1,1,
0,0,0,0,0, // 123 (fer)
0,0,0,0,0,
0,0,1,1,1,
0,0,1,1,1,
0,0,1,1,1,
0,0,0,0,0, // 124 (drapeau)
0,0,0,0,0,
0,0,1,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0, // 125 (mine)
0,0,0,0,0,
0,0,1,1,1,
0,0,1,1,1,
0,0,1,1,1,
2017-02-12 00:44:46 +01:00
0,0,0,0,0, // 126 (mine de fer, échaffaudage)
2017-01-21 17:27:46 +01:00
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0, // 127 (mine)
0,0,0,0,0,
0,0,1,1,1,
0,0,1,1,1,
0,0,1,1,1,
};
// Retourne les obstacles autour d'une cellule, sous la
// forme d'un tableau de 3x3.
void CDecor::SearchFloor(Sint32 rank, Sint32 icon, POINT cel, Sint32 *pBits)
2017-01-21 17:27:46 +01:00
{
char* pTable;
Sint32 first, last;
Sint32 dx, dy, x, y, i;
Sint32 def = 0;
2017-01-21 17:27:46 +01:00
pTable = tableObstacleFloor;
first = 0;
last = 64;
if ( rank != -1 && m_blupi[rank].vehicule == 1 ) // en bateau ?
{
pTable = tableObstacleFloorBateau;
first = 2;
last = 14;
def = 1;
}
if ( icon >= first && icon <= last )
{
pTable += (icon-first)*5*5;
if ( cel.x%2 == 0 ) dx = 0;
else dx = 2;
if ( cel.y%2 == 0 ) dy = 0;
else dy = 2;
for ( y=dy ; y<dy+3 ; y++ )
{
for ( x=dx ; x<dx+3 ; x++ )
{
*pBits++ = pTable[x+y*5];
}
}
}
else
{
for ( i=0 ; i<9 ; i++ )
{
*pBits++ = def;
}
}
}
// Retourne les obstacles autour d'une cellule, sous la
// forme d'un tableau de 3x3.
void CDecor::SearchObject(Sint32 rank, Sint32 icon, POINT cel, Sint32 *pBits)
2017-01-21 17:27:46 +01:00
{
char* pTable;
Sint32 dx, dy, x, y, i;
2017-01-21 17:27:46 +01:00
if ( icon >= 0 && icon <= 127 )
{
pTable = tableObstacleObject+(icon)*5*5;
if ( cel.x%2 == 0 ) dx = 0;
else dx = 2;
if ( cel.y%2 == 0 ) dy = 0;
else dy = 2;
for ( y=dy ; y<dy+3 ; y++ )
{
for ( x=dx ; x<dx+3 ; x++ )
{
*pBits++ = pTable[x+y*5];
}
}
}
else
{
for ( i=0 ; i<9 ; i++ )
{
*pBits++ = 0;
}
}
}
// Ajuste un sol en fonction du personnage.
void CDecor::AjustFloor(Sint32 rank, Sint32 icon, POINT cel, Sint32 *pBits)
2017-01-21 17:27:46 +01:00
{
Sint32 i;
2017-01-21 17:27:46 +01:00
if ( rank < 0 ) return;
if ( m_blupi[rank].perso == 0 ) // blupi ?
{
if ( m_blupi[rank].interrupt == -1 ) // passe muraille (*) ?
{
goto pass;
}
if ( m_blupi[rank].vehicule == 1 ) // en bateau ?
{
if ( icon >= 59 && icon <= 64 ) goto lock; // pont ?
}
return;
}
if ( m_blupi[rank].perso == 2 ) // virus ?
{
goto pass; // le virus peut aller partout (il volle)
return;
}
if ( m_blupi[rank].perso == 3 ) // tracks ?
{
if ( icon >= 59 && icon <= 64 ) // ponts ?
{
goto lock; // le tracks ne peut pas aller sur les ponts
}
return;
}
//- if ( m_blupi[rank].perso == 4 ) // robot ?
//- {
//- if ( icon >= 59 && icon <= 64 ) // ponts ?
//- {
//- goto lock; // le robot ne peut pas aller sur les ponts
//- }
//- return;
//- }
return;
pass:
for ( i=0 ; i<9 ; i++ )
{
*pBits++ = 0; // peut passer
}
return;
lock:
for ( i=0 ; i<9 ; i++ )
{
2017-02-12 00:44:46 +01:00
*pBits++ = 1; // bloqué
2017-01-21 17:27:46 +01:00
}
return;
}
2017-02-12 00:44:46 +01:00
// (*) Blupi est passe muraille lorsqu'il embarque ou débarque
2017-01-21 17:27:46 +01:00
// du bateau. Dans ce cas, tous les sols (rivages) doivent
// permettre de passer. En revanche, pas les obstacles !
// Ajuste un obstacle en fonction du personnage.
void CDecor::AjustObject(Sint32 rank, Sint32 icon, POINT cel, Sint32 *pBits)
2017-01-21 17:27:46 +01:00
{
Sint32 i;
2017-01-21 17:27:46 +01:00
if ( rank < 0 ) return;
if ( m_blupi[rank].perso == 0 ) // blupi ?
{
2017-02-12 00:44:46 +01:00
if ( m_blupi[rank].vehicule != 0 && // pas à pied ?
2017-01-21 17:27:46 +01:00
cel.x%2 == 1 && cel.y%2 == 1 &&
m_decor[cel.x/2][cel.y/2].objectIcon == 117 ) // bateau ?
{
goto lock; // blupi ne peut pas aller dans le bateau
}
// if ( m_blupi[rank].interrupt == -1 ) // passe muraille (*) ?
// {
// goto pass;
// }
// if ( cel.x > 0 && cel.x%2 == 0 && cel.y%2 == 1 &&
// (m_decor[(cel.x-2)/2][cel.y/2].objectIcon == 100 || // usine ?
// m_decor[(cel.x-2)/2][cel.y/2].objectIcon == 102 ||
// m_decor[(cel.x-2)/2][cel.y/2].objectIcon == 104 ||
// m_decor[(cel.x-2)/2][cel.y/2].objectIcon == 115 ||
// m_decor[(cel.x-2)/2][cel.y/2].objectIcon == 17) )
// {
// goto lock; // blupi ne peut pas bloquer la porte
// }
if ( cel.x%2 == 1 && cel.y%2 == 1 &&
m_decor[cel.x/2][cel.y/2].objectIcon == 99 ) // recharge ?
{
goto lock; // blupi ne peut pas bloquer la station
}
if ( m_blupi[rank].vehicule == 2 && // en jeep ?
m_decor[cel.x/2][cel.y/2].objectIcon == 113 ) // maison ?
{
goto lock; // blupi ne peut pas aller dans la maison
}
return;
}
2017-02-12 00:44:46 +01:00
if ( m_blupi[rank].perso == 1 ) // araignée ?
2017-01-21 17:27:46 +01:00
{
// if ( cel.x%2 != 0 && cel.y%2 != 0 &&
if ( IsSpiderObject(icon) ) // tomate ou poison ?
{
2017-02-12 00:44:46 +01:00
goto pass; // l'araignée peut aller dans les tomates
2017-01-21 17:27:46 +01:00
}
return;
}
if ( m_blupi[rank].perso == 2 ) // virus ?
{
if ( icon == 81 ||
icon == 83 ||
2017-02-12 00:44:46 +01:00
icon == 94 || // fleurs non-coupées ?
(icon >= 106 && icon <= 112) ) // barrières ennemies ?
2017-01-21 17:27:46 +01:00
{
goto pass; // le virus peut aller
}
return;
}
if ( m_blupi[rank].perso == 3 ) // tracks ?
{
if ( IsTracksObject(icon) ) // fleurs ou objet ?
{
goto pass; // le tracks peut aller
}
if ( icon == 113 || // maison ?
icon == 28 || icon == 29 || // laboratoire ?
icon == 119 || icon == 120 || // usine ?
icon == 121 || icon == 122 ) // mine de fer ?
{
goto lock; // le tracks ne peut pas aller dans la maison
}
return;
}
if ( m_blupi[rank].perso == 4 ) // robot ?
{
2017-02-12 00:44:46 +01:00
if ( IsRobotObject(icon) ) // piège ou dynamite ?
2017-01-21 17:27:46 +01:00
{
goto pass; // le robot peut aller
}
return;
}
if ( m_blupi[rank].perso == 5 ) // bombe ?
{
2017-02-12 00:44:46 +01:00
if ( icon == 93 ) // piège ?
2017-01-21 17:27:46 +01:00
{
goto pass; // la bombe peut aller
}
return;
}
2017-02-12 00:44:46 +01:00
if ( m_blupi[rank].perso == 7 ) // électro ?
2017-01-21 17:27:46 +01:00
{
2017-02-12 00:44:46 +01:00
if ( icon == 93 ) // piège ?
2017-01-21 17:27:46 +01:00
{
2017-02-12 00:44:46 +01:00
goto pass; // l'électro peut aller
2017-01-21 17:27:46 +01:00
}
if ( icon == 113 || // maison ?
icon == 28 || icon == 29 || // laboratoire ?
icon == 119 || icon == 120 || // usine ?
icon == 121 || icon == 122 ) // mine de fer ?
{
2017-02-12 00:44:46 +01:00
goto lock; // l'électro ne peut pas aller dans la maison
2017-01-21 17:27:46 +01:00
}
return;
}
if ( m_blupi[rank].perso == 8 ) // disciple ?
{
if ( cel.x > 0 && cel.x%2 == 0 && cel.y%2 == 1 &&
(m_decor[(cel.x-2)/2][cel.y/2].objectIcon == 100 || // usine ?
m_decor[(cel.x-2)/2][cel.y/2].objectIcon == 102 ||
m_decor[(cel.x-2)/2][cel.y/2].objectIcon == 104 ||
m_decor[(cel.x-2)/2][cel.y/2].objectIcon == 115) )
{
goto lock; // disciple ne peut pas bloquer la porte
}
if ( cel.x%2 == 1 && cel.y%2 == 1 &&
m_decor[cel.x/2][cel.y/2].objectIcon == 99 ) // recharge ?
{
goto lock; // disciple ne peut pas bloquer la station
}
if ( m_decor[cel.x/2][cel.y/2].objectIcon == 113 ) // maison ?
{
goto lock; // disciple ne peut pas aller dans la maison
}
return;
}
return;
pass:
for ( i=0 ; i<9 ; i++ )
{
*pBits++ = 0; // peut passer
}
return;
lock:
for ( i=0 ; i<9 ; i++ )
{
2017-02-12 00:44:46 +01:00
*pBits++ = 1; // bloqué
2017-01-21 17:27:46 +01:00
}
return;
}
// Copie un tableau 3x3 dans un tableau 9x9.
void Copy33To99(Sint32 *pSrc33, Sint32 *pDst99, Sint32 dx, Sint32 dy)
2017-01-21 17:27:46 +01:00
{
Sint32 x, y;
2017-01-21 17:27:46 +01:00
for ( y=0 ; y<3 ; y++ )
{
for ( x=0 ; x<3 ; x++ )
{
pDst99[(dx+1)*3+x + ((dy+1)*3+y)*9] = pSrc33[x+y*3];
}
}
}
2017-02-12 00:44:46 +01:00
// Indique s'il est possible d'avancer dans une direction donnée.
2017-01-21 17:27:46 +01:00
bool CDecor::IsFreeDirect(POINT cel, Sint32 direct, Sint32 rank)
2017-01-21 17:27:46 +01:00
{
Sint32 icon, workBlupi;
Sint32 bits[3*3], obstacles[9*9];
2017-01-21 17:27:46 +01:00
POINT test, vector;
vector = GetVector(direct);
test.x = cel.x+vector.x;
test.y = cel.y+vector.y;
if ( m_decor[test.x/2][test.y/2].fire > 0 &&
m_decor[test.x/2][test.y/2].fire < MoveMaxFire() ) return false;
2017-01-21 17:27:46 +01:00
2017-02-12 00:44:46 +01:00
// Cellule bloquée (un blupi travaille ici) ?
2017-01-21 17:27:46 +01:00
if ( m_blupi[rank].perso != 3 ) // pas tracks ?
{
workBlupi = m_decor[test.x/2][test.y/2].workBlupi;
if ( workBlupi >= 0 && workBlupi != rank ) return false;
2017-01-21 17:27:46 +01:00
}
2017-02-12 00:44:46 +01:00
// Déplacement possible par-rapport au sol ?
2017-01-21 17:27:46 +01:00
// icon = m_decor[cel.x/2][cel.y/2].floorIcon;
// SearchFloor(rank, icon, cel, bits);
// AjustFloor(rank, icon, cel, bits);
// if ( bits[(1+vector.x)+(1+vector.y)*3] == 1 ) return false;
2017-01-21 17:27:46 +01:00
icon = m_decor[test.x/2][test.y/2].floorIcon;
SearchFloor(rank, icon, test, bits);
AjustFloor(rank, icon, test, bits);
if ( bits[1+1*3] == 1 ) return false;
if ( bits[(1-vector.x)+(1-vector.y)*3] == 1 ) return false;
2017-01-21 17:27:46 +01:00
2017-02-12 00:44:46 +01:00
// Déplacement possible par-rapport aux obstacles ?
2017-01-21 17:27:46 +01:00
icon = m_decor[cel.x/2][cel.y/2].objectIcon;
SearchObject(rank, icon, cel, bits);
AjustObject(rank, icon, cel, bits);
if ( bits[(1+vector.x)+(1+vector.y)*3] == 1 ) return false;
2017-01-21 17:27:46 +01:00
icon = m_decor[test.x/2][test.y/2].objectIcon;
SearchObject(rank, icon, test, bits);
AjustObject(rank, icon, test, bits);
if ( bits[(1-vector.x)+(1-vector.y)*3] == 1 ) return false;
if ( bits[1+1*3] == 1 ) return false;
2017-01-21 17:27:46 +01:00
2017-02-12 00:44:46 +01:00
if ( vector.x != 0 && vector.y != 0 ) // déplacement diagonal ?
2017-01-21 17:27:46 +01:00
{
test.x = cel.x;
test.y = cel.y+vector.y;
icon = m_decor[test.x/2][test.y/2].objectIcon;
SearchObject(rank, icon, test, bits);
AjustObject(rank, icon, test, bits);
Copy33To99(bits, obstacles, 0, vector.y);
test.x = cel.x+vector.x;
test.y = cel.y;
icon = m_decor[test.x/2][test.y/2].objectIcon;
SearchObject(rank, icon, test, bits);
AjustObject(rank, icon, test, bits);
Copy33To99(bits, obstacles, vector.x, 0);
if ( obstacles[(4+vector.x*1)+(4+vector.y*2)*9] == 1 ) return false;
if ( obstacles[(4+vector.x*2)+(4+vector.y*1)*9] == 1 ) return false;
2017-01-21 17:27:46 +01:00
}
return true; // pas d'obstacle
2017-01-21 17:27:46 +01:00
}
// Indique si une cellule contient un objet.
2017-02-12 00:44:46 +01:00
// Est utilisé lors du dessin (BuildPutBlupi), pour savoir
2017-01-21 17:27:46 +01:00
// si blupi est devant un objet.
bool CDecor::IsFreeCelObstacle(POINT cel)
2017-01-21 17:27:46 +01:00
{
Sint32 icon;
Sint32 bits[9];
2017-01-21 17:27:46 +01:00
if ( !IsValid(cel) ) return false;
2017-01-21 17:27:46 +01:00
if ( m_decor[cel.x/2][cel.y/2].fire > 0 &&
m_decor[cel.x/2][cel.y/2].fire < MoveMaxFire() ) return false;
2017-01-21 17:27:46 +01:00
icon = m_decor[cel.x/2][cel.y/2].objectIcon;
if ( icon != -1 )
{
SearchObject(-1, icon, cel, bits);
if ( bits[1+1*3] == 1 ) return false;
2017-01-21 17:27:46 +01:00
}
return true; // pas d'obstacle
2017-01-21 17:27:46 +01:00
}
// Indique si une cellule contient un sol.
2017-02-12 00:44:46 +01:00
// Est utilisé pour savoir si blupi peut aller sur une cellule
2017-01-21 17:27:46 +01:00
// en tenant compte uniquement des sols.
// Retourne true si blupi peut y aller !
2017-01-21 17:27:46 +01:00
bool CDecor::IsFreeCelFloor(POINT cel, Sint32 rank)
2017-01-21 17:27:46 +01:00
{
Sint32 icon;
Sint32 bits[9];
2017-01-21 17:27:46 +01:00
if ( !IsValid(cel) ) return false;
2017-01-21 17:27:46 +01:00
icon = m_decor[cel.x/2][cel.y/2].floorIcon;
if ( icon != -1 )
{
SearchFloor(rank, icon, cel, bits);
AjustFloor(rank, icon, cel, bits);
if ( bits[1+1*3] == 1 ) return false;
2017-01-21 17:27:46 +01:00
}
return true; // pas d'obstacle
2017-01-21 17:27:46 +01:00
}
// Indique si une cellule est libre.
2017-02-12 00:44:46 +01:00
// Est utilisé pour savoir si blupi peut venir ici
// débarquer en bateau ou monter dans sa jeep.
2017-01-21 17:27:46 +01:00
bool CDecor::IsFreeCelGo(POINT cel, Sint32 rank)
2017-01-21 17:27:46 +01:00
{
bool bOK;
2017-01-21 17:27:46 +01:00
POINT limit;
Sint32 action, channel, icon;
2017-01-21 17:27:46 +01:00
if ( rank == -1 ) return IsFreeCel(cel, rank);
GetObject(cel, channel, icon);
// Refuse d'aller dans la maison si blupi porte qq chose.
if ( m_blupi[rank].takeChannel != -1 && // porte qq chose ?
channel == CHOBJECT &&
icon == 113 ) // maison ?
{
return false;
2017-01-21 17:27:46 +01:00
}
// Refuse d'aller dans le laboratoire (on peut seulement
// y transformer qq chose).
if ( channel == CHOBJECT &&
(icon == 28 || // laboratoire ?
icon == 120 || // usine ?
icon == 122) ) // mine de fer ?
{
return false;
2017-01-21 17:27:46 +01:00
}
bOK = IsFreeCel(cel, rank);
if ( bOK ) return true;
2017-01-21 17:27:46 +01:00
bOK = IsFreeCelEmbarque(cel, rank, action, limit);
if ( bOK ) return true;
2017-01-21 17:27:46 +01:00
bOK = IsFreeCelDebarque(cel, rank, action, limit);
if ( bOK ) return true;
2017-01-21 17:27:46 +01:00
if ( !m_blupi[rank].bMalade &&
2017-02-12 00:44:46 +01:00
m_blupi[rank].vehicule == 0 && // à pied ?
2017-01-21 17:27:46 +01:00
m_blupi[rank].perso != 8 && // pas le disciple ?
channel == CHOBJECT &&
icon == 118 ) // jeep ?
{
return true;
2017-01-21 17:27:46 +01:00
}
if ( !m_blupi[rank].bMalade &&
2017-02-12 00:44:46 +01:00
m_blupi[rank].vehicule == 0 && // à pied ?
2017-01-21 17:27:46 +01:00
m_blupi[rank].perso != 8 && // pas le disciple ?
m_blupi[rank].energy > MAXENERGY/4 && // fort ?
m_blupi[rank].takeChannel == -1 && // porte rien ?
channel == CHOBJECT &&
icon == 16 ) // armure ?
{
return true;
2017-01-21 17:27:46 +01:00
}
return false;
2017-01-21 17:27:46 +01:00
}
// Indique si on peut faire qq chose sur une cellule.
2017-02-12 00:44:46 +01:00
// Est utilisé pour savoir comment est la mise en évidence (hili)
// à cet endroit.
2017-01-21 17:27:46 +01:00
bool CDecor::IsFreeCelHili(POINT cel, Sint32 rank)
2017-01-21 17:27:46 +01:00
{
bool bOK;
2017-01-21 17:27:46 +01:00
POINT limit;
Sint32 workBlupi, channel, icon, action;
2017-01-21 17:27:46 +01:00
if ( IsValid(cel) )
{
workBlupi = m_decor[cel.x/2][cel.y/2].workBlupi;
if ( workBlupi >= 0 && workBlupi != rank ) return false;
2017-01-21 17:27:46 +01:00
channel = m_decor[cel.x/2][cel.y/2].objectChannel;
icon = m_decor[cel.x/2][cel.y/2].objectIcon;
if ( channel == CHOBJECT &&
2017-02-12 00:44:46 +01:00
(icon == 12 || // fusée ?
2017-01-21 17:27:46 +01:00
(icon >= 20 && icon <= 26) || // mur ?
2017-02-12 00:44:46 +01:00
(icon >= 106 && icon <= 112) || // barrière ?
2017-01-21 17:27:46 +01:00
(icon >= 99 && icon <= 105) || // batiment ennemi ?
(icon >= 115 && icon <= 116) || // idem ?
(icon >= 17 && icon <= 18)) ) // idem ?
{
return false;
2017-01-21 17:27:46 +01:00
}
}
if ( rank == -1 ) return IsFreeCelFloor(cel, rank);
bOK = IsFreeCelFloor(cel, rank);
if ( bOK ) return true;
2017-01-21 17:27:46 +01:00
bOK = IsFreeCelEmbarque(cel, rank, action, limit);
if ( bOK ) return true;
2017-01-21 17:27:46 +01:00
bOK = IsFreeCelDebarque(cel, rank, action, limit);
if ( bOK ) return true;
2017-01-21 17:27:46 +01:00
return false;
2017-01-21 17:27:46 +01:00
}
// Indique si une cellule est libre.
2017-02-12 00:44:46 +01:00
// Est utilisé pour savoir si blupi peut venir ici.
2017-01-21 17:27:46 +01:00
bool CDecor::IsFreeCel(POINT cel, Sint32 rank)
2017-01-21 17:27:46 +01:00
{
Sint32 icon, workBlupi;
Sint32 bits[9];
2017-01-21 17:27:46 +01:00
if ( !IsValid(cel) ) return false;
2017-01-21 17:27:46 +01:00
if ( m_decor[cel.x/2][cel.y/2].fire > 0 &&
m_decor[cel.x/2][cel.y/2].fire < MoveMaxFire() ) return false;
2017-01-21 17:27:46 +01:00
2017-02-12 00:44:46 +01:00
// Cellule bloquée (un blupi travaille ici) ?
2017-01-21 17:27:46 +01:00
if ( rank != -1 && m_blupi[rank].perso != 3 ) // pas tracks ?
{
workBlupi = m_decor[cel.x/2][cel.y/2].workBlupi;
if ( workBlupi >= 0 && workBlupi != rank ) return false;
2017-01-21 17:27:46 +01:00
}
icon = m_decor[cel.x/2][cel.y/2].floorIcon;
SearchFloor(rank, icon, cel, bits);
AjustFloor(rank, icon, cel, bits);
if ( bits[1+1*3] == 1 ) return false;
2017-01-21 17:27:46 +01:00
icon = m_decor[cel.x/2][cel.y/2].objectIcon;
SearchObject(rank, icon, cel, bits);
AjustObject(rank, icon, cel, bits);
if ( bits[1+1*3] == 1 ) return false;
2017-01-21 17:27:46 +01:00
return true; // pas d'obstacle
2017-01-21 17:27:46 +01:00
}
2017-02-12 00:44:46 +01:00
// Indique si blupi peut déposer un objet ici.
2017-01-21 17:27:46 +01:00
bool CDecor::IsFreeCelDepose(POINT cel, Sint32 rank)
2017-01-21 17:27:46 +01:00
{
Sint32 icon;
2017-01-21 17:27:46 +01:00
if ( !IsFreeCel(cel, rank) ) return false;
2017-01-21 17:27:46 +01:00
icon = m_decor[cel.x/2][cel.y/2].objectIcon;
2017-02-12 00:44:46 +01:00
if ( icon == 10000 || icon == 10001 || // éclairs entre tours ?
2017-01-21 17:27:46 +01:00
icon == 18 ) // dalle glissante ?
{
return false;
2017-01-21 17:27:46 +01:00
}
icon = m_decor[cel.x/2][cel.y/2].floorIcon;
2017-02-12 00:44:46 +01:00
if ( icon == 80 ) // téléporteur ?
2017-01-21 17:27:46 +01:00
{
return false;
2017-01-21 17:27:46 +01:00
}
return true;
2017-01-21 17:27:46 +01:00
}
// Indique s'il est possible d'embarquer ici.
2017-02-12 00:44:46 +01:00
// Le point retourné dans "limit" indique jusqu'où il est
2017-01-21 17:27:46 +01:00
// possible de marcher normalement (sans passe muraille).
bool CDecor::IsFreeCelEmbarque(POINT cel, Sint32 rank,
Sint32 &action, POINT &limit)
2017-01-21 17:27:46 +01:00
{
bool bOK;
Sint32 channel, icon;
2017-01-21 17:27:46 +01:00
2017-02-12 00:44:46 +01:00
// Impossible si blupi n'est pas à pied,
2017-01-21 17:27:46 +01:00
// ou s'il s'agit d'un disciple.
if ( rank == -1 || m_blupi[rank].vehicule != 0 ||
m_blupi[rank].perso == 8 ) return false;
2017-01-21 17:27:46 +01:00
2017-02-12 00:44:46 +01:00
// A-t-on cliqué sur un bateau ?
if ( cel.x%2 != 1 || cel.y%2 != 1 ) return false;
2017-01-21 17:27:46 +01:00
GetObject(cel, channel, icon);
if ( channel != CHOBJECT || icon != 117 ) return false;
2017-01-21 17:27:46 +01:00
GetFloor(cel, channel, icon);
if ( channel == CHFLOOR && icon == 2 )
{
m_blupi[rank].vehicule = 1;
bOK = IsFreeCel(GetCel(cel,+1,0), rank); // libre (en bateau) ?
m_blupi[rank].vehicule = 0;
if ( bOK )
{
limit = GetCel(cel,-2,0);
action = WM_ACTION_BATEAUDE;
return true;
2017-01-21 17:27:46 +01:00
}
}
GetFloor(cel, channel, icon);
if ( channel == CHFLOOR && icon == 3 )
{
m_blupi[rank].vehicule = 1;
bOK = IsFreeCel(GetCel(cel,0,+1), rank); // libre (en bateau) ?
m_blupi[rank].vehicule = 0;
if ( bOK )
{
limit = GetCel(cel,0,-2);
action = WM_ACTION_BATEAUDS;
return true;
2017-01-21 17:27:46 +01:00
}
}
GetFloor(cel, channel, icon);
if ( channel == CHFLOOR && icon == 4 )
{
m_blupi[rank].vehicule = 1;
bOK = IsFreeCel(GetCel(cel,-1,0), rank); // libre (en bateau) ?
m_blupi[rank].vehicule = 0;
if ( bOK )
{
limit = GetCel(cel,+1,0);
action = WM_ACTION_BATEAUDO;
return true;
2017-01-21 17:27:46 +01:00
}
}
GetFloor(cel, channel, icon);
if ( channel == CHFLOOR && icon == 5 )
{
m_blupi[rank].vehicule = 1;
bOK = IsFreeCel(GetCel(cel,0,-1), rank); // libre (en bateau) ?
m_blupi[rank].vehicule = 0;
if ( bOK )
{
limit = GetCel(cel,0,+1);
action = WM_ACTION_BATEAUDN;
return true;
2017-01-21 17:27:46 +01:00
}
}
return false;
2017-01-21 17:27:46 +01:00
}
2017-02-12 00:44:46 +01:00
// Indique s'il est possible de débarquer ici.
// Le point retourné dans "limit" indique jusqu'où il est
2017-01-21 17:27:46 +01:00
// possible de naviguer normalement (sans passe muraille).
bool CDecor::IsFreeCelDebarque(POINT cel, Sint32 rank,
Sint32 &action, POINT &limit)
2017-01-21 17:27:46 +01:00
{
bool bOK;
Sint32 channel1, icon1;
Sint32 channel2, icon2;
2017-01-21 17:27:46 +01:00
// Impossible si blupi n'est pas en bateau.
if ( rank == -1 || m_blupi[rank].vehicule != 1 ) return false;
2017-01-21 17:27:46 +01:00
m_blupi[rank].vehicule = 0;
2017-02-12 00:44:46 +01:00
bOK = IsFreeCel(cel, rank); // libre (à pied) ?
2017-01-21 17:27:46 +01:00
m_blupi[rank].vehicule = 1;
if ( !bOK ) return false;
2017-01-21 17:27:46 +01:00
GetFloor(GetCel(cel,+2,0), channel1, icon1);
GetObject(GetCel(cel,+2,0), channel2, icon2);
if ( channel1 == CHFLOOR && icon1 == 2 && // rive ?
2017-02-12 00:44:46 +01:00
channel2 == -1 && icon2 == -1 && // pas de bateau amarré ?
2017-01-21 17:27:46 +01:00
cel.x%2 == 1 && cel.y%2 == 1 )
{
limit = GetCel(cel,+3,0);
action = WM_ACTION_BATEAUAE;
return true;
2017-01-21 17:27:46 +01:00
}
GetFloor(GetCel(cel,0,+2), channel1, icon1);
GetObject(GetCel(cel,0,+2), channel2, icon2);
if ( channel1 == CHFLOOR && icon1 == 3 && // rive ?
2017-02-12 00:44:46 +01:00
channel2 == -1 && icon2 == -1 && // pas de bateau amarré ?
2017-01-21 17:27:46 +01:00
cel.x%2 == 1 && cel.y%2 == 1 )
{
limit = GetCel(cel,0,+3);
action = WM_ACTION_BATEAUAS;
return true;
2017-01-21 17:27:46 +01:00
}
GetFloor(GetCel(cel,-2,0), channel1, icon1);
GetObject(GetCel(cel,-2,0), channel2, icon2);
if ( channel1 == CHFLOOR && icon1 == 4 && // rive ?
2017-02-12 00:44:46 +01:00
channel2 == -1 && icon2 == -1 && // pas de bateau amarré ?
2017-01-21 17:27:46 +01:00
cel.x%2 == 0 && cel.y%2 == 1 )
{
limit = GetCel(cel,-2,0);
action = WM_ACTION_BATEAUAO;
return true;
2017-01-21 17:27:46 +01:00
}
GetFloor(GetCel(cel,0,-2), channel1, icon1);
GetObject(GetCel(cel,0,-2), channel2, icon2);
if ( channel1 == CHFLOOR && icon1 == 5 && // rive ?
2017-02-12 00:44:46 +01:00
channel2 == -1 && icon2 == -1 && // pas de bateau amarré ?
2017-01-21 17:27:46 +01:00
cel.x%2 == 1 && cel.y%2 == 0 )
{
limit = GetCel(cel,0,-2);
action = WM_ACTION_BATEAUAN;
return true;
2017-01-21 17:27:46 +01:00
}
return false;
2017-01-21 17:27:46 +01:00
}
// Indique s'il est possible de sauter dans une direction.
bool CDecor::IsFreeJump(POINT cel, Sint32 direct, Sint32 rank, Sint32 &action)
2017-01-21 17:27:46 +01:00
{
POINT depart, vector;
Sint32 i, icon;
Sint32 bits[3*3];
2017-01-21 17:27:46 +01:00
2017-02-12 00:44:46 +01:00
// Refuse de sauter si blupi n'est pas à pied !
if ( m_blupi[rank].vehicule != 0 ) return false;
2017-01-21 17:27:46 +01:00
// Refuse de sauter dans les directions se, so, no, ne.
if ( (direct/16)%2 != 0 ) return false;
2017-01-21 17:27:46 +01:00
2017-02-12 00:44:46 +01:00
// Refuse de sauter si peu d'énergie ou si porte qq chose.
2017-01-21 17:27:46 +01:00
if ( m_blupi[rank].perso != 0 ||
m_blupi[rank].energy <= MAXENERGY/4 ||
m_blupi[rank].takeChannel != -1 ) return false;
2017-01-21 17:27:46 +01:00
vector = GetVector(direct);
depart = cel;
i = 0;
while ( true )
2017-01-21 17:27:46 +01:00
{
cel.x += vector.x;
cel.y += vector.y;
if ( i == 4 ) break;
if ( IsFreeCelFloor(cel, rank) ) break;
i ++;
}
if ( i == 0 ) return false;
2017-01-21 17:27:46 +01:00
2017-02-12 00:44:46 +01:00
// Départ possible par-rapport aux obstacles ?
2017-01-21 17:27:46 +01:00
icon = m_decor[depart.x/2][depart.y/2].objectIcon;
SearchObject(rank, icon, depart, bits);
AjustObject(rank, icon, depart, bits);
if ( bits[(1+vector.x)+(1+vector.y)*3] == 1 ) return false;
2017-01-21 17:27:46 +01:00
2017-02-12 00:44:46 +01:00
// Arrivée possible par-rapport aux obstacles ?
2017-01-21 17:27:46 +01:00
icon = m_decor[cel.x/2][cel.y/2].objectIcon;
SearchObject(rank, icon, cel, bits);
AjustObject(rank, icon, cel, bits);
if ( bits[(1-vector.x)+(1-vector.y)*3] == 1 ) return false;
2017-01-21 17:27:46 +01:00
if ( !IsFreeCel(cel, rank) ||
IsBlupiHere(cel, true) ) return false;
2017-01-21 17:27:46 +01:00
action = ACTION_SAUTE2+(i-1);
return true;
2017-01-21 17:27:46 +01:00
}
// Indique s'il est possible de glisser dans une direction.
bool CDecor::IsFreeGlisse(POINT cel, Sint32 direct, Sint32 rank, Sint32 &action)
2017-01-21 17:27:46 +01:00
{
Sint32 channel, icon;
2017-01-21 17:27:46 +01:00
// Y'a que blupi qui glisse !
if ( m_blupi[rank].perso != 0 ) return false;
2017-01-21 17:27:46 +01:00
GetFloor(GetCel((cel.x/2)*2,(cel.y/2)*2), channel, icon);
if ( channel != CHFLOOR || icon != 18 ) // pas dalle glissante ?
{
return false;
2017-01-21 17:27:46 +01:00
}
if ( !IsFreeDirect(cel, direct, rank) ) return false;
2017-01-21 17:27:46 +01:00
action = ACTION_GLISSE;
return true;
2017-01-21 17:27:46 +01:00
}
// Cherche la meilleure direction pour atteindre un but.
2017-02-12 00:44:46 +01:00
// Retourne -1 si on est déjà sur le but.
2017-01-21 17:27:46 +01:00
Sint32 CDecor::DirectSearch(POINT cel, POINT goal)
2017-01-21 17:27:46 +01:00
{
POINT dir;
Sint32 direct, tan;
2017-01-21 17:27:46 +01:00
dir.x = goal.x - cel.x;
dir.y = goal.y - cel.y;
if ( dir.x == 0 && dir.y == 0 ) // but atteint ?
{
return -1;
}
#if 0
if ( dir.x > 0 )
{
if ( dir.y > 0 ) direct = DIRECT_SE;
if ( dir.y == 0 ) direct = DIRECT_E;
if ( dir.y < 0 ) direct = DIRECT_NE;
}
if ( dir.x == 0 )
{
if ( dir.y > 0 ) direct = DIRECT_S;
else direct = DIRECT_N;
}
if ( dir.x < 0 )
{
if ( dir.y > 0 ) direct = DIRECT_SO;
if ( dir.y == 0 ) direct = DIRECT_O;
if ( dir.y < 0 ) direct = DIRECT_NO;
}
#endif
2017-02-12 00:44:46 +01:00
// Cherche le huitième de cadrant correspondant à
2017-01-21 17:27:46 +01:00
// la direction.
// 41 = 100*tan(22.5)
// 241 = 100*tan(67.5)
if ( dir.x == 0 )
{
if ( dir.y > 0 ) direct = DIRECT_S;
else direct = DIRECT_N;
}
else
{
tan = abs(100*dir.y/dir.x); // calcule la tangente*100
if ( dir.x > 0 )
{
if ( dir.y > 0 )
{
direct = DIRECT_SE;
if ( tan < 41 ) direct = DIRECT_E;
if ( tan > 241 ) direct = DIRECT_S;
}
else
{
direct = DIRECT_NE;
if ( tan < 41 ) direct = DIRECT_E;
if ( tan > 241 ) direct = DIRECT_N;
}
}
else
{
if ( dir.y > 0 )
{
direct = DIRECT_SO;
if ( tan < 41 ) direct = DIRECT_O;
if ( tan > 241 ) direct = DIRECT_S;
}
else
{
direct = DIRECT_NO;
if ( tan < 41 ) direct = DIRECT_O;
if ( tan > 241 ) direct = DIRECT_N;
}
}
}
return direct;
}
2017-02-12 00:44:46 +01:00
// Vide les positions déjà essayées.
2017-01-21 17:27:46 +01:00
void CDecor::FlushUsed(Sint32 rank)
2017-01-21 17:27:46 +01:00
{
m_blupi[rank].nbUsed = 0;
m_blupi[rank].nextRankUsed = 0;
}
2017-02-12 00:44:46 +01:00
// Ajoute une position déjà été essayée.
2017-01-21 17:27:46 +01:00
void CDecor::AddUsedPos(Sint32 rank, POINT pos)
2017-01-21 17:27:46 +01:00
{
Sint32 i, j, old;
2017-01-21 17:27:46 +01:00
2017-02-12 00:44:46 +01:00
// Un virus est bête.
2017-01-21 17:27:46 +01:00
if ( m_blupi[rank].perso == 2 ) return;
2017-02-12 00:44:46 +01:00
// Déjà dans la liste ?
2017-01-21 17:27:46 +01:00
for ( i=0 ; i<m_blupi[rank].nbUsed ; i++ )
{
if ( pos.x == m_blupi[rank].posUsed[i].x &&
pos.y == m_blupi[rank].posUsed[i].y )
{
m_blupi[rank].rankUsed[i] = m_blupi[rank].nextRankUsed;
m_blupi[rank].nextRankUsed ++;
return;
}
}
// Si la liste est pleine, remplace le plus vieux point.
if ( m_blupi[rank].nbUsed >= MAXUSED )
{
old = 10000;
j = 0;
for ( i=0 ; i<m_blupi[rank].nbUsed ; i++ )
{
if ( m_blupi[rank].rankUsed[i] < old )
{
old = m_blupi[rank].rankUsed[i];
j = i;
}
}
m_blupi[rank].posUsed[j] = pos;
m_blupi[rank].rankUsed[j] = m_blupi[rank].nextRankUsed;
m_blupi[rank].nextRankUsed ++;
return;
}
2017-02-12 00:44:46 +01:00
// Ajoute à la suite de la liste.
2017-01-21 17:27:46 +01:00
i = m_blupi[rank].nbUsed;
m_blupi[rank].posUsed[i] = pos;
m_blupi[rank].rankUsed[i] = m_blupi[rank].nextRankUsed;
m_blupi[rank].nbUsed ++;
m_blupi[rank].nextRankUsed ++;
return;
}
2017-02-12 00:44:46 +01:00
// Cherche si une position a déjà été essayée.
2017-01-21 17:27:46 +01:00
bool CDecor::IsUsedPos(Sint32 rank, POINT pos)
2017-01-21 17:27:46 +01:00
{
Sint32 i;
2017-01-21 17:27:46 +01:00
for ( i=0 ; i<m_blupi[rank].nbUsed ; i++ )
{
if ( pos.x == m_blupi[rank].posUsed[i].x &&
pos.y == m_blupi[rank].posUsed[i].y ) return true;
2017-01-21 17:27:46 +01:00
}
return false;
2017-01-21 17:27:46 +01:00
}
// Cherche la meilleure direction pour atteindre un but.
bool CDecor::SearchBestBase(Sint32 rank, Sint32 &action, POINT &newCel, Sint32 &direct)
2017-01-21 17:27:46 +01:00
{
Sint32 searchDirect[8] = {0,1,7,2,6,5,3,4};
Sint32 tryDirect, workBlupi, i, a;
2017-01-21 17:27:46 +01:00
POINT cel, vector;
bool bFree;
2017-01-21 17:27:46 +01:00
cel = m_blupi[rank].cel;
direct = DirectSearch(cel, m_blupi[rank].goalCel);
AddUsedPos(rank, cel);
for ( i=0 ; i<8 ; i++ )
{
tryDirect = ((direct/16+searchDirect[i])%8)*16;
vector = GetVector(tryDirect);
bFree = IsFreeGlisse(cel, tryDirect, rank, action);
if ( !bFree )
{
bFree = IsFreeDirect(cel, tryDirect, rank);
action = ACTION_MARCHE;
}
if ( !bFree )
{
bFree = IsFreeJump(cel, tryDirect, rank, action);
}
a = GetAmplitude(action);
// Blupi peut aller sur le lieu de la construction.
if ( m_blupi[rank].passCel.x != -1 )
{
newCel = m_blupi[rank].passCel;
workBlupi = m_decor[newCel.x/2][newCel.y/2].workBlupi;
if ( m_blupi[rank].passCel.x/2 == (cel.x+vector.x*a)/2 &&
m_blupi[rank].passCel.y/2 == (cel.y+vector.y*a)/2 &&
(workBlupi < 0 || workBlupi == rank) )
{
bFree = true;
2017-01-21 17:27:46 +01:00
}
}
if ( bFree )
{
newCel.x = cel.x + vector.x*a;
newCel.y = cel.y + vector.y*a;
if ( !IsUsedPos(rank, newCel) )
{
if ( m_blupi[rank].perso == 3 ) // tracks ?
{
// Le tracks peut aller sur les blupi
2017-02-12 00:44:46 +01:00
// pour les écraser !
if ( IsTracksHere(newCel, false) )
2017-01-21 17:27:46 +01:00
{
continue;
}
else
{
AddUsedPos(rank, newCel);
direct = tryDirect;
return true;
2017-01-21 17:27:46 +01:00
}
}
else
{
if ( IsBlupiHere(newCel, false) )
2017-01-21 17:27:46 +01:00
{
// Si blupi immobile, comme si obstacle qq.
if ( m_blupi[m_blupiHere].goalCel.x == -1 ) continue;
newCel = cel;
action = ACTION_STOP;
direct = tryDirect;
return true;
2017-01-21 17:27:46 +01:00
}
else
{
AddUsedPos(rank, newCel);
direct = tryDirect;
return true;
2017-01-21 17:27:46 +01:00
}
}
}
}
}
return false;
2017-01-21 17:27:46 +01:00
}
// Cherche la meilleure direction pour atteindre un but.
bool CDecor::SearchBestPass(Sint32 rank, Sint32 &action)
2017-01-21 17:27:46 +01:00
{
Blupi iBlupi;
Sint32 i, j, direct;
2017-01-21 17:27:46 +01:00
POINT iCel, lCel, cel;
if ( m_blupi[rank].perso == 0 || // blupi ?
2017-02-12 00:44:46 +01:00
m_blupi[rank].perso == 7 || // électro ?
2017-01-21 17:27:46 +01:00
m_blupi[rank].perso == 8 || // disciple ?
(m_blupi[rank].perso == 4 && // robot ?
2017-02-12 00:44:46 +01:00
m_term.bHachRobot ) ) // robot sur dalles hachurées ?
2017-01-21 17:27:46 +01:00
{
if ( m_blupi[rank].busyDelay > 0 )
{
m_blupi[rank].busyDelay --;
if ( m_blupi[rank].busyDelay == 0 &&
m_blupi[rank].busyCount > 0 )
{
m_blupi[rank].busyCount --;
}
return false;
2017-01-21 17:27:46 +01:00
}
2017-02-12 00:44:46 +01:00
if ( CheminCherche(rank, action) ) // recherche futée selon DD ...
2017-01-21 17:27:46 +01:00
{
return true;
2017-01-21 17:27:46 +01:00
}
else
{
2017-02-12 00:44:46 +01:00
// Si la destination est occupée pendant une répétition,
// il faut attendre à l'infini !
2017-01-21 17:27:46 +01:00
if ( m_blupi[rank].repeatLevel != -1 &&
IsBlupiHereEx(m_blupi[rank].goalCel, rank, false) )
2017-01-21 17:27:46 +01:00
{
m_blupi[rank].busyCount ++;
}
2017-02-12 00:44:46 +01:00
m_blupi[rank].busyDelay = Random(8,12); // délai avant réessai
return false;
2017-01-21 17:27:46 +01:00
}
}
for ( j=0 ; j<7 ; j++ )
{
iBlupi = m_blupi[rank]; // sauvegarde blupi
// Essaye 7 coups en avance, pour voir.
iCel = m_blupi[rank].cel;
i = 0;
while ( true )
2017-01-21 17:27:46 +01:00
{
if ( !SearchBestBase(rank, action, cel, direct) ) break;
if ( action == ACTION_STOP ) // collision avec autre blupi ?
{
if ( i == 0 )
{
m_blupi[rank] = iBlupi; // restitue blupi
return false;
2017-01-21 17:27:46 +01:00
}
i = 7; // comme si ok pour 7 coups
break;
}
m_blupi[rank].cel = cel;
lCel = cel;
2017-02-12 00:44:46 +01:00
// Est-on revenu juste à côté de la position
// de départ ? Si oui, simplifie le mouvement.
2017-01-21 17:27:46 +01:00
if ( i > 1 &&
abs(m_blupi[rank].cel.x-iCel.x) <= 1 &&
abs(m_blupi[rank].cel.y-iCel.y) <= 1 )
{
direct = DirectSearch(iCel, cel);
if ( IsFreeDirect(iCel, direct, rank) )
{
m_blupi[rank].cel = iCel;
m_blupi[rank].sDirect = direct;
action = ACTION_MARCHE;
return true;
2017-01-21 17:27:46 +01:00
}
}
// A-t-on atteint le but ?
if ( cel.x == m_blupi[rank].goalCel.x &&
cel.y == m_blupi[rank].goalCel.y )
{
i = 7; // comme si ok pour 7 coups
break;
}
i ++;
if ( i >= 7 ) break;
}
m_blupi[rank] = iBlupi; // restitue blupi
if ( i == 0 ) return false;
2017-01-21 17:27:46 +01:00
if ( i == 7 )
{
SearchBestBase(rank, action, cel, direct);
m_blupi[rank].sDirect = direct;
return true;
2017-01-21 17:27:46 +01:00
}
AddUsedPos(rank, lCel); // bloque position ridicule
}
return false;
2017-01-21 17:27:46 +01:00
}
2017-02-12 00:44:46 +01:00
// Vérifie si un objet est utilisable pour travailler dessus.
2017-01-21 17:27:46 +01:00
// Le sol doit permettre d'aller aux 4 coins, et il ne doit
2017-02-12 00:44:46 +01:00
// pas y avoir un autre blupi que soi-même.
2017-01-21 17:27:46 +01:00
bool CDecor::IsWorkableObject(POINT cel, Sint32 rank)
2017-01-21 17:27:46 +01:00
{
if ( !IsFreeCelFloor(GetCel(cel,0,0), -1) ||
!IsFreeCelFloor(GetCel(cel,1,0), -1) ||
!IsFreeCelFloor(GetCel(cel,0,1), -1) ||
!IsFreeCelFloor(GetCel(cel,1,1), -1) ) return false;
2017-01-21 17:27:46 +01:00
if ( IsBlupiHereEx(GetCel(cel,0,0), rank, false) ||
IsBlupiHereEx(GetCel(cel,1,0), rank, false) ||
IsBlupiHereEx(GetCel(cel,0,1), rank, false) ||
IsBlupiHereEx(GetCel(cel,1,1), rank, false) ) return false;
2017-01-21 17:27:46 +01:00
if ( m_decor[cel.x/2][cel.y/2].fire > 0 &&
m_decor[cel.x/2][cel.y/2].fire < MoveMaxFire() ) return false;
2017-01-21 17:27:46 +01:00
return true;
2017-01-21 17:27:46 +01:00
}
// Cherche un autre objet pour continuer une action
// (comme par exemple abatre des arbres).
bool CDecor::SearchOtherObject(Sint32 rank, POINT initCel, Sint32 action,
Sint32 distMax, Sint32 channel,
Sint32 firstIcon1, Sint32 lastIcon1,
Sint32 firstIcon2, Sint32 lastIcon2,
POINT &foundCel, Sint32 &foundIcon)
2017-01-21 17:27:46 +01:00
{
Sint32 startx, starty, endx, endy;
Sint32 x, y, xx, yy;
Sint32 dist, min = distMax;
2017-01-21 17:27:46 +01:00
POINT cel;
bool bOK;
2017-01-21 17:27:46 +01:00
if ( firstIcon1 == 33 && lastIcon1 == 48 &&
firstIcon2 == 71 && lastIcon2 == 71 ) // cherche du fer ?
{
return SearchOtherDrapeau(rank, initCel, distMax,
foundCel, foundIcon);
}
initCel.x = (initCel.x/2)*2;
initCel.y = (initCel.y/2)*2;
startx = ((initCel.x-distMax/2)/2)*2;
endx = ((initCel.x+distMax/2)/2)*2;
starty = ((initCel.y-distMax/2)/2)*2;
endy = ((initCel.y+distMax/2)/2)*2;
if ( startx < 0 ) startx = 0;
if ( endx > MAXCELX ) endx = MAXCELX;
if ( starty < 0 ) starty = 0;
if ( endy > MAXCELY ) endy = MAXCELY;
if ( firstIcon2 == -1 && lastIcon2 == -1 )
{
firstIcon2 = 22222;
lastIcon2 = 22222;
}
for ( y=starty ; y<endy ; y+=2 )
{
for ( x=startx ; x<endx ; x+=2 )
{
bOK = false;
2017-01-21 17:27:46 +01:00
if ( channel == CHFLOOR )
{
if ( m_decor[x/2][y/2].floorChannel == channel &&
((m_decor[x/2][y/2].floorIcon >= firstIcon1 &&
m_decor[x/2][y/2].floorIcon <= lastIcon1 )||
(m_decor[x/2][y/2].floorIcon >= firstIcon2 &&
m_decor[x/2][y/2].floorIcon <= lastIcon2 ))&&
m_decor[x/2][y/2].objectChannel == -1 ) bOK = true;
2017-01-21 17:27:46 +01:00
}
else
{
if ( m_decor[x/2][y/2].objectChannel == channel &&
((m_decor[x/2][y/2].objectIcon >= firstIcon1 &&
m_decor[x/2][y/2].objectIcon <= lastIcon1 )||
(m_decor[x/2][y/2].objectIcon >= firstIcon2 &&
m_decor[x/2][y/2].objectIcon <= lastIcon2 )) ) bOK = true;
2017-01-21 17:27:46 +01:00
}
if ( bOK )
{
cel.x = x;
cel.y = y;
if ( BlupiIsGoalUsed(cel) ) continue;
if ( action == WM_ACTION_ABAT1 ||
action == WM_ACTION_BUILD1 ||
action == WM_ACTION_BUILD2 ||
action == WM_ACTION_BUILD3 ||
action == WM_ACTION_BUILD4 ||
action == WM_ACTION_BUILD5 ||
action == WM_ACTION_BUILD6 ||
action == WM_ACTION_ROC1 ||
action == WM_ACTION_MUR ||
action == WM_ACTION_PONTE ||
action == WM_ACTION_TOUR ||
action == WM_ACTION_BATEAUE ||
action == WM_ACTION_CULTIVE2 ||
action == WM_ACTION_DRAPEAU2 ||
action == WM_ACTION_DEPOSE )
{
if ( !IsWorkableObject(cel, rank) ) continue;
}
dist = abs(initCel.x-x) + abs(initCel.y-y);
if ( dist <= min )
{
min = dist;
xx = x;
yy = y;
}
}
}
}
if ( min == distMax ) return false;
2017-01-21 17:27:46 +01:00
foundCel.x = xx;
foundCel.y = yy;
if ( channel == CHFLOOR )
{
foundIcon = m_decor[xx/2][yy/2].floorIcon;
}
else
{
foundIcon = m_decor[xx/2][yy/2].objectIcon;
}
return true;
2017-01-21 17:27:46 +01:00
}
// Cherche un autre sol pouvant contenir du fer, pour y
// planter un drapeau.
bool CDecor::SearchOtherDrapeau(Sint32 rank, POINT initCel, Sint32 distMax,
POINT &foundCel, Sint32 &foundIcon)
2017-01-21 17:27:46 +01:00
{
Sint32 startx, starty, endx, endy, icon;
Sint32 x, y;
Sint32 dist, min = distMax;
2017-01-21 17:27:46 +01:00
POINT cel;
startx = ((initCel.x-distMax/2)/2)*2;
endx = ((initCel.x+distMax/2)/2)*2;
starty = ((initCel.y-distMax/2)/2)*2;
endy = ((initCel.y+distMax/2)/2)*2;
if ( startx < 0 ) startx = 0;
if ( endx > MAXCELX ) endx = MAXCELX;
if ( starty < 0 ) starty = 0;
if ( endy > MAXCELY ) endy = MAXCELY;
for ( y=starty ; y<endy ; y+=2 )
{
for ( x=startx ; x<endx ; x+=2 )
{
icon = m_decor[x/2][y/2].floorIcon;
if ( m_decor[x/2][y/2].objectIcon == -1 &&
((icon >= 33 && icon <= 48) || // terre ?
icon == 71 ) &&
2017-02-12 00:44:46 +01:00
!TestDrapeau(GetCel(x,y)) ) // pas encore sondé ?
2017-01-21 17:27:46 +01:00
{
cel.x = x;
cel.y = y;
if ( BlupiIsGoalUsed(cel) ) continue;
if ( !IsWorkableObject(cel, rank) ) continue;
dist = abs(initCel.x-x) + abs(initCel.y-y);
if ( dist <= min )
{
min = dist;
foundCel.x = x;
foundCel.y = y;
foundIcon = icon;
}
}
}
}
if ( min == distMax ) return false;
return true;
2017-01-21 17:27:46 +01:00
}
2017-02-12 00:44:46 +01:00
// Cherche un autre sol permettant de déposer du bois
2017-01-21 17:27:46 +01:00
// pour construire un bateau.
bool CDecor::SearchOtherBateau(Sint32 rank, POINT initCel, Sint32 distMax,
POINT &foundCel, Sint32 &foundIcon)
2017-01-21 17:27:46 +01:00
{
Sint32 startx, starty, endx, endy;
Sint32 x, y, direct;
Sint32 dist, min = distMax;
2017-01-21 17:27:46 +01:00
startx = ((initCel.x-distMax/2)/2)*2;
endx = ((initCel.x+distMax/2)/2)*2;
starty = ((initCel.y-distMax/2)/2)*2;
endy = ((initCel.y+distMax/2)/2)*2;
if ( startx < 0 ) startx = 0;
if ( endx > MAXCELX ) endx = MAXCELX;
if ( starty < 0 ) starty = 0;
if ( endy > MAXCELY ) endy = MAXCELY;
for ( y=starty ; y<endy ; y+=2 )
{
for ( x=startx ; x<endx ; x+=2 )
{
if ( !IsBuildBateau(GetCel(x,y), direct) ) continue;
dist = abs(initCel.x-x) + abs(initCel.y-y);
if ( dist <= min )
{
min = dist;
foundCel.x = x;
foundCel.y = y;
foundIcon = m_decor[x/2][y/2].floorIcon;
}
}
}
if ( min == distMax ) return false;
return true;
2017-01-21 17:27:46 +01:00
}
2017-02-12 00:44:46 +01:00
// Vérifie si l'objet peut être détruit par l'araignée.
2017-01-21 17:27:46 +01:00
bool CDecor::IsSpiderObject(Sint32 icon)
2017-01-21 17:27:46 +01:00
{
return ( icon == 60 || // tomates ?
icon == 92 || // poison ?
2017-02-12 00:44:46 +01:00
icon == 93 ); // piège ?
2017-01-21 17:27:46 +01:00
}
2017-02-12 00:44:46 +01:00
// Cherche un autre objet pour l'araignée.
2017-01-21 17:27:46 +01:00
bool CDecor::SearchSpiderObject(Sint32 rank, POINT initCel, Sint32 distMax,
POINT &foundCel, Sint32 &foundIcon)
2017-01-21 17:27:46 +01:00
{
Sint32 startx, starty, endx, endy;
Sint32 x, y;
Sint32 dist, min = distMax;
2017-01-21 17:27:46 +01:00
POINT cel;
startx = ((initCel.x-distMax/2)/2)*2;
endx = ((initCel.x+distMax/2)/2)*2;
starty = ((initCel.y-distMax/2)/2)*2;
endy = ((initCel.y+distMax/2)/2)*2;
if ( startx < 0 ) startx = 0;
if ( endx > MAXCELX ) endx = MAXCELX;
if ( starty < 0 ) starty = 0;
if ( endy > MAXCELY ) endy = MAXCELY;
for ( y=starty ; y<endy ; y+=2 )
{
for ( x=startx ; x<endx ; x+=2 )
{
if ( IsSpiderObject(m_decor[x/2][y/2].objectIcon) )
{
cel.x = x;
cel.y = y;
if ( IsBlupiHere(cel, false) ) continue;
2017-01-21 17:27:46 +01:00
dist = abs(initCel.x-x) + abs(initCel.y-y);
2017-02-12 00:44:46 +01:00
if ( m_decor[x/2][y/2].objectIcon == 93 && //piège ?
dist > 4 ) continue; // si piège loin -> ignore
2017-01-21 17:27:46 +01:00
if ( dist <= min )
{
min = dist;
foundCel.x = x+1;
foundCel.y = y+1; // +1 -> sur l'objet
foundIcon = m_decor[x/2][y/2].objectIcon;
}
}
}
}
if ( min == distMax ) return false;
2017-01-21 17:27:46 +01:00
return true;
2017-01-21 17:27:46 +01:00
}
2017-02-12 00:44:46 +01:00
// Vérifie si l'objet peut être détruit par le tracks.
2017-01-21 17:27:46 +01:00
bool CDecor::IsTracksObject(Sint32 icon)
2017-01-21 17:27:46 +01:00
{
return ( icon == 36 || // planches ?
icon == 44 || // pierres ?
icon == 60 || // tomates ?
icon == 63 || // oeufs ?
icon == 80 || // bouteille ?
icon == 85 || // dynamite ?
icon == 92 || // poison ?
2017-02-12 00:44:46 +01:00
icon == 93 || // piège ?
icon == 123 || // piège ?
2017-01-21 17:27:46 +01:00
icon == 125 || // mine ?
icon == 127 || // mine ?
(icon >= 81 && icon <= 84) || // fleurs ?
(icon >= 94 && icon <= 95) ); // fleurs ?
}
// Cherche un autre objet pour le tracks.
bool CDecor::SearchTracksObject(Sint32 rank, POINT initCel, Sint32 distMax,
POINT &foundCel, Sint32 &foundIcon)
2017-01-21 17:27:46 +01:00
{
Sint32 startx, starty, endx, endy, icon;
Sint32 x, y;
Sint32 dist, min = distMax;
2017-01-21 17:27:46 +01:00
//? POINT cel;
startx = ((initCel.x-distMax/2)/2)*2;
endx = ((initCel.x+distMax/2)/2)*2;
starty = ((initCel.y-distMax/2)/2)*2;
endy = ((initCel.y+distMax/2)/2)*2;
if ( startx < 0 ) startx = 0;
if ( endx > MAXCELX ) endx = MAXCELX;
if ( starty < 0 ) starty = 0;
if ( endy > MAXCELY ) endy = MAXCELY;
for ( y=starty ; y<endy ; y+=2 )
{
for ( x=startx ; x<endx ; x+=2 )
{
if ( IsTracksObject(m_decor[x/2][y/2].objectIcon) )
{
//? cel.x = x;
//? cel.y = y;
//? if ( BlupiIsGoalUsed(cel) ) continue;
//? if ( IsBlupiHere(cel, false) ) continue;
2017-01-21 17:27:46 +01:00
dist = abs(initCel.x-x) + abs(initCel.y-y);
if ( dist <= min )
{
min = dist;
foundCel.x = x+1;
foundCel.y = y+1; // +1 -> sur l'objet
foundIcon = m_decor[x/2][y/2].objectIcon;
}
}
}
}
2017-02-12 00:44:46 +01:00
// Le tracks peut écraser blupi.
2017-01-21 17:27:46 +01:00
for ( rank=0 ; rank<MAXBLUPI ; rank++ )
{
if ( m_blupi[rank].bExist &&
m_blupi[rank].perso == 0 && // blupi ?
2017-02-12 00:44:46 +01:00
m_blupi[rank].vehicule == 0 ) // à pied ?
2017-01-21 17:27:46 +01:00
{
//? if ( BlupiIsGoalUsed(m_blupi[rank].cel) ) continue;
x = m_blupi[rank].cel.x;
y = m_blupi[rank].cel.y;
icon = m_decor[x/2][y/2].objectIcon;
if ( icon == 113 || // maison ?
icon == 28 || icon == 29 || // laboratoire ?
icon == 119 || icon == 120 || // usine ?
icon == 121 || icon == 122 ) // mine de fer ?
{
continue;
}
dist = abs(initCel.x-x) + abs(initCel.y-y);
if ( dist <= min )
{
min = dist;
foundCel.x = x;
foundCel.y = y;
foundIcon = -1; // blupi (pas un objet) !
}
}
}
if ( min == distMax ) return false;
2017-01-21 17:27:46 +01:00
return true;
2017-01-21 17:27:46 +01:00
}
2017-02-12 00:44:46 +01:00
// Vérifie si l'objet peut être détruit par le robot.
2017-01-21 17:27:46 +01:00
bool CDecor::IsRobotObject(Sint32 icon)
2017-01-21 17:27:46 +01:00
{
return ( icon == 85 || // dynamite ?
2017-02-12 00:44:46 +01:00
icon == 93 || // piège ?
2017-01-21 17:27:46 +01:00
icon == 125 || // mine ?
icon == 127 ); // mine ?
}
// Cherche une autre action pour le robot.
// C'est ici qu'est contenue l'IA du robot !
bool CDecor::SearchRobotObject(Sint32 rank, POINT initCel, Sint32 distMax,
POINT &foundCel, Sint32 &foundIcon,
Sint32 &foundAction)
2017-01-21 17:27:46 +01:00
{
Sint32 startx, starty, endx, endy;
Sint32 x, y;
Sint32 dist, maxUsine, min = distMax;
Sint32 nbUsine[10];
Sint32 nbPerso[10];
Sint32 i, r, d, dd, icon, index, nb;
2017-01-21 17:27:46 +01:00
2017-02-12 00:44:46 +01:00
if ( m_term.bHachRobot ) // robot sur dalles hachurées ?
2017-01-21 17:27:46 +01:00
{
foundAction = WM_ACTION_GO;
return SearchOtherObject(rank, initCel, WM_ACTION_GO,
200, CHFLOOR,17,17,-1,-1,
foundCel, foundIcon);
}
initCel.x = (initCel.x/2)*2;
2017-02-12 00:44:46 +01:00
initCel.y = (initCel.y/2)*2; // bâtiments très espacés !
2017-01-21 17:27:46 +01:00
startx = ((initCel.x-distMax/2)/2)*2;
endx = ((initCel.x+distMax/2)/2)*2;
starty = ((initCel.y-distMax/2)/2)*2;
endy = ((initCel.y+distMax/2)/2)*2;
for ( i=0 ; i<10 ; i++ )
{
nbUsine[i] = 0;
}
if ( startx < 0 ) startx = 0;
if ( endx > MAXCELX ) endx = MAXCELX;
if ( starty < 0 ) starty = 0;
if ( endy > MAXCELY ) endy = MAXCELY;
for ( y=starty ; y<endy ; y+=2 )
{
for ( x=startx ; x<endx ; x+=2 )
{
icon = m_decor[x/2][y/2].objectIcon;
if ( icon == 99 ) nbUsine[0] ++; // recharge ?
if ( icon == 104 ) nbUsine[1] ++; // usine tracks ?
2017-02-12 00:44:46 +01:00
if ( icon == 100 ) nbUsine[2] ++; // usine araignée ?
2017-01-21 17:27:46 +01:00
if ( icon == 102 ) nbUsine[3] ++; // usine virus ?
if ( icon == 115 ) nbUsine[4] ++; // usine bombe ?
2017-02-12 00:44:46 +01:00
if ( icon == 17 ) nbUsine[5] ++; // usine électro ?
2017-01-21 17:27:46 +01:00
dist = abs(initCel.x-x) + abs(initCel.y-y);
2017-02-12 00:44:46 +01:00
if ( IsRobotObject(icon) && // piège/dynamite ?
dist <= 4 ) // très proche ?
2017-01-21 17:27:46 +01:00
{
if ( dist <= min )
{
min = dist;
foundCel.x = x+1;
foundCel.y = y+1; // +1 -> sur l'objet
foundIcon = m_decor[x/2][y/2].objectIcon;
}
}
}
}
if ( min < distMax )
{
2017-02-12 00:44:46 +01:00
foundAction = -1; // robot passe tout prèt d'un piège/dynamite
return true;
2017-01-21 17:27:46 +01:00
}
// Cherche l'usine la moins construite.
min = 999;
maxUsine = 0;
index = 0;
for ( i=0 ; i<6 ; i++ )
{
if ( nbUsine[i] < min )
{
min = nbUsine[i];
index = i;
}
if ( nbUsine[i] > maxUsine )
{
maxUsine = nbUsine[i];
}
}
//? if ( nbUsine[0] > 0 && // sation de recharge existe ?
//? m_blupi[rank].energy <= MAXENERGY/2 ) // peu de forces ?
//? {
//? index = 0; // station de recharge
//? goto search;
//? }
2017-02-12 00:44:46 +01:00
if ( min == 0 ) // encore une usine à construire ?
2017-01-21 17:27:46 +01:00
{
// Libre juste ici ?
if ( IsUsineBuild(rank, initCel) )
{
foundCel = initCel;
build:
if ( index == 0 ) foundAction = WM_ACTION_R_BUILD1; // recharge
if ( index == 1 ) foundAction = WM_ACTION_R_BUILD4; // tracks
2017-02-12 00:44:46 +01:00
if ( index == 2 ) foundAction = WM_ACTION_R_BUILD2; // araignée
2017-01-21 17:27:46 +01:00
if ( index == 3 ) foundAction = WM_ACTION_R_BUILD3; // virus
if ( index == 4 ) foundAction = WM_ACTION_R_BUILD5; // bombe
2017-02-12 00:44:46 +01:00
if ( index == 5 ) foundAction = WM_ACTION_R_BUILD6; // électro
return true;
2017-01-21 17:27:46 +01:00
}
// Cherche un emplacement libre.
for ( d=1 ; d<distMax/6 ; d++ )
{
x = initCel.x + d*6;
y = initCel.y - d*6;
for ( i=0 ; i<4 ; i++ ) // 4 directions
{
for ( dd=0 ; dd<=d ; dd++ )
{
2017-02-12 00:44:46 +01:00
if ( i == 0 ) x -= 6; // à gauche
2017-01-21 17:27:46 +01:00
if ( i == 1 ) y += 6; // descend
2017-02-12 00:44:46 +01:00
if ( i == 2 ) x += 6; // à droite
2017-01-21 17:27:46 +01:00
if ( i == 3 ) y -= 6; // monte
if ( IsUsineBuild(rank, GetCel(x,y)) )
{
foundCel.x = x;
foundCel.y = y;
goto build;
}
}
}
}
}
2017-02-12 00:44:46 +01:00
// Cherche l'ennemi le moins répandu.
2017-01-21 17:27:46 +01:00
for ( i=0 ; i<10 ; i++ )
{
nbPerso[i] = 0;
}
nb = 0;
for ( r=0 ; r<MAXBLUPI ; r++ )
{
if ( m_blupi[r].bExist )
{
nb ++;
if ( m_blupi[r].perso == 3 ) // tracks ?
{
nbPerso[0] += 1;
}
2017-02-12 00:44:46 +01:00
if ( m_blupi[r].perso == 1 ) // araignée ?
2017-01-21 17:27:46 +01:00
{
nbPerso[1] += 1;
}
if ( m_blupi[r].perso == 2 ) // virus ?
{
nbPerso[2] += 1;
}
if ( m_blupi[r].perso == 5 ) // bombe ?
{
nbPerso[3] += 2;
}
2017-02-12 00:44:46 +01:00
if ( m_blupi[r].perso == 7 ) // électro ?
2017-01-21 17:27:46 +01:00
{
nbPerso[4] += 2;
}
}
}
2017-02-12 00:44:46 +01:00
if ( nb > MAXBLUPI-10 ) return false; // rien si trop peuplé !
// Cherche l'ennemi le moins répandu.
2017-01-21 17:27:46 +01:00
min = 999;
index = 0;
for ( i=0 ; i<5 ; i++ )
{
if ( nbPerso[i] < min &&
nbUsine[i+1] != 0 ) // usine correspondante existe ?
{
min = nbPerso[i];
index = i+1;
}
}
if ( m_blupi[rank].energy <= MAXENERGY/2 ) // peu de forces ?
{
index = 0; // station de recharge
}
if ( m_skill >= 1 ) maxUsine *= 2; // 2 ennemis par batiment
2017-02-12 00:44:46 +01:00
if ( min >= maxUsine ) // assez peuplé ?
2017-01-21 17:27:46 +01:00
{
index = 0; // station de recharge
}
2017-02-12 00:44:46 +01:00
// Cherche l'usine pour fabriquer l'ennemi le moins rédandu.
2017-01-21 17:27:46 +01:00
//? search:
min = distMax;
for ( y=starty ; y<endy ; y+=2 )
{
for ( x=startx ; x<endx ; x+=2 )
{
icon = m_decor[x/2][y/2].objectIcon;
if ( (index == 0 && icon == 99) || // recharge ?
(index == 1 && icon == 104) || // tracks ?
2017-02-12 00:44:46 +01:00
(index == 2 && icon == 100) || // araignée ?
2017-01-21 17:27:46 +01:00
(index == 3 && icon == 102) || // virus ?
(index == 4 && icon == 115) || // bombe ?
2017-02-12 00:44:46 +01:00
(index == 5 && icon == 17) ) // électro ?
2017-01-21 17:27:46 +01:00
{
if ( IsUsineFree(rank, GetCel(x,y)) )
{
dist = abs(initCel.x-x) + abs(initCel.y-y);
if ( dist <= min )
{
min = dist;
foundCel.x = x;
foundCel.y = y; // dans l'usine
foundIcon = icon;
}
}
}
}
}
if ( min < distMax )
{
if ( index == 0 ) foundAction = WM_ACTION_R_MAKE1; // recharge
if ( index == 1 ) foundAction = WM_ACTION_R_MAKE4; // tracks
2017-02-12 00:44:46 +01:00
if ( index == 2 ) foundAction = WM_ACTION_R_MAKE2; // araignée
2017-01-21 17:27:46 +01:00
if ( index == 3 ) foundAction = WM_ACTION_R_MAKE3; // virus
if ( index == 4 ) foundAction = WM_ACTION_R_MAKE5; // bombe
2017-02-12 00:44:46 +01:00
if ( index == 5 ) foundAction = WM_ACTION_R_MAKE6; // électro
return true;
2017-01-21 17:27:46 +01:00
}
// Cherche l'usine la plus proche.
min = distMax;
for ( y=starty ; y<endy ; y+=2 )
{
for ( x=startx ; x<endx ; x+=2 )
{
icon = m_decor[x/2][y/2].objectIcon;
2017-02-12 00:44:46 +01:00
if ( (icon == 100 && nbPerso[1] <= maxUsine) || // araignée ?
2017-01-21 17:27:46 +01:00
(icon == 102 && nbPerso[2] <= maxUsine) || // virus ?
(icon == 104 && nbPerso[0] <= maxUsine) || // tracks ?
(icon == 115 && nbPerso[3] <= maxUsine) || // bombe ?
2017-02-12 00:44:46 +01:00
(icon == 17 && nbPerso[4] <= maxUsine) ) // électro ?
2017-01-21 17:27:46 +01:00
{
if ( IsUsineFree(rank, GetCel(x,y)) )
{
dist = abs(initCel.x-x) + abs(initCel.y-y);
if ( dist <= min )
{
min = dist;
foundCel.x = x;
foundCel.y = y; // dans l'usine
foundIcon = icon;
}
}
}
}
}
if ( min < distMax )
{
2017-02-12 00:44:46 +01:00
if ( foundIcon == 100 ) foundAction = WM_ACTION_R_MAKE2; // araignée
2017-01-21 17:27:46 +01:00
if ( foundIcon == 102 ) foundAction = WM_ACTION_R_MAKE3; // virus
if ( foundIcon == 104 ) foundAction = WM_ACTION_R_MAKE4; // tracks
if ( foundIcon == 115 ) foundAction = WM_ACTION_R_MAKE5; // bombe
2017-02-12 00:44:46 +01:00
if ( foundIcon == 17 ) foundAction = WM_ACTION_R_MAKE6; // électro
return true;
2017-01-21 17:27:46 +01:00
}
return false;
2017-01-21 17:27:46 +01:00
}
2017-02-12 00:44:46 +01:00
// Teste si un emplacement est ok pour bâtir une usine.
2017-01-21 17:27:46 +01:00
bool CDecor::IsUsineBuild(Sint32 rank, POINT cel)
2017-01-21 17:27:46 +01:00
{
Sint32 icon, channel;
Sint32 x, y;
2017-01-21 17:27:46 +01:00
2017-02-12 00:44:46 +01:00
// Pas sur les dalles hachurées !
2017-01-21 17:27:46 +01:00
GetFloor(cel, channel, icon);
if ( channel == CHFLOOR &&
(icon < 65 || icon > 67) ) return false;
2017-01-21 17:27:46 +01:00
for ( x=-1 ; x<3 ; x++ )
{
for ( y=-1 ; y<3 ; y++ )
{
if ( !IsFreeCel(GetCel(cel,x,y), rank) ||
IsBlupiHereEx(GetCel(cel,x,y), rank, false) )
2017-01-21 17:27:46 +01:00
{
return false;
2017-01-21 17:27:46 +01:00
}
}
}
return true;
2017-01-21 17:27:46 +01:00
}
// Teste s'il est possible d'entrer dans une usine.
2017-02-12 00:44:46 +01:00
// L'usine doit être libre devant (lieu de stationnement
2017-01-21 17:27:46 +01:00
// pour l'ennemi qui sera construit).
bool CDecor::IsUsineFree(Sint32 rank, POINT cel)
2017-01-21 17:27:46 +01:00
{
Sint32 channel, icon;
2017-01-21 17:27:46 +01:00
GetObject(cel, channel, icon);
2017-02-12 00:44:46 +01:00
if ( channel == CHOBJECT && icon == 115 ) // usine à bombes ?
2017-01-21 17:27:46 +01:00
{
return ( !IsBlupiHereEx(GetCel(cel,0,1), rank, false) &&
!IsBlupiHereEx(GetCel(cel,1,1), rank, false) &&
!IsBlupiHereEx(GetCel(cel,2,1), rank, false) &&
!IsBlupiHereEx(GetCel(cel,3,1), rank, false) );
2017-01-21 17:27:46 +01:00
}
return ( !IsBlupiHereEx(GetCel(cel,0,1), rank, false) &&
!IsBlupiHereEx(GetCel(cel,1,1), rank, false) &&
!IsBlupiHereEx(GetCel(cel,2,0), rank, false) &&
!IsBlupiHereEx(GetCel(cel,2,1), rank, false) &&
(!IsBlupiHereEx(GetCel(cel,3,0), rank, false)||
!IsBlupiHereEx(GetCel(cel,3,1), rank, false)) );
2017-01-21 17:27:46 +01:00
}
2017-02-12 00:44:46 +01:00
// Vérifie si l'objet peut être détruit par une bombe.
2017-01-21 17:27:46 +01:00
bool CDecor::IsBombeObject(Sint32 icon)
2017-01-21 17:27:46 +01:00
{
return ( icon == 36 || // planches ?
icon == 61 || // cabane ?
icon == 121 || icon == 122 || // mine de fer ?
(icon >= 65 && icon <= 71) || // palissade ?
2017-02-12 00:44:46 +01:00
icon == 93 || // piège ?
2017-01-21 17:27:46 +01:00
icon == 117 ); // bateau ?
}
// Cherche un autre objet pour une bombe.
bool CDecor::SearchBombeObject(Sint32 rank, POINT initCel, Sint32 distMax,
POINT &foundCel, Sint32 &foundIcon)
2017-01-21 17:27:46 +01:00
{
Sint32 startx, starty, endx, endy;
Sint32 x, y;
Sint32 dist, min = distMax;
2017-01-21 17:27:46 +01:00
POINT cel;
startx = ((initCel.x-distMax/2)/2)*2;
endx = ((initCel.x+distMax/2)/2)*2;
starty = ((initCel.y-distMax/2)/2)*2;
endy = ((initCel.y+distMax/2)/2)*2;
if ( startx < 0 ) startx = 0;
if ( endx > MAXCELX ) endx = MAXCELX;
if ( starty < 0 ) starty = 0;
if ( endy > MAXCELY ) endy = MAXCELY;
for ( y=starty ; y<endy ; y+=2 )
{
for ( x=startx ; x<endx ; x+=2 )
{
if ( IsBombeObject(m_decor[x/2][y/2].objectIcon) )
{
cel.x = x;
cel.y = y;
if ( IsBlupiHere(cel, false) ) continue;
2017-01-21 17:27:46 +01:00
dist = abs(initCel.x-x) + abs(initCel.y-y);
2017-02-12 00:44:46 +01:00
if ( m_decor[x/2][y/2].objectIcon == 93 && //piège ?
dist > 8 ) continue; // si piège loin -> ignore
2017-01-21 17:27:46 +01:00
if ( dist <= min )
{
min = dist;
foundCel.x = x+1;
foundCel.y = y+1; // +1 -> sur l'objet
foundIcon = m_decor[x/2][y/2].objectIcon;
}
}
}
}
if ( min == distMax ) return false;
2017-01-21 17:27:46 +01:00
return true;
2017-01-21 17:27:46 +01:00
}
2017-02-12 00:44:46 +01:00
// Cherche un autre objet pour un électro.
2017-01-21 17:27:46 +01:00
bool CDecor::SearchElectroObject(Sint32 rank, POINT initCel, Sint32 distMax,
POINT &foundCel, Sint32 &foundIcon)
2017-01-21 17:27:46 +01:00
{
Sint32 startx, starty, endx, endy;
Sint32 x, y, i, d, dd, r;
Sint32 dist, min = distMax;
2017-01-21 17:27:46 +01:00
POINT cel;
startx = ((initCel.x-10/2)/2)*2;
endx = ((initCel.x+10/2)/2)*2;
starty = ((initCel.y-10/2)/2)*2;
endy = ((initCel.y+10/2)/2)*2;
if ( startx < 0 ) startx = 0;
if ( endx > MAXCELX ) endx = MAXCELX;
if ( starty < 0 ) starty = 0;
if ( endy > MAXCELY ) endy = MAXCELY;
for ( y=starty ; y<endy ; y+=2 )
{
for ( x=startx ; x<endx ; x+=2 )
{
2017-02-12 00:44:46 +01:00
if ( m_decor[x/2][y/2].objectIcon == 93 ) // piège ?
2017-01-21 17:27:46 +01:00
{
cel.x = x;
cel.y = y;
if ( IsBlupiHere(cel, false) ) continue;
2017-01-21 17:27:46 +01:00
dist = abs(initCel.x-x) + abs(initCel.y-y);
if ( dist <= 4 )
{
min = dist;
foundCel.x = x+1;
foundCel.y = y+1; // +1 -> sur l'objet
foundIcon = m_decor[x/2][y/2].objectIcon;
}
}
}
}
if ( min <= 4 ) return true;
2017-01-21 17:27:46 +01:00
min = distMax;
for ( r=0 ; r<MAXBLUPI ; r++ )
{
if ( m_blupi[r].bExist &&
m_blupi[r].perso == 0 && // blupi ?
m_blupi[r].goalAction != WM_ACTION_ELECTRO )
{
//? if ( BlupiIsGoalUsed(m_blupi[r].cel) ) continue;
x = m_blupi[r].cel.x;
y = m_blupi[r].cel.y;
dist = abs(initCel.x-x) + abs(initCel.y-y);
if ( dist <= distMax/2 && dist <= min )
{
min = dist;
foundCel.x = x;
foundCel.y = y;
foundIcon = -1; // blupi (pas un objet) !
}
}
}
if ( min == distMax ) return false;
2017-01-21 17:27:46 +01:00
// Cherche un emplacement libre.
for ( d=1 ; d<distMax/2 ; d++ )
{
x = foundCel.x + d;
y = foundCel.y - d;
for ( i=0 ; i<4 ; i++ ) // 4 directions
{
for ( dd=0 ; dd<=d ; dd++ )
{
2017-02-12 00:44:46 +01:00
if ( i == 0 ) x -= 1; // à gauche
2017-01-21 17:27:46 +01:00
if ( i == 1 ) y += 1; // descend
2017-02-12 00:44:46 +01:00
if ( i == 2 ) x += 1; // à droite
2017-01-21 17:27:46 +01:00
if ( i == 3 ) y -= 1; // monte
if ( IsFreeCel(GetCel(x,y), rank) &&
!IsBlupiHereEx(GetCel(x,y), rank, false) )
2017-01-21 17:27:46 +01:00
{
foundCel.x = x;
foundCel.y = y;
return true;
2017-01-21 17:27:46 +01:00
}
}
}
}
return false;
2017-01-21 17:27:46 +01:00
}
2017-02-12 00:44:46 +01:00
// Teste si une position est très proche du feu.
// Si oui, retourne true.
2017-01-21 17:27:46 +01:00
bool CDecor::IsFireCel(POINT cel)
2017-01-21 17:27:46 +01:00
{
Sint32 x, y;
2017-01-21 17:27:46 +01:00
POINT test;
cel.x = (cel.x/2)*2;
cel.y = (cel.y/2)*2;
for ( x=-2 ; x<3 ; x+=2 )
{
for ( y=-2 ; y<3 ; y+=2 )
{
test.x = cel.x + x;
test.y = cel.y + y;
if ( !IsValid(test) ) continue;
if ( m_decor[test.x/2][test.y/2].fire > 0 &&
m_decor[test.x/2][test.y/2].fire < MoveMaxFire() ) return true;
2017-01-21 17:27:46 +01:00
}
}
return false;
2017-01-21 17:27:46 +01:00
}
2017-02-12 00:44:46 +01:00
// Teste si une position est très proche d'un virus.
// Si oui, retourne true.
2017-01-21 17:27:46 +01:00
bool CDecor::IsVirusCel(POINT cel)
2017-01-21 17:27:46 +01:00
{
Sint32 rank;
2017-01-21 17:27:46 +01:00
for ( rank=0 ; rank<MAXBLUPI ; rank++ )
{
if ( m_blupi[rank].bExist &&
m_blupi[rank].perso == 2 ) // virus ?
{
if ( cel.x >= m_blupi[rank].cel.x-1 &&
cel.x <= m_blupi[rank].cel.x+1 &&
cel.y >= m_blupi[rank].cel.y-1 &&
cel.y <= m_blupi[rank].cel.y+1 ) return true;
2017-01-21 17:27:46 +01:00
}
}
return false;
2017-01-21 17:27:46 +01:00
}
2017-02-12 00:44:46 +01:00
// Regarde s'il est possible de construire un pont à partir
// d'une cellule donnée (cel).
2017-01-21 17:27:46 +01:00
// Retourne 0 si c'est possible, ou une erreur autrement !
Sint32 CDecor::IsBuildPont(POINT &cel, Sint32 &iconBuild)
2017-01-21 17:27:46 +01:00
{
POINT vector, test;
Sint32 i, channel, icon, p1, p2, p3, r1, r2, nb, rest;
Sint32 error = ERROR_MISC;
2017-01-21 17:27:46 +01:00
for ( i=0 ; i<4 ; i++ )
{
vector.x = 0;
vector.y = 0;
GetFloor(GetCel(cel,+2,0), channel, icon);
if ( i == 0 &&
channel == CHFLOOR &&
(icon == 2 || icon == 59) ) // rivage ?
{
vector.x = +1;
vector.y = 0;
p1 = 59;
p2 = 60;
p3 = 61;
r1 = 2;
r2 = 4;
}
GetFloor(GetCel(cel,-2,0), channel, icon);
if ( i == 1 &&
channel == CHFLOOR &&
(icon == 4 || icon == 61) ) // rivage ?
{
vector.x = -1;
vector.y = 0;
p1 = 61;
p2 = 60;
p3 = 59;
r1 = 4;
r2 = 2;
}
GetFloor(GetCel(cel,0,+2), channel, icon);
if ( i == 2 &&
channel == CHFLOOR &&
(icon == 3 || icon == 62) ) // rivage ?
{
vector.x = 0;
vector.y = +1;
p1 = 62;
p2 = 63;
p3 = 64;
r1 = 3;
r2 = 5;
}
GetFloor(GetCel(cel,0,-2), channel, icon);
if ( i == 3 &&
channel == CHFLOOR &&
(icon == 5 || icon == 64) ) // rivage ?
{
vector.x = 0;
vector.y = -1;
p1 = 64;
p2 = 63;
p3 = 62;
r1 = 5;
r2 = 3;
}
if ( vector.x == 0 && vector.y == 0 ) continue;
// Avance tant que le pont existe.
test = cel;
nb = 0;
do
{
test.x += vector.x*2;
test.y += vector.y*2;
if ( test.x < 0 || test.x >= MAXCELX ||
test.y < 0 || test.y >= MAXCELY ) break;
if ( !GetFloor(test, channel, icon) ) continue;
nb ++;
}
while ( icon == p1 || icon == p2 );
test.x -= vector.x*2;
test.y -= vector.y*2;
if ( icon == p3 )
{
error = ERROR_PONTTERM;
continue;
}
if ( nb == 1 ) iconBuild = p1;
else iconBuild = p2;
2017-02-12 00:44:46 +01:00
// Avance jusqu'à la rive opposée.
2017-01-21 17:27:46 +01:00
rest = 0;
do
{
test.x += vector.x*2;
test.y += vector.y*2;
if ( test.x < 0 || test.x >= MAXCELX ||
test.y < 0 || test.y >= MAXCELY ) break;
if ( !GetFloor(test, channel, icon) ) continue;
rest ++;
}
while ( icon == r1 || icon == 14 );
if ( icon == r2 && rest == 1 ) iconBuild = p3;
if ( icon != r2 && icon != p2 && icon != p3 )
{
error = ERROR_PONTOP;
continue;
}
cel.x += vector.x*2*nb;
cel.y += vector.y*2*nb;
return 0; // ok
}
return error;
}
2017-02-12 00:44:46 +01:00
// Regarde s'il est possible de construire un bateau à partir
// d'une cellule donnée (cel).
2017-01-21 17:27:46 +01:00
bool CDecor::IsBuildBateau(POINT cel, Sint32 &direct)
2017-01-21 17:27:46 +01:00
{
Sint32 fChannel, fIcon;
Sint32 oChannel, oIcon;
2017-01-21 17:27:46 +01:00
GetFloor (GetCel(cel,+2,0), fChannel, fIcon);
GetObject(GetCel(cel,+2,0), oChannel, oIcon);
if ( fChannel == CHFLOOR && fIcon == 2 && // rivage ?
oChannel == -1 && oIcon == -1 )
{
direct = DIRECT_E;
return true;
2017-01-21 17:27:46 +01:00
}
GetFloor (GetCel(cel,-2,0), fChannel, fIcon);
GetObject(GetCel(cel,-2,0), oChannel, oIcon);
if ( fChannel == CHFLOOR && fIcon == 4 && // rivage ?
oChannel == -1 && oIcon == -1 )
{
direct = DIRECT_O;
return true;
2017-01-21 17:27:46 +01:00
}
GetFloor (GetCel(cel,0,+2), fChannel, fIcon);
GetObject(GetCel(cel,0,+2), oChannel, oIcon);
if ( fChannel == CHFLOOR && fIcon == 3 && // rivage ?
oChannel == -1 && oIcon == -1 )
{
direct = DIRECT_S;
return true;
2017-01-21 17:27:46 +01:00
}
GetFloor (GetCel(cel,0,-2), fChannel, fIcon);
GetObject(GetCel(cel,0,-2), oChannel, oIcon);
if ( fChannel == CHFLOOR && fIcon == 5 && // rivage ?
oChannel == -1 && oIcon == -1 )
{
direct = DIRECT_N;
return true;
2017-01-21 17:27:46 +01:00
}
direct = -1;
return false;
2017-01-21 17:27:46 +01:00
}
2017-02-12 00:44:46 +01:00
// Vide toutes les positions visitées.
2017-01-21 17:27:46 +01:00
void CDecor::InitDrapeau()
{
Sint32 i;
2017-01-21 17:27:46 +01:00
for ( i=0 ; i<MAXLASTDRAPEAU ; i++ )
{
m_lastDrapeau[i].x = -1;
m_lastDrapeau[i].y = -1;
}
}
2017-02-12 00:44:46 +01:00
// Mémorise une cellule visitée (ne contenant pas de fer).
2017-01-21 17:27:46 +01:00
void CDecor::AddDrapeau(POINT cel)
{
Sint32 i;
2017-01-21 17:27:46 +01:00
2017-02-12 00:44:46 +01:00
if ( TestDrapeau(cel) ) return; // déjà dans la liste
2017-01-21 17:27:46 +01:00
for ( i=MAXLASTDRAPEAU-1 ; i>0 ; i-- )
{
m_lastDrapeau[i] = m_lastDrapeau[i-1];
}
m_lastDrapeau[0] = cel;
}
2017-02-12 00:44:46 +01:00
// Supprime une cellule visitée (ne contenant pas de fer).
2017-01-21 17:27:46 +01:00
void CDecor::SubDrapeau(POINT cel)
{
Sint32 i;
2017-01-21 17:27:46 +01:00
for ( i=0 ; i<MAXLASTDRAPEAU ; i++ )
{
if ( cel.x == m_lastDrapeau[i].x &&
cel.y == m_lastDrapeau[i].y )
{
m_lastDrapeau[i].x = -1;
m_lastDrapeau[i].y = -1;
}
}
}
2017-02-12 00:44:46 +01:00
// Teste si une cellule a déjà été visitée.
2017-01-21 17:27:46 +01:00
bool CDecor::TestDrapeau(POINT cel)
2017-01-21 17:27:46 +01:00
{
Sint32 i;
2017-01-21 17:27:46 +01:00
for ( i=0 ; i<MAXLASTDRAPEAU ; i++ )
{
if ( cel.x == m_lastDrapeau[i].x &&
cel.y == m_lastDrapeau[i].y ) return true;
2017-01-21 17:27:46 +01:00
}
return false;
2017-01-21 17:27:46 +01:00
}