void CSelectedUnitsHandler::SelectCycle(const std::string& command) { static std::set<int> unitIDs; static int lastID = -1; if (command == "restore") { ClearSelected(); for (const int& unitID: unitIDs) { CUnit* unit = unitHandler->units[unitID]; if (unit != NULL) { AddUnit(unit); } } return; } if (selectedUnits.size() >= 2) { // assign the cycle units unitIDs.clear(); for (const CUnit* u: selectedUnits) { unitIDs.insert(u->id); } ClearSelected(); lastID = *unitIDs.begin(); AddUnit(unitHandler->units[lastID]); return; } // clean the list std::set<int> tmpSet; for (const int& unitID: unitIDs) { if (unitHandler->units[unitID] != NULL) { tmpSet.insert(unitID); } } unitIDs = tmpSet; if ((lastID >= 0) && (unitHandler->units[lastID] == NULL)) { lastID = -1; } // selectedUnits size is 0 or 1 ClearSelected(); if (!unitIDs.empty()) { std::set<int>::const_iterator fit = unitIDs.find(lastID); if (fit == unitIDs.end()) { lastID = *unitIDs.begin(); } else { ++fit; if (fit != unitIDs.end()) { lastID = *fit; } else { lastID = *unitIDs.begin(); } } AddUnit(unitHandler->units[lastID]); } }
void CSelectedUnitsHandler::SelectUnits(const std::string& line) { const std::vector<string>& args = CSimpleParser::Tokenize(line, 0); for (int i = 0; i < (int)args.size(); i++) { const std::string& arg = args[i]; if (arg == "clear") { selectedUnitsHandler.ClearSelected(); } else if ((arg[0] == '+') || (arg[0] == '-')) { char* endPtr; const char* startPtr = arg.c_str() + 1; const int unitIndex = strtol(startPtr, &endPtr, 10); if (endPtr == startPtr) continue; // bad number if ((unitIndex < 0) || (static_cast<unsigned int>(unitIndex) >= unitHandler->MaxUnits())) continue; // bad index CUnit* unit = unitHandler->units[unitIndex]; if (unit == nullptr) continue; if (!gu->spectatingFullSelect && (unit->team != gu->myTeam)) continue; // not mine to select // perform the selection if (arg[0] == '+') { AddUnit(unit); } else { RemoveUnit(unit); } } } }
void CSelectedUnits::HandleSingleUnitClickSelection(CUnit* unit, bool doInViewTest) { GML_RECMUTEX_LOCK(sel); // SelectUnits //FIXME make modular? const CMouseHandler::ButtonPressEvt& bp = mouse->buttons[SDL_BUTTON_LEFT]; if (unit == NULL) return; if (unit->team != gu->myTeam && !gu->spectatingFullSelect && !gs->godMode) return; if (bp.lastRelease < (gu->gameTime - mouse->doubleClickTime)) { if (keyInput->IsKeyPressed(SDLK_LCTRL) && (selectedUnits.find(unit) != selectedUnits.end())) { RemoveUnit(unit); } else { AddUnit(unit); } } else { //double click, select all units of same type (on screen, unless CTRL is pressed) int team, lastTeam; if (gu->spectatingFullSelect || gs->godMode) { team = 0; lastTeam = teamHandler->ActiveTeams() - 1; } else { team = gu->myTeam; lastTeam = gu->myTeam; } for (; team <= lastTeam; team++) { CUnitSet::iterator ui; CUnitSet& teamUnits = teamHandler->Team(team)->units; for (ui = teamUnits.begin(); ui != teamUnits.end(); ++ui) { if ((*ui)->unitDef->id == unit->unitDef->id) { if (!doInViewTest || keyInput->IsKeyPressed(SDLK_LCTRL) || camera->InView((*ui)->midPos)) { AddUnit(*ui); } } } } } #if (PLAY_SOUNDS == 1) Channels::UnitReply.PlayRandomSample(unit->unitDef->sounds.select, unit); #endif }
bool CSmileyTranslator::AddUnit(const TDVCHAR* pString, const TDVCHAR* pReplace, bool bCountAsSmiley) { if (pString != NULL && pString[0] != 0) { CSmileyUnit* pNew = new CSmileyUnit(pString, pReplace, bCountAsSmiley); int iValue = (unsigned char)pString[0]; AddUnit(pNew, iValue); } return true; }
bool CSceneManager::Init() { if(m_pHge->Resource_AttachPack("res.dat"))printf("LoadPack Success!\n"); else printf("LoadPack Fail!Try To Load From File...\n"); m_pRs = new hgeResourceManager(SCRIPTNAME); m_pRs->Precache(); m_pCamera = new C2DCamera(); m_pSelectSqure = new CSeletSqure(m_pRs, m_pCamera); m_pBG = m_pRs->GetSprite("Logo"); m_pSltSpr = m_pRs->GetSprite("TouchStart"); m_pMask = m_pRs->GetSprite("Black"); m_pGUI = new hgeGUI(); m_pGUI->SetCursor(m_pRs->GetSprite("Cursor")); m_pMap = new CMap(20,20, "city.bmp"); if(!m_pMap->Init()) return false; m_objs.push_back(new CGrid(m_pMap->m_col,m_pMap->m_row,m_pMap->m_tileWidth,m_pMap->m_tileHeight)); CMapElement* elem = new CMapElement(m_pRs, Point(40,40*8), "Elem01"); elem->Init(); m_objs.push_back(elem); elem = new CMapElement(m_pRs, Point(40*2,40*10), "Elem02"); elem->Init(); m_objs.push_back(elem); for(int i = 0;i < 32;i ++) { //AddUnit("girl", 400.f + 30*i, 180.f+m_pHge->Random_Float(0,50),CUnit::ENEMY); AddUnit("neko", 400, 250.f ,CUnit::OUR); } AddUnit("girl", 400, 250.f ,CUnit::OUR); m_pPlayer = new CPlayer(m_pRs, m_pSelectSqure, m_pMap); printf("Init Success!\n"); return true; }
UNIT * InstantiateUnit(LEVEL *pLevel, char * ArchetypeName, VECTOR position) { ARCHETYPE * pArchetype = FindArchetypeByName(pTheGame, ArchetypeName); UNIT * pUnit = AddUnit(pLevel, pArchetype, ArchetypeName); pUnit->pInitTransform->Position = position; pUnit->Tag = pUnit->pInitArchetype->Tag; InitializeUnit(pUnit); pUnit->pInitTransform = NULL; pUnit->pInitArchetype = NULL; return pUnit; }
void CSelectedUnitsHandler::HandleSingleUnitClickSelection(CUnit* unit, bool doInViewTest, bool selectType) { //FIXME make modular? if (unit == NULL) return; if (unit->team != gu->myTeam && !gu->spectatingFullSelect && !gs->godMode) return; if (!selectType) { if (KeyInput::GetKeyModState(KMOD_CTRL) && (selectedUnits.find(unit) != selectedUnits.end())) { RemoveUnit(unit); } else { AddUnit(unit); } } else { //double click, select all units of same type (on screen, unless CTRL is pressed) int team, lastTeam; if (gu->spectatingFullSelect || gs->godMode) { team = 0; lastTeam = teamHandler->ActiveTeams() - 1; } else { team = gu->myTeam; lastTeam = gu->myTeam; } for (; team <= lastTeam; team++) { for (CUnit* u: teamHandler->Team(team)->units) { if (u->unitDef->id == unit->unitDef->id) { if (!doInViewTest || KeyInput::GetKeyModState(KMOD_CTRL) || camera->InView((u)->midPos)) { AddUnit(u); } } } } } Channels::UnitReply->PlayRandomSample(unit->unitDef->sounds.select, unit); }
void World::Init() { float2 peonPos(SCREEN_WIDTH/4, SCREEN_HEIGHT/4); WalkTile::Align(peonPos); AddUnit(new WorkerUnit(peonPos, EUT_PEON)); float2 gruntPos(SCREEN_WIDTH/2, SCREEN_HEIGHT/2); WalkTile::Align(gruntPos); AddUnit(new Unit(gruntPos, EUT_GRUNT)); float2 minePos(3*SCREEN_WIDTH/4, SCREEN_HEIGHT/4); BuildTile::Align(minePos, EUT_MINE); AddUnit(new Unit(minePos, EUT_MINE)); float2 townhallPos(4*SCREEN_WIDTH/4, 3*SCREEN_HEIGHT/4); BuildTile::Align(townhallPos, EUT_TOWN_HALL); AddUnit(new Unit(townhallPos, EUT_TOWN_HALL)); #if 0 // used to kill performance for (int i = 0; i < 40; ++i) units_.push_back(new Unit(float2(3*SCREEN_WIDTH/4 - i*50, 3*SCREEN_HEIGHT/4), EUT_TOWN_HALL)); #endif }
void CMP_TREE_NODE_LIB_ID::Update( LIB_ALIAS* aAlias ) { Name = aAlias->GetName(); Desc = aAlias->GetDescription(); // Parent node is the library nickname so set the LIB_ID library nickname. IsRoot = aAlias->IsRoot(); // Pre-normalized strings for fast case-insensitive matching // Search text spaces out keywords and description to penalize description // matches - earlier matches are worth more. MatchName = aAlias->GetName().Lower(); SearchText = (aAlias->GetKeyWords() + " " + Desc); // Extract default footprint text LIB_PART* part = aAlias->GetPart(); wxString footprint; if( part ) { LibId = part->GetLibId(); LibId.SetLibItemName( Name ); footprint = part->GetFootprintField().GetText(); } // If a footprint is defined for the part, // add it to the serach string if( !footprint.IsEmpty() ) { SearchText += " "; SearchText += footprint; } Children.clear(); if( part && part->IsMulti() ) { for( int u = 1; u <= part->GetUnitCount(); ++u ) AddUnit( u ); } SearchTextNormalized = false; }
void CSelectedUnits::HandleUnitBoxSelection(const float4& planeRight, const float4& planeLeft, const float4& planeTop, const float4& planeBottom) { GML_RECMUTEX_LOCK(sel); // SelectUnits CUnit* unit = NULL; int addedunits = 0; int team, lastTeam; if (gu->spectatingFullSelect || gs->godMode) { // any team's units can be *selected* // (whether they can be given orders // depends on our ability to play god) team = 0; lastTeam = teamHandler->ActiveTeams() - 1; } else { team = gu->myTeam; lastTeam = gu->myTeam; } for (; team <= lastTeam; team++) { CUnitSet& teamUnits = teamHandler->Team(team)->units; for (CUnitSet::iterator ui = teamUnits.begin(); ui != teamUnits.end(); ++ui) { const float4 vec((*ui)->midPos, 1.0f); if (vec.dot4(planeRight) < 0.0f && vec.dot4(planeLeft) < 0.0f && vec.dot4(planeTop) < 0.0f && vec.dot4(planeBottom) < 0.0f) { if (keyInput->IsKeyPressed(SDLK_LCTRL) && (selectedUnits.find(*ui) != selectedUnits.end())) { RemoveUnit(*ui); } else { AddUnit(*ui); unit = *ui; addedunits++; } } } } #if (PLAY_SOUNDS == 1) if (addedunits >= 2) { Channels::UserInterface.PlaySample(soundMultiselID); } else if (addedunits == 1) { Channels::UnitReply.PlayRandomSample(unit->unitDef->sounds.select, unit); } #endif }
void CSelectedUnitsHandler::HandleUnitBoxSelection(const float4& planeRight, const float4& planeLeft, const float4& planeTop, const float4& planeBottom) { CUnit* unit = NULL; int addedunits = 0; int team, lastTeam; if (gu->spectatingFullSelect || gs->godMode) { // any team's units can be *selected* // (whether they can be given orders // depends on our ability to play god) team = 0; lastTeam = teamHandler->ActiveTeams() - 1; } else { team = gu->myTeam; lastTeam = gu->myTeam; } for (; team <= lastTeam; team++) { for (CUnit* u: teamHandler->Team(team)->units) { const float4 vec(u->midPos, 1.0f); if (vec.dot4(planeRight) < 0.0f && vec.dot4(planeLeft) < 0.0f && vec.dot4(planeTop) < 0.0f && vec.dot4(planeBottom) < 0.0f) { if (KeyInput::GetKeyModState(KMOD_CTRL) && (selectedUnits.find(u) != selectedUnits.end())) { RemoveUnit(u); } else { AddUnit(u); unit = u; addedunits++; } } } } if (addedunits >= 2) { Channels::UserInterface->PlaySample(soundMultiselID); } else if (addedunits == 1) { Channels::UnitReply->PlayRandomSample(unit->unitDef->sounds.select, unit); } }
void InterpretLevel(FILE * fpLevel) { char buffer[MAX_LENGTH]; LEVEL * pNewLevel = malloc(sizeof(LEVEL)); CAMERA * pCam = malloc(sizeof(CAMERA)); UNIT * pCurrUnit = NULL; pCam->Position = NewVector(0, 0); pCam->Zoom = 48; pNewLevel->Name = "Untitled"; pNewLevel->Order = 0; pNewLevel->pCamera = pCam; pNewLevel->nextUnit = NULL; pNewLevel->pGame = pTheGame; pNewLevel->nextLevel = pTheGame->nextLevel; pTheGame->nextLevel = pNewLevel; while (!feof(fpLevel)) { if (fgets(buffer, MAX_LENGTH, fpLevel)) { char question[MAX_LENGTH]; int inputInt = 0; float inputFloat = 0.0f; VECTOR inputVector = NewVector(0, 0); AddNull(buffer); if (buffer[0] != '#' && strlen(buffer) > 2) { sscanf(buffer, "%s", &question); if ((myStrCmp(question, "Name") <= 0) && pCurrUnit == NULL) { char nameInput[MAX_LENGTH]; sscanf(buffer, "Name = %s", nameInput); pNewLevel->Name = myStrCpy(nameInput); continue; } if (myStrCmp(question, "Order") <= 0) { char nameInput[MAX_LENGTH]; sscanf(buffer, "Order = %i", &inputInt); pNewLevel->Order = inputInt; continue; } if (myStrCmp(question, "UNIT") <= 0) { char archInput[MAX_LENGTH]; char nameInput[MAX_LENGTH]; ARCHETYPE * pArchetype = NULL; sscanf(buffer, "UNIT < %s > %s", &archInput, &nameInput); pArchetype = FindArchetypeByName(pTheGame, archInput); pCurrUnit = AddUnit(pNewLevel, pArchetype, myStrCpy(nameInput)); continue; } if (pCurrUnit) { if (myStrCmp(question, "Tag") <= 0) { char tagInput[MAX_LENGTH]; sscanf(buffer, "\tTag = %s", tagInput); pCurrUnit->Tag = GetTagFromString(tagInput); continue; } if (myStrCmp(question, "InitialPosition") <= 0) { sscanf(buffer, "\tInitialPosition = (%f, %f)", &inputVector.x, &inputVector.y); pCurrUnit->pInitTransform->Position = inputVector; continue; } if (myStrCmp(question, "InitialRotation") <= 0) { sscanf(buffer, "\tInitialRotation = %f", &inputFloat); pCurrUnit->pInitTransform->Rotation = inputFloat; continue; } if (myStrCmp(question, "InitialScale") <= 0) { sscanf(buffer, "\tInitialScale = (%f, %f)", &inputVector.x, &inputVector.y); pCurrUnit->pInitTransform->Scale = inputVector; continue; } if (myStrCmp(question, "VAR") <= 0) { VTYPE theType; VAR * newVar; char varInput[MAX_LENGTH]; char typeInput[MAX_LENGTH]; char dataInput[MAX_LENGTH]; void * data; sscanf(buffer, "\tVAR %s : %s = %s", &varInput, &typeInput, &dataInput); theType = GetVTypeFromString(typeInput); newVar = AddUnitVar(theType, varInput, pCurrUnit); if (theType == Float) { float x; sscanf(dataInput, "%f", &x); data = malloc(sizeof(x)); *((float*)newVar->Data) = x; } else if (theType == Int) { int x; sscanf(dataInput, "%i", &x); data = malloc(sizeof(x)); *(int*)newVar->Data = x; } else if (theType == Vector) { VECTOR x; sscanf(dataInput, "(%f, %f)", &x.x, &x.y); data = malloc(sizeof(x)); *(VECTOR*)newVar->Data = x; } else if (theType == String) { char * x; x = myStrCpy(dataInput); data = malloc(sizeof(x)); *(char**)newVar->Data = x; } else if (theType == Bool) { BOOL x; sscanf(dataInput, "%i", &x); data = malloc(sizeof(x)); *(BOOL*)newVar->Data = x; } else if (theType == Color) { COLOR x; sscanf(dataInput, "(%f, %f, %f, %f)", &x.r, &x.g, &x.b, &x.a); data = malloc(sizeof(x)); *(COLOR*)newVar->Data = x; } else if (theType == Char) { char x; sscanf(dataInput, "%c", &x); data = malloc(sizeof(x)); *(char*)newVar->Data = x; } else if (theType == Matrix) { MATRIX x; sscanf(dataInput, "{ {%f, %f, %f} {%f, %f, %f} {%f, %f, %f} }", &x.m[0][0], &x.m[0][1], &x.m[0][2], &x.m[1][0], &x.m[1][1], &x.m[1][2], &x.m[2][0], &x.m[2][1], &x.m[2][2]); data = malloc(sizeof(x)); *(MATRIX*)newVar->Data = x; } } } if (myStrCmp(question, "EndUnit") <= 0) { pCurrUnit = NULL; continue; } } } } }
bool CGraphmatFile :: GraphmatMain () { m_LastError = ""; if (0x500000 < GetInputBuffer().size()) { m_LastError = "File is to large, it cannot be more than 5 MB"; return false; }; InitTokenBuffer(); { // NUMBER of all UNITS which were read from INPUT file size_t CurrOutBufOffset = 0; // we should process all bytes except the last terminating null size_t InputBufferSize = GetInputBuffer().size()-1; for (size_t InputOffset = 0; InputOffset < InputBufferSize ; ) { CGraLine NewLine; NewLine.SetToken(GetUnitBufferStart() + CurrOutBufOffset); DWORD PageNumber; InputOffset = NewLine.ReadWord(InputOffset,this, PageNumber); // ignore single spaces in order to save memory if ( !NewLine.IsSingleSpaceToDelete() ) { AddUnit(NewLine); CurrOutBufOffset += NewLine.GetTokenLength(); if (NewLine.IsPageBreak() ) SetPageNumber(GetUnits().size() - 1,PageNumber); } else { assert (!GetUnits().empty()); GetUnit(GetUnits().size() -1).SetSingleSpaceAfter(); }; } } // больше TBuf не нужен, так что освобождаем память ClearInputBuffer(); for (size_t i=1; i< GetUnits().size(); i++) InitNonContextDescriptors(GetUnit(i)); if (m_bOnlyNonContextDescriptors) return true; BuildUnitBufferUpper(); InitContextDescriptors (0,GetUnits().size()); MacSynHierarchy(); if (m_bSentBreaker) if (!DealSentBreaker ()) { m_LastError = "An exception occurred in Sentence breaker"; return false; }; if (m_bWriteTextBuffer) WriteVector(m_SaveTxtName, GetUnitBuf()); if (m_bWriteGraFile) WriteGraphMat (m_GraFileName.c_str()); return true; };
struct List *GetUnits(char *name) { struct List *list; struct IFFHandle *iff; BOOL devnodes[UNITNODES] = { FALSE, FALSE, FALSE, FALSE } ; BOOL lownode = FALSE; int i; globalprefs.ahigp_MaxCPU = (90 << 16) / 100; list = AllocVec(sizeof(struct List), MEMF_CLEAR); if(list) { NewList(list); if(name && (iff = AllocIFF())) { iff->iff_Stream = Open(name, MODE_OLDFILE); if(iff->iff_Stream) { InitIFFasDOS(iff); if(!OpenIFF(iff, IFFF_READ)) { if(!(PropChunk (iff, ID_PREF, ID_AHIG) || CollectionChunk(iff, ID_PREF, ID_AHIU) || StopOnExit (iff, ID_PREF, ID_FORM))) { if(ParseIFF(iff, IFFPARSE_SCAN) == IFFERR_EOC) { struct StoredProperty *global = FindProp(iff, ID_PREF, ID_AHIG); struct CollectionItem *ci = FindCollection(iff, ID_PREF, ID_AHIU); if(global != NULL) { CopyMem(global->sp_Data, &globalprefs, min( sizeof(struct AHIGlobalPrefs), global->sp_Size )); } while(ci) { struct AHIUnitPrefs *p = ci->ci_Data; struct UnitNode *u; u = AllocVec(sizeof(struct UnitNode), MEMF_CLEAR); if(u == NULL) break; CopyMem(p, &u->prefs, min( sizeof(struct AHIUnitPrefs), ci->ci_Size )); FillUnitName(u); u->node.ln_Pri = -(u->prefs.ahiup_Unit); Enqueue(list, (struct Node *) u); if(u->prefs.ahiup_Unit == AHI_NO_UNIT) { lownode = TRUE; } else if(u->prefs.ahiup_Unit < UNITNODES) { devnodes[u->prefs.ahiup_Unit] = TRUE; } ci=ci->ci_Next; } } } CloseIFF(iff); } Close(iff->iff_Stream); } FreeIFF(iff); } // Fill up to lowlevel + UNITNODES device nodes, if not found in prefs file if(!lownode) AddUnit(list, AHI_NO_UNIT); for(i = 0; i < UNITNODES; i++) { if(!devnodes[i]) AddUnit(list, i); } } return list; }