diff --git a/include/core.h b/include/core.h index e31e05a..d15c9f9 100644 --- a/include/core.h +++ b/include/core.h @@ -324,6 +324,22 @@ enum PickupType PICKUP_DEFUSEKIT }; +// fight style type +enum FightStyle +{ + FIGHT_NONE, + FIGHT_STRAFE, + FIGHT_STAY +}; + +// dodge type +enum StrafeDir +{ + STRAFE_DIR_NONE, + STRAFE_DIR_LEFT, + STRAFE_DIR_RIGHT +}; + // reload state enum ReloadState { @@ -836,8 +852,8 @@ private: bool m_checkWeaponSwitch; // is time to check weapon switch bool m_isUsingGrenade; // bot currently using grenade?? - unsigned char m_combatStrafeDir; // direction to strafe - unsigned char m_fightStyle; // combat style to use + StrafeDir m_combatStrafeDir; // direction to strafe + FightStyle m_fightStyle; // combat style to use float m_lastFightStyleCheck; // time checked style float m_strafeSetTime; // time strafe direction was set @@ -1524,7 +1540,7 @@ extern bool IsInViewCone (const Vector &origin, edict_t *ent); extern bool IsValidBot (edict_t *ent); extern bool IsValidPlayer (edict_t *ent); extern bool IsPlayerVIP (edict_t *ent); -extern bool OpenConfig (const char *fileName, const char *errorIfNotExists, File *outFile, bool languageDependant = false); +extern bool OpenConfig (const char *fileName, const char *errorIfNotExists, MemoryFile *outFile, bool languageDependant = false); extern bool FindNearestPlayer (void **holder, edict_t *to, float searchDistance = 4096.0, bool sameTeam = false, bool needBot = false, bool needAlive = false, bool needDrawn = false); extern void FreeLibraryMemory (void); diff --git a/include/corelib.h b/include/corelib.h index a206db4..badce0f 100644 --- a/include/corelib.h +++ b/include/corelib.h @@ -3694,6 +3694,287 @@ public: } }; +// +// Class: MemoryFile +// Simple Memory file wrapper class. (RO) +// +class MemoryFile +{ +public: + typedef unsigned char *(*MF_Loader) (const char *, int *); + typedef void (*MF_Unloader) (unsigned char *); + +public: + static MF_Loader Loader; + static MF_Unloader Unloader; + +protected: + String m_fileName; + int m_fileSize; + int m_filePos; + unsigned char *m_fileBuffer; + + // + // Group: (Con/De)structors + // +public: + + // + // Function: File + // Default file class, constructor. + // + MemoryFile (void) + { + m_fileSize = 0; + m_filePos = 0; + + m_fileBuffer = NULL; + m_fileName.Empty (); + } + + // + // Function: File + // Default file class, constructor, with file opening. + // + MemoryFile (const String &fileName) + { + m_fileSize = 0; + m_filePos = 0; + + m_fileBuffer = NULL; + m_fileName.Empty (); + + Open (fileName); + } + + // + // Function: ~File + // Default file class, destructor. + // + ~MemoryFile (void) + { + Close (); + } + + // + // Function: Open + // Opens file and gets it's size. + // + // Parameters: + // fileName - String containing file name. + // + // Returns: + // True if operation succeeded, false otherwise. + // + bool Open (const String &fileName) + { + if (fileName.IsEmpty () || Loader == NULL) + return false; + + m_fileSize = 0; + m_filePos = 0; + m_fileName = fileName; + + m_fileBuffer = Loader (fileName.GetBuffer (), &m_fileSize); + + if (m_fileBuffer == NULL || m_fileSize < 0) + return false; + + return true; + } + + // + // Function: Close + // Closes file, and destroys STDIO file object. + // + void Close (void) + { + if (Unloader != NULL) + Unloader (m_fileBuffer); + + m_fileSize = 0; + m_filePos = 0; + + m_fileBuffer = NULL; + m_fileName.Empty (); + } + + // + // Function: GetChar + // Pops one character from the file stream. + // + // Returns: + // Popped from stream character + // + int GetChar (void) + { + if (m_fileBuffer == NULL || m_filePos >= m_fileSize) + return -1; + + int readCh = m_fileBuffer[m_filePos]; + m_filePos++; + + return readCh; + } + + // + // Function: GetBuffer + // Gets the single line, from the non-binary stream. + // + // Parameters: + // buffer - Pointer to buffer, that should receive string. + // count - Max. size of buffer. + // + // Returns: + // Pointer to string containing popped line. + // + char *GetBuffer (char *buffer, int count) + { + if (m_fileBuffer == NULL || m_filePos >= m_fileSize) + return NULL; + + int lineStartOffset = m_filePos; + int lineEndOffset = (m_fileSize - m_filePos > count - 1) ? (lineEndOffset = m_filePos + count - 1) : lineEndOffset = m_fileSize - 1; + + while (m_filePos < lineEndOffset) + { + if (m_fileBuffer[m_filePos] == 0x0a) + lineEndOffset = m_filePos; + + m_filePos++; + } + + if (m_filePos == lineStartOffset) + return NULL; + + int pos = lineStartOffset; + + for (; pos <= lineEndOffset; pos++) + buffer[pos - lineStartOffset] = m_fileBuffer[pos]; + + if (buffer[pos - lineStartOffset - 2] == 0x0d) + { + buffer[pos - lineStartOffset - 2] = '\n'; + pos--; + } + + if (buffer[pos - lineStartOffset - 1] == 0x0d || buffer[pos - lineStartOffset - 1] == 0x0a) + buffer[pos - lineStartOffset - 1] = '\n'; + + buffer[pos - lineStartOffset] = 0; + + return buffer; + } + + // + // Function: GetBuffer + // Gets the line from file stream, and stores it inside string class. + // + // Parameters: + // buffer - String buffer, that should receive line. + // count - Max. size of buffer. + // + // Returns: + // True if operation succeeded, false otherwise. + // + bool GetBuffer (String &buffer, int count) + { + return !String (GetBuffer (buffer, count)).IsEmpty (); + } + + // + // Function: Read + // Reads buffer from file stream in binary format. + // + // Parameters: + // buffer - Holder for read buffer. + // size - Size of the buffer to read. + // count - Number of buffer chunks to read. + // + // Returns: + // Number of bytes red from file. + // + int Read (void *buffer, int size, int count = 1) + { + if (m_fileBuffer == NULL || m_filePos >= m_fileSize) + return 0; + + if (buffer == NULL || size == 0 || count == 0 || m_fileBuffer == NULL) + return 0; + + int blocksRead = min ((m_fileSize - m_filePos) / size, count); + + memcpy (buffer, &m_fileBuffer[m_filePos], blocksRead * size); + m_filePos += blocksRead * size; + + return blocksRead; + } + + // + // Function: Seek + // Seeks file stream with specified parameters. + // + // Parameters: + // offset - Offset where cursor should be set. + // origin - Type of offset set. + // + // Returns: + // True if operation success, false otherwise. + // + bool Seek (long offset, int origin) + { + if (m_fileBuffer == NULL || m_filePos >= m_fileSize) + return false; + + if (origin == SEEK_SET) + { + if (offset >= m_fileSize) + return false; + + m_filePos = offset; + } + else if (origin == SEEK_END) + { + if (offset >= m_fileSize) + return false; + + m_filePos = m_fileSize - offset; + } + else + { + if (m_filePos + offset >= m_fileSize) + return false; + + m_filePos += offset; + } + return true; + } + + // + // Function: GetSize + // Gets the file size of opened file stream. + // + // Returns: + // Number of bytes in file. + // + int GetSize (void) + { + return m_fileSize; + } + + // + // Function: IsValid + // Checks whether file stream is valid. + // + // Returns: + // True if file stream valid, false otherwise. + // + bool IsValid (void) + { + return m_fileBuffer != NULL && m_fileSize > 0; + } +}; + // // Type: StrVec // Array of strings. diff --git a/source/basecode.cpp b/source/basecode.cpp index 1a3cca1..6a5e15e 100644 --- a/source/basecode.cpp +++ b/source/basecode.cpp @@ -4457,17 +4457,17 @@ void Bot::RunTask_PickupItem () if (id < 7) { // secondary weapon. i.e., pistol - int weaponID = 0; + int wid = 0; for (id = 0; id < 7; id++) { if (pev->weapons & (1 << g_weaponSelect[id].id)) - weaponID = id; + wid = id; } - if (weaponID > 0) + if (wid > 0) { - SelectWeaponbyNumber (weaponID); + SelectWeaponbyNumber (wid); engine.IssueBotCommand (GetEntity (), "drop"); if (HasShield ()) // If we have the shield... @@ -4478,11 +4478,11 @@ void Bot::RunTask_PickupItem () else { // primary weapon - int weaponID = GetHighestWeapon (); + int wid = GetHighestWeapon (); - if ((weaponID > 6) || HasShield ()) + if (wid > 6 || HasShield ()) { - SelectWeaponbyNumber (weaponID); + SelectWeaponbyNumber (wid); engine.IssueBotCommand (GetEntity (), "drop"); } EquipInBuyzone (BUYSTATE_PRIMARY_WEAPON); @@ -4502,11 +4502,11 @@ void Bot::RunTask_PickupItem () else if (itemDistance < 50.0f) // near to shield? { // get current best weapon to check if it's a primary in need to be dropped - int weaponID = GetHighestWeapon (); + int wid = GetHighestWeapon (); - if (weaponID > 6) + if (wid > 6) { - SelectWeaponbyNumber (weaponID); + SelectWeaponbyNumber (wid); engine.IssueBotCommand (GetEntity (), "drop"); } } @@ -5117,12 +5117,12 @@ void Bot::DisplayDebugOverlay (void) else strcpy (pickupName, " (null)"); - WeaponSelect *selectTab = &g_weaponSelect[0]; + WeaponSelect *tab = &g_weaponSelect[0]; char weaponCount = 0; - while (m_currentWeapon != selectTab->id && weaponCount < NUM_WEAPONS) + while (m_currentWeapon != tab->id && weaponCount < NUM_WEAPONS) { - selectTab++; + tab++; weaponCount++; } memset (aimFlags, 0, sizeof (aimFlags)); @@ -5169,7 +5169,7 @@ void Bot::DisplayDebugOverlay (void) } } else - strncpy (weaponName, selectTab->weaponName, SIZEOF_CHAR (weaponName)); + strncpy (weaponName, tab->weaponName, SIZEOF_CHAR (weaponName)); char outputBuffer[512]; memset (outputBuffer, 0, sizeof (outputBuffer)); @@ -5326,8 +5326,7 @@ void Bot::TakeDamage (edict_t *inflictor, int damage, int armor, int bits) void Bot::TakeBlinded (const Vector &fade, int alpha) { // this function gets called by network message handler, when screenfade message get's send - // it's used to make bot blind froumd the grenade. - + // it's used to make bot blind from the grenade. if (fade.x != 255.0f || fade.y != 255.0f || fade.z != 255.0f || alpha <= 170.0f) return; @@ -5342,29 +5341,29 @@ void Bot::TakeBlinded (const Vector &fade, int alpha) m_blindMoveSpeed = 0.0f; m_blindSidemoveSpeed = 0.0f; m_blindButton = IN_DUCK; + + return; } - else if (m_difficulty > 2) + + m_blindMoveSpeed = -pev->maxspeed; + m_blindSidemoveSpeed = 0.0f; + + float walkSpeed = GetWalkSpeed (); + + if (Random.Long (0, 100) > 50) + m_blindSidemoveSpeed = walkSpeed; + else + m_blindSidemoveSpeed = -walkSpeed; + + if (pev->health < 85.0f) + m_blindMoveSpeed = -walkSpeed; + else if (m_personality == PERSONALITY_CAREFUL) { - m_blindMoveSpeed = -pev->maxspeed; - m_blindSidemoveSpeed = 0.0f; - - float walkSpeed = GetWalkSpeed (); - - if (Random.Long (0, 100) > 50) - m_blindSidemoveSpeed = walkSpeed; - else - m_blindSidemoveSpeed = -walkSpeed; - - if (pev->health < 85.0f) - m_blindMoveSpeed = -walkSpeed; - else if (m_personality == PERSONALITY_CAREFUL) - { - m_blindMoveSpeed = 0.0f; - m_blindButton = IN_DUCK; - } - else - m_blindMoveSpeed = walkSpeed; + m_blindMoveSpeed = 0.0f; + m_blindButton = IN_DUCK; } + else + m_blindMoveSpeed = walkSpeed; } void Bot::CollectGoalExperience (int damage, int team) diff --git a/source/combat.cpp b/source/combat.cpp index 5547c3a..c1ee1ed 100644 --- a/source/combat.cpp +++ b/source/combat.cpp @@ -735,13 +735,13 @@ void Bot::FireWeapon (void) { if (IsFriendInLineOfFire (distance)) { - m_fightStyle = 0; + m_fightStyle = FIGHT_STRAFE; m_lastFightStyleCheck = engine.Time (); return; } } - WeaponSelect *selectTab = &g_weaponSelect[0]; + WeaponSelect *tab = &g_weaponSelect[0]; edict_t *enemy = m_enemy; @@ -757,18 +757,18 @@ void Bot::FireWeapon (void) goto WeaponSelectEnd; // loop through all the weapons until terminator is found... - while (selectTab[selectIndex].id) + while (tab[selectIndex].id) { // is the bot carrying this weapon? - if (weapons & (1 << selectTab[selectIndex].id)) + if (weapons & (1 << tab[selectIndex].id)) { // is enough ammo available to fire AND check is better to use pistol in our current situation... - if (m_ammoInClip[selectTab[selectIndex].id] > 0 && !IsWeaponBadInDistance (selectIndex, distance)) + if (m_ammoInClip[tab[selectIndex].id] > 0 && !IsWeaponBadInDistance (selectIndex, distance)) chosenWeaponIndex = selectIndex; } selectIndex++; } - selectId = selectTab[chosenWeaponIndex].id; + selectId = tab[chosenWeaponIndex].id; // if no available weapon... if (chosenWeaponIndex == 0) @@ -776,14 +776,14 @@ void Bot::FireWeapon (void) selectIndex = 0; // loop through all the weapons until terminator is found... - while (selectTab[selectIndex].id) + while (tab[selectIndex].id) { - int id = selectTab[selectIndex].id; + int id = tab[selectIndex].id; // is the bot carrying this weapon? if (weapons & (1 << id)) { - if ( g_weaponDefs[id].ammo1 != -1 && g_weaponDefs[id].ammo1 < 32 && m_ammo[g_weaponDefs[id].ammo1] >= selectTab[selectIndex].minPrimaryAmmo) + if ( g_weaponDefs[id].ammo1 != -1 && g_weaponDefs[id].ammo1 < 32 && m_ammo[g_weaponDefs[id].ammo1] >= tab[selectIndex].minPrimaryAmmo) { // available ammo found, reload weapon if (m_reloadState == RELOAD_NONE || m_reloadCheckTime > engine.Time ()) @@ -823,14 +823,14 @@ WeaponSelectEnd: return; } - if (selectTab[chosenWeaponIndex].id != selectId) + if (tab[chosenWeaponIndex].id != selectId) { chosenWeaponIndex = 0; // loop through all the weapons until terminator is found... - while (selectTab[chosenWeaponIndex].id) + while (tab[chosenWeaponIndex].id) { - if (selectTab[chosenWeaponIndex].id == selectId) + if (tab[chosenWeaponIndex].id == selectId) break; chosenWeaponIndex++; @@ -896,7 +896,7 @@ WeaponSelectEnd: } else { - if (selectTab[chosenWeaponIndex].primaryFireHold && m_ammo[g_weaponDefs[selectTab[selectIndex].id].ammo1] > selectTab[selectIndex].minPrimaryAmmo) // if automatic weapon, just press attack + if (tab[chosenWeaponIndex].primaryFireHold && m_ammo[g_weaponDefs[tab[selectIndex].id].ammo1] > tab[selectIndex].minPrimaryAmmo) // if automatic weapon, just press attack pev->button |= IN_ATTACK; else // if not, toggle buttons { @@ -918,7 +918,7 @@ WeaponSelectEnd: return; } - if (selectTab[chosenWeaponIndex].primaryFireHold) + if (tab[chosenWeaponIndex].primaryFireHold) { m_shootTime = engine.Time (); m_zoomCheckTime = engine.Time (); @@ -943,9 +943,9 @@ bool Bot::IsWeaponBadInDistance (int weaponIndex, float distance) if (m_difficulty < 2) return false; - int weaponID = g_weaponSelect[weaponIndex].id; + int wid = g_weaponSelect[weaponIndex].id; - if (weaponID == WEAPON_KNIFE) + if (wid == WEAPON_KNIFE) return false; // check is ammo available for secondary weapon @@ -953,11 +953,11 @@ bool Bot::IsWeaponBadInDistance (int weaponIndex, float distance) return false; // better use pistol in short range distances, when using sniper weapons - if ((weaponID == WEAPON_SCOUT || weaponID == WEAPON_AWP || weaponID == WEAPON_G3SG1 || weaponID == WEAPON_SG550) && distance < 500.0f) + if ((wid == WEAPON_SCOUT || wid == WEAPON_AWP || wid == WEAPON_G3SG1 || wid == WEAPON_SG550) && distance < 500.0f) return true; // shotguns is too inaccurate at long distances, so weapon is bad - if ((weaponID == WEAPON_M3 || weaponID == WEAPON_XM1014) && distance > 750.0f) + if ((wid == WEAPON_M3 || wid == WEAPON_XM1014) && distance > 750.0f) return true; return false; @@ -1055,7 +1055,7 @@ void Bot::CombatFight (void) if (UsesSniper ()) { - m_fightStyle = 1; + m_fightStyle = FIGHT_STAY; m_lastFightStyleCheck = engine.Time (); } else if (UsesRifle () || UsesSubmachineGun ()) @@ -1065,20 +1065,20 @@ void Bot::CombatFight (void) int rand = Random.Long (1, 100); if (distance < 450.0f) - m_fightStyle = 0; + m_fightStyle = FIGHT_STRAFE; else if (distance < 1024.0f) { if (rand < (UsesSubmachineGun () ? 50 : 30)) - m_fightStyle = 0; + m_fightStyle = FIGHT_STRAFE; else - m_fightStyle = 1; + m_fightStyle = FIGHT_STAY; } else { if (rand < (UsesSubmachineGun () ? 80 : 93)) - m_fightStyle = 1; + m_fightStyle = FIGHT_STAY; else - m_fightStyle = 0; + m_fightStyle = FIGHT_STRAFE; } m_lastFightStyleCheck = engine.Time (); } @@ -1088,15 +1088,15 @@ void Bot::CombatFight (void) if (m_lastFightStyleCheck + 3.0f < engine.Time ()) { if (Random.Long (0, 100) < 50) - m_fightStyle = 1; + m_fightStyle = FIGHT_STRAFE; else - m_fightStyle = 0; + m_fightStyle = FIGHT_STAY; m_lastFightStyleCheck = engine.Time (); } } - if (m_fightStyle == 0 || ((pev->button & IN_RELOAD) || m_isReloading) || (UsesPistol () && distance < 400.0f) || m_currentWeapon == WEAPON_KNIFE) + if (m_fightStyle == FIGHT_STRAFE || ((pev->button & IN_RELOAD) || m_isReloading) || (UsesPistol () && distance < 400.0f) || m_currentWeapon == WEAPON_KNIFE) { if (m_strafeSetTime < engine.Time ()) { @@ -1107,24 +1107,24 @@ void Bot::CombatFight (void) const Vector &rightSide = g_pGlobals->v_right.Normalize2D (); if ((dirToPoint | rightSide) < 0) - m_combatStrafeDir = 1; + m_combatStrafeDir = STRAFE_DIR_LEFT; else - m_combatStrafeDir = 0; + m_combatStrafeDir = STRAFE_DIR_RIGHT; if (Random.Long (1, 100) < 30) - m_combatStrafeDir ^= 1; + m_combatStrafeDir == STRAFE_DIR_LEFT ? STRAFE_DIR_RIGHT : STRAFE_DIR_LEFT; - m_strafeSetTime = engine.Time () + Random.Float (0.5f, 3.0f); + m_strafeSetTime = engine.Time () + Random.Float (1.5f, 3.0f); } - if (m_combatStrafeDir == 0) + if (m_combatStrafeDir == STRAFE_DIR_LEFT) { if (!CheckWallOnLeft ()) m_strafeSpeed = -pev->maxspeed; else { - m_combatStrafeDir ^= 1; - m_strafeSetTime = engine.Time () + 1.0f; + m_combatStrafeDir == STRAFE_DIR_LEFT ? STRAFE_DIR_RIGHT : STRAFE_DIR_LEFT; + m_strafeSetTime = engine.Time () + 1.5f; } } else @@ -1133,8 +1133,8 @@ void Bot::CombatFight (void) m_strafeSpeed = pev->maxspeed; else { - m_combatStrafeDir ^= 1; - m_strafeSetTime = engine.Time () + 1.0f; + m_combatStrafeDir == STRAFE_DIR_LEFT ? STRAFE_DIR_RIGHT : STRAFE_DIR_LEFT; + m_strafeSetTime = engine.Time () + 1.5f; } } @@ -1147,9 +1147,9 @@ void Bot::CombatFight (void) if (m_currentWeapon == WEAPON_KNIFE) m_strafeSpeed = 0.0f; } - else if (m_fightStyle == 1) + else if (m_fightStyle == FIGHT_STAY) { - if (!(m_visibility & (VISIBLE_HEAD | VISIBLE_BODY)) && GetTaskId () != TASK_SEEKCOVER && GetTaskId () != TASK_HUNTENEMY && (m_visibility & VISIBLE_BODY) && !(m_visibility & VISIBLE_OTHER) && waypoints.IsDuckVisible (m_currentWaypointIndex, waypoints.FindNearest (m_enemy->v.origin))) + if ((m_visibility & (VISIBLE_HEAD | VISIBLE_BODY)) && GetTaskId () != TASK_SEEKCOVER && GetTaskId () != TASK_HUNTENEMY && waypoints.IsDuckVisible (m_currentWaypointIndex, waypoints.FindNearest (m_enemy->v.origin))) m_duckTime = engine.Time () + 0.5f; m_moveSpeed = 0.0f; @@ -1244,19 +1244,19 @@ bool Bot::UsesSniper (void) bool Bot::UsesRifle (void) { - WeaponSelect *selectTab = &g_weaponSelect[0]; + WeaponSelect *tab = &g_weaponSelect[0]; int count = 0; - while (selectTab->id) + while (tab->id) { - if (m_currentWeapon == selectTab->id) + if (m_currentWeapon == tab->id) break; - selectTab++; + tab++; count++; } - if (selectTab->id && count > 13) + if (tab->id && count > 13) return true; return false; @@ -1264,20 +1264,20 @@ bool Bot::UsesRifle (void) bool Bot::UsesPistol (void) { - WeaponSelect *selectTab = &g_weaponSelect[0]; + WeaponSelect *tab = &g_weaponSelect[0]; int count = 0; // loop through all the weapons until terminator is found - while (selectTab->id) + while (tab->id) { - if (m_currentWeapon == selectTab->id) + if (m_currentWeapon == tab->id) break; - selectTab++; + tab++; count++; } - if (selectTab->id && count < 7) + if (tab->id && count < 7) return true; return false; @@ -1330,30 +1330,30 @@ void Bot::SelectBestWeapon (void) if (m_isReloading) return; - WeaponSelect *selectTab = &g_weaponSelect[0]; + WeaponSelect *tab = &g_weaponSelect[0]; int selectIndex = 0; int chosenWeaponIndex = 0; // loop through all the weapons until terminator is found... - while (selectTab[selectIndex].id) + while (tab[selectIndex].id) { // is the bot NOT carrying this weapon? - if (!(pev->weapons & (1 << selectTab[selectIndex].id))) + if (!(pev->weapons & (1 << tab[selectIndex].id))) { selectIndex++; // skip to next weapon continue; } - int id = selectTab[selectIndex].id; + int id = tab[selectIndex].id; bool ammoLeft = false; // is the bot already holding this weapon and there is still ammo in clip? - if (selectTab[selectIndex].id == m_currentWeapon && (GetAmmoInClip () < 0 || GetAmmoInClip () >= selectTab[selectIndex].minPrimaryAmmo)) + if (tab[selectIndex].id == m_currentWeapon && (GetAmmoInClip () < 0 || GetAmmoInClip () >= tab[selectIndex].minPrimaryAmmo)) ammoLeft = true; // is no ammo required for this weapon OR enough ammo available to fire - if (g_weaponDefs[id].ammo1 < 0 || (g_weaponDefs[id].ammo1 < 32 && m_ammo[g_weaponDefs[id].ammo1] >= selectTab[selectIndex].minPrimaryAmmo)) + if (g_weaponDefs[id].ammo1 < 0 || (g_weaponDefs[id].ammo1 < 32 && m_ammo[g_weaponDefs[id].ammo1] >= tab[selectIndex].minPrimaryAmmo)) ammoLeft = true; if (ammoLeft) @@ -1365,11 +1365,11 @@ void Bot::SelectBestWeapon (void) chosenWeaponIndex %= NUM_WEAPONS + 1; selectIndex = chosenWeaponIndex; - int id = selectTab[selectIndex].id; + int id = tab[selectIndex].id; // select this weapon if it isn't already selected if (m_currentWeapon != id) - SelectWeaponByName (selectTab[selectIndex].weaponName); + SelectWeaponByName (tab[selectIndex].weaponName); m_isReloading = false; m_reloadState = RELOAD_NONE; @@ -1387,21 +1387,21 @@ void Bot::SelectPistol (void) int Bot::GetHighestWeapon (void) { - WeaponSelect *selectTab = &g_weaponSelect[0]; + WeaponSelect *tab = &g_weaponSelect[0]; int weapons = pev->weapons; int num = 0; int i = 0; // loop through all the weapons until terminator is found... - while (selectTab->id) + while (tab->id) { // is the bot carrying this weapon? - if (weapons & (1 << selectTab->id)) + if (weapons & (1 << tab->id)) num = i; i++; - selectTab++; + tab++; } return num; } diff --git a/source/interface.cpp b/source/interface.cpp index 425450f..38fd6a8 100644 --- a/source/interface.cpp +++ b/source/interface.cpp @@ -479,9 +479,19 @@ void ParseVoiceEvent (const String &base, int type, float timeToRepeat) temp.RemoveAll (); } +// forwards for MemoryFile +MemoryFile::MF_Loader MemoryFile::Loader = NULL; +MemoryFile::MF_Unloader MemoryFile::Unloader = NULL; + void InitConfig (void) { - File fp; + // assign engine loaders to memoryfile handler + if (MemoryFile::Loader == NULL || MemoryFile::Unloader == NULL) + { + MemoryFile::Loader = reinterpret_cast (g_engfuncs.pfnLoadFileForMe); + MemoryFile::Unloader = reinterpret_cast (g_engfuncs.pfnFreeFile); + } + MemoryFile fp; char line[512]; KeywordFactory replyKey; @@ -2994,6 +3004,15 @@ DLL_GIVEFNPTRSTODLL GiveFnptrsToDll (enginefuncs_t *functionTable, globalvars_t // register our cvars ConVarWrapper::GetReference ().PushRegisteredConVarsToEngine (); + // ensure we're have all needed directories + { + const char *mod = engine.GetModName (); + + // create the needed paths + File::CreatePath (const_cast (FormatBuffer ("%s/addons/yapb/conf/lang", mod))); + File::CreatePath (const_cast (FormatBuffer ("%s/addons/yapb/data/learned", mod))); + } + #ifdef PLATFORM_ANDROID g_gameFlags |= (GAME_LEGACY | GAME_XASH | GAME_MOBILITY); @@ -3001,13 +3020,13 @@ DLL_GIVEFNPTRSTODLL GiveFnptrsToDll (enginefuncs_t *functionTable, globalvars_t return; // we should stop the attempt for loading the real gamedll, since metamod handle this for us #ifdef LOAD_HARDFP - #define GAME_SERVER_DLL "libserver_hardfp.so" + const char *serverDLL = "libserver_hardfp.so"; #else - #define GAME_SERVER_DLL "libserver.so" + const char *serverDLL = "libserver.so"; #endif char gameDLLName[256]; - snprintf (gameDLLName, SIZEOF_CHAR (gameDLLName), "%s/%s", getenv ("XASH3D_GAMELIBDIR"), GAME_SERVER_DLL); + snprintf (gameDLLName, SIZEOF_CHAR (gameDLLName), "%s/%s", getenv ("XASH3D_GAMELIBDIR"), serverDLL); g_gameLib = new Library (gameDLLName); diff --git a/source/manager.cpp b/source/manager.cpp index 6e916d2..32e713c 100644 --- a/source/manager.cpp +++ b/source/manager.cpp @@ -1204,8 +1204,8 @@ void Bot::NewRound (void) m_shieldCheckTime = 0.0f; m_zoomCheckTime = 0.0f; m_strafeSetTime = 0.0f; - m_combatStrafeDir = 0; - m_fightStyle = 0; + m_combatStrafeDir = STRAFE_DIR_NONE; + m_fightStyle = FIGHT_NONE; m_lastFightStyleCheck = 0.0f; m_checkWeaponSwitch = true; diff --git a/source/support.cpp b/source/support.cpp index d3acd20..51d7a04 100644 --- a/source/support.cpp +++ b/source/support.cpp @@ -452,7 +452,7 @@ bool IsValidBot (edict_t *ent) return false; } -bool OpenConfig (const char *fileName, const char *errorIfNotExists, File *outFile, bool languageDependant /*= false*/) +bool OpenConfig (const char *fileName, const char *errorIfNotExists, MemoryFile *outFile, bool languageDependant /*= false*/) { if (outFile->IsValid ()) outFile->Close (); @@ -469,12 +469,12 @@ bool OpenConfig (const char *fileName, const char *errorIfNotExists, File *outFi // check is file is exists for this language if (File::Accessible (languageDependantConfigFile)) - outFile->Open (languageDependantConfigFile, "rt"); + outFile->Open (languageDependantConfigFile); else - outFile->Open (FormatBuffer ("%s/addons/yapb/conf/lang/en_%s", mod, fileName), "rt"); + outFile->Open (FormatBuffer ("%s/addons/yapb/conf/lang/en_%s", mod, fileName)); } else - outFile->Open (FormatBuffer ("%s/addons/yapb/conf/%s", engine.GetModName (), fileName), "rt"); + outFile->Open (FormatBuffer ("%s/addons/yapb/conf/%s", engine.GetModName (), fileName)); if (!outFile->IsValid ()) { diff --git a/source/waypoint.cpp b/source/waypoint.cpp index 7469038..4044763 100644 --- a/source/waypoint.cpp +++ b/source/waypoint.cpp @@ -1052,7 +1052,7 @@ void Waypoint::InitTypes (void) bool Waypoint::Load (void) { - File fp (CheckSubfolderFile (), "rb"); + MemoryFile fp (CheckSubfolderFile ()); WaypointHeader header; memset (&header, 0, sizeof (header));