//--------------------------------------------------------------------------- // 函数: GetString // 功能: 取得某行某列字符串的值 // 参数: nRow 行 从1开始 // nColomn 列 从1开始 // lpDefault 缺省值 // lpRString 返回值 // dwSize 返回字符串的最大长度 // 返回: 是否成功 //--------------------------------------------------------------------------- BOOL KTabFile::GetString(int nRow, int nColumn, LPSTR lpDefault, LPSTR lpRString, DWORD dwSize) { if (GetValue(nRow - 1, nColumn - 1, lpRString, dwSize)) return TRUE; g_StrCpyLen(lpRString, lpDefault, dwSize); return FALSE; }
//--------------------------------------------------------------------------- // 函数: GetKeyValue // 功能: 取得Key的Value // 参数: pSection 节名 // pKey 建名 // pValue 建值 // 返回: TRUE-成功 FALSE-失败 //--------------------------------------------------------------------------- BOOL KIniFile::GetKeyValue( LPCSTR pSection, LPCSTR pKey, LPSTR pValue, DWORD dwSize) { DWORD dwID; // setup section name char szSection[32] = "["; if (pSection[0] != '[') { g_StrCat(szSection, pSection); g_StrCat(szSection, "]"); } else { g_StrCpy(szSection, pSection); } // search for the matched section SECNODE* pSecNode = m_Header.pNextNode; dwID = String2Id(szSection); while (pSecNode != NULL) { if (dwID == pSecNode->dwID) { break; } pSecNode = pSecNode->pNextNode; } // if no such section founded if (pSecNode == NULL) { return FALSE; } // search for the same key KEYNODE* pKeyNode = pSecNode->pKeyNode.pNextNode; dwID = String2Id(pKey); while (pKeyNode != NULL) { if (dwID == pKeyNode->dwID) { break; } pKeyNode = pKeyNode->pNextNode; } // if no such key found if (pKeyNode == NULL) { return FALSE; } // copy the value of the key g_StrCpyLen(pValue, pKeyNode->pValue, dwSize); return TRUE; }
//--------------------------------------------------------------------------- // 函数: CreateIniLink // 功能: 创建Ini链表 // 参数: pBuffer 缓存 // nBufLen 长度 // 返回: void //--------------------------------------------------------------------------- void KIniFile::CreateIniLink(LPVOID pBuffer, LONG nBufLen) { LPSTR lpBuffer = (LPSTR)pBuffer; LPSTR lpString = NULL; LPSTR lpValue = NULL; char szSection[32] = "[MAIN]"; m_Offset = 0; while (m_Offset < nBufLen) { lpString = &lpBuffer[m_Offset]; if (!ReadLine(lpBuffer, nBufLen)) continue; if (*lpString == ';') { continue; } if (*lpString == '#') { continue; } if (*lpString == '[') { g_StrCpyLen(szSection, lpString, sizeof(szSection)); continue; } lpValue = SplitKeyValue(lpString); SetKeyValue(szSection, lpString, lpValue); } }
//--------------------------------------------------------------------------- // 函数: GetString // 功能: 取得某行某列字符串的值 // 参数: szRow 行 (关键字) // szColomn 列 (关键字) // lpDefault 缺省值 // lpRString 返回值 // dwSize 返回字符串的最大长度 // 返回: 是否成功 //--------------------------------------------------------------------------- BOOL KTabFile::GetString(LPSTR szRow, LPSTR szColumn, LPSTR lpDefault, LPSTR lpRString, DWORD dwSize) { int nRow, nColumn; nRow = FindRow(szRow); nColumn = FindColumn(szColumn); if (GetValue(nRow - 1, nColumn - 1, lpRString, dwSize)) return TRUE; g_StrCpyLen(lpRString, lpDefault, dwSize); return FALSE; }
void KObj::SetScriptFile(char *lpszScriptFile) { char szScript[80]; if ( !lpszScriptFile || strlen(lpszScriptFile) >= sizeof(szScript)) { g_DebugLog("[error]Script FileName Error!!!"); } else { if (lpszScriptFile[0]) { if (lpszScriptFile[0] == '.') g_StrCpyLen(szScript, &lpszScriptFile[1], sizeof(szScript)); else g_StrCpyLen(szScript, lpszScriptFile, sizeof(szScript)); g_StrLower(szScript); m_dwScriptID = g_FileName2Id(szScript); } } }
//--------------------------------------------------------------------------- // 函数: GetString // 功能: 取得某行某列字符串的值 // 参数: nRow 行 // nColomn 列 // lpDefault 缺省值 // lpRString 返回值 // dwSize 返回字符串的最大长度 // 返回: 是否成功 //--------------------------------------------------------------------------- BOOL KTabFile::GetString(int nRow, LPSTR szColumn, LPSTR lpDefault, LPSTR lpRString, DWORD dwSize, BOOL bColumnLab) { int nColumn; if (bColumnLab) nColumn = FindColumn(szColumn); else nColumn = Str2Col(szColumn); if (GetValue(nRow - 1, nColumn - 1, lpRString, dwSize)) return TRUE; g_StrCpyLen(lpRString, lpDefault, dwSize); return FALSE; }
//--------------------------------------------------------------------------- // 函数: GetString // 功能: 读取一个字符串 // 参数: lpSection 节名 // lpKeyName 建名 // lpDefault 缺省值 // lpRString 返回值 // dwSize 返回字符串的最大长度 // 返回: void //--------------------------------------------------------------------------- BOOL KIniFile::GetString( LPCSTR lpSection, // points to section name LPCSTR lpKeyName, // points to key name LPCSTR lpDefault, // points to default string LPSTR lpRString, // points to destination buffer DWORD dwSize // size of string buffer ) { if (GetKeyValue(lpSection, lpKeyName, lpRString, dwSize)) return TRUE; g_StrCpyLen(lpRString, lpDefault, dwSize); return FALSE; }
//--------------------------------------------------------------------------- // 函数: GetString // 功能: 取得某行某列字符串的值 // 参数: nRow 行 从1开始 // nColomn 列 从1开始 // lpDefault 缺省值 // lpRString 返回值 // dwSize 返回字符串的最大长度 // 返回: 1:成功 0:表格不对 -1:未填,使用默认值 //--------------------------------------------------------------------------- int KTabFile::GetString(int nRow, int nColumn, const char* lpDefault, char* lpRString, unsigned int dwSize) { int nRet = 0; nRet = GetValue(nRow - 1, nColumn - 1, lpRString, dwSize); if (1 != nRet) g_StrCpyLen(lpRString, lpDefault, dwSize); if (nRet == 0 && m_bErrorLogEnable) { KGLogPrintf(KGLOG_DEBUG, "GetString(%d, %d) failed !\n", nRow, nColumn); } return nRet; }
//--------------------------------------------------------------------------- // 功能: 根据动作编号、装备编号得到资源文件名 //--------------------------------------------------------------------------- BOOL CRESINFO::GetName(int nActionNo, int nEquipNo, char *lpszDefault, char *lpszGetName, int nStrLen) { if (!lpszGetName) return FALSE; if (m_cSprInfo == NULL) goto FALSE_LAB; if (nActionNo < 0 || nActionNo >= m_nActionKind || nEquipNo < 0 || nEquipNo >= m_nEquipKind) goto FALSE_LAB; strcpy(lpszGetName, m_cSprInfo[nEquipNo * m_nActionKind + nActionNo].szFileName); return TRUE; FALSE_LAB: g_StrCpyLen(lpszGetName, lpszDefault, nStrLen); return FALSE; }
//--------------------------------------------------------------------------- // 函数: GetString // 功能: 取得某行某列字符串的值 // 参数: szRow 行 (关键字) // szColomn 列 (关键字) // lpDefault 缺省值 // lpRString 返回值 // dwSize 返回字符串的最大长度 // 返回: 1:成功 0:表格不对 -1:未填,使用默认值 //--------------------------------------------------------------------------- int KTabFile::GetString(const char* szRow, const char* szColumn, const char* lpDefault, char* lpRString, unsigned int dwSize) { int nRow, nColumn; int nRet = 0; nRow = FindRow(szRow); nColumn = FindColumn(szColumn); nRet = GetValue(nRow - 1, nColumn - 1, lpRString, dwSize); if (1 != nRet) g_StrCpyLen(lpRString, lpDefault, dwSize); if (nRet == 0 && m_bErrorLogEnable) { KGLogPrintf(KGLOG_DEBUG, "GetString(%s, %s) failed !\n", szRow, szColumn); } return nRet; }
//--------------------------------------------------------------------------- // 函数: GetString // 功能: 取得某行某列字符串的值 // 参数: nRow 行 // nColomn 列 // lpDefault 缺省值 // lpRString 返回值 // dwSize 返回字符串的最大长度 // 返回: 1:成功 0:表格不对 -1:未填,使用默认值 //--------------------------------------------------------------------------- int KTabFile::GetString(int nRow, const char* szColumn, const char* lpDefault, char* lpRString, unsigned int dwSize, int bColumnLab) { int nColumn; int nRet = 0; if (bColumnLab) nColumn = FindColumn(szColumn); else nColumn = Str2Col(szColumn); nRet = GetValue(nRow - 1, nColumn - 1, lpRString, dwSize); if (1 != nRet) g_StrCpyLen(lpRString, lpDefault, dwSize); if (nRet == 0 && m_bErrorLogEnable) { KGLogPrintf(KGLOG_DEBUG, "GetString(%d, %s) failed !\n", nRow, szColumn); } return nRet; }
BOOL KNpcResNode::Init(char *lpszNpcName, CActionName *cActionName, CActionName *cNpcAction) { if (lpszNpcName == NULL || lpszNpcName[0] == 0) return FALSE; KTabFile KindFile; int i, j, k, nFindNo; char szBuffer[FILE_NAME_LENGTH], szTemp[FILE_NAME_LENGTH], szBuf[FILE_NAME_LENGTH]; const char *pcszTemp = NULL; strcpy(m_szNpcName, lpszNpcName); // 载入文件 人物类型.txt // g_SetFilePath(RES_INI_FILE_PATH); if ( !KindFile.Load(NPC_RES_KIND_FILE_NAME) ) return FALSE; nFindNo = KindFile.FindRow(lpszNpcName); if (nFindNo < 0) return FALSE; KindFile.GetString(nFindNo, KIND_NAME_SECT, "", szBuffer, sizeof(szBuffer)); // 判断npc类型 if (strcmp(szBuffer, KIND_NAME_SPECIAL) == 0) m_nNpcKind = NPC_RES_SPECIAL; else m_nNpcKind = NPC_RES_NORMAL; // 得到资源文件路径 KindFile.GetString(nFindNo, KIND_FILE_SECT5, "", m_szResPath, sizeof(m_szResPath)); // 特殊npc if (m_nNpcKind == NPC_RES_SPECIAL) { KTabFile PartFile, SoundName, ShadowName; // 得到部件说明文件名 KindFile.GetString(nFindNo, KIND_FILE_SECT1, "", szBuffer, sizeof(szBuffer)); if ( !szBuffer[0] ) return FALSE; // g_SetFilePath(RES_INI_FILE_PATH); g_UnitePathAndName(RES_INI_FILE_PATH, szBuffer, szBuf); if ( !PartFile.Load(szBuf) ) return FALSE; // 得到部件组成信息 m_nPartNum = 0; for (i = 0; i < MAX_BODY_PART; i++) { for (j = 0; j < MAX_BODY_PART_SECT; j++) { m_nSectInfo[i * MAX_BODY_PART_SECT + j].Clear(); PartFile.GetString( i + 2, j + 3, "", m_nSectInfo[i * MAX_BODY_PART_SECT + j].szSectName, sizeof(m_nSectInfo[i * MAX_BODY_PART_SECT + j].szSectName)); if ( m_nSectInfo[i * MAX_BODY_PART_SECT + j].szSectName[0] ) { m_nSectInfo[i * MAX_BODY_PART_SECT + j].nFlag = 1; m_nPartNum++; } } } // 得到每个部件的资源说明文件名 for (i = 0; i < MAX_PART; i++) { if (m_nSectInfo[i].nFlag) { KindFile.GetString( nFindNo, m_nSectInfo[i].szSectName, "", m_nSectInfo[i].szSectResName, sizeof(m_nSectInfo[i].szSectResName)); // 资源信息说明文件名是资源说明文件名加上SPR_INFO_NAME(“信息”) if (m_nSectInfo[i].szSectResName[0]) { g_StrCpyLen( m_nSectInfo[i].szSectSprInfoName, m_nSectInfo[i].szSectResName, g_StrLen(m_nSectInfo[i].szSectResName) - 3 ); g_StrCat(m_nSectInfo[i].szSectSprInfoName, SPR_INFO_NAME); g_StrCat(m_nSectInfo[i].szSectSprInfoName, ".txt"); } } } // 得到每个部件的具体的资源文件名 KTabFile SectFile, SectInfoFile; int nGetEquipNo, nActionCount; for (i = 0; i < MAX_PART; i++) { m_cResInfo[i].AutoDelete(); if (m_nSectInfo[i].nFlag) { // g_SetFilePath(RES_INI_FILE_PATH); #ifdef TOOLVERSION g_UnitePathAndName(RES_INI_FILE_PATH, m_nSectInfo[i].szSectResName, szBuf); if (!SectFile.Load(szBuf)) continue; else { g_UnitePathAndName(RES_INI_FILE_PATH, m_nSectInfo[i].szSectSprInfoName, szBuf); SectInfoFile.Load(szBuf); } #else g_UnitePathAndName(RES_INI_FILE_PATH, m_nSectInfo[i].szSectResName, szBuf); if ( !SectFile.Load(szBuf) ) continue; g_UnitePathAndName(RES_INI_FILE_PATH, m_nSectInfo[i].szSectSprInfoName, szBuf); if ( !SectInfoFile.Load(szBuf)) continue; #endif nGetEquipNo = SectFile.GetHeight() - 1; if (nGetEquipNo <= 0) continue; nActionCount = cActionName->GetActionCount(); if (nActionCount <= 0) continue; m_cResInfo[i].AutoNew(nActionCount, nGetEquipNo); for (j = 0; j < nGetEquipNo; j++) { for (k = 0; k < nActionCount; k++) { // 用字符串比较太慢,所以直接用编号,但是表格必须保证不出错 // cActionName->GetActionName(k, szBuffer, sizeof(szBuffer)); // SectFile.GetString( // j + 2, // szBuffer, // "", // szTemp, // 80); SectFile.GetString( j + 2, k + 2, "", szTemp, sizeof(szTemp)); ComposePathAndName(m_cResInfo[i].m_cSprInfo[j * nActionCount + k].szFileName, m_szResPath, szTemp); SectInfoFile.GetString( j + 2, k + 2, "16,16,0", szTemp, sizeof(szTemp) ); pcszTemp = szTemp; m_cResInfo[i].m_cSprInfo[j * nActionCount + k].nTotalFrames = KSG_StringGetInt(&pcszTemp, 16); KSG_StringSkipSymbol(&pcszTemp, ','); m_cResInfo[i].m_cSprInfo[j * nActionCount + k].nTotalDirs = KSG_StringGetInt(&pcszTemp, 16); KSG_StringSkipSymbol(&pcszTemp, ','); m_cResInfo[i].m_cSprInfo[j * nActionCount + k].nInterval = KSG_StringGetInt(&pcszTemp, 0); //sscanf(szTemp, "%d,%d,%d", // &m_cResInfo[i].m_cSprInfo[j * nActionCount + k].nTotalFrames, // &m_cResInfo[i].m_cSprInfo[j * nActionCount + k].nTotalDirs, // &m_cResInfo[i].m_cSprInfo[j * nActionCount + k].nInterval //); } } } } // 得到武器行为关联表文件名 KTabFile NoHorseFile, OnHorseFile; int nTableWidth, nTableHeight, nGetNo; char szNoHorseTableName[80], szOnHorseTableName[80]; KindFile.GetString(nFindNo, KIND_FILE_SECT2, "", szNoHorseTableName, sizeof(szNoHorseTableName)); KindFile.GetString(nFindNo, KIND_FILE_SECT3, "", szOnHorseTableName, sizeof(szOnHorseTableName)); // 未骑马对应表 if (szNoHorseTableName[0]) { // g_SetFilePath(RES_INI_FILE_PATH); g_UnitePathAndName(RES_INI_FILE_PATH, szNoHorseTableName, szBuf); if ( NoHorseFile.Load(szBuf) ) { nTableWidth = NoHorseFile.GetWidth() - 1; nTableHeight = NoHorseFile.GetHeight() - 1; m_NoHorseTable.AutoNew(nTableWidth, nTableHeight); for (i = 0; i < nTableHeight; i++) { for (j = 0; j < nTableWidth; j++) { NoHorseFile.GetString(i + 2, j + 2, "", szBuffer, sizeof(szBuffer)); nGetNo = cActionName->GetActionNo(szBuffer); m_NoHorseTable.SetValue(j, i, nGetNo); } } } } // 骑马对应表 if (szOnHorseTableName[0]) { // g_SetFilePath(RES_INI_FILE_PATH); g_UnitePathAndName(RES_INI_FILE_PATH, szOnHorseTableName, szBuf); if ( OnHorseFile.Load(szBuf) ) { nTableWidth = OnHorseFile.GetWidth() - 1; nTableHeight = OnHorseFile.GetHeight() - 1; m_OnHorseTable.AutoNew(nTableWidth, nTableHeight); for (i = 0; i < nTableHeight; i++) { for (j = 0; j < nTableWidth; j++) { OnHorseFile.GetString(i + 2, j + 2, "", szBuffer, sizeof(szBuffer)); nGetNo = cActionName->GetActionNo(szBuffer); m_OnHorseTable.SetValue(j, i, nGetNo); } } } } // 得到贴图顺序表文件名 if ( KindFile.GetString(nFindNo, KIND_FILE_SECT4, "", szBuffer, sizeof(szBuffer)) ) { strcpy(m_cSortTable.m_sSortTableFileName, szBuffer); m_cSortTable.GetTable(szBuffer, cActionName, m_nPartNum); } // 获得动作阴影文件信息 int nFindNo; // g_SetFilePath(RES_INI_FILE_PATH); nActionCount = cActionName->GetActionCount(); this->m_cShadowInfo.Init(nActionCount); ShadowName.Load(PLAYER_RES_SHADOW_FILE); nFindNo = ShadowName.FindRow(lpszNpcName); if (nFindNo > 0 && nActionCount > 0) { for (i = 0; i < nActionCount; i++) { ShadowName.GetString(nFindNo, 2 + i * 2, "", szTemp, sizeof(szTemp)); if (szTemp[0]) this->ComposePathAndName(m_cShadowInfo.m_psInfo[i].m_szName, m_szResPath, szTemp); ShadowName.GetString(nFindNo, 2 + i * 2 + 1, "16,8,1", szTemp, sizeof(szTemp)); pcszTemp = szTemp; m_cShadowInfo.m_psInfo[i].m_nTotalFrame = KSG_StringGetInt(&pcszTemp, 16); KSG_StringSkipSymbol(&pcszTemp, ','); m_cShadowInfo.m_psInfo[i].m_nTotalDir = KSG_StringGetInt(&pcszTemp, 8); KSG_StringSkipSymbol(&pcszTemp, ','); m_cShadowInfo.m_psInfo[i].m_nInterval = KSG_StringGetInt(&pcszTemp, 1); //sscanf(szTemp, "%d,%d,%d", &m_cShadowInfo.m_psInfo[i].m_nTotalFrame, &m_cShadowInfo.m_psInfo[i].m_nTotalDir, &m_cShadowInfo.m_psInfo[i].m_nInterval); m_cShadowInfo.m_psInfo[i].m_nCgX = SPR_X_OFF; m_cShadowInfo.m_psInfo[i].m_nCgY = SPR_Y_OFF; } } // 获得动作音效文件名 // g_SetFilePath(RES_INI_FILE_PATH); SoundName.Load(PLAYER_SOUND_FILE); nFindNo = SoundName.FindColumn(lpszNpcName); nActionCount = cActionName->GetActionCount(); if (nFindNo > 0 && nActionCount > 0) { for (i = 0; i < nActionCount; i++) { SoundName.GetString(i + 2, nFindNo, "", szTemp, sizeof(szTemp)); if (szTemp[0]) this->ComposePathAndName(this->m_szSoundName[i], RES_SOUND_FILE_PATH, szTemp); } } } // 普通npc else if (m_nNpcKind == NPC_RES_NORMAL) { int nActionCount; KTabFile NormalNpc, NormalNpcSprInfo, SoundName; for (i = 0; i < MAX_PART; i++) m_nSectInfo[i].nFlag = 0; m_nSectInfo[NORMAL_NPC_PART_NO].nFlag = 1; m_nPartNum = 1; for (i = 0; i < MAX_PART; i++) m_cResInfo[i].AutoDelete(); nActionCount = cNpcAction->GetActionCount(); if (nActionCount < 0) nActionCount = 0; m_cResInfo[NORMAL_NPC_PART_NO].AutoNew(nActionCount, 1); this->m_cShadowInfo.Init(nActionCount); // g_SetFilePath(RES_INI_FILE_PATH); if ( !NormalNpc.Load(NPC_NORMAL_RES_FILE)) return FALSE; // 动画信息文件没有没有必要初始化不成功,所以没有If(!) return FALSE; NormalNpcSprInfo.Load(NPC_NORMAL_SPRINFO_FILE); SoundName.Load(NPC_SOUND_FILE); nFindNo = NormalNpc.FindRow(lpszNpcName); if (nFindNo < 0) return FALSE; for (i = 0; i < nActionCount; i++) { cNpcAction->GetActionName(i, szBuffer, sizeof(szBuffer)); NormalNpc.GetString(nFindNo, szBuffer, "", szTemp, sizeof(szTemp)); ComposePathAndName(m_cResInfo[NORMAL_NPC_PART_NO].m_cSprInfo[i].szFileName, m_szResPath, szTemp); NormalNpcSprInfo.GetString(nFindNo, szBuffer, "16,8,0", szTemp, sizeof(szTemp)); pcszTemp = szTemp; m_cResInfo[NORMAL_NPC_PART_NO].m_cSprInfo[i].nTotalFrames = KSG_StringGetInt(&pcszTemp, 16); KSG_StringSkipSymbol(&pcszTemp, ','); m_cResInfo[NORMAL_NPC_PART_NO].m_cSprInfo[i].nTotalDirs = KSG_StringGetInt(&pcszTemp, 8); KSG_StringSkipSymbol(&pcszTemp, ','); m_cResInfo[NORMAL_NPC_PART_NO].m_cSprInfo[i].nInterval = KSG_StringGetInt(&pcszTemp, 0); //sscanf(szTemp, "%d,%d,%d", // &m_cResInfo[NORMAL_NPC_PART_NO].m_cSprInfo[i].nTotalFrames, // &m_cResInfo[NORMAL_NPC_PART_NO].m_cSprInfo[i].nTotalDirs, // &m_cResInfo[NORMAL_NPC_PART_NO].m_cSprInfo[i].nInterval //); KNpcResNode::GetShadowName(m_cShadowInfo.m_psInfo[i].m_szName, m_cResInfo[NORMAL_NPC_PART_NO].m_cSprInfo[i].szFileName); m_cShadowInfo.m_psInfo[i].m_nTotalFrame = m_cResInfo[NORMAL_NPC_PART_NO].m_cSprInfo[i].nTotalFrames; m_cShadowInfo.m_psInfo[i].m_nTotalDir = m_cResInfo[NORMAL_NPC_PART_NO].m_cSprInfo[i].nTotalDirs; m_cShadowInfo.m_psInfo[i].m_nInterval = m_cResInfo[NORMAL_NPC_PART_NO].m_cSprInfo[i].nInterval; m_cShadowInfo.m_psInfo[i].m_nCgX = SPR_X_OFF; m_cShadowInfo.m_psInfo[i].m_nCgY = SPR_Y_OFF; SoundName.GetString(nFindNo, szBuffer, "", szTemp, sizeof(szTemp)); if (szTemp[0]) ComposePathAndName(m_szSoundName[i], RES_SOUND_FILE_PATH, szTemp); } } return TRUE; }