Commit 75038aeb authored by Fluorohydride's avatar Fluorohydride

merge master

parents 1e042601 b490235a
Ygopro script engine.
#Ygopro script engine.
##Introduction
The core logic and lua script processor of YGOPro. this library can be made external of the project and used to power server technologies. It mantains a state engine that is manipulated by Lua scripts using manipulation functions it exposes.
##Compiling
###1.) Download Fluorohydride/ygopro
Start by downloading the most parent of the source code. The team developing this project are the defacto edge and experts in our community. The most upto date `ocgcore` is a compiled dll version of the `Fluorohydride/ygopro/ocgcore` folders project.
###2.) Install Premake4 and Visual Studio 2010 (or later).
Download premake4.exe, put it in `c:\windows` or a similar folder that is globally accessiable via `cmd` or PowerShell. Install Visual Studio 2010, it is the system used for the guide because other parts of the project use C# and most the development team are Windows users.
###3.) Download dependencies
Dependencies are absent from the main project. There is information on how to build them but the easist thing to do is to download the following folders from a `soarquin/ygopro` fork and simply copy them into the `Fluorohydride/ygopro` folder.
* event
* freetype
* irrklang
* irrlict
* lua
* sqlite3
###4.) Create the project files
Run the following commands from the command line in the `Fluorohydride/ygopro` folder.
` premake4 /help `
` premake4 vs2010 `
If you are not using Visual Studio 2010 or higher, make the needed adjustments. In the file system open `Fluorohydride/ygopro/build` folder open the `ygo` project.
### Build the system
Make sure the code actually compiles. Compile them in the following order one by one:
* lua
* sqlite3
* ocgcore
This should provide you with `ocgcore.lib` in the build output folder. `YGOCore` requires a `*.dll`; in `ocgcore` project properities change it to a dynamically linked library. Recompile, it should fail with an error indicating missing dependencies. Right click the project, add a existing file. Add `lua.lib` from the build folder to the project. It should now compile.
##Exposed Functions
These three function need to be provided to the core so it can get card and database information.
- `void set_script_reader(script_reader f);` : Interface provided returns scripts based on number that corrosponses to a lua file, send in a string.
- `void set_card_reader(card_reader f);` : Inferface provided function that provides database information from the `data` table of `cards.cdb`.
- `void set_message_handler(message_handler f);` : Interface provided function that handles errors
These functions create the game itself and then manipulate it.
- `ptr create_duel(uint32 seed);` : Create a the instance of the duel using a random number.
- `void start_duel(ptr pduel, int32 options);` : Starts the duel
- `void end_duel(ptr pduel);` : ends the duel
- `void set_player_info(ptr pduel, int32 playerid, int32 lp, int32 startcount, int32 drawcount);` sets the duel up
- `void get_log_message(ptr pduel, byte* buf);`
- `int32 get_message(ptr pduel, byte* buf);`
- `int32 process(ptr pduel);` : do a game tick
- `void new_card(ptr pduel, uint32 code, uint8 owner, uint8 playerid, uint8 location, uint8 sequence, uint8 position);` : add a card to the duel state.
- `void new_tag_card(ptr pduel, uint32 code, uint8 owner, uint8 location);` : add a new card to the tag pool.
- `int32 query_card(ptr pduel, uint8 playerid, uint8 location, uint8 sequence, int32 query_flag, byte* buf, int32 use_cache);` : find out about a card in a specific spot.
- `int32 query_field_count(ptr pduel, uint8 playerid, uint8 location);`Get the number of cards in a specific field/zone.
- `int32 query_field_card(ptr pduel, uint8 playerid, uint8 location, int32 query_flag, byte* buf, int32 use_cache);`
- `int32 query_field_info(ptr pduel, byte* buf);`
- `void set_responsei(ptr pduel, int32 value);`
- `void set_responseb(ptr pduel, byte* buf);`
- `int32 preload_script(ptr pduel, char* script, int32 len);`
#Lua functions
`interpreter.cpp`
\ No newline at end of file
This diff is collapsed.
......@@ -12,6 +12,7 @@
#include "effectset.h"
#include <set>
#include <map>
#include <unordered_map>
class card;
class duel;
......@@ -66,11 +67,11 @@ public:
typedef std::vector<card*> card_vector;
typedef std::multimap<uint32, effect*> effect_container;
typedef std::set<card*, card_sort> card_set;
typedef std::map<effect*, effect_container::iterator> effect_indexer;
typedef std::map<effect*, uint32> effect_relation;
typedef std::map<card*, uint32> relation_map;
typedef std::unordered_map<effect*, effect_container::iterator> effect_indexer;
typedef std::unordered_map<effect*, uint32> effect_relation;
typedef std::unordered_map<card*, uint32> relation_map;
typedef std::map<uint16, uint16> counter_map;
typedef std::map<uint16, card*> attacker_map;
typedef std::unordered_map<uint16, card*> attacker_map;
int32 scrtype;
int32 ref_handle;
duel* pduel;
......@@ -240,7 +241,7 @@ public:
int32 is_control_can_be_changed();
int32 is_capable_be_battle_target(card* pcard);
int32 is_capable_be_effect_target(effect* peffect, uint8 playerid);
int32 is_can_be_fusion_material(uint8 ignore_mon = FALSE);
int32 is_can_be_fusion_material(card* fcard, uint8 ignore_mon = FALSE);
int32 is_can_be_synchro_material(card* scard, card* tuner = 0);
int32 is_can_be_ritual_material(card* scard);
int32 is_can_be_xyz_material(card* scard);
......
......@@ -24,21 +24,21 @@ duel::duel() {
clear_buffer();
}
duel::~duel() {
for(std::set<card*>::iterator cit = cards.begin(); cit != cards.end(); ++cit)
for(auto cit = cards.begin(); cit != cards.end(); ++cit)
delete *cit;
for(std::set<group*>::iterator git = groups.begin(); git != groups.end(); ++git)
for(auto git = groups.begin(); git != groups.end(); ++git)
delete *git;
for(std::set<effect*>::iterator eit = effects.begin(); eit != effects.end(); ++eit)
for(auto eit = effects.begin(); eit != effects.end(); ++eit)
delete *eit;
delete lua;
delete game_field;
}
void duel::clear() {
for(std::set<card*>::iterator cit = cards.begin(); cit != cards.end(); ++cit)
for(auto cit = cards.begin(); cit != cards.end(); ++cit)
delete *cit;
for(std::set<group*>::iterator git = groups.begin(); git != groups.end(); ++git)
for(auto git = groups.begin(); git != groups.end(); ++git)
delete *git;
for(std::set<effect*>::iterator eit = effects.begin(); eit != effects.end(); ++eit)
for(auto eit = effects.begin(); eit != effects.end(); ++eit)
delete *eit;
delete game_field;
cards.clear();
......@@ -101,8 +101,7 @@ int32 duel::read_buffer(byte* buf) {
return bufferlen;
}
void duel::release_script_group() {
std::set<group*>::iterator sit;
for(sit = sgroups.begin(); sit != sgroups.end(); ++sit) {
for(auto sit = sgroups.begin(); sit != sgroups.end(); ++sit) {
group* pgroup = *sit;
if(pgroup->is_readonly == 0) {
lua->unregister_group(pgroup);
......@@ -113,8 +112,7 @@ void duel::release_script_group() {
sgroups.clear();
}
void duel::restore_assumes() {
std::set<card*>::iterator sit;
for(sit = assumes.begin(); sit != assumes.end(); ++sit)
for(auto sit = assumes.begin(); sit != assumes.end(); ++sit)
(*sit)->assume_type = 0;
assumes.clear();
}
......
......@@ -11,6 +11,7 @@
#include "common.h"
#include "mtrandom.h"
#include <set>
#include <unordered_set>
class card;
class group;
......@@ -35,12 +36,12 @@ public:
interpreter* lua;
field* game_field;
mtrandom random;
std::set<card*> cards;
std::set<card*> assumes;
std::set<group*> groups;
std::set<group*> sgroups;
std::set<effect*> effects;
std::set<effect*> uncopy;
std::unordered_set<card*> cards;
std::unordered_set<card*> assumes;
std::unordered_set<group*> groups;
std::unordered_set<group*> sgroups;
std::unordered_set<effect*> effects;
std::unordered_set<effect*> uncopy;
ygoAdapter* adapter;
duel();
......
This diff is collapsed.
......@@ -24,6 +24,8 @@ class effect;
struct tevent;
struct effect_set;
struct effect_set_v;
enum effect_flag;
enum effect_flag2;
class effect {
public:
......@@ -35,7 +37,7 @@ public:
uint8 effect_owner;
uint32 description;
uint32 code;
uint32 flag;
uint32 flag[2];
uint32 id;
uint16 type;
uint16 copy_id;
......@@ -86,6 +88,12 @@ public:
uint8 get_owner_player();
uint8 get_handler_player();
int32 in_range(int32 loc, int32 seq);
bool is_flag(effect_flag flag) const {
return !!(this->flag[0] & flag);
}
bool is_flag(effect_flag2 flag) const {
return !!(this->flag[1] & flag);
}
};
//status
......@@ -141,38 +149,48 @@ public:
#define EFFECT_TYPE_CONTINUOUS 0x0800 //
//========== Flags ==========
#define EFFECT_FLAG_INITIAL 0x0001 //
#define EFFECT_FLAG_FUNC_VALUE 0x0002 //
#define EFFECT_FLAG_COUNT_LIMIT 0x0004 //
#define EFFECT_FLAG_FIELD_ONLY 0x0008 //
#define EFFECT_FLAG_CARD_TARGET 0x0010 //
#define EFFECT_FLAG_IGNORE_RANGE 0x0020 //
#define EFFECT_FLAG_ABSOLUTE_TARGET 0x0040 //
#define EFFECT_FLAG_IGNORE_IMMUNE 0x0080 //
#define EFFECT_FLAG_SET_AVAILABLE 0x0100 //
#define EFFECT_FLAG_CONTINUOUS 0x0200 //
#define EFFECT_FLAG_CANNOT_DISABLE 0x0400 //
#define EFFECT_FLAG_PLAYER_TARGET 0x0800 //
#define EFFECT_FLAG_BOTH_SIDE 0x1000 //
#define EFFECT_FLAG_COPY_INHERIT 0x2000 //
#define EFFECT_FLAG_DAMAGE_STEP 0x4000 //
#define EFFECT_FLAG_DAMAGE_CAL 0x8000 //
#define EFFECT_FLAG_DELAY 0x10000 //
#define EFFECT_FLAG_SINGLE_RANGE 0x20000 //
#define EFFECT_FLAG_UNCOPYABLE 0x40000 //
#define EFFECT_FLAG_OATH 0x80000 //
#define EFFECT_FLAG_SPSUM_PARAM 0x100000 //
#define EFFECT_FLAG_REPEAT 0x200000 //
#define EFFECT_FLAG_NO_TURN_RESET 0x400000 //
#define EFFECT_FLAG_EVENT_PLAYER 0x800000 //
#define EFFECT_FLAG_OWNER_RELATE 0x1000000 //
#define EFFECT_FLAG_AVAILABLE_BD 0x2000000 //
#define EFFECT_FLAG_CLIENT_HINT 0x4000000 //
#define EFFECT_FLAG_CHAIN_UNIQUE 0x8000000 //
#define EFFECT_FLAG_NAGA 0x10000000 //
#define EFFECT_FLAG_COF 0x20000000 //
#define EFFECT_FLAG_CVAL_CHECK 0x40000000 //
#define EFFECT_FLAG_IMMEDIATELY_APPLY 0x80000000 //
enum effect_flag {
EFFECT_FLAG_INITIAL = 0x0001,
EFFECT_FLAG_FUNC_VALUE = 0x0002,
EFFECT_FLAG_COUNT_LIMIT = 0x0004,
EFFECT_FLAG_FIELD_ONLY = 0x0008,
EFFECT_FLAG_CARD_TARGET = 0x0010,
EFFECT_FLAG_IGNORE_RANGE = 0x0020,
EFFECT_FLAG_ABSOLUTE_TARGET = 0x0040,
EFFECT_FLAG_IGNORE_IMMUNE = 0x0080,
EFFECT_FLAG_SET_AVAILABLE = 0x0100,
EFFECT_FLAG_CONTINUOUS = 0x0200,
EFFECT_FLAG_CANNOT_DISABLE = 0x0400,
EFFECT_FLAG_PLAYER_TARGET = 0x0800,
EFFECT_FLAG_BOTH_SIDE = 0x1000,
EFFECT_FLAG_COPY_INHERIT = 0x2000,
EFFECT_FLAG_DAMAGE_STEP = 0x4000,
EFFECT_FLAG_DAMAGE_CAL = 0x8000,
EFFECT_FLAG_DELAY = 0x10000,
EFFECT_FLAG_SINGLE_RANGE = 0x20000,
EFFECT_FLAG_UNCOPYABLE = 0x40000,
EFFECT_FLAG_OATH = 0x80000,
EFFECT_FLAG_SPSUM_PARAM = 0x100000,
EFFECT_FLAG_REPEAT = 0x200000,
EFFECT_FLAG_NO_TURN_RESET = 0x400000,
EFFECT_FLAG_EVENT_PLAYER = 0x800000,
EFFECT_FLAG_OWNER_RELATE = 0x1000000,
EFFECT_FLAG_AVAILABLE_BD = 0x2000000,
EFFECT_FLAG_CLIENT_HINT = 0x4000000,
EFFECT_FLAG_CHAIN_UNIQUE = 0x8000000,
// EFFECT_FLAG_NAGA = 0x10000000,
// EFFECT_FLAG_COF = 0x20000000,
EFFECT_FLAG_CVAL_CHECK = 0x40000000,
EFFECT_FLAG_IMMEDIATELY_APPLY = 0x80000000,
};
enum effect_flag2 {
EFFECT_FLAG2_NAGA = 0x0001,
EFFECT_FLAG2_COF = 0x0002,
};
inline effect_flag operator|(effect_flag flag1, effect_flag flag2)
{
return static_cast<effect_flag>(static_cast<uint32>(flag1) | static_cast<uint32>(flag2));
}
//========== Codes ==========
#define EFFECT_IMMUNE_EFFECT 1 //
#define EFFECT_DISABLE 2 //
......@@ -382,6 +400,8 @@ public:
#define EFFECT_NO_EFFECT_DAMAGE 335
#define EFFECT_UNSUMMONABLE_CARD 336
#define EFFECT_DISABLE_CHAIN_FIELD 337
#define EFFECT_DISCARD_COST_CHANGE 338
#define EFFECT_HAND_SYNCHRO 339
#define EVENT_STARTUP 1000
#define EVENT_FLIP 1001
......
......@@ -42,6 +42,7 @@ field::field(duel* pduel) {
player[i].disabled_location = 0;
player[i].used_location = 0;
player[i].extra_p_count = 0;
player[i].tag_extra_p_count = 0;
player[i].list_mzone.reserve(5);
player[i].list_szone.reserve(8);
player[i].list_main.reserve(45);
......@@ -140,7 +141,8 @@ void field::reload_field_info() {
pduel->write_buffer32(peffect->description);
}
}
// Debug.AddCard() will call this function directly
// check Fusion/S/X monster redirection by the rule
void field::add_card(uint8 playerid, card* pcard, uint8 location, uint8 sequence) {
if (pcard->current.location != 0)
return;
......@@ -196,6 +198,8 @@ void field::add_card(uint8 playerid, card* pcard, uint8 location, uint8 sequence
case LOCATION_EXTRA:
player[playerid].list_extra.push_back(pcard);
pcard->current.sequence = player[playerid].list_extra.size() - 1;
if((pcard->data.type & TYPE_PENDULUM) && ((pcard->operation_param >> 24) & POS_FACEUP))
++player[playerid].extra_p_count;
break;
}
pcard->apply_field_effect();
......@@ -239,6 +243,8 @@ void field::remove_card(card* pcard) {
case LOCATION_EXTRA:
player[playerid].list_extra.erase(player[playerid].list_extra.begin() + pcard->current.sequence);
reset_sequence(playerid, LOCATION_EXTRA);
if((pcard->data.type & TYPE_PENDULUM) && (pcard->current.position & POS_FACEUP))
--player[playerid].extra_p_count;
break;
}
pcard->cancel_field_effect();
......@@ -254,6 +260,8 @@ void field::remove_card(card* pcard) {
pcard->current.location = 0;
pcard->current.sequence = 0;
}
// check Fusion/S/X monster redirection by the rule
// it will call remove_card(), add_card()
void field::move_card(uint8 playerid, card* pcard, uint8 location, uint8 sequence) {
if (!is_location_useable(playerid, location, sequence))
return;
......@@ -388,7 +396,7 @@ void field::set_control(card* pcard, uint8 playerid, uint16 reset_phase, uint8 r
peffect->type = EFFECT_TYPE_SINGLE;
peffect->code = EFFECT_SET_CONTROL;
peffect->value = playerid;
peffect->flag = EFFECT_FLAG_CANNOT_DISABLE;
peffect->flag[0] = EFFECT_FLAG_CANNOT_DISABLE;
peffect->reset_flag = RESET_EVENT | 0xc6c0000;
if(reset_count) {
peffect->reset_flag |= RESET_PHASE | reset_phase;
......@@ -673,6 +681,7 @@ void field::tag_swap(uint8 playerid) {
clit->cancel_field_effect();
}
std::swap(player[playerid].list_extra, player[playerid].tag_list_extra);
std::swap(player[playerid].extra_p_count, player[playerid].tag_extra_p_count);
for(auto& clit : player[playerid].list_extra) {
clit->apply_field_effect();
clit->enable_field_effect(true);
......@@ -681,6 +690,7 @@ void field::tag_swap(uint8 playerid) {
pduel->write_buffer8(playerid);
pduel->write_buffer8(player[playerid].list_main.size());
pduel->write_buffer8(player[playerid].list_extra.size());
pduel->write_buffer8(player[playerid].extra_p_count);
pduel->write_buffer8(player[playerid].list_hand.size());
if(core.deck_reversed && player[playerid].list_main.size())
pduel->write_buffer32(player[playerid].list_main.back()->data.code);
......@@ -690,10 +700,12 @@ void field::tag_swap(uint8 playerid) {
pduel->write_buffer32(cit->data.code | (cit->is_position(POS_FACEUP) ? 0x80000000 : 0));
for(auto& cit : player[playerid].list_hand)
cit->update_infos_nocache(0x3ffe);
for(auto cit : player[playerid].list_extra)
pduel->write_buffer32(cit->data.code | (cit->is_position(POS_FACEUP) ? 0x80000000 : 0));
}
void field::add_effect(effect* peffect, uint8 owner_player) {
if (!peffect->handler) {
peffect->flag |= EFFECT_FLAG_FIELD_ONLY;
peffect->flag[0] |= EFFECT_FLAG_FIELD_ONLY;
peffect->handler = peffect->owner;
peffect->effect_owner = owner_player;
peffect->id = infos.field_id++;
......@@ -724,14 +736,14 @@ void field::add_effect(effect* peffect, uint8 owner_player) {
it = effects.continuous_effect.insert(make_pair(peffect->code, peffect));
}
effects.indexer.insert(make_pair(peffect, it));
if((peffect->flag & EFFECT_FLAG_FIELD_ONLY)) {
if(peffect->flag & EFFECT_FLAG_OATH)
if((peffect->is_flag(EFFECT_FLAG_FIELD_ONLY))) {
if(peffect->is_flag(EFFECT_FLAG_OATH))
effects.oath.insert(make_pair(peffect, core.reason_effect));
if(peffect->reset_flag & RESET_PHASE)
effects.pheff.insert(peffect);
if(peffect->reset_flag & RESET_CHAIN)
effects.cheff.insert(peffect);
if(peffect->flag & EFFECT_FLAG_COUNT_LIMIT)
if(peffect->is_flag(EFFECT_FLAG_COUNT_LIMIT))
effects.rechargeable.insert(peffect);
}
}
......@@ -761,14 +773,14 @@ void field::remove_effect(effect* peffect) {
effects.continuous_effect.erase(it);
}
effects.indexer.erase(peffect);
if((peffect->flag & EFFECT_FLAG_FIELD_ONLY)) {
if(peffect->flag & EFFECT_FLAG_OATH)
if((peffect->is_flag(EFFECT_FLAG_FIELD_ONLY))) {
if(peffect->is_flag(EFFECT_FLAG_OATH))
effects.oath.erase(peffect);
if(peffect->reset_flag & RESET_PHASE)
effects.pheff.erase(peffect);
if(peffect->reset_flag & RESET_CHAIN)
effects.cheff.erase(peffect);
if(peffect->flag & EFFECT_FLAG_COUNT_LIMIT)
if(peffect->is_flag(EFFECT_FLAG_COUNT_LIMIT))
effects.rechargeable.erase(peffect);
core.reseted_effects.insert(peffect);
}
......@@ -779,7 +791,7 @@ void field::remove_oath_effect(effect* reason_effect) {
if(rm->second == reason_effect) {
effect* peffect = rm->first;
effects.oath.erase(rm);
if(peffect->flag & EFFECT_FLAG_FIELD_ONLY)
if(peffect->is_flag(EFFECT_FLAG_FIELD_ONLY))
remove_effect(peffect);
else
peffect->handler->remove_effect(peffect);
......@@ -792,7 +804,7 @@ void field::reset_effect(uint32 id, uint32 reset_type) {
auto rm = it++;
auto peffect = rm->first;
auto pit = rm->second;
if (!(peffect->flag & EFFECT_FLAG_FIELD_ONLY))
if (!(peffect->is_flag(EFFECT_FLAG_FIELD_ONLY)))
continue;
result = peffect->reset(id, reset_type);
if (result) {
......@@ -825,7 +837,7 @@ void field::reset_phase(uint32 phase) {
for(auto eit = effects.pheff.begin(); eit != effects.pheff.end();) {
auto rm = eit++;
if((*rm)->reset(phase, RESET_PHASE)) {
if((*rm)->flag & EFFECT_FLAG_FIELD_ONLY)
if((*rm)->is_flag(EFFECT_FLAG_FIELD_ONLY))
remove_effect((*rm));
else
(*rm)->handler->remove_effect((*rm));
......@@ -835,7 +847,7 @@ void field::reset_phase(uint32 phase) {
void field::reset_chain() {
for(auto eit = effects.cheff.begin(); eit != effects.cheff.end();) {
auto rm = eit++;
if((*rm)->flag & EFFECT_FLAG_FIELD_ONLY)
if((*rm)->is_flag(EFFECT_FLAG_FIELD_ONLY))
remove_effect((*rm));
else
(*rm)->handler->remove_effect((*rm));
......@@ -873,7 +885,7 @@ void field::filter_field_effect(uint32 code, effect_set* eset, uint8 sort) {
eset->sort();
}
void field::filter_affected_cards(effect* peffect, card_set* cset) {
if ((peffect->type & EFFECT_TYPE_ACTIONS) || !(peffect->type & EFFECT_TYPE_FIELD) || (peffect->flag & EFFECT_FLAG_PLAYER_TARGET))
if ((peffect->type & EFFECT_TYPE_ACTIONS) || !(peffect->type & EFFECT_TYPE_FIELD) || (peffect->is_flag(EFFECT_FLAG_PLAYER_TARGET)))
return;
uint8 self = peffect->get_handler_player();
if(self == PLAYER_NONE)
......@@ -1213,7 +1225,7 @@ int32 field::get_summon_release_list(card* target, card_set* release_list, card_
rcount += pcard->operation_param;
} else {
effect* peffect = pcard->is_affected_by_effect(EFFECT_EXTRA_RELEASE_SUM);
if(!peffect || ((peffect->flag & EFFECT_FLAG_COUNT_LIMIT) && (peffect->reset_count & 0xf00) == 0))
if(!peffect || ((peffect->is_flag(EFFECT_FLAG_COUNT_LIMIT)) && (peffect->reset_count & 0xf00) == 0))
continue;
if(ex_list_sum)
ex_list_sum->insert(pcard);
......@@ -1373,6 +1385,7 @@ void field::adjust_disable_check_list() {
}
} while(effects.disable_check_list.size());
}
// adjust check_unique_onfield(), EFFECT_SELF_DESTROY, EFFECT_SELF_TOGRAVE
void field::adjust_self_destroy_set() {
if(core.selfdes_disabled || !core.self_destroy_set.empty() || !core.self_tograve_set.empty())
return;
......@@ -1984,6 +1997,7 @@ int32 field::is_player_can_sset(uint8 playerid, card * pcard) {
}
return TRUE;
}
// check player-effect EFFECT_CANNOT_SPECIAL_SUMMON without target
int32 field::is_player_can_spsummon(uint8 playerid) {
effect_set eset;
filter_player_effect(playerid, EFFECT_CANNOT_SPECIAL_SUMMON, &eset);
......@@ -2185,9 +2199,9 @@ int32 field::is_chain_negatable(uint8 chaincount, uint8 naga_check) {
peffect = core.current_chain.back().triggering_effect;
else
peffect = core.current_chain[chaincount - 1].triggering_effect;
if(naga_check && peffect->flag & EFFECT_FLAG_NAGA)
if(naga_check && peffect->is_flag(EFFECT_FLAG2_NAGA))
return FALSE;
if(peffect->flag & EFFECT_FLAG_CANNOT_DISABLE)
if(peffect->is_flag(EFFECT_FLAG_CANNOT_DISABLE))
return FALSE;
filter_field_effect(EFFECT_CANNOT_INACTIVATE, &eset);
for(int32 i = 0; i < eset.size(); ++i) {
......@@ -2206,9 +2220,9 @@ int32 field::is_chain_disablable(uint8 chaincount, uint8 naga_check) {
peffect = core.current_chain.back().triggering_effect;
else
peffect = core.current_chain[chaincount - 1].triggering_effect;
if(naga_check && peffect->flag & EFFECT_FLAG_NAGA)
if(naga_check && peffect->is_flag(EFFECT_FLAG2_NAGA))
return FALSE;
if(peffect->flag & EFFECT_FLAG_CANNOT_DISABLE)
if(peffect->is_flag(EFFECT_FLAG_CANNOT_DISABLE))
return FALSE;
filter_field_effect(EFFECT_CANNOT_DISEFFECT, &eset);
for(int32 i = 0; i < eset.size(); ++i) {
......@@ -2228,7 +2242,7 @@ int32 field::check_chain_target(uint8 chaincount, card * pcard) {
pchain = &core.current_chain[chaincount - 1];
effect* peffect = pchain->triggering_effect;
uint8 tp = pchain->triggering_player;
if(!(peffect->flag & EFFECT_FLAG_CARD_TARGET) || !peffect->target)
if(!(peffect->is_flag(EFFECT_FLAG_CARD_TARGET)) || !peffect->target)
return FALSE;
if(!pcard->is_capable_be_effect_target(peffect, tp))
return false;
......
......@@ -44,7 +44,7 @@ struct optarget {
int32 op_param;
};
struct chain {
typedef std::map<uint32, optarget > opmap;
typedef std::unordered_map<uint32, optarget> opmap;
uint16 chain_id;
uint8 chain_count;
uint8 triggering_player;
......@@ -72,6 +72,7 @@ struct player_info {
uint32 used_location;
uint32 disabled_location;
uint32 extra_p_count;
uint32 tag_extra_p_count;
card_vector list_mzone;
card_vector list_szone;
card_vector list_main;
......@@ -85,9 +86,9 @@ struct player_info {
};
struct field_effect {
typedef std::multimap<uint32, effect*> effect_container;
typedef std::map<effect*, effect_container::iterator> effect_indexer;
typedef std::map<effect*, effect*> oath_effects;
typedef std::set<effect*> effect_collection;
typedef std::unordered_map<effect*, effect_container::iterator> effect_indexer;
typedef std::unordered_map<effect*, effect*> oath_effects;
typedef std::unordered_set<effect*> effect_collection;
effect_container aura_effect;
effect_container ignition_effect;
......@@ -105,7 +106,7 @@ struct field_effect {
effect_collection spsummon_count_eff;
std::list<card*> disable_check_list;
std::set<card*, card_sort> disable_check_set;
std::unordered_set<card*> disable_check_set;
};
struct field_info {
int32 field_id;
......@@ -147,7 +148,6 @@ struct processor {
typedef std::vector<chain> chain_array;
typedef std::list<processor_unit> processor_list;
typedef std::set<card*, card_sort> card_set;
typedef std::set<effect*> effect_collection;
typedef std::set<std::pair<effect*, tevent> > delayed_effect_collection;
processor_list units;
......@@ -301,7 +301,6 @@ struct processor {
class field {
public:
typedef std::multimap<uint32, effect*> effect_container;
typedef std::map<effect*, effect_container::iterator> effect_indexer;
typedef std::set<card*, card_sort> card_set;
typedef std::vector<effect*> effect_vector;
typedef std::vector<card*> card_vector;
......@@ -311,7 +310,6 @@ public:
typedef std::map<effect*, chain> instant_f_list;
typedef std::vector<chain> chain_array;
typedef std::list<processor_unit> processor_list;
typedef std::map<effect*, effect*> oath_effects;
duel* pduel;
player_info player[2];
......
......@@ -322,6 +322,7 @@ static const struct luaL_Reg duellib[] = {
{ "SendtoGrave", scriptlib::duel_sendto_grave },
{ "SendtoHand", scriptlib::duel_sendto_hand },
{ "SendtoDeck", scriptlib::duel_sendto_deck },
{ "PSendtoExtra", scriptlib::duel_sendto_extra },
{ "GetOperatedGroup", scriptlib::duel_get_operated_group },
{ "Summon", scriptlib::duel_summon },
{ "SpecialSummonRule", scriptlib::duel_special_summon_rule },
......@@ -602,7 +603,7 @@ void interpreter::unregister_effect(effect *peffect) {
luaL_unref(lua_state, LUA_REGISTRYINDEX, peffect->target);
if(peffect->operation)
luaL_unref(lua_state, LUA_REGISTRYINDEX, peffect->operation);
if(peffect->value && (peffect->flag & EFFECT_FLAG_FUNC_VALUE))
if(peffect->value && (peffect->is_flag(EFFECT_FLAG_FUNC_VALUE)))
luaL_unref(lua_state, LUA_REGISTRYINDEX, peffect->value);
luaL_unref(lua_state, LUA_REGISTRYINDEX, peffect->ref_handle);
peffect->ref_handle = 0;
......
......@@ -591,7 +591,7 @@ int32 scriptlib::card_enable_dual_state(lua_State *L) {
deffect->owner = pcard;
deffect->code = EFFECT_DUAL_STATUS;
deffect->type = EFFECT_TYPE_SINGLE;
deffect->flag = EFFECT_FLAG_CANNOT_DISABLE;
deffect->flag[0] = EFFECT_FLAG_CANNOT_DISABLE;
deffect->reset_flag = RESET_EVENT + 0x1fe0000;
pcard->add_effect(deffect);
return 0;
......@@ -743,8 +743,7 @@ int32 scriptlib::card_get_attacked_group(lua_State *L) {
check_param(L, PARAM_TYPE_CARD, 1);
card* pcard = *(card**) lua_touserdata(L, 1);
group* pgroup = pcard->pduel->new_group();
card::attacker_map::iterator cit;
for(cit = pcard->attacked_cards.begin(); cit != pcard->attacked_cards.end(); ++cit) {
for(auto cit = pcard->attacked_cards.begin(); cit != pcard->attacked_cards.end(); ++cit) {
if(cit->second)
pgroup->container.insert(cit->second);
}
......@@ -770,8 +769,7 @@ int32 scriptlib::card_get_battled_group(lua_State *L) {
check_param(L, PARAM_TYPE_CARD, 1);
card* pcard = *(card**) lua_touserdata(L, 1);
group* pgroup = pcard->pduel->new_group();
card::attacker_map::iterator cit;
for(cit = pcard->battled_cards.begin(); cit != pcard->battled_cards.end(); ++cit) {
for(auto cit = pcard->battled_cards.begin(); cit != pcard->battled_cards.end(); ++cit) {
if(cit->second)
pgroup->container.insert(cit->second);
}
......@@ -989,7 +987,7 @@ int32 scriptlib::card_register_flag_effect(lua_State *L) {
peffect->type = EFFECT_TYPE_SINGLE;
peffect->code = code;
peffect->reset_flag = reset;
peffect->flag = flag | EFFECT_FLAG_CANNOT_DISABLE;
peffect->flag[0] = flag | EFFECT_FLAG_CANNOT_DISABLE;
peffect->reset_count |= count & 0xff;
peffect->label = lab;
peffect->description = desc;
......@@ -1143,7 +1141,7 @@ int32 scriptlib::card_enable_unsummonable(lua_State *L) {
peffect->owner = pcard;
peffect->code = EFFECT_UNSUMMONABLE_CARD;
peffect->type = EFFECT_TYPE_SINGLE;
peffect->flag = EFFECT_FLAG_CANNOT_DISABLE | EFFECT_FLAG_UNCOPYABLE;
peffect->flag[0] = EFFECT_FLAG_CANNOT_DISABLE | EFFECT_FLAG_UNCOPYABLE;
pcard->add_effect(peffect);
}
return 0;
......@@ -1158,13 +1156,13 @@ int32 scriptlib::card_enable_revive_limit(lua_State *L) {
peffect1->owner = pcard;
peffect1->code = EFFECT_UNSUMMONABLE_CARD;
peffect1->type = EFFECT_TYPE_SINGLE;
peffect1->flag = EFFECT_FLAG_CANNOT_DISABLE | EFFECT_FLAG_UNCOPYABLE;
peffect1->flag[0] = EFFECT_FLAG_CANNOT_DISABLE | EFFECT_FLAG_UNCOPYABLE;
pcard->add_effect(peffect1);
effect* peffect2 = pduel->new_effect();
peffect2->owner = pcard;
peffect2->code = EFFECT_REVIVE_LIMIT;
peffect2->type = EFFECT_TYPE_SINGLE;
peffect2->flag = EFFECT_FLAG_CANNOT_DISABLE | EFFECT_FLAG_UNCOPYABLE;
peffect2->flag[0] = EFFECT_FLAG_CANNOT_DISABLE | EFFECT_FLAG_UNCOPYABLE;
pcard->add_effect(peffect2);
}
return 0;
......@@ -1808,7 +1806,7 @@ int32 scriptlib::card_enable_counter_permit(lua_State *L) {
peffect->owner = pcard;
peffect->type = EFFECT_TYPE_SINGLE;
peffect->code = EFFECT_COUNTER_PERMIT | countertype;
peffect->flag = EFFECT_FLAG_SINGLE_RANGE;
peffect->flag[0] = EFFECT_FLAG_SINGLE_RANGE;
peffect->range = prange;
pcard->add_effect(peffect);
return 0;
......@@ -1859,10 +1857,15 @@ int32 scriptlib::card_is_can_be_fusion_material(lua_State *L) {
check_param_count(L, 1);
check_param(L, PARAM_TYPE_CARD, 1);
card* pcard = *(card**) lua_touserdata(L, 1);
card* fcard = 0;
uint32 ign = FALSE;
if(lua_gettop(L) >= 2)
ign = lua_toboolean(L, 2);
lua_pushboolean(L, pcard->is_can_be_fusion_material(ign));
if(lua_gettop(L) >= 2 && !lua_isnil(L, 2)) {
check_param(L, PARAM_TYPE_CARD, 2);
fcard = *(card**)lua_touserdata(L, 2);
}
if(lua_gettop(L) >= 3)
ign = lua_toboolean(L, 3);
lua_pushboolean(L, pcard->is_can_be_fusion_material(fcard, ign));
return 1;
}
int32 scriptlib::card_is_can_be_synchro_material(lua_State *L) {
......@@ -1973,7 +1976,7 @@ int32 scriptlib::card_add_trap_monster_attribute(lua_State *L) {
peffect->owner = pcard;
peffect->type = EFFECT_TYPE_SINGLE;
peffect->code = EFFECT_ADD_TYPE;
peffect->flag = EFFECT_FLAG_CANNOT_DISABLE;
peffect->flag[0] = EFFECT_FLAG_CANNOT_DISABLE;
peffect->reset_flag = RESET_EVENT + 0x47e0000;
peffect->value = TYPE_MONSTER | TYPE_TRAPMONSTER | extra_type;
pcard->add_effect(peffect);
......@@ -1982,7 +1985,7 @@ int32 scriptlib::card_add_trap_monster_attribute(lua_State *L) {
peffect->owner = pcard;
peffect->type = EFFECT_TYPE_SINGLE;
peffect->code = EFFECT_ADD_ATTRIBUTE;
peffect->flag = EFFECT_FLAG_CANNOT_DISABLE;
peffect->flag[0] = EFFECT_FLAG_CANNOT_DISABLE;
peffect->reset_flag = RESET_EVENT + 0x47e0000;
peffect->value = attribute;
pcard->add_effect(peffect);
......@@ -1991,7 +1994,7 @@ int32 scriptlib::card_add_trap_monster_attribute(lua_State *L) {
peffect->owner = pcard;
peffect->type = EFFECT_TYPE_SINGLE;
peffect->code = EFFECT_ADD_RACE;
peffect->flag = EFFECT_FLAG_CANNOT_DISABLE;
peffect->flag[0] = EFFECT_FLAG_CANNOT_DISABLE;
peffect->reset_flag = RESET_EVENT + 0x47e0000;
peffect->value = race;
pcard->add_effect(peffect);
......@@ -2000,7 +2003,7 @@ int32 scriptlib::card_add_trap_monster_attribute(lua_State *L) {
peffect->owner = pcard;
peffect->type = EFFECT_TYPE_SINGLE;
peffect->code = EFFECT_CHANGE_LEVEL;
peffect->flag = EFFECT_FLAG_CANNOT_DISABLE;
peffect->flag[0] = EFFECT_FLAG_CANNOT_DISABLE;
peffect->reset_flag = RESET_EVENT + 0x47e0000;
peffect->value = level;
pcard->add_effect(peffect);
......@@ -2009,7 +2012,7 @@ int32 scriptlib::card_add_trap_monster_attribute(lua_State *L) {
peffect->owner = pcard;
peffect->type = EFFECT_TYPE_SINGLE;
peffect->code = EFFECT_SET_BASE_ATTACK;
peffect->flag = EFFECT_FLAG_CANNOT_DISABLE;
peffect->flag[0] = EFFECT_FLAG_CANNOT_DISABLE;
peffect->reset_flag = RESET_EVENT + 0x47e0000;
peffect->value = atk;
pcard->add_effect(peffect);
......@@ -2018,7 +2021,7 @@ int32 scriptlib::card_add_trap_monster_attribute(lua_State *L) {
peffect->owner = pcard;
peffect->type = EFFECT_TYPE_SINGLE;
peffect->code = EFFECT_SET_BASE_DEFENCE;
peffect->flag = EFFECT_FLAG_CANNOT_DISABLE;
peffect->flag[0] = EFFECT_FLAG_CANNOT_DISABLE;
peffect->reset_flag = RESET_EVENT + 0x47e0000;
peffect->value = def;
pcard->add_effect(peffect);
......@@ -2036,7 +2039,7 @@ int32 scriptlib::card_trap_monster_block(lua_State *L) {
peffect->type = EFFECT_TYPE_FIELD;
peffect->range = LOCATION_MZONE;
peffect->code = EFFECT_USE_EXTRA_SZONE;
peffect->flag = EFFECT_FLAG_CANNOT_DISABLE;
peffect->flag[0] = EFFECT_FLAG_CANNOT_DISABLE;
peffect->reset_flag = RESET_EVENT + 0x5fe0000;
peffect->value = 1 + (0x10000 << pcard->previous.sequence);
pcard->add_effect(peffect);
......@@ -2133,7 +2136,7 @@ int32 scriptlib::card_set_unique_onfield(lua_State *L) {
peffect->owner = pcard;
peffect->type = EFFECT_TYPE_SINGLE;
peffect->code = EFFECT_UNIQUE_CHECK;
peffect->flag = EFFECT_FLAG_COPY_INHERIT;
peffect->flag[0] = EFFECT_FLAG_COPY_INHERIT;
pcard->add_effect(peffect);
pcard->unique_effect = peffect;
if(pcard->current.location & LOCATION_ONFIELD)
......
......@@ -39,14 +39,13 @@ int32 scriptlib::debug_add_card(lua_State *L) {
if(pduel->game_field->is_location_useable(playerid, location, sequence)) {
card* pcard = pduel->new_card(code);
pcard->owner = owner;
pcard->operation_param = position << 24;
pduel->game_field->add_card(playerid, pcard, location, sequence);
pcard->current.position = position;
if(!(location & LOCATION_ONFIELD) || (position & POS_FACEUP)) {
pcard->enable_field_effect(TRUE);
pduel->game_field->adjust_instant();
}
if((pcard->data.type & TYPE_PENDULUM) && (location == LOCATION_EXTRA) && (position & POS_FACEUP))
pduel->game_field->player[playerid].extra_p_count += 1;
if(proc)
pcard->set_status(STATUS_PROC_COMPLETE, TRUE);
interpreter::card2value(L, pcard);
......
......@@ -95,7 +95,7 @@ int32 scriptlib::duel_register_flag_effect(lua_State *L) {
peffect->type = EFFECT_TYPE_FIELD;
peffect->code = code;
peffect->reset_flag = reset;
peffect->flag = flag | EFFECT_FLAG_CANNOT_DISABLE | EFFECT_FLAG_PLAYER_TARGET | EFFECT_FLAG_FIELD_ONLY;
peffect->flag[0] = flag | EFFECT_FLAG_CANNOT_DISABLE | EFFECT_FLAG_PLAYER_TARGET | EFFECT_FLAG_FIELD_ONLY;
peffect->s_range = 1;
peffect->o_range = 0;
peffect->reset_count |= count & 0xff;
......@@ -453,6 +453,31 @@ int32 scriptlib::duel_sendto_deck(lua_State *L) {
pduel->game_field->core.subunits.begin()->type = PROCESSOR_SENDTO_S;
return lua_yield(L, 0);
}
int32 scriptlib::duel_sendto_extra(lua_State *L) {
check_action_permission(L);
check_param_count(L, 3);
card* pcard = 0;
group* pgroup = 0;
duel* pduel = 0;
if(check_param(L, PARAM_TYPE_CARD, 1, TRUE)) {
pcard = *(card**) lua_touserdata(L, 1);
pduel = pcard->pduel;
} else if(check_param(L, PARAM_TYPE_GROUP, 1, TRUE)) {
pgroup = *(group**) lua_touserdata(L, 1);
pduel = pgroup->pduel;
} else
luaL_error(L, "Parameter %d should be \"Card\" or \"Group\".", 1);
uint32 playerid = lua_tointeger(L, 2);
if(lua_isnil(L, 2) || (playerid != 0 && playerid != 1))
playerid = PLAYER_NONE;
uint32 reason = lua_tointeger(L, 3);
if(pcard)
pduel->game_field->send_to(pcard, pduel->game_field->core.reason_effect, reason, pduel->game_field->core.reason_player, playerid, LOCATION_EXTRA, 0, POS_FACEUP);
else
pduel->game_field->send_to(&(pgroup->container), pduel->game_field->core.reason_effect, reason, pduel->game_field->core.reason_player, playerid, LOCATION_EXTRA, 0, POS_FACEUP);
pduel->game_field->core.subunits.begin()->type = PROCESSOR_SENDTO_S;
return lua_yield(L, 0);
}
int32 scriptlib::duel_get_operated_group(lua_State *L) {
duel* pduel = interpreter::get_duel_info(L);
group* pgroup = pduel->new_group(pduel->game_field->core.operated_set);
......@@ -1489,7 +1514,7 @@ int32 scriptlib::duel_skip_phase(lua_State *L) {
peffect->type = EFFECT_TYPE_FIELD;
peffect->code = code;
peffect->reset_flag = (reset & 0xff) | RESET_PHASE | RESET_SELF_TURN;
peffect->flag = EFFECT_FLAG_CANNOT_DISABLE | EFFECT_FLAG_PLAYER_TARGET;
peffect->flag[0] = EFFECT_FLAG_CANNOT_DISABLE | EFFECT_FLAG_PLAYER_TARGET;
peffect->s_range = 1;
peffect->o_range = 0;
peffect->reset_count |= count & 0xff;
......@@ -2223,7 +2248,7 @@ int32 scriptlib::duel_set_target_card(lua_State *L) {
for(auto cit = pgroup->container.begin(); cit != pgroup->container.end(); ++cit)
(*cit)->create_relation(peffect);
}
if(peffect->flag & EFFECT_FLAG_CARD_TARGET) {
if(peffect->is_flag(EFFECT_FLAG_CARD_TARGET)) {
if(pcard) {
if(pcard->current.location & 0x30)
pduel->game_field->move_card(pcard->current.controler, pcard, pcard->current.location, 0);
......@@ -2321,8 +2346,8 @@ int32 scriptlib::duel_set_operation_info(lua_State *L) {
opt.op_player = playerid;
opt.op_param = param;
if(ct == 0 && pduel->game_field->core.continuous_chain.size()) {
field::chain_list::reverse_iterator clit = pduel->game_field->core.continuous_chain.rbegin();
chain::opmap::iterator omit = clit->opinfos.find(cate);
auto clit = pduel->game_field->core.continuous_chain.rbegin();
auto omit = clit->opinfos.find(cate);
if(omit != clit->opinfos.end() && omit->second.op_cards)
pduel->delete_group(omit->second.op_cards);
clit->opinfos[cate] = opt;
......@@ -2330,14 +2355,14 @@ int32 scriptlib::duel_set_operation_info(lua_State *L) {
if (pduel->game_field->core.current_chain.size() == 0)
return 0;
if(ct < 1 || ct > pduel->game_field->core.current_chain.size()) {
field::chain_array::reverse_iterator cait = pduel->game_field->core.current_chain.rbegin();
chain::opmap::iterator omit = cait->opinfos.find(cate);
auto cait = pduel->game_field->core.current_chain.rbegin();
auto omit = cait->opinfos.find(cate);
if(omit != cait->opinfos.end() && omit->second.op_cards)
pduel->delete_group(omit->second.op_cards);
cait->opinfos[cate] = opt;
} else {
chain* ch = &pduel->game_field->core.current_chain[ct - 1];
chain::opmap::iterator omit = ch->opinfos.find(cate);
auto omit = ch->opinfos.find(cate);
if(omit != ch->opinfos.end() && omit->second.op_cards)
pduel->delete_group(omit->second.op_cards);
ch->opinfos[cate] = opt;
......@@ -3210,7 +3235,7 @@ int32 scriptlib::duel_venom_swamp_check(lua_State *L) {
for (int32 i = 0; i < eset.size(); ++i) {
switch (eset[i]->code) {
case EFFECT_UPDATE_ATTACK: {
if (eset[i]->type & EFFECT_TYPE_SINGLE && !(eset[i]->flag & EFFECT_FLAG_SINGLE_RANGE))
if (eset[i]->type & EFFECT_TYPE_SINGLE && !(eset[i]->is_flag(EFFECT_FLAG_SINGLE_RANGE)))
up += eset[i]->get_value(pcard);
else
upc += eset[i]->get_value(pcard);
......@@ -3220,11 +3245,11 @@ int32 scriptlib::duel_venom_swamp_check(lua_State *L) {
}
case EFFECT_SET_ATTACK:
base = eset[i]->get_value(pcard);
if (eset[i]->type & EFFECT_TYPE_SINGLE && !(eset[i]->flag & EFFECT_FLAG_SINGLE_RANGE))
if (eset[i]->type & EFFECT_TYPE_SINGLE && !(eset[i]->is_flag(EFFECT_FLAG_SINGLE_RANGE)))
up = 0;
break;
case EFFECT_SET_ATTACK_FINAL:
if (eset[i]->type & EFFECT_TYPE_SINGLE && !(eset[i]->flag & EFFECT_FLAG_SINGLE_RANGE)) {
if (eset[i]->type & EFFECT_TYPE_SINGLE && !(eset[i]->is_flag(EFFECT_FLAG_SINGLE_RANGE))) {
base = eset[i]->get_value(pcard);
up = 0;
upc = 0;
......@@ -3269,14 +3294,14 @@ int32 scriptlib::duel_majestic_copy(lua_State *L) {
}
effect* peffect = eit->second;
if(!(peffect->type & 0x7c)) continue;
if(!(peffect->flag & EFFECT_FLAG_INITIAL)) continue;
if(!(peffect->is_flag(EFFECT_FLAG_INITIAL))) continue;
effect* ceffect = pduel->new_effect();
int32 ref = ceffect->ref_handle;
*ceffect = *peffect;
ceffect->ref_handle = ref;
ceffect->owner = pcard;
ceffect->handler = 0;
ceffect->flag &= ~EFFECT_FLAG_INITIAL;
ceffect->flag[0] &= ~EFFECT_FLAG_INITIAL;
ceffect->effect_owner = PLAYER_NONE;
if(peffect->condition) {
lua_rawgeti(L, LUA_REGISTRYINDEX, peffect->condition);
......@@ -3300,7 +3325,7 @@ int32 scriptlib::duel_majestic_copy(lua_State *L) {
if(ceffect->type & EFFECT_TYPE_TRIGGER_F) {
ceffect->type &= ~EFFECT_TYPE_TRIGGER_F;
ceffect->type |= EFFECT_TYPE_TRIGGER_O;
ceffect->flag |= EFFECT_FLAG_DELAY;
ceffect->flag[0] |= EFFECT_FLAG_DELAY;
}
if(ceffect->type & EFFECT_TYPE_QUICK_F) {
ceffect->type &= ~EFFECT_TYPE_QUICK_F;
......
......@@ -57,7 +57,7 @@ int32 scriptlib::effect_clone(lua_State *L) {
lua_rawgeti(L, LUA_REGISTRYINDEX, peffect->operation);
ceffect->operation = luaL_ref(L, LUA_REGISTRYINDEX);
}
if(peffect->value && (peffect->flag & EFFECT_FLAG_FUNC_VALUE)) {
if(peffect->value && (peffect->is_flag(EFFECT_FLAG_FUNC_VALUE))) {
lua_rawgeti(L, LUA_REGISTRYINDEX, peffect->value);
ceffect->value = luaL_ref(L, LUA_REGISTRYINDEX);
}
......@@ -70,7 +70,7 @@ int32 scriptlib::effect_reset(lua_State *L) {
effect* peffect = *(effect**) lua_touserdata(L, 1);
if(peffect->owner == 0)
return 0;
if(peffect->flag & EFFECT_FLAG_FIELD_ONLY)
if(peffect->is_flag(EFFECT_FLAG_FIELD_ONLY))
peffect->pduel->game_field->remove_effect(peffect);
else
peffect->handler->remove_effect(peffect);
......@@ -115,7 +115,7 @@ int32 scriptlib::effect_set_target_range(lua_State *L) {
int32 o = lua_tointeger(L, 3);
peffect->s_range = s;
peffect->o_range = o;
peffect->flag &= ~EFFECT_FLAG_ABSOLUTE_TARGET;
peffect->flag[0] &= ~EFFECT_FLAG_ABSOLUTE_TARGET;
return 0;
}
int32 scriptlib::effect_set_absolute_range(lua_State *L) {
......@@ -132,7 +132,7 @@ int32 scriptlib::effect_set_absolute_range(lua_State *L) {
peffect->s_range = o;
peffect->o_range = s;
}
peffect->flag |= EFFECT_FLAG_ABSOLUTE_TARGET;
peffect->flag[0] |= EFFECT_FLAG_ABSOLUTE_TARGET;
return 0;
}
int32 scriptlib::effect_set_count_limit(lua_State *L) {
......@@ -145,7 +145,7 @@ int32 scriptlib::effect_set_count_limit(lua_State *L) {
code = lua_tointeger(L, 3);
if(v == 0)
v = 1;
peffect->flag |= EFFECT_FLAG_COUNT_LIMIT;
peffect->flag[0] |= EFFECT_FLAG_COUNT_LIMIT;
peffect->reset_count |= ((v << 12) & 0xf000) | ((v << 8) & 0xf00);
peffect->count_code = code;
return 0;
......@@ -189,8 +189,10 @@ int32 scriptlib::effect_set_property(lua_State *L) {
check_param_count(L, 2);
check_param(L, PARAM_TYPE_EFFECT, 1);
effect* peffect = *(effect**) lua_touserdata(L, 1);
uint32 v = lua_tounsigned(L, 2);
peffect->flag = (peffect->flag & 0x4f) | (v & ~0x4f);
uint32 v1 = lua_tounsigned(L, 2);
uint32 v2 = lua_tounsigned(L, 3);
peffect->flag[0] = (peffect->flag[0] & 0x4f) | (v1 & ~0x4f);
peffect->flag[1] = v2;
return 0;
}
int32 scriptlib::effect_set_label(lua_State *L) {
......@@ -269,13 +271,13 @@ int32 scriptlib::effect_set_value(lua_State *L) {
check_param_count(L, 2);
check_param(L, PARAM_TYPE_EFFECT, 1);
effect* peffect = *(effect**) lua_touserdata(L, 1);
if(peffect->value && (peffect->flag & EFFECT_FLAG_FUNC_VALUE))
if(peffect->value && (peffect->is_flag(EFFECT_FLAG_FUNC_VALUE)))
luaL_unref(L, LUA_REGISTRYINDEX, peffect->value);
if (lua_isfunction(L, 2)) {
peffect->value = interpreter::get_function_handle(L, 2);
peffect->flag |= EFFECT_FLAG_FUNC_VALUE;
peffect->flag[0] |= EFFECT_FLAG_FUNC_VALUE;
} else {
peffect->flag &= ~EFFECT_FLAG_FUNC_VALUE;
peffect->flag[0] &= ~EFFECT_FLAG_FUNC_VALUE;
if(lua_isboolean(L, 2))
peffect->value = lua_toboolean(L, 2);
else
......@@ -341,8 +343,9 @@ int32 scriptlib::effect_get_property(lua_State *L) {
check_param(L, PARAM_TYPE_EFFECT, 1);
effect* peffect = *(effect**) lua_touserdata(L, 1);
if (peffect) {
lua_pushunsigned(L, peffect->flag);
return 1;
lua_pushunsigned(L, peffect->flag[0]);
lua_pushunsigned(L, peffect->flag[1]);
return 2;
}
return 0;
}
......@@ -437,7 +440,7 @@ int32 scriptlib::effect_get_value(lua_State *L) {
check_param_count(L, 1);
check_param(L, PARAM_TYPE_EFFECT, 1);
effect* peffect = *(effect**) lua_touserdata(L, 1);
if(peffect->flag & EFFECT_FLAG_FUNC_VALUE)
if(peffect->is_flag(EFFECT_FLAG_FUNC_VALUE))
interpreter::function2value(L, peffect->value);
else
lua_pushinteger(L, (int32)peffect->value);
......@@ -489,8 +492,9 @@ int32 scriptlib::effect_is_has_property(lua_State *L) {
check_param_count(L, 2);
check_param(L, PARAM_TYPE_EFFECT, 1);
effect* peffect = *(effect**) lua_touserdata(L, 1);
uint32 tflag = lua_tounsigned(L, 2);
if (peffect && (peffect->flag & tflag))
uint32 tflag1 = lua_tounsigned(L, 2);
uint32 tflag2 = lua_tounsigned(L, 3);
if (peffect && (!tflag1 || (peffect->flag[0] & tflag1)) && (!tflag2 || (peffect->flag[1] & tflag2)))
lua_pushboolean(L, 1);
else
lua_pushboolean(L, 0);
......
......@@ -127,6 +127,7 @@ void duelAdapter::new_tag_card(uint32 code, uint8 owner, uint8 location) {
pcard->current.controler = owner;
pcard->current.location = LOCATION_DECK;
pcard->current.sequence = pduel->game_field->player[owner].tag_list_main.size() - 1;
pcard->current.position = POS_FACEDOWN_DEFENCE;
break;
case LOCATION_EXTRA:
pduel->game_field->player[owner].tag_list_extra.push_back(pcard);
......@@ -134,6 +135,7 @@ void duelAdapter::new_tag_card(uint32 code, uint8 owner, uint8 location) {
pcard->current.controler = owner;
pcard->current.location = LOCATION_EXTRA;
pcard->current.sequence = pduel->game_field->player[owner].tag_list_extra.size() - 1;
pcard->current.position = POS_FACEDOWN_DEFENCE;
break;
}
}
......@@ -167,6 +169,7 @@ int32 duelAdapter::query_field_info( byte* buf) {
*buf++ = pduel->game_field->player[playerid].list_grave.size();
*buf++ = pduel->game_field->player[playerid].list_remove.size();
*buf++ = pduel->game_field->player[playerid].list_extra.size();
*buf++ = pduel->game_field->player[playerid].extra_p_count;
}
*buf++ = pduel->game_field->core.current_chain.size();
for(auto chit = pduel->game_field->core.current_chain.begin(); chit != pduel->game_field->core.current_chain.end(); ++chit) {
......
This diff is collapsed.
......@@ -308,7 +308,7 @@ int32 field::select_chain(uint16 step, uint8 playerid, uint8 spe_count, uint8 fo
card* pcard = peffect->handler;
if(!(peffect->type & EFFECT_TYPE_ACTIONS))
pcard = peffect->owner;
if(peffect->flag & EFFECT_FLAG_FIELD_ONLY)
if(peffect->is_flag(EFFECT_FLAG_FIELD_ONLY))
pduel->write_buffer32(1000000000 + pcard->data.code);
else
pduel->write_buffer32(pcard->data.code);
......
This diff is collapsed.
......@@ -328,6 +328,7 @@ public:
static int32 duel_special_summon_complete(lua_State *L);
static int32 duel_sendto_hand(lua_State *L);
static int32 duel_sendto_deck(lua_State *L);
static int32 duel_sendto_extra(lua_State *L);
static int32 duel_get_operated_group(lua_State *L);
static int32 duel_remove_counter(lua_State *L);
static int32 duel_is_can_remove_counter(lua_State *L);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment