BOOL load_configfile(LPCTSTR pszFileName) { HANDLE hFile; int t, act_samplingrate=DEF_PACKETSPERSECOND; int act_type,num_objects, save_toolbox, save_connected, try_connect; const char * d_name; char new_name[256],szdata[20]; write_logfile("loading design configuration: %s",(char *)pszFileName); hFile = CreateFile(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if(hFile != INVALID_HANDLE_VALUE) { GLOBAL.loading=1; d_name=pszFileName; while (strstr(d_name,"\\")) d_name=strstr(d_name,"\\")+1; strcpy(new_name,"BrainBay - ");strcat(new_name,d_name); SetWindowText(ghWndMain,new_name); strcpy(GLOBAL.configfile,pszFileName); save_settings(); save_toolbox=-1; save_connected=TTY.CONNECTED; SendMessage(ghWndStatusbox,WM_COMMAND, IDC_STOPSESSION,0); //TTY.read_pause=1; close_captfile(); if (ghWndAnimation!=NULL) SendMessage(ghWndAnimation,WM_CLOSE,0,0); ghWndAnimation=NULL; close_toolbox();actobject=NULL; //InvalidateRect(ghWndMain, NULL, TRUE); while (GLOBAL.objects>0) free_object(0); GLOBAL.run_exception=0; GLOBAL.minimized=FALSE; load_next_config_buffer(hFile); load_property("objects",P_INT,&GLOBAL.objects); load_property("main-top",P_INT,&GLOBAL.top); load_property("main-left",P_INT,&GLOBAL.left); load_property("main-right",P_INT,&GLOBAL.right); load_property("main-bottom",P_INT,&GLOBAL.bottom); load_property("anim-top",P_INT,&GLOBAL.anim_top); load_property("anim-left",P_INT,&GLOBAL.anim_left); load_property("anim-right",P_INT,&GLOBAL.anim_right); load_property("anim-bottom",P_INT,&GLOBAL.anim_bottom); load_property("design-top",P_INT,&GLOBAL.design_top); load_property("design-left",P_INT,&GLOBAL.design_left); load_property("design-right",P_INT,&GLOBAL.design_right); load_property("design-bottom",P_INT,&GLOBAL.design_bottom); load_property("tool-top",P_INT,&GLOBAL.tool_top); load_property("tool-left",P_INT,&GLOBAL.tool_left); load_property("tool-right",P_INT,&GLOBAL.tool_right); load_property("tool-bottom",P_INT,&GLOBAL.tool_bottom); load_property("showdesign",P_INT,&GLOBAL.showdesign); load_property("hidestatus",P_INT,&GLOBAL.hidestatus); load_property("showtoolbox",P_INT,&GLOBAL.showtoolbox); load_property("autorun",P_INT,&GLOBAL.autorun); load_property("minimized",P_INT,&GLOBAL.minimized); save_toolbox=GLOBAL.showtoolbox; TTY.PORT=0;try_connect=0; load_property("comport",P_INT,&TTY.PORT); load_property("connected",P_INT,&try_connect); load_property("bidirect",P_INT,&TTY.BIDIRECT); load_property("devicetype",P_INT,&TTY.devicetype); load_property("samplingtype",P_INT,&TTY.samplingrate); load_property("baudtype",P_INT,&TTY.BAUDRATE); load_property("flow_control",P_INT,&TTY.FLOW_CONTROL); if (save_connected) { update_p21state(); save_connected=TTY.CONNECTED; } BreakDownCommPort(); if (try_connect) { TTY.CONNECTED=SetupCommPort(TTY.PORT); update_p21state(); } load_property("captfilename",P_STRING,CAPTFILE.filename); load_property("captfiletype",P_INT,&CAPTFILE.filetype); load_property("captfileoffset",P_INT,&CAPTFILE.offset); load_property("dialoginterval",P_INT,&GLOBAL.dialog_interval); load_property("drawinterval",P_INT,&GLOBAL.draw_interval); load_property("samplingrate",P_INT,&act_samplingrate); PACKETSPERSECOND=act_samplingrate; MoveWindow(ghWndMain,GLOBAL.left,GLOBAL.top,GLOBAL.right-GLOBAL.left,GLOBAL.bottom-GLOBAL.top,TRUE); MoveWindow(ghWndDesign,GLOBAL.design_left,GLOBAL.design_top,GLOBAL.design_right-GLOBAL.design_left,GLOBAL.design_bottom-GLOBAL.design_top,TRUE); if (!GLOBAL.showdesign) { ShowWindow(ghWndDesign, FALSE); SetDlgItemText(ghWndStatusbox,IDC_DESIGN,"Show Design"); } else { ShowWindow(ghWndDesign,TRUE); SetWindowPos(ghWndDesign,0,0,0,0,0,SWP_DRAWFRAME|SWP_NOMOVE|SWP_NOSIZE); SetDlgItemText(ghWndStatusbox,IDC_DESIGN,"Hide Design"); } if (!GLOBAL.hidestatus) ShowWindow(ghWndStatusbox, TRUE); else ShowWindow(ghWndStatusbox,FALSE); num_objects=GLOBAL.objects; GLOBAL.objects=0; for (t=0;t<num_objects;t++) { act_type=load_next_config_buffer(hFile); if (act_type>=0) { create_object(act_type); if (actobject != NULL ) { actobject->load(hFile); link_object(actobject); } else critical_error("Could not load all objects, quitting ...\ndelete brainbay.cfg to prevent this at program startup ... "); } } CloseHandle(hFile); for (t=0;t<num_objects;t++) objects[t]->update_inports(); update_dimensions(); CAPTFILE.filehandle=INVALID_HANDLE_VALUE; CAPTFILE.do_read=0; if (strcmp(CAPTFILE.filename,"none")) { char st[150]; reduce_filepath(st,CAPTFILE.filename); strcpy(CAPTFILE.filename,GLOBAL.resourcepath); strcat(CAPTFILE.filename,"ARCHIVES\\"); strcat(CAPTFILE.filename,st); open_captfile(CAPTFILE.filename); } init_system_time(); reset_oscilloscopes(); PACKET.readstate=0; ShowWindow( ghWndMain, TRUE ); UpdateWindow( ghWndMain ); update_samplingrate(act_samplingrate); update_devicetype(); get_session_length(); SetDlgItemInt(ghWndStatusbox,IDC_SAMPLINGRATE,act_samplingrate,0); SetDlgItemText(ghWndStatusbox,IDC_STATUS,"Configuration loaded"); SetDlgItemText(ghWndStatusbox,IDC_TIME,"0.0"); SetDlgItemText(ghWndStatusbox,IDC_JUMPPOS,"0.0"); sprintf(szdata, "%.1f", (float)GLOBAL.session_length/(float)PACKETSPERSECOND); SetDlgItemText(ghWndStatusbox,IDC_SESSLEN,szdata); SendMessage(GetDlgItem(ghWndStatusbox,IDC_SESSIONPOS),TBM_SETPOS,TRUE,(LONG)0); SendMessage(GetDlgItem(ghWndStatusbox,IDC_SESSIONPOS),TBM_SETSELEND,TRUE,(LONG)0); SendMessage(GetDlgItem(ghWndStatusbox,IDC_SESSIONPOS),TBM_SETSELSTART,TRUE,(LONG)0); SetWindowPos(ghWndMain,0,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE); InvalidateRect(ghWndMain,NULL,TRUE); InvalidateRect(ghWndDesign,NULL,TRUE); SendMessage(GetDlgItem(ghWndStatusbox,IDC_SESSIONPOS),TBM_SETSELSTART,TRUE,0); SendMessage(GetDlgItem(ghWndStatusbox,IDC_SESSIONPOS),TBM_SETSELEND,TRUE,1000); SendMessage(GetDlgItem(ghWndStatusbox,IDC_SESSIONPOS),TBM_SETPOS,TRUE,(LONG)(0)); if (GLOBAL.minimized) ShowWindow(ghWndMain, SW_MINIMIZE); GLOBAL.loading=0; if ((GLOBAL.autorun) && (!GLOBAL.run_exception)) SendMessage(ghWndStatusbox,WM_COMMAND, IDC_RUNSESSION,0); if (save_toolbox!=-1) { GLOBAL.showtoolbox=save_toolbox; actobject=objects[GLOBAL.showtoolbox]; actobject->make_dialog(); } write_logfile("load successful"); return TRUE; } write_logfile("could not load design configuration file."); return FALSE; }
void create_portal(int type, CHAR_DATA *ch, int x1, int y1, int p1, int x2, int y2, int p2) { OBJECT_DATA *obj, *obj2; char buf[MAX_STRING_LENGTH]; obj = new_object(); obj2 = new_object(); link_object(obj); link_object(obj2); buf[0] = 0; if (type == 0) { strlcpy(obj->keywords, "red portal", 128); strlcpy(obj->shortdesc, "a #Rred#n portal", 128); strlcpy(obj->longdesc, "A #Rred#n portal spins", 128); strlcpy(buf, "A #Rred#n portal opens up.\n", MAX_STRING_LENGTH); setup_event_obj(obj, NULL, event_cportal, "", TICKS_PER_SECOND * 30, EVENT_CPORTAL); setup_event_obj(obj2, NULL, event_cportal, "", TICKS_PER_SECOND * 30, EVENT_CPORTAL); if (ch) { strlcpy(obj->owner, ch->name, 32); strlcpy(obj2->owner, ch->name, 32); } } else if (type == 1) { strlcpy(obj->keywords, "blue portal", 128); strlcpy(obj->shortdesc, "a #Cblue#n portal", 128); strlcpy(obj->longdesc, "A #Cblue#n portal ominously spins", 128); } else { strlcpy(obj->keywords, "green portal", 128); strlcpy(obj->shortdesc, "a #Ggreen#n portal", 128); strlcpy(obj->longdesc, "A #Ggreen#n portal ominously spins", 128); } strlcpy(obj2->keywords, obj->keywords, 128); strlcpy(obj2->shortdesc, obj->shortdesc, 128); strlcpy(obj2->longdesc, obj->longdesc, 128); obj->x = x1; obj->y = y1; obj->plane = p1; obj2->v1 = x1; obj2->v2 = y1; obj2->v3 = p1; SET_BIT(obj->oflags, OFLAG_NOTAKE); obj->type = OTYPE_PORTAL; obj2->x = x2; obj2->y = y2; obj2->plane = p2; obj->v1 = x2; obj->v2 = y2; obj->v3 = p2; SET_BIT(obj2->oflags, OFLAG_NOTAKE); obj2->type = OTYPE_PORTAL; if (!buf[0]) return; put_sense_area(x1, y1, p1, SENSE_SIGHT, buf); put_sense_area(x2, y2, p2, SENSE_SIGHT, buf); }