static long Video_RandomizeHotspot( long lHotspot ) /***********************************************************************/ { if ( lHotspot <= 0 ) return( 0 ); char szBuff[5]; wsprintf (szBuff, "%04ld", lHotspot); szBuff[4] = '\0'; int iLow, iMid, iHigh; iLow = (int)(szBuff[0] - '0'); iHigh = (int)(szBuff[1] - '0'); iMid = iLow + GetRandomNumber( iHigh - iLow + 1 ); if ( iMid < 1 ) iMid = 1; if ( iMid > 8 ) iMid = 8; szBuff[0] = '0' + (iMid - 1); szBuff[1] = '0' + (iMid + 1); iLow = (int)(szBuff[2] - '0'); iHigh = (int)(szBuff[3] - '0'); iMid = iLow + GetRandomNumber( iHigh - iLow + 1 ); if ( iMid < 1 ) iMid = 1; if ( iMid > 8 ) iMid = 8; szBuff[2] = '0' + (iMid - 1); szBuff[3] = '0' + (iMid + 1); return( latol( szBuff ) ); }
BOOL CCreditsParser::GetColor(COLORREF FAR *lpColor, LPSTR lpEntry, LPSTR lpValues, int nValues) /***********************************************************************/ { long l; LPSTR lpValue; BOOL bError; BYTE rgb[3]; if (nValues != 3) { Print("'%s'\n Invalid color '%s'", lpEntry, lpValues); return(FALSE); } for (int i = 0; i < 3; ++i) { lpValue = GetNextValue(&lpValues); l = latol(lpValue, &bError); if ( bError || l < 0 ) { Print("'%s'\n Bad number at '%s'", lpEntry, lpValue); return(FALSE); } rgb[i] = (BYTE)l; } *lpColor = RGB(rgb[0], rgb[1], rgb[2]); return(TRUE); }
BOOL CParser::GetPoint(LPPOINT lpPoint, LPSTR lpEntry, LPSTR lpValues, int nValues) /***********************************************************************/ { long l; LPSTR lpValue; LPINT lpPtValue; BOOL bError; if (nValues != 2) { Print("'%s'\n Invalid point '%s'", lpEntry, lpValues); return(FALSE); } // even though the idiots at Microsoft made POINT use // INTs in 16-bit and LONGs in 32-bit, using an INT will // work fine since it naturally grows from 16 to 32 bits. lpPtValue = (LPINT)lpPoint; while (--nValues >= 0) { lpValue = GetNextValue(&lpValues); l = latol(lpValue, &bError); if ( bError ) { Print("'%s'\n Bad number at '%s'", lpEntry, lpValue); return(FALSE); } *lpPtValue++ = (int)l; } return(TRUE); }
BOOL CParser::GetRect(LPRECT lpRect, LPSTR lpEntry, LPSTR lpValues, int nValues) /***********************************************************************/ { long l; LPSTR lpValue; LPINT lpRectValue; BOOL bError; if (nValues != 4) { Print("'%s'\n Invalid rectangle '%s'", lpEntry, lpValues); return(FALSE); } lpRectValue = (LPINT)lpRect; while (--nValues >= 0) { lpValue = GetNextValue(&lpValues); l = latol(lpValue, &bError); if ( bError || l < 0 ) { Print("'%s'\n Bad number at '%s'", lpEntry, lpValue); return(FALSE); } *lpRectValue++ = (int)l; } return(TRUE); }
BOOL CParser::GetInt(LPINT lpInt, LPSTR lpEntry, LPSTR lpValues, int nValues) /***********************************************************************/ { long l; LPSTR lpValue; BOOL bError; if (nValues != 1) { Print("'%s'\n Invalid integer '%s'", lpEntry, lpValues); return(FALSE); } lpValue = GetNextValue(&lpValues); l = latol(lpValue, &bError); if ( bError || l < 0 ) { Print("'%s'\n Bad number at '%s'", lpEntry, lpValue); return(FALSE); } *lpInt = (int)l; return(TRUE); }
//************************************************************************ BOOL CCreditsParser::HandleKey(LPSTR lpEntry, LPSTR lpKey, LPSTR lpValues, int nValues, int nIndex, DWORD dwUserData) //************************************************************************ { static POINT ptStartDefault = {0,0}, ptEndDefault = {0,480}; static DWORD dwDelayTimeDefault= 500L; static int iSpeedDefault = 50, iTypeDefault = 0; LPCREDITSSCENE lpScene = (LPCREDITSSCENE)dwUserData; if (nIndex == 0) { if (!lstrcmpi(lpKey, "face1")) GetString(lpScene->m_szFaceName[0], lpEntry, lpValues, nValues); else if (!lstrcmpi(lpKey, "face2")) GetString(lpScene->m_szFaceName[1], lpEntry, lpValues, nValues); else if (!lstrcmpi(lpKey, "size1")) GetInt(&lpScene->m_ptSize[0], lpEntry, lpValues, nValues); else if (!lstrcmpi(lpKey, "size2")) GetInt(&lpScene->m_ptSize[1], lpEntry, lpValues, nValues); else if (!lstrcmpi(lpKey, "italic1")) GetInt(&lpScene->m_fItalic[0], lpEntry, lpValues, nValues); else if (!lstrcmpi(lpKey, "italic2")) GetInt(&lpScene->m_fItalic[1], lpEntry, lpValues, nValues); else if (!lstrcmpi(lpKey, "color1")) GetColor(&lpScene->m_Color[0], lpEntry, lpValues, nValues); else if (!lstrcmpi(lpKey, "color2")) GetColor(&lpScene->m_Color[1], lpEntry, lpValues, nValues); else if (!lstrcmpi(lpKey, "bgcolor")) GetColor(&lpScene->m_BackgrndColor, lpEntry, lpValues, nValues); else if (!lstrcmpi(lpKey, "center")) GetInt(&lpScene->m_fCenter, lpEntry, lpValues, nValues); else if (!lstrcmpi(lpKey, "cliprect") || !lstrcmpi(lpKey, "gamearea")) GetRect(&lpScene->m_rGameArea, lpEntry, lpValues, nValues); else if (!lstrcmpi(lpKey, "soundtrack")) GetFilename(lpScene->m_szSoundTrack, lpEntry, lpValues, nValues); else if (!lstrcmpi(lpKey, "start")) GetPoint(&ptStartDefault, lpEntry, lpValues, nValues); else if (!lstrcmpi(lpKey, "end")) GetPoint(&ptEndDefault, lpEntry, lpValues, nValues); else if (!lstrcmpi(lpKey, "delay")) { STRING szTime; GetString(szTime, lpEntry, lpValues, nValues); dwDelayTimeDefault = latol(szTime); } else if (!lstrcmpi(lpKey, "speed")) GetInt(&iSpeedDefault, lpEntry, lpValues, nValues); else if (!lstrcmpi(lpKey, "type")) { GetInt(&iTypeDefault, lpEntry, lpValues, nValues); --iTypeDefault; // make zero relative if (iTypeDefault <= 0) iTypeDefault = 0; else iTypeDefault = 1; } else Print("'%ls'\n Unknown key '%s'", lpEntry, lpKey); } else { LPCONTRIBUTOR pContributor = lpScene->GetContributor(nIndex-1);; if (!lstrcmpi(lpKey, "start")) GetPoint(&pContributor->m_ptStart, lpEntry, lpValues, nValues); else if (!lstrcmpi(lpKey, "end")) GetPoint(&pContributor->m_ptEnd, lpEntry, lpValues, nValues); else if (!lstrcmpi(lpKey, "name")) { GetString(pContributor->m_szName, lpEntry, lpValues, nValues); LPSTR lp; while (lp = FindString(pContributor->m_szName, "]")) *lp = ','; pContributor->m_ptStart = ptStartDefault; pContributor->m_ptEnd = ptEndDefault; pContributor->m_dwDelayTime = dwDelayTimeDefault; pContributor->m_iSpeed = iSpeedDefault; pContributor->m_iType = iTypeDefault; } else if (!lstrcmpi(lpKey, "delay")) { STRING szTime; GetString(szTime, lpEntry, lpValues, nValues); pContributor->m_dwDelayTime = latol(szTime); } else if (!lstrcmpi(lpKey, "speed")) GetInt(&pContributor->m_iSpeed, lpEntry, lpValues, nValues); else if (!lstrcmpi(lpKey, "type")) { GetInt(&pContributor->m_iType, lpEntry, lpValues, nValues); --pContributor->m_iType; // make zero relative if (pContributor->m_iType <= 0) pContributor->m_iType = 0; else pContributor->m_iType = 1; } else Print("'%ls'\n Unknown key '%s'", lpEntry, lpKey); } return(TRUE); }