Ejemplo n.º 1
0
local void Cvars(const char *cmd, const char *params, Player *p, const Target *target)
{
	PData *pdata = PPDATA(p, pdata_key);
	LinkedList list;

	LLInit(&list);

	HashEnum(pdata->vars, enum_vars, &list);

	if (LLGetHead(&list) != NULL)
	{
		Link *link;
		StringBuffer sb;
		SBInit(&sb);

		chat->SendMessage(p, "Variables:");

		for (link = LLGetHead(&list); link; link = link->next)
		{
			SBPrintf(&sb, ", %s", (const char*)link->data);
		}
		chat->SendWrappedText(p, SBText(&sb, 2));
		SBDestroy(&sb);

		LLEmpty(&list);
	}
	else
	{
		chat->SendMessage(p, "No Variables.");
	}
}
Ejemplo n.º 2
0
//Misc/Utilities
local int getNumberOfAwers(Player *p)
{
    LinkedList awers;
    int numAwers = 0;

    LLInit(&awers);

    game->IsAntiwarped(p, &awers);
    numAwers = LLCount(&awers);

    LLEmpty(&awers);

    return numAwers;
}
Ejemplo n.º 3
0
void UserMain( void * pd )
{

    initWithWeb();
    Nunchuck_Init(); // FIXME
    LLInit(1);
    TheWSHandler = MyDoWSUpgrade;

    stepper.Init();
    ConfigureStepper( &stepper, 1 );
    stepSpeed = 100;
    stepDir = 1;
    StartStepper( 1, stepDir, stepSpeed );
    stepForever = true;
    OSSemInit( &SockReadySem, 0 );
    OSCritInit( &I2CLock );

    iprintf("Application: %s\r\nNNDK Revision: %s\r\n",AppName,GetReleaseTag());
    OSTimeDly(2);
    OSSimpleTaskCreate(ReportTask, 5);
    OSSimpleTaskCreate(InputTask, MAIN_PRIO-1);
    OSSimpleTaskCreate(RangingTask, 2);

    EnableEncoder(EncodeStep, ButtonChange, ButtonDoubleClick );

    ClearTaskTimes();
    SMPoolPtr pp;

    while(1) {
        fd_set error_fds;
        FD_ZERO( &error_fds );
        OSCritEnter( &I2CLock, 0 );
        nun.Update();
        OSCritLeave( &I2CLock );

        serv_x.SetPos(nun.stick.x);
        serv_y.SetPos(nun.stick.y);

//        iprintf("%lu\na_x: %4.4d - a_y: %4.4d - a_z: %4.4d\ns_x: %3.3d - s_y: %3.3d - b_z: %d - b_c: %d\n\n",
//            TimeTick, nun.accel.x, nun.accel.y, nun.accel.z,
//            nun.stick.x, nun.stick.y,
//            nun.button.z, nun.button.c);
//        iprintf("range: %u\n", lidarRange);
            if (ws_fd > 0){
                SendConfigReport(ws_fd);
            }

    }
}
Ejemplo n.º 4
0
static void Combine(LinkedList* l1, LinkedList* l2, int (*comparator)(void* left, void* right))
{
  LinkedList* ret = NULL;
  LLInit(&ret);
  Node* p1 = l1->head;
  Node* p2 = l2->head;
  while ( p1 && p2 )
  {
    int cres = (*comparator)(p1->data, p2->data);
    if ( cres < 0 )
    {
      LLInsert(ret, p1->data);
      p1 = p1->next;
    }
    else if ( !cres )
    {
      LLInsert(ret, p1->data);
      LLInsert(ret, p2->data);
      p1 = p1->next;
      p2 = p2->next;
    } 
    else
    {
      LLInsert(ret, p2->data);
      p2 = p2->next;
    }
  }
  while ( p1 )
  {
      LLInsert(ret, p1->data);
      p1 = p1->next;
  }
  while ( p2 )
  {
      LLInsert(ret, p2->data);
      p2 = p2->next;
  }
  LLCopy(l1, ret);
  LLDestroy(ret);
}
Ejemplo n.º 5
0
local void postReward(Arena *arena, TurfArena *ta)
{
	TurfStats *ts, **p_ts = P_ARENA_DATA(arena, tskey);
	Link *l = NULL;
	TurfStatsData *tsd;

	if (!arena || !*p_ts) return; else ts = *p_ts;

	LOCK_STATUS(arena);

	if (ts->numStats >= ts->maxHistory)
	{
		/* we already have the maximum # of histories
		 * erase oldest history (end of linked list) */
		Link *nextL = NULL;
		TurfStatsData *data;

		for(nextL = LLGetHead(&ts->stats) ; nextL ; nextL=nextL->next)
		{
			l = nextL;
		}

		l = LLGetHead(&ts->stats);  /* l now points to the end of the LinkedList */
		data = l->data;
		LLRemove(&ts->stats, data); /* remove the link */
		ts->numStats--;
	}

	/* create new node for stats data, add it to the linked list, and fill in data */
	tsd = amalloc(sizeof(TurfStatsData));
	LLAddFirst(&ts->stats, tsd);
	ts->numStats++;

	tsd->numFlags       = ta->numFlags;
	tsd->numPlayers     = ta->numPlayers;
	tsd->numTeams       = ta->numTeams;
	tsd->numWeights     = ta->numWeights;
	tsd->numPoints      = ta->numPoints;
	tsd->sumPerCapitaFlags   = ta->sumPerCapitaFlags;
	tsd->sumPerCapitaWeights = ta->sumPerCapitaWeights;

	tsd->tags       = ta->tags;
	tsd->steals     = ta->steals;
	tsd->lost       = ta->lost;
	tsd->recoveries = ta->recoveries;

	/* copy teams data */
	LLInit(&tsd->teams);
	for(l = LLGetHead(&ta->teams) ; l ; l=l->next)
	{
		TurfTeam *src = l->data;
		TurfTeam *dst = amalloc(sizeof(TurfTeam));

		*dst = *src;

		LLAdd(&tsd->teams, dst);
	}

	ts->dingCount++;
	if (ts->dingCount >= ts->statsOnDing)
		ADisplay(arena, 0);  /* output for the history we just copied */

	UNLOCK_STATUS(arena);
}
Ejemplo n.º 6
0
local void arenaAction(Arena *arena, int action)
{
	TurfStats *ts, **p_ts = P_ARENA_DATA(arena, tskey);

	if (action == AA_PRECREATE)
	{
		pthread_mutexattr_t attr;

		pthread_mutexattr_init(&attr);
		pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
		pthread_mutex_init((pthread_mutex_t*)P_ARENA_DATA(arena, mtxkey), &attr);
		pthread_mutexattr_destroy(&attr);
	}
	else if (action == AA_PRECREATE)
	{
		ts = amalloc(sizeof(TurfStats));
		*p_ts = ts;
	}

	ts = *p_ts;
	LOCK_STATUS(arena);

	if (action == AA_CREATE)
	{
		ConfigHandle c = arena->cfg;
		ts->maxHistory = config->GetInt(c, "TurfStats", "MaxHistory", 0);
		if (ts->maxHistory<0)
			ts->maxHistory = 0;
		ts->statsOnDing = config->GetInt(c, "TurfStats", "StatsOnDing", 1);
		if (ts->statsOnDing<1)
			ts->statsOnDing=1;

		ts->dingCount = 0;
		ts->numStats = 0;
		LLInit(&ts->stats); /* initalize list of stats */
	}
	else if (action == AA_DESTROY)
	{
		/* free history array */
		clearHistory(arena);

		/* might as well, just in case to be safe */
		ts->numStats = 0;
		ts->dingCount = 0;
	}
	else if (action == AA_CONFCHANGED)
	{
		int newMaxHistory;
		ConfigHandle c = arena->cfg;

		ts->statsOnDing = config->GetInt(c, "TurfStats", "StatsOnDing", 1);
		if (ts->statsOnDing<1)
			ts->statsOnDing=1;

		newMaxHistory = config->GetInt(c, "TurfStats", "MaxHistory", 0);
		if (newMaxHistory < 0)
			newMaxHistory = 0;  /* max history must be >= 0 */
		if (newMaxHistory != ts->maxHistory)
		{
			ts->maxHistory = newMaxHistory;

			/* erase history */
			clearHistory(arena);
		}
	}

	UNLOCK_STATUS(arena);

	if (action == AA_DESTROY)
	{
		afree(ts);
	}
	else if (action == AA_POSTDESTROY)
	{
		pthread_mutex_destroy((pthread_mutex_t*)P_ARENA_DATA(arena, mtxkey));
	}
}