File: cmdscore.c

package info (click to toggle)
xshipwars 1.32-5
  • links: PTS
  • area: main
  • in suites: potato
  • size: 17,176 kB
  • ctags: 6,357
  • sloc: ansic: 157,152; makefile: 226; sh: 75
file content (70 lines) | stat: -rw-r--r-- 1,751 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "swserv.h"


/*
 *      Prints object's score.
 */
int CmdScore(int condescriptor, char *arg)
{
        long object_num;
        char name[XSW_OBJ_NAME_MAX];
        char sndbuf[CS_DATA_MAX_LEN]; 
	xsw_object_struct *obj_ptr;


        /* Copy arg to name. */
        strncpy(name, arg, XSW_OBJ_NAME_MAX);
        name[XSW_OBJ_NAME_MAX - 1] = '\0';   
        StringStripSpaces(name);


        /* If no argument, assume connection's object. */
        if(name[0] == '\0')
            object_num = connection[condescriptor]->object_num;
	else if(!strcmp(name, "me"))
	    object_num = connection[condescriptor]->object_num;
        else
            object_num = MatchObjectByName(name, -1);


        /* Make sure object_num is valid. */
        if(DBIsObjectGarbage(object_num))   
        {
            sprintf(sndbuf, "%s: No such object.", name);
            NetSendLiveMessage(condescriptor, sndbuf);

            return(-1);
        }
	else
	{
	    obj_ptr = xsw_object[object_num];
	}

	strncpy(name, obj_ptr->name, XSW_OBJ_NAME_MAX);
	name[XSW_OBJ_NAME_MAX - 1] = '\0';


        /* Does object have scores? */
        if(obj_ptr->score == NULL)
        {
            sprintf(sndbuf, "%s: No scores.", name);
        }
	else
	{
            sprintf(sndbuf,
 "%s: Credits: %.2lf  RMU: %.2lf(%.2lf)  DmgGiv: %.2lf  DmgRec: %.2lf\
  Kills: %ld",
                DBGetFormalNameStr(object_num),
                obj_ptr->score->credits,
                obj_ptr->score->rmu,
                obj_ptr->score->rmu_max,
                obj_ptr->score->damage_given,
                obj_ptr->score->damage_recieved,
                obj_ptr->score->kills
            );
	}
        NetSendLiveMessage(condescriptor, sndbuf);


        return(0);
}