c2eCreature *getc2eCreature(Agent *a) { if (!a) return 0; CreatureAgent *b = dynamic_cast<CreatureAgent *>(a); if (!b) return 0; c2eCreature *c = dynamic_cast<c2eCreature *>(b->getCreature()); return c; }
bool Agent::fireScript(unsigned short event, Agent *from, caosVar one, caosVar two) { // Start running the specified script on the VM of this agent, with FROM set to the provided agent. if (dying) return false; CreatureAgent *c = 0; if (event <= 3 || event == 4 || event == 12 || event == 13 || event == 14) c = dynamic_cast<CreatureAgent *>(from); switch (event) { case 0: // deactivate if (c && !cr_can_stop) return false; // TODO: not sure if this is the right place to do this. actv.setInt(event); break; case 1: // activate 1 if (c && !cr_can_push) return false; // TODO: not sure if this is the right place to do this. actv.setInt(event); break; case 2: // activate 2 if (c && !cr_can_pull) return false; // TODO: not sure if this is the right place to do this. actv.setInt(event); break; case 3: // hit if (c && !cr_can_hit) return false; break; case 4: // pickup if (c && !cr_can_pickup) return false; if (!from) return false; if (from == world.hand()) { if (!mouseable()) return false; } else if (!c) { // TODO: valid check for vehicles? if (!carryable()) return false; } from->addCarried(this); // TODO: correct behaviour? break; case 5: // drop if (!from) return false; // TODO: this check isn't very good for vehicles ;p // if (from != carriedby) return false; from->dropCarried(this); // TODO: correct? break; case 12: // eat if (c && !cr_can_eat) return false; break; case 13: // hold hands with pointer if (c) { // TODO } break; case 14: // stop holding hands with pointer if (c) { // TODO } break; case 92: // TODO: hack for 'UI Mouse Down' event - we need a real event system! std::cout << "faking event 92 on " << identify() << std::endl; CompoundPart *p = world.partAt(world.hand()->pointerX(), world.hand()->pointerY()); if (!p || p->getParent() != this) // if something is horridly broken here, return return false; // was caos_assert(p && p->getParent() == this); p->handleClick(world.hand()->pointerX() - p->x - p->getParent()->x, world.hand()->pointerY() - p->y - p->getParent()->y); // TODO: we're [obviously] missing firing the pointer script here, but it's a hack for now break; } bool ranscript = false; shared_ptr<script> s = findScript(event); if (s) { bool madevm = false; if (!vm) { madevm = true; vm = world.getVM(this); } if (vm->fireScript(s, event == 9, from)) { lastScript = event; zotstack(); vm->setVariables(one, two); // TODO: we should set _it_ in a more sensible way CreatureAgent *a = dynamic_cast<CreatureAgent *>(this); if (a) { Creature *c = a->getCreature(); assert(c); vm->_it_ = c->getAttentionFocus(); } vmTick(); ranscript = true; } else if (madevm) { world.freeVM(vm); vm = 0; } } switch (event) { case 5: if (invehicle) break; if (engine.version > 1) break; // Creatures 1 drop snapping // TODO: this probably doesn't belong here, but it has to be run after the // drop script starts (see for instance C1 carrots, which change pose) MetaRoom* m = world.map.metaRoomAt(x, y); if (!m) break; shared_ptr<Room> r = m->nextFloorFromPoint(x, y); if (!r) break; moveTo(x, r->bot.pointAtX(x).y - getHeight()); break; } return ranscript; }