Exemplo n.º 1
0
void ColorConsole::log(const Source & file, int line, Logger::LogLevel level,
                       const std::string & str) {
	
	std::ostream * os;
	
	const char * c = "\x1b[m";
	const char * e = "";
	size_t length = 3;
	switch(level) {
		case Logger::Debug:    std::cout << "\x1b[1;36m[D]\x1b[0;36m", os = &std::cout; break;
		case Logger::Info:     std::cout << "\x1b[1;32m[I]\x1b[0;32m", os = &std::cout; break;
		case Logger::Console:  std::cout << "\x1b[1;37m[C]\x1b[0;37m", os = &std::cout; break;
		case Logger::Warning:  std::cerr << "\x1b[1;33m[W]\x1b[0;33m";
			                     os = &std::cerr, e = c, c = "\x1b[0;33m"; break;
		case Logger::Error:    std::cerr << "\x1b[1;31m[E]\x1b[0;31m";
		                       os = &std::cerr, e = c, c = "\x1b[0;31m"; break;
		case Logger::Critical: std::cerr << "\x1b[1;31m[CRITICAL]\x1b[0;31m";
			                     os = &std::cerr, e = c, c = "\x1b[1;31m", length = 10; break;
		case Logger::None: ARX_DEAD_CODE(); return;
	}
	(*os) << ' ' << file.name << "\x1b[m:\x1b[0;33m";
	
	std::ostream::fmtflags flags = os->flags();
	
	length += 1 + file.name.length() + 1;
	if(length < alignment) {
		(*os) << std::left << std::setfill(' ') << std::setw(alignment - length);
	}
	
	(*os) << line << " " << c << str << e << std::endl;
	
	os->flags(flags);
}
Exemplo n.º 2
0
void logger::Backend::format(std::ostream & os, const Source & file,
                             int line, Logger::LogLevel level, const std::string & str) {
	
	size_t length = 3;
	switch(level) {
		case Logger::Debug:    os << "[D]"; break;
		case Logger::Info:     os << "[I]"; break;
		case Logger::Console:  os << "[C]"; break;
		case Logger::Warning:  os << "[W]"; break;
		case Logger::Error:    os << "[E]"; break;
		case Logger::Critical: os << "[CRITICAL]", length = 10; break;
		case Logger::None: ARX_DEAD_CODE();
	}
	os << ' ' << file.name << ':';
	
	std::ostream::fmtflags flags = os.flags();
	
	length += 1 + file.name.length() + 1;
	if(length < alignment) {
		os << std::left << std::setfill(' ') << std::setw(alignment - length);
	}
	
	os << line << "  " << str << std::endl;
	
	os.flags(flags);
}
Exemplo n.º 3
0
void FireFieldSpell::Launch() {
	
	spells.endByCaster(m_caster, SPELL_FIRE_FIELD);
	
	ARX_SOUND_PlaySFX(SND_SPELL_FIRE_FIELD_START);
	
	m_duration = (m_launchDuration > ArxDuration(-1)) ? m_launchDuration : ArxDurationMs(100000);
	m_hasDuration = true;
	m_fManaCostPerSecond = 2.8f;
	m_light = LightHandle();
	
	Vec3f target;
	float beta = 0.f;
	bool displace = false;
	if(m_caster == EntityHandle_Player) {
		target = player.basePosition();
		beta = player.angle.getYaw();
		displace = true;
	} else {
		if(ValidIONum(m_caster)) {
			Entity * io = entities[m_caster];
			target = io->pos;
			beta = io->angle.getYaw();
			displace = (io->ioflags & IO_NPC) == IO_NPC;
		} else {
			ARX_DEAD_CODE();
		}
	}
	if(displace) {
		target += angleToVectorXZ(beta) * 250.f;
	}
	
	m_pos = target + Vec3f(0, -10, 0);
	
	DamageParameters damage;
	damage.radius = 150.f;
	damage.damages = 10.f;
	damage.area = DAMAGE_FULL;
	damage.duration = ArxDurationMs(100000000);
	damage.source = m_caster;
	damage.flags = 0;
	damage.type = DAMAGE_TYPE_MAGICAL | DAMAGE_TYPE_FIRE | DAMAGE_TYPE_FIELD;
	damage.pos = target;
	m_damage = DamageCreate(damage);
	
	m_snd_loop = ARX_SOUND_PlaySFX(SND_SPELL_FIRE_FIELD_LOOP, &target, 1.f, ARX_SOUND_PLAY_LOOPED);
	
	pPSStream.SetParams(g_particleParameters[ParticleParam_FireFieldBase]);
	pPSStream.SetPos(m_pos);
	
	pPSStream1.SetParams(g_particleParameters[ParticleParam_FireFieldFlame]);
	pPSStream1.SetPos(m_pos + Vec3f(0, 10, 0));
	pPSStream1.Update(0);
}
Exemplo n.º 4
0
void logger::Backend::format(std::ostream & os, const logger::Source & file, int line, Logger::LogLevel level, const std::string & str) {
	
	switch(level) {
		case Logger::Debug:   os << "[D]"; break;
		case Logger::Info:    os << "[I]"; break;
		case Logger::Warning: os << "[W]"; break;
		case Logger::Error:   os << "[E]"; break;
		case Logger::Critical:   os << "[CRITICAL]"; break;
		case Logger::None: ARX_DEAD_CODE();
	}
	
	os << ' ' << file.name << ':' << line << "  " << str << std::endl;
}
Exemplo n.º 5
0
//-----------------------------------------------------------------------------
void CSpeed::AddRuban(int * f, int id, int dec)
{
	int	num;

	num = this->GetFreeRuban();

	if (num >= 0)
	{
		truban[num].actif = 1;
		truban[num].pos = entities[this->num]->obj->vertexlist3[id].v;

		if (*f < 0)
		{
			*f = num;
			this->truban[num].next = -1;
		}
		else
		{
			this->truban[num].next = *f;
			*f = num;
		}

		int nb = 0, oldnum = num;

		while (num != -1)
		{
			nb++;
			oldnum = num;
			num = this->truban[num].next;
		}

		if (oldnum < 0) ARX_DEAD_CODE();

		if (nb > dec)
		{

			this->truban[oldnum].actif = 0;
			num = *f;
			nb -= 2;

			while (nb--)
			{
				num = this->truban[num].next;
			}

			this->truban[num].next = -1;
		}
	}
}
Exemplo n.º 6
0
static void EntityEnteringCurrentZone(Entity * io, ARX_PATH * current) {
	
	io->inzone_show = io->show;
	
	if(JUST_RELOADED && (current->name == "ingot_maker" || current->name == "mauld_user")) {
		ARX_DEAD_CODE(); // TODO remove JUST_RELOADED global
	} else {
		
		SendIOScriptEvent(NULL, io, SM_ENTERZONE, current->name);
		
		if(!current->controled.empty()) {
			EntityHandle t = entities.getById(current->controled);
			if(t != EntityHandle()) {
				ScriptParameters parameters;
				parameters.push_back(io->idString());
				parameters.push_back(current->name);
				SendIOScriptEvent(NULL, entities[t], SM_CONTROLLEDZONE_ENTER, parameters);
			}
		}
		
	}
	
}
Exemplo n.º 7
0
void ARX_PATH_UpdateAllZoneInOutInside() {
	
	arx_assert(entities.player());
	
	static size_t count = 1;
	
	long f = glm::clamp(static_cast<long>(framedelay), 10l, 50l);
	
	if(count >= entities.size()) {
		count = 1;
	}

	if(entities.size() > 1)
		for(long tt = 0; tt < f; tt++) {
			const EntityHandle i = EntityHandle(count);
			Entity * io = entities[i];
			

			if(count < entities.size()
			   && io
			   && io->ioflags & (IO_NPC | IO_ITEM)
			   && io->show != SHOW_FLAG_MEGAHIDE
			) {
				arx_assert(io->show != SHOW_FLAG_DESTROYED);
				ARX_PATH * p = ARX_PATH_CheckInZone(io);
				ARX_PATH * op = io->inzone;

				if(op == NULL && p == NULL)
					goto next; // Not in a zone

				if(op == p) { // Stayed inside Zone OP
					if(io->show != io->inzone_show) {
						io->inzone_show = io->show;
						goto entering;
					}
				}
				else if ((op != NULL) && (p == NULL)) // Leaving Zone OP
				{
					SendIOScriptEvent(io, SM_LEAVEZONE, op->name);

					if(!op->controled.empty()) {
						EntityHandle t = entities.getById(op->controled);

						if(t != EntityHandle::Invalid) {
							std::string str = io->idString() + ' ' + op->name;
							SendIOScriptEvent(entities[t], SM_CONTROLLEDZONE_LEAVE, str);
						}
					}
				}
				else if ((op == NULL) && (p != NULL)) // Entering Zone P
				{
					io->inzone_show = io->show;
				entering:

					if(JUST_RELOADED && (p->name == "ingot_maker" || p->name == "mauld_user")) {
						ARX_DEAD_CODE(); // TODO remove JUST_RELOADED global
					} else {
						SendIOScriptEvent(io, SM_ENTERZONE, p->name);

						if(!p->controled.empty()) {
							EntityHandle t = entities.getById(p->controled);

							if(t != EntityHandle::Invalid) {
								std::string params = io->idString() + ' ' + p->name;
								SendIOScriptEvent(entities[t], SM_CONTROLLEDZONE_ENTER, params);
							}
						}
					}
				} else {
					SendIOScriptEvent(io, SM_LEAVEZONE, op->name);

					if(!op->controled.empty()) {
						EntityHandle t = entities.getById(op->controled);

						if(t != EntityHandle::Invalid) {
							std::string str = io->idString() + ' ' + op->name;
							SendIOScriptEvent(entities[t], SM_CONTROLLEDZONE_LEAVE, str);
						}
					}

					io->inzone_show = io->show;
					SendIOScriptEvent(io, SM_ENTERZONE, p->name);

					if(!p->controled.empty()) {
						EntityHandle t = entities.getById(p->controled);

						if(t != EntityHandle::Invalid) {
							std::string str = io->idString() + ' ' + p->name;
							SendIOScriptEvent(entities[t], SM_CONTROLLEDZONE_ENTER, str);
						}
					}
				}

				io->inzone = p;
			}

		next:
			count++;

			if(count >= entities.size())
				count = 1;
		}

	// player check*************************************************
	{
		ARX_PATH * p = ARX_PATH_CheckPlayerInZone();
		ARX_PATH * op = player.inzone;

		if((op == NULL) && (p == NULL))
			goto suite; // Not in a zone

		if(op == p) // Stayed inside Zone OP
		{
		
		}
		else if(op != NULL && p == NULL) // Leaving Zone OP
		{
			SendIOScriptEvent(entities.player(), SM_LEAVEZONE, op->name);
			CHANGE_LEVEL_ICON = -1;

			if(!op->controled.empty()) {
				EntityHandle t = entities.getById(op->controled);

				if(t != EntityHandle::Invalid) {
					SendIOScriptEvent(entities[t], SM_CONTROLLEDZONE_LEAVE, "player " + op->name);
				}
			}
		}
		else if ((op == NULL) && (p != NULL)) // Entering Zone P
		{
			SendIOScriptEvent(entities.player(), SM_ENTERZONE, p->name);

			if(p->flags & PATH_AMBIANCE && !p->ambiance.empty())
				ARX_SOUND_PlayZoneAmbiance(p->ambiance, ARX_SOUND_PLAY_LOOPED, p->amb_max_vol * ( 1.0f / 100 ));

			if(p->flags & PATH_FARCLIP) {
				desired.flags |= GMOD_ZCLIP;
				desired.zclip = p->farclip;
			}

			if (p->flags & PATH_REVERB)
			{
			}

			if(p->flags & PATH_RGB) {
				desired.flags |= GMOD_DCOLOR;
				desired.depthcolor = p->rgb;
			}

			if(!p->controled.empty()) {
				EntityHandle t = entities.getById(p->controled);

				if(t != EntityHandle::Invalid) {
					SendIOScriptEvent(entities[t], SM_CONTROLLEDZONE_ENTER, "player " + p->name);
				}
			}
		} else {
			if(!op->controled.empty()) {
				EntityHandle t = entities.getById(op->controled);

				if(t != EntityHandle::Invalid) {
					SendIOScriptEvent(entities[t], SM_CONTROLLEDZONE_LEAVE, "player " + p->name);
				}
			}

			if(!op->controled.empty()) {
				EntityHandle t = entities.getById(p->controled);

				if(t != EntityHandle::Invalid) {
					SendIOScriptEvent(entities[t], SM_CONTROLLEDZONE_ENTER, "player " + p->name);
				}
			}
		}

		player.inzone = p;
	}

	
suite:
	JUST_RELOADED = 0;
}
Exemplo n.º 8
0
void IceFieldSpell::Launch()
{
	spells.endByCaster(m_caster, SPELL_ICE_FIELD);
	
	ARX_SOUND_PlaySFX(SND_SPELL_ICE_FIELD);
	
	m_duration = (m_launchDuration > -1) ? m_launchDuration : 100000;
	m_hasDuration = true;
	m_fManaCostPerSecond = 2.8f;
	m_light = LightHandle::Invalid;
	
	Vec3f target;
	float beta = 0.f;
	bool displace = false;
	if(m_caster == PlayerEntityHandle) {
		target = player.basePosition();
		beta = player.angle.getPitch();
		displace = true;
	} else {
		if(ValidIONum(m_caster)) {
			Entity * io = entities[m_caster];
			target = io->pos;
			beta = io->angle.getPitch();
			displace = (io->ioflags & IO_NPC) == IO_NPC;
		} else {
			ARX_DEAD_CODE();
		}
	}
	if(displace) {
		target += angleToVectorXZ(beta) * 250.f;
	}
	
	m_pos = target;
	
	DamageParameters damage;
	damage.radius = 150.f;
	damage.damages = 10.f;
	damage.area = DAMAGE_FULL;
	damage.duration = 100000000;
	damage.source = m_caster;
	damage.flags = 0;
	damage.type = DAMAGE_TYPE_MAGICAL | DAMAGE_TYPE_COLD | DAMAGE_TYPE_FIELD;
	damage.pos = target;
	m_damage = DamageCreate(damage);
	
	tex_p1 = TextureContainer::Load("graph/obj3d/textures/(fx)_tsu_blueting");
	tex_p2 = TextureContainer::Load("graph/obj3d/textures/(fx)_tsu_bluepouf");
	
	for(int i = 0; i < iMax; i++) {
		float t = rnd();

		if (t < 0.5f)
			tType[i] = 0;
		else
			tType[i] = 1;
		
		tSize[i] = Vec3f_ZERO;
		tSizeMax[i] = Vec3f(rnd(), rnd(), rnd()) + Vec3f(0.f, 0.2f, 0.f);
		
		Vec3f minPos;
		if(tType[i] == 0) {
			minPos = Vec3f(1.2f, 1, 1.2f);
		} else {
			minPos = Vec3f(0.4f, 0.3f, 0.4f);
		}
		
		tSizeMax[i] = glm::max(tSizeMax[i], minPos);
		
		if(tType[i] == 0) {
			tPos[i].x = m_pos.x + frand2() * 80;
			tPos[i].y = m_pos.y;
			tPos[i].z = m_pos.z + frand2() * 80;
		} else {
			tPos[i].x = m_pos.x + frand2() * 120;
			tPos[i].y = m_pos.y;
			tPos[i].z = m_pos.z + frand2() * 120;
		}
	}
	
	m_snd_loop = ARX_SOUND_PlaySFX(SND_SPELL_ICE_FIELD_LOOP, &target, 1.f, ARX_SOUND_PLAY_LOOPED);
}
Exemplo n.º 9
0
void FireFieldSpell::Launch() {
	
	spells.endByCaster(m_caster, SPELL_FIRE_FIELD);
	
	ARX_SOUND_PlaySFX(SND_SPELL_FIRE_FIELD_START);
	
	m_duration = (m_launchDuration > -1) ? m_launchDuration : 100000;
	m_hasDuration = true;
	m_fManaCostPerSecond = 2.8f;
	m_light = LightHandle::Invalid;
	
	Vec3f target;
	float beta = 0.f;
	bool displace = false;
	if(m_caster == PlayerEntityHandle) {
		target = player.basePosition();
		beta = player.angle.getPitch();
		displace = true;
	} else {
		if(ValidIONum(m_caster)) {
			Entity * io = entities[m_caster];
			target = io->pos;
			beta = io->angle.getPitch();
			displace = (io->ioflags & IO_NPC) == IO_NPC;
		} else {
			ARX_DEAD_CODE();
		}
	}
	if(displace) {
		target += angleToVectorXZ(beta) * 250.f;
	}
	
	m_pos = target + Vec3f(0, -10, 0);
	
	DamageParameters damage;
	damage.radius = 150.f;
	damage.damages = 10.f;
	damage.area = DAMAGE_FULL;
	damage.duration = 100000000;
	damage.source = m_caster;
	damage.flags = 0;
	damage.type = DAMAGE_TYPE_MAGICAL | DAMAGE_TYPE_FIRE | DAMAGE_TYPE_FIELD;
	damage.pos = target;
	m_damage = DamageCreate(damage);
	
	m_snd_loop = ARX_SOUND_PlaySFX(SND_SPELL_FIRE_FIELD_LOOP, &target, 1.f, ARX_SOUND_PLAY_LOOPED);
	
	{
	ParticleParams cp = ParticleParams();
	cp.m_nbMax = 100;
	cp.m_life = 2000;
	cp.m_lifeRandom = 1000;
	cp.m_pos = Vec3f(80, 10, 80);
	cp.m_direction = Vec3f(0.f, 1.f, 0.f);
	cp.m_angle = 0;
	cp.m_speed = 0;
	cp.m_speedRandom = 0;
	cp.m_gravity = Vec3f_ZERO;
	cp.m_flash = 0;
	cp.m_rotation = 0;
	cp.m_rotationRandomDirection = false;
	cp.m_rotationRandomStart = false;

	cp.m_startSegment.m_size = 10;
	cp.m_startSegment.m_sizeRandom = 3;
	cp.m_startSegment.m_color = Color(25, 25, 25, 50).to<float>();
	cp.m_startSegment.m_colorRandom = Color(51, 51, 51, 101).to<float>();

	cp.m_endSegment.m_size = 10;
	cp.m_endSegment.m_sizeRandom = 3;
	cp.m_endSegment.m_color = Color(25, 25, 25, 50).to<float>();
	cp.m_endSegment.m_colorRandom = Color(0, 0, 0, 100).to<float>();
	cp.m_texture.m_texLoop = true;

	cp.m_blendMode = RenderMaterial::AlphaAdditive;
	cp.m_freq = 150.0f;
	cp.m_texture.set("graph/particles/firebase", 4, 100);
	cp.m_spawnFlags = 0;
	
	pPSStream.SetParams(cp);
	}
	pPSStream.SetPos(m_pos);
	pPSStream.Update(0);

	//-------------------------------------------------------------------------

	{
	ParticleParams cp = ParticleParams();
	cp.m_nbMax = 50;
	cp.m_life = 1000;
	cp.m_lifeRandom = 500;
	cp.m_pos = Vec3f(100, 10, 100);
	cp.m_direction = Vec3f(0.f, -1.f, 0.f);
	cp.m_angle = glm::radians(10.f);
	cp.m_speed = 0;
	cp.m_speedRandom = 0;
	cp.m_gravity = Vec3f_ZERO;
	cp.m_flash = 0;
	cp.m_rotation = 0;
	cp.m_rotationRandomDirection = false;
	cp.m_rotationRandomStart = false;

	cp.m_startSegment.m_size = 10;
	cp.m_startSegment.m_sizeRandom = 10;
	cp.m_startSegment.m_color = Color(40, 40, 40, 50).to<float>();
	cp.m_startSegment.m_colorRandom = Color(51, 51, 51, 100).to<float>();

	cp.m_endSegment.m_size = 10;
	cp.m_endSegment.m_sizeRandom = 10;
	cp.m_endSegment.m_color = Color(0, 0, 0, 50).to<float>();
	cp.m_endSegment.m_colorRandom = Color(0, 0, 0, 100).to<float>();
	cp.m_texture.m_texLoop = false;

	cp.m_blendMode = RenderMaterial::Additive;
	cp.m_freq = 150.0f;
	cp.m_texture.set("graph/particles/fire", 0, 500);
	cp.m_spawnFlags = 0;
	
	pPSStream1.SetParams(cp);
	}
	pPSStream1.SetPos(m_pos + Vec3f(0, 10, 0));
	pPSStream1.Update(0);
}
Exemplo n.º 10
0
void ErrorReportDialog::onPaneChanged(int index)
{
	switch(index)
	{
	case Pane_Progress:
	{
		ui->btnBack->setEnabled(false);
		ui->btnNext->setEnabled(false);
		ui->btnSend->setEnabled(false);
		break;
	}

	case Pane_Welcome:
	{
		ui->btnBack->setEnabled(false);
		ui->btnNext->setEnabled(true);
		ui->btnSend->setEnabled(false);
		break;
	}

	case Pane_CrashDetails:
	{
		ui->btnBack->setEnabled(true);
		ui->btnNext->setEnabled(true);
		ui->btnSend->setEnabled(false);
		ui->textEditErrorDescription->setText(m_errorReport.GetErrorDescription());
		break;
	}

	case Pane_AttachedFiles:
	{
		ui->btnBack->setEnabled(true);
		ui->btnNext->setEnabled(true);
		ui->btnSend->setEnabled(false);
		QModelIndex idx = ui->listFiles->model()->index(0, 0);
		if(idx.isValid())
			ui->listFiles->selectionModel()->select(idx, QItemSelectionModel::Select);
		break;
	}

	case Pane_ReproSteps:
	{
		ui->btnBack->setEnabled(true);
		ui->btnNext->setEnabled(true);
		ui->btnSend->setEnabled(false);
		break;
	}

	case Pane_Send:
	{
		ui->btnBack->setEnabled(true);
		ui->btnNext->setEnabled(false);
		ui->btnSend->setEnabled(true);
		break;
	}

	case Pane_ExitSuccess:
	case Pane_ExitError:
	{
		ui->btnBack->setEnabled(false);
		ui->btnNext->setEnabled(false);
		ui->btnSend->setEnabled(false);
		ui->btnClose->setEnabled(true);
		break;
	}
	
	default:
		ARX_DEAD_CODE();
	}
}
Exemplo n.º 11
0
//***********************************************************************************************
// flags & 1 = blood spawn only
//-----------------------------------------------------------------------------------------------
//***********************************************************************************************
bool ARX_EQUIPMENT_Strike_Check(Entity * io_source, Entity * io_weapon, float ratioaim, long flags, EntityHandle targ) {
	
	ARX_PROFILE_FUNC();
	
	arx_assert(io_source);
	arx_assert(io_weapon);
	
	bool ret = false;
	EntityHandle source = io_source->index();
	EntityHandle weapon = io_weapon->index();
	Sphere sphere;

	EXCEPTIONS_LIST_Pos = 0;

	float drain_life = ARX_EQUIPMENT_GetSpecialValue(io_weapon, IO_SPECIAL_ELEM_DRAIN_LIFE);
	float paralyse = ARX_EQUIPMENT_GetSpecialValue(io_weapon, IO_SPECIAL_ELEM_PARALYZE);

	BOOST_FOREACH(const EERIE_ACTIONLIST & action, io_weapon->obj->actionlist) {
		
		float rad = GetHitValue(action.name);

		if(rad == -1)
			continue;
		
		sphere.origin = actionPointPosition(io_weapon->obj, action.idx);
		sphere.radius = rad; 

		if(source != PlayerEntityHandle)
			sphere.radius += 15.f;

		std::vector<EntityHandle> sphereContent;

		if(CheckEverythingInSphere(sphere, source, targ, sphereContent)) {
			BOOST_FOREACH(const EntityHandle & content, sphereContent) {
				if(ValidIONum(content)
						&& !(entities[content]->ioflags & IO_BODY_CHUNK))
				{
					long HIT_SPARK = 0;
					EXCEPTIONS_LIST[EXCEPTIONS_LIST_Pos] = content;
					EXCEPTIONS_LIST_Pos++;

					if(EXCEPTIONS_LIST_Pos >= MAX_IN_SPHERE)
						EXCEPTIONS_LIST_Pos--;

					Entity * target = entities[content];
			
					Vec3f pos;
					Color color = Color::white;
					long hitpoint = -1;
					float curdist = 999999.f;
					
					Vec3f vector = (sphere.origin - target->pos) * Vec3f(1.f, 0.5f, 1.f);
					vector = glm::normalize(vector);

					for(size_t ii = 0; ii < target->obj->facelist.size(); ii++) {
						if(target->obj->facelist[ii].facetype & POLY_HIDE)
							continue;

						float d = glm::distance(sphere.origin, target->obj->vertexlist3[target->obj->facelist[ii].vid[0]].v);

						if(d < curdist) {
							hitpoint = target->obj->facelist[ii].vid[0];
							curdist = d;
						}
					}

					if(hitpoint >= 0) {
						color = (target->ioflags & IO_NPC) ? target->_npcdata->blood_color : Color::white;
						pos = target->obj->vertexlist3[hitpoint].v;
					}
					else ARX_DEAD_CODE(); 
					
					float dmgs = 0.f;
					if(!(flags & 1)) {
						Vec3f posi;

						if(hitpoint >= 0) {
							posi = target->obj->vertexlist3[hitpoint].v;
							dmgs = ARX_EQUIPMENT_ComputeDamages(io_source, target, ratioaim, &posi);
						} else {
							dmgs = ARX_EQUIPMENT_ComputeDamages(io_source, target, ratioaim);
						}

						if(target->ioflags & IO_NPC) {
							ret = true;
							target->spark_n_blood = 0;
							target->_npcdata->SPLAT_TOT_NB = 0;

							if(drain_life > 0.f) {
								float life_gain = std::min(dmgs, drain_life);
								life_gain = std::min(life_gain, target->_npcdata->lifePool.current);
								life_gain = std::max(life_gain, 0.f);
								ARX_DAMAGES_HealInter(io_source, life_gain);
							}

							if(paralyse > 0.f) {
								float ptime = std::min(dmgs * 1000.f, paralyse);
								ARX_SPELLS_Launch(SPELL_PARALYSE, weapon, SPELLCAST_FLAG_NOMANA | SPELLCAST_FLAG_NOCHECKCANCAST
												  , 5, content, (long)(ptime));
							}
						}

						if(io_source == entities.player())
							ARX_DAMAGES_DurabilityCheck(io_weapon, 0.2f);
					}

					if(dmgs > 0.f || ((target->ioflags & IO_NPC) && target->spark_n_blood == SP_BLOODY)) {
						if(target->ioflags & IO_NPC) {
							target->spark_n_blood = SP_BLOODY;

							if(!(flags & 1)) {
								ARX_PARTICLES_Spawn_Splat(pos, dmgs, color);

								Sphere sp;
								float power;
								power = (dmgs * ( 1.0f / 40 )) + 0.7f;
								Vec3f vect;
								vect.x = target->obj->vertexlist3[hitpoint].v.x - io_source->pos.x;
								vect.y = 0;
								vect.z = target->obj->vertexlist3[hitpoint].v.z - io_source->pos.z;
								vect = glm::normalize(vect);
								sp.origin.x = target->obj->vertexlist3[hitpoint].v.x + vect.x * 30.f;
								sp.origin.y = target->obj->vertexlist3[hitpoint].v.y;
								sp.origin.z = target->obj->vertexlist3[hitpoint].v.z + vect.z * 30.f;
								sp.radius = 3.5f * power * 20;

								if(CheckAnythingInSphere(sp, PlayerEntityHandle, CAS_NO_NPC_COL)) {
									Color3f rgb = color.to<float>();
									
									Sphere splatSphere;
									splatSphere.origin = sp.origin;
									splatSphere.radius = 30.f;
									SpawnGroundSplat(splatSphere, rgb, 1);
								}
							}

							ARX_PARTICLES_Spawn_Blood2(pos, dmgs, color, target);
						} else {
							if(target->ioflags & IO_ITEM)
								ARX_PARTICLES_Spawn_Spark(pos, Random::get(0, 3), SpawnSparkType_Default);
							else
								ARX_PARTICLES_Spawn_Spark(pos, Random::get(0, 30), SpawnSparkType_Default);

							ARX_NPC_SpawnAudibleSound(pos, io_source);

							if(io_source == entities.player())
								HIT_SPARK = 1;
						}
					} else if((target->ioflags & IO_NPC) && (dmgs <= 0.f || target->spark_n_blood == SP_SPARKING)) {
						unsigned int nb;

						if(target->spark_n_blood == SP_SPARKING)
							nb = Random::get(0, 3);
						else
							nb = 30;

						if(target->ioflags & IO_ITEM)
							nb = 1;

						ARX_PARTICLES_Spawn_Spark(pos, nb, SpawnSparkType_Default);
						ARX_NPC_SpawnAudibleSound(pos, io_source);
						target->spark_n_blood = SP_SPARKING;

						if(!(target->ioflags & IO_NPC))
							HIT_SPARK = 1;
					} else if(dmgs <= 0.f && ((target->ioflags & IO_FIX) || (target->ioflags & IO_ITEM))) {
						unsigned int nb;

						if(target->spark_n_blood == SP_SPARKING)
							nb = Random::get(0, 3);
						else
							nb = 30;

						if(target->ioflags & IO_ITEM)
							nb = 1;

						ARX_PARTICLES_Spawn_Spark(pos, nb, SpawnSparkType_Default);
						ARX_NPC_SpawnAudibleSound(pos, io_source);
						target->spark_n_blood = SP_SPARKING;

						if (!(target->ioflags & IO_NPC))
							HIT_SPARK = 1;
					}

					if(HIT_SPARK) {
						if(!io_source->isHit) {
							ARX_DAMAGES_DurabilityCheck(io_weapon, 1.f);
							io_source->isHit = true;
							
								std::string _weapon_material = "metal";
								const std::string * weapon_material = &_weapon_material;

								if(!io_weapon->weaponmaterial.empty()) {
									weapon_material = &io_weapon->weaponmaterial;
								}

								char bkg_material[128];

								if(ARX_MATERIAL_GetNameById(target->material, bkg_material))
									ARX_SOUND_PlayCollision(*weapon_material, bkg_material, 1.f, 1.f, sphere.origin, NULL);
						}
					}
				}
			}
		}

		const EERIEPOLY * ep = CheckBackgroundInSphere(sphere);
		if(ep) {
			if(io_source == entities.player()) {
				if(!io_source->isHit) {
					ARX_DAMAGES_DurabilityCheck(io_weapon, 1.f);
					io_source->isHit = true;
					
						std::string _weapon_material = "metal";
						const std::string * weapon_material = &_weapon_material;
						if(!io_weapon->weaponmaterial.empty()) {
							weapon_material = &io_weapon->weaponmaterial;
						}

						std::string bkg_material = "earth";

						if(ep && ep->tex && !ep->tex->m_texName.empty())
							bkg_material = GetMaterialString(ep->tex->m_texName);

						ARX_SOUND_PlayCollision(*weapon_material, bkg_material, 1.f, 1.f, sphere.origin, io_source);
				}
			}

			ARX_PARTICLES_Spawn_Spark(sphere.origin, Random::get(0, 10), SpawnSparkType_Default);
			ARX_NPC_SpawnAudibleSound(sphere.origin, io_source);
		}
	}

	return ret;
}
Exemplo n.º 12
0
static float ARX_THROWN_ComputeDamages(long thrownum, EntityHandle source,
                                       EntityHandle target) {
	
	float distance_limit = 1000.f;
	Entity * io_target = entities[target];
	Entity * io_source = entities[source];

	SendIOScriptEvent(io_target, SM_AGGRESSION);

	float distance = fdist(Thrown[thrownum].position, Thrown[thrownum].initial_position);
	float distance_modifier = 1.f;

	if(distance < distance_limit * 2.f) {
		distance_modifier = distance / distance_limit;

		if(distance_modifier < 0.5f)
			distance_modifier = 0.5f;
	} else {
		distance_modifier = 2.f;
	}

	float attack, dmgs, backstab, ac;

	backstab = 1.f;
	bool critical = false;

	if(source == 0) {
		attack = Thrown[thrownum].damages;

		if(Random::getf(0.f, 100.f) <= float(player.m_attributeFull.dexterity - 9) * 2.f
						   + float(player.m_skillFull.projectile * 0.2f)) {
			if(SendIOScriptEvent(io_source, SM_CRITICAL, "bow") != REFUSE)
				critical = true;
		}

		dmgs = attack;

		if(io_target->_npcdata->npcflags & NPCFLAG_BACKSTAB) {
			if(Random::getf(0.f, 100.f) <= player.m_skillFull.stealth) {
				if(SendIOScriptEvent(io_source, SM_BACKSTAB, "bow") != REFUSE)
					backstab = 1.5f;
			}
		}
	} else {
		// TODO treat NPC !!!

		ARX_DEAD_CODE();
		attack = 0;
		dmgs = 0;
	}

	float absorb;

	if(target == 0) {
		ac = player.m_miscFull.armorClass;
		absorb = player.m_skillFull.defense * .5f;
	} else {
		ac = ARX_INTERACTIVE_GetArmorClass(io_target);
		absorb = io_target->_npcdata->absorb;
	}

	char wmat[64];

	std::string _amat = "flesh";
	const std::string * amat = &_amat;

	strcpy(wmat, "dagger");

	if(!io_target->armormaterial.empty()) {
		amat = &io_target->armormaterial;
	}

	if(io_target == entities.player()) {
		if(ValidIONum(player.equiped[EQUIP_SLOT_ARMOR])) {
			Entity * io = entities[player.equiped[EQUIP_SLOT_ARMOR]];
			if(io && !io->armormaterial.empty()) {
				amat = &io->armormaterial;
			}
		}
	}

	float power;
	power = dmgs * ( 1.0f / 20 );

	if(power > 1.f)
		power = 1.f;

	power = power * 0.15f + 0.85f;

	ARX_SOUND_PlayCollision(*amat, wmat, power, 1.f, Thrown[thrownum].position, io_source);

	dmgs *= backstab;
	dmgs -= dmgs * (absorb * ( 1.0f / 100 ));

	float chance = 100.f - (ac - attack);
	float dice = Random::getf(0.f, 100.f);

	if(dice <= chance) {
		if(dmgs > 0.f) {
			if(critical)
				dmgs *= 1.5f;

			dmgs *= distance_modifier;
			return dmgs;
		}
	}

	return 0.f;
}
Exemplo n.º 13
0
bool Note::allocate() {
	
	if(allocatedForRatio == sizeRatio()) {
		return background ? true : false;
	}
	
	deallocate();
	
	// Allocate textures and calculate sizes
	
	Vec2f newPos;
	Vec2f newTextStart;
	Vec2f newTextEnd;
	
	Vec2f prevButtonOffset;
	Vec2f nextButtonOffset;
	
	size_t maxPages = 1;
	
	Vec2f scale = Vec2f(minSizeRatio(), minSizeRatio());
	
	if(_type == QuestBook) {
		// TODO change this once the aspect ratio in character screen, spell book, etc. is fixed.
		scale = sizeRatio();
	}
	
	switch(_type) {
		
		// TODO this information should not be hardcoded
		
		case Notice: {
			background = TextureContainer::LoadUI("graph/interface/book/notice");
			if(background) {
				newPos = Vec2f(320 * Xratio - background->m_dwWidth * 0.5f * scale.x, 47.f * scale.y);
				newTextStart = Vec2f(50.f, 50.f);
				newTextEnd = Vec2f(background->size()) - Vec2f(50.f, 50.f);
			}
			break;
		}
		
		case SmallNote: {
			background = TextureContainer::LoadUI("graph/interface/book/bignote");
			if(background) {
				newPos = Vec2f(320 * Xratio - background->m_dwWidth * 0.5f * scale.x, 47.f * scale.y);
				newTextStart = Vec2f(30.f, 30.f);
				newTextEnd = Vec2f(background->size()) - Vec2f(30.f, 40.f);
			}
			break;
		}
		
		case BigNote: {
			background = TextureContainer::LoadUI("graph/interface/book/very_bignote");
			if(background) {
				newPos = Vec2f(320 * Xratio - background->m_dwWidth * 0.5f * scale.x, 47.f * scale.y);
				newTextStart = Vec2f(40.f, 40.f);
				newTextEnd = Vec2f(background->size()) * Vec2f(0.5f, 1.f) - Vec2f(10.f, 40.f);
				maxPages = 2;
			}
			break;
		}
		
		case Book: {
			background = TextureContainer::LoadUI("graph/interface/book/ingame_books");
			prevPage = TextureContainer::LoadUI("graph/interface/book/left_corner");
			nextPage = TextureContainer::LoadUI("graph/interface/book/right_corner");
			if(background) {
				newPos = Vec2f(320 * Xratio - background->m_dwWidth * 0.5f * scale.x, 47.f * scale.y);
				newTextStart = Vec2f(40.f, 20.f);
				newTextEnd = Vec2f(background->size()) * Vec2f(0.5f, 1.f) - Vec2f(10.f, 40.f);
				maxPages = std::numeric_limits<size_t>::max();
				prevButtonOffset = Vec2f(8.f, -6.f);
				nextButtonOffset = Vec2f(-15.f, -6.f);
			}
			break;
		}
		
		case QuestBook: {
			background = TextureContainer::LoadUI("graph/interface/book/questbook");
			prevPage = TextureContainer::LoadUI("graph/interface/book/left_corner_original");
			nextPage = TextureContainer::LoadUI("graph/interface/book/right_corner_original");
			if(background) {
				newPos = Vec2f(97, 64) * scale;
				newTextStart = Vec2f(40.f, 40.f);
				newTextEnd = Vec2f(background->size()) * Vec2f(0.5f, 1.f) - Vec2f(10.f, 65.f);
				maxPages = std::numeric_limits<size_t>::max();
				prevButtonOffset = Vec2f(8.f, -6.f);
				nextButtonOffset = Vec2f(-15.f, -6.f);
			}
		}
		
		case Undefined: break; // Cannot handle notes of undefined type.
	}
	
	if(!background) {
		allocatedForRatio = sizeRatio();
		return false;
	}
	
	_area = Rectf(newPos,
	             background->m_dwWidth * scale.x, background->m_dwHeight * scale.y);
	_textArea = Rect(Vec2i(newTextStart * scale), Vec2i(newTextEnd * scale));
	_pageSpacing = 20 * scale.x;
	if(prevPage) {
		Vec2f pos = Vec2f(0.f, background->m_dwHeight - prevPage->m_dwHeight) + prevButtonOffset;
		pos *= scale;
		_prevPageButton = Rectf(newPos + pos,
		                       prevPage->m_dwWidth * scale.x, prevPage->m_dwHeight * scale.y);
	}
	if(nextPage) {
		Vec2f pos = Vec2f(background->size() - nextPage->size()) + nextButtonOffset;
		pos *= scale;
		_nextPageButton = Rectf(newPos + pos,
		                       nextPage->m_dwWidth * scale.x, nextPage->m_dwHeight * scale.y);
	}
	
	// Split text into pages
	
	// TODO This buffer and related string copies can be avoided by
	// using iterators for ARX_UNICODE_ForceFormattingInRect
	std::string buffer = _text;
	
	while(!buffer.empty()) {
		
		// Change the note type if the text is too long.
		if(pages.size() >= maxPages) {
			switch(_type) {
				case Notice: _type = SmallNote; break;
				case SmallNote: _type = BigNote; break;
				case BigNote: _type = Book; break;
				default: ARX_DEAD_CODE(); break;
			}
			return allocate();
		}
		
		long pageSize = ARX_UNICODE_ForceFormattingInRect(hFontInGameNote, buffer, _textArea);
		if(pageSize <= 0) {
			LogWarning << "Error splitting note text into pages";
			pages.push_back(buffer);
			break;
		}
		
		pages.push_back(buffer.substr(0, pageSize));
		
		// Skip whitespace at the start of pages.
		while(size_t(pageSize) < buffer.size() && std::isspace(buffer[pageSize])) {
			pageSize++;
		}
		
		buffer = buffer.substr(pageSize);
	}
	
	// Clamp the current page to a valid page.
	setPage(_page);
	
	allocatedForRatio = sizeRatio();
	
	return true;
}
Exemplo n.º 14
0
void CreateFieldSpell::Launch()
{
	unsigned long start = (unsigned long)(arxtime);
	if(m_flags & SPELLCAST_FLAG_RESTORE) {
		start -= std::min(start, 4000ul);
	}
	m_timcreation = start;
	
	m_duration = (m_launchDuration > -1) ? m_launchDuration : 800000;
	m_hasDuration = true;
	m_fManaCostPerSecond = 1.2f;
	
	Vec3f target;
	float beta = 0.f;
	bool displace = false;
	if(m_caster == PlayerEntityHandle) {
		target = entities.player()->pos;
		beta = player.angle.getPitch();
		displace = true;
	} else {
		if(ValidIONum(m_caster)) {
			Entity * io = entities[m_caster];
			target = io->pos;
			beta = io->angle.getPitch();
			displace = (io->ioflags & IO_NPC) == IO_NPC;
		} else {
			ARX_DEAD_CODE();
		}
	}
	if(displace) {
		target += angleToVectorXZ(beta) * 250.f;
	}
	
	ARX_SOUND_PlaySFX(SND_SPELL_CREATE_FIELD, &target);
	
	res::path cls = "graph/obj3d/interactive/fix_inter/blue_cube/blue_cube";
	Entity * io = AddFix(cls, -1, IO_IMMEDIATELOAD);
	if(io) {
		
		ARX_INTERACTIVE_HideGore(io);
		RestoreInitialIOStatusOfIO(io);
		m_entity = io->index();
		io->scriptload = 1;
		io->ioflags |= IO_NOSAVE | IO_FIELD;
		io->initpos = io->pos = target;
		SendInitScriptEvent(io);
		
		m_field.Create(target);
		m_field.SetDuration(m_duration);
		m_field.lLightId = GetFreeDynLight();
		
		if(lightHandleIsValid(m_field.lLightId)) {
			EERIE_LIGHT * light = lightHandleGet(m_field.lLightId);
			
			light->intensity = 0.7f + 2.3f;
			light->fallend = 500.f;
			light->fallstart = 400.f;
			light->rgb = Color3f(0.8f, 0.0f, 1.0f);
			light->pos = m_field.eSrc - Vec3f(0.f, 150.f, 0.f);
		}
		
		m_duration = m_field.GetDuration();
		
		if(m_flags & SPELLCAST_FLAG_RESTORE) {
			m_field.Update(4000);
		}
		
	} else {
		m_duration = 0;
	}
}
Exemplo n.º 15
0
void ARX_PATH_UpdateAllZoneInOutInside() {
	
	ARX_PROFILE_FUNC();
	
	arx_assert(entities.player());
	
	static size_t count = 1;
	
	long f = glm::clamp(static_cast<long>(framedelay), 10l, 50l);
	
	if(count >= entities.size()) {
		count = 1;
	}

	if(entities.size() > 1)
		for(long tt = 0; tt < f; tt++) {
			const EntityHandle i = EntityHandle(count);
			Entity * io = entities[i];
			

			if(count < entities.size()
			   && io
			   && io->ioflags & (IO_NPC | IO_ITEM)
			   && io->show != SHOW_FLAG_MEGAHIDE
			) {
				arx_assert(io->show != SHOW_FLAG_DESTROYED);
				ARX_PATH * current = ARX_PATH_CheckInZone(io);
				ARX_PATH * last = io->inzone;

				if(!last && !current) { // Not in a zone
				} else if(last == current) { // Stayed inside last zone
					if(io->show != io->inzone_show) {
						io->inzone_show = io->show;
						goto entering;
					}
				} else if(last && !current) { // Leaving last zone
					SendIOScriptEvent(io, SM_LEAVEZONE, last->name);

					if(!last->controled.empty()) {
						EntityHandle t = entities.getById(last->controled);

						if(t != EntityHandle::Invalid) {
							std::string str = io->idString() + ' ' + last->name;
							SendIOScriptEvent(entities[t], SM_CONTROLLEDZONE_LEAVE, str);
						}
					}
				} else if(!last && current) { // Entering current zone
					io->inzone_show = io->show;
				entering:

					if(JUST_RELOADED && (current->name == "ingot_maker" || current->name == "mauld_user")) {
						ARX_DEAD_CODE(); // TODO remove JUST_RELOADED global
					} else {
						SendIOScriptEvent(io, SM_ENTERZONE, current->name);

						if(!current->controled.empty()) {
							EntityHandle t = entities.getById(current->controled);

							if(t != EntityHandle::Invalid) {
								std::string params = io->idString() + ' ' + current->name;
								SendIOScriptEvent(entities[t], SM_CONTROLLEDZONE_ENTER, params);
							}
						}
					}
				} else { // Changed from last to current zone
					SendIOScriptEvent(io, SM_LEAVEZONE, last->name);

					if(!last->controled.empty()) {
						EntityHandle t = entities.getById(last->controled);

						if(t != EntityHandle::Invalid) {
							std::string str = io->idString() + ' ' + last->name;
							SendIOScriptEvent(entities[t], SM_CONTROLLEDZONE_LEAVE, str);
						}
					}

					io->inzone_show = io->show;
					SendIOScriptEvent(io, SM_ENTERZONE, current->name);

					if(!current->controled.empty()) {
						EntityHandle t = entities.getById(current->controled);

						if(t != EntityHandle::Invalid) {
							std::string str = io->idString() + ' ' + current->name;
							SendIOScriptEvent(entities[t], SM_CONTROLLEDZONE_ENTER, str);
						}
					}
				}

				io->inzone = current;
			}
			
			count++;

			if(count >= entities.size())
				count = 1;
		}

	// player check*************************************************
	{
		ARX_PATH * current = ARX_PATH_CheckPlayerInZone();
		ARX_PATH * last = player.inzone;

		if(!last && !current) { // Not in a zone
		} else if(last == current) { // Stayed inside last zone
		} else if(last && !current) { // Leaving last zone
			SendIOScriptEvent(entities.player(), SM_LEAVEZONE, last->name);
			CHANGE_LEVEL_ICON = -1;

			if(!last->controled.empty()) {
				EntityHandle t = entities.getById(last->controled);

				if(t != EntityHandle::Invalid) {
					SendIOScriptEvent(entities[t], SM_CONTROLLEDZONE_LEAVE, "player " + last->name);
				}
			}
		} else if(!last && current) { // Entering current zone
			SendIOScriptEvent(entities.player(), SM_ENTERZONE, current->name);

			if(current->flags & PATH_AMBIANCE && !current->ambiance.empty())
				ARX_SOUND_PlayZoneAmbiance(current->ambiance, ARX_SOUND_PLAY_LOOPED, current->amb_max_vol * ( 1.0f / 100 ));

			if(current->flags & PATH_FARCLIP) {
				desired.flags |= GMOD_ZCLIP;
				desired.zclip = current->farclip;
			}

			if (current->flags & PATH_REVERB)
			{
			}

			if(current->flags & PATH_RGB) {
				desired.flags |= GMOD_DCOLOR;
				desired.depthcolor = current->rgb;
			}

			if(!current->controled.empty()) {
				EntityHandle t = entities.getById(current->controled);

				if(t != EntityHandle::Invalid) {
					SendIOScriptEvent(entities[t], SM_CONTROLLEDZONE_ENTER, "player " + current->name);
				}
			}
		} else { // Changed from last to current zone
			if(!last->controled.empty()) {
				EntityHandle t = entities.getById(last->controled);

				if(t != EntityHandle::Invalid) {
					SendIOScriptEvent(entities[t], SM_CONTROLLEDZONE_LEAVE, "player " + current->name);
				}
			}

			if(!last->controled.empty()) {
				EntityHandle t = entities.getById(current->controled);

				if(t != EntityHandle::Invalid) {
					SendIOScriptEvent(entities[t], SM_CONTROLLEDZONE_ENTER, "player " + current->name);
				}
			}
		}

		player.inzone = current;
	}
	
	JUST_RELOADED = 0;
}