Пример #1
0
/**
**  Checks if dependencies are met.
**
**  @return true if the dependencies are met.
**
**  @param l  Lua state.
**  Argument 1: player
**  Argument 2: object which we want to check the dependencies of
*/
static int CclCheckDependency(lua_State *l)
{
	LuaCheckArgs(l, 2);
	const char *object = LuaToString(l, 2);
	lua_pop(l, 1);
	const int plynr = TriggerGetPlayer(l);
	if (plynr == -1) {
		LuaError(l, "bad player: %i" _C_ plynr);
	}
	const CPlayer *player = &Players[plynr];
	
	if (!strncmp(object, "unit-", 5)) {
		const CUnitType *unit_type = UnitTypeByIdent(object);
		if (!unit_type) {
			LuaError(l, "Invalid unit type: \"%s\"" _C_ object);
		}
		lua_pushboolean(l, CheckDependencies(unit_type, player));
	} else if (!strncmp(object, "upgrade-", 8)) {
		const CUpgrade *upgrade = CUpgrade::Get(object);
		if (!upgrade) {
			LuaError(l, "Invalid upgrade: \"%s\"" _C_ object);
		}
		lua_pushboolean(l, CheckDependencies(upgrade, player));
	} else {
		LuaError(l, "Invalid target of dependency check: \"%s\"" _C_ object);
	}

	return 1;
}
Пример #2
0
bool CheckDependencies(const CUpgrade *target, const CPlayer *player, bool ignore_units, bool is_predependency, bool is_neutral_use)
{
	if (!is_predependency && !CheckDependencies(target, player, ignore_units, true, is_neutral_use)) {
		return false;
	}
	
	if (UpgradeIdAllowed(*player, target->ID) != 'A' && !((is_predependency || is_neutral_use) && UpgradeIdAllowed(*player, target->ID) == 'R')) {
		return false;
	}

	if (player->Faction != -1 && PlayerRaces.Factions[player->Faction]->Type == FactionTypeHolyOrder) { // if the player is a holy order, and the upgrade is incompatible with its deity, don't allow it
		if (PlayerRaces.Factions[player->Faction]->HolyOrderDeity) {
			CUpgrade *deity_upgrade = PlayerRaces.Factions[player->Faction]->HolyOrderDeity->DeityUpgrade;
			if (deity_upgrade) {
				for (CUpgradeModifier *upgrade_modifier : target->UpgradeModifiers) {
					if (std::find(upgrade_modifier->RemoveUpgrades.begin(), upgrade_modifier->RemoveUpgrades.end(), deity_upgrade) != upgrade_modifier->RemoveUpgrades.end()) {
						return false;
					}
				}
				for (CUpgradeModifier *upgrade_modifier : deity_upgrade->UpgradeModifiers) {
					if (std::find(upgrade_modifier->RemoveUpgrades.begin(), upgrade_modifier->RemoveUpgrades.end(), target) != upgrade_modifier->RemoveUpgrades.end()) {
						return false;
					}
				}
			}
		}
	}
	
	if (is_predependency) {
		return !target->Predependency || target->Predependency->Check(player, ignore_units);
	} else {
		return !target->Dependency || target->Dependency->Check(player, ignore_units);
	}
}
vtkObject *
avtDatasetToDataObjectFilter::FetchArbitraryVTKObject(int dependencies,
                                             const char *name, int dom, int ts,
                                             const char *type)
{
    // If we can't cache it, then there's something in the pipeline that
    // subset the cells, transforms the data, etc.
    // So, even if there is something in the cache, we can't use it ... it
    // might be appropriate for a different pipeline, but not ours.
    bool canUse = CheckDependencies(dependencies);
    if (! canUse)
        return NULL;

    avtOriginatingSource *source = GetInput()->GetOriginatingSource();
    return source->FetchArbitraryVTKObject(name, dom, ts, type);
}
Пример #4
0
bool CheckDependencies(const CUpgrade *target, const CUnit *unit, bool ignore_units, bool is_predependency)
{
	if (!is_predependency && !CheckDependencies(target, unit, ignore_units, true)) {
		return false;
	}
	
	if (UpgradeIdAllowed(*unit->Player, target->ID) == 'F') {
		return false;
	}

	if (is_predependency) {
		return !target->Predependency || target->Predependency->Check(unit, ignore_units);
	} else {
		return !target->Dependency || target->Dependency->Check(unit, ignore_units);
	}
}
Пример #5
0
bool CheckDependencies(const CUnitType *target, const CPlayer *player, bool ignore_units, bool is_predependency, bool is_neutral_use)
{
	if (!is_predependency && !CheckDependencies(target, player, ignore_units, true, is_neutral_use)) {
		return false;
	}
	
	if (UnitIdAllowed(*player, target->Slot) == 0) {
		return false;
	}
	
	if (is_predependency) {
		return !target->Predependency || target->Predependency->Check(player, ignore_units);
	} else {
		return !target->Dependency || target->Dependency->Check(player, ignore_units);
	}
}
void
avtDatasetToDataObjectFilter::StoreArbitraryVTKObject(int dependencies,
                                           const char *name, int dom, int ts, 
                                           const char *type, vtkObject *obj)
{
    bool canUse = CheckDependencies(dependencies);
    if (! canUse)
    {
        if (DebugStream::Level5())
        {
            debug5 << "Cannot cache " << type << " for " << name << " because "
               << "dependencies were not satisfied.\n"
               << "This is an informational message, not an error." << endl;
        }
        return;
    }

    avtOriginatingSource *source = GetInput()->GetOriginatingSource();
    source->StoreArbitraryVTKObject(name, dom, ts, type, obj);
}
Пример #7
0
// converts the input opCPP format to c++ format
bool opDriver::Convert(const opParameters& p) {
    opMemoryTracker memorytracker;

    bool bResult = true;

    // run it
    try {
        // Validate the files specified on the command
        // line (oh and doh).
        if (!ValidateDialectFiles(p) || !ValidateFiles(p)) {
            return false;
        }

        if (p.CleanMode) {
            bResult = CleanMode(p) ? bResult : false;

            return bResult;
        }

        if (!bResult) return false;

        bool bSkipCompiling = false;

        // must be in normal mode to read dialects
        if (p.NormalMode) {
            // check dependencies
            bool bNewDependency = CheckDependencies();

            if (bNewDependency) {
                if (p.Verbose) {
                    Log("Dependency is out of date, forcing recompile ...");
                    Log("");
                }

                ForceCompile();
            }

            // if new dependency, we can't try to skip
            if (!bNewDependency && !p.Force) {
                // early skip detection:
                // if we have any dialect files out of date, we must continue
                if (DialectsCurrent()) {
                    // if we have any code files out of date, we must continue
                    if (CodeCurrent()) {
                        // or else, we can just get out of here...
                        bSkipCompiling = true;
                    }
                }
            }

            if (!bSkipCompiling) bResult = DialectMode(p) ? bResult : false;
        }

        if (!bSkipCompiling) {
            if (!bResult) return false;

            // validate dialect read parameters
            if (!opParameters::ValidateParameters()) return false;

            // validate registered dialects
            if (!DialectTracker::Validate()) {
                opError::Print();
                return false;
            }

            if (p.NormalMode) bResult = NormalMode(p) ? bResult : false;

            if (!bResult) return false;
        }

        // glob mode
        if (p.GlobMode) bResult = GlobMode(p) ? bResult : false;

        if (!bResult) return false;

        return true;
    } catch (opException::opCPP_Exception&) {
        opError::ExceptionError("opCPP");
    } catch (opException::opCPP_ParseException&) {
        opError::ExceptionError("opCPP Parse");
    } catch (opException::opCPP_FatalException&) {
        opError::ExceptionError("opCPP Fatal");
    } catch (opException::opCPP_AssertException& e) {
        opError::ExceptionError("Assert Failed (" + e.exceptionstring + ")");
    } catch (boost::filesystem::filesystem_error& fe) {
        opString errorstr = fe.what();
        opString who = "";
        errorstr.Replace(who, "Error: Improper path detected ");
        Log(errorstr);
        Log(opParameters::Get().GetCommandLineString());
    } catch (...) {
        opError::ExceptionError("Unhandled Unknown");
    }

    opException::CaughtException();

    return false;
}