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