//------------------------------------------------------------------------
void CItem::NetSetOwnerId(EntityId id)
{
	if (id==m_ownerId)
		return;

	CryLogAlways("%s::NetSetOwnerId(%s)", GetEntity()->GetName(), GetActor(id)?GetActor(id)->GetEntity()->GetName():"null");

	if (id)
		PickUp(id, true);
	else
	{
		Drop();

		CActor *pActor=GetOwnerActor();
		if (pActor)
			pActor->GetInventory()->SetCurrentItem(0);
	}
}
Exemple #2
0
//------------------------------------------------------------------------------------------------
void AI::Update(float dt)
{
	//return;
	if (mState == DEAD) {
		Person::Update(dt);
		return;
	}

	//if (mGunIndex != KNIFE) Switch(KNIFE);
	float dx = mOldX-mX;
	float dy = mOldY-mY;
	if (fabs(dx) >= EPSILON || fabs(dy) >= EPSILON) {
		if (dx*dx + dy*dy < 0.0016f) {
			mStuckTimer += dt;
			if (mStuckTimer > 3000.0f) {
				mPath.clear();
				mTargetNode = mNode;
			}
		}
		else {
			mStuckTimer = 0.0f;
		}
	}
	else {
		mStuckTimer += dt;
		if (mStuckTimer > 3000.0f) {
			mPath.clear();
			mTargetNode = mNode;
		}
	}

	if (mIsFlashed) {
		SetAIState(AI_FLASHED);
	}

	mAIStateTime += dt;

	switch (mAIState) {
		case AI_IDLE: {

			mMoveTargetX = mX;
			mMoveTargetY = mY;

			if (mAIStateTime > 100.0f) {
				mTarget = GetClosestPerson();

				if (mTarget != NULL) {
					float dx = mTarget->mX-mX;
					float dy = mTarget->mY-mY;
					float distance = dx*dx + dy*dy;

					if (distance < 50000) {
						mPath.clear();
						SetAIState(AI_ATTACKING);
						break;
					}
				}

				SetAIState(AI_SEARCHING);

				mAIStateTime = 0.0f;
			}
			break;
		}
		case AI_RANDOM: {
			if (mTargetNode == NULL) break;

			float dx = mTargetNode->mX-mX;
			float dy = mTargetNode->mY-mY;
			float distance = dx*dx + dy*dy;
			if (distance < 1000) {
				Node* mTempNode;
				for (int i=0;i<50;i++) {
					mTempNode = mTargetNode->mConnections[rand()%mTargetNode->mConnections.size()];
					if (mTargetNode->mConnections.size() == 1) break;
					if (mTempNode != mNode) break;
				}
				mNode = mTargetNode;
				mTargetNode = mTempNode;
			}

			if (mAIStateTime > 100.0f) {
				mTarget = GetClosestPerson();

				if (mTarget != NULL) {
					float dx = mTarget->mX-mX;
					float dy = mTarget->mY-mY;
					float distance = dx*dx + dy*dy;

					if (distance < 50000) {
						mPath.clear();
						SetAIState(AI_ATTACKING);
						break;
					}
				}
				SetAIState(AI_SEARCHING);

				mAIStateTime = 0.0f;
			}

			mMoveTargetX = mTargetNode->mX;
			mMoveTargetY = mTargetNode->mY;

			mFaceTargetX = mTargetNode->mX;
			mFaceTargetY = mTargetNode->mY;

			break;
		}
		case AI_SEARCHING: {

			if (mTarget == NULL) {
				mTarget = GetClosestPerson();
				if (mTarget == NULL) {
					SetAIState(AI_RANDOM);
					break;
				}
			}
			if (mTargetNode == NULL) {
				float dx = mTarget->mX-mX;
				float dy = mTarget->mY-mY;
				float distance = dx*dx + dy*dy;

				if (mNode == NULL) {
					mNode = mAStar->GetClosestNode(this);
				}
				if (mNode == NULL) {
					SetAIState(AI_IDLE);
					break;
				}

				Node* endnode = mTarget->mTargetNode; //mAStar->GetClosestNode(mTarget);
				if (endnode == NULL) {
					endnode = mAStar->GetClosestNode(mTarget);
				}
				if (endnode == NULL) break;

				mPath = mAStar->GetPath(mNode,endnode,(int)sqrtf(distance)*15);
				mTargetNode = mPath.back();
				mPath.pop_back();
			}

			if (mAIStateTime > 100.0f) {
				if (mTargetNode != NULL) {
					float dx = mTargetNode->mX-mX;
					float dy = mTargetNode->mY-mY;
					float distance = dx*dx + dy*dy;
					if (distance < 1000) {
						mNode = mTargetNode;
						if (mPath.size() > 0) {
							mTargetNode = mPath.back();
							mPath.pop_back();
						}
						else {
							float dx = mTarget->mX-mX;
							float dy = mTarget->mY-mY;
							float distance = dx*dx + dy*dy;

							Node* endnode = mTarget->mTargetNode; //mAStar->GetClosestNode(mTarget);
							if (endnode == NULL) {
								endnode = mAStar->GetClosestNode(mTarget);
							}
							if (endnode == NULL) break;

							mPath = mAStar->GetPath(mNode,endnode,(int)sqrtf(distance)*15);
							mTargetNode = mPath.back();
							mPath.pop_back();
						}
					}

					mFaceTargetX = mTargetNode->mX;
					mFaceTargetY = mTargetNode->mY;
				}

				mTarget = GetClosestPerson();

				if (mTarget != NULL) {
					float dx = mTarget->mX-mX;
					float dy = mTarget->mY-mY;
					float distance = dx*dx + dy*dy;

					if (distance < 50000) {
						mPath.clear();
						SetAIState(AI_ATTACKING);
						break;
					}
				}

				mAIStateTime = 0.0f;
			}

			mMoveTargetX = mTargetNode->mX;
			mMoveTargetY = mTargetNode->mY;

			break;
		}
		case AI_ATTACKING: {
			if (mTarget == NULL) {
				SetAIState(AI_SEARCHING);
				break;
			}
			if (mTargetNode != NULL) {
				float dx = mTargetNode->mX-mX;
				float dy = mTargetNode->mY-mY;
				float distance = dx*dx + dy*dy;
				if (distance < 500) {
					mNode = mTargetNode;
					if (mPath.size() > 0) {
						mTargetNode = mPath.back();
						mPath.pop_back();
					}
					else {
						Node* endnode = mTarget->mTargetNode; //mAStar->GetClosestNode(mTarget);
						if (endnode == NULL) {
							endnode = mAStar->GetClosestNode(mTarget);
						}
						if (endnode == NULL) break;

						mPath = mAStar->GetPath(mNode,endnode);
						mTargetNode = mPath.back();
						mPath.pop_back();
					}
				}
				mMoveTargetX = mTargetNode->mX;
				mMoveTargetY = mTargetNode->mY;
			}

			mFaceTargetX = mTarget->mX;
			mFaceTargetY = mTarget->mY;

			float dx = mTarget->mX-mX;
			float dy = mTarget->mY-mY;
			float distance = dx*dx + dy*dy;

			if (mCanSeeEnemy) {
				mFaceTargetX = mTarget->mX+mTarget->mSpeed*cosf(mTarget->mAngle)*(sqrtf(distance)/0.25f);
				mFaceTargetY = mTarget->mY+mTarget->mSpeed*sinf(mTarget->mAngle)*(sqrtf(distance)/0.25f);
			}
			if (distance > 50000) {
				SetAIState(AI_SEARCHING);
				break;
			}
			if (mTarget->mState == DEAD) {
				SetAIState(AI_SEARCHING);
				mTarget = NULL;
				break;
			}
			if (mAIStateTime > 100.0f) {
				if (GetClosestPerson() != mTarget) {
					mTarget = GetClosestPerson();
				}

				//Vector2D A(mX,mY);
				//Vector2D B(mTarget->mX,mTarget->mY);

				//Line line1(A,B);
				mCanSeeEnemy = true;
				mCanSeeEnemy = mGrid->LineOfSight(mX,mY,mTarget->mX,mTarget->mY);

				/*for (unsigned int i=0;i<mCollisionPoints->size()-1;i++) {
					if ((*mCollisionPoints)[i].bullets == false) continue;
					if ((*mCollisionPoints)[i].x == -1 || (*mCollisionPoints)[i+1].x == -1) continue;
					Vector2D C((*mCollisionPoints)[i].x,(*mCollisionPoints)[i].y);
					Vector2D D((*mCollisionPoints)[i+1].x,(*mCollisionPoints)[i+1].y);
					if (C == D) continue;
					Line line2(C,D);

					Vector2D d;
					if (LineLineIntersect(line1,line2,d)) {
						mCanSeeEnemy = false;
						break;
					}
				}*/
				mAIStateTime = 0.0f;
			}

			break;
		}
		case AI_FLASHED: {
			if (!mIsFlashed) {
				mTarget = NULL;
				mTargetNode = NULL;
				mNode = NULL;
				SetAIState(AI_SEARCHING);
			}
			if (mAIStateTime > 1000.0f+rand()%1000-500) {
				float angle = 2*M_PI*(rand()%100)/100.0f;
				mMoveTargetX = mX+cosf(angle)*1000;
				mMoveTargetY = mY+sinf(angle)*1000;

				angle = 2*M_PI*(rand()%100)/100.0f;
				mFaceTargetX = mX+cosf(angle);
				mFaceTargetY = mY+sinf(angle);
				mAIStateTime = 0.0f;
			}


			break;
		}
	}

	if (fabs(mFaceTargetX-mX) >= EPSILON || fabs(mFaceTargetY-mY) >= EPSILON) {
		float e = atan2f(mFaceTargetY-mY,mFaceTargetX-mX);//+((double)rand()/((double)RAND_MAX*2))-0.25;
		float diffangle = e-mFacingAngle;
		if (diffangle < -M_PI) {
			diffangle += M_PI*2;
		}
		else if (diffangle > M_PI) {
			diffangle -= M_PI*2;
		}
		RotateFacing(diffangle*(0.003f*dt));
	}


	if (fabs(mMoveTargetX-mX) >= EPSILON || fabs(mMoveTargetY-mY) >= EPSILON) {
		float e = atan2f(mMoveTargetY-mY,mMoveTargetX-mX);//+((double)rand()/((double)RAND_MAX*2))-0.25;
		float diffangle = e-mAngle;
		if (diffangle < -M_PI) {
			diffangle += M_PI*2;
		}
		else if (diffangle > M_PI) {
			diffangle -= M_PI*2;
		}

		mAngle += diffangle*(0.005f*dt);
		//SetAngle(GetAngle()+(((float)rand()/RAND_MAX)-0.5f)/50*dt);
		//SetRotation(GetRotation()+(((float)rand()/RAND_MAX)-0.5f)/50*dt);
		Move(.08f,mAngle+M_PI_2);
		//SetSpeed((float)rand()/RAND_MAX/10);
	}

	if (mAIState == AI_ATTACKING && mCanSeeEnemy) {
		mFireTime += dt;
		if (mFireTime >= 500+rand()%500-250) {
			if (mState != ATTACKING) {
				Fire();
			}
			if (mFireTime >= 1000+rand()%1000-500) {
				mFireTime = 0.0f;
			}
		}
	}
	else {
		StopFire();
	}

	if (mState != RELOADING) {
		if (mGuns[mGunIndex]->mClipAmmo == 0) {
			if (!Reload()) {
				Drop(mGunIndex);
			}
		}
	}

	if (mIsInBuyZone && mBuyGun != NULL && mMoney >= mBuyGun->mCost) {
		if (mBuyGun->mType == PRIMARY) {
			mMoney -= mBuyGun->mCost;
			Drop(PRIMARY);
			GunObject *gun = new GunObject(mBuyGun,mBuyGun->mClip,0);
			PickUp(gun);
			//mPlayer->mGuns[PRIMARY] = gun;
			//mPlayer->mGunIndex = PRIMARY;
			gSfxManager->PlaySample(gPickUpSound, mX, mY);
			mBuyGun = NULL;
		}
	}

	Person::Update(dt);
}
Exemple #3
0
//Alters the map to the users specifications
void Map::AlterMap (char W, char S, char F, char G, char C, char X, char L, char E, char P)
{
	if (Washrooms(W))
	{
		floorOne[3][3] = 'W'; floorOne[2][11] = 'W'; floorOne[13][45] = 'W'; floorOne[13][51] = 'W';
		floorTwo[13][4] = 'W'; floorTwo[13][12] = 'W'; floorTwo[2][50] = 'W'; floorTwo[5][50] = 'W';
	} else
	{
		floorOne[3][3] = ' '; floorOne[2][11] = ' '; floorOne[13][45] = ' '; floorOne[13][51] = ' ';
		floorTwo[13][4] = ' '; floorTwo[13][12] = ' '; floorTwo[2][50] = ' '; floorTwo[5][50] = ' ';
	}

	if (Store(S))
	{
		floorOne[11][4] = 'S';
		floorTwo[8][3] = 'S';
	} else
	{
		floorOne[11][4] = ' ';
		floorTwo[8][3] = ' ';
	}

	if (Food(F))
	{
		floorTwo[2][4] = 'F'; floorTwo[2][12] = 'F';
	} else
	{
		floorTwo[2][4] = ' '; floorTwo[2][12] = ' ';
	}

	if (Gate(G))
	{
		floorTwo[1][27] = 'G'; floorTwo[1][40] = 'G';
	} else
	{
		floorTwo[1][27] = ' '; floorTwo[1][40] = ' ';
	}

	if (Customs(C))
	{
		floorTwo[9][31] = 'C';
	} else
	{
		floorTwo[9][31] = ' ';
	}

	if (CheckIn(X))
	{
		floorOne[2][38] = 'X';
	} else
	{
		floorOne[2][38] = ' ';
	}

	if (Luggage(L))
	{
		floorOne[2][38] = 'L';
	} else
	{
		floorOne[2][38] = ' ';
	}

	if (Entrance(E))
	{
		floorOne[10][52] = 'E';
	} else
	{
		floorOne[10][52] = ' ';
	}

	if (PickUp(P))
	{
		floorOne[11][28] = 'P'; floorOne[11][37] = 'P';
	} else
	{
		floorOne[11][28] = ' '; floorTwo[11][37] = ' ';
	}
}
Exemple #4
0
void MainLoop()
{
	int a=0,b=0;
	while(1)
	{
		you.player_move = true;

		if(you.s_timestep)
		{
			turn_skip();
			Sleep(16);
			continue;
		}


		int char_ = waitkeyinput();

		you.prev_hp[1] = you.hp;
		you.prev_mp[1] = you.mp;
		switch(char_)
		{
		case 'j':
			Move(coord_def(you.position.x,you.position.y-1));  //위
			break;
		case 'k':
			Move(coord_def(you.position.x,you.position.y+1)); //아래
			break;
		case 'h':
			Move(coord_def(you.position.x-1,you.position.y)); //왼쪽
			break;
		case 'l':
			Move(coord_def(you.position.x+1,you.position.y)); //오른쪽
			break;
		case 'b':
			Move(coord_def(you.position.x-1,you.position.y+1));
			break;
		case 'n':
			Move(coord_def(you.position.x+1,you.position.y+1));
			break;
		case 'y':
			Move(coord_def(you.position.x-1,you.position.y-1));
			break;
		case 'u':
			Move(coord_def(you.position.x+1,you.position.y-1));
			break;
		case 'x': //주위탐색
			Search();
			break;
		case 's': //턴스킵
		case '.': //턴스킵
			turn_skip();
			break;
		case 'g':
		case ',': //줍기
			PickUp();
			break;
		case 'i': //아이템확인
			iteminfor();
			break;	
		case 'd': //아이템버리기
			iteminfor_discard();
			break;
		case 'D': //마지막에 먹은 아이템 버리기
			fast_discard();
			break;
		case 'w': //무기장착
			Equip_Weapon();
			break;
		case 'W': //방어구장착
			Equip_Armor();
			break;
		case 'T': //방어구해제
			Unequip_Armor();
			break;
		case 'C': //문닫기
			Close_door();
			break;
		case 'O': //문열기
			Open_door();
			break;
		case 'o': //자동이동
			auto_Move();
			break;
		case '5': //100턴넘기기
			long_rest();
			break;
		case 0x88: //컨트롤P - 로그
			view_log();
			break;
		case 15: //컨트롤o
			if(isNormalGame())
				dungeonView();
			break;
		case 'e': //먹기
			Eatting();
			break;
		case 'q': //마시기
			Drinking();
			break;
		case 'r': //읽기
			Reading();
			break;
		case 'm': //스킬정보창
			skill_view();
			break;
		case 'P': //장신구장착
			Equip_Jewelry();
			break;
		case 'R': //장신구해제
			Unequip_Jewelry();
			break;
		case 'S': //체크후 종료
			saveandcheckexit();
			break;
		case 0x89: //강제종료
			nosaveandexit();
			break;
		case 0x8A: //저장과 종료
			saveandexit();
			break;
		case 'X': //넓은탐색
			Wide_Search();
			break;
		case 'f': //던지기(빠른)
			Quick_Throw(you.GetThrowIter(),you.GetTargetIter());
			break;
		case 'F': //던지기(선택)
			Select_Throw();
			break;
		case '\\': //식별템 확인
			Iden_Show();
			break;
		case '>':
			Stair_move(true);
			break;
		case '<':
			Stair_move(false);
			break;
		case '%':
			stat_view();
			break;
		case '}':
			Weapon_Show();
			break;
		case '[':
			Armour_Show();
			break;
		case ']':
			rune_Show();
			break;
		case '\"':
			Amulet_Show();
			break;
		case '@':
			Simple_State_Show();
			break;
		case 'N':
			//sendScore();
			break;
		case 'E':
			Experience_Show();
			break;
		//case 'c':
		//	Spelllcard_Declare();
		//	//Eat_Power();
		//	break;
		case 'v':
		case 'V':
			Spelllcard_Evoke();
			break;
		case 'p':
			Pray();
			break;
		case '#':
			if(isNormalGame() && Dump(0,NULL))
				printlog("덤프에 성공했습니다.",true,false,false,CL_normal);
			break;
		case 'Z':
		case 'z':
			SpellUse();
			break;
		case 'I':
			SpellView();
			break;
		case 'a':
			SkillUse();
			break;
		case 'A':
			PropertyView();
			break;
		case 'M':
			run_spell();
			break;
		case 't':
			shout();
			break;
		case '^':
			God_show();
			break;
		case '&': //위자드모드!
			//waitkeyinput();
			wiz_mode();
			break;
		case '_':
			save_mode();
			break;
		case 0x8B:
			auto_pick_onoff(false);
			break;
		case '?'://도움말
			Help_Show();
			break;
		case VK_ESCAPE://esc
			escape();
			break;
		case VK_TAB:
			auto_battle();
			break;
		default:
			break;
		}
	}
}