static void CAL_SetupAudioFile() { int handle; long length; char fname[13]; int i; strcpy(fname, aheadname); strcat(fname, extension); handle = OpenRead(fname); if (handle == -1) CA_CannotOpen(fname); length = ReadLength(handle); MM_GetPtr((memptr)&audiostarts, length); for (i = 0; i < (length/4); i++) audiostarts[i] = ReadInt32(handle); CloseRead(handle); /* open the data file */ strcpy(fname, afilename); strcat(fname, extension); audiohandle = OpenRead(fname); if (audiohandle == -1) CA_CannotOpen(fname); }
boolean CA_LoadFile(const char *filename, memptr *ptr) { int handle; ssize_t l; long size; if ((handle = OpenRead(filename)) == -1) return false; size = ReadLength(handle); MM_GetPtr(ptr, size); l = ReadBytes(handle, (byte *)(*ptr), size); if (l == -1) { perror("CA_FarRead"); return false; } else if (l == 0) { fprintf(stderr, "CA_FarRead hit EOF?\n"); return false; } else if (l != size) { fprintf(stderr, "CA_FarRead only read %d out of %ld\n", l, size); return false; } CloseRead(handle); return true; }
bool Pickle::ReadWString(void** iter, std::wstring* result) const { DCHECK(iter); int len; if(!ReadLength(iter, &len)) { return false; } // 避免整数溢出. if(len > INT_MAX/static_cast<int>(sizeof(wchar_t))) { return false; } if(!IteratorHasRoomFor(*iter, len*sizeof(wchar_t))) { return false; } wchar_t* chars = reinterpret_cast<wchar_t*>(*iter); result->assign(chars, len); UpdateIter(iter, len*sizeof(wchar_t)); return true; }
float Extra(int i, int j) const { assert(0 <= j && j <= TemplateLength() && 0 <= i && i < ReadLength() ); float trans = pStay(j); float em = stayDist(features_.Channel[i], j); return log(trans * em); }
float Del(int i, int j) const { assert(0 <= j && j < TemplateLength() && 0 <= i && i <= ReadLength() ); if ( (!PinStart() && i == 0) || (!PinEnd() && i == ReadLength()) ) { return 0.0f; } else { float ps = pStay(j); float pm = (1.0f - ps) * pMerge(j); float trans = 1.0f - ps - pm; float em = moveDist(0, j); return log(trans * em); } }
bool PrivateKeyInfoCodec::ReadTypeHeaderAndLength(uint8** pos, uint8* end, uint8 expected_tag, uint32* length) { if(!(*pos < end)) return false; if(!(**pos == expected_tag)) return false; (*pos)++; return ReadLength(pos, end, length); }
float Inc(int i, int j) const { assert(0 <= j && j < TemplateLength() && 0 <= i && i < ReadLength() ); float ps = pStay(j); float pm = (1.0f - ps) * pMerge(j); float trans = 1.0f - ps - pm; float em = moveDist(features_.Channel[i], j); return log(trans * em); }
//--------------------------------------------------------------------------- // Очистить приемный буфер // Возвращает - сколько пакетов укучено int TUDP::Flush(void) { DWORD l; int count = 0; FlushSize = 0; while( (l = ReadLength()) > 0 ) { BYTE * p = new BYTE[l]; Read(p, l); delete [] p; count++; FlushSize += l; } return count; }
bool Pickle::ReadData(void** iter, const char** data, int* length) const { DCHECK(iter); DCHECK(data); DCHECK(length); *length = 0; *data = 0; if(!ReadLength(iter, length)) { return false; } return ReadBytes(iter, data, *length); }
int GetHeaders(int sock, char *addr, char *file) { char out[8192] = { 0 }; char buf[8192] = { 0 }; sprintf(out, "GET %s HTTP/1.1\r\nHost: %s\r\n\r\n", file, addr); write(sock, out, strlen(out)); ssize_t len = 0; do { len = ReadLength(sock); } while (!len); return len; }
float Merge(int i, int j) const { assert(0 <= j && j < TemplateLength() - 1 && 0 <= i && i < ReadLength() ); if (!(features_.Channel[i] == channelTpl_[j] && features_.Channel[i] == channelTpl_[j + 1]) ) { return -FLT_MAX; } else { float ps = pStay(j); float pm = (1.0f - ps) * pMerge(j); return log(pm); } }
bool Pickle::ReadString16(void** iter, string16* result) const { DCHECK(iter); int len; if(!ReadLength(iter, &len)) { return false; } if(!IteratorHasRoomFor(*iter, len*sizeof(char16))) { return false; } char16* chars = reinterpret_cast<char16*>(*iter); result->assign(chars, len); UpdateIter(iter, len*sizeof(char16)); return true; }
int ezStringUtils::vsnprintf(char* szOutputBuffer, unsigned int uiBufferSize, const char* szFormat, va_list args0) { va_list args; va_copy(args, args0); EZ_ASSERT(ezUnicodeUtils::IsValidUtf8(szFormat), "The sprintf format string must be valid Utf8."); // make sure the last character is a \0 if ((szOutputBuffer) && (uiBufferSize > 0)) szOutputBuffer[uiBufferSize - 1] = '\0'; unsigned int uiReadPos = 0; unsigned int uiWritePos = 0; bool bError = false; while (szFormat[uiReadPos] != '\0') { const char c = szFormat[uiReadPos]; ++uiReadPos; // if c is not %, just print it out and be done with it if (c != '%') { OutputChar (szOutputBuffer, uiBufferSize, uiWritePos, c); continue; } // otherwise parse the formatting string to find out what has to be done char cNext = szFormat[uiReadPos]; // *** parse the format string *** // first read the flags (as many as there are) unsigned int Flags = ReadFlags (szFormat, uiReadPos, cNext); // read the width of the field int iWidth = ReadWidth (szFormat, uiReadPos, cNext); // read the precision specifier int iPrecision = ReadPrecision (szFormat, uiReadPos, cNext); // read the input data 'length' (short / int / long it, float / double) const sprintfLength::Enum Length = ReadLength (szFormat, uiReadPos, cNext); // read the 'specifier' type const char cSpecifier = ReadSpecifier (szFormat, uiReadPos, cNext, bError); if (bError) { snprintf (szOutputBuffer, uiBufferSize, "Error in formatting string at position %u ('%c').", uiReadPos, cSpecifier); va_end(args); return -1; } // if 'width' was specified as '*', read it from an extra parameter if (iWidth < 0) iWidth = va_arg (args, int); // if 'precision' was specified as '*', read it from an extra parameter if (iPrecision == -2) iPrecision = va_arg (args, int); // % Sign if (cSpecifier == '%') { OutputChar (szOutputBuffer, uiBufferSize, uiWritePos, '%'); continue; } // Nothing: Writes the current write position back to an int pointer if (cSpecifier == 'n') { int* p = va_arg (args, int*); if (p) *p = (int) uiWritePos; continue; } // String if (cSpecifier == 's') { const char* s = va_arg (args, const char*); OutputString (szOutputBuffer, uiBufferSize, uiWritePos, s, Flags, iWidth, iPrecision); continue; } // Character if (cSpecifier == 'c') { char c2 = va_arg (args, int); char s[2] = {c2, 0}; OutputString (szOutputBuffer, uiBufferSize, uiWritePos, s, Flags, iWidth, iPrecision); continue; }
//#define CUPDEBUG bool ParseCUPWayPointString(TCHAR *String,WAYPOINT *Temp) { TCHAR ctemp[(COMMENT_SIZE*2)+1]; // must be bigger than COMMENT_SIZE! TCHAR *pToken; TCHAR TempString[READLINE_LENGTH+1]; TCHAR OrigString[READLINE_LENGTH+1]; TCHAR Tname[NAME_SIZE+1]; int flags=0; unsigned int i, j; bool ishome=false; // 100310 // strtok does not return empty fields. we create them here with special char #define DUMCHAR '|' Temp->Visible = true; // default all waypoints visible at start Temp->FarVisible = true; Temp->Format = LKW_CUP; Temp->Number = WayPointList.size(); Temp->FileNum = globalFileNum; #if BUGSTOP // This should never happen LKASSERT(_tcslen(String) < sizeof(OrigString)); #endif LK_tcsncpy(OrigString, String,READLINE_LENGTH); // if string is too short do nothing if (_tcslen(OrigString)<11) return false; #ifdef CUPDEBUG StartupStore(_T("OLD:<%s>%s"),OrigString,NEWLINE); #endif for (i=0,j=0; i<_tcslen(OrigString); i++) { // skip last comma, and avoid overruning the end if ( (i+1)>= _tcslen(OrigString)) break; if ( (OrigString[i] == _T(',')) && (OrigString[i+1] == _T(',')) ) { TempString[j++] = _T(','); TempString[j++] = _T(DUMCHAR); continue; } /* we need terminations for comments if ( OrigString[i] == _T('\r') ) continue; if ( OrigString[i] == _T('\n') ) continue; */ TempString[j++] = OrigString[i]; } TempString[j] = _T('\0'); #ifdef CUPDEBUG StartupStore(_T("NEW:<%s>%s"),TempString,NEWLINE); #endif // ---------------- NAME ---------------- pToken = _tcstok(TempString, TEXT(",")); if (pToken == NULL) return false; if (_tcslen(pToken)>NAME_SIZE) { pToken[NAME_SIZE-1]= _T('\0'); } _tcscpy(Temp->Name, pToken); CleanCupCode(Temp->Name); #ifdef CUPDEBUG StartupStore(_T(" CUP NAME=<%s>%s"),Temp->Name,NEWLINE); #endif // ---------------- CODE ------------------ pToken = _tcstok(NULL, TEXT(",")); if (pToken == NULL) return false; if (_tcslen(pToken)>CUPSIZE_CODE) { pToken[CUPSIZE_CODE-1]= _T('\0'); } _tcscpy(Temp->Code, pToken); for (i=_tcslen(Temp->Code)-1; i>1; i--) { if (Temp->Code[i]==' ') { Temp->Code[i]=0; } else { break; } } _tcscpy(Tname,Temp->Code); for (j=0, i=0; i<_tcslen(Tname); i++) { //if (Tname[i]!='\"') Temp->Code[j++]=Tname[i]; if ( (Tname[i]!='\"') && (Tname[i]!=DUMCHAR) ){ Temp->Code[j++]=Tname[i]; } } Temp->Code[j]= _T('\0'); if (_tcslen(Temp->Code)>5) { // 100310 if ( _tcscmp(Temp->Code,_T("LKHOME")) == 0 ) { StartupStore(_T(". Found LKHOME inside CUP waypoint <%s>%s"),Temp->Name,NEWLINE); ishome=true; } } #ifdef CUPDEBUG StartupStore(_T(" CUP CODE=<%s>%s"),Temp->Code,NEWLINE); #endif // ---------------- COUNTRY ------------------ pToken = _tcstok(NULL, TEXT(",")); if (pToken == NULL) return false; LK_tcsncpy(Temp->Country,pToken,CUPSIZE_COUNTRY); if (_tcslen(Temp->Country)>3) { Temp->Country[3]= _T('\0'); } if ((_tcslen(Temp->Country) == 1) && Temp->Country[0]==DUMCHAR) Temp->Country[0]=_T('\0'); #ifdef CUPDEBUG StartupStore(_T(" CUP COUNTRY=<%s>%s"),Temp->Country,NEWLINE); #endif // ---------------- LATITUDE ------------------ pToken = _tcstok(NULL, TEXT(",")); if (pToken == NULL) return false; Temp->Latitude = CUPToLat(pToken); if((Temp->Latitude > 90) || (Temp->Latitude < -90)) { return false; } #ifdef CUPDEBUG StartupStore(_T(" CUP LATITUDE=<%f>%s"),Temp->Latitude,NEWLINE); #endif // ---------------- LONGITUDE ------------------ pToken = _tcstok(NULL, TEXT(",")); if (pToken == NULL) return false; Temp->Longitude = CUPToLon(pToken); if((Temp->Longitude > 180) || (Temp->Longitude < -180)) { return false; } #ifdef CUPDEBUG StartupStore(_T(" CUP LONGITUDE=<%f>%s"),Temp->Longitude,NEWLINE); #endif // ---------------- ELEVATION ------------------ pToken = _tcstok(NULL, TEXT(",")); if (pToken == NULL) return false; Temp->Altitude = ReadAltitude(pToken); #ifdef CUPDEBUG StartupStore(_T(" CUP ELEVATION=<%f>%s"),Temp->Altitude,NEWLINE); #endif if (Temp->Altitude == -9999){ Temp->Altitude=0; } // ---------------- STYLE ------------------ pToken = _tcstok(NULL, TEXT(",")); if (pToken == NULL) return false; Temp->Style = (int)_tcstol(pToken,NULL,10); switch(Temp->Style) { case STYLE_AIRFIELDGRASS: // airfield grass case STYLE_GLIDERSITE: // glider site case STYLE_AIRFIELDSOLID: // airfield solid flags = AIRPORT; flags += LANDPOINT; break; case STYLE_OUTLANDING: // outlanding flags = LANDPOINT; break; default: flags = TURNPOINT; break; } if (ishome) flags += HOME; Temp->Flags = flags; #ifdef CUPDEBUG StartupStore(_T(" CUP STYLE=<%d> flags=%d %s"),Temp->Style,Temp->Flags,NEWLINE); #endif // ---------------- RWY DIRECTION ------------------ pToken = _tcstok(NULL, TEXT(",")); if (pToken == NULL) return false; if ((_tcslen(pToken) == 1) && (pToken[0]==DUMCHAR)) Temp->RunwayDir=-1; else Temp->RunwayDir = (int)AngleLimit360(_tcstol(pToken, NULL, 10)); #ifdef CUPDEBUG StartupStore(_T(" CUP RUNWAY DIRECTION=<%d>%s"),Temp->RunwayDir,NEWLINE); #endif // ---------------- RWY LENGTH ------------------ pToken = _tcstok(NULL, TEXT(",")); if (pToken == NULL) return false; if ((_tcslen(pToken) == 1) && (pToken[0]==DUMCHAR)) Temp->RunwayLen = -1; else Temp->RunwayLen = (int)ReadLength(pToken); #ifdef CUPDEBUG StartupStore(_T(" CUP RUNWAY LEN=<%d>%s"),Temp->RunwayLen,NEWLINE); #endif // ---------------- AIRPORT FREQ ------------------ pToken = _tcstok(NULL, TEXT(",")); if (pToken == NULL) return false; if (_tcslen(pToken)>CUPSIZE_FREQ) pToken[CUPSIZE_FREQ-1]= _T('\0'); _tcscpy(Temp->Freq, pToken); TrimRight(Temp->Freq); _tcscpy(Tname,Temp->Freq); for (j=0, i=0; i<_tcslen(Tname); i++) if ( (Tname[i]!='\"') && (Tname[i]!=DUMCHAR) ) Temp->Freq[j++]=Tname[i]; Temp->Freq[j]= _T('\0'); #ifdef CUPDEBUG StartupStore(_T(" CUP FREQ=<%s>%s"),Temp->Freq,NEWLINE); #endif // ---------------- COMMENT ------------------ pToken = _tcstok(NULL, TEXT("\n\r")); if (pToken != NULL) { if (_tcslen(pToken)>=COMMENT_SIZE) pToken[COMMENT_SIZE-1]= _T('\0'); // remove trailing spaces and CR LF _tcscpy(ctemp, pToken); for (i=_tcslen(ctemp)-1; i>1; i--) { if ( (ctemp[i]==' ') || (ctemp[i]=='\r') || (ctemp[i]=='\n') ) ctemp[i]=0; else break; } // now remove " " (if there) for (j=0, i=0; i<_tcslen(ctemp); i++) if (ctemp[i]!='\"') ctemp[j++]=ctemp[i]; ctemp[j]= _T('\0'); if (_tcslen(ctemp) >0 ) { if (Temp->Comment) { free(Temp->Comment); } Temp->Comment = (TCHAR*)malloc((_tcslen(ctemp)+1)*sizeof(TCHAR)); if (Temp->Comment) _tcscpy(Temp->Comment, ctemp); } #ifdef CUPDEBUG StartupStore(_T(" CUP COMMENT=<%s>%s"),Temp->Comment,NEWLINE); #endif } else { Temp->Comment=NULL; // useless } if(Temp->Altitude <= 0) { WaypointAltitudeFromTerrain(Temp); } if (Temp->Details) { free(Temp->Details); } return true; }
bool LoadCupTask(LPCTSTR szFileName) { // LockTaskData(); mapCode2Waypoint_t mapWaypoint; // ClearTask(); size_t idxTP = 0; bool bTakeOff = true; bool bLoadComplet = true; bool bLastInvalid=true; TCHAR szString[READLINE_LENGTH + 1]; TCHAR TpCode[NAME_SIZE + 1]; szString[READLINE_LENGTH] = _T('\0'); TpCode[NAME_SIZE] = _T('\0'); memset(szString, 0, sizeof (szString)); // clear Temp Buffer WAYPOINT newPoint = {0}; WAYPOINT* WPtoAdd=NULL; enum { none, Waypoint, TaskTp, Option } FileSection = none; zzip_stream stream(szFileName, "rt"); iNO_Tasks =0; TaskIndex =0; for (int i =0 ; i< MAX_TASKS;i++) szTaskStrings[ i] = NULL; #define MULTITASKS_CUP #ifdef MULTITASKS_CUP if (stream) { while (stream.read_line(szString)) { if ((FileSection == none) && ((_tcsncmp(_T("name,code,country"), szString, 17) == 0) || (_tcsncmp(_T("Title,Code,Country"), szString, 18) == 0))) { FileSection = Waypoint; continue; } else if ((FileSection == Waypoint) && (_tcscmp(szString, _T("-----Related Tasks-----")) == 0)) { FileSection = TaskTp; continue; } if( FileSection == TaskTp) { if(_tcsstr(szString, _T("\",\""))!= NULL) // really a task? (not an option) { if(iNO_Tasks < MAX_TASKS) // Space in List left {//[READLINE_LENGTH + 1]; szTaskStrings[ iNO_Tasks] = new TCHAR[READLINE_LENGTH + 1]; if( szTaskStrings[ iNO_Tasks] != NULL) { _tcscpy(szTaskStrings[ iNO_Tasks] , szString); // copy task string // StartupStore(_T("..Cup Task : %s %s"), szTaskStrings[ iNO_Tasks], NEWLINE); iNO_Tasks++; } else StartupStore(_T("..Cup Task: no memory %s"), NEWLINE); } else StartupStore(_T("..Cup Task Too many Tasks (more than %i) %s"), MAX_TASKS, NEWLINE); } } } stream.close(); StartupStore(_T("..Cup Selected Task:%i %s %s"), TaskIndex, szTaskStrings[ TaskIndex] , NEWLINE); } int res = 0; if(iNO_Tasks >1) // Selection only if more than one task found res = dlgTaskSelectListShowModal(); for (int i =0 ; i< MAX_TASKS;i++) // free dynamic memory if(szTaskStrings[i] != NULL) { // StartupStore(_T("..Cup Task : delete dynamic memoryLine %i %s"), i,NEWLINE); delete[] szTaskStrings[i]; szTaskStrings[i] = NULL; } if(res == mrCancel) return false; /***********************************************************************************/ LockTaskData(); ClearTask(); stream.open(szFileName, "rt"); #endif FileSection = none; int i=0; if (stream) { while (stream.read_line(szString)) { if ((FileSection == none) && ((_tcsncmp(_T("name,code,country"), szString, 17) == 0) || (_tcsncmp(_T("Title,Code,Country"), szString, 18) == 0))) { FileSection = Waypoint; continue; } else if ((FileSection == Waypoint) && (_tcscmp(szString, _T("-----Related Tasks-----")) == 0)) { FileSection = TaskTp; continue; } TCHAR *pToken = NULL; TCHAR *pWClast = NULL; switch (FileSection) { case Waypoint: memset(&newPoint, 0, sizeof(newPoint)); if (ParseCUPWayPointString(szString, &newPoint)) { mapWaypoint[newPoint.Name] = newPoint; } break; case TaskTp: // 1. Description // First column is the description of the task. If filled it should be double quoted. // If left empty, then SeeYou will determine the task type on runtime. if ((pToken = strsep_r(szString, TEXT(","), &pWClast)) == NULL) { // UnlockTaskData(); // no need to skip if only name missing!!! // return false; } // 2. and all successive columns, separated by commas // Each column represents one waypoint name double quoted. The waypoint name must be exactly the // same as the Long name of a waypoint listed above the Related tasks. WPtoAdd=NULL; if (i++ == TaskIndex) // load selected task { while (bLoadComplet && (pToken = strsep_r(NULL, TEXT(","), &pWClast)) != NULL) { if (idxTP < MAXTASKPOINTS) { _tcsncpy(TpCode, pToken, NAME_SIZE); CleanCupCode(TpCode); mapCode2Waypoint_t::iterator It = mapWaypoint.find(TpCode); if(!ISGAAIRCRAFT) { if (It != mapWaypoint.end()) { if (bTakeOff) { // skip TakeOff Set At Home Waypoint int ix = FindOrAddWaypoint(&(It->second),false); if (ix>=0) { #if 0 // REMOVE // We must not change HomeWaypoint without user knowing! // The takeoff and homewaypoint are independent from task. // In addition, this is a bug because on next run the index is invalid // and we have no more HowWaypoint! HomeWaypoint = ix; #endif bTakeOff = false; } #if BUGSTOP else LKASSERT(0); // .. else is unmanaged, TODO #endif } else { int ix = FindOrAddWaypoint(&(It->second),false); if (ix>=0) Task[idxTP++].Index = ix; #if BUGSTOP else LKASSERT(0); // .. else is unmanaged, TODO #endif } bLastInvalid=false; } else { // An invalid takeoff, probably a "???" , which we ignore #if TESTBENCH if (bTakeOff) StartupStore(_T("....... CUP Takeoff not found: <%s>\n"),TpCode); #endif // in any case bTakeOff now is false bTakeOff=false; bLastInvalid=true; } } else { //ISGAIRRCRAFT if(It != mapWaypoint.end()) { if(WPtoAdd!=NULL) { //add what we found in previous cycle: it was not the last one int ix = FindOrAddWaypoint(WPtoAdd,false); if (ix>=0) Task[idxTP++].Index = ix; #if BUGSTOP else LKASSERT(0); // .. else is unmanaged, TODO #endif } if (bTakeOff) { //it's the first: may be we have a corresponding airfield //look for departure airfield and add it int ix = FindOrAddWaypoint(&(It->second),true); if (ix>=0) { Task[idxTP++].Index = ix; bTakeOff = false; } #if BUGSTOP else LKASSERT(0); // .. else is unmanaged, TODO #endif } else WPtoAdd=&(It->second); //store it for next cycle (may be it is the last one) } } } else { bLoadComplet = false; } } if(ISGAAIRCRAFT) { //For GA: check if we have an airport corresponding to the last WP if(WPtoAdd!=NULL) { //if we have the last one (probably an airfield) still to add... if(idxTP<MAXTASKPOINTS) { int ix=FindOrAddWaypoint(WPtoAdd,true); //look for arrival airport and add it if (ix>=0) { Task[idxTP++].Index= ix; } #if BUGSTOP else LKASSERT(0); // .. else is unmanaged, TODO #endif } else bLoadComplet=false; } } FileSection = Option; } break; case Option: if ((pToken = strsep_r(szString, TEXT(","), &pWClast)) != NULL) { if (_tcscmp(pToken, _T("Options")) == 0) { while ((pToken = strsep_r(NULL, TEXT(","), &pWClast)) != NULL) { if (_tcsstr(pToken, _T("NoStart=")) == pToken) { // Opening of start line PGNumberOfGates = 1; StrToTime(pToken + 8, &PGOpenTimeH, &PGOpenTimeM); } else if (_tcsstr(pToken, _T("TaskTime=")) == pToken) { // Designated Time for the task // TODO : } else if (_tcsstr(pToken, _T("WpDis=")) == pToken) { // Task distance calculation. False = use fixes, True = use waypoints // TODO : } else if (_tcsstr(pToken, _T("NearDis=")) == pToken) { // Distance tolerance // TODO : } else if (_tcsstr(pToken, _T("NearAlt=")) == pToken) { // Altitude tolerance // TODO : } else if (_tcsstr(pToken, _T("MinDis=")) == pToken) { // Uncompleted leg. // False = calculate maximum distance from last observation zone. // TODO : } else if (_tcsstr(pToken, _T("RandomOrder=")) == pToken) { // if true, then Random order of waypoints is checked // TODO : } else if (_tcsstr(pToken, _T("MaxPts=")) == pToken) { // Maximum number of points // TODO : } else if (_tcsstr(pToken, _T("BeforePts=")) == pToken) { // Number of mandatory waypoints at the beginning. 1 means start line only, two means // start line plus first point in task sequence (Task line). // TODO : } else if (_tcsstr(pToken, _T("AfterPts=")) == pToken) { // Number of mandatory waypoints at the end. 1 means finish line only, two means finish line // and one point before finish in task sequence (Task line). // TODO : } else if (_tcsstr(pToken, _T("Bonus=")) == pToken) { // Bonus for crossing the finish line // TODO : } } } else if (_tcsstr(pToken, _T("ObsZone=")) == pToken) { TCHAR *sz = NULL; CupObsZoneUpdater TmpZone; TmpZone.mIdx = _tcstol(pToken + 8, &sz, 10); if (TmpZone.mIdx < MAXTASKPOINTS) { while ((pToken = strsep_r(NULL, TEXT(","), &pWClast)) != NULL) { if (_tcsstr(pToken, _T("Style=")) == pToken) { // Direction. 0 - Fixed value, 1 - Symmetrical, 2 - To next point, 3 - To previous point, 4 - To start point TmpZone.mType = _tcstol(pToken + 6, &sz, 10); } else if (_tcsstr(pToken, _T("R1=")) == pToken) { // Radius 1 TmpZone.mR1 = ReadLength(pToken + 3); } else if (_tcsstr(pToken, _T("A1=")) == pToken) { // Angle 1 in degrees TmpZone.mA1 = _tcstod(pToken + 3, &sz); } else if (_tcsstr(pToken, _T("R2=")) == pToken) { // Radius 2 TmpZone.mR2 = ReadLength(pToken + 3); } else if (_tcsstr(pToken, _T("A2=")) == pToken) { // Angle 2 in degrees TmpZone.mA2 = _tcstod(pToken + 3, &sz); } else if (_tcsstr(pToken, _T("A12=")) == pToken) { // Angle 12 TmpZone.mA12 = _tcstod(pToken + 4, &sz); } else if (_tcsstr(pToken, _T("Line=")) == pToken) { // true For Line Turmpoint type // Exist only for start an Goalin LK TmpZone.mLine = (_tcstol(pToken + 5, &sz, 10) == 1); } } TmpZone.UpdateTask(); } } } break; case none: default: break; } memset(szString, 0, sizeof (szString)); // clear Temp Buffer } } if(!ISGAAIRCRAFT) { // Landing don't exist in LK Task Systems, so Remove It; if ( bLoadComplet && !bLastInvalid ) { RemoveTaskPoint(getFinalWaypoint()); } } UnlockTaskData(); for (mapCode2Waypoint_t::iterator It = mapWaypoint.begin(); It != mapWaypoint.end(); ++It) { if (It->second.Comment) { free(It->second.Comment); } if (It->second.Details) { free(It->second.Details); } } mapWaypoint.clear(); return ValidTaskPoint(0); }
myint SaveTheGame(const char *fn, const char *tag, myint dx, myint dy) { objtype *ob; myint fd, i, x, y; int32_t cs; fd = OpenWrite(fn); if (fd != -1) { WriteBytes(fd, (byte *)GAMEHDR, 8); WriteBytes(fd, (byte *)SAVTYPE, 4); WriteInt32(fd, 0x00000000); /* write version */ WriteBytes(fd, (byte *)GAMETYPE, 4); WriteInt32(fd, time(NULL)); WriteInt32(fd, 0x00000000); WriteInt32(fd, 0x00000000); /* write checksum (placeholder) */ WriteBytes(fd, (byte *)tag, 32); /* write savegame name */ DiskFlopAnim(dx, dy); WriteInt32(fd, gamestate_difficulty); WriteInt32(fd, gamestate.mapon); WriteInt32(fd, gamestate.oldscore); WriteInt32(fd, gamestate.score); WriteInt32(fd, gamestate.nextextra); WriteInt32(fd, gamestate.lives); WriteInt32(fd, gamestate.health); WriteInt32(fd, gamestate.ammo); WriteInt32(fd, gamestate.keys); WriteInt32(fd, gamestate.bestweapon); WriteInt32(fd, gamestate.weapon); WriteInt32(fd, gamestate.chosenweapon); WriteInt32(fd, gamestate.faceframe); WriteInt32(fd, gamestate.attackframe); WriteInt32(fd, gamestate.attackcount); WriteInt32(fd, gamestate.weaponframe); WriteInt32(fd, gamestate_episode); WriteInt32(fd, gamestate.secretcount); WriteInt32(fd, gamestate.treasurecount); WriteInt32(fd, gamestate.killcount); WriteInt32(fd, gamestate.secrettotal); WriteInt32(fd, gamestate.treasuretotal); WriteInt32(fd, gamestate.killtotal); WriteInt32(fd, gamestate.TimeCount); WriteInt32(fd, gamestate.killx); WriteInt32(fd, gamestate.killy); WriteInt8(fd, gamestate.victoryflag); DiskFlopAnim(dx, dy); #ifdef SPEAR for (i = 0; i < 20; i++) { #else for (i = 0; i < 8; i++) { #endif WriteInt32(fd, LevelRatios[i].kill); WriteInt32(fd, LevelRatios[i].secret); WriteInt32(fd, LevelRatios[i].treasure); WriteInt32(fd, LevelRatios[i].time); } DiskFlopAnim(dx, dy); WriteBytes(fd, (byte *)tilemap, 64*64); /* MAPSIZE * MAPSIZE */ DiskFlopAnim(dx, dy); for (x = 0; x < 64; x++) for (y = 0; y < 64; y++) WriteInt32(fd, actorat[x][y]); DiskFlopAnim(dx, dy); WriteBytes(fd, (byte *)&areabyplayer, 8); for (ob = player; ob; ob = obj_next(ob)) { DiskFlopAnim(dx, dy); WriteInt32(fd, obj_id(ob)); WriteInt32(fd, ob->active); WriteInt32(fd, ob->ticcount); WriteInt32(fd, ob->obclass); WriteInt32(fd, ob->state); WriteInt8(fd, ob->flags); WriteInt32(fd, ob->distance); WriteInt32(fd, ob->dir); WriteInt32(fd, ob->x); WriteInt32(fd, ob->y); WriteInt32(fd, ob->tilex); WriteInt32(fd, ob->tiley); WriteInt8(fd, ob->areanumber); WriteInt32(fd, ob->viewx); WriteInt32(fd, ob->viewheight); WriteInt32(fd, ob->transx); WriteInt32(fd, ob->transy); WriteInt32(fd, ob->angle); WriteInt32(fd, ob->hitpoints); WriteInt32(fd, ob->speed); WriteInt32(fd, ob->temp1); WriteInt32(fd, ob->temp2); //WriteInt32(fd, ob->temp3); } WriteInt32(fd, 0xFFFFFFFF); /* end of actor list */ DiskFlopAnim(dx, dy); WriteInt32(fd, laststatobj - statobjlist); /* ptr offset */ for (i = 0; i < 400; i++) { /* MAXSTATS */ WriteInt8(fd, statobjlist[i].tilex); WriteInt8(fd, statobjlist[i].tiley); WriteInt32(fd, statobjlist[i].shapenum); WriteInt8(fd, statobjlist[i].is_bonus); WriteInt8(fd, statobjlist[i].itemnumber); } DiskFlopAnim(dx, dy); for (i = 0; i < 64; i++) { /* MAXDOORS */ WriteInt32(fd, doorposition[i]); } DiskFlopAnim(dx, dy); for (i = 0; i < 64; i++) { /* MAXDOORS */ WriteInt8(fd, doorobjlist[i].tilex); WriteInt8(fd, doorobjlist[i].tiley); WriteInt8(fd, doorobjlist[i].vertical); WriteInt8(fd, doorobjlist[i].lock); WriteInt8(fd, doorobjlist[i].action); WriteInt32(fd, doorobjlist[i].ticcount); } DiskFlopAnim(dx, dy); WriteInt32(fd, pwallstate); WriteInt32(fd, pwallx); WriteInt32(fd, pwally); WriteInt32(fd, pwalldir); WriteInt32(fd, pwallpos); DiskFlopAnim(dx, dy); CloseWrite(fd); fd = OpenRead(fn); ReadSeek(fd, 64, SEEK_SET); cs = CalcFileChecksum(fd, ReadLength(fd) - 64); CloseRead(fd); fd = OpenWriteAppend(fn); WriteSeek(fd, 28, SEEK_SET); WriteInt32(fd, cs); CloseWrite(fd); } else {
myint ReadConfig() { #ifndef EMBEDDED myint fd, configokay; char buf[8]; int32_t version, v; #ifdef ENABLE_CONTROLS myint i; #endif configokay = 0; fd = OpenRead(configname); if (fd != -1) { SetDefaults(); ReadBytes(fd, (byte *)buf, 8); if (strncmp(buf, GAMEHDR, 8)) goto configend; ReadBytes(fd, (byte *)buf, 4); if (strncmp(buf, CFGTYPE, 4)) goto configend; version = ReadInt32(fd); if (version != 0xFFFFFFFF && version != 0x00000000) goto configend; ReadBytes(fd, (byte *)buf, 4); if (strncmp(buf, GAMETYPE, 4)) goto configend; ReadInt32(fd); /* skip over time */ ReadInt32(fd); /* skip over padding */ v = ReadInt32(fd); /* get checksum */ if (v != CalcFileChecksum(fd, ReadLength(fd) - 32)) goto configend; ReadSeek(fd, 32, SEEK_SET); #ifdef ENABLE_HIGHSCORES for (i = 0; i < 7; i++) { /* MaxScores = 7 */ ReadBytes(fd, (byte *)Scores[i].name, 58); Scores[i].score = ReadInt32(fd); Scores[i].completed = ReadInt32(fd); Scores[i].episode = ReadInt32(fd); } #endif viewsize = ReadInt32(fd); /* load the new data */ if (version == 0x00000000) { /* sound config, etc. */ ReadInt32(fd); /* padding */ ReadInt32(fd); /* padding */ ReadInt32(fd); /* padding */ ReadInt32(fd); /* padding */ ReadInt32(fd); /* padding */ ReadInt32(fd); /* padding */ ReadInt32(fd); /* padding */ ReadInt32(fd); /* padding */ #ifdef ENABLE_CONTROLS /* direction keys */ for (i = 0; i < 4; i++) { dirscan[i] = ReadInt32(fd); } /* other game keys */ for (i = 0; i < 8; i++) { /* NUMBUTTONS = 8 */ buttonscan[i] = ReadInt32(fd); } /* mouse enabled */ mouseenabled = ReadInt8(fd); /* mouse buttons */ for (i = 0; i < 4; i++) { buttonmouse[i] = ReadInt32(fd); } #endif /* mouse adjustment */ mouseadjustment = ReadInt32(fd); /* unimplemented joystick */ v = ReadInt32(fd); if (v != 0xFFFFFFFF) { } } #ifndef EMBEDDED #ifdef UPLOAD MainMenu[readthis].active = 1; MainItems.curpos = 0; #endif #endif configokay = 1; } configend: if (fd != -1) CloseRead(fd); if (!configokay) { SetDefaults(); } #else SetDefaults(); #endif return 0; }
myint WriteConfig() { #ifndef EMBEDDED #ifdef ENABLE_CONTROLS myint i; #endif myint fd; int32_t cs; fd = OpenWrite(configname); if (fd != -1) { WriteBytes(fd, (byte *)GAMEHDR, 8); /* WOLF3D, 0, 0 */ WriteBytes(fd, (byte *)CFGTYPE, 4); /* CFG, 0 */ WriteInt32(fd, 0x00000000); /* Version (integer) */ WriteBytes(fd, (byte *)GAMETYPE, 4); /* XXX, 0 */ WriteInt32(fd, time(NULL)); /* Time */ WriteInt32(fd, 0x00000000); /* Padding */ WriteInt32(fd, 0x00000000); /* Checksum (placeholder) */ #ifdef ENABLE_HIGHSCORES for (i = 0; i < 7; i++) { /* MaxScores = 7 */ WriteBytes(fd, (byte *)Scores[i].name, 58); WriteInt32(fd, Scores[i].score); WriteInt32(fd, Scores[i].completed); WriteInt32(fd, Scores[i].episode); } #endif WriteInt32(fd, viewsize); /* sound config, etc. (to be done) */ WriteInt32(fd, 0); /* padding */ WriteInt32(fd, 0); /* padding */ WriteInt32(fd, 0); /* padding */ WriteInt32(fd, 0); /* padding */ WriteInt32(fd, 0); /* padding */ WriteInt32(fd, 0); /* padding */ WriteInt32(fd, 0); /* padding */ WriteInt32(fd, 0); /* padding */ #ifdef ENABLE_CONTROLS /* direction keys */ for (i = 0; i < 4; i++) { WriteInt32(fd, dirscan[i]); } /* other game keys */ for (i = 0; i < 8; i++) { /* NUMBUTTONS = 8 */ WriteInt32(fd, buttonscan[i]); } /* mouse enabled */ WriteInt8(fd, mouseenabled); /* mouse buttons */ for (i = 0; i < 4; i++) { WriteInt32(fd, buttonmouse[i]); } #endif /* mouse adjustment */ WriteInt32(fd, mouseadjustment); /* joystick (to be done) */ WriteInt32(fd, -1); CloseWrite(fd); fd = OpenRead(configname); ReadSeek(fd, 32, SEEK_SET); cs = CalcFileChecksum(fd, ReadLength(fd) - 32); CloseRead(fd); fd = OpenWriteAppend(configname); WriteSeek(fd, 28, SEEK_SET); WriteInt32(fd, cs); CloseWrite(fd); } #endif return 0; }
bool IsMatch(int i, int j) const { assert(0 <= i && i < ReadLength()); assert (0 <= j && j < TemplateLength()); return (features_.Channel[i] == channelTpl_[j]); }