Opis forum
Kod jest w 100% by me !
W map.cpp nad:
std::list<Position> Map::getPathTo(Creature *creature, Position start, Position to,
dodaj
std::list<Position> Map::getPathToEx(Creature *creature, Position start, Position to, bool creaturesBlock /*=true*/, bool ignoreMoveableBlockingItems /*= false*/, int maxNodSize /*= 100*/){ std::list<Position> path; /* if(start.z != to.z) return path; */ AStarNodes nodes; AStarNode* found = NULL; int z = start.z; AStarNode* startNode = nodes.createOpenNode(); startNode->parent = NULL; startNode->h = 0; startNode->x = start.x; startNode->y = start.y; while(!found && nodes.countClosedNodes() < (unsigned long)maxNodSize){ AStarNode* current = nodes.getBestNode(); if(!current) return path; //no path nodes.closeNode(current); for(int dx=-1; dx <= 1; dx++){ for(int dy=-1; dy <= 1; dy++){ if(1 == 1/*std::abs(dx) != std::abs(dy)*/){ int x = current->x + dx; int y = current->y + dy; if(dx == -1 && dy == -1) { Tile *ctest1 = getTile(x+1, y, z); Tile *ctest2 = getTile(x, y+1, z); if(ctest1 && ctest2) { ReturnValue ctest1er = ctest1->isBlocking(BLOCK_SOLID | BLOCK_PATHFIND, !creaturesBlock, ignoreMoveableBlockingItems); ReturnValue ctest2er = ctest2->isBlocking(BLOCK_SOLID | BLOCK_PATHFIND, !creaturesBlock, ignoreMoveableBlockingItems); if(ctest1er == RET_CREATUREBLOCK && ctest1->getCreature() == creature && ctest1->creatures.size() == 1) ctest1er = RET_NOERROR; if(ctest2er == RET_CREATUREBLOCK && ctest2->getCreature() == creature && ctest2->creatures.size() == 1) ctest2er = RET_NOERROR; if(ctest1er == RET_NOERROR || ctest2er == RET_NOERROR) { continue; } } } if(dx == 1 && dy == -1) { Tile *ctest1 = getTile(x-1, y, z); Tile *ctest2 = getTile(x, y+1, z); if(ctest1 && ctest2) { ReturnValue ctest1er = ctest1->isBlocking(BLOCK_SOLID | BLOCK_PATHFIND, !creaturesBlock, ignoreMoveableBlockingItems); ReturnValue ctest2er = ctest2->isBlocking(BLOCK_SOLID | BLOCK_PATHFIND, !creaturesBlock, ignoreMoveableBlockingItems); if(ctest1er == RET_CREATUREBLOCK && ctest1->getCreature() == creature && ctest1->creatures.size() == 1) ctest1er = RET_NOERROR; if(ctest2er == RET_CREATUREBLOCK && ctest2->getCreature() == creature && ctest2->creatures.size() == 1) ctest2er = RET_NOERROR; if(ctest1er == RET_NOERROR || ctest2er == RET_NOERROR) { continue; } } } if(dx == 1 && dy == 1) { Tile *ctest1 = getTile(x-1, y, z); Tile *ctest2 = getTile(x, y-1, z); if(ctest1 && ctest2) { ReturnValue ctest1er = ctest1->isBlocking(BLOCK_SOLID | BLOCK_PATHFIND, !creaturesBlock, ignoreMoveableBlockingItems); ReturnValue ctest2er = ctest2->isBlocking(BLOCK_SOLID | BLOCK_PATHFIND, !creaturesBlock, ignoreMoveableBlockingItems); if(ctest1er == RET_CREATUREBLOCK && ctest1->getCreature() == creature && ctest1->creatures.size() == 1) ctest1er = RET_NOERROR; if(ctest2er == RET_CREATUREBLOCK && ctest2->getCreature() == creature && ctest2->creatures.size() == 1) ctest2er = RET_NOERROR; if(ctest1er == RET_NOERROR || ctest2er == RET_NOERROR) { continue; } } } if(dx == -1 && dy == 1) { Tile *ctest1 = getTile(x-1, y, z); Tile *ctest2 = getTile(x, y+1, z); if(ctest1 && ctest2) { ReturnValue ctest1er = ctest1->isBlocking(BLOCK_SOLID | BLOCK_PATHFIND, !creaturesBlock, ignoreMoveableBlockingItems); ReturnValue ctest2er = ctest2->isBlocking(BLOCK_SOLID | BLOCK_PATHFIND, !creaturesBlock, ignoreMoveableBlockingItems); if(ctest1er == RET_CREATUREBLOCK && ctest1->getCreature() == creature && ctest1->creatures.size() == 1) ctest1er = RET_NOERROR; if(ctest2er == RET_CREATUREBLOCK && ctest2->getCreature() == creature && ctest2->creatures.size() == 1) ctest2er = RET_NOERROR; if(ctest1er == RET_NOERROR || ctest2er == RET_NOERROR) { continue; } } } Tile *t = getTile(x, y, z); if(t) { ReturnValue ret = t->isBlocking(BLOCK_SOLID | BLOCK_PATHFIND, !creaturesBlock, ignoreMoveableBlockingItems); if(ret == RET_CREATUREBLOCK && t->getCreature() == creature && t->creatures.size() == 1) ret = RET_NOERROR; if(ret != RET_NOERROR) { continue; } } else continue; if(!nodes.isInList(x,y)){ AStarNode* n = nodes.createOpenNode(); if(n){ n->x = x; n->y = y; n->h = abs(n->x - to.x)*abs(n->x - to.x) + abs(n->y - to.y)*abs(n->y - to.y); n->parent = current; if(x == to.x && y == to.y){ found = n; } } } /* else{ if(current->g + 1 < child->g) child->parent = current; child->g=current->g+1; }*/ } } } } //cleanup the mess while(found){ Position p; p.x = found->x; p.y = found->y; p.z = z; path.push_front(p); found = found->parent; } return path; }
Map.h pod:
std::list<Position> getPathTo(Creature* creature, Position start, Position to, bool creaturesBlock = true, bool ignoreMoveableBlockingItems
dodaj
std::list<Position> getPathToEx(Creature* creature, Position start, Position to, bool creaturesBlock = true, bool ignoreMoveableBlockingItems
w monster.cpp zamień:
route = game->map->getPathTo(this, this->pos, moveToPos, true, mType->canPushItems);
na
route = game->map->getPathToEx(this, this->pos, moveToPos, true, mType->canPushItems);
Offline
Zielony
ja tez zaczolem pisac w c++ tylko nie mam kompilatora napiszcie jakas stronke gdzie mozna go sciagnac
Offline
Grubass Zioom napisał:
ja tez zaczolem pisac w c++ tylko nie mam kompilatora napiszcie jakas stronke gdzie mozna go sciagnac
Grubass nie to, że cię wyśmiewam, ale ty nawet nie umiesz zrobić prostej gierki to napewno piszesz w c++?
Offline
Grubass Zioom napisał:
ja tez zaczolem pisac w c++ tylko nie mam kompilatora napiszcie jakas stronke gdzie mozna go sciagnac
Buahahahahahaha Grybass ściemniać to ja też potrafie
Hmm... Ja nie chce potworów na skos!! Bo będą szybko chdozić
Offline