- Код: Выделить всё
bool IsReplaceable( int ObjType )
{
// bool IsArt = ( ObjType == 65 || ObjType == 66 || ObjType == 67 || ObjType == 68 || ObjType == 69 || ObjType == 5 );
bool IsArt = ( ObjType == 5 );
bool IsRes = ( ObjType == 79 );
bool IsShc = ( ObjType == 81 );
bool IsScr = ( ObjType == 93 );
bool IsChe = ( ObjType == 101 );
bool IsPan = ( ObjType == 6 );
bool IsOrh = ( ObjType == 12 ); //Костер
return ( IsArt || IsRes || IsShc || IsScr || IsChe || IsPan );
}
void ReplaceObject( _Object_ *obj, int addX, int addY, int CurObjSubtype ){
_GameMap_ *map = &o_GameMgr->Map;
int mapSize = o_GameMgr->GetMapWidth();
int CurX = obj->x;
int CurY = obj->y;
int ofsetX = CurX+addX;
int ofsetY = CurY+addY;
if ( CurX >= mapSize-1 || CurY >= mapSize-1 ) return;
_List_<_Object_> *objects = &map->Objects;
_List_<_Template_> *templates = &map->Templates;
for (_Object_ *objReplace = objects->Data; objReplace < objects->EndData; objReplace++)
{
if ( objReplace->x >= mapSize-1 || objReplace->y >= mapSize-1 ) continue;
if ( objReplace->x <= 0 || objReplace->y <= 0 ) continue;
_Template_ *tempR = &templates->Data[objReplace->template_id];
bool IsX = false, IsY = false;
if ( addX != 0 ) {
IsY = ( objReplace->y == CurY-1 || objReplace->y == CurY || objReplace->y == CurY+1 );
IsX = ( objReplace->x == ofsetX );
}
else if ( addY != 0 ) {
IsX = ( objReplace->x == CurX-1 || objReplace->x == CurX || objReplace->x == CurX+1 );
IsY = ( objReplace->y == ofsetY );
}
if ( IsX && IsY && IsReplaceable( tempR->ObjType ) ) {
obj->x = objReplace->x;
obj->y = objReplace->y;
//continue;
objReplace->x = CurX;
objReplace->y = CurY;
return;
}
}
}
int __stdcall shiftBlocks(LoHook* h, HookContext* c)
{
_GameMap_ *map = &o_GameMgr->Map;
_List_<_Template_> *templates = &map->Templates;
_List_<_Object_> *objects = &map->Objects;
_MapItem_ *MapItemLeft, *MapItemRight, *MapItemUp, *MapItemDown, *MapItemCur;
for (_Object_ *obj = objects->Data; obj < objects->EndData; obj++) {
_Template_ *temp = &templates->Data[obj->template_id];
MapItemCur = map->GetItem( obj->x, obj->y, obj->z );
if (temp->ObjType != 54) continue;
MapItemRight = map->GetItem( obj->x+1, obj->y, obj->z);
MapItemLeft = map->GetItem( obj->x-1, obj->y, obj->z);
MapItemUp = map->GetItem( obj->x, obj->y-1, obj->z);
MapItemDown = map->GetItem( obj->x, obj->y+1, obj->z);
if ( MapItemRight->road ) {
ReplaceObject( obj, -1, 0, temp->ObjSubtype );
}
else if ( MapItemLeft->road ) {
ReplaceObject( obj, +1, 0, temp->ObjSubtype );
}
else if ( MapItemUp->road ) {
ReplaceObject( obj, 0, +1, temp->ObjSubtype);
}
else if (MapItemDown->road ) {
ReplaceObject( obj, 0, -1, temp->ObjSubtype);
}
}
return EXEC_DEFAULT;
}
_PI->WriteLoHook(0x4FDF64, shiftBlocks);
Все работает как задумано.
Вот только иногда вылетает создание карты на этих строчках
- Код: Выделить всё
obj->x = objReplace->x;
obj->y = objReplace->y;
Никак не могу понять в чем проблема.