Example #1
0
File: m_medic.c Project: qbism/qbq2
edict_t *medic_FindDeadMonster (edict_t *self)
{
	edict_t	*ent = NULL;
	edict_t	*best = NULL;

	while ((ent = findradius(ent, self->s.origin, 1024)) != NULL)
	{
		if (ent == self)
			continue;
		if (!(ent->svflags & SVF_MONSTER))
			continue;
		if (ent->monsterinfo.aiflags & AI_GOOD_GUY)
			continue;
		if (ent->owner)
			continue;
		if (ent->health > 0)
			continue;
		if (ent->nextthink && (ent->think != M_FliesOff) && (ent->think != M_FliesOn))
			continue;
		// check to make sure we haven't bailed on this guy already
		if ((ent->monsterinfo.badMedic1 == self) || (ent->monsterinfo.badMedic2 == self))
			continue;
		if (!visible(self, ent))
			continue;
		if (embedded(ent))
			continue;
		if (!canReach(self,ent))
			continue;
		if (!best)
		{
			best = ent;
			continue;
		}
		if (ent->max_health <= best->max_health)
			continue;
		best = ent;
	}

	if(best)
	{
		self->oldenemy = self->enemy;
		self->enemy = best;
		self->enemy->owner = best;
		self->monsterinfo.aiflags |= AI_MEDIC;
		self->monsterinfo.aiflags &= ~AI_MEDIC_PATROL;
		self->monsterinfo.medicTries = 0;
		self->movetarget = self->goalentity = NULL;
		self->enemy->monsterinfo.healer = self;
		self->timestamp = level.time + MEDIC_TRY_TIME;
		FoundTarget (self);

		if(developer->value)
			gi.dprintf("medic found dead monster: %s at %s\n",
			best->classname,vtos(best->s.origin));

	}
	return best;
}
Example #2
0
	bool IsAccessiblePoint(CPoint* point, int x, int y, bool isIgnoreCorner)
	{
		if(!canReach(x, y) || isInCloseVec(x, y))
			return false;
		else
		{
			//可到达的点
			if(abs(x - point->X) + abs(y - point->Y) == 1)    // 左右上下点
				return true;
			else
			{
				if(canReach(abs(x - 1), y) && canReach(x, abs(y - 1)))   // 对角点
					return true;
				else
					return isIgnoreCorner;   //墙的边角
			}
		}
	}
Example #3
0
int HintTestStart (edict_t *self)
{
	edict_t	*e;
	edict_t	*hint=NULL;
	float	dist;
	vec3_t	dir;
	int		i;
	float	bestdistance=99999;

	if (!hint_chains_exist)
		return 0;

	for(i=game.maxclients+1; i<globals.num_edicts; i++)
	{
			e = &g_edicts[i];
			if(!e->inuse)
				continue;
			if(Q_strcasecmp(e->classname,"hint_path"))
				continue;
			if(!visible(self,e))
				continue;
			if(!canReach(self,e))
				continue;
			VectorSubtract(e->s.origin,self->s.origin,dir);
			dist = VectorLength(dir);
			if(dist < bestdistance)
			{
				hint = e;
				bestdistance = dist;
			}
	}
	if(hint)
	{
		self->hint_chain_id = hint->hint_chain_id;
		if(!self->monsterinfo.pathdir)
			self->monsterinfo.pathdir = 1;
		VectorSubtract(hint->s.origin, self->s.origin, dir);
		self->ideal_yaw = vectoyaw(dir);
		self->enemy = self->oldenemy = NULL;
		self->goalentity = self->movetarget = hint;
		self->monsterinfo.pausetime = 0;
		self->monsterinfo.aiflags = AI_HINT_TEST;
		// run for it
		self->monsterinfo.run (self);
		return 1;
	}
	else
		return -1;
}
Example #4
0
 bool canJump(vector<int>& nums) {
     int size = nums.size();
     if (1 == size || 0 == size) {
         return true;
     }
     vector<int> canReach(size, false);
     canReach[0] = true;
     int lastInd = 0;
     for (int i=0; i<size-1; i++) {
         if (i > lastInd && !canReach[i]) {
             return false;
         }
         int ind = i + nums[i];
         bool flag = canReach[i] && true;
         if (ind >= size-1) {
             return true;
         } else {
             canReach[ind] = flag;
         }
         lastInd = max(ind, lastInd);
     }
     
     return canReach[size-2] && nums[size-2]>0;
 }
Example #5
0
File: m_medic.c Project: qbism/qbq2
void medic_idle (edict_t *self)
{
	if(!(self->spawnflags & SF_MONSTER_AMBUSH))
		gi.sound (self, CHAN_VOICE, sound_idle1, 1, ATTN_IDLE, 0);

	if(self->monsterinfo.aiflags & AI_MEDIC)
	{
		// Then we must have reached this point after losing sight
		// of our patient.
		abortHeal(self,false);
	}

	if(medic_FindDeadMonster(self))
		return;

	// If the map has hint_paths, AND the medic isn't at a HOLD point_combat,
	// AND the medic has previously called FoundTarget (trail_time set to
	// level.time), then look for hint_path chain and follow it, hopefully
	// to find monsters to resurrect
	if(self->monsterinfo.aiflags & AI_HINT_TEST)
		return;

	if (hint_chains_exist && !(self->monsterinfo.aiflags & AI_STAND_GROUND)
		&& ((self->monsterinfo.trail_time > 0) || medic_test) )
	{
		edict_t	*e;
		edict_t	*hint=NULL;
		float	dist;
		vec3_t	dir;
		int		i;
		float	bestdistance=99999;

		for(i=game.maxclients+1; i<globals.num_edicts; i++)
		{
			e = &g_edicts[i];
			if(!e->inuse)
				continue;
			if(Q_strcasecmp(e->classname,"hint_path"))
				continue;
			if(!visible(self,e))
				continue;
			if(!canReach(self,e))
				continue;
			VectorSubtract(e->s.origin,self->s.origin,dir);
			dist = VectorLength(dir);
			if(dist < bestdistance)
			{
				hint = e;
				bestdistance = dist;
			}
		}
		if(hint)
		{
			self->hint_chain_id = hint->hint_chain_id;
			if(!self->monsterinfo.pathdir)
				self->monsterinfo.pathdir = 1;
			VectorSubtract(hint->s.origin, self->s.origin, dir);
			self->ideal_yaw = vectoyaw(dir);
			self->goalentity = self->movetarget = hint;
			self->monsterinfo.pausetime = 0;
			self->monsterinfo.aiflags |= AI_MEDIC_PATROL;
			self->monsterinfo.aiflags &= ~(AI_SOUND_TARGET | AI_PURSUIT_LAST_SEEN | AI_PURSUE_NEXT | AI_PURSUE_TEMP);
			// run for it
			self->monsterinfo.run (self);
		}
	}
}
Example #6
0
File: m_medic.c Project: qbism/qbq2
void medic_NextPatrolPoint (edict_t *self, edict_t *hint)
{
	edict_t		*next=NULL;
	edict_t		*e;
	vec3_t		dir;
	qboolean	switch_paths=false;

	self->monsterinfo.aiflags &= ~AI_MEDIC_PATROL;

//	if(self->monsterinfo.aiflags & AI_MEDIC)
//		return;

	if(self->goalentity == hint)
		self->goalentity = NULL;
	if(self->movetarget == hint)
		self->movetarget = NULL;
	if (!(self->monsterinfo.aiflags & AI_MEDIC))
	{
		if(medic_FindDeadMonster(self))
			return;
	}
	if(self->monsterinfo.pathdir == 1)
	{
		if(hint->hint_chain)
			next = hint->hint_chain;
		else
		{
			self->monsterinfo.pathdir = -1;
			switch_paths = true;
		}
	}
	if(self->monsterinfo.pathdir == -1)
	{
		e = hint_chain_starts[hint->hint_chain_id];
		while(e)
		{
			if(e->hint_chain == hint)
			{
				next = e;
				break;
			}
			e = e->hint_chain;
		}
	}
	if(!next)
	{
		self->monsterinfo.pathdir = 1;
		next = hint->hint_chain;
		switch_paths = true;
	}
	// If switch_paths is true, we reached the end of a hint_chain. Just for grins,
	// search for *another* visible hint_path chain and use it if it's reasonably close
	if(switch_paths && hint_chain_count > 1)
	{
		edict_t	*e;
		edict_t	*alternate=NULL;
		float	dist;
		vec3_t	dir;
		int		i;
		float	bestdistance=512;

		for(i=game.maxclients+1; i<globals.num_edicts; i++)
		{
			e = &g_edicts[i];
			if(!e->inuse)
				continue;
			if(Q_strcasecmp(e->classname,"hint_path"))
				continue;
			if(next && (e->hint_chain_id == next->hint_chain_id))
				continue;
			if(!visible(self,e))
				continue;
			if(!canReach(self,e))
				continue;
			VectorSubtract(e->s.origin,self->s.origin,dir);
			dist = VectorLength(dir);
			if(dist < bestdistance)
			{
				alternate = e;
				bestdistance = dist;
			}
		}
		if(alternate)
			next = alternate;
	}
	if(next)
	{
		self->hint_chain_id = next->hint_chain_id;
		VectorSubtract(next->s.origin, self->s.origin, dir);
		self->ideal_yaw = vectoyaw(dir);
		self->goalentity = self->movetarget = next;
		self->monsterinfo.pausetime = 0;
		self->monsterinfo.aiflags |= AI_MEDIC_PATROL;
		self->monsterinfo.aiflags &= ~(AI_SOUND_TARGET | AI_PURSUIT_LAST_SEEN | AI_PURSUE_NEXT | AI_PURSUE_TEMP);
		// run for it
		self->monsterinfo.run (self);
	}
	else
	{
		self->monsterinfo.pausetime = level.time + 100000000;
		self->monsterinfo.stand (self);
	}
}
Example #7
0
void AIPlayer::decide(int partial, int depth)
{
  //fprintf(stderr, "  Decision %d on %d - Depth = %d\n",partial+1,DISPATCHCYCLES,depth);
  if (partial == 0)
  {
    // get flobo binoms to drop
    FloboState etat;
    etat = attachedGame->getFallingState();
    if (etat == FLOBO_EMPTY) return;
    current.falling     = extractColor(etat);
    etat = attachedGame->getCompanionState();
    if (etat == FLOBO_EMPTY) return;
    current.companion   = extractColor(etat);
    current.orientation = extractOrientation(attachedGame->getFallingCompanionDir());
    current.position.x  = attachedGame->getFallingX();
    current.position.y  = FLOBOBAN_DIMY - attachedGame->getFallingY();
    
    originalFlobo = current;
    
    next.falling        = extractColor(attachedGame->getNextFalling());
    next.companion      = extractColor(attachedGame->getNextCompanion());
    next.orientation    = Left;
    next.position.x     = 0;
    next.position.y     = IA_FLOBOBAN_DIMY+1;

    bestl1=1;
    foundOne = false;
    bestEvaluation = 0;
  }
  
  switch (depth)
  {
    case 1:
      for (unsigned int l1 = 1+partial; l1 <= MAXCOMBINATION; l1+=DISPATCHCYCLES)
      {
        // set position of binom 1
        serialPosition(l1,&current);
        
        // reset evaluation
        GridEvaluation evaluation1 = nullEvaluation;
        
        GridState state1;
        
        // drop the binom (including destroying eligible groups) and continue if game not lost
        if (canReach(originalFlobo, current, internalGrid, 1) && dropBinom(current, internalGrid, &state1, &evaluation1))
        {
          evalWith(&state1, &nullEvaluation, &evaluation1);
          
          if (foundOne == false || selectIfBetterEvaluation(&bestEvaluation, &evaluation1, current, &state1))
          {
            bestl1 = l1;
          }
          foundOne = true;
        }
      }
      if (foundOne) serialPosition(bestl1,&current);
      objective = current;
      break;
      
    case 2:
      for (unsigned int l1 = 1+partial; l1 <= MAXCOMBINATION; l1+=DISPATCHCYCLES)
      {
        // set position of binom 1
        serialPosition(l1,&current);
        
        // reset evaluation
        GridEvaluation evaluation1 = nullEvaluation;
        
        GridState state1;
        
        // drop the binom (including destroying eligible groups) and continue if game not lost
        if (canReach(originalFlobo, current, internalGrid, 1) && dropBinom(current, internalGrid, &state1, &evaluation1))
        {
          for (unsigned int l2 = 1; l2 <= MAXCOMBINATION; l2++)
          {
            // set position of binom 1
            serialPosition(l2,&next);
            
            // copy evaluation
            GridEvaluation evaluation2 = evaluation1;
            
            GridState state1bis;
            GridState state2;
            
            dropNeutrals(lastNumberOfBadFlobos-evaluation1.floboSuppressed, totalNumberOfBadFlobos, &state1bis, &state1);  
            
            // drop the binom (including destroying eligible groups) and eval board if game not lost
            if (canReach(originalFlobo, next, &state1bis, 1) && dropBinom(next, &state1bis, &state2, &evaluation2))
            {
              evalWith(&state2, &evaluation1, &evaluation2);
              
              if (foundOne == false || selectIfBetterEvaluation(&bestEvaluation, &evaluation2, current, &state2))
              {
                bestl1 = l1;
              }
              foundOne = true;
            }
          }
        }
      }
      if (foundOne) serialPosition(bestl1,&current);
      objective = current;
      break;
      
    default:
      objective.position.x = (random() % IA_FLOBOBAN_DIMX);
      objective.orientation = (FloboOrientation)(random() % 4);
      break;
  }

}
Example #8
0
int test(int *matr){
	if(canReach(matr) < (SIZE-obstacles)){
		return 0;
	}
	return 1;
}