Page MenuHomeWildfire Games

Revisit animal roaming
ClosedPublic

Authored by mimo on Sep 22 2017, 9:34 PM.

Details

Reviewers
bb
Group Reviewers
Restricted Owners Package(Owns No Changed Paths)
Commits
rP20223: Revisit the random walk of animals
Summary

I was tired of looking at the roaming of 0AD animals, with these abrupt changes of directions which does not look natural at all. So here is an attempt to improve it.

Test Plan

Compare with the current animal roaming (best in african maps with lot of animals, but also on sea for whales) to see which one looks more "natural".

Diff Detail

Repository
rP 0 A.D. Public Repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

mimo created this revision.Sep 22 2017, 9:34 PM
Vulcan added a subscriber: Vulcan.Sep 22 2017, 10:58 PM

Build is green

Updating workspaces.
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (307 tests)...................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (307 tests)...................................................................................................................................................................................................................................................................................................................OK!
Checking XML files...

http://jenkins-master:8080/job/phabricator/2064/ for more details.

Executing section Default...
Executing section Source...
Executing section JS...
|    | [NORMAL] ESLintBear (no-else-return):
|    | Unnecessary 'else' after 'return'.
|----|    | /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/components/UnitAI.js
| 911| 911| 					this.FinishOrder();
| 912| 912| 					return;
| 913| 913| 				}
| 914|    |-				else
| 915|    |-				{
|    | 914|+				
| 916| 915| 					// Out of range; move there in formation
| 917| 916| 					if (this.MoveToGarrisonRange(msg.data.target))
| 918| 917| 					{
| 919| 918| 						this.SetNextState("GARRISON.APPROACHING");
| 920| 919| 						return;
| 921| 920| 					}
| 922|    |-				}
|    | 921|+				
| 923| 922| 			}
| 924| 923| 
| 925| 924| 			this.SetNextState("GARRISON.GARRISONING");
|    | [NORMAL] ESLintBear (no-unneeded-ternary):
|    | Unnecessary use of boolean literals in conditional expression.
|----|    | /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/components/UnitAI.js
|1958|1958| 					// TODO: we should probably only bother syncing projectile attacks, not melee
|1959|1959| 
|1960|1960| 					// If using a non-default prepare time, re-sync the animation when the timer runs.
|1961|    |-					this.resyncAnimation = (prepare != this.attackTimers.prepare) ? true : false;
|    |1961|+					this.resyncAnimation = (prepare != this.attackTimers.prepare);
|1962|1962| 
|1963|1963| 					this.FaceTowardsTarget(this.order.data.target);
|1964|1964| 
|    | [NORMAL] ESLintBear (no-else-return):
|    | Unnecessary 'else' after 'return'.
|----|    | /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/components/UnitAI.js
|2184|2184| 							this.PerformGather(nearby, false, false);
|2185|2185| 							return true;
|2186|2186| 						}
|2187|    |-						else
|2188|    |-						{
|    |2187|+						
|2189|2188| 							// It's probably better in this case, to avoid units getting stuck around a dropsite
|2190|2189| 							// in a "Target is far away, full, nearby are no good resources, return to dropsite" loop
|2191|2190| 							// to order it to GatherNear the resource position.
|2206|2205| 									return true;
|2207|2206| 								}
|2208|2207| 							}
|2209|    |-						}
|    |2208|+						
|2210|2209| 						return true;
|2211|2210| 					}
|2212|2211| 					return false;
|    | [NORMAL] ESLintBear (no-else-return):
|    | Unnecessary 'else' after 'return'.
|----|    | /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/components/UnitAI.js
|2196|2196| 								this.GatherNearPosition(pos.x, pos.z, oldType, oldTemplate);
|2197|2197| 								return true;
|2198|2198| 							}
|2199|    |-							else
|2200|    |-							{
|    |2199|+							
|2201|2200| 								// we're kind of stuck here. Return resource.
|2202|2201| 								var nearby = this.FindNearestDropsite(oldType.generic);
|2203|2202| 								if (nearby)
|2205|2204| 									this.PushOrderFront("ReturnResource", { "target": nearby, "force": false });
|2206|2205| 									return true;
|2207|2206| 								}
|2208|    |-							}
|    |2207|+							
|2209|2208| 						}
|2210|2209| 						return true;
|2211|2210| 					}
|    | [NORMAL] ESLintBear (no-unneeded-ternary):
|    | Unnecessary use of boolean literals in conditional expression.
|----|    | /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/components/UnitAI.js
|2580|2580| 					this.StartTimer(prepare, this.healTimers.repeat);
|2581|2581| 
|2582|2582| 					// If using a non-default prepare time, re-sync the animation when the timer runs.
|2583|    |-					this.resyncAnimation = (prepare != this.healTimers.prepare) ? true : false;
|    |2583|+					this.resyncAnimation = (prepare != this.healTimers.prepare);
|2584|2584| 
|2585|2585| 					this.FaceTowardsTarget(this.order.data.target);
|2586|2586| 				},
|    | [NORMAL] ESLintBear (no-unneeded-ternary):
|    | Unnecessary use of boolean literals in conditional expression.
|----|    | /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/components/UnitAI.js
|3396|3396| 
|3397|3397| UnitAI.prototype.IsAnimal = function()
|3398|3398| {
|3399|    |-	return (this.template.NaturalBehaviour ? true : false);
|    |3399|+	return (!!this.template.NaturalBehaviour);
|3400|3400| };
|3401|3401| 
|3402|3402| UnitAI.prototype.IsDangerousAnimal = function()
|    | [NORMAL] ESLintBear (no-else-return):
|    | Unnecessary 'else' after 'return'.
|----|    | /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/components/UnitAI.js
|3715|3715| 		// Otherwise we've successfully processed a new order
|3716|3716| 		return true;
|3717|3717| 	}
|3718|    |-	else
|3719|    |-	{
|    |3718|+	
|3720|3719| 		this.SetNextState("IDLE");
|3721|3720| 
|3722|3721| 		Engine.PostMessage(this.entity, MT_UnitAIOrderDataChanged, { "to": this.GetOrderData() });
|3737|3736| 		}
|3738|3737| 
|3739|3738| 		return false;
|3740|    |-	}
|    |3739|+	
|3741|3740| };
|3742|3741| 
|3743|3742| /**
|    | [NORMAL] ESLintBear (no-multi-spaces):
|    | Multiple spaces found before 'Engine'.
|----|    | /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/components/UnitAI.js
|4772|4772| 	// If we are guarding/escorting, don't abandon as long as the guarded unit is in target range of the attacker
|4773|4773| 	if (this.isGuardOf)
|4774|4774| 	{
|4775|    |-		var cmpUnitAI =  Engine.QueryInterface(target, IID_UnitAI);
|    |4775|+		var cmpUnitAI = Engine.QueryInterface(target, IID_UnitAI);
|4776|4776| 		var cmpAttack = Engine.QueryInterface(target, IID_Attack);
|4777|4777| 		if (cmpUnitAI && cmpAttack &&
|4778|4778| 		    cmpAttack.GetAttackTypes().some(type => cmpUnitAI.CheckTargetAttackRange(this.isGuardOf, type)))
|    | [NORMAL] ESLintBear (no-multi-spaces):
|    | Multiple spaces found before 'Engine'.
|----|    | /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/components/UnitAI.js
|4819|4819| 	// If we are guarding/escorting, chase at least as long as the guarded unit is in target range of the attacker
|4820|4820| 	if (this.isGuardOf)
|4821|4821| 	{
|4822|    |-		var cmpUnitAI =  Engine.QueryInterface(target, IID_UnitAI);
|    |4822|+		var cmpUnitAI = Engine.QueryInterface(target, IID_UnitAI);
|4823|4823| 		var cmpAttack = Engine.QueryInterface(target, IID_Attack);
|4824|4824| 		if (cmpUnitAI && cmpAttack &&
|4825|4825| 		    cmpAttack.GetAttackTypes().some(type => cmpUnitAI.CheckTargetAttackRange(this.isGuardOf, type)))
|    | [NORMAL] ESLintBear (no-else-return):
|    | Unnecessary 'else' after 'return'.
|----|    | /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/components/UnitAI.js
|4993|4993| 	{
|4994|4994| 		if (this.isGuardOf == target && this.order && this.order.type == "Guard")
|4995|4995| 			return;
|4996|    |-		else
|4997|    |-			this.RemoveGuard();
|    |4996|+		this.RemoveGuard();
|4998|4997| 	}
|4999|4998| 
|5000|4999| 	this.AddOrder("Guard", { "target": target, "force": false }, queued);
|    | [NORMAL] ESLintBear (no-undef-init):
|    | It's not necessary to initialize 'lastPos' to undefined.
|----|    | /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/components/UnitAI.js
|5241|5241| 
|5242|5242| 	// Remember the position of our target, if any, in case it disappears
|5243|5243| 	// later and we want to head to its last known position
|5244|    |-	var lastPos = undefined;
|    |5244|+	var lastPos;
|5245|5245| 	var cmpPosition = Engine.QueryInterface(target, IID_Position);
|5246|5246| 	if (cmpPosition && cmpPosition.IsInWorld())
|5247|5247| 		lastPos = cmpPosition.GetPosition();

binaries/data/mods/public/simulation/components/UnitAI.js
|2482| »   »   »   »   »   »   let·nearby·=·this.FindNearestDropsite(resourceType.generic);
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'nearby' is already declared in the upper scope.

binaries/data/mods/public/simulation/components/UnitAI.js
|3904| »   var·isWorkType·=·type·=>·type·==·"Gather"·||·type·==·"Trade"·||·type·==·"Repair"·||·type·==·"ReturnResource";
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'type' is already declared in the upper scope.

binaries/data/mods/public/simulation/components/UnitAI.js
|4229| »   »   let·cmpOwnership·=·Engine.QueryInterface(ent,·IID_Ownership);
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'cmpOwnership' is already declared in the upper scope.

binaries/data/mods/public/simulation/components/UnitAI.js
|4694| »   var·target·=·ents.find(target·=>·this.CanAttack(target,·forceResponse));
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'target' is already declared in the upper scope.

binaries/data/mods/public/simulation/components/UnitAI.js
|4709| »   var·target·=·ents.find(target·=>
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'target' is already declared in the upper scope.

binaries/data/mods/public/simulation/components/UnitAI.js
|4755| »   var·ent·=·ents.find(ent·=>·this.CanHeal(ent));
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'ent' is already declared in the upper scope.

binaries/data/mods/public/simulation/components/UnitAI.js
|4778| »   »   ····cmpAttack.GetAttackTypes().some(type·=>·cmpUnitAI.CheckTargetAttackRange(this.isGuardOf,·type)))
|    | [NORMAL] ESLintBear (no-shadow):
|    | 'type' is already declared in the upper scope.

binaries/data/mods/public/simulation/components/UnitAI.js
| 363| »   »   ····&&·(this.lastShorelinePosition.z·==·cmpPosition.GetPosition().z))
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '&&'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|1951| »   »   »   »   »   »   var·cmpFormation·=·Engine.QueryInterface(this.formationController,·IID_Formation);
|    | [NORMAL] JSHintBear:
|    | 'cmpFormation' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|2177| »   »   »   »   »   »   »   »   ·&&·((type.generic·==·"treasure"·&&·oldType.generic·==·"treasure")
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '&&'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|2178| »   »   »   »   »   »   »   »   ·||·(type.specific·==·oldType.specific
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '||'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|2179| »   »   »   »   »   »   »   »   ·&&·(type.specific·!=·"meat"·||·oldTemplate·==·template)))
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '&&'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|2202| »   »   »   »   »   »   »   »   var·nearby·=·this.FindNearestDropsite(oldType.generic);
|    | [NORMAL] JSHintBear:
|    | 'nearby' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|2242| »   »   »   »   »   »   »   »   &&·((type.generic·==·"treasure"·&&·oldType.generic·==·"treasure")
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '&&'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|2243| »   »   »   »   »   »   »   »   ||·(type.specific·==·oldType.specific
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '||'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|2244| »   »   »   »   »   »   »   »   &&·(type.specific·!=·"meat"·||·oldTemplate·==·template)))
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '&&'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|2288| »   »   »   »   »   »   »   ||·(type.specific·==·resourceType.specific
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '||'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|2289| »   »   »   »   »   »   »   &&·(type.specific·!=·"meat"·||·resourceTemplate·==·template))
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '&&'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|2305| »   »   »   »   »   var·nearby·=·this.FindNearestDropsite(resourceType.generic);
|    | [NORMAL] JSHintBear:
|    | 'nearby' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|2477| »   »   »   »   »   var·cmpResourceGatherer·=·Engine.QueryInterface(this.entity,·IID_ResourceGatherer);
|    | [NORMAL] JSHintBear:
|    | 'cmpResourceGatherer' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|2493| »   »   »   »   »   var·nearby·=·this.FindNearbyResource(function·(ent,·type,·template)·{
|    | [NORMAL] JSHintBear:
|    | 'nearby' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|2496| »   »   »   »   »   »   »   ||·(type.specific·==·resourceType.specific
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '||'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|2497| »   »   »   »   »   »   »   &&·(type.specific·!=·"meat"·||·resourceTemplate·==·template))
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '&&'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|2517| »   »   »   »   »   var·nearby·=·this.FindNearestDropsite(resourceType.generic);
|    | [NORMAL] JSHintBear:
|    | 'nearby' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|2701| »   »   »   »   »   var·cmpResourceGatherer·=·Engine.QueryInterface(this.entity,·IID_ResourceGatherer);
|    | [NORMAL] JSHintBear:
|    | 'cmpResourceGatherer' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|2896| »   »   »   »   »   var·cmpResourceDropsite·=·Engine.QueryInterface(msg.data.newentity,·IID_ResourceDropsite);
|    | [NORMAL] JSHintBear:
|    | 'cmpResourceDropsite' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|2991| »   »   »   »   »   »   var·target·=·this.alertGarrisoningTarget;
|    | [NORMAL] JSHintBear:
|    | 'target' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|2995| »   »   »   »   »   if·(this.CanGarrison(target))
|    | [NORMAL] JSHintBear:
|    | 'target' used out of scope.

binaries/data/mods/public/simulation/components/UnitAI.js
|2998| »   »   »   »   »   »   if·(this.CheckGarrisonRange(target))
|    | [NORMAL] JSHintBear:
|    | 'target' used out of scope.

binaries/data/mods/public/simulation/components/UnitAI.js
|3000| »   »   »   »   »   »   »   var·cmpGarrisonHolder·=·Engine.QueryInterface(target,·IID_GarrisonHolder);
|    | [NORMAL] JSHintBear:
|    | 'target' used out of scope.

binaries/data/mods/public/simulation/components/UnitAI.js
|3022| »   »   »   »   »   »   »   »   var·cmpResourceDropsite·=·Engine.QueryInterface(target,·IID_ResourceDropsite);
|    | [NORMAL] JSHintBear:
|    | 'target' used out of scope.

binaries/data/mods/public/simulation/components/UnitAI.js
|3023| »   »   »   »   »   »   »   »   if·(cmpResourceDropsite·&&·this.CanReturnResource(target,·true))
|    | [NORMAL] JSHintBear:
|    | 'target' used out of scope.

binaries/data/mods/public/simulation/components/UnitAI.js
|3038| »   »   »   »   »   »   »   »   »   var·cmpHolderPosition·=·Engine.QueryInterface(target,·IID_Position);
|    | [NORMAL] JSHintBear:
|    | 'target' used out of scope.

binaries/data/mods/public/simulation/components/UnitAI.js
|3039| »   »   »   »   »   »   »   »   »   var·cmpHolderUnitAI·=·Engine.QueryInterface(target,·IID_UnitAI);
|    | [NORMAL] JSHintBear:
|    | 'target' used out of scope.

binaries/data/mods/public/simulation/components/UnitAI.js
|3066| »   »   »   »   »   »   »   if·(this.MoveToTarget(target))
|    | [NORMAL] JSHintBear:
|    | 'target' used out of scope.

binaries/data/mods/public/simulation/components/UnitAI.js
|3363| »   return·this.alertRaiser·!=·undefined;
|    | [NORMAL] JSHintBear:
|    | Use '!==' to compare with 'undefined'.

binaries/data/mods/public/simulation/components/UnitAI.js
|3505| »   »   »   ||·this.orderQueue[0].type·==·"Pack"·||·this.orderQueue[0].type·==·"Unpack")))
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '||'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|3569| »   »   if·(i·==·0)
|    | [NORMAL] JSHintBear:
|    | Use '===' to compare with '0'.

binaries/data/mods/public/simulation/components/UnitAI.js
|3862| »   »   var·order·=·{·"type":·type,·"data":·data·};
|    | [NORMAL] JSHintBear:
|    | 'order' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|3935| »   for·(var·i·=·0;·i·<·this.orderQueue.length;·++i)
|    | [NORMAL] JSHintBear:
|    | 'i' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|3947| »   if·(this.workOrders.length·==·0)
|    | [NORMAL] JSHintBear:
|    | Use '===' to compare with '0'.

binaries/data/mods/public/simulation/components/UnitAI.js
|4133| »   return·cmpHealth·&&·cmpHealth.GetHitpoints()·!=·0;
|    | [NORMAL] JSHintBear:
|    | Use '!==' to compare with '0'.

binaries/data/mods/public/simulation/components/UnitAI.js
|4472| »   »   var·parabolicMaxRange·=·0;
|    | [NORMAL] JSHintBear:
|    | 'parabolicMaxRange' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|4476| »   var·guessedMaxRange·=·(range.max·+·parabolicMaxRange)/2;
|    | [NORMAL] JSHintBear:
|    | 'parabolicMaxRange' used out of scope.

binaries/data/mods/public/simulation/components/UnitAI.js
|4483| »   return·cmpUnitMotion.MoveToTargetRange(target,·range.min,·Math.min(range.max,·parabolicMaxRange));
|    | [NORMAL] JSHintBear:
|    | 'parabolicMaxRange' used out of scope.

binaries/data/mods/public/simulation/components/UnitAI.js
|4539| »   »   »   &&·cmpFormationUnitAI.order.data.target·==·target)
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '&&'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|4711| »   »   &&·this.CheckTargetDistanceFromHeldPosition(target,·IID_Attack,·this.GetBestAttackAgainst(target,·true))
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '&&'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|4712| »   »   &&·(this.GetStance().respondChaseBeyondVision·||·this.CheckTargetIsInVisionRange(target))
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '&&'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|5244| »   var·lastPos·=·undefined;
|    | [NORMAL] JSHintBear:
|    | It's not necessary to initialize 'lastPos' to 'undefined'.

binaries/data/mods/public/simulation/components/UnitAI.js
|5583| »   »   »   »   »   »   &&·!MatchesClassList(cmpIdentity.GetClassesList(),·targetClasses.attack))
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '&&'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|5586| »   »   »   »   »   »   &&·MatchesClassList(cmpIdentity.GetClassesList(),·targetClasses.avoid))
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '&&'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|5599| »   var·targets·=·this.GetTargetsFromUnit();
|    | [NORMAL] JSHintBear:
|    | 'targets' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|5600| »   for·(var·targ·of·targets)
|    | [NORMAL] JSHintBear:
|    | 'targ' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|5606| »   »   »   var·cmpIdentity·=·Engine.QueryInterface(targ,·IID_Identity);
|    | [NORMAL] JSHintBear:
|    | 'cmpIdentity' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|5607| »   »   »   var·targetClasses·=·this.order.data.targetClasses;
|    | [NORMAL] JSHintBear:
|    | 'targetClasses' is already defined.

binaries/data/mods/public/simulation/components/UnitAI.js
|5609| »   »   »   »   &&·!MatchesClassList(cmpIdentity.GetClassesList(),·targetClasses.attack))
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '&&'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|5612| »   »   »   »   &&·MatchesClassList(cmpIdentity.GetClassesList(),·targetClasses.avoid))
|    | [NORMAL] JSHintBear:
|    | Misleading line break before '&&'; readers may interpret this as an expression boundary.

binaries/data/mods/public/simulation/components/UnitAI.js
|5612| »   »   »   »   &&·MatchesClassList(cmpIdentity.GetClassesList(),·targetClasses.avoid))
|    | [MAJOR] JSHintBear:
|    | Too many errors. (91% scanned).
Executing section XML GUI...
Executing section Python...
Executing section Perl...

http://jenkins-master:8080/job/phabricator_lint/544/ for more details.

bb added a subscriber: bb.Sep 22 2017, 11:18 PM

Improvement noticed but some slight changes might make it even better, also some style rubbish:

Probably just true for observers, but they might now get annoyed by animals always walking in sorta circles, maybe a slight randomization on the angle (as in not having a fixed angle, but choosing every move ang = randFloat(this.roamAngle-foo, this.roamAngle+foo))

Maybe roamAngle could become a template setting?

binaries/data/mods/public/simulation/components/UnitAI.js
6026 ↗(On Diff #3753)

reorder so the position check are next to eachother

6034 ↗(On Diff #3753)

just want to note that (randInt(0, 1)*2-1)* Math.PI / 6 does the same and is already used in rms, but this is fine too

We could also make this more random with something like randFloat(-ang, ang) or randInt(-ang, ang) (so we don't always have that 12 corner polygon)

6035 ↗(On Diff #3753)

-=

6037 ↗(On Diff #3753)

\n and -.

6041 ↗(On Diff #3753)

was dubious about this first, but got convinced ingame :)

6042 ↗(On Diff #3753)

+=

6043–6044 ↗(On Diff #3753)

inline

6047 ↗(On Diff #3753)

+=

6049–6050 ↗(On Diff #3753)

inline

mimo added a comment.Sep 23 2017, 2:47 PM
In D927#36205, @bb wrote:

Improvement noticed but some slight changes might make it even better, also some style rubbish:

Probably just true for observers, but they might now get annoyed by animals always walking in sorta circles, maybe a slight randomization on the angle (as in not having a fixed angle, but choosing every move ang = randFloat(this.roamAngle-foo, this.roamAngle+foo))

Maybe roamAngle could become a template setting?

I've no strong opinion about a template setting. Maybe in a following patch when someone will tune the values for the different animals (for example, currently most of them have roamDistance=8 and that could be improved)?

binaries/data/mods/public/simulation/components/UnitAI.js
6034 ↗(On Diff #3753)

I find the randBool more indicative of the intent (i.e. that each sign has equal proba).

Agree on the second point. My first tests used a varying angle (for each step the angle was roamAngle + randFloat(-roamAngle/2, roamAngle/2), but i didn't keep it because the rotation was not nice with big angles. But that was before adding the trick on pre-rotation by half angle. So i'll put it back.

mimo updated this revision to Diff 3758.Sep 23 2017, 2:49 PM

updated following bb's comments

Build is green

Updating workspaces.
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (307 tests)...................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (307 tests)...................................................................................................................................................................................................................................................................................................................OK!
Checking XML files...

http://jenkins-master:8080/job/phabricator/2066/ for more details.

Executing section Default...
Executing section Source...
Executing section JS...
|    | [NORMAL] ESLintBear (no-else-return):
|    | Unnecessary 'else' after 'return'.
|----|    | /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/components/UnitAI.js
| 911| 911| 					this.FinishOrder();
| 912| 912| 					return;
| 913| 913| 				}
| 914|    |-				else
| 915|    |-				{
|    | 914|+				
| 916| 915| 					// Out of range; move there in formation
| 917| 916| 					if (this.MoveToGarrisonRange(msg.data.target))
| 918| 917| 					{
| 919| 918| 						this.SetNextState("GARRISON.APPROACHING");
| 920| 919| 						return;
| 921| 920| 					}
| 922|    |-				}
|    | 921|+				
| 923| 922| 			}
| 924| 923| 
| 925| 924| 			this.SetNextState("GARRISON.GARRISONING");
|    | [NORMAL] ESLintBear (no-unneeded-ternary):
|    | Unnecessary use of boolean literals in conditional expression.
|----|    | /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/components/UnitAI.js
|1958|1958| 					// TODO: we should probably only bother syncing projectile attacks, not melee
|1959|1959| 
|1960|1960| 					// If using a non-default prepare time, re-sync the animation when the timer runs.
|1961|    |-					this.resyncAnimation = (prepare != this.attackTimers.prepare) ? true : false;
|    |1961|+					this.resyncAnimation = (prepare != this.attackTimers.prepare);
|1962|1962| 
|1963|1963| 					this.FaceTowardsTarget(this.order.data.target);
|1964|1964| 
|    | [NORMAL] ESLintBear (no-else-return):
|    | Unnecessary 'else' after 'return'.
|----|    | /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/components/UnitAI.js
|2184|2184| 							this.PerformGather(nearby, false, false);
|2185|2185| 							return true;
|2186|2186| 						}
|2187|    |-						else
|2188|    |-						{
|    |2187|+						
|2189|2188| 							// It's probably better in this case, to avoid units getting stuck around a dropsite
|2190|2189| 							// in a "Target is far away, full, nearby are no good resources, return to dropsite" loop
|2191|2190| 							// to order it to GatherNear the resource position.
|2206|2205| 									return true;
|2207|2206| 								}
|2208|2207| 							}
|2209|    |-						}
|    |2208|+						
|2210|2209| 						return true;
|2211|2210| 					}
|2212|2211| 					return false;
|    | [NORMAL] ESLintBear (no-else-return):
|    | Unnecessary 'else' after 'return'.
|----|    | /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/components/UnitAI.js
|2196|2196| 								this.GatherNearPosition(pos.x, pos.z, oldType, oldTemplate);
|2197|2197| 								return true;
|2198|2198| 							}
|2199|    |-							else
|2200|    |-							{
|    |2199|+							
|2201|2200| 								// we're kind of stuck here. Return resource.
|2202|2201| 								var nearby = this.FindNearestDropsite(oldType.generic);
|2203|2202| 								if (nearby)
|2205|2204| 									this.PushOrderFront("ReturnResource", { "target": nearby, "force": false });
|2206|2205| 									return true;
|2207|2206| 								}
|2208|    |-							}
|    |2207|+							
|2209|2208| 						}
|2210|2209| 						return true;
|2211|2210| 					}
|    | [NORMAL] ESLintBear (no-unneeded-ternary):
|    | Unnecessary use of boolean literals in conditional expression.
|----|    | /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/simulation/components/UnitAI.js
|    |++++| /mnt/data/jenkins-phabricator/workspace/phabricator_lint/binaries/data/mods/public/s

http://jenkins-master:8080/job/phabricator_lint/545/ for more details.

bb accepted this revision.Sep 23 2017, 10:32 PM

Looks much better imo, those style things can be done while committing.

Agree on doing the template things later (indeed the dists can use a check aswel)

binaries/data/mods/public/simulation/components/UnitAI.js
6037 ↗(On Diff #3758)

}
\n
else if

6041 ↗(On Diff #3758)

== this.roamAngle*(randFloat(1/2,3/2)) /2== randFloat(this.roamAngle/4, this.roamAngle*3/4)
which looks cleaner to me

This revision is now accepted and ready to land.Sep 23 2017, 10:32 PM
This revision was automatically updated to reflect the committed changes.
fatherbushido added inline comments.
ps/trunk/binaries/data/mods/public/simulation/components/UnitAI.js
6029

(no real benefit to change it but only 2D is needed)

mimo added inline comments.Sep 25 2017, 7:12 PM
ps/trunk/binaries/data/mods/public/simulation/components/UnitAI.js
6029

My worry was that using rot.y with the coordinates pos.x and pos.y would make the code obscure. Maybe we should also add a GetRotation2D which would return only rot.y, to be used in conjonction with GetPosition2D.

elexis retitled this revision from Revisit the random walk of animals to Revisit animal roaming.Sep 26 2017, 6:26 AM