backspaces/agentscript — pull request #78 by bennlich (2014-12-19 06:06:23+00:00)
Title: Allow breeds based on subclasses

Previously: `model.createBreeds()` would determine if a new breed was a sub-breed (i.e. a breed based on agents, links, or patches) [by looking at the `breed` attribute of the base class's prototype](https://github.com/backspaces/agentscript/blob/master/src/model.coffee#L252). This worked if your base class was one of `model.Agent`, `model.Patch`, or `model.Link`, but it wouldn't work with a custom subclass:
```
class Ant extends ABM.Agent
# define Ant class

class MyModel extends ABM.Model
setup: ->
@createBreeds("ants", Ant, @Agents)
```
The problem is that the `breed` attribute [is only assigned to a class's prototype when that class is used to build an agentset](https://github.com/backspaces/agentscript/blob/master/src/agentset.coffee#L61). So our `Ant` class never gets a `breed` attribute, and `createBreeds()` fails to pass a mainSet into the agentset constructor.

I changed `createBreeds()` to accept mainSet as a fourth argument, and I refactored `patchBreeds()`, `agentBreeds()`, and `linkBreeds()` to default to using the appropriate mainSet.

Now the above example works with this syntax:
```
class Ant extends ABM.Agent
# define Ant class

class MyModel extends ABM.Model
setup: ->
@agentBreeds("ants", Ant)
```

This is in preparation for writing more object-oriented models. Is this what we want? The ultimate goal is to make behaviors modular, and I'm thinking that may be easiest if behaviors are a part of an agent's prototype. Then we can swap out behaviors by swapping prototypes, or adding behaviors to agent prototypes (instead of to model objects). What do you think?