-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
889 additions
and
567 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
OpenRA.Mods.CA/Traits/Conditions/GrantConditionOnDockingHarvester.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#region Copyright & License Information | ||
/* | ||
* Copyright 2007-2020 The OpenRA Developers (see AUTHORS) | ||
* This file is part of OpenRA, which is free software. It is made | ||
* available to you under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation, either version 3 of | ||
* the License, or (at your option) any later version. For more | ||
* information, see COPYING. | ||
*/ | ||
#endregion | ||
|
||
using OpenRA.Mods.Common.Traits; | ||
using OpenRA.Traits; | ||
|
||
namespace OpenRA.Mods.CA.Traits | ||
{ | ||
public class GrantConditionOnDockingHarvesterInfo : TraitInfo, Requires<HarvesterInfo> | ||
{ | ||
[FieldLoader.Require] | ||
[GrantedConditionReference] | ||
[Desc("Condition to grant when docking.")] | ||
public readonly string Condition = null; | ||
|
||
public override object Create(ActorInitializer init) { return new GrantConditionOnDockingHarvester(init, this); } | ||
} | ||
|
||
public class GrantConditionOnDockingHarvester : INotifyHarvesterAction | ||
{ | ||
readonly Harvester harvester; | ||
readonly string conditionToGrant; | ||
readonly Actor self; | ||
int token = Actor.InvalidConditionToken; | ||
|
||
public GrantConditionOnDockingHarvester(ActorInitializer init, GrantConditionOnDockingHarvesterInfo info) | ||
{ | ||
conditionToGrant = info.Condition; | ||
self = init.Self; | ||
harvester = init.Self.Trait<Harvester>(); | ||
} | ||
|
||
void INotifyHarvesterAction.MovingToResources(Actor self, CPos targetCell) { } | ||
void INotifyHarvesterAction.MovingToRefinery(Actor self, Actor refineryActor) { } | ||
void INotifyHarvesterAction.MovementCancelled(Actor self) { } | ||
void INotifyHarvesterAction.Harvested(Actor self, string resourceType) { } | ||
|
||
void INotifyHarvesterAction.Docked() | ||
{ | ||
token = self.GrantCondition(conditionToGrant); | ||
} | ||
|
||
void INotifyHarvesterAction.Undocked() | ||
{ | ||
if (token != Actor.InvalidConditionToken) | ||
token = self.RevokeCondition(token); | ||
} | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
OpenRA.Mods.CA/Traits/Conditions/GrantConditionOnHarvesting.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#region Copyright & License Information | ||
/* | ||
* Copyright 2007-2020 The OpenRA Developers (see AUTHORS) | ||
* This file is part of OpenRA, which is free software. It is made | ||
* available to you under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation, either version 3 of | ||
* the License, or (at your option) any later version. For more | ||
* information, see COPYING. | ||
*/ | ||
#endregion | ||
|
||
using System.Linq; | ||
using OpenRA.Mods.Common.Traits; | ||
using OpenRA.Traits; | ||
|
||
namespace OpenRA.Mods.CA.Traits | ||
{ | ||
public class GrantConditionOnHarvestingInfo : PausableConditionalTraitInfo, Requires<HarvesterInfo> | ||
{ | ||
[FieldLoader.Require] | ||
[GrantedConditionReference] | ||
[Desc("Condition to grant while harvesting.")] | ||
public readonly string Condition = null; | ||
|
||
[Desc("Duration of harvesting condition.")] | ||
public readonly int Duration = 10; | ||
|
||
public override object Create(ActorInitializer init) { return new GrantConditionOnHarvesting(init, this); } | ||
} | ||
|
||
public class GrantConditionOnHarvesting : PausableConditionalTrait<GrantConditionOnHarvestingInfo>, ITick, ISync, INotifyCreated, INotifyHarvesterAction | ||
{ | ||
readonly GrantConditionOnHarvestingInfo info; | ||
readonly Harvester harvester; | ||
readonly string conditionToGrant; | ||
readonly Actor self; | ||
int token = Actor.InvalidConditionToken; | ||
IConditionTimerWatcher[] watchers; | ||
|
||
[Sync] | ||
public int Ticks { get; private set; } | ||
|
||
public GrantConditionOnHarvesting(ActorInitializer init, GrantConditionOnHarvestingInfo info) | ||
: base(info) | ||
{ | ||
this.info = info; | ||
conditionToGrant = info.Condition; | ||
self = init.Self; | ||
harvester = init.Self.Trait<Harvester>(); | ||
} | ||
|
||
protected override void Created(Actor self) | ||
{ | ||
watchers = self.TraitsImplementing<IConditionTimerWatcher>().Where(Notifies).ToArray(); | ||
|
||
base.Created(self); | ||
} | ||
|
||
void INotifyHarvesterAction.Harvested(Actor self, string resourceType) | ||
{ | ||
if (token == Actor.InvalidConditionToken) | ||
{ | ||
Ticks = info.Duration; | ||
token = self.GrantCondition(conditionToGrant); | ||
} | ||
} | ||
|
||
void RevokeCondition(Actor self) | ||
{ | ||
if (token != Actor.InvalidConditionToken) | ||
token = self.RevokeCondition(token); | ||
} | ||
|
||
void ITick.Tick(Actor self) | ||
{ | ||
if (IsTraitDisabled && token != Actor.InvalidConditionToken) | ||
RevokeCondition(self); | ||
|
||
if (IsTraitPaused || IsTraitDisabled) | ||
return; | ||
|
||
foreach (var w in watchers) | ||
w.Update(info.Duration, Ticks); | ||
|
||
if (token == Actor.InvalidConditionToken) | ||
return; | ||
|
||
if (--Ticks < 1) | ||
RevokeCondition(self); | ||
} | ||
|
||
void INotifyHarvesterAction.MovingToResources(Actor self, CPos targetCell) { } | ||
void INotifyHarvesterAction.MovingToRefinery(Actor self, Actor refineryActor) { } | ||
void INotifyHarvesterAction.MovementCancelled(Actor self) { } | ||
void INotifyHarvesterAction.Docked() { } | ||
void INotifyHarvesterAction.Undocked() { } | ||
|
||
bool Notifies(IConditionTimerWatcher watcher) { return watcher.Condition == Info.Condition; } | ||
} | ||
} |
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.