Example #1
0
/* Add random jumpgates to the level */
static void add_random_gates(int count) {
    int w=jumpgate_gfx[0]->w;
    int h=jumpgate_gfx[0]->h;
    int r;
    for(r=0;r<count;r++) {
        struct SpecialObj *gate[2];
        int g;
        for(g=0;g<2;g++) {
            int x,y,loops=0;
            do {
                x = rand()%lev_level.width;
                y = rand()%lev_level.height;
            } while((hitsolid_rect(x-w/2,y-h/2,w,h) ||
                        (g==1 && hypot(gate[0]->x-x,gate[0]->y-y)<500.0))
                    && ++loops<1000);
            if(loops>=1000) {
                fprintf(stderr,"Warning: Couldn't find place for a jumpgate!\n");
                if(g>0)
                    free(gate[0]);
                return;
            }
            gate[g] = make_jumpgate(x,y);
        }
        gate[0]->link = gate[1];
        gate[1]->link = gate[0];
        add_special(gate[0]);
        add_special(gate[1]);
    }
}
Example #2
0
File: reach.c Project: DevL/ponyc
static reachable_type_t* add_nominal(reachable_method_stack_t** s,
  reachable_types_t* r, uint32_t* next_type_id, ast_t* type)
{
  const char* type_name = genname_type(type);
  reachable_type_t* t = reach_type(r, type_name);

  if(t != NULL)
    return t;

  t = add_reachable_type(r, type, type_name);

  AST_GET_CHILDREN(type, pkg, id, typeparams);
  ast_t* typeparam = ast_child(typeparams);

  while(typeparam != NULL)
  {
    add_type(s, r, next_type_id, typeparam);
    typeparam = ast_sibling(typeparam);
  }

  ast_t* def = (ast_t*)ast_data(type);

  switch(ast_id(def))
  {
    case TK_INTERFACE:
    case TK_TRAIT:
      add_types_to_trait(s, r, t);
      break;

    case TK_PRIMITIVE:
      add_traits_to_type(s, r, t);
      add_special(s, t, type, "_init");
      add_special(s, t, type, "_final");
      break;

    case TK_STRUCT:
    case TK_CLASS:
      add_traits_to_type(s, r, t);
      add_special(s, t, type, "_final");
      add_fields(s, r, next_type_id, type);
      break;

    case TK_ACTOR:
      add_traits_to_type(s, r, t);
      add_special(s, t, type, "_event_notify");
      add_special(s, t, type, "_final");
      add_fields(s, r, next_type_id, type);
      break;

    default: {}
  }

  if(t->type_id == 0)
    t->type_id = ++(*next_type_id);

  return t;
}
Example #3
0
/* before it will open. */
void drop_jumppoint (int x, int y, int player) {
    /* First search for a exit point to this jumppoint */
    struct dllist *ptr=special_list;
    struct SpecialObj *exit,*point;
    while(ptr) {
        exit = ptr->data;
        if(exit->gfx==jumppoint_gfx[1] && exit->owner == player &&
                exit->link==NULL)
            break;
        ptr=ptr->next;
    }
    if(ptr) { /* If exit point exists, create the wormhole */
        point = make_jumppoint(x,y,player,0);
        point->link = exit;
        exit->link = point;

        exit->life = point->life;
        exit->animate = point->animate;
        exit->secret = 0;
        if(game_settings.onewayjp==0) {
            exit->hitship = point->hitship;
            exit->hitprojectile = point->hitprojectile;
        }
        playwave (WAV_JUMP);
    } else { /* No exit point, create one */
        point = make_jumppoint(x,y,player,1);
        point->animate = NULL;
        point->hitship = NULL;
        point->hitprojectile = NULL;
        point->life=-1;
        point->secret = 1;
    }
    add_special(point);
}
Example #4
0
/* Open a wormhole between two jumpgates */
static void jumpgate_hitship(struct SpecialObj *gate, struct Ship *ship) {
    if(gate->timer==0 && gate->link) {
        struct SpecialObj *exit = make_jumppoint(gate->link->x,gate->link->y,gate->owner,1);
        struct SpecialObj *entry = make_jumppoint(gate->x,gate->y,gate->owner,0);

        entry->link = exit;
        exit->link = entry;
        if(game_settings.onewayjp) {
            exit->hitship = NULL;
            exit->hitprojectile = NULL;
        }
        gate->timer=exit->life*1.5;
        gate->link->timer=gate->timer;
        add_special(exit);
        add_special(entry);
    }
}
Example #5
0
/* Place level specials at the start of the level */
void prepare_specials (struct LevelSettings * settings) {
    struct dllist *objects=NULL;

    /* Add random objects */
    add_random_gates(level_settings.jumpgates);
    add_random_turrets(level_settings.turrets);

    /* Add manually placed objects */
    if(settings)
        objects=settings->objects;
    while(objects) {
        struct LSB_Object *objdef = objects->data;
        struct SpecialObj *obj=NULL;
        switch(objdef->type) {
            case OBJ_TURRET:
                obj = make_turret(objdef->x,objdef->y,objdef->value);
                break;
            case OBJ_JUMPGATE:
                obj = make_jumpgate(objdef->x,objdef->y);
                obj->owner = objdef->id; /* Store id here temporarily */
                obj->link = (struct SpecialObj*)objdef->link;
                break;
            default: break;
        }
        add_special(obj);
        objects = objects->next;
    }
    /* Pair up the manually placed jumpgates */
    objects = special_list;
    while(objects) {
        struct SpecialObj *obj = objects->data;
        if(obj->gfx == jumpgate_gfx && (int)obj->link<=255) {
            struct dllist *pair = objects->next;
            while(pair) {
                struct SpecialObj *p = pair->data;
                if(p->gfx == jumpgate_gfx && (int)p->link == obj->owner &&
                        p->owner == (int)obj->link)
                {
                    obj->owner = -1;
                    obj->link = p;
                    p->owner = -1;
                    p->link = obj;
                    break;
                }
                pair = pair->next;
            }
            if(pair==NULL) {
                fprintf(stderr,"No pair (%d) found for jumpgate %d\n",
                        (int)obj->link,obj->owner);
                obj->life=0; /* mark the jumpgate for deletion */
            }
        }
        objects = objects->next;
    }
}
Example #6
0
/* Add random turrets to level */
static void add_random_turrets(int count) {
    int r;
    for(r=0;r<count;r++) {
        int x,y,loops=0;
        int type=rand()%3;
        do {
            x = rand()%lev_level.width;
            y = rand()%lev_level.height;
            if(is_free(x,y)) {
                if(find_turret_xy(&x,&y,type==2))
                    break;
            }
        } while(++loops<1000);
        if(loops>=1000) {
            fprintf(stderr,"Warning: Couldn't find place for a turret!\n");
            return;
        }
        add_special(make_turret(x,y,type));
    }
}
Example #7
0
static reach_type_t* add_nominal(reach_t* r, ast_t* type, pass_opt_t* opt)
{
  reach_type_t* t = reach_type(r, type);

  if(t != NULL)
    return t;

  t = add_reach_type(r, type);
  ast_t* def = (ast_t*)ast_data(type);
  t->underlying = ast_id(def);

  AST_GET_CHILDREN(type, pkg, id, typeparams);
  ast_t* typeparam = ast_child(typeparams);

  while(typeparam != NULL)
  {
    add_type(r, typeparam, opt);
    typeparam = ast_sibling(typeparam);
  }

  switch(ast_id(def))
  {
    case TK_INTERFACE:
    case TK_TRAIT:
      add_types_to_trait(r, t, opt);
      break;

    case TK_PRIMITIVE:
      add_traits_to_type(r, t, opt);
      add_special(r, t, type, "_init", opt);
      add_special(r, t, type, "_final", opt);
      break;

    case TK_STRUCT:
    case TK_CLASS:
      add_traits_to_type(r, t, opt);
      add_special(r, t, type, "_final", opt);
      add_fields(r, t, opt);
      break;

    case TK_ACTOR:
      add_traits_to_type(r, t, opt);
      add_special(r, t, type, "_event_notify", opt);
      add_special(r, t, type, "_final", opt);
      add_fields(r, t, opt);
      break;

    default: {}
  }

  if(t->type_id == (uint32_t)-1)
    t->type_id = r->next_type_id++;

  if(ast_id(def) != TK_PRIMITIVE)
    return t;

  if(strcmp(ast_name(pkg), "$0"))
    return t;

  const char* name = ast_name(id);

  if(name[0] == 'I')
  {
    if(!strcmp(name, "I8"))
      t->mangle = "c";
    else if(!strcmp(name, "I16"))
      t->mangle = "s";
    else if(!strcmp(name, "I32"))
      t->mangle = "i";
    else if(!strcmp(name, "I64"))
      t->mangle = "w";
    else if(!strcmp(name, "I128"))
      t->mangle = "q";
    else if(!strcmp(name, "ILong"))
      t->mangle = "l";
    else if(!strcmp(name, "ISize"))
      t->mangle = "z";
  } else if(name[0] == 'U') {
    if(!strcmp(name, "U8"))
      t->mangle = "C";
    else if(!strcmp(name, "U16"))
      t->mangle = "S";
    else if(!strcmp(name, "U32"))
      t->mangle = "I";
    else if(!strcmp(name, "U64"))
      t->mangle = "W";
    else if(!strcmp(name, "U128"))
      t->mangle = "Q";
    else if(!strcmp(name, "ULong"))
      t->mangle = "L";
    else if(!strcmp(name, "USize"))
      t->mangle = "Z";
  } else if(name[0] == 'F') {
    if(!strcmp(name, "F32"))
      t->mangle = "f";
    else if(!strcmp(name, "F64"))
      t->mangle = "d";
  } else if(!strcmp(name, "Bool")) {
    t->mangle = "b";
  }

  return t;
}
Example #8
0
Intent *read_input_devices(void)
{
     static Intent intent;


     intent.force_x = intent.force_y = intent.force_z = 0.0;
     intent.force_rotate = 0.0;
     intent.n_special = 0;

     keyboard_update();
     if (keyboard_keypressed(SCANCODE_CURSORBLOCKLEFT))
	  rotating_ccw = True;
     if (keyboard_keypressed(SCANCODE_CURSORBLOCKRIGHT))
	  rotating_cw = True;
     if (keyboard_keypressed(SCANCODE_CURSORBLOCKUP))
	  moving_forward = True;
     if (keyboard_keypressed(SCANCODE_CURSORBLOCKDOWN))
	  moving_backward= True;
     if (keyboard_keypressed(42) || keyboard_keypressed(54))
	  running= True;
     if (keyboard_keypressed(57))
	  add_special(&intent, INTENT_JUMP);
     if (keyboard_keypressed(56) || keyboard_keypressed(100))
	  strafing= True;

     if (!keyboard_keypressed(SCANCODE_CURSORBLOCKLEFT))
	  rotating_ccw = False;
     if (!keyboard_keypressed( SCANCODE_CURSORBLOCKRIGHT))
	  rotating_cw = False;
     if (!keyboard_keypressed(SCANCODE_CURSORBLOCKUP))
	  moving_forward = False;
     if (!keyboard_keypressed(SCANCODE_CURSORBLOCKDOWN))
	  moving_backward= False;
     if (!keyboard_keypressed(42) && !keyboard_keypressed(54))
	  running= False;
     if (!keyboard_keypressed(56) && !keyboard_keypressed(100))
	  strafing= False;
     if (keyboard_keypressed(SCANCODE_Q))
	  add_special(&intent, INTENT_END_GAME);

     if (rotating_cw) {
	  if (strafing)
	       intent.force_y -= 0.5;
	  else
	       intent.force_rotate -= 0.5;
     }
     if (rotating_ccw) {
	  if (strafing) {
	       intent.force_y += 0.5;
	  } else
	       intent.force_rotate += 0.5;
     }
     if (moving_forward)
	  intent.force_x += 0.5;
     if (moving_backward)
	  intent.force_x -= 0.5;
     if (running) {
	  intent.force_x *= 2.0;
	  intent.force_y *= 2.0;
	  intent.force_z *= 2.0;
	  intent.force_rotate *= 2.0;
     }

     return &intent;
}
Example #9
0
Intent *read_input_devices(void)
{
    static Intent intent;
    int count;
    char buffer[20];
    KeySym key;
    XComposeStatus compose;
    XEvent event;
    int n_events;


    n_events = XEventsQueued(display, QueuedAlready);
    intent.force_x = intent.force_y = intent.force_z = 0.0;
    intent.force_rotate = 0.0;
    intent.n_special = 0;

    while (n_events--) {
        XNextEvent(display, &event);

        if (event.type == KeyPress) {
            count = XLookupString(&event.xkey, buffer, 20, &key, &compose);

            switch (key) {
            case XK_Left:
                rotating_ccw = True;
                break;

            case XK_Right:
                rotating_cw = True;
                break;

            case XK_Up:
                moving_forward = True;
                break;

            case XK_Down:
                moving_backward = True;
                break;

            case XK_Shift_L:
            case XK_Shift_R:
                running = True;
                break;

            case XK_Meta_R:
            case XK_Meta_L:
            case XK_Alt_R:
            case XK_Alt_L:
            case XK_slash:
                strafing = True;
                break;

            case XK_space:
                add_special(&intent, INTENT_JUMP);
                break;

            case XK_q:
                add_special(&intent, INTENT_END_GAME);
                break;

            case XK_1:
                add_special(&intent, INTENT_ACTION1);
                break;

            case XK_2:
                add_special(&intent, INTENT_ACTION2);
                break;

            case XK_3:
                add_special(&intent, INTENT_ACTION3);
                break;

            case XK_4:
                add_special(&intent, INTENT_ACTION4);
                break;

            case XK_5:
                add_special(&intent, INTENT_ACTION5);
                break;

            default:
                break;
            }

        } else if (event.type == KeyRelease) {

            count = XLookupString(&event.xkey, buffer, 20, &key, &compose);

            switch (key) {
            case XK_Left:
                rotating_ccw = False;
                break;

            case XK_Right:
                rotating_cw = False;
                break;

            case XK_Up:
                moving_forward = False;
                break;

            case XK_Down:
                moving_backward = False;
                break;

            case XK_Shift_L:
            case XK_Shift_R:
                running = False;
                break;

            case XK_Meta_R:
            case XK_Meta_L:
            case XK_Alt_R:
            case XK_Alt_L:
            case XK_slash:
                strafing = False;
                break;

            default:
                break;
            }

        }
    }

    if (rotating_cw) {
        if (strafing)
            intent.force_y -= MOVE_FORCE;
        else
            intent.force_rotate -= TURN_FORCE;
    }
    if (rotating_ccw) {
        if (strafing) {
            intent.force_y += MOVE_FORCE;
        } else
            intent.force_rotate += TURN_FORCE;
    }
    if (moving_forward)
        intent.force_x += MOVE_FORCE;
    if (moving_backward)
        intent.force_x -= MOVE_FORCE;
    if (running) {
        intent.force_x *= 2.0;
        intent.force_y *= 2.0;
        intent.force_z *= 2.0;
        intent.force_rotate *= 2.0;
    }

    return &intent;
}