forked from Mirrors/openclonk
added functionality for an AI player as the owner of animals
Animals should use SetCreatureControlled() and Find_OCF(OCF_Alvie) and Find_Hostile in their prey checks. Then, a scenario author could easily decide to make certain animals not attack the player. Or even animals attack each other. That's cool.lights3
parent
36c0d84c03
commit
ce3d7e4227
|
@ -0,0 +1,4 @@
|
|||
[DefCore]
|
||||
id=Library_CreatureControl
|
||||
Version=6,1
|
||||
Category=C4D_StaticBack
|
|
@ -0,0 +1,74 @@
|
|||
/**
|
||||
AnimalControl
|
||||
Cares about the ownership of non-player-controlled units.
|
||||
They are hostile to every other player.
|
||||
|
||||
global func GetCreaturePlayer()
|
||||
global func SetAnimalControlled()
|
||||
*/
|
||||
|
||||
static CreatureControl_animal_player;
|
||||
static CreatureControl_yet_to_set;
|
||||
static CreatureControl_initializing;
|
||||
|
||||
private func Enqueue(obj)
|
||||
{
|
||||
if(GetType(CreatureControl_yet_to_set) != C4V_Array)
|
||||
CreatureControl_yet_to_set = [];
|
||||
PushBack(CreatureControl_yet_to_set, obj);
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the hostile NPC player or creates it.
|
||||
Returns nil when the NPC player is currently joining.
|
||||
*/
|
||||
global func GetCreaturePlayer()
|
||||
{
|
||||
if(CreatureControl_animal_player != nil)
|
||||
return CreatureControl_animal_player;
|
||||
if(CreatureControl_initializing == true)
|
||||
return nil;
|
||||
|
||||
CreatureControl_initializing = true;
|
||||
CreateScriptPlayer("Creatures", RGB(50, 100, 50), 0, CSPF_NoScenarioInit | CSPF_NoEliminationCheck | CSPF_Invisible, Library_CreatureControl);
|
||||
return nil;
|
||||
}
|
||||
|
||||
/**
|
||||
Sets the owner of an object to the hostile NPC player.
|
||||
*/
|
||||
global func SetCreatureControlled()
|
||||
{
|
||||
if(!this) return false;
|
||||
var o = GetCreaturePlayer();
|
||||
if(o != nil) return SetOwner(o);
|
||||
|
||||
// No owner during creation. If the scripter overwrites it to a real owner, it's not changed later.
|
||||
SetOwner(NO_OWNER);
|
||||
Library_CreatureControl->Enqueue(this);
|
||||
}
|
||||
|
||||
public func InitializeScriptPlayer(plr, team)
|
||||
{
|
||||
CreatureControl_animal_player = plr;
|
||||
|
||||
if(CreatureControl_yet_to_set != nil)
|
||||
{
|
||||
for(var obj in CreatureControl_yet_to_set)
|
||||
{
|
||||
// Overwritten by the scripter?
|
||||
if (obj->GetOwner() != NO_OWNER) continue;
|
||||
obj->SetOwner(CreatureControl_animal_player);
|
||||
}
|
||||
}
|
||||
CreatureControl_yet_to_set = nil;
|
||||
|
||||
// hostile!
|
||||
for(var i = 0; i < GetPlayerCount(); ++i)
|
||||
{
|
||||
var p = GetPlayerByIndex(i);
|
||||
if(p == CreatureControl_animal_player) continue;
|
||||
SetHostility(p, plr, true, true, true);
|
||||
SetHostility(plr, p, true, true, true);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue