summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2014-11-19 17:44:13 -0800
committerBen Longbons <b.r.longbons@gmail.com>2014-11-19 18:19:45 -0800
commit711680d652a8db17c1b91428b6d6835f30dfb4fd (patch)
tree0d64c8314f8531e2a09c7dc5e242333ddec6582b
parent078028058d2e9fbcde2147eb4154830e08652066 (diff)
downloadtmwa-711680d652a8db17c1b91428b6d6835f30dfb4fd.tar.gz
tmwa-711680d652a8db17c1b91428b6d6835f30dfb4fd.tar.bz2
tmwa-711680d652a8db17c1b91428b6d6835f30dfb4fd.tar.xz
tmwa-711680d652a8db17c1b91428b6d6835f30dfb4fd.zip
Magically allow "break" within WITH_VAR
-rw-r--r--src/char/int_party.cpp4
-rw-r--r--src/char/inter.cpp2
-rw-r--r--src/compat/attr.hpp28
-rw-r--r--src/compat/attr_test.cpp50
-rw-r--r--src/compat/option.hpp9
-rw-r--r--src/compat/option_test.cpp4
-rw-r--r--src/generic/db.hpp4
-rw-r--r--src/map/atcommand.cpp10
-rw-r--r--src/map/battle.cpp4
-rw-r--r--src/map/chrif.cpp2
-rw-r--r--src/map/clif.cpp12
-rw-r--r--src/map/itemdb.cpp2
-rw-r--r--src/map/map.cpp2
-rw-r--r--src/map/mob.cpp2
-rw-r--r--src/map/party.cpp4
-rw-r--r--src/map/pc.cpp20
-rw-r--r--src/map/script-call.cpp2
-rw-r--r--src/map/script-fun.cpp24
-rw-r--r--src/map/script-parse.cpp2
-rw-r--r--src/map/trade.cpp4
-rw-r--r--src/sexpr/variant.hpp6
21 files changed, 136 insertions, 61 deletions
diff --git a/src/char/int_party.cpp b/src/char/int_party.cpp
index 9a9dbd9..5000ff2 100644
--- a/src/char/int_party.cpp
+++ b/src/char/int_party.cpp
@@ -327,7 +327,7 @@ void mapif_party_created(Session *s, AccountId account_id, Option<PartyPair> p_)
{
Packet_Fixed<0x3820> fixed_20;
fixed_20.account_id = account_id;
- if OPTION_IS_SOME(p, p_)
+ if OPTION_IS_SOME_NOLOOP(p, p_)
{
fixed_20.error = 0;
fixed_20.party_id = p.party_id;
@@ -524,7 +524,7 @@ static
void mapif_parse_PartyInfo(Session *s, PartyId party_id)
{
Option<P<PartyMost>> maybe_party_most = party_db.search(party_id);
- if OPTION_IS_SOME(party_most, maybe_party_most)
+ if OPTION_IS_SOME_NOLOOP(party_most, maybe_party_most)
mapif_party_info(s, PartyPair{party_id, party_most});
else
mapif_party_noinfo(s, party_id);
diff --git a/src/char/inter.cpp b/src/char/inter.cpp
index 03d027a..eccfc1b 100644
--- a/src/char/inter.cpp
+++ b/src/char/inter.cpp
@@ -270,7 +270,7 @@ void mapif_account_reg_reply(Session *s, AccountId account_id)
Packet_Head<0x3804> head_04;
head_04.account_id = account_id;
std::vector<Packet_Repeat<0x3804>> repeat_04;
- if OPTION_IS_SOME(reg, reg_)
+ if OPTION_IS_SOME_NOLOOP(reg, reg_)
{
repeat_04.resize(reg->reg_num);
assert (reg->reg_num < ACCOUNT_REG_NUM);
diff --git a/src/compat/attr.hpp b/src/compat/attr.hpp
index 5322a14..9ddf654 100644
--- a/src/compat/attr.hpp
+++ b/src/compat/attr.hpp
@@ -1,7 +1,7 @@
#pragma once
// attr.hpp - Attributes.
//
-// Copyright © 2013 Ben Longbons <b.r.longbons@gmail.com>
+// Copyright © 2013-2014 Ben Longbons <b.r.longbons@gmail.com>
//
// This file is part of The Mana World (Athena server)
//
@@ -31,7 +31,27 @@ namespace tmwa
#define JOIN(a, b) a##b
-#define WITH_VAR(ty, var, expr) \
- for (bool JOIN(var, _guard) = true; JOIN(var, _guard); ) \
- for (ty var = expr; JOIN(var, _guard); JOIN(var, _guard) = false)
+// first loop:
+// declare flag 'guard' (initially true)
+// declare flag 'broken' (initially false)
+// condition is 'guard' must be true, which is the case only for the first iteration
+// post checks 'broken' and if set, break the loop
+// second loop:
+// declare public 'var' variable
+// condition is that 'guard' must be true
+// post sets 'guard' to false to make this loop run only once
+// third loop:
+// enable broken flag; it will remain set if 'break' is in the loop
+// condition is that 'broken' must be true
+// post sets 'broken' to false, which then fails the condition
+// if user has a 'break' inside, then 'broken' will be true
+// in either case, go back to the second loop's post
+#define WITH_VAR_INLOOP(ty, var, expr) \
+ for (bool JOIN(var, _guard) = true, JOIN(var, _broken) = false; JOIN(var, _guard); ({if (JOIN(var, _broken)) { break; } })) \
+ for (ty var = expr; JOIN(var, _guard); JOIN(var, _guard) = false) \
+ for (JOIN(var, _broken) = true; JOIN(var, _broken); JOIN(var, _broken) = false)
+#define WITH_VAR_NOLOOP(ty, var, expr) \
+ for (bool JOIN(var, _guard) = true, JOIN(var, _broken) = false; JOIN(var, _guard); ({if (JOIN(var, _broken)) {abort();} })) \
+ for (ty var = expr; JOIN(var, _guard); JOIN(var, _guard) = false) \
+ for (JOIN(var, _broken) = true; JOIN(var, _broken); JOIN(var, _broken) = false)
} // namespace tmwa
diff --git a/src/compat/attr_test.cpp b/src/compat/attr_test.cpp
new file mode 100644
index 0000000..eb9042d
--- /dev/null
+++ b/src/compat/attr_test.cpp
@@ -0,0 +1,50 @@
+#include "attr.hpp"
+// attr_test.cpp - Tests for attributes
+//
+// Copyright © 2014 Ben Longbons <b.r.longbons@gmail.com>
+//
+// This file is part of The Mana World (Athena server)
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include <gtest/gtest.h>
+
+#include "../poison.hpp"
+
+
+namespace tmwa
+{
+TEST(attr, withvar)
+{
+ int x = 41;
+ for (int i = 0; i < 2; ++i)
+ {
+ WITH_VAR_NOLOOP(auto, y, x + 1)
+ {
+ x = y;
+ }
+ }
+ EXPECT_EQ(x, 43);
+ for (int i = 0; i < 2; ++i)
+ {
+ if (i == 1)
+ WITH_VAR_INLOOP(auto, y, i)
+ {
+ x = y;
+ break;
+ }
+ }
+ EXPECT_EQ(x, 1);
+}
+} // namespace tmwa
diff --git a/src/compat/option.hpp b/src/compat/option.hpp
index 1976589..7beef6f 100644
--- a/src/compat/option.hpp
+++ b/src/compat/option.hpp
@@ -424,9 +424,12 @@ namespace option
tmwa::option::option_unwrap(std::move(o)); \
}).maybe_ref_fun()
// immediately preceded by 'if'; not double-eval-safe
-#define OPTION_IS_SOME(var, expr) \
- ((expr).is_some()) \
- WITH_VAR(auto&, var, *(expr).ptr_or(nullptr))
+#define OPTION_IS_SOME_INLOOP(var, expr) \
+ ((expr).is_some()) \
+ WITH_VAR_INLOOP(auto&, var, *(expr).ptr_or(nullptr))
+#define OPTION_IS_SOME_NOLOOP(var, expr) \
+ ((expr).is_some()) \
+ WITH_VAR_NOLOOP(auto&, var, *(expr).ptr_or(nullptr))
} // namespace option
//using option::Option;
diff --git a/src/compat/option_test.cpp b/src/compat/option_test.cpp
index ac95424..f9cec0e 100644
--- a/src/compat/option_test.cpp
+++ b/src/compat/option_test.cpp
@@ -398,7 +398,7 @@ TEST(Option, unwrap)
v = None; TRY_UNWRAP(fcr(), v = Some(1));
v = None;
- if OPTION_IS_SOME(o, v)
+ if OPTION_IS_SOME_NOLOOP(o, v)
{
EXPECT_NE(o, o);
}
@@ -408,7 +408,7 @@ TEST(Option, unwrap)
}
v = Some(1);
- if OPTION_IS_SOME(o, v)
+ if OPTION_IS_SOME_NOLOOP(o, v)
{
EXPECT_EQ(o, 1);
}
diff --git a/src/generic/db.hpp b/src/generic/db.hpp
index 707d8ae..b0dcf0c 100644
--- a/src/generic/db.hpp
+++ b/src/generic/db.hpp
@@ -115,7 +115,7 @@ public:
V get(const K& k)
{
Option<Borrowed<V>> vp = impl.search(k);
- if OPTION_IS_SOME(v, vp)
+ if OPTION_IS_SOME_NOLOOP(v, vp)
{
return *v;
}
@@ -162,7 +162,7 @@ public:
Option<Borrowed<V>> get(const K& k)
{
Option<Borrowed<U>> up = impl.search(k);
- if OPTION_IS_SOME(u, up)
+ if OPTION_IS_SOME_NOLOOP(u, up)
{
return Some(borrow(*u->get()));
}
diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp
index 0b23ddd..bd1690d 100644
--- a/src/map/atcommand.cpp
+++ b/src/map/atcommand.cpp
@@ -375,7 +375,7 @@ bool atcommand_config_read(ZString cfgName)
continue;
}
Option<P<AtCommandInfo>> p_ = get_atcommandinfo_byname(w1);
- if OPTION_IS_SOME(p, p_)
+ if OPTION_IS_SOME_NOLOOP(p, p_)
{
p->level = GmLevel::from(static_cast<uint32_t>(atoi(w2.c_str())));
}
@@ -3406,7 +3406,7 @@ ATCE atcommand_partyrecall(Session *s, dumb_ptr<map_session_data> sd,
Option<PartyPair> p_ = party_searchname(party_name);
if (p_.is_none())
p_ = party_search(wrap<PartyId>(static_cast<uint32_t>(atoi(message.c_str()))));
- if OPTION_IS_SOME(p, p_)
+ if OPTION_IS_SOME_NOLOOP(p, p_)
{
count = 0;
for (io::FD i : iter_fds())
@@ -3588,7 +3588,7 @@ ATCE atcommand_partyspy(Session *s, dumb_ptr<map_session_data> sd,
Option<PartyPair> p_ = party_searchname(party_name);
if (p_.is_none())
p_ = party_search(wrap<PartyId>(static_cast<uint32_t>(atoi(message.c_str()))));
- if OPTION_IS_SOME(p, p_)
+ if OPTION_IS_SOME_NOLOOP(p, p_)
{
if (sd->partyspy == p.party_id)
{
@@ -3962,7 +3962,7 @@ ATCE atcommand_character_storage_list(Session *s, dumb_ptr<map_session_data> sd,
{
// you can look items only lower or same level
Option<P<Storage>> stor_ = account2storage2(pl_sd->status_key.account_id);
- if OPTION_IS_SOME(stor, stor_)
+ if OPTION_IS_SOME_NOLOOP(stor, stor_)
{
counter = 0;
count = 0;
@@ -4426,7 +4426,7 @@ ATCE atcommand_adjcmdlvl(Session *s, dumb_ptr<map_session_data>,
Option<P<AtCommandInfo>> it_ = atcommand_info.search(cmd);
{
- if OPTION_IS_SOME(it, it_)
+ if OPTION_IS_SOME_NOLOOP(it, it_)
{
it->level = newlev;
clif_displaymessage(s, "@command level changed."_s);
diff --git a/src/map/battle.cpp b/src/map/battle.cpp
index f852265..28c9d5f 100644
--- a/src/map/battle.cpp
+++ b/src/map/battle.cpp
@@ -1411,7 +1411,7 @@ struct Damage battle_calc_pc_weapon_attack(dumb_ptr<block_list> src,
if (widx.ok())
{
- if OPTION_IS_SOME(sdidw, sd->inventory_data[widx])
+ if OPTION_IS_SOME_NOLOOP(sdidw, sd->inventory_data[widx])
atkmin = atkmin * (80 + sdidw->wlv * 20) / 100;
}
if (sd->status.weapon == ItemLook::BOW)
@@ -1932,7 +1932,7 @@ ATK battle_weapon_attack(dumb_ptr<block_list> src, dumb_ptr<block_list> target,
ItemNameId weapon;
if (weapon_index.ok())
{
- if OPTION_IS_SOME(sdidw, sd->inventory_data[weapon_index])
+ if OPTION_IS_SOME_NOLOOP(sdidw, sd->inventory_data[weapon_index])
{
if (bool(sd->status.inventory[weapon_index].equip & EPOS::WEAPON))
{
diff --git a/src/map/chrif.cpp b/src/map/chrif.cpp
index dbdd401..7119ee8 100644
--- a/src/map/chrif.cpp
+++ b/src/map/chrif.cpp
@@ -967,7 +967,7 @@ void ladmin_itemfrob_c2(dumb_ptr<block_list> bl, ItemNameId source_id, ItemNameI
IFIX(pc->status.head_bottom);
Option<P<Storage>> stor_ = account2storage2(pc->status_key.account_id);
- if OPTION_IS_SOME(stor, stor_)
+ if OPTION_IS_SOME_NOLOOP(stor, stor_)
{
for (SOff0 j : SOff0::iter())
FIX(stor->storage_[j]);
diff --git a/src/map/clif.cpp b/src/map/clif.cpp
index 430d928..3a84e03 100644
--- a/src/map/clif.cpp
+++ b/src/map/clif.cpp
@@ -401,7 +401,7 @@ int clif_send(const Buffer& buf, dumb_ptr<block_list> bl, SendWho type)
p_ = party_search(sd->status.party_id);
}
}
- if OPTION_IS_SOME(p, p_)
+ if OPTION_IS_SOME_NOLOOP(p, p_)
{
for (int i = 0; i < MAX_PARTY; i++)
{
@@ -1262,17 +1262,19 @@ int clif_selllist(dumb_ptr<map_session_data> sd)
{
if (!sd->status.inventory[i].nameid)
continue;
- if OPTION_IS_SOME(sdidi, sd->inventory_data[i])
+ if OPTION_IS_SOME_NOLOOP(sdidi, sd->inventory_data[i])
{
int val = sdidi->value_sell;
if (val < 0)
- continue;
+ goto continue_outer;
Packet_Repeat<0x00c7> info;
info.ioff2 = i.shift();
info.base_price = val;
info.actual_price = val;
repeat_c7.push_back(info);
}
+ continue_outer:
+ ;
}
send_packet_repeatonly<0x00c7, 4, 10>(s, repeat_c7);
@@ -3636,7 +3638,7 @@ RecvResult clif_parse_GetCharNameRequest(Session *s, dumb_ptr<map_session_data>
{
Option<PartyPair> p_ = party_search(ssd->status.party_id);
- if OPTION_IS_SOME(p, p_)
+ if OPTION_IS_SOME_NOLOOP(p, p_)
{
party_name = p->name;
send = 1;
@@ -4188,7 +4190,7 @@ RecvResult clif_parse_EquipItem(Session *s, dumb_ptr<map_session_data> sd)
if (sd->npc_id)
return rv;
- if OPTION_IS_SOME(sdidi, sd->inventory_data[index])
+ if OPTION_IS_SOME_NOLOOP(sdidi, sd->inventory_data[index])
{
EPOS epos = fixed.epos_ignored;
if (sdidi->type == ItemType::ARROW)
diff --git a/src/map/itemdb.cpp b/src/map/itemdb.cpp
index 2f7ed30..dbe2dd6 100644
--- a/src/map/itemdb.cpp
+++ b/src/map/itemdb.cpp
@@ -92,7 +92,7 @@ Option<Borrowed<struct item_data>> itemdb_exists(ItemNameId nameid)
Borrowed<struct item_data> itemdb_search(ItemNameId nameid)
{
Option<P<struct item_data>> id_ = item_db.search(nameid);
- if OPTION_IS_SOME(id, id_)
+ if OPTION_IS_SOME_NOLOOP(id, id_)
return id;
P<struct item_data> id = item_db.init(nameid);
diff --git a/src/map/map.cpp b/src/map/map.cpp
index b5f08ea..784319f 100644
--- a/src/map/map.cpp
+++ b/src/map/map.cpp
@@ -1247,7 +1247,7 @@ void map_setcell(Borrowed<map_local> m, int x, int y, MapCell t)
int map_setipport(MapName name, IP4Address ip, int port)
{
Option<P<map_abstract>> md_ = maps_db.get(name);
- if OPTION_IS_SOME(md, md_)
+ if OPTION_IS_SOME_NOLOOP(md, md_)
{
if (md->gat)
{
diff --git a/src/map/mob.cpp b/src/map/mob.cpp
index 044d0b6..63db442 100644
--- a/src/map/mob.cpp
+++ b/src/map/mob.cpp
@@ -2591,7 +2591,7 @@ int mob_damage(dumb_ptr<block_list> src, dumb_ptr<mob_data> md, int damage,
if (it == ptv.end())
{
Option<PartyPair> p_ = party_search(pid);
- if OPTION_IS_SOME(p, p_)
+ if OPTION_IS_SOME_NOLOOP(p, p_)
{
if (p->exp != 0)
{
diff --git a/src/map/party.cpp b/src/map/party.cpp
index 8150743..0a9d2c5 100644
--- a/src/map/party.cpp
+++ b/src/map/party.cpp
@@ -213,7 +213,7 @@ static
PartyPair handle_info(const PartyPair sp)
{
Option<PartyPair> p_ = party_search(sp.party_id);
- if OPTION_IS_SOME(p, p_)
+ if OPTION_IS_SOME_NOLOOP(p, p_)
{
*p.party_most = *sp.party_most;
return p;
@@ -459,7 +459,7 @@ int party_member_leaved(PartyId party_id, AccountId account_id, CharName name)
{
dumb_ptr<map_session_data> sd = map_id2sd(account_to_block(account_id));
Option<PartyPair> p_ = party_search(party_id);
- if OPTION_IS_SOME(p, p_)
+ if OPTION_IS_SOME_NOLOOP(p, p_)
{
int i;
for (i = 0; i < MAX_PARTY; i++)
diff --git a/src/map/pc.cpp b/src/map/pc.cpp
index 95bdb8d..55e430a 100644
--- a/src/map/pc.cpp
+++ b/src/map/pc.cpp
@@ -555,14 +555,14 @@ int pc_setequipindex(dumb_ptr<map_session_data> sd)
sd->equip_index_maybe[j] = i;
if (bool(sd->status.inventory[i].equip & EPOS::WEAPON))
{
- if OPTION_IS_SOME(sdidi, sd->inventory_data[i])
+ if OPTION_IS_SOME_NOLOOP(sdidi, sd->inventory_data[i])
sd->weapontype1 = sdidi->look;
else
sd->weapontype1 = ItemLook::NONE;
}
if (bool(sd->status.inventory[i].equip & EPOS::SHIELD))
{
- if OPTION_IS_SOME(sdidi, sd->inventory_data[i])
+ if OPTION_IS_SOME_NOLOOP(sdidi, sd->inventory_data[i])
{
if (sdidi->type == ItemType::WEAPON)
{
@@ -1007,7 +1007,7 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first)
|| sd->equip_index_maybe[EQUIP::LEGS] == index))
continue;
- if OPTION_IS_SOME(sdidi, sd->inventory_data[index])
+ if OPTION_IS_SOME_NOLOOP(sdidi, sd->inventory_data[index])
{
sd->spellpower_bonus_target +=
sdidi->magic_bonus;
@@ -1042,7 +1042,7 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first)
&& (sd->equip_index_maybe[EQUIP::TORSO] == index
|| sd->equip_index_maybe[EQUIP::LEGS] == index))
continue;
- if OPTION_IS_SOME(sdidi, sd->inventory_data[index])
+ if OPTION_IS_SOME_NOLOOP(sdidi, sd->inventory_data[index])
{
sd->def += sdidi->def;
if (sdidi->type == ItemType::WEAPON)
@@ -1093,7 +1093,7 @@ int pc_calcstatus(dumb_ptr<map_session_data> sd, int first)
if (aidx.ok())
{
IOff0 index = aidx;
- if OPTION_IS_SOME(sdidi, sd->inventory_data[index])
+ if OPTION_IS_SOME_NOLOOP(sdidi, sd->inventory_data[index])
{ //まだ属性が入っていない
argrec_t arg[2] =
{
@@ -2120,7 +2120,7 @@ int pc_useitem(dumb_ptr<map_session_data> sd, IOff0 n)
if (!n.ok())
return 0;
- if OPTION_IS_SOME(sdidn, sd->inventory_data[n])
+ if OPTION_IS_SOME_NOLOOP(sdidn, sd->inventory_data[n])
{
amount = sd->status.inventory[n].amount;
if (!sd->status.inventory[n].nameid
@@ -3335,7 +3335,7 @@ int pc_damage(dumb_ptr<block_list> src, dumb_ptr<map_session_data> sd,
if (sd->status.party_id)
{ // on-the-fly party hp updates [Valaris]
Option<PartyPair> p_ = party_search(sd->status.party_id);
- if OPTION_IS_SOME(p, p_)
+ if OPTION_IS_SOME_NOLOOP(p, p_)
clif_party_hp(p, sd);
} // end addition [Valaris]
@@ -3703,7 +3703,7 @@ int pc_heal(dumb_ptr<map_session_data> sd, int hp, int sp)
if (sd->status.party_id)
{ // on-the-fly party hp updates [Valaris]
Option<PartyPair> p_ = party_search(sd->status.party_id);
- if OPTION_IS_SOME(p, p_)
+ if OPTION_IS_SOME_NOLOOP(p, p_)
clif_party_hp(p, sd);
} // end addition [Valaris]
@@ -4369,7 +4369,7 @@ int pc_equipitem(dumb_ptr<map_session_data> sd, IOff0 n, EPOS)
ItemNameId view_i;
ItemLook view_l = ItemLook::NONE;
// TODO: This is ugly.
- if OPTION_IS_SOME(sdidn, sd->inventory_data[n])
+ if OPTION_IS_SOME_NOLOOP(sdidn, sd->inventory_data[n])
{
bool look_not_weapon = sdidn->look == ItemLook::NONE;
bool equip_is_weapon = bool(sd->status.inventory[n].equip & EPOS::WEAPON);
@@ -4389,7 +4389,7 @@ int pc_equipitem(dumb_ptr<map_session_data> sd, IOff0 n, EPOS)
}
if (bool(sd->status.inventory[n].equip & EPOS::SHIELD))
{
- if OPTION_IS_SOME(sdidn, sd->inventory_data[n])
+ if OPTION_IS_SOME_NOLOOP(sdidn, sd->inventory_data[n])
{
if (sdidn->type == ItemType::WEAPON)
{
diff --git a/src/map/script-call.cpp b/src/map/script-call.cpp
index 212e0e3..abab24d 100644
--- a/src/map/script-call.cpp
+++ b/src/map/script-call.cpp
@@ -108,7 +108,7 @@ void get_val(dumb_ptr<map_session_data> sd, struct script_data *data)
else if (prefix == '$')
{
Option<P<RString>> s_ = mapregstr_db.search(u.reg);
- if OPTION_IS_SOME(s, s_)
+ if OPTION_IS_SOME_NOLOOP(s, s_)
str = *s;
}
else
diff --git a/src/map/script-fun.cpp b/src/map/script-fun.cpp
index c38f498..a291a11 100644
--- a/src/map/script-fun.cpp
+++ b/src/map/script-fun.cpp
@@ -122,7 +122,7 @@ void builtin_callfunc(ScriptState *st)
RString str = conv_str(st, &AARG(0));
Option<P<const ScriptBuffer>> scr_ = userfunc_db.get(str);
- if OPTION_IS_SOME(scr, scr_)
+ if OPTION_IS_SOME_NOLOOP(scr, scr_)
{
int j = 0;
assert (st->start + 3 == st->end);
@@ -720,7 +720,7 @@ void builtin_countitem(ScriptState *st)
{
ZString name = ZString(conv_str(st, data));
Option<P<struct item_data>> item_data_ = itemdb_searchname(name);
- if OPTION_IS_SOME(item_data, item_data_)
+ if OPTION_IS_SOME_NOLOOP(item_data, item_data_)
nameid = item_data->nameid;
}
else
@@ -763,7 +763,7 @@ void builtin_checkweight(ScriptState *st)
{
ZString name = ZString(conv_str(st, data));
Option<P<struct item_data>> item_data_ = itemdb_searchname(name);
- if OPTION_IS_SOME(item_data, item_data_)
+ if OPTION_IS_SOME_NOLOOP(item_data, item_data_)
nameid = item_data->nameid;
}
else
@@ -808,7 +808,7 @@ void builtin_getitem(ScriptState *st)
{
ZString name = ZString(conv_str(st, data));
Option<P<struct item_data>> item_data_ = itemdb_searchname(name);
- if OPTION_IS_SOME(item_data, item_data_)
+ if OPTION_IS_SOME_NOLOOP(item_data, item_data_)
nameid = item_data->nameid;
}
else
@@ -861,7 +861,7 @@ void builtin_makeitem(ScriptState *st)
{
ZString name = ZString(conv_str(st, data));
Option<P<struct item_data>> item_data_ = itemdb_searchname(name);
- if OPTION_IS_SOME(item_data, item_data_)
+ if OPTION_IS_SOME_NOLOOP(item_data, item_data_)
nameid = item_data->nameid;
}
else
@@ -905,7 +905,7 @@ void builtin_delitem(ScriptState *st)
{
ZString name = ZString(conv_str(st, data));
Option<P<struct item_data>> item_data_ = itemdb_searchname(name);
- if OPTION_IS_SOME(item_data, item_data_)
+ if OPTION_IS_SOME_NOLOOP(item_data, item_data_)
nameid = item_data->nameid;
}
else
@@ -1080,7 +1080,7 @@ void builtin_getequipid(ScriptState *st)
if (i.ok())
{
Option<P<struct item_data>> item_ = sd->inventory_data[i];
- if OPTION_IS_SOME(item, item_)
+ if OPTION_IS_SOME_NOLOOP(item, item_)
push_int<ScriptDataInt>(st->stack, unwrap<ItemNameId>(item->nameid));
else
push_int<ScriptDataInt>(st->stack, 0);
@@ -1109,7 +1109,7 @@ void builtin_getequipname(ScriptState *st)
if (i.ok())
{
Option<P<struct item_data>> item_ = sd->inventory_data[i];
- if OPTION_IS_SOME(item, item_)
+ if OPTION_IS_SOME_NOLOOP(item, item_)
buf = STRPRINTF("%s-[%s]"_fmt, pos_str[num - 1], item->jname);
else
buf = STRPRINTF("%s-[%s]"_fmt, pos_str[num - 1], pos_str[10]);
@@ -1832,7 +1832,7 @@ void builtin_getareadropitem(ScriptState *st)
{
ZString name = ZString(conv_str(st, data));
Option<P<struct item_data>> item_data_ = itemdb_searchname(name);
- if OPTION_IS_SOME(item_data, item_data_)
+ if OPTION_IS_SOME_NOLOOP(item_data, item_data_)
item = item_data->nameid;
}
else
@@ -2013,7 +2013,7 @@ void builtin_setmapflag(ScriptState *st)
int i = conv_num(st, &AARG(1));
MapFlag mf = map_flag_from_int(i);
Option<P<map_local>> m_ = map_mapname2mapid(str);
- if OPTION_IS_SOME(m, m_)
+ if OPTION_IS_SOME_NOLOOP(m, m_)
{
m->flag.set(mf, 1);
}
@@ -2026,7 +2026,7 @@ void builtin_removemapflag(ScriptState *st)
int i = conv_num(st, &AARG(1));
MapFlag mf = map_flag_from_int(i);
Option<P<map_local>> m_ = map_mapname2mapid(str);
- if OPTION_IS_SOME(m, m_)
+ if OPTION_IS_SOME_NOLOOP(m, m_)
{
m->flag.set(mf, 0);
}
@@ -2041,7 +2041,7 @@ void builtin_getmapflag(ScriptState *st)
int i = conv_num(st, &AARG(1));
MapFlag mf = map_flag_from_int(i);
Option<P<map_local>> m_ = map_mapname2mapid(str);
- if OPTION_IS_SOME(m, m_)
+ if OPTION_IS_SOME_NOLOOP(m, m_)
{
r = m->flag.get(mf);
}
diff --git a/src/map/script-parse.cpp b/src/map/script-parse.cpp
index 878397f..47e0def 100644
--- a/src/map/script-parse.cpp
+++ b/src/map/script-parse.cpp
@@ -134,7 +134,7 @@ Option<Borrowed<str_data_t>> search_strp(XString p)
Borrowed<str_data_t> add_strp(XString p)
{
Option<P<str_data_t>> rv_ = search_strp(p);
- if OPTION_IS_SOME(rv, rv_)
+ if OPTION_IS_SOME_NOLOOP(rv, rv_)
return rv;
RString p2 = p;
diff --git a/src/map/trade.cpp b/src/map/trade.cpp
index b5e19be..5ec63c9 100644
--- a/src/map/trade.cpp
+++ b/src/map/trade.cpp
@@ -174,7 +174,7 @@ void trade_tradeadditem(dumb_ptr<map_session_data> sd, IOff2 index, int amount)
sd->status.inventory[index.unshift()].nameid)
continue;
- if OPTION_IS_SOME(id, target_sd->inventory_data[i])
+ if OPTION_IS_SOME_INLOOP(id, target_sd->inventory_data[i])
{
if (id->type != ItemType::WEAPON
&& id->type != ItemType::ARMOR
@@ -231,7 +231,7 @@ void trade_tradeadditem(dumb_ptr<map_session_data> sd, IOff2 index, int amount)
sd->status.
inventory[sd->deal_item_index[trade_i].unshift()].nameid)
continue;
- if OPTION_IS_SOME(id, target_sd->inventory_data[i])
+ if OPTION_IS_SOME_INLOOP(id, target_sd->inventory_data[i])
{
if (id->type != ItemType::WEAPON
&& id->type != ItemType::ARMOR
diff --git a/src/sexpr/variant.hpp b/src/sexpr/variant.hpp
index ecf0237..287a5f0 100644
--- a/src/sexpr/variant.hpp
+++ b/src/sexpr/variant.hpp
@@ -35,13 +35,13 @@ namespace tmwa
{
namespace sexpr
{
-#define MATCH(expr) \
- WITH_VAR(auto&&, _match_var, expr) \
+#define MATCH(expr) \
+ WITH_VAR_NOLOOP(auto&&, _match_var, expr) \
switch (tmwa::sexpr::VariantFriend::get_state(_match_var))
#define TYPED_CASE(ty, var, look) \
break; \
case tmwa::sexpr::VariantFriend::get_state_for<look, decltype(_match_var)>(): \
- WITH_VAR(ty, var, tmwa::sexpr::VariantFriend::unchecked_get<look>(_match_var))
+ WITH_VAR_INLOOP(ty, var, tmwa::sexpr::VariantFriend::unchecked_get<look>(_match_var))
#define CASE(ty, var) TYPED_CASE(ty, var, std::remove_const<std::remove_reference<ty>::type>::type)
template<class... T>