Changeset 272 for trunk/src/bindings/scripts/ScriptMgr.cpp
- Timestamp:
- 11/22/08 00:35:41 (17 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bindings/scripts/ScriptMgr.cpp
r260 r272 18 18 19 19 //*** Global data *** 20 int num_db_scripts; 21 int num_sc_scripts; 20 int nrscripts; 22 21 Script *m_scripts[MAX_SCRIPTS]; 23 22 … … 48 47 // Text Maps 49 48 UNORDERED_MAP<int32, StringTextData> TextMap; 49 50 50 51 51 //*** End Global data *** … … 1181 1181 TRINITY_DLL_EXPORT 1182 1182 void ScriptsFree() 1183 { 1183 { 1184 1184 // Free Spell Summary 1185 1185 delete []SpellSummary; 1186 1186 1187 1187 // Free resources before library unload 1188 for(int i=0;i<n um_db_scripts;i++)1188 for(int i=0;i<nrscripts;i++) 1189 1189 delete m_scripts[i]; 1190 1190 1191 num_db_scripts = 0; 1192 num_sc_scripts = 0; 1191 nrscripts = 0; 1193 1192 } 1194 1193 … … 1241 1240 LoadDatabase(); 1242 1241 1243 num_db_scripts = GetScriptNames().size();1244 1245 1242 outstring_log("TSCR: Loading C++ scripts"); 1246 1243 barGoLink bar(1); … … 1248 1245 outstring_log(""); 1249 1246 1247 nrscripts = 0; 1250 1248 for(int i=0;i<MAX_SCRIPTS;i++) 1251 1249 m_scripts[i]=NULL; … … 1778 1776 // ------------------- 1779 1777 1780 outstring_log(">> Loaded %i C++ Scripts (of %i ScriptNames defined in Mangos database)", num_sc_scripts, num_db_scripts); 1778 outstring_log("TSCR: Loaded %u C++ Scripts", nrscripts); 1779 outstring_log(""); 1781 1780 } 1782 1781 … … 1850 1849 //*** Functions used internally *** 1851 1850 1852 void Script::RegisterSelf() 1853 { 1854 int id = GetScriptId(Name.c_str()); 1855 if (id != 0) 1856 { 1857 m_scripts[id] = this; 1858 ++num_sc_scripts; 1859 } else 1860 debug_log("SD2: RegisterSelf, but script named %s does not have ScriptName assigned in database.",(this)->Name.c_str()); 1851 TRINITY_DLL_EXPORT 1852 char const* ScriptsVersion() 1853 { 1854 return "Default Trinity scripting library"; 1855 } 1856 1857 Script* GetScriptByName(std::string Name) 1858 { 1859 if (Name.empty()) 1860 return NULL; 1861 1862 for(int i=0;i<MAX_SCRIPTS;i++) 1863 { 1864 if (m_scripts[i] && m_scripts[i]->Name == Name) 1865 return m_scripts[i]; 1866 } 1867 return NULL; 1861 1868 } 1862 1869 … … 1865 1872 1866 1873 TRINITY_DLL_EXPORT 1867 char const* ScriptsVersion()1868 {1869 return "Default Trinity scripting library";1870 }1871 TRINITY_DLL_EXPORT1872 1874 bool GossipHello ( Player * player, Creature *_Creature ) 1873 1875 { 1874 Script *tmpscript = m_scripts[_Creature->GetScriptId()];1876 Script *tmpscript = GetScriptByName(_Creature->GetScriptName()); 1875 1877 if (!tmpscript || !tmpscript->pGossipHello) return false; 1876 1878 … … 1884 1886 debug_log("TSCR: Gossip selection, sender: %d, action: %d",sender, action); 1885 1887 1886 Script *tmpscript = m_scripts[_Creature->GetScriptId()];1888 Script *tmpscript = GetScriptByName(_Creature->GetScriptName()); 1887 1889 if (!tmpscript || !tmpscript->pGossipSelect) return false; 1888 1890 … … 1896 1898 debug_log("TSCR: Gossip selection with code, sender: %d, action: %d",sender, action); 1897 1899 1898 Script *tmpscript = m_scripts[_Creature->GetScriptId()];1900 Script *tmpscript = GetScriptByName(_Creature->GetScriptName()); 1899 1901 if (!tmpscript || !tmpscript->pGossipSelectWithCode) return false; 1900 1902 … … 1906 1908 bool QuestAccept( Player *player, Creature *_Creature, Quest const *_Quest ) 1907 1909 { 1908 Script *tmpscript = m_scripts[_Creature->GetScriptId()];1910 Script *tmpscript = GetScriptByName(_Creature->GetScriptName()); 1909 1911 if (!tmpscript || !tmpscript->pQuestAccept) return false; 1910 1912 … … 1916 1918 bool QuestSelect( Player *player, Creature *_Creature, Quest const *_Quest ) 1917 1919 { 1918 Script *tmpscript = m_scripts[_Creature->GetScriptId()];1920 Script *tmpscript = GetScriptByName(_Creature->GetScriptName()); 1919 1921 if (!tmpscript || !tmpscript->pQuestSelect) return false; 1920 1922 … … 1926 1928 bool QuestComplete( Player *player, Creature *_Creature, Quest const *_Quest ) 1927 1929 { 1928 Script *tmpscript = m_scripts[_Creature->GetScriptId()];1930 Script *tmpscript = GetScriptByName(_Creature->GetScriptName()); 1929 1931 if (!tmpscript || !tmpscript->pQuestComplete) return false; 1930 1932 … … 1936 1938 bool ChooseReward( Player *player, Creature *_Creature, Quest const *_Quest, uint32 opt ) 1937 1939 { 1938 Script *tmpscript = m_scripts[_Creature->GetScriptId()];1940 Script *tmpscript = GetScriptByName(_Creature->GetScriptName()); 1939 1941 if (!tmpscript || !tmpscript->pChooseReward) return false; 1940 1942 … … 1946 1948 uint32 NPCDialogStatus( Player *player, Creature *_Creature ) 1947 1949 { 1948 Script *tmpscript = m_scripts[_Creature->GetScriptId()];1950 Script *tmpscript = GetScriptByName(_Creature->GetScriptName()); 1949 1951 if (!tmpscript || !tmpscript->pNPCDialogStatus) return 100; 1950 1952 … … 1956 1958 uint32 GODialogStatus( Player *player, GameObject *_GO ) 1957 1959 { 1958 Script *tmpscript = m_scripts[_GO->GetGOInfo()->ScriptId];1959 if 1960 Script *tmpscript = GetScriptByName(_GO->GetGOInfo()->ScriptName); 1961 if(!tmpscript || !tmpscript->pGODialogStatus) return 100; 1960 1962 1961 1963 player->PlayerTalkClass->ClearMenus(); … … 1966 1968 bool ItemHello( Player *player, Item *_Item, Quest const *_Quest ) 1967 1969 { 1968 Script *tmpscript = m_scripts[_Item->GetProto()->ScriptId];1970 Script *tmpscript = GetScriptByName(_Item->GetProto()->ScriptName); 1969 1971 if (!tmpscript || !tmpscript->pItemHello) return false; 1970 1972 … … 1976 1978 bool ItemQuestAccept( Player *player, Item *_Item, Quest const *_Quest ) 1977 1979 { 1978 Script *tmpscript = m_scripts[_Item->GetProto()->ScriptId];1980 Script *tmpscript = GetScriptByName(_Item->GetProto()->ScriptName); 1979 1981 if (!tmpscript || !tmpscript->pItemQuestAccept) return false; 1980 1982 … … 1986 1988 bool GOHello( Player *player, GameObject *_GO ) 1987 1989 { 1988 Script *tmpscript = m_scripts[_GO->GetGOInfo()->ScriptId];1990 Script *tmpscript = GetScriptByName(_GO->GetGOInfo()->ScriptName); 1989 1991 if (!tmpscript || !tmpscript->pGOHello) return false; 1990 1992 … … 1996 1998 bool GOQuestAccept( Player *player, GameObject *_GO, Quest const *_Quest ) 1997 1999 { 1998 Script *tmpscript = m_scripts[_GO->GetGOInfo()->ScriptId];2000 Script *tmpscript = GetScriptByName(_GO->GetGOInfo()->ScriptName); 1999 2001 if (!tmpscript || !tmpscript->pGOQuestAccept) return false; 2000 2002 … … 2006 2008 bool GOChooseReward( Player *player, GameObject *_GO, Quest const *_Quest, uint32 opt ) 2007 2009 { 2008 Script *tmpscript = m_scripts[_GO->GetGOInfo()->ScriptId];2010 Script *tmpscript = GetScriptByName(_GO->GetGOInfo()->ScriptName); 2009 2011 if (!tmpscript || !tmpscript->pGOChooseReward) return false; 2010 2012 … … 2016 2018 bool AreaTrigger( Player *player, AreaTriggerEntry * atEntry) 2017 2019 { 2018 Script *tmpscript = m_scripts[GetAreaTriggerScriptId(atEntry->id)]; 2020 Script *tmpscript = NULL; 2021 2022 tmpscript = GetScriptByName(GetAreaTriggerScriptNameById(atEntry->id)); 2019 2023 if (!tmpscript || !tmpscript->pAreaTrigger) return false; 2020 2024 … … 2025 2029 CreatureAI* GetAI(Creature *_Creature) 2026 2030 { 2027 Script *tmpscript = m_scripts[_Creature->GetScriptId()]; 2031 Script *tmpscript = GetScriptByName(_Creature->GetScriptName()); 2032 2028 2033 if (!tmpscript || !tmpscript->GetAI) return NULL; 2029 2030 2034 return tmpscript->GetAI(_Creature); 2031 2035 } … … 2034 2038 bool ItemUse( Player *player, Item* _Item, SpellCastTargets const& targets) 2035 2039 { 2036 Script *tmpscript = m_scripts[_Item->GetProto()->ScriptId];2040 Script *tmpscript = GetScriptByName(_Item->GetProto()->ScriptName); 2037 2041 if (!tmpscript || !tmpscript->pItemUse) return false; 2038 2042 … … 2043 2047 bool ReceiveEmote( Player *player, Creature *_Creature, uint32 emote ) 2044 2048 { 2045 Script *tmpscript = m_scripts[_Creature->GetScriptId()];2049 Script *tmpscript = GetScriptByName(_Creature->GetScriptName()); 2046 2050 if (!tmpscript || !tmpscript->pReceiveEmote) return false; 2047 2051 … … 2052 2056 InstanceData* CreateInstanceData(Map *map) 2053 2057 { 2054 if (!map->IsDungeon()) return NULL; 2055 2056 Script *tmpscript = m_scripts[((InstanceMap*)map)->GetScriptId()]; 2057 if (!tmpscript || !tmpscript->GetInstanceData) return NULL; 2058 Script *tmpscript = NULL; 2059 2060 if (!map->IsDungeon()) return false; 2061 2062 tmpscript = GetScriptByName(((InstanceMap*)map)->GetScript()); 2063 if (!tmpscript || !tmpscript->GetInstanceData) return false; 2058 2064 2059 2065 return tmpscript->GetInstanceData(map);