void VirusViewer::debugMove(Vector position) { //Tile *tile = map->getTile(position); //map->findAllPathsTo(tile->hx, tile->hy, 10); Tile *tile = map->getTile(position); if (tile->getType() != TILE_EMPTY) { Cell *cell = tile->getCell(); if (cell) { cell->startCloning(FACTION_ENEMY, randomGenerator->getIntNumberBetween(0, 65535)); //cell->startCloning(FACTION_ENEMY, 2); } } else { /* Virus *virus = new Virus(FACTION_ENEMY, randomGenerator->getIntNumberBetween(0, 65535), true); */ Virus *virus = new Virus(FACTION_ENEMY, 920, true); virus->setPosition(position); virus->setOrientation(0.0); double rotateSpeed = randomGenerator->getRealNumberBetween(-1.5, 1.5); virus->setRotateSpeed(rotateSpeed); Entity *entity = (Entity *)virus; map->addEntity(entity); } }
string virusTest() { vector<File*> fls; Folder * f = new Folder("test"); File * file = new File(); Virus * v = new Virus(); v->type = Virus::CREATING; v->nextHarm = 0; file->setVirus(v); f->addFile(file); f->getAllFilesRecursively(fls); if(fls.size() != 1) return "file count mismatch 1"; v->update(f); fls.clear(); f->getAllFilesRecursively(fls); if(fls.size() != 2) return "file count mismatch 2"; v->type = Virus::ERASING; v->nextHarm = 0; v->update(f); fls.clear(); f->getAllFilesRecursively(fls); if(fls.size() != 2) return "file count mismatch 3"; delete f; return ""; }
void Tile::notifyMovement(const std::deque<Tile *> &path, int delay) { std::list<Entity *>::iterator it; for (it = entities.begin(); it != entities.end(); it++) { Entity *entity = (*it); if (entity->isVirus()) { Virus *virus = (Virus *)entity; virus->setPath(path, delay); } } }
bool RandomOfficer::advance() { NotifySuperiors("Issuing orders for troops."); for (vector<int>::iterator u = _employedUnits.begin(); u != _employedUnits.end(); u++) { _TakeNotes("Determining orders for virus ID "<<(*u)); Virus *v = _ai->locateVirus(*u); if (!v) { NotifySuperiors(string("Bad employee id: ")+int_str(*u)); continue; } int x = v->x(); int y = v->y(); int dir = rand()%2; int dist = (rand()%3)-1; if (dir == 0) { x += dist; } else { y += dist; } // Keep choosing until you get one that's not off the map. // getTileAtLocation() doesn't do any bounds checking. // if the tile you want to move to is NOT a wall or a base. int rand_limit = 100; int tries = 0; while (!( (x >= 0 && x<_ai->width()) && (y >= 0 && y<_ai->height()) && (_ai->getTileAtLocation(x,y).owner() != 3) && (_ai->_map.at(x,y) != OPBASE) && (_ai->_map.at(x,y) != MYBASE) ) ) { if (tries++ > rand_limit) break; int dir = rand()%2; int dist = (rand()%3)-1; if (dir == 0) { x = v->x() + dist; } else { y = v->y() + dist; } } if (tries > rand_limit) continue; // Don't try anything if this happens. _NotifySuperiors("Sending virus to "<<Point(x,y)<<":"<<v); // Move the virus (if it's going somewhere--the game complains if you // attempt to move() it to the same location). if ( x != v->x() || y != v->y() ) v->move(x,y); } return Officer::advance(); }
string fileTest() { File * f = new File(); if(f->getName() == "") return "filename gen failed"; f->setCompressed(true); if(f->getSize() >= f->getRealSize()) return "compression failed"; Virus * virus = new Virus(); f->setVirus(virus); delete f; if(virus->isAlive()) return "virus survived after file deletion"; return ""; }
Sequence* GameObjectFactory::createVirusPatternSpawnActionWithPatternTypeAndPosition(BattleField *parent, CreateObjectType virusType, VirusSpawnPatternType patternType, Vec2 rootPos) { auto data = JSONPacker::unpackVirusSpawnPattern(json, patternType); Vector<cocos2d::FiniteTimeAction *> arrayOfActions; for (auto pos : data.positions) { auto callfunc = CallFunc::create([&, rootPos, pos, parent, virusType]() { Virus* virus = static_cast<Virus*>(this->createGameObjectByType(virusType)); virus->setPosition(rootPos + pos); virus->setDelegate(parent); parent->addGameObject(virus); virus->playSpawnAnimation(); }); arrayOfActions.pushBack(callfunc); arrayOfActions.pushBack(DelayTime::create(0.1f)); } return Sequence::create(arrayOfActions); }
bool victimNearby( Virus& v, AI *ai, Map& map, Point &target ) { // output param vector<Point> legalMoves; Point vloc(v.x(),v.y()); getLegalMoves(vloc,ai,map,legalMoves); for (vector<Point>::iterator move = legalMoves.begin(); move != legalMoves.end(); move++) { if (map.at((*move).x,(*move).y) == OPVIRUS) { // ensure we can kill it. Virus *victim = getVirusAt(*move,ai); if (victim->level() < v.level()) { target = *move; return true; } } } return false; }
void Host:: InfectWithMoreWildType(Virus& newVirus, double simulationTime, int maxNumberInfections) //function of the host receiving a new virus { //cout << "do i get stuck here??? InfectWith()"<<endl; Infection newInfection; list<Infection>::iterator it; list<Infection>::iterator end = infections.end(); if(!IsInfected()) // if the host is NOT infected yet { newInfection.TransmitInfection(newVirus,simulationTime);//set the parameters to the new infection! infections.push_back(newInfection); } else //but if the host IS infected with some viruses { if(infections.size()<maxNumberInfections) //check first whether it is already at its maximum { if(newVirus.IsWildType()) { newInfection.TransmitInfection(newVirus,simulationTime);//set the parameters to the new infection! infections.push_back(newInfection); } } } }
void build_shell_virus( Virus& v, AI *ai, Map& map ) { ai->players[ai->playerID()].talk("Better..."); // If this returns true, this virus has been given "special" orders. //if (CommandAttacker(v,ai,map)) return; // get all legal moves. Point here(v.x(),v.y()); cout << "Virus at " << here << endl; vector<Point> moves; int off = (v.id() % 2)*2; for (int d=0; d<4; d++) { int doff = (d+off)%4; // odd virus id: Left/Right; even: up/down if (doff==0) { // up if (map.legal(here.x,here.y-1)) moves.push_back(Point(here.x,here.y-1)); } else if (doff==1) { // down if (map.legal(here.x,here.y+1)) moves.push_back(Point(here.x,here.y+1)); } else if (doff==2) { // right if (map.legal(here.x+1,here.y)) moves.push_back(Point(here.x+1,here.y)); } else if (doff==3) { // left if (map.legal(here.x-1,here.y)) moves.push_back(Point(here.x-1,here.y)); } } // cout << "Legal Moves:"; // for (int i=0; i<moves.size(); i++) { cout << " (" << i << ")" << moves[i]; } cout << endl; if (moves.size() == 0) return; // Why? // check for an adjacent killable opponent for (vector<Point>::iterator pMove = moves.begin(); pMove != moves.end(); pMove++) { MAPCODE content = map.at((*pMove).x,(*pMove).y); if (content == OPVIRUS) { Virus *t = getVirusAt(*pMove,ai); if (t->level() < v.level()) { cout << "Attack: " << *pMove << endl; v.move((*pMove).x,(*pMove).y); return; } } } // cout << "after attack" << endl; // if we can combine, do so for (vector<Point>::iterator pMove = moves.begin(); pMove != moves.end(); pMove++) { MAPCODE content = map.at((*pMove).x,(*pMove).y); if (content == MYVIRUS) { Virus *t = getVirusAt(*pMove,ai); if (t->level() == v.level()) { cout << "Combine: " << *pMove << endl; v.move((*pMove).x,(*pMove).y); return; } } } // cout << "after combine" << endl; // If we can surround a base, do so. // Break a chain for (vector<Point>::iterator pMove = moves.begin(); pMove != moves.end(); pMove++) { MAPCODE content = map.at((*pMove).x,(*pMove).y); // Take an opponent's tile. if (content == OP) { // take it. cout << "Take: " << *pMove << endl; v.move((*pMove).x,(*pMove).y); return; } else if (content == EMPTY) { // take it. cout << "Occupy: " << *pMove << endl; v.move((*pMove).x,(*pMove).y); return; } else if (content == MY) { // skip it. } } //cout << "after take ownership" << endl; // Look for the closest empty spot. cout << "Looking for nearest open tile." << endl; vector<MAPCODE> targets; targets.push_back(EMPTY); targets.push_back(OP); Path *target = pathToNearestTarget(map,here,targets); if (target) { cout << "Nearest: [" << target->end << "] <-- " << target->nodes[1] << endl; v.move(target->nodes[1].x,target->nodes[1].y); return; } // Nothing remains but death or my own squares. Random move. int m = rand(); //cout << "R: " << m << endl; m %= moves.size(); cout << "Random: [" << m << "] " << moves[m] << endl; v.move(moves[m].x,moves[m].y); //cout << "after random move" << endl; return; }
bool CommandAttacker( Virus &v, AI *ai, Map& m ) { // Check for "attacker" status. if (v.level() >= attackerMin) { if (baseAttackers.size() <= maxAttackers) { baseAttackers[v.id()] = -1; cout << "Unassigned Attacker: " << v << endl; } Point vloc = Point(v.x(),v.y()); if (baseAttackers.count(v.id())) { cout << " Searching for target..." << endl; Path *closestPath = NULL; Base closest_base; EdgeCost closest = EdgeFar; // known attacker if (baseAttackers[v.id()] == -1) { for (vector<Base>::iterator base = ai->bases.begin(); base != ai->bases.end(); base++) { if ((*base).owner() == ai->playerID()) continue; cout << " Enemy Base: " << (*base) << endl; Path p; p.start = vloc; p.end = Point((*base).x(),(*base).y()); cout << asText(m,p); Path *toBase = path_astar(m,vloc,Point((*base).x(),(*base).y()), (AStarBehavior_t)(AS_IgnoreViruses | AS_AllowImpassableEnd)); if (!toBase) { cout << " * No path from " << vloc << " to base " << (*base) << endl; continue; // no path } cout << asText(m,*toBase); EdgeCost d = toBase->nodes.size()-1; if (d < closest) { closest = d; closest_base = *base; closestPath = toBase; } } if (closest != EdgeFar) { cout << " Base acquired: " << closest_base << endl; baseAttackers[v.id()] = closest_base.id(); } } if (closestPath == NULL) { baseAttackers.erase(v.id()); return false; // this guy can't do it. } // Now, what to do. if (closestPath->nodes.size() <= 3) { // Look for a kill, or go to a corner. Point target; if (victimNearby(v,ai,m,target)) { cout << " Attacker [" << v.id() << "]" << vloc << " -> Victim " << target << "]" << endl; stringstream s(stringstream::out); s << " Attacker [" << v.id() << "]" << vloc << " -> Victim " << target << "]"; string st = s.str(); ai->players[ai->playerID()].talk((char*)(s.str().c_str())); v.move(target.x,target.y); return true; } } else { // Direct him toward the base. Point vMove = closestPath->nodes[1]; cout << " Attacker [" << v.id() << "]" << vloc << " -> Base[" << closest_base << "]" << endl; stringstream s(stringstream::out); s << " Attacker [" << v.id() << "]" << vloc << " -> Base " << closest_base << "]"; ai->players[ai->playerID()].talk((char*)(s.str().c_str())); v.move(vMove.x,vMove.y); return true; } } } return false; }