PSPower* PSProvince::GetOccupant(PSData* pData) { // Returns a pointer to the Power that occupies this province or NULL if it is empty. if (!pData) pData = TG.GetData(); PSUnit* pUnit = GetUnit(pData); if (!pUnit) return NULL; return pUnit->GetOwner(); }
void OnCombatStop() { RemoveAIUpdateEvent(); // well, we are alive and our opponent ran away or died. // notify twiggy and despawn TwiggyFlatheadAI *twiggy = (TwiggyFlatheadAI *)GetLinkedCreature(); if(twiggy) twiggy->OnBigWillSurvived(); GetUnit()->Despawn(1,0); }
double nsCSSValue::GetAngleValueInRadians() const { double angle = GetFloatValue(); switch (GetUnit()) { case eCSSUnit_Radian: return angle; case eCSSUnit_Degree: return angle * M_PI / 180.0; case eCSSUnit_Grad: return angle * M_PI / 200.0; default: NS_ABORT_IF_FALSE(false, "unrecognized angular unit"); return 0.0; } }
void CUnitPane::OnRClick(wxListEvent& event) { wxMenu menu; long idx = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); CUnit * pUnit = GetUnit(idx); int x=0,y; int width, height; int nItems = GetSelectedItemCount(); wxDisplaySize(&width, &height); y = event.GetPoint().y; ClientToScreen(&x, &y); if (height-y < 150) y = height-150; ScreenToClient(&x, &y); if (nItems>1) { // multiple units menu.Append(menu_Popup_IssueOrders , wxT("Issue orders")); menu.Append(menu_Popup_UnitFlags , wxT("Set custom flags") ); menu.Append(menu_Popup_AddToTracking , wxT("Add to a tracking group")); PopupMenu( &menu, event.GetPoint().x, y); } else if (pUnit) { // single unit if (pUnit->IsOurs) { menu.Append(menu_Popup_ShareSilv , wxT("Share SILV") ); menu.Append(menu_Popup_Teach , wxT("Teach") ); menu.Append(menu_Popup_Split , wxT("Split") ); menu.Append(menu_Popup_DiscardJunk , wxT("Discard junk items")); menu.Append(menu_Popup_GiveEverything, wxT("Give everything") ); menu.Append(menu_Popup_DetectSpies , wxT("Detect spies") ); } menu.Append(menu_Popup_UnitFlags , wxT("Set custom flags") ); menu.Append(menu_Popup_AddToTracking , wxT("Add to a tracking group")); PopupMenu( &menu, event.GetPoint().x, y); } }
// private stuff bool Start() { if(active) return false; // all is fine, lets start the affray active = true; phase = 0; GetUnit()->SendChatMessage(CHAT_MSG_MONSTER_SAY, LANG_UNIVERSAL, "The Affray has begun. Choperation. get ready to fight!"); // after 5 seconds, start RegisterAIUpdateEvent(5000); return true; }
bool CAICheats::GetUnitResourceInfo(int unitId, UnitResourceInfo* unitResInf) const { bool fetchOk = false; const CUnit* unit = GetUnit(unitId); if (unit) { unitResInf->energyMake = unit->resourcesMake.energy; unitResInf->energyUse = unit->resourcesUse.energy; unitResInf->metalMake = unit->resourcesMake.metal; unitResInf->metalUse = unit->resourcesUse.metal; fetchOk = true; } return fetchOk; }
double nsStyleCoord::GetAngleValueInRadians() const { double angle = mValue.mFloat; switch (GetUnit()) { case eStyleUnit_Radian: return angle; case eStyleUnit_Degree: return angle * M_PI / 180.0; case eStyleUnit_Grad: return angle * M_PI / 200.0; default: NS_NOTREACHED("unrecognized angular unit"); return 0.0; } }
void AIUpdate() { if(GetHealthPercent() <= 20 && SerpentForm->mEnabled == true) { CastSpellNowNoScheduling(SerpentForm); SerpentForm->mEnabled = false; // Disable Lightning Bolt LightningBolt->mEnabled = false; } else if(GetHealthPercent() <= 20 && SerpentForm->mEnabled == false && !GetUnit()->HasAura(7965)) { // Enable Lightning Bolt LightningBolt->mEnabled = true; } ParentClass::AIUpdate(); }
bool UnitContainer::Allow( const Unit *unit ) const { if ( !Allow( unit->Type() ) ) return false; int i; for ( i = UnitCount() - 1; i >= 0; --i ) if ( GetUnit(i) == unit ) return true; if ( unit->IsTransport() ) { const Transport *t = static_cast<const Transport *>(unit); if ( Crystals() + t->Crystals() > MaxCrystals() ) return false; for ( i = t->UnitCount() - 1; i >= 0; --i ) if ( !Allow( t->GetUnit(i) ) ) return false; } return uc_slots >= uc_slots_full + unit->Weight(); }
Enemies GetAdjacentEnemyData(Unit unit) { Enemies enemies; enemies.count = 0; char color = GetUnitColor(unit); Grids adjacentGrids = GetAdjacentGrids(*GetGrid(GetLocation(unit))); for (unsigned int i = 0; i < adjacentGrids.count; i++) { Grid grid = *adjacentGrids.grids[i]; if (isOccupied(grid) && !isOccupiedByAlly(grid, color)) { Unit *enemy = GetUnit(grid); enemies.enemy[enemies.count].unit = enemy; enemies.enemy[enemies.count].canRetaliate = Retaliates(unit, *enemy); ++enemies.count; } } return enemies; }
void COMMAND_INFO() { int x, y; do { printf("Enter the coordinate of the cell: "); scanf("%d %d", &x, &y); } while (!isValidCoordinate(x, y)); Grid *grid = GetGrid(MakePOINT(x, y)); Type type = GetType(*grid); Player *gridOwner = GetOwner(*grid); Unit *unit = GetUnit(*grid); printf("== Cell Info ==\n"); if (type == Normal) { printf("Normal\n"); } else if (type == Tower) { printf("Tower\n"); } else if (type == Castle) { printf("Castle\n"); } else if (type == Village) { printf("Village\n"); } printf("Owned by Player %d\n", GetPlayerIndex(*gridOwner)); if (unit) { Player *unitOwner = GetPlayerFromColor(GetUnitColor(*unit)); char unitClassName[11]; UnitClassName(GetUnitClass(*unit), unitClassName); printf("== Unit Info ==\n"); printf("%s\n", unitClassName); printf("Owned by Player %d\n", GetPlayerIndex(*unitOwner)); printf("Health %d/%d | ATK %d\n", GetHealth(*unit), GetMaximumHealth(*unit), GetAttack(*unit) ); } printf("\n"); }
static void MapAttributesIntoRule(const nsMappedAttributes* aAttributes, nsRuleData* aData) { if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Position)) { nsCSSValue* width = aData->ValueForWidth(); if (width->GetUnit() == eCSSUnit_Null) { // width: int (html4 attribute == nav4 cols) const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::width); if (!value || value->Type() != nsAttrValue::eInteger) { // cols: int (nav4 attribute) value = aAttributes->GetAttr(nsGkAtoms::cols); } if (value && value->Type() == nsAttrValue::eInteger) width->SetFloatValue((float)value->GetIntegerValue(), eCSSUnit_Char); } } if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Text)) { nsCSSValue* whiteSpace = aData->ValueForWhiteSpace(); if (whiteSpace->GetUnit() == eCSSUnit_Null) { // wrap: empty if (aAttributes->GetAttr(nsGkAtoms::wrap)) whiteSpace->SetIntValue(NS_STYLE_WHITESPACE_PRE_WRAP, eCSSUnit_Enumerated); // width: int (html4 attribute == nav4 cols) const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::width); if (!value || value->Type() != nsAttrValue::eInteger) { // cols: int (nav4 attribute) value = aAttributes->GetAttr(nsGkAtoms::cols); } if (value && value->Type() == nsAttrValue::eInteger) { // Force wrap property on since we want to wrap at a width // boundary not just a newline. whiteSpace->SetIntValue(NS_STYLE_WHITESPACE_PRE_WRAP, eCSSUnit_Enumerated); } } } nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData); }
void CUnitPane::OnPopupMenuDiscardJunk(wxCommandEvent& WXUNUSED(event)) { long idx = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); CUnit * pUnit = GetUnit(idx); CEditPane * pOrders; if (pUnit) { pOrders = (CEditPane*)gpApp->m_Panes[AH_PANE_UNIT_COMMANDS]; if (pOrders) pOrders->SaveModifications(); if (m_pCurLand) m_pCurLand->guiUnit = pUnit->Id; gpApp->SetOrdersChanged(gpApp->m_pAtlantis->DiscardJunkItems(pUnit, gpApp->GetConfig(SZ_SECT_UNITPROP_GROUPS, PRP_JUNK_ITEMS)) || gpApp->GetOrdersChanged()); Update(m_pCurLand); } }
bool CAICheats::GetProperty(int id, int property, void *data) const { bool fetchOk = false; switch (property) { case AIVAL_UNITDEF: { const CUnit* unit = GetUnit(id); if (unit) { (*(const UnitDef**) data) = unit->unitDef; fetchOk = true; } break; } default: { fetchOk = false; } } return fetchOk; }
void CUnitPane::OnPopupMenuShareSilv (wxCommandEvent& event) { long idx = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); CUnit * pUnit = GetUnit(idx); CEditPane * pOrders; if (pUnit) { pOrders = (CEditPane*)gpApp->m_Panes[AH_PANE_UNIT_COMMANDS]; if (pOrders) pOrders->SaveModifications(); if (m_pCurLand) m_pCurLand->guiUnit = pUnit->Id; gpApp->SetOrdersChanged(gpApp->m_pAtlantis->ShareSilver(pUnit) || gpApp->GetOrdersChanged()); Update(m_pCurLand); } }
//--------------------------------------------------------------------------- // --- Methods :: Unit --- // //--------------------------------------------------------------------------- UnitData* UnitDatas::CreateUnit (INT32 nCol, INT32 nRow) { if (nCol >= _nCountCols || nRow >= _nCountRows) { return NULL; } UnitData newData = UnitData(nCol, nRow); if (!IsExistsUnit(nCol, nRow)) { _lstUnit.push_back(newData); return GetUnit(nCol, nRow); } else { return NULL; } }
UnitData* UnitDatas::CreateUnit (POINT point) { if (point.x >= _nCountCols || point.y >= _nCountRows) { return NULL; } UnitData newData = UnitData(point); if (!IsExistsUnit(point)) { _lstUnit.push_back(newData); return GetUnit(point); } else { return NULL; } }
void OnReachWP(uint32 iWaypointId, bool bForwards) { if( iWaypointId == 1 ) { switch( RandomUInt(2) ) { case 0: Emote( "Life from the lifelessness... death for you.", Text_Yell, 13961); break; case 1: Emote( "Nothing is wasted in the process. You will see....", Text_Yell, 13962); break; }; MoonScriptCreatureAI* pAnvil = GetNearestCreature( CN_VOLKHANS_ANVIL ); if( pAnvil ) _unit->CastSpell( pAnvil->GetUnit(), SPELL_TEMPER, true ); else _unit->CastSpell( GetUnit(), SPELL_TEMPER, true ); SetCanEnterCombat( true ); _unit->GetAIInterface()->AttackReaction( GetNearestPlayer() , 1 ); // hackfix }; };
//--------------------------------------------------------------------------- void __fastcall TFMain_11011981::lbUnitsDblClick(TObject *Sender) { DWORD adr; String item = lbUnits->Items->Strings[lbUnits->ItemIndex]; sscanf(item.c_str() + 1, "%lX", &adr); PUnitRec recU = GetUnit(adr); if (!CurUnitAdr || adr != CurUnitAdr) { CurUnitAdr = adr; ShowUnitItems(recU, 0, -1); } else { ShowUnitItems(recU, lbUnitItems->TopIndex, lbUnitItems->ItemIndex); } CurUnitAdr = adr; }
void CUnitPane::OnPopupMenuIssueOrders(wxCommandEvent& event) { long idx; CUnit * pUnit; CEditPane * pOrders; BOOL Changed = FALSE; CGetTextDlg dlg(this, "Order", "Orders for the selected units"); if (wxID_OK != dlg.ShowModal()) return; dlg.m_Text.TrimRight(TRIM_ALL); if (dlg.m_Text.IsEmpty()) return; pOrders = (CEditPane*)gpApp->m_Panes[AH_PANE_UNIT_COMMANDS]; if (pOrders) pOrders->SaveModifications(); idx = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); while (idx>=0) { pUnit = GetUnit(idx); if (pUnit->IsOurs) { Changed = TRUE; pUnit->Orders.TrimRight(TRIM_ALL); if (!pUnit->Orders.IsEmpty()) pUnit->Orders << EOL_SCR; pUnit->Orders << dlg.m_Text; } idx = GetNextItem(idx, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); } if (Changed) { gpApp->SetOrdersChanged(TRUE); gpApp->m_pAtlantis->RunOrders(m_pCurLand); Update(m_pCurLand); } }
Object* MapMgr::_GetObject(const uint64 & guid) { switch(GET_TYPE_FROM_GUID(guid)) { case HIGHGUID_TYPE_GAMEOBJECT: return GetGameObject(GET_LOWGUID_PART(guid)); break; case HIGHGUID_TYPE_UNIT: return GetCreature(GET_LOWGUID_PART(guid)); break; case HIGHGUID_TYPE_DYNAMICOBJECT: return GetDynamicObject((uint32)guid); break; case HIGHGUID_TYPE_TRANSPORTER: return objmgr.GetTransporter(GUID_LOPART(guid)); break; default: return GetUnit(guid); break; } }
int CAICallback::SendUnits(const std::vector<int>& unitIds, int receivingTeamId) { typedef unsigned char ubyte; std::vector<short> sentUnitIDs; if ((team != receivingTeamId) && teamHandler->IsValidTeam(receivingTeamId) && teamHandler->Team(receivingTeamId) && teamHandler->Team(team) && !teamHandler->Team(receivingTeamId)->isDead && !teamHandler->Team(team)->isDead) { // we must iterate over the ID's to check if // all of them really belong to the AI's team std::vector<int>::const_iterator uid; for (uid = unitIds.begin(); uid != unitIds.end(); ++uid) { const int unitId = *uid; const CUnit* unit = GetUnit(unitId); if (unit && unit->team == team) { // we own this unit, save it // (note: safe cast since MAX_UNITS currently fits in a short) sentUnitIDs.push_back(short(unitId)); // stop whatever this unit is doing Command c(CMD_STOP); GiveOrder(unitId, &c); } } if (!sentUnitIDs.empty()) { // we ca not use SendShare() here either, since // AIs do not have a notion of "selected units" net->Send(CBaseNetProtocol::Get().SendAIShare(ubyte(gu->myPlayerNum), skirmishAIHandler.GetCurrentAIID(), ubyte(team), ubyte(receivingTeamId), 0.0f, 0.0f, sentUnitIDs)); } } // return how many units were actually put up for transfer return (sentUnitIDs.size()); }
void ClientGame::UpdateCamera(Miliseconds aFrameTime) const { Ogre::Vector3 pos(Ogre::Vector3::ZERO); Ogre::Quaternion ort(Ogre::Quaternion::ZERO); if (ClientUnit* avatar = GetUnit(mAvatar)) { GetCameraPosAndOrt(avatar->GetPosition(), pos, ort); } if (mFreeCamera) { mAxes->setOrientation(ort); mAxes->setPosition(pos); FreeCameraControl(aFrameTime); } else { ClientApp::GetCamera().setPosition(pos); ClientApp::GetCamera().setOrientation(ort); } }
void LIB_EDIT_FRAME::pasteClipboard( const wxPoint& aOffset ) { LIB_PART* part = GetCurPart(); if( !part || m_clipboard.GetCount() == 0 ) return; for( unsigned int i = 0; i < m_clipboard.GetCount(); i++ ) { // Append a copy to the current part, so the clipboard buffer might be pasted multiple times LIB_ITEM* item = (LIB_ITEM*) m_clipboard.GetItem( i )->Clone(); item->SetParent( part ); item->SetSelected(); item->SetUnit( GetUnit() ); part->AddDrawItem( item ); } BlockMoveSelectedItems( aOffset, GetCurPart(), &GetScreen()->m_BlockLocate ); RebuildView(); GetCanvas()->Refresh(); OnModify(); }
UnitData* UnitDatas::CreateUnit (INT32 nColPerBlock, INT32 nRowPerBlock, INT32 nBlockX, INT32 nBlockY) { POINT pointUnit; if (!ConvertPointPerBlockToPoint(nColPerBlock, nRowPerBlock, nBlockX, nBlockY, pointUnit)) { return NULL; } UnitData newData = UnitData(pointUnit); if (!IsExistsUnit(pointUnit)) { _lstUnit.push_back(newData); return GetUnit(pointUnit); } else { return NULL; } }
UnitData* UnitDatas::CreateUnit (POINT pointPerBlock, POINT pointBlock) { POINT pointUnit; if (!ConvertPointPerBlockToPoint(pointPerBlock, pointBlock, pointUnit)) { return NULL; } UnitData newData = UnitData(pointUnit); if (!IsExistsUnit(pointUnit)) { _lstUnit.push_back(newData); return GetUnit(pointUnit); } else { return NULL; } }
void OnLoad() { // we are friendly on spawn until we reach the battle place GetUnit()->SetFaction(35); // Get Twiggy Flathead and store him as linked creature to have nice and easy access to him Creature *twiggy = GetUnit()->GetMapMgr()->GetInterface()->GetCreatureNearestCoords(SPAWNPOINT_TWIGGYFLATHEAD, NPC_TWIGGYFLATHEAD); if(twiggy) SetLinkedCreature(twiggy->GetScript()); // set path to walk along to the affray sEAS.CreateCustomWaypointMap(GetUnit()); sEAS.WaypointCreate(GetUnit(), -1698, -4344.0f, 4.6f, 0.2f, 0, RUN, 0); sEAS.WaypointCreate(GetUnit(), -1684, -4335.0f, 2.9f, 0.7f, 0, RUN, 0); sEAS.WaypointCreate(GetUnit(), -1683, -4329.0f, 2.8f, 0.0f, 0, RUN, 0); sEAS.EnableWaypoints(GetUnit()); // after 3 minutes we will despawn unless something happens RegisterAIUpdateEvent(3*60*1000); }
CUIBase* CUIImageSplit::Clone() { CUIImageSplit* pImg = new CUIImageSplit(*this); pImg->setTexString( getTexString() ); pImg->SetSplitMode( (eSPLIT_TYPE)GetMode() ); pImg->SetUnit( GetUnit() ); CUIRectSurface* pRS = NULL; pRS = GetSurface(); if( pRS != NULL ) { { CUIRectSurface* pCopy = new CUIRectSurface; pCopy->CopyRectSurface(pRS); pImg->SetSurface(pCopy); } } CUIBase::CloneChild(pImg); return pImg; }
bool Field::Kill(std::shared_ptr<Unit> unit, const size_t reason) { auto cell = GetCell(unit->GetX(), unit->GetY()); Application *gui = Application::GetInstance(); if (cell->GetUnit() == unit) { const size_t id = unit->GetId(); *gui << "Unit "<< id << " is dead: " << pimpl_->GetReason(reason) << "\n"; const size_t x = unit->GetX(); const size_t y = unit->GetY(); const double energy = unit->GetDna("normal_weight"); const bool carnivore = unit->IsCarnivore(); cell->RemoveObject(); gui->RemoveObject(unit); unit->alive_ = false; unit->RemoveStatistics(); InsertNmo(std::make_shared<Flesh>(energy, carnivore), x, y); *gui << "Flesh of unit " << id << " inserted at: " << x << ", " << y << "\n"; return true; } else { *gui << "\nERROR: Possible lose of some object. Program will continue.\n"; return false; } }
void CUnitPane::OnPopupMenuGiveEverything (wxCommandEvent& event) { long idx = GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); CUnit * pUnit = GetUnit(idx); CEditPane * pOrders; wxString N; if (pUnit) { pOrders = (CEditPane*)gpApp->m_Panes[AH_PANE_UNIT_COMMANDS]; if (pOrders) pOrders->SaveModifications(); if (m_pCurLand) m_pCurLand->guiUnit = pUnit->Id; N = wxGetTextFromUser(wxT("Give everything to unit"), wxT("Confirm")); gpApp->SetOrdersChanged(gpApp->m_pAtlantis->GenGiveEverything(pUnit, N.mb_str()) || gpApp->GetOrdersChanged()); Update(m_pCurLand); } }