예제 #1
0
Conj<Posicion> Campus::IngresosMasCercanos(Posicion pos) {
    Conj<Posicion> conjunto = Conj<Posicion>();
    Posicion superior = Posicion(pos.x, 0);
    Posicion inferior = Posicion(pos.x, Filas()-1);
    if (Distancia(pos, superior) <= Distancia(pos, inferior))
        conjunto.Agregar(superior);
    if (Distancia(pos, superior) >= Distancia(pos, inferior))
        conjunto.Agregar(inferior);
    return conjunto;
}
예제 #2
0
int main(void){
    int x, y, a, b, c;

    printf("Dame las coordenadas del punto en x : "); scanf("%d", &x);
    printf("Dame las coordenadas del punto en y : "); scanf("%d", &y);
    printf("Dame los coeficientes de la recta separados por coma(,): "); scanf("%d,%d,%d",&a,&b,&c);

    printf("La distancia entre el punto y la recta es : %.3f", Distancia(x,y,a,b,c));

    return 0;
}
예제 #3
0
 int Disparo() {
    if (existe && click && !disparada) {
       int puntos = 0;
       float dist = Distancia();
       if (dist < 20*tipo) {
          click = 0;
          disparada = 1;
          puntos = 4*(3-tipo);
          for (float i = 15; i > 0; i -= 5) {
             if (dist < i*tipo) {
                puntos += 4*(3-tipo);
             }
          }
       }
       return puntos;
    }
    return 0;
 }
예제 #4
0
파일: medroso.cpp 프로젝트: lymber/tdm
//----------------------------------------------------------------------------------
void Medroso::Atualiza(void)
{
   //procura por quem é a nave principal na central
   Objeto *nave = Procura(JOGADOR); 
    
   if (nave == NULL) return; //por algum motivo, a nave principal não está na central
   
   ZeraComandos();
   
   
   //tenta se afastar dos outros inimigos
   Objeto *outro = InimigoMaisProximo();
   
   if (outro != NULL && outro->Distancia(Posicao()) < 10)
   {
      if (NaEsquerda(outro->Posicao())) JogadaDeLadoDir(true);
      if (NaDireita(outro->Posicao())) JogadaDeLadoEsq(true);
      if (NaTras(outro->Posicao())) ParaFrente(true);
      if (NaFrente(outro->Posicao())) ParaTras(true);
   }
   
   if (nave->NaFrente(Posicao())) //se eu estou na frente do outro, melhor fugir
   {
      if (NaEsquerda(nave->Posicao())) ParaDireita(true);
      else ParaEsquerda(true);

      if (NaFrente(nave->Posicao())) ParaTras(true);
      else ParaFrente(true);
   }
   else //se ele está de costas para mim, vamos atacar
   {
     if (NaEsquerda(nave->Posicao())) ParaEsquerda(true);
     else ParaDireita(true);
     if (NaFrente(nave->Posicao()))
     {
         if (Distancia(nave->Posicao()) > 10) ParaFrente(true);
     }
     else ParaTras(true);    
   }
   if (NaFrente(nave->Posicao())) Atira(true);
   else Atira(false);
   
   Nave::Atualiza();
}
예제 #5
0
void SeguirAmo(int NpcIndex) {
	/* '*************************************************** */
	/* 'Author: Unknown */
	/* 'Last Modification: - */
	/* ' */
	/* '*************************************************** */

	int tHeading;
	int UI;

	if (Npclist[NpcIndex].Target == 0 && Npclist[NpcIndex].TargetNPC == 0) {
		UI = Npclist[NpcIndex].MaestroUser;

		if (UI > 0) {
			/* 'Is it in it's range of vision?? */
			if (vb6::Abs(UserList[UI].Pos.X - Npclist[NpcIndex].Pos.X)
					<= RANGO_VISION_X) {
				if (vb6::Abs(UserList[UI].Pos.Y - Npclist[NpcIndex].Pos.Y)
						<= RANGO_VISION_Y) {
					if (UserList[UI].flags.Muerto == 0
							&& UserList[UI].flags.invisible == 0
							&& UserList[UI].flags.Oculto == 0
							&& Distancia(Npclist[NpcIndex].Pos,
									UserList[UI].Pos) > 3) {
						tHeading = FindDirection(Npclist[NpcIndex].Pos,
								UserList[UI].Pos);
						MoveNPCChar(NpcIndex, tHeading);
						return;
					}
				}
			}
		}
	}

	RestoreOldMovement(NpcIndex);
}
예제 #6
0
double GRAO::Interpenetracao(const GRAO &a){
    if (Distancia(a) < this->Geometria.raio + a.Geometria.raio)
        return (Geometria.raio + a.Geometria.raio -Distancia(a));
    return 0;
}
예제 #7
0
void PasarMinutoCentinela() {
	/* '************************************************* */
	/* 'Author: Unknown */
	/* 'Last modified: 02/10/2010 */
	/* 'Control del timer. Llamado cada un minuto. */
	/* '03/10/2010: ZaMa - Adaptado para que funcione mas de un centinela en paralelo. */
	/* '************************************************* */

	int index;
	int UserIndex;
	int IdleCount = 0;

	if (!centinelaActivado) {
		return;
	}

	/* ' Primero reviso los que estan chequeando usuarios */
	for (index = (1); index <= (NRO_CENTINELA); index++) {

		/* ' Esta activo? */
		if (Centinela[index].Activo) {
			Centinela[index].TiempoRestante = Centinela[index].TiempoRestante - 1;

			/* ' Temrino el tiempo de chequeo? */
			if (Centinela[index].TiempoRestante == 0) {
				CentinelaFinalCheck(index);
			} else {

				UserIndex = Centinela[index].RevisandoUserIndex;

				/* 'RECORDamos al user que debe escribir */
				if (Distancia(Npclist[Centinela[index].NpcIndex].Pos, UserList[UserIndex].Pos) > 5) {
					WarpCentinela(UserIndex, index);
				}

				/* 'El centinela habla y se manda a consola para que no quepan dudas */
				WriteChatOverHead(UserIndex,
						"¡" + UserList[UserIndex].Name
								+ ", tienes un minuto más para responder! Debes escribir /CENTINELA "
								+ vb6::CStr(Centinela[index].clave) + ".",
						(Npclist[Centinela[index].NpcIndex].Char.CharIndex), vbRed);
				WriteConsoleMsg(UserIndex,
						"¡" + UserList[UserIndex].Name + ", tienes un minuto más para responder!",
						FontTypeNames_FONTTYPE_CENTINELA);
				FlushBuffer(UserIndex);
			}
		} else {

			/* ' Lo reseteo aca, para que pueda hablarle al usuario chequeado aunque haya respondido bien. */
			if (Centinela[index].NpcIndex != 0) {
				if (Centinela[index].RevisandoUserIndex != 0) {
					UserList[Centinela[index].RevisandoUserIndex].flags.CentinelaIndex = 0;
					Centinela[index].RevisandoUserIndex = 0;
				}
				QuitarNPC(Centinela[index].NpcIndex);
				Centinela[index].NpcIndex = 0;
			}

			IdleCount = IdleCount + 1;
		}

	}

	/* 'Verificamos si ya debemos resetear la lista */
	int TActual;
	TActual = vb6::GetTickCount();

	if (checkInterval(centinelaStartTime, TActual, centinelaInterval)) {
		/* ' Espero a que terminen de controlar todos los centinelas */
		DetenerAsignacion = true;
	}

	/* ' Si hay algun centinela libre, se fija si no hay trabajadores disponibles para chequear */
	if (IdleCount != 0) {

		/* ' Si es tiempo de resetear flags, chequeo que no quede nadie activo */
		if (DetenerAsignacion) {

			/* ' No se completaron los ultimos chequeos */
			if (IdleCount < NRO_CENTINELA) {
				return;
			}

			/* ' Resetea todos los flags */
			ResetCentinelaInfo();
			DetenerAsignacion = false;

			/* ' Renuevo el contador de reseteo */
			RenovarResetTimer();

		}

		GoToNextWorkingChar();

	}
}
예제 #8
0
bool clsParty::PuedeEntrar(int UserIndex, std::string razon) {
	bool retval;
	/* '*************************************************** */
	/* 'Author: Unknown */
	/* 'Last Modification: 09/29/07 */
	/* 'Last Modification By: Lucas Tavolaro Ortiz (Tavo) */
	/* ' - 09/29/07 There is no level prohibition */
	/* '*************************************************** */
	/* 'DEFINE LAS REGLAS DEL JUEGO PARA DEJAR ENTRAR A MIEMBROS */
	bool esArmada;
	bool esCaos;
//	int MyLevel;
	int i;
	bool rv;
	int UI;

	rv = true;
	esArmada = (UserList[UserIndex].Faccion.ArmadaReal == 1);
	esCaos = (UserList[UserIndex].Faccion.FuerzasCaos == 1);
//	MyLevel = UserList[UserIndex].Stats.ELV;

	rv = Distancia(UserList[p_members[1].UserIndex].Pos, UserList[UserIndex].Pos) <= MAXDISTANCIAINGRESOPARTY;
	if (rv) {
		rv = (p_members[PARTY_MAXMEMBERS].UserIndex == 0);
		if (rv) {
			for (i = (1); i <= (PARTY_MAXMEMBERS); i++) {
				UI = p_members[i].UserIndex;
				/* 'pongo los casos que evitarian que pueda entrar */
				/* 'aspirante armada en party crimi */
				if (UI > 0) {
					if (esArmada && criminal(UI)) {
						razon = "Los miembros del ejército real no entran a una party con criminales.";
						rv = false;
					}
					/* 'aspirante caos en party ciuda */
					if (esCaos && !criminal(UI)) {
						razon = "Los miembros de la legión oscura no entran a una party con ciudadanos.";
						rv = false;
					}
					/* 'aspirante crimi en party armada */
					if (UserList[UI].Faccion.ArmadaReal == 1 && criminal(UserIndex)) {
						razon = "Los criminales no entran a parties con miembros del ejército real.";
						rv = false;
					}
					/* 'aspirante ciuda en party caos */
					if (UserList[UI].Faccion.FuerzasCaos == 1 && !criminal(UserIndex)) {
						razon = "Los ciudadanos no entran a parties con miembros de la legión oscura.";
						rv = false;
					}

					/* 'violate una programacion estructurada */
					if (!rv) {
						break; /* FIXME: EXIT FOR */
					}
				}
			}
		} else {
			razon = "La mayor cantidad de miembros es " + vb6::CStr(PARTY_MAXMEMBERS);
		}
	} else {
		/* '¿Con o sin nombre? */
		razon = "El usuario " + UserList[UserIndex].Name + " se encuentra muy lejos.";
	}

	retval = rv;

	return retval;
}
예제 #9
0
void AiNpcAtacaNpc(int NpcIndex) {
	/* '*************************************************** */
	/* 'Author: Unknown */
	/* 'Last Modification: - */
	/* ' */
	/* '*************************************************** */

	int tHeading;
	int X;
	int Y;
	int NI;
	bool bNoEsta = false;

	int SignoNS;
	int SignoEO;

	if (Npclist[NpcIndex].flags.Inmovilizado == 1) {
		switch (Npclist[NpcIndex].Char.heading) {
		case eHeading_NORTH:
			SignoNS = -1;
			SignoEO = 0;

			break;

		case eHeading_EAST:
			SignoNS = 0;
			SignoEO = 1;

			break;

		case eHeading_SOUTH:
			SignoNS = 1;
			SignoEO = 0;

			break;

		case eHeading_WEST:
			SignoEO = -1;
			SignoNS = 0;
			break;

		default:
			SignoEO = SignoNS = 0;
			break;
		}

		for (Y = (Npclist[NpcIndex].Pos.Y);
				((vb6::IIf(SignoNS == 0, 1, SignoNS)) > 0) ?
						(Y
								<= (Npclist[NpcIndex].Pos.Y
										+ SignoNS * RANGO_VISION_Y)) :
						(Y
								>= (Npclist[NpcIndex].Pos.Y
										+ SignoNS * RANGO_VISION_Y));
				Y = Y + (vb6::IIf(SignoNS == 0, 1, SignoNS))) {
			for (X = (Npclist[NpcIndex].Pos.X);
					((vb6::IIf(SignoEO == 0, 1, SignoEO)) > 0) ?
							(X
									<= (Npclist[NpcIndex].Pos.X
											+ SignoEO * RANGO_VISION_X)) :
							(X
									>= (Npclist[NpcIndex].Pos.X
											+ SignoEO * RANGO_VISION_X));
					X = X + (vb6::IIf(SignoEO == 0, 1, SignoEO))) {
				if (X >= MinXBorder && X <= MaxXBorder && Y >= MinYBorder
						&& Y <= MaxYBorder) {
					NI = MapData[Npclist[NpcIndex].Pos.Map][X][Y].NpcIndex;
					if (NI > 0) {
						if (Npclist[NpcIndex].TargetNPC == NI) {
							bNoEsta = true;
							if (Npclist[NpcIndex].Numero == ELEMENTALFUEGO) {
								NpcLanzaUnSpellSobreNpc(NpcIndex, NI);
								if (Npclist[NI].NPCtype == eNPCType_DRAGON) {
									Npclist[NI].CanAttack = 1;
									NpcLanzaUnSpellSobreNpc(NI, NpcIndex);
								}
							} else {
								/* 'aca verificamosss la distancia de ataque */
								if (Distancia(Npclist[NpcIndex].Pos,
										Npclist[NI].Pos) <= 1) {
									NpcAtacaNpc(NpcIndex, NI);
								}
							}
							return;
						}
					}
				}
			}
		}
	} else {
		for (Y = (Npclist[NpcIndex].Pos.Y - RANGO_VISION_Y);
				Y <= (Npclist[NpcIndex].Pos.Y + RANGO_VISION_Y); Y++) {
			for (X = (Npclist[NpcIndex].Pos.X - RANGO_VISION_Y);
					X <= (Npclist[NpcIndex].Pos.X + RANGO_VISION_Y); X++) {
				if (X >= MinXBorder && X <= MaxXBorder && Y >= MinYBorder
						&& Y <= MaxYBorder) {
					NI = MapData[Npclist[NpcIndex].Pos.Map][X][Y].NpcIndex;
					if (NI > 0) {
						if (Npclist[NpcIndex].TargetNPC == NI) {
							bNoEsta = true;
							if (Npclist[NpcIndex].Numero == ELEMENTALFUEGO) {
								NpcLanzaUnSpellSobreNpc(NpcIndex, NI);
								if (Npclist[NI].NPCtype == eNPCType_DRAGON) {
									Npclist[NI].CanAttack = 1;
									NpcLanzaUnSpellSobreNpc(NI, NpcIndex);
								}
							} else {
								/* 'aca verificamosss la distancia de ataque */
								if (Distancia(Npclist[NpcIndex].Pos,
										Npclist[NI].Pos) <= 1) {
									NpcAtacaNpc(NpcIndex, NI);
								}
							}
							if (Npclist[NpcIndex].flags.Inmovilizado == 1) {
								return;
							}
							if (Npclist[NpcIndex].TargetNPC == 0) {
								return;
							}
							tHeading =
									FindDirection(Npclist[NpcIndex].Pos,
											Npclist[MapData[Npclist[NpcIndex].Pos.Map][X][Y].NpcIndex].Pos);
							MoveNPCChar(NpcIndex, tHeading);
							return;
						}
					}
				}
			}
		}
	}

	if (!bNoEsta) {
		if (Npclist[NpcIndex].MaestroUser > 0) {
			FollowAmo(NpcIndex);
		} else {
			Npclist[NpcIndex].Movement = Npclist[NpcIndex].flags.OldMovement;
			Npclist[NpcIndex].Hostile = Npclist[NpcIndex].flags.OldHostil;
		}
	}
}
예제 #10
0
/* ' @param NpcIndex Specifies reference to the npc */
void SeguirAgresor(int NpcIndex) {
	/* '************************************************************** */
	/* 'Author: Unknown */
	/* 'Last Modify by: Marco Vanotti (MarKoxX) */
	/* 'Last Modify Date: 08/16/2008 */
	/* '08/16/2008: MarKoxX - Now pets that do mel� attacks have to be near the enemy to attack. */
	/* '************************************************************** */
	int tHeading;
	int UI;

	int i;

	int SignoNS;
	int SignoEO;

	if (Npclist[NpcIndex].flags.Paralizado == 1
			|| Npclist[NpcIndex].flags.Inmovilizado == 1) {
		switch (Npclist[NpcIndex].Char.heading) {
		case eHeading_NORTH:
			SignoNS = -1;
			SignoEO = 0;

			break;

		case eHeading_EAST:
			SignoNS = 0;
			SignoEO = 1;

			break;

		case eHeading_SOUTH:
			SignoNS = 1;
			SignoEO = 0;

			break;

		case eHeading_WEST:
			SignoEO = -1;
			SignoNS = 0;
			break;

		default:
			SignoEO = SignoNS = 0;
			break;
		}

		for (i = (1); i <= (ConnGroups[Npclist[NpcIndex].Pos.Map].CountEntrys);
				i++) {
			UI = ConnGroups[Npclist[NpcIndex].Pos.Map].UserEntrys[i];

			/* 'Is it in it's range of vision?? */
			if (vb6::Abs(UserList[UI].Pos.X - Npclist[NpcIndex].Pos.X)
					<= RANGO_VISION_X
					&& vb6::Sgn(UserList[UI].Pos.X - Npclist[NpcIndex].Pos.X)
							== SignoEO) {
				if (vb6::Abs(UserList[UI].Pos.Y - Npclist[NpcIndex].Pos.Y)
						<= RANGO_VISION_Y
						&& vb6::Sgn(UserList[UI].Pos.Y - Npclist[NpcIndex].Pos.Y)
								== SignoNS) {

					if (UserList[UI].Name
							== Npclist[NpcIndex].flags.AttackedBy) {
						if (Npclist[NpcIndex].MaestroUser > 0) {
							if (!criminal(Npclist[NpcIndex].MaestroUser)
									&& !criminal(UI)
									&& (UserList[Npclist[NpcIndex].MaestroUser].flags.Seguro
											|| UserList[Npclist[NpcIndex].MaestroUser].Faccion.ArmadaReal
													== 1)) {
								WriteConsoleMsg(Npclist[NpcIndex].MaestroUser,
										"La mascota no atacará a ciudadanos si eres miembro del ejército real o tienes el seguro activado.",
										FontTypeNames_FONTTYPE_INFO);
								FlushBuffer(Npclist[NpcIndex].MaestroUser);
								Npclist[NpcIndex].flags.AttackedBy = "";
								return;
							}
						}

						if (UserList[UI].flags.Muerto == 0
								&& UserList[UI].flags.invisible == 0
								&& UserList[UI].flags.Oculto == 0) {
							if (Npclist[NpcIndex].flags.LanzaSpells > 0) {
								NpcLanzaUnSpell(NpcIndex, UI);
							} else {
								if (Distancia(UserList[UI].Pos,
										Npclist[NpcIndex].Pos) <= 1) {
									/* ' TODO : Set this a separate AI for Elementals and Druid's pets */
									if (Npclist[NpcIndex].Numero != 92) {
										NpcAtacaUser(NpcIndex, UI);
									}
								}
							}
							return;
						}
					}

				}
			}

		}
	} else {
		for (i = (1); i <= (ConnGroups[Npclist[NpcIndex].Pos.Map].CountEntrys);
				i++) {
			UI = ConnGroups[Npclist[NpcIndex].Pos.Map].UserEntrys[i];

			/* 'Is it in it's range of vision?? */
			if (vb6::Abs(UserList[UI].Pos.X - Npclist[NpcIndex].Pos.X)
					<= RANGO_VISION_X) {
				if (vb6::Abs(UserList[UI].Pos.Y - Npclist[NpcIndex].Pos.Y)
						<= RANGO_VISION_Y) {

					if (UserList[UI].Name
							== Npclist[NpcIndex].flags.AttackedBy) {
						if (Npclist[NpcIndex].MaestroUser > 0) {
							if (!criminal(Npclist[NpcIndex].MaestroUser)
									&& !criminal(UI)
									&& (UserList[Npclist[NpcIndex].MaestroUser].flags.Seguro
											|| UserList[Npclist[NpcIndex].MaestroUser].Faccion.ArmadaReal
													== 1)) {
								WriteConsoleMsg(Npclist[NpcIndex].MaestroUser,
										"La mascota no atacará a ciudadanos si eres miembro del ejército real o tienes el seguro activado.",
										FontTypeNames_FONTTYPE_INFO);
								FlushBuffer(Npclist[NpcIndex].MaestroUser);
								Npclist[NpcIndex].flags.AttackedBy = "";
								FollowAmo(NpcIndex);
								return;
							}
						}

						if (UserList[UI].flags.Muerto == 0
								&& UserList[UI].flags.invisible == 0
								&& UserList[UI].flags.Oculto == 0) {
							if (Npclist[NpcIndex].flags.LanzaSpells > 0) {
								NpcLanzaUnSpell(NpcIndex, UI);
							} else {
								if (Distancia(UserList[UI].Pos,
										Npclist[NpcIndex].Pos) <= 1) {
									/* ' TODO : Set this a separate AI for Elementals and Druid's pets */
									if (Npclist[NpcIndex].Numero != 92) {
										NpcAtacaUser(NpcIndex, UI);
									}
								}
							}

							tHeading = FindDirection(Npclist[NpcIndex].Pos,
									UserList[UI].Pos);
							MoveNPCChar(NpcIndex, tHeading);

							return;
						}
					}

				}
			}

		}
	}

	RestoreOldMovement(NpcIndex);
}