/** * Actually build the object. * @param type The type of object to build. * @param tile The tile to build the northern tile of the object on. * @param owner The owner of the object. * @param town Town the tile is related with. * @param view The view for the object. * @pre All preconditions for building the object at that location * are met, e.g. slope and clearness of tiles are checked. */ void BuildObject(ObjectType type, TileIndex tile, CompanyID owner, Town *town, uint8 view) { const ObjectSpec *spec = ObjectSpec::Get(type); TileArea ta(tile, GB(spec->size, HasBit(view, 0) ? 4 : 0, 4), GB(spec->size, HasBit(view, 0) ? 0 : 4, 4)); Object *o = new Object(); o->type = type; o->location = ta; o->town = town == NULL ? CalcClosestTownFromTile(tile) : town; o->build_date = _date; o->view = view; /* If nothing owns the object, the colour will be random. Otherwise * get the colour from the company's livery settings. */ if (owner == OWNER_NONE) { o->colour = Random(); } else { const Livery *l = Company::Get(owner)->livery; o->colour = l->colour1 + l->colour2 * 16; } /* If the object wants only one colour, then give it that colour. */ if ((spec->flags & OBJECT_FLAG_2CC_COLOUR) == 0) o->colour &= 0xF; if (HasBit(spec->callback_mask, CBM_OBJ_COLOUR)) { uint16 res = GetObjectCallback(CBID_OBJECT_COLOUR, o->colour, 0, spec, o, tile); if (res != CALLBACK_FAILED) { if (res >= 0x100) ErrorUnknownCallbackResult(spec->grf_prop.grffile->grfid, CBID_OBJECT_COLOUR, res); o->colour = GB(res, 0, 8); } } assert(o->town != NULL); TILE_AREA_LOOP(t, ta) { WaterClass wc = (IsWaterTile(t) ? GetWaterClass(t) : WATER_CLASS_INVALID); /* Update company infrastructure counts for objects build on canals owned by nobody. */ if (wc == WATER_CLASS_CANAL && owner != OWNER_NONE && (IsTileOwner(tile, OWNER_NONE) || IsTileOwner(tile, OWNER_WATER))) { Company::Get(owner)->infrastructure.water++; DirtyCompanyInfrastructureWindows(owner); } MakeObject(t, owner, o->index, wc, Random()); MarkTileDirtyByTile(t); }
/*========================================================*/ CObjectBase* CObjectManager::AddObject( const std::string _Name , const D3DXVECTOR3 _Pos ) { std::string FileName = "Makeing"; LOAD_OBJECT_DATA Data; Data.Str[OBJECT_NAME] = _Name; Data.Str[POS_X] = std::to_string( _Pos.x ); Data.Str[POS_Y] = std::to_string( _Pos.y ); Data.Str[POS_Z] = std::to_string( _Pos.z ); Data.Str[ROT_X] = "0"; Data.Str[ROT_Y] = "0"; Data.Str[ROT_Z] = "0"; Data.Str[GIMMICK_ID] = "0"; Data.Str[GIMMICK_RECEVER] = "0"; OBJECT_DATA TmpData; TmpData.Init( Data ); CObjectBase* Tmp = MakeObject( TmpData , FileName ); m_AddObjectList.push_back( Tmp ); return Tmp; }
int Clone_Object(ITEM *i, ITEM *j) { short x=0; OBJECT *r,*s; if(MakeObject(i)==-1) return(-1); r=(OBJECT *)FindSub(i,KEY_OBJECT); s=(OBJECT *)FindSub(j,KEY_OBJECT); if((!r)||(!s)) Error("CloneObject: Not Object!"); FreeText(r->ob_Text[0]); FreeText(r->ob_Text[1]); FreeText(r->ob_Text[2]); FreeText(r->ob_Text[3]); r->ob_Flags=s->ob_Flags; r->ob_Size=s->ob_Size; r->ob_Weight=s->ob_Weight; while(x<4) { r->ob_Text[x]=AllocText(TextOf(s->ob_Text[x])); x++; } return(0); }
/*=======================================================================================*/ bool CObjectManager::LoadObject( const std::string _FilePass ) { std::vector< OBJECT_DATA > Data; // 既にオブジェクトが解放されているので再初期化する m_pPlayer = nullptr; // カウンターの初期化 m_ErrorCheckCounter = 0; std::vector< LOAD_OBJECT_DATA > DataStr; const std::string Sep( "," ); const std::string Ignore( " \t" ); DEBUG->PrintConsole( "\n===Loading Object===\n" , CDebug::ConPreside ); DEBUG->PrintConsole( "================================================================\n" , CDebug::ConFence ); // データの読み込み if( CLoadFile::LoadFile( DataStr , DATA_STRUCTURE_MAX , _FilePass , Sep , Ignore ) ) { for( auto &x : DataStr ) { OBJECT_DATA Tmp; if( Tmp.Init( x ) ) { Data.push_back( Tmp ); } else { // エラー処理 CLoadFile::FileErrorMessage( _FilePass , CLoadFile::READ_ERROR ); PostQuitMessage( 0 ); return false; } } } else { // エラー処理 PostQuitMessage( 0 ); return false; } // データを元にオブジェクトを生成する for( auto &x : Data ) { CObjectBase* Tmp = MakeObject( x , _FilePass ); if( Tmp != nullptr ) { m_ObjectList.push_back( Tmp ); } else { // エラー処理 CLoadFile::FileErrorMessage( _FilePass , CLoadFile::READ_ERROR ); PostQuitMessage( 0 ); return false; } } // MakeObject内でカウント // 部屋データを読み込んでいない、もしくは1つ以上の部屋データを読み込もうとした場合エラーを出す if( m_ErrorCheckCounter != 1 ) { // エラー処理 CLoadFile::FileErrorMessage( _FilePass , CLoadFile::READ_ERROR ); PostQuitMessage( 0 ); return false; } DEBUG->PrintConsole( "================================================================\n\n" , CDebug::ConFence ); return true; }
bool CShape::ImportSolidsFile(const wxChar* filepath, std::map<int, CShapeData> *index_map, HeeksObj* paste_into) { // only allow paste of solids at top level or to groups if(paste_into && paste_into->GetType() != GroupType)return false; // returns true, if suffix handled wxString wf(filepath); HeeksObj* add_to = &wxGetApp(); if(paste_into)add_to = paste_into; if(wf.EndsWith(_T(".stp")) || wf.EndsWith(_T(".STP")) || wf.EndsWith(_T(".step")) || wf.EndsWith(_T(".STEP"))) { char oldlocale[1000]; strcpy(oldlocale, setlocale(LC_NUMERIC, "C")); Standard_CString aFileName = (Standard_CString) (Ttc(filepath)); STEPControl_Reader Reader; int status = Reader.ReadFile( aFileName ); if ( status == IFSelect_RetDone ) { int num = Reader.NbRootsForTransfer(); for(int i = 1; i<=num; i++) { Handle_Standard_Transient root = Reader.RootForTransfer(i); Reader.TransferEntity(root); TopoDS_Shape rShape = Reader.Shape(i); if(index_map) { // change the id ( and any other data ), to the one in the step file index std::map<int, CShapeData>::iterator FindIt = index_map->find(i); if(FindIt != index_map->end()) { CShapeData& shape_data = FindIt->second; HeeksObj* new_object = MakeObject(rShape, _("STEP solid"), shape_data.m_solid_type, HeeksColor(191, 191, 191), 1.0f); if(new_object) { add_to->Add(new_object, NULL); shape_data.SetShape((CShape*)new_object); } } } else { HeeksObj* new_object = MakeObject(rShape, _("STEP solid"), SOLID_TYPE_UNKNOWN, HeeksColor(191, 191, 191), 1.0f); add_to->Add(new_object, NULL); } } } else{ wxMessageBox(_("STEP import not done!")); } setlocale(LC_NUMERIC, oldlocale); return true; } else if(wf.EndsWith(_T(".igs")) || wf.EndsWith(_T(".IGS")) || wf.EndsWith(_T(".iges")) || wf.EndsWith(_T(".IGES"))) { char oldlocale[1000]; strcpy(oldlocale, setlocale(LC_NUMERIC, "C")); Standard_CString aFileName = (Standard_CString) (Ttc(filepath)); // //#ifdef WIN32 //#ifdef UNICODE // // if the const char* filename is different to the original unicode filename, then copy the file to a temporary file with a simple name // if(stricmp(Ctt(aFileName), filepath)) // { // wxStandardPaths standard_paths; // wxFileName path( standard_paths.GetTempDir().c_str(), _("temp_iges.igs")); // copy_file; // to do // m_backup_file_name = path.GetFullPath(); //#endif //#endif IGESControl_Reader Reader; int status = Reader.ReadFile( aFileName ); if ( status == IFSelect_RetDone ) { Reader.TransferRoots(); TopoDS_Shape shape = Reader.OneShape(); HeeksObj* new_object = MakeObject(shape, _("IGES shape"), SOLID_TYPE_UNKNOWN, HeeksColor(191, 191, 191), 1.0f); add_to->Add(new_object, NULL); #if 0 Reader.TransferRoots(); int num_shapes = Reader.NbShapes(); if(num_shapes > 0) { BRepOffsetAPI_Sewing face_sewing (0.001); int shapes_added_for_sewing = 0; for(int j = 1; j<= num_shapes; j++) { TopoDS_Shape rShape = Reader.Shape(j); if(rShape.ShapeType() == TopAbs_EDGE) { HeeksObj* new_object = new CEdge(TopoDS::Edge(rShape)); add_to->Add(new_object, NULL); } else { face_sewing.Add (rShape); shapes_added_for_sewing++; } } if(shapes_added_for_sewing > 0) { face_sewing.Perform (); if(!face_sewing.SewedShape().IsNull()) { HeeksObj* new_object = MakeObject(face_sewing.SewedShape(), _("sewed IGES solid"), SOLID_TYPE_UNKNOWN, HeeksColor(191, 191, 191)); add_to->Add(new_object, NULL); } } } #endif } else{ wxMessageBox(_("IGES import not done!")); } setlocale(LC_NUMERIC, oldlocale); return true; } else if(wf.EndsWith(_T(".brep")) || wf.EndsWith(_T(".BREP"))) { char oldlocale[1000]; strcpy(oldlocale, setlocale(LC_NUMERIC, "C")); TopoDS_Shape shape; BRep_Builder builder; Standard_Boolean result = BRepTools::Read( shape,(char *) Ttc(filepath), builder ); if(result) { HeeksObj* new_object = MakeObject(shape, _("BREP solid"), SOLID_TYPE_UNKNOWN, HeeksColor(191, 191, 191), 1.0f); add_to->Add(new_object, NULL); } else{ wxMessageBox(_("STEP import not done!")); } setlocale(LC_NUMERIC, oldlocale); return true; } return false; }
// --- tERROR pr_call _PropertySetStr( tPO* po, tHANDLE* handle, tDATA* result, tPROPID propid, tSTRING buffer, tDWORD size, tCODEPAGE src_cp ) { tERROR error = errOK; tDATA len = 0; const tDATA* table; tINTERFACE* iface; tDWORD init_prop_pos = 0xffffffff; PR_TRACE_A0( MakeObject(handle), "Enter _PropertySetStr method" ); /* if ( !KNOWN_CP(receive_cp) ) error = errCODEPAGE_NOT_SUPPORTED; */ if ( 0 == (iface=handle->iface) ) error = errINTERFACE_NOT_ASSIGNED_YET; else if ( (0 == (table = _PropTableSearch(iface,propid,&init_prop_pos))) && (0==(table=_PropTableSearch(iface,pgPROP_LAST_CALL,&init_prop_pos))) ) error = errPROPERTY_NOT_FOUND; /* else if ( !KNOWN_CP(src_cp) ) error = errCODEPAGE_NOT_SUPPORTED; */ else if ( PROP_MODE(table) & cPROP_BUFFER_SHARED ) // shared buffer is RO !!! error = errPROPERTY_NOT_WRITABLE; else if ( ((PROP_MODE(table) & cPROP_WRITABLE_ON_INIT) != 0) && ((handle->flags & hf_OPERATIONAL_MODE) != 0) ) // property cannot be set in this operational mode error = errPROPERTY_NOT_WRITABLE; else if ( (cPROP_BUFFER_WRITE|cPROP_BUFFER_HSTRING) == (PROP_MODE(table) & (cPROP_BUFFER_WRITE|cPROP_BUFFER_HSTRING)) ) { hSTRING* pstr = (hSTRING*)(((tBYTE*)*hdata(handle))+PROP_OFFSET(table)); if ( !*pstr ) { tHANDLE* hstr; rlock(po); if ( PR_SUCC(error=_ObjectIIDCreate(po,g_hRoot,&hstr,IID_STRING,PID_ANY,SUBTYPE_ANY)) ) { if ( PR_SUCC(error=_ObjectCreateDone(po,hstr)) ) *pstr = (hSTRING)MakeObject( hstr ); else _ObjectClose( po, hstr, 0 ); } runlock(po); } if ( PR_SUCC(error) ) { tDWORD dwLen = 0; error = CALL_String_ImportFromBuff( *pstr, &dwLen, buffer, size, src_cp, cSTRING_Z ); len = dwLen; } if ( PR_SUCC(error) && buffer && (init_prop_pos < 32) ) handle->init_props &= ~( 1 << init_prop_pos ); } else { tIntFnPropIO func; tPTR dst; tDATA dst_len = 0; tCODEPAGE dst_cp; if ( PR_FAIL(error=_PropertyGetStrCP(po,handle,&dst_cp,propid)) ) dst_cp = src_cp; // cannot get destination CP, just put string witout conversion !!! if ( 0 != (func=PROP_SETFN(table)) ) dst = 0; else if ( PROP_MODE(table) & cPROP_BUFFER_WRITE ) { dst = ((tBYTE*)*hdata(handle))+PROP_OFFSET(table); dst_len = PROP_SIZE(table); } else dst = 0; if ( !func && !dst ) error = errPROPERTY_NOT_WRITABLE; else if ( buffer ) { if ( src_cp != dst_cp ) { if ( func ) { if ( !CalcExportLen || !CopyTo ) error = errCODEPAGE_CONVERSION_UNAVAILABLE; else { tPTR tmp = 0; tDWORD tmp_len = size; call_func6( error, 0/*DPO*/, CalcExportLen, buffer, size, src_cp, dst_cp, cSTRING_Z, &tmp_len ); if ( PR_FAIL(error) ) ; else if ( PR_FAIL(error=PrAlloc(&tmp,tmp_len)) ) ; else { call_func8( error, 0/*DPO*/, CopyTo, tmp, tmp_len, dst_cp, buffer, size, src_cp, cSTRING_Z, &tmp_len ); if ( PR_SUCC(error) ) { tDWORD dwLen = 0; call_func5( error, DPO, func, MakeObject(handle), &dwLen, propid, tmp, tmp_len ); len = dwLen; } } if ( tmp ) PrFree( tmp ); } } else if ( CopyTo ) { tDWORD dwLen = 0; call_func8( error, 0/*DPO*/, CopyTo, dst, (tDWORD)dst_len, dst_cp, buffer, size, src_cp, cSTRING_Z, &dwLen ); len = dwLen; } else error = errCODEPAGE_CONVERSION_UNAVAILABLE; } else if ( !size && ((error=errSTRING_LEN_NOT_SPECIFIED,!CalcExportLen) || PR_FAIL(error=CalcExportLen(buffer,0,src_cp,src_cp,cSTRING_Z,&size))) ) ; else if ( func ) { tDWORD dwLen = 0; call_func5( error, DPO, func, MakeObject(handle), &dwLen, propid, buffer, size ); len = dwLen; } else if ( dst_len < size ) { len = 0; error = errBUFFER_TOO_SMALL; } else { memcpy( dst, buffer, (tDWORD)(len=size) ); error = errOK; } if ( PR_SUCC(error) && (init_prop_pos < 32) ) handle->init_props &= ~( 1 << init_prop_pos ); } else if ( func ) { tDWORD dwLen = (tDWORD)len; call_func5( error, DPO, func, MakeObject(handle), &dwLen, propid, 0, 0 ); if ( PR_SUCC(error) && (src_cp != dst_cp) && dwLen ) { if ( ConvertLen ) { call_func4( error, 0/*DPO*/, ConvertLen, dwLen, &dwLen, dst_cp, src_cp ); } else error = errCODEPAGE_CONVERSION_UNAVAILABLE; } len = dwLen; } else if ( src_cp == dst_cp ) len = dst_len; else if ( ConvertLen ) { tDWORD dwLen = 0; call_func4( error, 0/*DPO*/, ConvertLen, (tDWORD)dst_len, &dwLen, dst_cp, src_cp ); len = dwLen; } else error = errCODEPAGE_CONVERSION_UNAVAILABLE; } if ( result ) *result = len; PR_TRACE_A2( MakeObject(handle), "Leave _PropertySetStr method, ret tDWORD = %u, error = %terr", (tDWORD)len, error ); return error; }
// --- tERROR pr_call _PropertyGetStr( tPO* po, tHANDLE* handle, tDATA* result, tPROPID propid, tSTRING buffer, tDWORD size, tCODEPAGE receive_cp ) { tERROR error = errUNEXPECTED; tDATA len = 0; const tDATA* table; tINTERFACE* iface; tCODEPAGE src_cp; PR_TRACE_A0( MakeObject(handle), "Enter _PropertyGetStr method" ); /* if ( !KNOWN_CP(receive_cp) ) error = errCODEPAGE_NOT_SUPPORTED; */ if ( 0 == (iface=handle->iface) ) error = errINTERFACE_NOT_ASSIGNED_YET; else if ( propid == pgPLUGIN_NAME ) { if ( iface->plugin ) { tHANDLE* plugin; tINT lock = 1; if ( _HCP(plugin,po,lock,iface->plugin,&error) ) { error = _PropertyGetStr( po, plugin, &len, pgMODULE_NAME, buffer, size, receive_cp ); runlockc(po,lock); } } else error = errMODULE_NOT_FOUND; } else if ( (0 == (table=_PropTableSearch(iface,propid,0))) && (0==(table=_PropTableSearch(iface,pgPROP_LAST_CALL,0))) ) error = errPROPERTY_NOT_FOUND; else if ( (cPROP_BUFFER_READ|cPROP_BUFFER_HSTRING) == (PROP_MODE(table) & (cPROP_BUFFER_READ|cPROP_BUFFER_HSTRING)) ) { hSTRING hstr = *(hSTRING*)(((tBYTE*)*hdata(handle))+PROP_OFFSET(table)); if ( hstr ) { tDWORD l; error = CALL_String_ExportToBuff( hstr, &l, cSTRING_WHOLE, buffer, size, receive_cp, cSTRING_Z ); len = l; } else error = errOBJECT_NOT_FOUND; } else { tIntFnPropIO func; tPTR src = 0; tDATA src_len = 0; if ( PR_FAIL(error=_PropertyGetStrCP(po,handle,&src_cp,propid)) ) src_cp = receive_cp; // cannot get source CP, just get string witout conversion !!! if ( PROP_MODE(table) & cPROP_BUFFER_SHARED ) { func = 0; if ( PROP_MODE(table) & (cPROP_BUFFER_SHARED_PTR & ~cPROP_BUFFER_SHARED) ) src = PROP_BUFFER(table); else if ( PROP_MODE(table) & (cPROP_BUFFER_SHARED_VAR & ~cPROP_BUFFER_SHARED) ) src = (tSTRING)(*(tPTR*)PROP_BUFFER(table)); else src = &((tDATA*)table)[1]; // &PROP_BUFFER(table) !!! Palm OS doesn't accept it } else if ( 0 != (func=PROP_GETFN(table)) ) src = 0; else if ( (PROP_MODE(table) & cPROP_BUFFER_READ) ) { func = 0; src = ((tBYTE*)*hdata(handle))+PROP_OFFSET(table); } if ( src ) src_len = PROP_SIZE(table); if ( !func && !src ) error = errPROPERTY_NOT_READABLE; else if ( buffer ) { len = src_len; if ( src_cp != receive_cp ) { if ( func ) { if ( !CopyTo || !CalcExportLen ) error = errCODEPAGE_CONVERSION_UNAVAILABLE; else { tPTR buff = 0; tDWORD dwLen = 0; call_func5( error, DPO, func, MakeObject(handle), &dwLen, propid, 0, 0 ); if ( PR_FAIL(error) ) ; else if ( PR_FAIL(error=PrAlloc(&buff,dwLen)) ) ; else { call_func5( error, DPO, func, MakeObject(handle), &dwLen, propid, buff, dwLen ); if ( PR_SUCC(error) ) { //tDWORD ex_len = 0; //call_func6( error, 0/*DPO*/, CalcExportLen, buff, dwLen, src_cp, receive_cp, cSTRING_Z, &ex_len ); //if ( PR_FAIL(error) ) // ; //else if ( size < ex_len ) // dwLen = 0, error = errBUFFER_TOO_SMALL; //else call_func8( error, 0/*DPO*/, CopyTo, buffer, size, receive_cp, buff, dwLen, src_cp, cSTRING_Z, &dwLen ); } } if ( buff ) PrFree( buff ); len = dwLen; } } else if ( !CalcExportLen || !CalcImportLen ) len = 0, error = errCODEPAGE_CONVERSION_UNAVAILABLE; else { tDWORD dwLen = 0; tDWORD dwSrcLen = (tDWORD)src_len; call_func5( error, 0/*DPO*/, CalcImportLen, src, src_cp, cSTRING_Z, dwSrcLen, &dwSrcLen ); if ( PR_FAIL(error) ) dwLen = 0; else { call_func6( error, 0/*DPO*/, CalcExportLen, src, dwSrcLen, src_cp, receive_cp, cSTRING_Z, &dwLen ); if ( PR_FAIL(error) ) dwLen = 0; else if ( size < dwLen ) dwLen = 0, error = errBUFFER_TOO_SMALL; else call_func8( error, 0/*DPO*/, CopyTo, buffer, size, receive_cp, src, dwSrcLen, src_cp, cSTRING_Z, &dwLen ); } len = dwLen; } } else if ( func ) { tDWORD dwLen = 0; call_func5( error, DPO, func, MakeObject(handle), &dwLen, propid, buffer, size ); len = dwLen; } else if ( !CalcExportLen ) len = 0, error = errCODEPAGE_CONVERSION_UNAVAILABLE; else { tDWORD dwLen = 0; call_func6( error, 0/*DPO*/, CalcExportLen, src, (tDWORD)src_len, src_cp, receive_cp, cSTRING_Z, &dwLen ); if ( PR_FAIL(error) ) dwLen = 0; else if ( size < dwLen ) dwLen = 0, error = errBUFFER_TOO_SMALL; else if ( CopyTo ) { call_func8( error, 0/*DPO*/, CopyTo, buffer, size, receive_cp, src, dwLen, src_cp, cSTRING_Z, &dwLen ); } else { dwLen = (tDWORD)src_len; memcpy( buffer, src, src_len ); } len = dwLen; } } else if ( func ) { tDWORD dwLen = 0; call_func5( error, DPO, func, MakeObject(handle), &dwLen, propid, 0, 0 ); if ( PR_SUCC(error) && (src_cp != receive_cp) && dwLen && ConvertLen ) call_func4( error, 0/*DPO*/, ConvertLen, dwLen, &dwLen, src_cp, receive_cp ); len = dwLen; } else if ( !CalcExportLen ) len = src_len; else { tDWORD dwLen = 0; call_func6( error, 0/*DPO*/, CalcExportLen, src, (tDWORD)src_len, src_cp, receive_cp, cSTRING_Z, &dwLen ); if ( PR_SUCC(error) ) len = dwLen; else len = src_len; } } if ( result ) *result = len; PR_TRACE_A2( MakeObject(handle), "Leave _PropertyGetStr method, ret tDWORD = %u, error = %terr", len, error ); return error; }