void R_Entity_UpdateAllTargetWaypoints(entity_t *pEnt, entity_t *pOriginalEnt, bool bHide) { if (pEnt) { if (strlen(ValueForKey(pEnt, sKEY_WAYPOINTHIDE_RECURSION_PROTECT))==0) { SetKeyValue(pEnt, sKEY_WAYPOINTHIDE_RECURSION_PROTECT, "1"); // note: actual value irrelevant, just so long as strlen()!=0 CString str; entity_t *pDestEnt; str = ValueForKey(pEnt, "target"); if (str.GetLength() > 0) { pDestEnt = FindEntity("targetname", str.GetBuffer(0)); R_Entity_UpdateAllTargetWaypoints(pDestEnt, pOriginalEnt, bHide); } str = ValueForKey(pEnt, "target2"); if (str.GetLength() > 0) { pDestEnt = FindEntity("targetname", str.GetBuffer(0)); R_Entity_UpdateAllTargetWaypoints(pDestEnt, pOriginalEnt, bHide); } str = ValueForKey(pEnt, "target3"); if (str.GetLength() > 0) { pDestEnt = FindEntity("targetname", str.GetBuffer(0)); R_Entity_UpdateAllTargetWaypoints(pDestEnt, pOriginalEnt, bHide); } str = ValueForKey(pEnt, "target4"); if (str.GetLength() > 0) { pDestEnt = FindEntity("targetname", str.GetBuffer(0)); R_Entity_UpdateAllTargetWaypoints(pDestEnt, pOriginalEnt, bHide); } if (pEnt != pOriginalEnt) // because we don't want to hide/unhide ourselves, just the children { if (bHide) { SetKeyValue(pEnt, sKEY_HIDDENWAYPOINT, "1"); // note: actual value irrelevant, just so long as strlen()!=0 } else { DeleteKey(pEnt, sKEY_HIDDENWAYPOINT); } } } } }
//------------------------------------------------------------------------------ // Purpose: //------------------------------------------------------------------------------ void CScriptedTarget::ScriptThink( void ) { // -------------------------------------------- // If I don't have target entity look for one // -------------------------------------------- if (GetTarget() == NULL) { m_flPauseDoneTime = 0; SetTarget( FindEntity() ); } SetNextThink( gpGlobals->curtime + 0.1f ); }
void CCineMonster::CineThink(void) { if(FindEntity()) { PossessEntity(); ALERT(at_aiconsole, "script \"%s\" using monster \"%s\"\n", STRING(pev->targetname), STRING(m_iszEntity)); } else { CancelScript(); ALERT(at_aiconsole, "script \"%s\" can't find monster \"%s\"\n", STRING(pev->targetname), STRING(m_iszEntity)); pev->nextthink = gpGlobals->time + 1.0; } }
// // ********** Cinematic Think ********** // void CCineMonster::CineThink( void ) { if( FindEntity() ) { PossessEntity(); ALERT( at_aiconsole, "script \"%s\" using monster \"%s\"\n", GetTargetname(), STRING( m_iszEntity ) ); } else { CancelScript(); ALERT( at_aiconsole, "script \"%s\" can't find monster \"%s\"\n", GetTargetname(), STRING( m_iszEntity ) ); SetNextThink( gpGlobals->time + 1.0 ); } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CPhysExplosion::Explode( CBaseEntity *pActivator ) { CBaseEntity *pEntity = NULL; float adjustedDamage, falloff, flDist; Vector vecSpot; falloff = 1.0 / 2.5; // iterate on all entities in the vicinity. // I've removed the traceline heuristic from phys explosions. SO right now they will // affect entities through walls. (sjb) // UNDONE: Try tracing world-only? while ((pEntity = FindEntity(pEntity, pActivator)) != NULL) { // UNDONE: Ask the object if it should get force if it's not MOVETYPE_VPHYSICS? if ( pEntity->m_takedamage != DAMAGE_NO && (pEntity->GetMoveType() == MOVETYPE_VPHYSICS || (pEntity->VPhysicsGetObject() && !pEntity->IsPlayer())) ) { vecSpot = pEntity->BodyTarget( GetAbsOrigin() ); // decrease damage for an ent that's farther from the bomb. flDist = ( GetAbsOrigin() - vecSpot ).Length(); if( m_radius == 0 || flDist <= m_radius ) { adjustedDamage = flDist * falloff; adjustedDamage = m_damage - adjustedDamage; if ( adjustedDamage < 0 ) { adjustedDamage = 0; } CTakeDamageInfo info( this, this, adjustedDamage, DMG_BLAST ); CalculateExplosiveDamageForce( &info, (vecSpot - GetAbsOrigin()), GetAbsOrigin() ); if ( HasSpawnFlags( SF_PHYSEXPLOSION_NODAMAGE ) ) { pEntity->VPhysicsTakeDamage( info ); } else { pEntity->TakeDamage( info ); } } } } }
void CScriptedSentence::FindThink(void) { CBaseMonster *pMonster = FindEntity(); if(pMonster) { StartSentence(pMonster); if(pev->spawnflags & SF_SENTENCE_ONCE) UTIL_Remove(this); SetThink(&CScriptedSentence::DelayThink); pev->nextthink = gpGlobals->time + m_flDuration + m_flRepeat; m_active = FALSE; // ALERT( at_console, "%s: found monster %s\n", STRING(m_iszSentence), STRING(m_iszEntity) ); } else { // ALERT( at_console, "%s: can't find monster %s\n", STRING(m_iszSentence), STRING(m_iszEntity) ); pev->nextthink = gpGlobals->time + m_flRepeat + 0.5; } }
int SquadronClass::MoveUnit (CampaignTime time) { GridIndex x,y,nx,ny; VuGridIterator* myit = NULL; Objective o,bo=NULL; float fd; int range,score,i,want_alert=0,bs=-999; CampEntity ab; /* Don't recall squadrons - per Gilman if (GetTotalVehicles() < GetFullstrengthVehicles() / 4) { if (this == FalconLocalSession->GetPlayerSquadron()) PostMessage(FalconDisplay.appWin,FM_SQUADRON_RECALLED,0,0); KillUnit(); } */ //TJL 11/02/03 Enable Scramble missions if (g_bScramble) { // Set up an alert bird for this squadron if (rating[ARO_CA] > 4) { // KCK: Check if we have available aircraft // NOTE: We might want to make sure we always ask for at least one // alert flight. for (i=0; i<VEHICLES_PER_UNIT/2; i++) { if (!schedule[i]) want_alert = 1; } if (want_alert) { //#ifdef DEBUG MonoPrint("Requesting alert bird for squadron #%d.\n",GetCampID()); //#endif MissionRequestClass mis; // JB 010728 Make the wait time configurable // MN 020102 This is not the relocation timer - check above // mis.tot = Camp_GetCurrentTime() + g_nRelocationWait * CampaignHours; // hang around for a few hours mis.tot = Camp_GetCurrentTime() + 3 * CampaignHours; mis.requesterID = Id(); mis.who = GetTeam(); mis.vs = GetEnemyTeam(mis.who); mis.tot_type = TYPE_NE; GetLocation(&mis.tx,&mis.ty); mis.targetID = FalconNullId; mis.mission = AMIS_ALERT; mis.roe_check = ROE_AIR_ENGAGE; mis.flags = REQF_ONETRY | REQF_USE_REQ_SQUAD | REQF_USERESERVES; mis.priority = 255; // High priority mis.RequestMission(); } } } else { } //TJL 11/02/03 End Scramble // OW AB Relocation fix if(g_bEnableABRelocation) { if(SimLibElapsedTime < 32450000.0f) return 0; //me123 dont relocate before the campaign has begun } ab = FindEntity(airbase_id); // A.S. begin CampEntity ab_old; // A.S. new variable if (g_bHelosReloc) { ab_old = ab; } // A.S. end ShiAssert (!ab || ab->IsObjective() || ab->IsTaskForce() || (ab == this && DontPlan())); if (!ab || ab->IsObjective() || ab == this) { // Don't plan flag used to mean don't rebase for squadrons if (DontPlan()) { // 2001-08-06 MODIFIED BY S.G. FRIENDLY BASE WILL DO THE JOB ALL RIGHT. NO NEED TO LIMIT IT TO OUR TEAM. // if (ab->GetTeam() != GetTeam()) if (!ab || !GetRoE(ab->GetTeam(), GetTeam(), ROE_AIR_USE_BASES)) { if (this == FalconLocalSession->GetPlayerSquadron()) PostMessage(FalconDisplay.appWin,FM_SQUADRON_RECALLED,0,0); KillUnit(); } return 0; } // If airbase is non-functional, force a rebase // 2001-08-03 MODIFIED BY S.G. ONLY IF CAPTURED SHOULD IT RELOCATE. DESTROYED AIRBASE STILL OWN BY US WILL REPAIR EVENTUALLY. // if (ab && ab->IsObjective() && ((Objective)ab)->GetAdjustedDataRate() < 1) if (ab && ab->IsObjective() && !GetRoE(ab->GetTeam(), GetTeam(), ROE_AIR_USE_BASES)) ab = NULL; // Added by A.S. 1.1.2002. Helos will be reallocated if armybase is destoyed. if (g_bHelosReloc) { if (ab && ab->IsObjective() && IsHelicopter() && ((Objective)ab)->GetAdjustedDataRate() < 1) { ab = NULL; // FILE *deb; // deb = fopen("c:\\temp\\realloc.txt", "a"); // fprintf(deb, "ArmyBase ID = %d team = %x type = %x TIME = %d\n", ab_old, ab_old->GetTeam, ab_old->GetType, TheCampaign.CurrentTime/(3600*1000)); // fclose(deb); } } // A.S. end // Check airbase location - if to near or far from front, relocate GetLocation(&x,&y); fd = DistanceToFront(x,y); range = GetUnitRange(); // 2001-07-05 MODIFIED BY S.G. DON'T RELOCATE IF TOO FAR FROM FLOT IF GLOBALLY SET TO ACT THAT WAY // if (fd < 999.0F && (fd < range/30 || fd > range/3 || !ab)) // We're to close or to far from the front or don't have an airbase if (fd < 999.0F && (fd < range/30 || (!(g_nAirbaseReloc & AirBaseRelocNoFar) && fd > range/3) || !ab)) // We're to close or to far from the front or don't have an airbase { // Find a better base for us UnitClassDataType *uc = GetUnitClassData(); ATMAirbaseClass *atmbase; Team us = GetTeam(); CAMPREGLIST_ITERATOR myit(AllObjList); o = (Objective) myit.GetFirst(); while (o) { // 2001-07-05 MODIFIED BY S.G. ONLY USE YOUR OWN AIRBASE IF GLOBALLY SET TO ACT THAT WAY // if ((o->GetType() == TYPE_AIRBASE && !IsHelicopter() && GetRoE(o->GetTeam(),us,ROE_AIR_USE_BASES)) || // (o->GetType() == TYPE_ARMYBASE && IsHelicopter() && GetRoE(o->GetTeam(),us,ROE_AIR_USE_BASES))) int enter = FALSE; if (g_nAirbaseReloc & AirBaseRelocTeamOnly) { if ((o->GetType() == TYPE_AIRBASE && !IsHelicopter() && o->GetTeam() == us) || (o->GetType() == TYPE_ARMYBASE && IsHelicopter() && o->GetTeam() == us)) enter = TRUE; } else { if ((o->GetType() == TYPE_AIRBASE && !IsHelicopter() && GetRoE(o->GetTeam(),us,ROE_AIR_USE_BASES)) || (o->GetType() == TYPE_ARMYBASE && IsHelicopter() && GetRoE(o->GetTeam(),us,ROE_AIR_USE_BASES))) enter = TRUE; } if (enter) // END OF MODIFIED SECTION { o->GetLocation(&nx,&ny); fd = DistanceToFront(nx,ny); if (fd > range/15 && o->GetAdjustedDataRate() > 0) { score = o->GetObjectiveStatus()*5 - FloatToInt32(fd); // Adjust by number of squadrons already based here. atmbase = TeamInfo[us]->atm->FindATMAirbase (o->Id()); if (atmbase && atmbase->usage) // JB 010328 from Mad__Max //score /= atmbase->usage; { if (o != ab) score /= (atmbase->usage+1); if (o == ab) score /= atmbase->usage; } // JB 010328 from Mad__Max if (score > bs) { bo = o; bs = score; } } } o = (Objective) myit.GetNext(); } if (bo) { if (bo != ab) { bo->GetLocation(&nx,&ny); SetLocation(nx,ny); SetUnitAirbase(bo->Id()); TeamInfo[us]->atm->AddToAirbaseList(bo); if (this == FalconLocalSession->GetPlayerSquadron()) PostMessage(FalconDisplay.appWin,FM_SQUADRON_REBASED,0,0); // 2001-07-05 MODIFIED BY S.G. RETASK IN ONE DAY ONLY // 020102 M.N. Variable relocate time squadronRetaskAt = Camp_GetCurrentTime() + CampaignHours * g_nRelocationWait; // A.S. begin: retask time for Helos only 1 hour if (g_bHelosReloc) { if (ab_old && ab_old->IsObjective() && ((Objective)ab_old)->GetAdjustedDataRate() < 1) { if ( IsHelicopter() ) { squadronRetaskAt = Camp_GetCurrentTime() + CampaignHours * 1; // FILE *deb; // deb = fopen("c:\\temp\\realloc.txt", "a"); // fprintf(deb, "====> squadronRetaskAt ID = %d ID_neu %d team = %x type = %x TIME = %d\n\n", ab_old, bo, ab_old->GetTeam, ab_old->GetType, TheCampaign.CurrentTime/(3600*1000)); // fclose(deb); } } } // A.S. end +++++++++++++++++ } } else { // We're lost if (this == FalconLocalSession->GetPlayerSquadron()) PostMessage(FalconDisplay.appWin,FM_SQUADRON_RECALLED,0,0); KillUnit(); return 0; } } } // Set up an alert bird for this squadron //TJL 10/31/03 Move This /* if (rating[ARO_CA] > 5) { // KCK: Check if we have available aircraft // NOTE: We might want to make sure we always ask for at least one // alert flight. for (i=0; i<VEHICLES_PER_UNIT/2; i++) { if (!schedule[i]) want_alert = 1; } if (want_alert) { #ifdef DEBUG // MonoPrint("Requesting alert bird for squadron #%d.\n",GetCampID()); #endif MissionRequestClass mis; // JB 010728 Make the wait time configurable // MN 020102 This is not the relocation timer - check above // mis.tot = Camp_GetCurrentTime() + g_nRelocationWait * CampaignHours; // hang around for a few hours mis.tot = Camp_GetCurrentTime() + 3 * CampaignHours; mis.requesterID = Id(); mis.who = GetTeam(); mis.vs = GetEnemyTeam(mis.who); mis.tot_type = TYPE_NE; GetLocation(&mis.tx,&mis.ty); mis.targetID = FalconNullId; mis.mission = AMIS_ALERT; mis.roe_check = ROE_AIR_ENGAGE; mis.flags = REQF_ONETRY | REQF_USE_REQ_SQUAD | REQF_USERESERVES; mis.priority = 255; // High priority mis.RequestMission(); } } */ return 0; }
// // ======================================================================================================================= // Map_ImportFile Timo 09/01/99:: called by CXYWnd::Paste & Map_ImportFile if Map_ImportFile ( prefab ), the buffer // may contain brushes in old format ( conversion needed ) // ======================================================================================================================= // void Map_ImportBuffer(char *buf, bool renameEntities) { entity_t *ent; brush_t *b = NULL; CPtrArray ptrs; Select_Deselect(); Undo_Start("import buffer"); g_qeglobals.d_parsed_brushes = 0; if (buf) { CMapStringToString mapStr; StartTokenParsing(buf); g_qeglobals.d_num_entities = 0; // // Timo will be used in Entity_Parse to detect if a conversion between brush // formats is needed // g_qeglobals.bNeedConvert = false; g_qeglobals.bOldBrushes = false; g_qeglobals.bPrimitBrushes = false; g_qeglobals.mapVersion = 1.0; if (GetToken(true)) { if (stricmp(token, "Version") == 0) { GetToken(false); g_qeglobals.mapVersion = atof(token); common->Printf("Map version: %1.2f\n", g_qeglobals.mapVersion); } else { UngetToken(); } } idDict RemappedNames; // since I can't use "map <string, string>"... sigh. So much for STL... while (1) { // // use the selected brushes list as it's handy ent = Entity_Parse (false, // &selected_brushes); // ent = Entity_Parse(false, &active_brushes); if (!ent) { break; } // end entity for undo Undo_EndEntity(ent); // end brushes for undo for (b = ent->brushes.onext; b && b != &ent->brushes; b = b->onext) { Undo_EndBrush(b); } if (!strcmp(ValueForKey(ent, "classname"), "worldspawn")) { // world brushes need to be added to the current world entity b = ent->brushes.onext; while (b && b != &ent->brushes) { brush_t *bNext = b->onext; Entity_UnlinkBrush(b); Entity_LinkBrush(world_entity, b); ptrs.Add(b); b = bNext; } } else { // the following bit remaps conflicting target/targetname key/value pairs CString str = ValueForKey(ent, "target"); CString strKey; CString strTarget(""); if (str.GetLength() > 0) { if (FindEntity("target", str.GetBuffer(0))) { if (!mapStr.Lookup(str, strKey)) { idStr key; UniqueTargetName(key); strKey = key; mapStr.SetAt(str, strKey); } strTarget = strKey; SetKeyValue(ent, "target", strTarget.GetBuffer(0)); } } /* * str = ValueForKey(ent, "name"); if (str.GetLength() > 0) { if * (FindEntity("name", str.GetBuffer(0))) { if (!mapStr.Lookup(str, strKey)) { * UniqueTargetName(strKey); mapStr.SetAt(str, strKey); } Entity_SetName(ent, * strKey.GetBuffer(0)); } } */ CString cstrNameOld = ValueForKey(ent, "name"); Entity_Name(ent, renameEntities); CString cstrNameNew = ValueForKey(ent, "name"); if (cstrNameOld != cstrNameNew) { RemappedNames.Set(cstrNameOld, cstrNameNew); } // // if (strTarget.GetLength() > 0) SetKeyValue(ent, "target", // strTarget.GetBuffer(0)); // add the entity to the end of the entity list // ent->next = &entities; ent->prev = entities.prev; entities.prev->next = ent; entities.prev = ent; g_qeglobals.d_num_entities++; for (b = ent->brushes.onext; b != &ent->brushes; b = b->onext) { ptrs.Add(b); } } } // now iterate through the remapped names, and see if there are any target-connections that need remaking... // // (I could probably write this in half the size with STL, but WTF, work with what we have...) // int iNumKeyVals = RemappedNames.GetNumKeyVals(); for (int iKeyVal=0; iKeyVal < iNumKeyVals; iKeyVal++) { const idKeyValue *pKeyVal = RemappedNames.GetKeyVal( iKeyVal ); LPCSTR psOldName = pKeyVal->GetKey().c_str(); LPCSTR psNewName = pKeyVal->GetValue().c_str(); entity_t *pEntOld = FindEntity("name", psOldName); // original ent we cloned from entity_t *pEntNew = FindEntity("name", psNewName); // cloned ent if (pEntOld && pEntNew) { CString cstrTargetNameOld = ValueForKey(pEntOld, "target"); if (!cstrTargetNameOld.IsEmpty()) { // ok, this ent was targeted at another ent, so it's clone needs updating to point to // the clone of that target, so... // entity_t *pEntOldTarget = FindEntity("name", cstrTargetNameOld); if ( pEntOldTarget ) { LPCSTR psNewTargetName = RemappedNames.GetString( cstrTargetNameOld ); if (psNewTargetName && psNewTargetName[0]) { SetKeyValue(pEntNew, "target", psNewTargetName); } } } } } } // // ::ShowWindow(g_qeglobals.d_hwndEntity, FALSE); // ::LockWindowUpdate(g_qeglobals.d_hwndEntity); // g_bScreenUpdates = false; for (int i = 0; i < ptrs.GetSize(); i++) { Brush_Build(reinterpret_cast < brush_t * > (ptrs[i]), true, false); Select_Brush(reinterpret_cast < brush_t * > (ptrs[i]), true, false); } // ::LockWindowUpdate(NULL); g_bScreenUpdates = true; ptrs.RemoveAll(); // // reset the "need conversion" flag conversion to the good format done in // Map_BuildBrushData // g_qeglobals.bNeedConvert = false; Sys_UpdateWindows(W_ALL); // Sys_MarkMapModified(); mapModified = 1; Undo_End(); }
void ExpandSpecialVar( char *name, Element_t *e, FILE *fp, int track_pos ) { FILE *infile; char buf[LINESIZE], *cp, *cp2, *atval; char **tok; int ntok, n, i, actioni; char *action, *action1; Element_t *ep; Trans_t *t, *tt; Entity_t *entp; /* Run a command. * Format: _! command args ... */ if (*name == '!') { name++; if ((infile = popen(name, "r"))) { while (fgets(buf, LINESIZE, infile)) fputs(buf, fp); pclose(infile); fflush(fp); } else { fprintf(stderr, "Could not start program '%s': %s", name, strerror(errno)); } return; } /* See if caller wants one of the tokens from _eachatt or _eachcon. * If so, output it and return. (Yes, I admit that this is a hack.) */ if (*name == 'A' && name[1] == EOS && each_A) { OutputString(each_A, fp, track_pos); return; } if (*name == 'C' && name[1] == EOS && each_C) { OutputString(each_C, fp, track_pos); return; } ntok = 0; tok = Split(name, &ntok, 0); /* Include another file. * Format: _include filename */ if (StrEq(tok[0], "include")) { name = tok[1]; if (ntok > 1 ) { if ((infile=OpenFile(name)) == NULL) { sprintf(buf, "Can not open included file '%s'", name); perror(buf); return; } while (fgets(buf, LINESIZE, infile)) fputs(buf, fp); fclose(infile); } else fprintf(stderr, "No file name specified for include\n"); return; } /* Print location (nearest title, line no, path). * Format: _location */ else if (StrEq(tok[0], "location")) { PrintLocation(e, fp); } /* Print path to this element. * Format: _path */ else if (StrEq(tok[0], "path")) { (void)FindElementPath(e, buf); OutputString(buf, fp, track_pos); } /* Print name of this element (gi). * Format: _gi [M|L|U] */ else if (StrEq(tok[0], "gi")) { strcpy(buf, e->gi); if (ntok >= 2) { if (*tok[1] == 'L' || *tok[1] == 'l' || *tok[1] == 'M' || *tok[1] == 'm') { for (cp=buf; *cp; cp++) if (isupper(*cp)) *cp = tolower(*cp); } if (*tok[1] == 'M' || *tok[1] == 'm') if (islower(buf[0])) buf[0] = toupper(buf[0]); } OutputString(buf, fp, track_pos); } /* Print filename of this element's associated external entity. * Format: _filename */ else if (StrEq(tok[0], "filename")) { if ( ntok >= 2 ) { cp2 = FindAttValByName(e, tok[1]); if ( ! (entp = FindEntity(cp2)) ) { fprintf(stderr, "Can't find entity named %s (via _filename expression):\n", tok[1]); PrintLocation(e, stderr); return; } OutputString(entp->sysid, fp, track_pos); } else { if (!e->entity) { fprintf(stderr, "Expected ext entity (element %s) - no ->entity (internal error? bug?):\n", e->gi); PrintLocation(e, stderr); return; } if (!e->entity->fname) { fprintf(stderr, "Expected filename (element %s) - no ->entity->fname (internal error? bug?):\n", e->gi); PrintLocation(e, stderr); return; } OutputString(e->entity->sysid, fp, track_pos); } } /* Value of parent's attribute, by attr name. * Format: _pattr attname */ else if (StrEq(tok[0], "pattr")) { ep = e->parent; if (!ep) { fprintf(stderr, "Element does not have a parent:\n"); PrintLocation(ep, stderr); return; } if ((atval = FindAttValByName(ep, tok[1]))) { OutputString(atval, fp, track_pos); } } /* Use an action, given transpec's SID. * Format: _action action */ else if (StrEq(tok[0], "action")) { TranTByAction(e, tok[1], fp); } /* Number of child elements of this element. * Format: _nchild */ else if (StrEq(tok[0], "nchild")) { if (ntok > 1) { for (n=0,i=0; i<e->necont; i++) if (StrEq(e->econt[i]->gi, tok[1])) n++; } else n = e->necont; sprintf(buf, "%d", n); OutputString(buf, fp, track_pos); } /* number of 1st child's child elements (grandchildren from first child). * Format: _n1gchild */ else if (StrEq(tok[0], "n1gchild")) { if (e->necont) { sprintf(buf, "%d", e->econt[0]->necont); OutputString(buf, fp, track_pos); } } /* Chase this element's pointers until we hit the named GI. * Do the action if it matches. * Format: _chasetogi gi action */ else if (StrEq(tok[0], "chasetogi")) { if (ntok < 3) { fprintf(stderr, "Error: Not enough args for _chasetogi.\n"); return; } actioni = atoi(tok[2]); if (actioni) ChaseIDRefs(e, tok[1], tok[2], fp); } /* Follow link to element pointed to, then do action. * Format: _followlink [attname] action. */ else if (StrEq(tok[0], "followlink")) { char **s; if (ntok > 2) { if ((atval = FindAttValByName(e, tok[1]))) { if ((ep = FindElemByID(atval))) { TranTByAction(ep, tok[2], fp); return; } } else fprintf(stderr, "Error: Did not find attr: %s.\n", tok[1]); return; } GetIDREFnames(); for (s=idrefs; *s; s++) { /* is this IDREF attr set? */ if ((atval = FindAttValByName(e, *s))) { ntok = 0; tok = Split(atval, &ntok, S_STRDUP); /* we'll follow the first one... */ if ((ep = FindElemByID(tok[0]))) { TranTByAction(ep, tok[1], fp); return; } else fprintf(stderr, "Error: Can not find elem for ID: %s.\n", tok[0]); } } fprintf(stderr, "Error: Element does not have IDREF attribute set:\n"); PrintLocation(e, stderr); return; } /* Starting at this element, decend tree (in-order), finding GI. * Do the action if it matches. * Format: _find args ... */ else if (StrEq(tok[0], "find")) { Find(e, ntok, tok, fp); } /* Starting at this element's parent, decend tree (in-order), finding GI. * Do the action if it matches. * Format: _pfind args ... */ else if (StrEq(tok[0], "pfind")) { Find(e->parent ? e->parent : e, ntok, tok, fp); } /* Content is supposed to be a list of IDREFs. Follow each, doing action. * If 2 actions are specified, use 1st for the 1st ID, 2nd for the rest. * Format: _namelist action [action2] */ else if (StrEq(tok[0], "namelist")) { int id; action1 = tok[1]; if (ntok > 2) action = tok[2]; else action = action1; for (i=0; i<e->ndcont; i++) { n = 0; tok = Split(e->dcont[i], &n, S_STRDUP); for (id=0; id<n; id++) { if (fold_case) for (cp=tok[id]; *cp; cp++) if (islower(*cp)) *cp = toupper(*cp); if ((e = FindElemByID(tok[id]))) { if (id) TranTByAction(e, action, fp); else TranTByAction(e, action1, fp); /* first one */ } else fprintf(stderr, "Error: Can not find ID: %s.\n", tok[id]); } } } /* For each word in the element's content, do action. * Format: _eachcon action [action] */ else if (StrEq(tok[0], "eachcon")) { int id; action1 = tok[1]; if (ntok > 3) action = tok[2]; else action = action1; for (i=0; i<e->ndcont; i++) { n = 0; tok = Split(e->dcont[i], &n, S_STRDUP|S_ALVEC); for (id=0; id<n; id++) { each_C = tok[id]; TranTByAction(e, action, fp); } free(*tok); } } /* For each word in the given attribute's value, do action. * Format: _eachatt attname action [action] */ else if (StrEq(tok[0], "eachatt")) { int id; action1 = tok[2]; if (ntok > 3) action = tok[3]; else action = action1; if ((atval = FindAttValByName(e, tok[1]))) { n = 0; tok = Split(atval, &n, S_STRDUP|S_ALVEC); for (id=0; id<n; id++) { each_A = tok[id]; if (id) TranTByAction(e, action, fp); else TranTByAction(e, action1, fp); /* first one */ } free(*tok); } } /* Do action on this element if element has [relationship] with gi. * Format: _relation relationship gi action [action] */ else if (StrEq(tok[0], "relation")) { if (ntok >= 4) { if (!CheckRelation(e, tok[1], tok[2], tok[3], fp, RA_Current)) { /* action not done, see if alt action specified */ if (ntok >= 5) TranTByAction(e, tok[4], fp); } } } /* Do action on followed element if element has [relationship] with gi. * Format: _followrel relationship gi action */ else if (StrEq(tok[0], "followrel")) { if (ntok >= 4) (void)CheckRelation(e, tok[1], tok[2], tok[3], fp, RA_Related); } /* Find element with matching ID and do action. If action not specified, * choose the right one appropriate for its context. * Format: _id id [action] */ else if (StrEq(tok[0], "id")) { if ((ep = FindElemByID(tok[1]))) { if (ntok > 2) TranTByAction(ep, tok[2], fp); else { t = FindTrans(ep, 0); TransElement(ep, fp, t); } } } /* Set variable to value. * Format: _set name value */ else if (StrEq(tok[0], "set")) { SetMappingNV(Variables, tok[1], tok[2]); } /* Do action if variable is set, optionally to value. * If not set, do nothing. * Format: _isset varname [value] action * Format: _issete varname [value] action -- expands value */ else if (StrEq(tok[0], "isset") || StrEq(tok[0], "issete")) { if ((cp = FindMappingVal(Variables, tok[1]))) { if (ntok == 3) TranTByAction(e, tok[2], fp); else if (ntok > 3) { if ( StrEq(tok[0], "issete") ) { ExpandVariables(tok[2], buf, e); cp2 = buf; } else cp2 = tok[2]; if ( !strcmp(cp, cp2)) TranTByAction(e, tok[3], fp); } } } /* Insert a node into the tree at start/end, pointing to action to perform. * Format: _insertnode S|E action */ else if (StrEq(tok[0], "insertnode")) { actioni = atoi(tok[2]); if (*tok[1] == 'S') e->gen_trans[0] = actioni; else if (*tok[1] == 'E') e->gen_trans[1] = actioni; } /* Do an CALS DTD table spec for TeX or troff. Looks through attributes * and determines what to output. "check" means to check consistency, * and print error messages. * This is (hopefully) the only hard-coded part of instant. * * This was originally written for the OSF DTDs and recoded by FLD for * CALS tables (since no one will ever use the OSF tables). Although * TeX was addressed first, it seems that a fresh approach was required, * and so, tbl is the first to be really *fixed*. Once tbl is stable, * and there is a need for TeX again, that part will be recoded. * * *Obsolete* form (viz, for TeX): * Format: _calstable [clear|check|tex] * [cellstart|cellend|rowstart|rowend|top|bottom] * * New, good form: * * Format: _calstable [tbl] * [tablestart|tableend|tablegroup|tablefoot|rowstart| * rowend|entrystart|entryend] */ else if (StrEq(tok[0], "calstable")) { CALStable(e, fp, tok, ntok); } /* Do action if element's attr is set, optionally to value. * If not set, do nothing. * Format: _attval att [value] action */ else if (StrEq(tok[0], "attval")) { if ((atval = FindAttValByName(e, tok[1]))) { if (ntok == 3) TranTByAction(e, tok[2], fp); else if (ntok > 3 && !strcmp(atval, tok[2])) TranTByAction(e, tok[3], fp); } } /* Same thing, but look at parent */ else if (StrEq(tok[0], "pattval")) { if ((atval = FindAttValByName(e->parent, tok[1]))) { if (ntok == 3) { TranTByAction(e, tok[2], fp); } if (ntok > 3 && !strcmp(atval, tok[2])) TranTByAction(e, tok[3], fp); } } /* Print each attribute and value for the current element, hopefully * in a legal sgml form: <elem-name att1="value1" att2="value2:> . * Format: _allatts */ else if (StrEq(tok[0], "allatts")) { for (i=0; i<e->natts; i++) { if (i != 0) putc(' ', fp); fputs(e->atts[i].name, fp); fputs("=\"", fp); fputs(e->atts[i].sval, fp); putc('"', fp); } } /* Print the element's input filename, and optionally, the line number. * Format: _infile [line] */ else if (StrEq(tok[0], "infile")) { if (e->infile) { if (ntok > 1 && !strcmp(tok[1], "root")) { strcpy(buf, e->infile); if ((cp = strrchr(buf, '.'))) *cp = EOS; fputs(buf, fp); } else { fputs(e->infile, fp); if (ntok > 1 && !strcmp(tok[1], "line")) fprintf(fp, " %d", e->lineno); } return; } else fputs("input-file??", fp); } /* Get value of an environement variable */ else if (StrEq(tok[0], "env")) { if (ntok > 1 && (cp = getenv(tok[1]))) { OutputString(cp, fp, track_pos); } } /* Something unknown */ else { fprintf(stderr, "Unknown special variable: %s\n", tok[0]); tt = e->trans; if (tt && tt->lineno) fprintf(stderr, "Used in transpec, line %d\n", tt->lineno); } return; }
// //================ //Map_ImportFile // Timo 09/01/99 : called by CXYWnd::Paste & Map_ImportFile // if Map_ImportFile ( prefab ), the buffer may contain brushes in old format ( conversion needed ) //================ // void Map_ImportBuffer (char* buf) { entity_t* ent; brush_t* b = NULL; CPtrArray ptrs; Select_Deselect(); Undo_Start("import buffer"); g_qeglobals.d_parsed_brushes = 0; if (buf) { CMapStringToString mapStr; StartTokenParsing (buf); g_qeglobals.d_num_entities = 0; // Timo // will be used in Entity_Parse to detect if a conversion between brush formats is needed g_qeglobals.bNeedConvert = false; g_qeglobals.bOldBrushes = false; g_qeglobals.bPrimitBrushes = false; while (1) { // use the selected brushes list as it's handy //ent = Entity_Parse (false, &selected_brushes); ent = Entity_Parse (false, &active_brushes); if (!ent) break; //end entity for undo Undo_EndEntity(ent); //end brushes for undo for(b = ent->brushes.onext; b && b != &ent->brushes; b = b->onext) { Undo_EndBrush(b); } if (!strcmp(ValueForKey (ent, "classname"), "worldspawn")) { // world brushes need to be added to the current world entity b=ent->brushes.onext; while (b && b != &ent->brushes) { brush_t* bNext = b->onext; Entity_UnlinkBrush(b); Entity_LinkBrush(world_entity, b); ptrs.Add(b); b = bNext; } } else { // the following bit remaps conflicting target/targetname key/value pairs CString str = ValueForKey(ent, "target"); CString strKey; CString strTarget(""); if (str.GetLength() > 0) { if (FindEntity("target", str.GetBuffer(0))) { if (!mapStr.Lookup(str, strKey)) { UniqueTargetName(strKey); mapStr.SetAt(str, strKey); } strTarget = strKey; SetKeyValue(ent, "target", strTarget.GetBuffer(0)); } } str = ValueForKey(ent, "targetname"); if (str.GetLength() > 0) { if (FindEntity("targetname", str.GetBuffer(0))) { if (!mapStr.Lookup(str, strKey)) { UniqueTargetName(strKey); mapStr.SetAt(str, strKey); } SetKeyValue(ent, "targetname", strKey.GetBuffer(0)); } } //if (strTarget.GetLength() > 0) // SetKeyValue(ent, "target", strTarget.GetBuffer(0)); // add the entity to the end of the entity list ent->next = &entities; ent->prev = entities.prev; entities.prev->next = ent; entities.prev = ent; g_qeglobals.d_num_entities++; for (b=ent->brushes.onext ; b != &ent->brushes ; b=b->onext) { ptrs.Add(b); } } } } //::ShowWindow(g_qeglobals.d_hwndEntity, FALSE); //::LockWindowUpdate(g_qeglobals.d_hwndEntity); g_bScreenUpdates = false; for (int i = 0; i < ptrs.GetSize(); i++) { Brush_Build(reinterpret_cast<brush_t*>(ptrs[i]), true, false); Select_Brush(reinterpret_cast<brush_t*>(ptrs[i]), true, false); } //::LockWindowUpdate(NULL); g_bScreenUpdates = true; ptrs.RemoveAll(); // reset the "need conversion" flag // conversion to the good format done in Map_BuildBrushData g_qeglobals.bNeedConvert=false; Sys_UpdateWindows (W_ALL); //Sys_MarkMapModified(); modified = true; Undo_End(); }
void CPointEntityFinder::InputFindEntity( inputdata_t &inputdata ) { FindEntity(); m_OnFoundEntity.FireOutput( inputdata.pActivator, m_hEntity ); }