コード例 #1
0
void PlayerInventoryHud::dragEntity(Entity * io, const Vec2s &pos) {
	Vec2f anchorPos = g_playerInventoryHud.anchorPosition();
	
	Vec2i iPos = Vec2i(anchorPos);
	
	if(g_playerInventoryHud.containsPos(pos)) {
		if(!GInput->actionPressed(CONTROLS_CUST_STEALTHMODE)) {
			if((io->ioflags & IO_ITEM) && io->_itemdata->count > 1) {
				if(io->_itemdata->count - 1 > 0) {
					
					Entity * ioo = AddItem(io->classPath());
					ioo->show = SHOW_FLAG_NOT_DRAWN;
					ioo->_itemdata->count = 1;
					io->_itemdata->count--;
					ioo->scriptload = 1;
					ARX_SOUND_PlayInterface(SND_INVSTD);
					Set_DragInter(ioo);
					RemoveFromAllInventories(ioo);
					sInventory = 1;
					
					float fX = (pos.x - iPos.x) / (32 * m_scale);
					float fY = (pos.y - iPos.y) / (32 * m_scale);
					
					sInventoryPos.x = checked_range_cast<short>(fX);
					sInventoryPos.y = checked_range_cast<short>(fY);
					
					SendInitScriptEvent(ioo);
					ARX_INVENTORY_IdentifyIO(ioo);
					return;
				}
			}
		}
	}
	
	arx_assert(player.bag >= 0);
	arx_assert(player.bag <= 3);
	
	for(size_t bag = 0; bag < size_t(player.bag); bag++)
	for(size_t y = 0; y < INVENTORY_Y; y++)
	for(size_t x = 0; x < INVENTORY_X; x++) {
		INVENTORY_SLOT & slot = inventory[bag][x][y];
		
		if(slot.io == io) {
			slot.io = NULL;
			slot.show = true;
			sInventory = 1;
			
			float fX = (pos.x - iPos.x) / (32 * m_scale);
			float fY = (pos.y - iPos.y) / (32 * m_scale);
			
			sInventoryPos.x = checked_range_cast<short>(fX);
			sInventoryPos.y = checked_range_cast<short>(fY);
		}
	}
	
	Set_DragInter(io);
	
	RemoveFromAllInventories(io);
	ARX_INVENTORY_IdentifyIO(io);
}
コード例 #2
0
//***********************************************************************************************
// flags & 1 == destroyed !
//***********************************************************************************************
void ARX_EQUIPMENT_UnEquip(Entity * target, Entity * tounequip, long flags)
{
	if(!target || !tounequip)
		return;

	if(target != entities.player())
		return;

	for(size_t i = 0; i < MAX_EQUIPED; i++) {
		if(ValidIONum(player.equiped[i]) && entities[player.equiped[i]] == tounequip) {
			EERIE_LINKEDOBJ_UnLinkObjectFromObject(target->obj, tounequip->obj);
			ARX_EQUIPMENT_Release(player.equiped[i]);
			target->bbox2D.min.x = 9999;
			target->bbox2D.max.x = -9999;
			
			if(!flags) {
				if(!DRAGINTER) {
					ARX_SOUND_PlayInterface(SND_INVSTD);
					Set_DragInter(tounequip);
				} else {
					giveToPlayer(tounequip);
				}
			}
			
			EVENT_SENDER = tounequip;
			SendIOScriptEvent(entities.player(), SM_EQUIPOUT);
			EVENT_SENDER = entities.player();
			SendIOScriptEvent(tounequip, SM_EQUIPOUT);
		}
	}

	if(tounequip->type_flags & (OBJECT_TYPE_HELMET | OBJECT_TYPE_ARMOR | OBJECT_TYPE_LEGGINGS))
		ARX_EQUIPMENT_RecreatePlayerMesh();
}
コード例 #3
0
ファイル: Hud.cpp プロジェクト: BSzili/ArxLibertatis
void CurrentTorchIconGui::updateInput() {
	if(player.torch) {
		
		if(m_rect.contains(Vec2f(DANAEMouse))) {
			eMouseState = MOUSE_IN_TORCH_ICON;
			cursorSetInteraction();
			
			if(!DRAGINTER && !PLAYER_MOUSELOOK_ON && DRAGGING) {
				Entity * io = player.torch;
				player.torch->show = SHOW_FLAG_IN_SCENE;
				ARX_SOUND_PlaySFX(SND_TORCH_END);
				ARX_SOUND_Stop(SND_TORCH_LOOP);
				player.torch = NULL;
				lightHandleGet(torchLightHandle)->exist = 0;
				io->ignition = 1;
				Set_DragInter(io);
			} else {
				if(eeMouseDoubleClick1() && !COMBINE) {
					COMBINE = player.torch;
				}
				
				if(eeMouseUp2()) {
					ARX_PLAYER_ClickedOnTorch(player.torch);
					TRUE_PLAYER_MOUSELOOK_ON = false;
				}
			}
		}
	}
}
コード例 #4
0
void Entity::cleanReferences() {
	
	if(DRAGINTER == this) {
		Set_DragInter(NULL);
	}
	
}
コード例 #5
0
ファイル: Entity.cpp プロジェクト: BSzili/ArxLibertatis
void Entity::cleanReferences() {
	
	ARX_INTERACTIVE_DestroyIOdelayedRemove(this);
	
	if(DRAGINTER == this) {
		Set_DragInter(NULL);
	}
	
	if(FlyingOverIO == this) {
		FlyingOverIO = NULL;
	}
	
	if(COMBINE == this) {
		COMBINE = NULL;
	}
	
	if(pIOChangeWeapon == this) {
		pIOChangeWeapon = NULL; // TODO we really need a proper weak_ptr
	}
	
	if(ioSteal == this) {
		ioSteal = NULL;
	}
	
	if(!FAST_RELEASE) {
		TREATZONE_RemoveIO(this);
	}
	gameFlags &= ~GFLAG_ISINTREATZONE;
	
	ARX_INTERACTIVE_DestroyDynamicInfo(this);
	
	RemoveFromAllInventories(this);
	
	ARX_SCRIPT_Timer_Clear_For_IO(this);
	
	spells.endByCaster(index());
	
	lightHandleDestroy(ignit_light);
	
	if(ignit_sound != audio::INVALID_ID) {
		ARX_SOUND_Stop(ignit_sound), ignit_sound = audio::INVALID_ID;
	}
	
}
コード例 #6
0
ファイル: Damage.cpp プロジェクト: byouloh/ArxLibertatis
void ARX_DAMAGES_ForceDeath(Entity * io_dead, Entity * io_killer) {
	
	if(io_dead->mainevent == "dead") {
		return;
	}

	Entity * old_sender = EVENT_SENDER;
	EVENT_SENDER = io_killer;

	if(io_dead == DRAGINTER)
		Set_DragInter(NULL);

	if(io_dead == FlyingOverIO)
		FlyingOverIO = NULL;

	if((MasterCamera.exist & 1) && (MasterCamera.io == io_dead))
		MasterCamera.exist = 0;

	if((MasterCamera.exist & 2) && (MasterCamera.want_io == io_dead))
		MasterCamera.exist = 0;

	lightHandleDestroy(io_dead->dynlight);
	lightHandleDestroy(io_dead->halo.dynlight);
	
	//Kill all speeches

	ARX_NPC_Behaviour_Reset(io_dead);

	ARX_SPEECH_ReleaseIOSpeech(io_dead);

	//Kill all Timers...
	ARX_SCRIPT_Timer_Clear_For_IO(io_dead);

	if(io_dead->mainevent != "dead") {
		if(SendIOScriptEvent(io_dead, SM_DIE) != REFUSE && ValidIOAddress(io_dead)) {
			io_dead->infracolor = Color3f::blue;
		}
	}
	
	if (!ValidIOAddress(io_dead))
		return;

	ARX_SCRIPT_SetMainEvent(io_dead, "dead");

	if(fartherThan(io_dead->pos, ACTIVECAM->orgTrans.pos, 3200.f)) {
		io_dead->animlayer[0].ctime = 9999999;
		io_dead->animBlend.lastanimtime = 0;
	}

	std::string killer;

	if(io_dead->ioflags & IO_NPC)
		io_dead->_npcdata->weaponinhand = 0;

	ARX_INTERACTIVE_DestroyDynamicInfo(io_dead);

	if(io_killer == entities.player()) {
		killer = "player";
	} else {
		if(io_killer)
			killer = io_killer->idString();
	}

	for(size_t i = 1; i < entities.size(); i++) {
		const EntityHandle handle = EntityHandle(i);
		Entity * ioo = entities[handle];

		if(ioo == io_dead)
			continue;

		if(ioo && (ioo->ioflags & IO_NPC)) {
			if(ValidIONum(ioo->targetinfo))
				if(entities[ioo->targetinfo] == io_dead) {
					EVENT_SENDER = io_dead; 
					Stack_SendIOScriptEvent(entities[handle], SM_NULL, killer, "target_death");
					ioo->targetinfo = EntityHandle(TARGET_NONE);
					ioo->_npcdata->reachedtarget = 0;
				}

			if(ValidIONum(ioo->_npcdata->pathfind.truetarget))
				if(entities[ioo->_npcdata->pathfind.truetarget] == io_dead) {
					EVENT_SENDER = io_dead; 
					Stack_SendIOScriptEvent(entities[handle], SM_NULL, killer, "target_death");
					ioo->_npcdata->pathfind.truetarget = EntityHandle(TARGET_NONE);
					ioo->_npcdata->reachedtarget = 0;
				}
		}
	}

	io_dead->animlayer[1].cur_anim = NULL;
	io_dead->animlayer[2].cur_anim = NULL;
	io_dead->animlayer[3].cur_anim = NULL;

	if(io_dead->ioflags & IO_NPC) {
		io_dead->_npcdata->lifePool.current = 0;

		if(io_dead->_npcdata->weapon) {
			Entity * ioo = io_dead->_npcdata->weapon;
			if(ValidIOAddress(ioo)) {
				ioo->show = SHOW_FLAG_IN_SCENE;
				ioo->ioflags |= IO_NO_NPC_COLLIDE;
				ioo->pos = ioo->obj->vertexlist3[ioo->obj->origin].v;
				ioo->velocity = Vec3f(0.f, 13.f, 0.f);
				ioo->stopped = 0;
			}
		}
	}

	EVENT_SENDER = old_sender;
}
コード例 #7
0
void PlayerInventoryHud::dropEntity() {
	if(!(player.Interface & INTER_INVENTORY) && !(player.Interface & INTER_INVENTORYALL))
		return;
	
	if(InventoryY != 0)
		return;
	
	if(!g_playerInventoryHud.containsPos(DANAEMouse))
		return;
	
	Vec2s s = DRAGINTER->m_inventorySize;
	
	int bag = 0;
	
	Vec2f anchorPos = g_playerInventoryHud.anchorPosition();
	
	float fCenterX	= anchorPos.x;
	float fSizY		= anchorPos.y;
	
	short iPosX = checked_range_cast<short>(fCenterX);
	short iPosY = checked_range_cast<short>(fSizY);
	
	Vec2s t = Vec2s_ZERO;
	
	if(player.Interface & INTER_INVENTORY) {
		t.x = DANAEMouse.x - iPosX;
		t.y = DANAEMouse.y - iPosY;
		t.x = t.x / (32 * m_scale); 
		t.y = t.y / (32 * m_scale); 
		
		if((t.x >= 0) && (t.x <= 16 - s.x) && (t.y >= 0) && (t.y <= 3 - s.y)) {
			bag = g_currentInventoryBag;
		} else {
			return;
		}
	} else {
		bool bOk = false;
		
		float fBag	= (player.bag - 1) * (-121 * m_scale);
		
		short iY = checked_range_cast<short>(fBag);
		
		//We must enter the for-loop to initialyze tx/ty
		arx_assert(0 < player.bag);
		
		for(int i = 0; i < player.bag; i++) {
			t.x = DANAEMouse.x - iPosX;
			t.y = DANAEMouse.y - iPosY - iY; 
			
			if((t.x >= 0) && (t.y >= 0)) {
				t.x = t.x / (32 * m_scale); 
				t.y = t.y / (32 * m_scale); 
				
				if((t.x >= 0) && (t.x <= 16 - s.x) && (t.y >= 0) && (t.y <= 3 - s.y)) {
					bOk = true;
					bag = i;
					break;
				}
			}
			
			float fRatio = (121 * m_scale);
			
			iY += checked_range_cast<short>(fRatio);
		}
		
		if(!bOk)
			return;
	}
	
	if(DRAGINTER->ioflags & IO_GOLD) {
		ARX_PLAYER_AddGold(DRAGINTER);
		Set_DragInter(NULL);
		return;
	}
	
	for(long j = 0; j < s.y; j++)
		for(long i = 0; i < s.x; i++) {
			Entity * ioo = inventory[bag][t.x+i][t.y+j].io;
			
			if(!ioo)
				continue;
			
			ARX_INVENTORY_IdentifyIO(ioo);
			
			if(   ioo->_itemdata->playerstacksize > 1
			&& IsSameObject(DRAGINTER, ioo)
			&& ioo->_itemdata->count < ioo->_itemdata->playerstacksize
			) {
				ioo->_itemdata->count += DRAGINTER->_itemdata->count;
				
				if(ioo->_itemdata->count > ioo->_itemdata->playerstacksize) {
					DRAGINTER->_itemdata->count = ioo->_itemdata->count - ioo->_itemdata->playerstacksize;
					ioo->_itemdata->count = ioo->_itemdata->playerstacksize;
				} else {
					DRAGINTER->_itemdata->count = 0;
				}
				
				ioo->scale = 1.f;
				ARX_INVENTORY_Declare_InventoryIn(DRAGINTER);
				
				if(!DRAGINTER->_itemdata->count) {
					DRAGINTER->destroy();
				}
				
				ARX_SOUND_PlayInterface(SND_INVSTD);
				return;
			}
			
			return;
		}
	
	for(long j = 0; j < s.y; j++) {
		for(long i = 0; i < s.x; i++) {
			inventory[bag][t.x+i][t.y+j].io = DRAGINTER;
			inventory[bag][t.x+i][t.y+j].show = false;
		}
	}
	
	inventory[bag][t.x][t.y].show = true;
	
	ARX_INVENTORY_Declare_InventoryIn(DRAGINTER);
	ARX_SOUND_PlayInterface(SND_INVSTD);
	DRAGINTER->show = SHOW_FLAG_IN_INVENTORY;
	Set_DragInter(NULL);
}
コード例 #8
0
ファイル: Cursor.cpp プロジェクト: Drakesinger/ArxLibertatis
bool Manage3DCursor(Entity * io, bool simulate) {
	
	arx_assert(io);
	
	if(BLOCK_PLAYER_CONTROLS)
		return false;

	float ag = player.angle.getYaw();

	if(ag > 180)
		ag = ag - 360;

	float drop_miny = (float)(g_size.center().y) - g_size.center().y * (ag * (1.f/70));

	if(DANAEMouse.y < drop_miny)
		return false;
	
	Anglef temp = Anglef::ZERO;

	if(io->ioflags & IO_INVERTED) {
		temp.setYaw(180.f);
		temp.setPitch(-MAKEANGLE(270.f - io->angle.getPitch() - (player.angle.getPitch() - STARTED_ANGLE)));
	} else {
		temp.setPitch(MAKEANGLE(270.f - io->angle.getPitch() - (player.angle.getPitch() - STARTED_ANGLE)));
	}
	
	EERIE_3D_BBOX bbox;
	for(size_t i = 0; i < io->obj->vertexlist.size(); i++) {
		bbox.add(io->obj->vertexlist[i].v);
	}
	
	Vec3f mvectx = angleToVectorXZ(player.angle.getPitch() - 90.f);
	
	Vec2f mod = Vec2f(Vec2i(DANAEMouse) - g_size.center()) / Vec2f(g_size.center()) * Vec2f(160.f, 220.f);
	mvectx *= mod.x;
	Vec3f mvecty(0, mod.y, 0);

	Vec3f orgn = player.pos;
	orgn += angleToVector(player.angle) * 50.f;
	orgn += mvectx;
	orgn.y += mvecty.y;

	Vec3f dest = player.pos;
	dest += angleToVector(player.angle) * 10000.f;
	dest += mvectx;
	dest.y += mvecty.y * 5.f;
	
	Vec3f pos = orgn;

	Vec3f movev = glm::normalize(dest - orgn);

	float lastanything = 0.f;
	float height = -(bbox.max.y - bbox.min.y);

	if(height > -30.f)
		height = -30.f;
	
	Vec3f objcenter = bbox.min + (bbox.max - bbox.min) * Vec3f(0.5f);
	
	Vec3f collidpos = Vec3f_ZERO;
	bool collidpos_ok = false;
	
	{
	float maxdist = 0.f;
	
	for(size_t i = 0; i < io->obj->vertexlist.size(); i++) {
		const EERIE_VERTEX & vert = io->obj->vertexlist[i];
		
		float dist = glm::distance(Vec2f(objcenter.x, objcenter.z), Vec2f(vert.v.x, vert.v.z)) - 4.f;
		maxdist = std::max(maxdist, dist);
	}

	if(io->obj->pbox) {
		Vec2f tmpVert(io->obj->pbox->vert[0].initpos.x, io->obj->pbox->vert[0].initpos.z);
		
		for(int i = 1; i < io->obj->pbox->nb_physvert; i++) {
			const PHYSVERT & physVert = io->obj->pbox->vert[i];
			
			float dist = glm::distance(tmpVert, Vec2f(physVert.initpos.x, physVert.initpos.z)) + 14.f;
			maxdist = std::max(maxdist, dist);
		}
	}
	
	Cylinder cyl2;
	const float inc = 10.f;
	long iterating = 40;

	cyl2.height = std::min(-30.f, height);
	cyl2.radius = glm::clamp(maxdist, 20.f, 150.f);
	
	while(iterating > 0) {
		cyl2.origin = pos + movev * inc + Vec3f(0.f, bbox.max.y, 0.f);

		float anything = CheckAnythingInCylinder(cyl2, io, CFLAG_JUST_TEST | CFLAG_COLLIDE_NOCOL | CFLAG_NO_NPC_COLLIDE);

		if(anything < 0.f) {
			if(iterating == 40) {
				CANNOT_PUT_IT_HERE = 1;
				// TODO is this correct ?
				return true;
			}

			iterating = 0;

			collidpos = cyl2.origin;

			if(lastanything < 0.f) {
				pos.y += lastanything;
				collidpos.y += lastanything;
			}
		} else {
			pos = cyl2.origin;
			lastanything = anything;
		}

		iterating--;
	}
	collidpos_ok = iterating == -1;
	
	}
	
	objcenter = VRotateY(objcenter, temp.getPitch());
	
	collidpos.x -= objcenter.x;
	collidpos.z -= objcenter.z;

	pos.x -= objcenter.x;
	pos.z -= objcenter.z;

	if(!collidpos_ok) {
		CANNOT_PUT_IT_HERE = 1;
		return false;
	}

	if(collidpos_ok && closerThan(player.pos, pos, 300.f)) {
		if(simulate) {
			ARX_INTERACTIVE_Teleport(io, pos, true);

			io->gameFlags &= ~GFLAG_NOCOMPUTATION;
			
			glm::quat rotation = glm::toQuat(toRotationMatrix(temp));
			
			if(SPECIAL_DRAGINTER_RENDER) {
			if(glm::abs(lastanything) > glm::abs(height)) {
				TransformInfo t(collidpos, rotation, io->scale);

				static const float invisibility = 0.5f;

				DrawEERIEInter(io->obj, t, io, false, invisibility);
			} else {
				TransformInfo t(pos, rotation, io->scale);

				float invisibility = Cedric_GetInvisibility(io);

				DrawEERIEInter(io->obj, t, io, false, invisibility);
			}
			}
		} else {
			if(glm::abs(lastanything) > std::min(glm::abs(height), 12.0f)) {
				Entity * io = DRAGINTER;
				ARX_PLAYER_Remove_Invisibility();
				io->obj->pbox->active = 1;
				io->obj->pbox->stopcount = 0;
				io->pos = collidpos;
				io->velocity = Vec3f_ZERO;

				io->stopped = 1;

				movev.x *= 0.0001f;
				movev.y = 0.1f;
				movev.z *= 0.0001f;
				Vec3f viewvector = movev;

				Anglef angle = temp;
				io->soundtime = 0;
				io->soundcount = 0;
				EERIE_PHYSICS_BOX_Launch(io->obj, io->pos, angle, viewvector);
				ARX_SOUND_PlaySFX(SND_WHOOSH, &pos);
				io->show = SHOW_FLAG_IN_SCENE;
				Set_DragInter(NULL);
			} else {
				ARX_PLAYER_Remove_Invisibility();
				ARX_SOUND_PlayInterface(SND_INVSTD);
				ARX_INTERACTIVE_Teleport(io, pos, true);

				io->angle.setYaw(temp.getYaw());
				io->angle.setPitch(270.f - temp.getPitch());
				io->angle.setRoll(temp.getRoll());

				io->stopped = 0;
				io->show = SHOW_FLAG_IN_SCENE;
				io->obj->pbox->active = 0;
				Set_DragInter(NULL);
			}
		}

		GRenderer->SetCulling(Renderer::CullNone);
		return true;
	} else {
		CANNOT_PUT_IT_HERE=-1;
	}

	return false;
}
コード例 #9
0
bool SecondaryInventoryHud::dragEntity(Entity * io, const Vec2s & pos) {
	
	if(SecondaryInventory != NULL) {
		if(g_secondaryInventoryHud.containsPos(pos) && (io->ioflags & IO_ITEM)) {
			Entity * ioo = SecondaryInventory->io;
			
			if(ioo->ioflags & IO_SHOP) {
				long cos = ARX_INTERACTIVE_GetPrice(io, ioo);
				
				float fcos	= cos - cos * player.m_skillFull.intuition * 0.005f;
				cos = checked_range_cast<long>(fcos);
				
				if(player.gold < cos) {
					return false;
				}
				
				ARX_SOUND_PlayInterface(SND_GOLD);
				player.gold -= cos;
				
				if(io->_itemdata->count > 1) {
					Entity * ioo = CloneIOItem(io);
					ioo->show = SHOW_FLAG_NOT_DRAWN;
					ioo->scriptload = 1;
					ioo->_itemdata->count = 1;
					io->_itemdata->count--;
					ARX_SOUND_PlayInterface(SND_INVSTD);
					Set_DragInter(ioo);
					return true;
				}
			} else if(io->_itemdata->count > 1) {
				
				if(!GInput->actionPressed(CONTROLS_CUST_STEALTHMODE)) {
					Entity * ioo = CloneIOItem(io);
					ioo->show = SHOW_FLAG_NOT_DRAWN;
					ioo->scriptload = 1;
					ioo->_itemdata->count = 1;
					io->_itemdata->count--;
					ARX_SOUND_PlayInterface(SND_INVSTD);
					Set_DragInter(ioo);
					sInventory = 2;
					
					Vec2f calc;
					calc.x = (pos.x + m_fadePosition - (2 * m_scale)) / (32 * m_scale);
					calc.y = (pos.y - (13 * m_scale)) / (32 * m_scale);
					
					sInventoryPos.x = checked_range_cast<short>(calc.x);
					sInventoryPos.y = checked_range_cast<short>(calc.y);
					
					//ARX_INVENTORY_Object_Out(SecondaryInventory->io, ioo);
					
					ARX_INVENTORY_IdentifyIO(ioo);
					return true;
				}
			}
		}
		
		for(long j = 0; j < SecondaryInventory->m_size.y; j++)
		for(long i = 0; i < SecondaryInventory->m_size.x; i++) {
			INVENTORY_SLOT & slot = SecondaryInventory->slot[i][j];
			
			if(slot.io != io)
				continue;
			
			slot.io = NULL;
			slot.show = true;
			sInventory = 2;
			
			float fCalcX = (pos.x + m_fadePosition - (2 * m_scale)) / (32 * m_scale);
			float fCalcY = (pos.y - (13 * m_scale)) / (32 * m_scale);
			
			sInventoryPos.x = checked_range_cast<short>(fCalcX);
			sInventoryPos.y = checked_range_cast<short>(fCalcY);
		}
	}
	
	Set_DragInter(io);
	RemoveFromAllInventories(io);
	ARX_INVENTORY_IdentifyIO(io);
	return true;
}
コード例 #10
0
void SecondaryInventoryHud::dropEntity() {
	
	// First Look for Identical Item...
	if(SecondaryInventory && g_secondaryInventoryHud.containsPos(DANAEMouse)) {
		Entity * io = SecondaryInventory->io;
		
		float fprice = ARX_INTERACTIVE_GetPrice(DRAGINTER, io) / 3.0f; //>>1;
		long price = checked_range_cast<long>(fprice);
		price *= DRAGINTER->_itemdata->count;
		fprice = price + price * player.m_skillFull.intuition * 0.005f;
		price = checked_range_cast<long>(fprice);
		
		// SHOP
		if(io->ioflags & IO_SHOP) {
			if(!io->shop_category.empty() && DRAGINTER->groups.find(io->shop_category) == DRAGINTER->groups.end())
				return;
			
			if(price <= 0)
				return;
			
			// Check shop group
			for(long j = 0; j < SecondaryInventory->m_size.y; j++) {
			for(long i = 0; i < SecondaryInventory->m_size.x; i++) {
				Entity * ioo = SecondaryInventory->slot[i][j].io;
				
				if(!ioo || !IsSameObject(DRAGINTER, ioo))
					continue;
				
				ioo->_itemdata->count += DRAGINTER->_itemdata->count;
				ioo->scale = 1.f;
				
				DRAGINTER->destroy();
				
				ARX_PLAYER_AddGold(price);
				ARX_SOUND_PlayInterface(SND_GOLD);
				ARX_SOUND_PlayInterface(SND_INVSTD);
				return;
			}
			}
		}
		
		Vec2s t = Vec2s_ZERO;
		t.x = DANAEMouse.x + static_cast<short>(m_fadePosition) - (2 * m_scale);
		t.y = DANAEMouse.y - (13 * m_scale);
		t.x = t.x / (32 * m_scale);
		t.y = t.y / (32 * m_scale);
		
		Vec2s s = DRAGINTER->m_inventorySize;
		
		if(t.x <= SecondaryInventory->m_size.x - s.x && t.y <= SecondaryInventory->m_size.y - s.y) {
			
			float fprice = ARX_INTERACTIVE_GetPrice(DRAGINTER, io) / 3.0f;
			long price = checked_range_cast<long>(fprice);
			price *= DRAGINTER->_itemdata->count;
			fprice = price + price * player.m_skillFull.intuition * 0.005f;
			price = checked_range_cast<long>(fprice);
			
			for(long j = 0; j < s.y; j++) {
			for(long i = 0; i < s.x; i++) {
				Entity * ioo = SecondaryInventory->slot[t.x+i][t.y+j].io;
				
				if(!ioo)
					continue;
				
				DRAGINTER->show = SHOW_FLAG_IN_INVENTORY;
				
				if(   ioo->_itemdata->playerstacksize > 1
				   && IsSameObject(DRAGINTER, ioo)
				   && ioo->_itemdata->count < ioo->_itemdata->playerstacksize
				) {
					ioo->_itemdata->count += DRAGINTER->_itemdata->count;
					
					if(ioo->_itemdata->count > ioo->_itemdata->playerstacksize) {
						DRAGINTER->_itemdata->count = ioo->_itemdata->count - ioo->_itemdata->playerstacksize;
						ioo->_itemdata->count = ioo->_itemdata->playerstacksize;
					} else {
						DRAGINTER->_itemdata->count = 0;
					}
				}
				
				if(DRAGINTER->_itemdata->count) {
					if(CanBePutInSecondaryInventory(SecondaryInventory, DRAGINTER)) {
						// SHOP
						if(io->ioflags & IO_SHOP) {
							ARX_PLAYER_AddGold(price);
							ARX_SOUND_PlayInterface(SND_GOLD);
						}
					} else {
						return;
					}
				}
				
				ARX_SOUND_PlayInterface(SND_INVSTD);
				Set_DragInter(NULL);
				return;
			}
			}
			
			if(DRAGINTER->ioflags & IO_GOLD) {
				ARX_PLAYER_AddGold(DRAGINTER);
				Set_DragInter(NULL);
				return;
			}

			for(long j = 0; j < s.y; j++) {
			for(long i = 0; i < s.x; i++) {
				SecondaryInventory->slot[t.x+i][t.y+j].io = DRAGINTER;
				SecondaryInventory->slot[t.x+i][t.y+j].show = false;
			}
			}
			
			// SHOP
			if(io->ioflags & IO_SHOP) {
				player.gold += price;
				ARX_SOUND_PlayInterface(SND_GOLD);
			}

			SecondaryInventory->slot[t.x][t.y].show = true;
			DRAGINTER->show = SHOW_FLAG_IN_INVENTORY;
			ARX_SOUND_PlayInterface(SND_INVSTD);
			Set_DragInter(NULL);
			return;
		}
	}
}
コード例 #11
0
void ARX_EQUIPMENT_Equip(Entity * target, Entity * toequip)
{
	if(!target || !toequip || target != entities.player())
		return;

	EntityHandle validid = EntityHandle();

	for(size_t i = 0; i < entities.size(); i++) {
		const EntityHandle handle = EntityHandle(i);
		Entity * e = entities[handle];
		
		if(e == toequip) {
			validid = handle;
			break;
		}
	}

	if(validid == EntityHandle())
		return;

	RemoveFromAllInventories(toequip);
	toequip->show = SHOW_FLAG_ON_PLAYER; // on player

	if(toequip == DRAGINTER)
		Set_DragInter(NULL);

	if(toequip->type_flags & (OBJECT_TYPE_DAGGER | OBJECT_TYPE_1H | OBJECT_TYPE_2H |OBJECT_TYPE_BOW)) {
		if(ValidIONum(player.equiped[EQUIP_SLOT_WEAPON]))
			ARX_EQUIPMENT_UnEquip(target, entities[player.equiped[EQUIP_SLOT_WEAPON]]);

		player.equiped[EQUIP_SLOT_WEAPON] = validid;

		if(toequip->type_flags & OBJECT_TYPE_BOW)
			EERIE_LINKEDOBJ_LinkObjectToObject(target->obj, toequip->obj, "weapon_attach", "test", toequip);
		else
			EERIE_LINKEDOBJ_LinkObjectToObject(target->obj, toequip->obj, "weapon_attach", "primary_attach", toequip);

		if((toequip->type_flags & (OBJECT_TYPE_2H | OBJECT_TYPE_BOW)) && ValidIONum(player.equiped[EQUIP_SLOT_SHIELD]))
			ARX_EQUIPMENT_UnEquip(target, entities[player.equiped[EQUIP_SLOT_SHIELD]]);
	} else if(toequip->type_flags & OBJECT_TYPE_SHIELD) {
		if(ValidIONum(player.equiped[EQUIP_SLOT_SHIELD]))
			ARX_EQUIPMENT_UnEquip(target, entities[player.equiped[EQUIP_SLOT_SHIELD]]);

		player.equiped[EQUIP_SLOT_SHIELD] = validid;
		EERIE_LINKEDOBJ_LinkObjectToObject(target->obj, toequip->obj, "shield_attach", "shield_attach", toequip);

		if(ValidIONum(player.equiped[EQUIP_SLOT_WEAPON])) {
			if(entities[player.equiped[EQUIP_SLOT_WEAPON]]->type_flags & (OBJECT_TYPE_2H | OBJECT_TYPE_BOW))
				ARX_EQUIPMENT_UnEquip(target, entities[player.equiped[EQUIP_SLOT_WEAPON]]);
		}
	} else if(toequip->type_flags & OBJECT_TYPE_RING) {
		// check first, if not already equiped
		if (!((ValidIONum(player.equiped[EQUIP_SLOT_RING_LEFT]) && (toequip == entities[player.equiped[EQUIP_SLOT_RING_LEFT]]))
		        ||	(ValidIONum(player.equiped[EQUIP_SLOT_RING_RIGHT]) && (toequip == entities[player.equiped[EQUIP_SLOT_RING_RIGHT]]))))
		{
			long willequip = -1;

			if(player.equiped[EQUIP_SLOT_RING_LEFT] == EntityHandle())
				willequip = EQUIP_SLOT_RING_LEFT;

			if(player.equiped[EQUIP_SLOT_RING_RIGHT] == EntityHandle())
				willequip = EQUIP_SLOT_RING_RIGHT;

			if(willequip == -1) {
				if(bRing) {
					if(ValidIONum(player.equiped[EQUIP_SLOT_RING_RIGHT]))
						ARX_EQUIPMENT_UnEquip(target, entities[player.equiped[EQUIP_SLOT_RING_RIGHT]]);

					willequip = EQUIP_SLOT_RING_RIGHT;
				} else {
					if(ValidIONum(player.equiped[EQUIP_SLOT_RING_LEFT]))
						ARX_EQUIPMENT_UnEquip(target, entities[player.equiped[EQUIP_SLOT_RING_LEFT]]);

					willequip = EQUIP_SLOT_RING_LEFT;
				}
				bRing = !bRing;
			}
			player.equiped[willequip] = validid;
		}
	} else if(toequip->type_flags & OBJECT_TYPE_ARMOR) {
		if(ValidIONum(player.equiped[EQUIP_SLOT_ARMOR]))
			ARX_EQUIPMENT_UnEquip(target, entities[player.equiped[EQUIP_SLOT_ARMOR]]);

		player.equiped[EQUIP_SLOT_ARMOR] = validid;
	} else if(toequip->type_flags & OBJECT_TYPE_LEGGINGS) {
		if(ValidIONum(player.equiped[EQUIP_SLOT_LEGGINGS]))
			ARX_EQUIPMENT_UnEquip(target, entities[player.equiped[EQUIP_SLOT_LEGGINGS]]);

		player.equiped[EQUIP_SLOT_LEGGINGS] = validid;
	} else if(toequip->type_flags & OBJECT_TYPE_HELMET) {
		if(ValidIONum(player.equiped[EQUIP_SLOT_HELMET]))
			ARX_EQUIPMENT_UnEquip(target, entities[player.equiped[EQUIP_SLOT_HELMET]]);

		player.equiped[EQUIP_SLOT_HELMET] = validid;
	}

	if(toequip->type_flags & (OBJECT_TYPE_HELMET | OBJECT_TYPE_ARMOR | OBJECT_TYPE_LEGGINGS))
		ARX_EQUIPMENT_RecreatePlayerMesh();

	ARX_PLAYER_ComputePlayerFullStats();
}
コード例 #12
0
ファイル: Hud.cpp プロジェクト: BSzili/ArxLibertatis
void BackpackIconGui::updateInput() {
	
	static PlatformInstant flDelay = 0;
	
	// Check for backpack Icon
	if(m_rect.contains(Vec2f(DANAEMouse))) {
		if(eeMouseUp1() && playerInventory.insert(DRAGINTER)) {
			ARX_SOUND_PlayInterface(SND_INVSTD);
			Set_DragInter(NULL);
		}
	}
	
	if(m_rect.contains(Vec2f(DANAEMouse)) || flDelay != 0) {
		eMouseState = MOUSE_IN_INVENTORY_ICON;
		cursorSetInteraction();
		
		
		if(eeMouseDoubleClick1()) {
			ARX_SOUND_PlayInterface(SND_BACKPACK, Random::getf(0.9f, 1.1f));
			
			playerInventory.optimize();
			
			flDelay = 0;
		} else if(eeMouseDown1() || flDelay != 0) {
			if(flDelay == 0) {
				flDelay = g_platformTime.frameStart();
				return;
			} else {
				if(g_platformTime.frameStart() - flDelay < PlatformDurationMs(300)) {
					return;
				} else {
					flDelay = 0;
				}
			}
			
			if(player.Interface & INTER_INVENTORYALL) {
				ARX_SOUND_PlayInterface(SND_BACKPACK, Random::getf(0.9f, 1.1f));
				g_playerInventoryHud.close();
			} else {
				bInverseInventory = !bInverseInventory;
				lOldTruePlayerMouseLook = TRUE_PLAYER_MOUSELOOK_ON;
			}
		} else if(eeMouseDown2()) {
			g_playerBook.close();
			ARX_INVENTORY_OpenClose(NULL);
			
			if(player.Interface & INTER_INVENTORYALL) {
				g_playerInventoryHud.close();
			} else {
				if(player.Interface & INTER_INVENTORY) {
					ARX_SOUND_PlayInterface(SND_BACKPACK, Random::getf(0.9f, 1.1f));
					g_playerInventoryHud.close();
					bInventorySwitch = true;
				} else {
					ARX_SOUND_PlayInterface(SND_BACKPACK, Random::getf(0.9f, 1.1f));
					player.Interface |= INTER_INVENTORYALL;
					
					g_playerInventoryHud.resetPos();
					
					ARX_INTERFACE_NoteClose();
					
					if(TRUE_PLAYER_MOUSELOOK_ON) {
						WILLRETURNTOFREELOOK = true;
					}
				}
			}
			
			TRUE_PLAYER_MOUSELOOK_ON = false;
		}
		
		if(DRAGINTER == NULL)
			return;
	}
}