/** * Gets a property of a units attack (__index metamethod). * - Arg 1: table containing the userdata containing the unit id. and a string identyfying the attack. * - Arg 2: string * - Ret 1: */ static int impl_unit_attack_set(lua_State *L) { attack_type& attack = luaW_checkweapon(L, 1); char const *m = luaL_checkstring(L, 2); modify_tstring_attrib("description", attack.set_name(value)); modify_string_attrib("name", attack.set_id(value)); modify_string_attrib("type", attack.set_type(value)); modify_string_attrib("icon", attack.set_icon(value)); modify_string_attrib("range", attack.set_range(value)); modify_int_attrib("damage", attack.set_damage(value)); modify_int_attrib("number", attack.set_num_attacks(value)); modify_int_attrib("attack_weight", attack.set_attack_weight(value)); modify_int_attrib("defense_weight", attack.set_defense_weight(value)); modify_int_attrib("accuracy", attack.set_accuracy(value)); modify_int_attrib("movement_used", attack.set_movement_used(value)); modify_int_attrib("parry", attack.set_parry(value)); if(strcmp(m, "specials") == 0) { attack.set_specials(luaW_checkconfig(L, 3)); return 0; } std::string err_msg = "unknown modifiable property of attack: "; err_msg += m; return luaL_argerror(L, 2, err_msg.c_str()); }
/** * Sets some data on a side (__newindex metamethod). * - Arg 1: full userdata containing the team. * - Arg 2: string containing the name of the property. * - Arg 3: something containing the attribute. */ static int impl_side_set(lua_State *L) { // Hidden metamethod, so arg1 has to be a pointer to a team. team &t = luaW_checkteam(L, 1); char const *m = luaL_checkstring(L, 2); // Find the corresponding attribute. modify_int_attrib("gold", t.set_gold(value)); modify_tstring_attrib("objectives", t.set_objectives(value, true)); //maybe add a setter for save_id too? modify_int_attrib("village_gold", t.set_village_gold(value)); modify_int_attrib("village_support", t.set_village_support(value)); modify_int_attrib("recall_cost", t.set_recall_cost(value)); modify_int_attrib("base_income", t.set_base_income(value)); modify_bool_attrib("objectives_changed", t.set_objectives_changed(value)); modify_bool_attrib("hidden", t.set_hidden(value)); modify_bool_attrib("scroll_to_leader", t.set_scroll_to_leader(value)); modify_tstring_attrib("user_team_name", t.change_team(t.team_name(), value)); modify_string_attrib("team_name", t.change_team(value, t.user_team_name())); modify_string_attrib("controller", t.change_controller_by_wml(value)); modify_string_attrib("color", t.set_color(value)); modify_string_attrib("defeat_condition", t.set_defeat_condition_string(value)); modify_int_attrib("carryover_percentage", t.set_carryover_percentage(value)); modify_bool_attrib("carryover_add", t.set_carryover_add(value)); modify_bool_attrib("lost", t.set_lost(value)); modify_bool_attrib("persistent", t.set_persistent(value)); modify_bool_attrib("suppress_end_turn_confirmation", t.set_no_turn_confirmation(value)); modify_bool_attrib("shroud", t.set_shroud(value)); modify_bool_attrib("fog", t.set_fog(value)); modify_string_attrib("flag_icon", t.set_flag_icon(value)); modify_string_attrib("share_vision", { team::SHARE_VISION v; if(v.parse(value)) { t.set_share_vision(v); } else { return luaL_argerror(L, 3, "Invalid share_vision value (should be 'all', 'none', or 'shroud')"); } });