From a17450047b5635b16eb5bb7c5072da9587df81fb Mon Sep 17 00:00:00 2001 From: VladimirMangos Date: Wed, 18 Aug 2010 14:23:45 +0400 Subject: [PATCH] [10372] Implement EFLAG_RANDOM_ACTION It allow execute one random action from EventAI event actions instead each action from event actions. --- doc/EventAI.txt | 3 ++- src/game/CreatureEventAI.cpp | 31 ++++++++++++++++++++++++++++--- src/game/CreatureEventAI.h | 17 +++++++++-------- src/shared/revision_nr.h | 2 +- 4 files changed, 40 insertions(+), 13 deletions(-) diff --git a/doc/EventAI.txt b/doc/EventAI.txt index 4e8a1c26b..227e90787 100644 --- a/doc/EventAI.txt +++ b/doc/EventAI.txt @@ -832,7 +832,8 @@ Below is the list of current Event Flags that EventAI can handle. Event flags ar 4 16 EFLAG_DIFFICULTY_3 Event occurs in instance difficulty 3 (will not occur if not set) 5 32 6 64 -7 128 EFLAG_DEBUG_ONLY Prevents events from occuring on Release builds. Useful for testing new features. +7 128 EFLAG_DEBUG_ONLY Prevents events from occuring on Release builds. Useful for testing new features. +8 256 EFLAG_RANDOM_ACTION At event occur execute one random action from event actions instead all actions. NOTE: You can add the numbers in the decimal column to combine flags. diff --git a/src/game/CreatureEventAI.cpp b/src/game/CreatureEventAI.cpp index 703508a42..0a16f654a 100644 --- a/src/game/CreatureEventAI.cpp +++ b/src/game/CreatureEventAI.cpp @@ -350,10 +350,35 @@ bool CreatureEventAI::ProcessEvent(CreatureEventAIHolder& pHolder, Unit* pAction if (pHolder.Event.event_chance <= rnd % 100) return false; - //Process actions - for (uint32 j = 0; j < MAX_ACTIONS; j++) - ProcessAction(pHolder.Event.action[j], rnd, pHolder.Event.event_id, pActionInvoker); + //Process actions, normal case + if (!(pHolder.Event.event_flags & EFLAG_RANDOM_ACTION)) + { + for (uint32 j = 0; j < MAX_ACTIONS; ++j) + ProcessAction(pHolder.Event.action[j], rnd, pHolder.Event.event_id, pActionInvoker); + } + //Process actions, random case + else + { + // amount of real actions + uint32 count = 0; + for (uint32 j = 0; j < MAX_ACTIONS; j++) + if (pHolder.Event.action[j].type != ACTION_T_NONE) + ++count; + if (count) + { + // select action number from found amount + uint32 idx = urand(0,count-1); + + // find selected action, skipping not used + uint32 j = 0; + for (; idx; ++j) + if (pHolder.Event.action[j].type != ACTION_T_NONE) + --idx; + + ProcessAction(pHolder.Event.action[j], rnd, pHolder.Event.event_id, pActionInvoker); + } + } return true; } diff --git a/src/game/CreatureEventAI.h b/src/game/CreatureEventAI.h index a042f2ba3..7fe4a5642 100644 --- a/src/game/CreatureEventAI.h +++ b/src/game/CreatureEventAI.h @@ -142,14 +142,15 @@ enum Target enum EventFlags { - EFLAG_REPEATABLE = 0x01, //Event repeats - EFLAG_DIFFICULTY_0 = 0x02, //Event only occurs in instance difficulty 0 - EFLAG_DIFFICULTY_1 = 0x04, //Event only occurs in instance difficulty 1 - EFLAG_DIFFICULTY_2 = 0x08, //Event only occurs in instance difficulty 2 - EFLAG_DIFFICULTY_3 = 0x10, //Event only occurs in instance difficulty 3 - EFLAG_RESERVED_5 = 0x20, - EFLAG_RESERVED_6 = 0x40, - EFLAG_DEBUG_ONLY = 0x80, //Event only occurs in debug build + EFLAG_REPEATABLE = 0x0001, //Event repeats + EFLAG_DIFFICULTY_0 = 0x0002, //Event only occurs in instance difficulty 0 + EFLAG_DIFFICULTY_1 = 0x0004, //Event only occurs in instance difficulty 1 + EFLAG_DIFFICULTY_2 = 0x0008, //Event only occurs in instance difficulty 2 + EFLAG_DIFFICULTY_3 = 0x0010, //Event only occurs in instance difficulty 3 + EFLAG_RESERVED_5 = 0x0020, + EFLAG_RESERVED_6 = 0x0040, + EFLAG_DEBUG_ONLY = 0x0080, //Event only occurs in debug build + EFLAG_RANDOM_ACTION = 0x0100, //Event only execute one from existed actions instead each action. EFLAG_DIFFICULTY_ALL = (EFLAG_DIFFICULTY_0|EFLAG_DIFFICULTY_1|EFLAG_DIFFICULTY_2|EFLAG_DIFFICULTY_3) }; diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 471a5b415..97b43de0e 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "10371" + #define REVISION_NR "10372" #endif // __REVISION_NR_H__