/** ** GM: GATE <id> <x> <y> ** requires: permission-key "gmgate" **/ static void gm_gate(const void *tnext, struct unit * u, struct order *ord) { const struct plane *pl = rplane(u->region); int id = getid(); int x = rel_to_abs(pl, u->faction, getint(), 0); int y = rel_to_abs(pl, u->faction, getint(), 1); building *b = findbuilding(id); region *r; pnormalize(&x, &y, pl); r = findregion(x, y); if (b == NULL || r == NULL || pl != rplane(b->region) || pl != rplane(r)) { mistake(u, ord, "the unit cannot transform this building."); return; } else { /* checking permissions */ attrib *permissions = a_find(u->faction->attribs, &at_permissions); if (permissions && has_permission(permissions, atoi36("gmgate"))) { remove_triggers(&b->attribs, "timer", &tt_gate); remove_triggers(&b->attribs, "create", &tt_unguard); if (r != b->region) { add_trigger(&b->attribs, "timer", trigger_gate(b, r)); add_trigger(&b->attribs, "create", trigger_unguard(b)); fset(b, BLD_UNGUARDED); } } } }
//----------------------------------------------------------------- // Adds a specific trigger flag to Markedsegp/Markedside if it is possible. // Automatically adds flag to Connectside if possible unless it is a control trigger. // Returns 1 if trigger flag added. // Returns 0 if trigger flag cannot be added. int trigger_flag_Markedside(short flag, int value) { int trigger_num; //, ctrigger_num; int wall_num; if (!Markedsegp) { editor_status("No Markedside."); return 0; } // If no child on Markedside return if (!IS_CHILD(Markedsegp->children[Markedside])) return 0; // If no wall just return wall_num = Markedsegp->sides[Markedside].wall_num; if (!value && wall_num == -1) return 0; trigger_num = value ? add_trigger(Markedsegp, Markedside) : Walls[wall_num].trigger; if (trigger_num == -1) { editor_status(value ? "Cannot add trigger at Markedside." : "No trigger at Markedside."); return 0; } if (value) Triggers[trigger_num].flags |= flag; else Triggers[trigger_num].flags &= ~flag; return 1; }
int sp_summon_alp(struct castorder *co) { unit *alp, *opfer; region *r = co_get_region(co); unit *mage = co->magician.u; int cast_level = co->level; spellparameter *pa = co->par; const struct race *rc = get_race(RC_ALP); struct faction *f = get_monsters(); struct message *msg; opfer = pa->param[0]->data.u; /* Der Alp gehört den Monstern, darum erhält der Magier auch keine * Regionsberichte von ihm. Er erhält aber später eine Mitteilung, * sobald der Alp sein Opfer erreicht hat. */ alp = create_unit(r, f, 1, rc, 0, NULL, NULL); set_level(alp, SK_STEALTH, 7); setstatus(alp, ST_FLEE); /* flieht */ { attrib *a = a_add(&alp->attribs, a_new(&at_alp)); alp_data *ad = (alp_data *) a->data.v; ad->mage = mage; ad->target = opfer; } { /* Wenn der Alp stirbt, den Magier nachrichtigen */ add_trigger(&alp->attribs, "destroy", trigger_unitmessage(mage, "trigger_alp_destroy", MSG_EVENT, ML_INFO)); /* Wenn Opfer oder Magier nicht mehr existieren, dann stirbt der Alp */ add_trigger(&mage->attribs, "destroy", trigger_killunit(alp)); add_trigger(&opfer->attribs, "destroy", trigger_killunit(alp)); } msg = msg_message("summon_alp_effect", "mage alp target", mage, alp, opfer); r_addmessage(r, mage->faction, msg); msg_release(msg); return cast_level; }
static void init_volcano(void) { building *b; region *r = arena_center; assert(arena_center); if (rterrain(r) != T_DESERT) return; /* been done before */ terraform(arena_center, T_VOLCANO_SMOKING); b = new_building(bt_find("caldera"), r, NULL); b->size = 1; b->name = _strdup("Igjarjuk's Schlund"); b->display = _strdup ("Feurige Lava fließt aus dem Krater des großen Vulkans. Alles wird von ihr verschlungen."); add_trigger(&b->attribs, "timer", trigger_caldera(b)); tt_register(&tt_caldera); }
//----------------------------------------------------------------- // Adds a specific trigger flag to Markedsegp/Markedside if it is possible. // Automatically adds flag to Connectside if possible unless it is a control trigger. // Returns 1 if trigger flag added. // Returns 0 if trigger flag cannot be added. int trigger_add_to_Markedside(short flag) { int trigger_num; //, ctrigger_num; if (!Markedsegp) { editor_status("No Markedside."); return 0; } // If no child on Markedside return if (!IS_CHILD(Markedsegp->children[Markedside])) return 0; trigger_num = add_trigger(Markedsegp, Markedside); if (trigger_num == -1) { editor_status("Cannot add trigger at Markedside."); return 0; } Triggers[trigger_num].flags |= flag; return 1; }
void alp_findet_opfer(unit * alp, region * r) { curse *c; attrib *a = a_find(alp->attribs, &at_alp); alp_data *ad = (alp_data *) a->data.v; unit *mage = ad->mage; unit *opfer = ad->target; float effect; message *msg; assert(opfer); assert(mage); /* Magier und Opfer Bescheid geben */ msg = msg_message("alp_success", "target", opfer); add_message(&mage->faction->msgs, msg); r_addmessage(opfer->region, opfer->faction, msg); msg_release(msg); /* Relations werden in destroy_unit(alp) automatisch gelöscht. * Die Aktionen, die beim Tod des Alps ausgelöst werden sollen, * müssen jetzt aber deaktiviert werden, sonst werden sie gleich * beim destroy_unit(alp) ausgelöst. */ a_removeall(&alp->attribs, &at_eventhandler); /* Alp umwandeln in Curse */ effect = -2; c = create_curse(mage, &opfer->attribs, ct_find("worse"), 2, 2, effect, opfer->number); /* solange es noch keine spezielle alp-Antimagie gibt, reagiert der * auch auf normale */ set_number(alp, 0); /* wenn der Magier stirbt, wird der Curse wieder vom Opfer genommen */ add_trigger(&mage->attribs, "destroy", trigger_removecurse(c, opfer)); }
/* Generates the absolute triggers for a component */ static void generate_absolute_triggers (ECalComponent *comp, struct alarm_occurrence_data *aod, ECalRecurResolveTimezoneFn resolve_tzid, gpointer user_data, icaltimezone *default_timezone) { GList *l; ECalComponentDateTime dt_start, dt_end; e_cal_component_get_dtstart (comp, &dt_start); e_cal_component_get_dtend (comp, &dt_end); for (l = aod->alarm_uids; l; l = l->next) { const gchar *auid; ECalComponentAlarm *alarm; ECalComponentAlarmAction action; ECalComponentAlarmRepeat repeat; ECalComponentAlarmTrigger trigger; time_t abs_time; time_t occur_start, occur_end; icaltimezone *zone; gint i; auid = l->data; alarm = e_cal_component_get_alarm (comp, auid); g_return_if_fail (alarm != NULL); e_cal_component_alarm_get_action (alarm, &action); e_cal_component_alarm_get_trigger (alarm, &trigger); e_cal_component_alarm_get_repeat (alarm, &repeat); e_cal_component_alarm_free (alarm); for (i = 0; aod->omit[i] != -1; i++) { if (aod->omit[i] == action) break; } if (aod->omit[i] != -1) continue; if (trigger.type != E_CAL_COMPONENT_ALARM_TRIGGER_ABSOLUTE) continue; /* Absolute triggers are always in UTC; * see RFC 2445 section 4.8.6.3 */ zone = icaltimezone_get_utc_timezone (); abs_time = icaltime_as_timet_with_zone (trigger.u.abs_time, zone); /* No particular occurrence, so just use the times from the * component */ if (dt_start.value) { if (dt_start.tzid && !dt_start.value->is_date) zone = (* resolve_tzid) (dt_start.tzid, user_data); else zone = default_timezone; occur_start = icaltime_as_timet_with_zone ( *dt_start.value, zone); } else occur_start = -1; if (dt_end.value) { if (dt_end.tzid && !dt_end.value->is_date) zone = (* resolve_tzid) (dt_end.tzid, user_data); else zone = default_timezone; occur_end = icaltime_as_timet_with_zone (*dt_end.value, zone); } else occur_end = -1; /* Add repeating alarms */ if (repeat.repetitions != 0) { gint i; time_t repeat_time; repeat_time = icaldurationtype_as_int (repeat.duration); for (i = 0; i < repeat.repetitions; i++) { time_t t; t = abs_time + (i + 1) * repeat_time; if (t >= aod->start && t < aod->end) add_trigger ( aod, auid, t, occur_start, occur_end); } } /* Add the trigger itself */ if (abs_time >= aod->start && abs_time < aod->end) add_trigger (aod, auid, abs_time, occur_start, occur_end); } e_cal_component_free_datetime (&dt_start); e_cal_component_free_datetime (&dt_end); }
/* Callback used from cal_recur_generate_instances(); generates triggers for all * of a component's RELATIVE alarms. */ static gboolean add_alarm_occurrences_cb (ECalComponent *comp, time_t start, time_t end, gpointer data) { struct alarm_occurrence_data *aod; GList *l; aod = data; for (l = aod->alarm_uids; l; l = l->next) { const gchar *auid; ECalComponentAlarm *alarm; ECalComponentAlarmAction action; ECalComponentAlarmTrigger trigger; ECalComponentAlarmRepeat repeat; struct icaldurationtype *dur; time_t dur_time; time_t occur_time, trigger_time; gint i; auid = l->data; alarm = e_cal_component_get_alarm (comp, auid); g_return_val_if_fail (alarm != NULL, FALSE); e_cal_component_alarm_get_action (alarm, &action); e_cal_component_alarm_get_trigger (alarm, &trigger); e_cal_component_alarm_get_repeat (alarm, &repeat); e_cal_component_alarm_free (alarm); for (i = 0; aod->omit[i] != -1; i++) { if (aod->omit[i] == action) break; } if (aod->omit[i] != -1) continue; if (trigger.type != E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START && trigger.type != E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_END) continue; dur = &trigger.u.rel_duration; dur_time = icaldurationtype_as_int (*dur); if (trigger.type == E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START) occur_time = start; else occur_time = end; /* If dur->is_neg is true then dur_time will already be * negative. So we do not need to test for dur->is_neg here; we * can simply add the dur_time value to the occur_time and get * the correct result. */ trigger_time = occur_time + dur_time; /* Add repeating alarms */ if (repeat.repetitions != 0) { gint i; time_t repeat_time; repeat_time = icaldurationtype_as_int (repeat.duration); for (i = 0; i < repeat.repetitions; i++) { time_t t; t = trigger_time + (i + 1) * repeat_time; if (t >= aod->start && t < aod->end) add_trigger (aod, auid, t, start, end); } } /* Add the trigger itself */ if (trigger_time >= aod->start && trigger_time < aod->end) add_trigger (aod, auid, trigger_time, start, end); } return TRUE; }
void handle_command(zmsg_t * request, zmsg_t * reply, rulepackage_t * rpkg, channeldb_t * db ) { char * command = zmsg_popstr(request); zclock_log("%s worker servicing request %s", rpkg->servicename,command); if (strcmp(command, "AddTrigger") == 0) { triggerconfig_t * tconf = add_trigger(rpkg, request, reply); if(tconf) db_store_trigger(db, tconf); } else if (strcmp(command, "AddAction") == 0) { zclock_log("actions not implemented yet"); //TODO } else if (strcmp(command,"RemoveRule") == 0) { char * rule_id = zmsg_popstr(request); // we always evaluate both, hence | usage rather than || int found = remove_rule(rpkg->context, rpkg->triggers, rule_id) | remove_rule(rpkg->context, rpkg->actions, rule_id); if(found) { // must also delete from local db. db_delete_action(db, rule_id); db_delete_trigger(db, rule_id); zmsg_pushstr(reply, "200"); } else { // not there! zclock_log("Received delete trigger request for nonexistent rule %s, ignoring", rule_id); zmsg_pushstr(reply, "404"); zmsg_pushstr(reply, "rule not found"); } } else if (strcmp(command, "AddMonitor")==0) { add_monitor(rpkg, reply); } else if (strcmp(command, "Service") == 0) { assert(zmsg_size(request) == 1); // TODO this is incomplete // services also have names char * name = zmsg_popstr(request); // char * service_pipe; // we _could_ just throw the request out into the ether, but // really, we want this to be a reply-request sort of deal. // otherwise, we have to contend with the same problem we have // with monitors: that they need to stay active. // let's set up a hash of pipes, and just have a worker for each // possible service. // problems: this _is_ synchronous for the channel involved. // this means we can't subsume monitors into it. probably ok for // now. //service_function * service_func; // if ((service_func=zhash_lookup(config->services, name))) { // found it, let's execute // problem here is that we don't particularly want to wait for // the next update, even though it's probably within the next // 60th of a second. // what are our options? // 1. listen to line000X, wait, return // 2. spin off a thread with a reference to the request, let // it reply on our behalf... i think this probably doesn't // work, majordomo expects a response before it gives you more // work. // 3. cache current value somewhere. this is fast, but pretty // sketchy in synchronisation terms. it migh tbe ok, given // that it's explicitly just sampling. // char * result = service_func(); //zmsg_pushstr(reply, result); // } else { zclock_log("bad service %s", name); zmsg_pushstr(reply, "no such service"); } else { zclock_log("Can't handle command %s: ignoring", command); zmsg_pushstr(reply, "bad command"); } zmsg_destroy(&request); }
static void create() { ::create(); add_trigger("dig", store_fp("do_dig")); }