void Character::Update() { if(isSeen()){ unit->SetY(prevY); unit->SetX(prevX); } //collidingUp = environment->isCollidingUp(unit->GetY()); Animate(); if(direction > 0){ Move(); // Moves the character } if(sdl_setup->GetEv()->type == SDL_KEYDOWN){ if(sdl_setup->GetEv()->key.keysym.sym == SDLK_DOWN){ //MOVE CHARACTER DOWN direction = 4; stopAnimation = false; }else if(sdl_setup->GetEv()->key.keysym.sym == SDLK_UP){ //MOVE CHARACTER UP direction = 3; stopAnimation = false; }else if(sdl_setup->GetEv()->key.keysym.sym == SDLK_LEFT){ //MOVE CHARACTER LEFT direction = 1; stopAnimation = false; }else if(sdl_setup->GetEv()->key.keysym.sym == SDLK_RIGHT){ //MOVE CHARACTER RIGHT direction = 2; stopAnimation = false; } }else{ direction = 0; stopAnimation = true; } }
void CChaseState::Update(float ElapsedTime) { const float rotationSpeed = mathUtils::Deg2Rad( 90.0f ); //m_Time = m_Time + ElapsedTime; float l_sqdistance = m_Owner->GetPosition().SqDistance(m_Player->GetPosition()); if (l_sqdistance < 1.5f) m_StateMachine->ChangeState("ATTACK"); Vect3f l_ras = m_Owner->GetPosition(); /*l_ras.y = 0.0f; m_Owner->SetPosition(l_ras);*/ if(isSeen() || isHeared()) { m_Owner->ChangeCharacterAnimation(WALK_ANIM, 0.3f); if(isReachable()) { Init(); if(l_sqdistance<4.0f) { m_StateMachine->ChangeState("ATTACK"); return; } if(isFaced()) { Vect3f l_dir = (m_Player->GetPosition() - m_Owner->GetPosition()).Normalize(); m_Owner->SetYaw(atan2(-l_dir.x, l_dir.z)); //m_Owner->SetPosition(m_Owner->GetPosition() + m_Owner->GetFront( ) * ElapsedTime *1.30f); m_Owner->SetPosition(m_Owner->GetFront()*m_WalkSpeed, ElapsedTime); return; } else { if( isAtLeft()) { m_Owner->SetYaw(m_Owner->GetYaw() + rotationSpeed*ElapsedTime); } else{ m_Owner->SetYaw(m_Owner->GetYaw() - rotationSpeed*ElapsedTime); } return; } } else{ if(!m_LPos) { m_LastPos = m_Player->GetPosition(); m_LPos =true; } if(!m_Lost) { if(isFaced(m_LastPos)) { m_Time = m_Time + ElapsedTime; if(m_Time < 2.0f) { Vect3f l_dir = (m_LastPos - m_Owner->GetPosition()).Normalize(); m_Owner->SetYaw(atan2(-l_dir.x, l_dir.z)); //m_Owner->SetPosition(m_Owner->GetPosition() + m_Owner->GetFront( ) * ElapsedTime *1.30f); m_Owner->SetPosition(m_Owner->GetFront()*m_WalkSpeed, ElapsedTime); return; } else{ m_Time=0; if(CORE->GetNodeManager()->GetNumNodes() == 0) { m_Owner->ChangeCharacterAnimation(WALK_ANIM, 0.3f); m_StateMachine->ChangeState("WANDER"); return; } CNode * l_start = CORE->GetNodeManager()->GetNode(CORE->GetNodeManager()->NearestNode(m_Owner->GetPosition())); CNode * l_end = CORE->GetNodeManager()->GetNode(CORE->GetNodeManager()->NearestNode(m_Player->GetPosition())); m_Path = CORE->GetNodeManager()->AStarAlgorithm(l_start, l_end); if(m_Path.empty()) { m_Owner->ChangeCharacterAnimation(WALK_ANIM, 0.3f); m_StateMachine->ChangeState("WANDER"); return; } if(isBetterNext()) { std::vector<CNode*>::iterator it = m_Path.begin(); m_Path.erase(it); } m_Lost = true; } } else { if( isAtLeft(m_LastPos)) { m_Owner->SetYaw(m_Owner->GetYaw() + rotationSpeed*ElapsedTime); } else{ m_Owner->SetYaw(m_Owner->GetYaw() - rotationSpeed*ElapsedTime); } return; } } } } else{ if(m_Path.empty() && !m_Lost) { m_Time=0; if(CORE->GetNodeManager()->GetNumNodes() == 0) { m_Owner->ChangeCharacterAnimation(WALK_ANIM, 0.3f); m_StateMachine->ChangeState("WANDER"); return; } CNode * l_start = CORE->GetNodeManager()->GetNode(CORE->GetNodeManager()->NearestNode(m_Owner->GetPosition())); CNode * l_end = CORE->GetNodeManager()->GetNode(CORE->GetNodeManager()->NearestNode(m_Player->GetPosition())); m_Path = CORE->GetNodeManager()->AStarAlgorithm(l_start, l_end); if(m_Path.empty()) { m_Owner->ChangeCharacterAnimation(WALK_ANIM, 0.3f); m_StateMachine->ChangeState("WANDER"); return; } if(isBetterNext()) { std::vector<CNode*>::iterator it = m_Path.begin(); m_Path.erase(it); } m_Lost = true; } } if(isFaced(m_Path[0]->GetPos())) { Vect3f l_dir = (m_Path[0]->GetPos() - m_Owner->GetPosition()).Normalize(); m_Owner->SetYaw(atan2(-l_dir.x, l_dir.z)); m_Owner->SetPosition(m_Owner->GetPosition() + m_Owner->GetFront( ) * ElapsedTime*1.30f); Vect3f l_new = m_Owner->GetPosition() +m_Owner->GetFront() * ElapsedTime * m_WalkSpeed; Vect3f l_post = (m_Path[0]->GetPos() - l_new).Normalize(); float l_dist = l_new.SqDistance(m_Path[0]->GetPos()); //if((l_dir * l_post) > 0.0f) if(l_dist > 0.01f) { m_Owner->SetPosition(m_Owner->GetFront()*m_WalkSpeed, ElapsedTime); } else{ //m_Owner->SetPosition(m_Path[0]->GetPos()); l_dir = m_Path[0]->GetPos() - m_Owner->GetPosition(); l_dir.y=0.0f; m_Owner->SetPosition(l_dir, ElapsedTime); std::vector<CNode*>::iterator it = m_Path.begin(); m_Path.erase(it); if(m_Path.size()==0) { m_Owner->ChangeCharacterAnimation(WALK_ANIM, 0.3f); m_StateMachine->ChangeState("WANDER"); return; } } } else{ m_fLostTime += ElapsedTime; m_Owner->SetPosition(m_Owner->GetFront()*m_WalkSpeed, ElapsedTime); if (m_fLostTime <= 1.5f) { if(isAtLeft(m_Path[0]->GetPos())) { m_Owner->SetYaw(m_Owner->GetYaw() + rotationSpeed*ElapsedTime); } else{ m_Owner->SetYaw(m_Owner->GetYaw() - rotationSpeed*ElapsedTime); } } else { m_fLostTime = 0.0f; m_StateMachine->ChangeState("WANDER"); } return; } }
bool CMoveTask::Chase(float ElapsedTime) { if((isHeared() && isNotBlockedEyeLine()) || (isSeen() && isNotBlockedEyeLine())) { return false; } m_Owner->ChangeCharacterAnimation(RUN_ANIM, 0.3f); const float rotationSpeed = mathUtils::Deg2Rad( 180.0f ); int l_numNode = CORE->GetNodeManager()->NearestNodeSoldier(m_Player->GetPosition()); Vect3f l_point = CORE->GetNodeManager()->GetNodeSoldier(l_numNode)->GetPos(); if(!isReachable(l_point)) { if(m_Path.empty()) { CNode * l_start = CORE->GetNodeManager()->GetNodeSoldier(CORE->GetNodeManager()->NearestNodeSoldier(m_Owner->GetPosition())); CNode * l_end = CORE->GetNodeManager()->GetNodeSoldier(l_numNode); m_Path = CORE->GetNodeManager()->AStarAlgorithmSoldier(l_start, l_end); } if (!m_Path.empty()) { if(isFaced(m_Path[0]->GetPos())) { Vect3f l_dir = m_Path[0]->GetPos(); l_dir.y = m_Owner->GetPosition().y; l_dir = (l_dir-m_Owner->GetPosition()).Normalize(); m_Owner->SetYaw(atan2(-l_dir.x, l_dir.z)); Vect3f l_prev= m_Owner->GetPosition(); m_Owner->SetPosition(m_Owner->GetFront()*0.090f, ElapsedTime); //Vect3f l_new = m_Owner->GetPosition() +m_Owner->GetFront() * ElapsedTime * 3.0f; Vect3f l_new = m_Owner->GetPosition(); l_new.y = m_Path[0]->GetPos().y; float l_dist = l_new.SqDistance(m_Path[0]->GetPos()); if(l_dist > 0.09f) { //m_Owner->SetPosition(l_new); } else { //m_Owner->SetPosition(m_Path[0]->GetPos()); //m_Owner->SetPosition(m_Owner->GetFront()*0.0f, ElapsedTime); //m_Owner->ChangeCharacterAnimation(WAIT_ANIM, 0.3f); l_dir = m_Path[0]->GetPos() - m_Owner->GetPosition(); l_dir.y=0.0f; m_Owner->SetPosition(l_dir, ElapsedTime); std::vector<CNode*>::iterator it = m_Path.begin(); m_Path.erase(it); } } else{ if(!isFacedRun(m_Path[0]->GetPos())) { if(isAtLeft(m_Path[0]->GetPos())) { m_Owner->SetYaw(m_Owner->GetYaw() + rotationSpeed*ElapsedTime); } else{ m_Owner->SetYaw(m_Owner->GetYaw() - rotationSpeed*ElapsedTime); } } else{ Vect3f l_dir = m_Path[0]->GetPos(); l_dir.y = m_Owner->GetPosition().y; l_dir = (l_dir-m_Owner->GetPosition()).Normalize(); m_Owner->SetYaw(atan2(-l_dir.x, l_dir.z)); Vect3f l_front = m_Owner->GetFront(); } } } } else{ if(isFaced(l_point)) { m_Owner->ChangeCharacterAnimation(RUN_ANIM, 0.3f); Vect3f l_dir = l_point; l_dir.y = m_Owner->GetPosition().y; l_dir = (l_dir-m_Owner->GetPosition()).Normalize(); m_Owner->SetYaw(atan2(-l_dir.x, l_dir.z)); Vect3f l_prev= m_Owner->GetPosition(); m_Owner->SetPosition(m_Owner->GetFront()*0.090f, ElapsedTime); //Vect3f l_new = m_Owner->GetPosition() +m_Owner->GetFront() * ElapsedTime * 3.0f; Vect3f l_new = m_Owner->GetPosition(); l_new.y =l_point.y; float l_dist = l_new.SqDistance(l_point); if(l_dist > 0.09f) { //m_Owner->SetPosition(l_new); } else { //m_Owner->SetPosition(l_point); //m_Owner->SetPosition(m_Owner->GetFront()*0.0f, ElapsedTime); //m_Owner->ChangeCharacterAnimation(WAIT_ANIM, 0.3f); l_dir = l_point - m_Owner->GetPosition(); l_dir.y=0.0f; m_Owner->SetPosition(l_dir, ElapsedTime); m_Owner->ChangeCharacterAnimation(WAIT_ANIM, 0.3f); } } else{ if(!isFacedRun(l_point)) { if(isAtLeft(l_point)) { m_Owner->SetYaw(m_Owner->GetYaw() + rotationSpeed*ElapsedTime); } else{ m_Owner->SetYaw(m_Owner->GetYaw() - rotationSpeed*ElapsedTime); } } else{ Vect3f l_dir = l_point; l_dir.y = m_Owner->GetPosition().y; l_dir = (l_dir-m_Owner->GetPosition()).Normalize(); m_Owner->SetYaw(atan2(-l_dir.x, l_dir.z)); } } } return true; }
TCHAR* ParseString(TCHAR *szstring, MCONTACT hcontact) { #define MAXSIZE 1024 static TCHAR sztemp[MAXSIZE + 1]; TCHAR szdbsetting[128]; TCHAR *charPtr; int isetting = 0; DWORD dwsetting = 0; struct in_addr ia; DBVARIANT dbv; sztemp[0] = '\0'; SYSTEMTIME st; if (!isSeen(hcontact, &st)) { mir_tstrcat(sztemp, TranslateT("<never seen>")); return sztemp; } CONTACTINFO ci = { sizeof(CONTACTINFO) }; ci.hContact = hcontact; ci.szProto = hcontact ? GetContactProto(hcontact) : courProtoName; TCHAR *d = sztemp; for (TCHAR *p = szstring; *p; p++) { if (d >= sztemp + MAXSIZE) break; if (*p != '%' && *p != '#') { *d++ = *p; continue; } bool wantempty = *p == '#'; switch (*++p) { case 'Y': if (!st.wYear) goto LBL_noData; d += _stprintf(d, _T("%04i"), st.wYear); //!!!!!!!!!!!! break; case 'y': if (!st.wYear) goto LBL_noData; d += _stprintf(d, _T("%02i"), st.wYear % 100); //!!!!!!!!!!!! break; case 'm': if (!(isetting = st.wMonth)) goto LBL_noData; LBL_2DigNum: d += _stprintf(d, _T("%02i"), isetting); //!!!!!!!!!!!! break; case 'd': if (isetting = st.wDay) goto LBL_2DigNum; else goto LBL_noData; case 'W': isetting = st.wDayOfWeek; if (isetting == -1) { LBL_noData: charPtr = wantempty ? _T("") : TranslateT("<unknown>"); goto LBL_charPtr; } charPtr = TranslateTS(weekdays[isetting]); LBL_charPtr: d += mir_sntprintf(d, MAXSIZE - (d - sztemp), _T("%s"), charPtr); break; case 'w': isetting = st.wDayOfWeek; if (isetting == -1) goto LBL_noData; charPtr = TranslateTS(wdays_short[isetting]); goto LBL_charPtr; case 'E': if (!(isetting = st.wMonth)) goto LBL_noData; charPtr = TranslateTS(monthnames[isetting - 1]); goto LBL_charPtr; case 'e': if (!(isetting = st.wMonth)) goto LBL_noData; charPtr = TranslateTS(mnames_short[isetting - 1]); goto LBL_charPtr; case 'H': if ((isetting = st.wHour) == -1) goto LBL_noData; goto LBL_2DigNum; case 'h': if ((isetting = st.wHour) == -1) goto LBL_noData; if (!isetting) isetting = 12; isetting = isetting - ((isetting > 12) ? 12 : 0); goto LBL_2DigNum; case 'p': if ((isetting = st.wHour) == -1) goto LBL_noData; charPtr = (isetting >= 12) ? _T("PM") : _T("AM"); goto LBL_charPtr; case 'M': if ((isetting = st.wMinute) == -1) goto LBL_noData; goto LBL_2DigNum; case 'S': if ((isetting = st.wHour) == -1) goto LBL_noData; goto LBL_2DigNum; case 'n': charPtr = hcontact ? (TCHAR*)pcli->pfnGetContactDisplayName(hcontact, 0) : (wantempty ? _T("") : _T("---")); goto LBL_charPtr; case 'N': ci.dwFlag = CNF_NICK | CNF_TCHAR; if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) { charPtr = ci.pszVal; goto LBL_charPtr; } goto LBL_noData; case 'G': if (!db_get_ts(hcontact, "CList", "Group", &dbv)) { _tcsncpy(szdbsetting, dbv.ptszVal, _countof(szdbsetting)); db_free(&dbv); charPtr = szdbsetting; goto LBL_charPtr; } break; case 'u': ci.dwFlag = CNF_UNIQUEID | CNF_TCHAR; if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) { switch (ci.type) { case CNFT_BYTE: _ltot(ci.bVal, szdbsetting, 10); break; case CNFT_WORD: _ltot(ci.wVal, szdbsetting, 10); break; case CNFT_DWORD: _ltot(ci.dVal, szdbsetting, 10); break; case CNFT_ASCIIZ: _tcsncpy(szdbsetting, ci.pszVal, _countof(szdbsetting)); break; } } else goto LBL_noData; charPtr = szdbsetting; goto LBL_charPtr; case 's': if (isetting = db_get_w(hcontact, S_MOD, hcontact ? "StatusTriger" : courProtoName, 0)) { _tcsncpy(szdbsetting, pcli->pfnGetStatusModeDescription(isetting | 0x8000, 0), _countof(szdbsetting)); if (!(isetting & 0x8000)) { mir_tstrncat(szdbsetting, _T("/"), _countof(szdbsetting) - mir_tstrlen(szdbsetting)); mir_tstrncat(szdbsetting, TranslateT("Idle"), _countof(szdbsetting) - mir_tstrlen(szdbsetting)); } charPtr = szdbsetting; goto LBL_charPtr; } goto LBL_noData; case 'T': if (db_get_ts(hcontact, "CList", "StatusMsg", &dbv)) goto LBL_noData; d += mir_sntprintf(d, MAXSIZE - (d - sztemp), _T("%s"), dbv.ptszVal); db_free(&dbv); break; case 'o': if (isetting = db_get_w(hcontact, S_MOD, hcontact ? "OldStatus" : courProtoName, 0)) { _tcsncpy(szdbsetting, pcli->pfnGetStatusModeDescription(isetting, 0), _countof(szdbsetting)); if (includeIdle && hcontact && db_get_b(hcontact, S_MOD, "OldIdle", 0)) { mir_tstrncat(szdbsetting, _T("/"), _countof(szdbsetting) - mir_tstrlen(szdbsetting)); mir_tstrncat(szdbsetting, TranslateT("Idle"), _countof(szdbsetting) - mir_tstrlen(szdbsetting)); } charPtr = szdbsetting; goto LBL_charPtr; } goto LBL_noData; case 'i': case 'r': if (isJabber(ci.szProto)) { if (db_get_ts(hcontact, ci.szProto, *p == 'i' ? "Resource" : "System", &dbv)) goto LBL_noData; _tcsncpy(szdbsetting, dbv.ptszVal, _countof(szdbsetting)); db_free(&dbv); charPtr = szdbsetting; } else { dwsetting = db_get_dw(hcontact, ci.szProto, *p == 'i' ? "IP" : "RealIP", 0); if (!dwsetting) goto LBL_noData; ia.S_un.S_addr = htonl(dwsetting); _tcsncpy(szdbsetting, _A2T(inet_ntoa(ia)), _countof(szdbsetting)); charPtr = szdbsetting; } goto LBL_charPtr; case 'P': _tcsncpy(szdbsetting, ci.szProto ? _A2T(ci.szProto) : (wantempty ? _T("") : _T("ProtoUnknown")), _countof(szdbsetting)); charPtr = szdbsetting; goto LBL_charPtr; case 'b': charPtr = _T("\x0D\x0A"); goto LBL_charPtr; case 'C': // Get Client Info if (!db_get_ts(hcontact, ci.szProto, "MirVer", &dbv)) { _tcsncpy(szdbsetting, dbv.ptszVal, _countof(szdbsetting)); db_free(&dbv); } else goto LBL_noData; charPtr = szdbsetting; goto LBL_charPtr; case 't': charPtr = _T("\t"); goto LBL_charPtr; case 'A': { PROTOACCOUNT *pa = Proto_GetAccount(ci.szProto); if (!pa) goto LBL_noData; _tcsncpy(szdbsetting, pa->tszAccountName, _countof(szdbsetting)); charPtr = szdbsetting; goto LBL_charPtr; } default: *d++ = p[-1]; *d++ = *p; } } *d = 0; return sztemp; }