static void mono_g_hash_table_insert_replace (MonoGHashTable *hash, gpointer key, gpointer value, gboolean replace) { guint hashcode; Slot *s; GEqualFunc equal; g_return_if_fail (hash != NULL); equal = hash->key_equal_func; if (hash->in_use >= hash->threshold) rehash (hash); hashcode = ((*hash->hash_func) (key)) % hash->table_size; for (s = hash->table [hashcode]; s != NULL; s = s->next){ if ((*equal) (s->key, key)){ if (replace){ if (hash->key_destroy_func != NULL) (*hash->key_destroy_func)(s->key); s->key = key; } if (hash->value_destroy_func != NULL) (*hash->value_destroy_func) (s->value); s->value = value; return; } } s = new_slot (hash); s->key = key; s->value = value; s->next = hash->table [hashcode]; hash->table [hashcode] = s; hash->in_use++; }
void Graphics::init() { ///should be the same code as in new_scene function! m_curScene = new Scene; m_Scenemap.insert(pair<string, Scene*>("Default", m_curScene)); new_slot("Default"); m_curScene->slotname = "Default"; reg_lua(); }
/* * Returns 1 if engineering was jettisoned */ int e_jettison(struct ship *sp, struct ship *fed) { struct list *lp; struct torpedo *tp; if (is_dead(sp, S_ENG)) return 0; (void) e_cloak_off(sp, fed); if (syswork(shiplist[0], S_SENSOR)) { printf("%s: Sensors indicate debris being left by\n", science); printf(" the %s. Insufficient mass . . .\n", sp->name); } lp = newitem(I_ENG); tp = lp->data.tp = MKNODE(struct torpedo, *, 1); if (tp == (struct torpedo *)NULL) { fprintf(stderr, "e_jettison: malloc failed\n"); exit(2); } tp->id = new_slot(); /* * ship slows to warp 1.0 when jettisonning engineering */ tp->newspeed = 0.0; tp->speed = sp->warp; tp->target = NULL; tp->course = sp->course; tp->x = sp->x; tp->y = sp->y; tp->prox = 0; tp->timedelay = 10.; tp->fuel = sp->energy; tp->type = TP_ENGINEERING; sp->energy = sp->pods = 0; sp->regen = 0.0; tp->from = sp; if (sp->newwarp < -1.0) sp->newwarp = -0.99; if (sp->newwarp > 1.0) sp->newwarp = 0.99; sp->max_speed = 1.0; sp->status[S_ENG] = 100; /* List as destroyed */ sp->status[S_WARP] = 100; sp->cloaking = C_NONE; sp->t_blind_left = sp->t_blind_right = sp->p_blind_left = sp->p_blind_right = 180; return 1; }
int main(void) { FILE *fin = fopen("milk2.in", "r"); FILE *fout = fopen("milk2.out", "w"); int n, i; int start, end; Slot *curr, *prev; Slot *root; int longest_milked = 0; int longest_not_milked = 0; root = NULL; fscanf(fin, "%d", &n); for (i = 0; i < n; ++i) { fscanf(fin, "%d %d", &start, &end); /* printf("%d %d->", start, end); */ curr = new_slot(start, end); root = insert_slot(root, curr); } prev = NULL; curr = prev = root; while (curr != NULL) { /* printf("%d %d\n", curr->start, curr->end); */ if (curr->end - curr->start > longest_milked) { longest_milked = curr->end - curr->start; } if (prev != NULL) { if (curr->start - prev->end > longest_not_milked) { longest_not_milked = curr->start - prev->end; } } prev = curr; curr = curr->next; } fprintf(fout, "%d %d\n", longest_milked, longest_not_milked); exit(0); }
/* * Returns 1 if a probe was launched */ int e_launchprobe(struct ship *sp, struct ship *fed) { int i; struct list *lp; struct torpedo *tp; if (!syswork(sp, S_PROBE) || sp->energy <= 10 || cantsee(sp)) return 0; /* * fed ship has to be going slow before we'll launch * a probe at it. */ if (fabs(fed->warp) > 1.0) return 0; lp = newitem(I_PROBE); tp = lp->data.tp = MKNODE(struct torpedo, *, 1); if (tp == (struct torpedo *)NULL) { fprintf(stderr, "e_launchprobe: malloc failed\n"); exit(2); } tp->from = sp; tp->speed = sp->warp; tp->newspeed = 3.0; tp->target = fed; tp->course = bearing(sp->x, fed->x, sp->y, fed->y); tp->x = sp->x; tp->y = sp->y; tp->prox = 200 + randm(200); tp->timedelay = 15.; tp->id = new_slot(); if ((i = randm(15) + 10) > sp->energy) i = sp->energy; tp->fuel = i; tp->type = TP_PROBE; sp->energy -= i; sp->pods -= i; printf("%s launching probe #%d\n", sp->name, tp->id); return 1; }
void Graphics::new_scene(const string& name) { #ifdef DEBUG__ if(m_Scenemap.find(name) != m_Scenemap.end()) { cout << "Scene name already exists!" << endl; throw 0; } #endif Scene* scene = new Scene; #ifdef DEBUG__ if(scene == nullptr) { cout << "failed to allocate new scene!" << endl; throw 0; } #endif m_Scenemap.insert(pair<string, Scene*>(name, scene)); new_slot(name); scene->slotname = name; m_curScene = scene; }