}
// Find the chosen alternative for this block in this instance.
- size_t chosen_alternative = (chain_idx / block->cardinality_base) % block->alternatives.size();
- EffectType chosen_type = block->alternatives[chosen_alternative]->effect_type;
+ EffectType chosen_type = block->alternatives[block->chosen_alternative(chain_idx)]->effect_type;
Effect *effect;
switch (chosen_type) {
break;
}
default:
- effect = instantiate_effect(instantiation->chain.get(), block->alternatives[chosen_alternative]->effect_type);
+ effect = instantiate_effect(instantiation->chain.get(), chosen_type);
instantiation->chain->add_effect(effect, inputs);
break;
}
return 0;
}
+int Block_enable_if(lua_State *L)
+{
+ assert(lua_gettop(L) == 2);
+ Block *block = *(Block **)luaL_checkudata(L, 1, "Block");
+
+ if (block->alternatives.size() != 2 ||
+ block->alternatives[1]->effect_type != IDENTITY_EFFECT) {
+ luaL_error(L, "enable_if() called on something that wasn't added with add_optional_effect()");
+ }
+ bool enabled = checkbool(L, 2);
+ block->currently_chosen_alternative = enabled ? 0 : 1;
+ return 0;
+}
+
int Block_disable(lua_State *L)
{
assert(lua_gettop(L) == 1);