/* Get the entities out of a block and add them to the appropriate * lists: if a block, back to blockList - if an entity onto the * the entity list according to samplemode. */ static int SampleBlock(DLL_LIST blist) { ADSResBuf *ri, *rb1, *rb2, *edata; char layer[64], type[16]; ads_name ename; ads_namep blent; DLL_LIST newList = NULL; #ifdef DEBUG fprintf(stderr, "SampleBlock(%p)\n", blist); #endif blent = DllFirst(blist, NULL); rb1 = ads_entget(blent); rb2 = ads_tblsearch("BLOCK", RBSearch(rb1, 2)->resval.rstring, 1); ads_relrb(rb1); ads_name_set(RBSearch(rb2, -2)->resval.rlname, ename); ads_relrb(rb2); do { edata = ads_entget(ename); ri = RBSearch(edata, 0); if (strcmp(ri->resval.rstring, "INSERT") == 0) { if (!(newList = DllCopyList(blist, entListsSetup, CopyNameProc, NULL, NULL))) return 0; (void)DllPushF(newList, NewADSName(ename), NULL); AddToBlockList(newList); ads_relrb(edata); continue; } if (strcmp(ri->resval.rstring, "ENDBLK") == 0) { ads_relrb(edata); break; } if (!IsValidEntType(GetEntType(edata, type))) { ads_relrb(edata); continue; } if (!(newList = DllCopyList(blist, entListsSetup, CopyNameProc, NULL, NULL))) return 0; if (!DllPushF(newList, NewADSName(ename), NULL)) return 0; switch (options.exportMode) { case EXP_BYCOLOR: AddEntToColorLists(newList, GetColorVal(edata, newList, 0)); break; case EXP_BYLAYER: GetLayerVal(layer, edata, newList, 0); AddEntToLayerLists(newList, layer); break; default: ads_fail("SampleBlock: bad export mode\n"); } ads_relrb(edata); if (ads_usrbrk()) return 0; } while (ads_entnext(ename, ename) == RTNORM); return 1; }
/* Extract entities out of a selection set and add them to the * appropriate list. */ int SampleEnts(ads_name selset, ExportMode expMode) { char layer[64], type[16]; long int num, numtot; ads_name ename; ADSResBuf *edata; DLL_LIST list; if (ads_sslength(selset, &numtot) != RTNORM) return 0; for (num = 0; num < numtot; num++) { if (num % 20 == 0) ads_printf("Sampling entities: %ld/%ld\r", num, numtot); if (ads_ssname(selset, num, ename) != RTNORM) return 0; if ((edata = ads_entget(ename)) == NULL) { WarnMsg("SampleEnts: can't get ent: %lx", ename); return 0; } if (strcmp(RBSearch(edata, 0)->resval.rstring, "INSERT") == 0) { if ((list = DllNewList(entListsSetup)) == NULL) { WarnMsg("SampleEnts: can't make block entity list"); return 0; } (void)DllPushF(list, NewADSName(ename), NULL); AddToBlockList(list); ads_relrb(edata); continue; } if (!IsValidEntType(GetEntType(edata, type))) { ads_relrb(edata); continue; } if ((list = DllNewList(entListsSetup)) == NULL) { WarnMsg("SampleEnts: can't make entity list"); ads_relrb(edata); return 0; } (void)DllPushF(list, NewADSName(ename), NULL); switch (expMode) { case EXP_BYCOLOR: if (!AddEntToColorLists(list, GetColorVal(edata, NULL, 0))) return 0; break; case EXP_BYLAYER: if (!GetLayerVal(layer, edata, list, 0)) return 0; if (!AddEntToLayerLists(list, layer)) return 0; break; default: ads_fail("SampleEnts: unknown export mode."); } ads_relrb(edata); } ads_printf("Sampling entities: %ld/%ld\n", num, numtot); return RTNORM; }
void GetEntXForm(ADSResBuf *edata, Matrix4 mx) { double xscl = 1.0, yscl = 1.0, zscl = 1.0, rotang = 0.0; Vector3 zaxis, *zaxis_p = NULL; Point3 inpt, *inpt_p = NULL; Point3 bpt, *bpt_p = NULL; ADSResBuf *bdata, *rb; int isinsert = 0; rb = RBGetPoint3(&zaxis, edata, 210); if(rb != NULL && V3Normalize(&zaxis) != 0.0) zaxis_p = &zaxis; if (strcmp(RBSearch(edata, 0)->resval.rstring, "INSERT") == 0) { isinsert = 1; if(RBGetPoint3(&inpt, edata, 10) != NULL) inpt_p = &inpt; (void)RBGetDouble(&rotang, edata, 50); (void)RBGetDouble(&xscl, edata, 41); (void)RBGetDouble(&yscl, edata, 42); (void)RBGetDouble(&zscl, edata, 43); /* the block base point */ bdata = ads_tblsearch("BLOCK", RBSearch(edata, 2)->resval.rstring, 1); if(bdata) { rb = RBGetPoint3(&bpt, bdata, 10); if (rb != NULL) bpt_p = &bpt; ads_relrb(bdata); } } M4GetAcadXForm(mx, zaxis_p, isinsert, inpt_p, rotang, xscl, yscl, zscl, bpt_p); #ifdef DEBUG fprintf(stderr, "GetEntXForm: bpt: %f %f %f\n", bpt.x, bpt.y, bpt.z); M4Print(stderr, mx); fprintf(stderr, "GetEntXForm: inpt: %f %f %f\n", inpt.x, inpt.y, inpt.z); fprintf(stderr, "GetEntXForm: pt: %f %f %f\n", pt.x, pt.y, pt.z); #endif }
void MissionInsert(struct MissionEngine* _Engine, struct Mission* _Mission) { if(RBSearch(&_Engine->MissionId, _Mission) != NULL) { Log(ELOG_WARNING, "Mission cannot be loaded id %f is already in use.", _Mission->Id); return; } RBInsert(&_Engine->MissionId, _Mission); if((_Mission->Flags & MISSION_FEVENT) != 0) { LnkLstPushBack(&_Engine->EventMissions[_Mission->TriggerEvent], _Mission); } if((_Mission->Flags & MISSION_FONLYTRIGGER) == 0) { LnkLstPushBack(&_Engine->MissionsTrigger, _Mission); } }
/* Get our own subtypes for the polyline type */ char *GetEntType(ADSResBuf *rb, char *type) { int flag; ADSResBuf *ri; double thick = 0.0, width = 0.0; ri = RBSearch(rb, 0); if ( (strcmp(ri->resval.rstring, "LINE") == 0) || (strcmp(ri->resval.rstring, "ARC") == 0) ) { /* another fix: Lines and arcs without thickness will be left out. This should avoid most empty output files now. What we don't catch will be layers or colors with only degenerate entities on them like 3dfaces with zero area. If users create such stuff, let them live with the empty files ... */ (void)RBGetDouble(&thick, rb, 39); if(thick != 0.0) strcpy(type, ri->resval.rstring); else strcpy(type, ""); } else if (strcmp(ri->resval.rstring, "POLYLINE") == 0) { if ((RBGetInt(&flag, rb, 70)) == NULL) { ads_printf("GetEntType: search for flag failed.\n"); return NULL; } if (flag & 64) strcpy(type, "PFACE"); else if (flag & 16) strcpy(type, "PMESH"); else if (flag & 8) strcpy(type, "3DPOLY"); else if ((ri = RBSearch(rb, 40)) && (ri->resval.rreal > 0.0)) strcpy(type, "WPLINE"); else if ((flag & 1) && ((flag & 8) == 0)) { /* if we don't sample polygons and it has thickness, pass it as pline, else as "". We duplicate IsValidEntType()s job here, but we just hope that WriteEntity() will never see the result... This operation will help us to avoid empty output files. */ if (IsValidEntType("POLYGON")) strcpy(type, "POLYGON"); else { (void)RBGetDouble(&thick, rb, 39); if(thick != 0.0) strcpy(type, "PLINE"); else strcpy(type, ""); } } else strcpy(type, "PLINE"); } /* lwpolyline is similar, but simpler (as the name suggests) */ else if (strcmp(ri->resval.rstring, "LWPOLYLINE") == 0) { /* width is either overall width or just the first opening width we find */ if ((ri = RBSearch(rb, 43)) != NULL) { width = ri->resval.rreal; } else if ((ri = RBSearch(rb, 40)) != NULL) { width = ri->resval.rreal; } else width = 0.0; if ((RBGetInt(&flag, rb, 70)) == NULL) { ads_printf("GetEntType: search for flag failed.\n"); return NULL; } else if (width > 0) strcpy(type, "WPLINE"); else if (flag & 1) { if (IsValidEntType("POLYGON")) strcpy(type, "POLYGON"); else { (void)RBGetDouble(&thick, rb, 39); if(thick != 0.0) strcpy(type, "PLINE"); else strcpy(type, ""); } } else strcpy(type, "PLINE"); } else { strcpy(type, ri->resval.rstring); } return type; }
void MissionAction(const char* _Name, struct BigGuy* _From, struct BigGuy* _Target) { int _MissionId = MissionStrToId(_Name); lua_settop(g_LuaState, 0); CoResume(CoSpawn(MissionCall, 4, g_LuaState, RBSearch(&g_MissionEngine.MissionId, &_MissionId)/*_Mission*/, _From, _Target)); }
static int ActionPrecondition(const struct Agent* _Agent) { struct BigGuyActionHist _Search = {_Agent->Agent, BGACT_DUEL, 0}; return (RBSearch(&g_GameWorld.ActionHistory, &_Search) == NULL) ? (1) : (0); }