本文整理汇总了C++中CUnit::AssignToPlayer方法的典型用法代码示例。如果您正苦于以下问题:C++ CUnit::AssignToPlayer方法的具体用法?C++ CUnit::AssignToPlayer怎么用?C++ CUnit::AssignToPlayer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CUnit
的用法示例。
在下文中一共展示了CUnit::AssignToPlayer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CclUnit
//.........这里部分代码省略.........
lua_rawgeti(l, 2, j + 1);
lua_pushvalue(l, -1);
unit->Resource.Assigned = LuaToNumber(l, -1);
lua_pop(l, 1);
} else if (!strcmp(value, "resource-active")) {
lua_rawgeti(l, 2, j + 1);
lua_pushvalue(l, -1);
unit->Resource.Active = LuaToNumber(l, -1);
lua_pop(l, 1);
} else if (!strcmp(value, "units-boarded-count")) {
unit->BoardCount = LuaToNumber(l, 2, j + 1);
} else if (!strcmp(value, "units-contained")) {
int subargs;
int k;
lua_rawgeti(l, 2, j + 1);
if (!lua_istable(l, -1)) {
LuaError(l, "incorrect argument");
}
subargs = lua_rawlen(l, -1);
for (k = 0; k < subargs; ++k) {
lua_rawgeti(l, -1, k + 1);
CUnit *u = CclGetUnitFromRef(l);
lua_pop(l, 1);
u->AddInContainer(*unit);
}
lua_pop(l, 1);
} else if (!strcmp(value, "orders")) {
lua_rawgeti(l, 2, j + 1);
lua_pushvalue(l, -1);
CclParseOrders(l, *unit);
lua_pop(l, 1);
// now we know unit's action so we can assign it to a player
Assert(player != NULL);
unit->AssignToPlayer(*player);
if (unit->CurrentAction() == UnitActionBuilt) {
DebugPrint("HACK: the building is not ready yet\n");
// HACK: the building is not ready yet
unit->Player->UnitTypesCount[type->Slot]--;
if (unit->Active) {
unit->Player->UnitTypesAiActiveCount[type->Slot]--;
}
}
} else if (!strcmp(value, "critical-order")) {
lua_rawgeti(l, 2, j + 1);
lua_pushvalue(l, -1);
CclParseOrder(l, *unit , &unit->CriticalOrder);
lua_pop(l, 1);
} else if (!strcmp(value, "saved-order")) {
lua_rawgeti(l, 2, j + 1);
lua_pushvalue(l, -1);
CclParseOrder(l, *unit, &unit->SavedOrder);
lua_pop(l, 1);
} else if (!strcmp(value, "new-order")) {
lua_rawgeti(l, 2, j + 1);
lua_pushvalue(l, -1);
CclParseOrder(l, *unit, &unit->NewOrder);
lua_pop(l, 1);
} else if (!strcmp(value, "goal")) {
unit->Goal = &UnitManager.GetSlotUnit(LuaToNumber(l, 2, j + 1));
} else if (!strcmp(value, "auto-cast")) {
const char *s = LuaToString(l, 2, j + 1);
Assert(SpellTypeByIdent(s));
if (!unit->AutoCastSpell) {
unit->AutoCastSpell = new char[SpellTypeTable.size()];
memset(unit->AutoCastSpell, 0, SpellTypeTable.size());
}
示例2: CclSetUnitVariable
/**
** Set the value of the unit variable.
**
** @param l Lua state.
**
** @return The new value of the unit.
*/
static int CclSetUnitVariable(lua_State *l)
{
const int nargs = lua_gettop(l);
Assert(nargs >= 3 && nargs <= 5);
lua_pushvalue(l, 1);
CUnit *unit = CclGetUnit(l);
lua_pop(l, 1);
const char *const name = LuaToString(l, 2);
int value;
if (!strcmp(name, "Player")) {
unit->AssignToPlayer(Players[LuaToNumber(l, 3)]);
} else if (!strcmp(name, "RegenerationRate")) {
value = LuaToNumber(l, 3);
unit->Variable[HP_INDEX].Increase = std::min(unit->Variable[HP_INDEX].Max, value);
} else if (!strcmp(name, "IndividualUpgrade")) {
LuaCheckArgs(l, 4);
std::string upgrade_ident = LuaToString(l, 3);
bool has_upgrade = LuaToBoolean(l, 4);
if (CUpgrade::Get(upgrade_ident)) {
if (has_upgrade && unit->IndividualUpgrades[CUpgrade::Get(upgrade_ident)->ID] == false) {
IndividualUpgradeAcquire(*unit, CUpgrade::Get(upgrade_ident));
} else if (!has_upgrade && unit->IndividualUpgrades[CUpgrade::Get(upgrade_ident)->ID]) {
IndividualUpgradeLost(*unit, CUpgrade::Get(upgrade_ident));
}
} else {
LuaError(l, "Individual upgrade \"%s\" doesn't exist." _C_ upgrade_ident.c_str());
}
} else if (!strcmp(name, "Active")) {
bool ai_active = LuaToBoolean(l, 3);
if (ai_active != unit->Active) {
if (ai_active) {
unit->Player->UnitTypesAiActiveCount[unit->Type->Slot]++;
} else {
unit->Player->UnitTypesAiActiveCount[unit->Type->Slot]--;
if (unit->Player->UnitTypesAiActiveCount[unit->Type->Slot] < 0) { // if unit AI active count is negative, something wrong happened
fprintf(stderr, "Player %d has a negative %s AI active count of %d.\n", unit->Player->Index, unit->Type->Ident.c_str(), unit->Player->UnitTypesAiActiveCount[unit->Type->Slot]);
}
}
}
unit->Active = ai_active;
} else {
const int index = UnitTypeVar.VariableNameLookup[name];// User variables
if (index == -1) {
LuaError(l, "Bad variable name '%s'\n" _C_ name);
}
value = LuaToNumber(l, 3);
bool stats = false;
if (nargs == 5) {
stats = LuaToBoolean(l, 5);
}
if (stats) { // stat variables
const char *const type = LuaToString(l, 4);
if (!strcmp(type, "Value")) {
unit->Stats->Variables[index].Value = std::min(unit->Stats->Variables[index].Max, value);
} else if (!strcmp(type, "Max")) {
unit->Stats->Variables[index].Max = value;
} else if (!strcmp(type, "Increase")) {
unit->Stats->Variables[index].Increase = value;
} else if (!strcmp(type, "Enable")) {
unit->Stats->Variables[index].Enable = value;
} else {
LuaError(l, "Bad variable type '%s'\n" _C_ type);
}
} else if (nargs == 3) {
unit->Variable[index].Value = std::min(unit->Variable[index].Max, value);
} else {
const char *const type = LuaToString(l, 4);
if (!strcmp(type, "Value")) {
unit->Variable[index].Value = std::min(unit->Variable[index].Max, value);
} else if (!strcmp(type, "Max")) {
unit->Variable[index].Max = value;
} else if (!strcmp(type, "Increase")) {
unit->Variable[index].Increase = value;
} else if (!strcmp(type, "Enable")) {
unit->Variable[index].Enable = value;
} else {
LuaError(l, "Bad variable type '%s'\n" _C_ type);
}
}
}
lua_pushnumber(l, value);
return 1;
}