1 | /* |
1 | /* |
2 | * static char *rcsid_c_object_c = |
2 | * static char *rcsid_c_object_c = |
3 | * "$Id: c_object.c,v 1.1.1.2 2006/02/22 18:03:20 elmex Exp $"; |
3 | * "$Id: c_object.c,v 1.1.1.3 2006/03/15 14:05:35 elmex Exp $"; |
4 | */ |
4 | */ |
5 | /* |
5 | /* |
6 | CrossFire, A Multiplayer game for X-windows |
6 | CrossFire, A Multiplayer game for X-windows |
7 | |
7 | |
8 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
8 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
… | |
… | |
52 | }\ |
52 | }\ |
53 | last->next=NULL;\ |
53 | last->next=NULL;\ |
54 | last->ob=(NEW);\ |
54 | last->ob=(NEW);\ |
55 | last->id=(COUNT); |
55 | last->id=(COUNT); |
56 | |
56 | |
|
|
57 | /** |
57 | /* Search the inventory of 'pl' for what matches best with params. |
58 | * Search the inventory of 'pl' for what matches best with params. |
58 | * we use item_matched_string above - this gives us consistent behaviour |
59 | * we use item_matched_string above - this gives us consistent behaviour |
59 | * between many commands. Return the best match, or NULL if no match. |
60 | * between many commands. Return the best match, or NULL if no match. |
|
|
61 | * aflag is used with apply -u , and apply -a to |
|
|
62 | * only unapply applied, or apply unapplied objects |
60 | */ |
63 | **/ |
61 | object *find_best_object_match(object *pl, const char *params) |
64 | static object *find_best_apply_object_match(object *pl, const char *params, enum apply_flag aflag) |
62 | { |
65 | { |
63 | object *tmp, *best=NULL; |
66 | object *tmp, *best=NULL; |
64 | int match_val=0,tmpmatch; |
67 | int match_val=0,tmpmatch; |
65 | |
68 | |
66 | for (tmp=pl->inv; tmp; tmp=tmp->below) { |
69 | for (tmp=pl->inv; tmp; tmp=tmp->below) { |
67 | if (tmp->invisible) continue; |
70 | if (tmp->invisible) continue; |
68 | if ((tmpmatch=item_matched_string(pl, tmp, params))>match_val) { |
71 | if ((tmpmatch=item_matched_string(pl, tmp, params))>match_val) { |
|
|
72 | if ((aflag==AP_APPLY) && (QUERY_FLAG(tmp,FLAG_APPLIED))) continue; |
|
|
73 | if ((aflag==AP_UNAPPLY) && (!QUERY_FLAG(tmp,FLAG_APPLIED))) continue; |
69 | match_val=tmpmatch; |
74 | match_val=tmpmatch; |
70 | best=tmp; |
75 | best=tmp; |
71 | } |
76 | } |
72 | } |
77 | } |
73 | return best; |
78 | return best; |
74 | } |
79 | } |
75 | /* Simlilar to find_best_object_match , but accepts an |
80 | |
76 | * additional parameter for apply -u , and apply -a to |
81 | /** |
77 | * only unapply applied , or apply unapplied objects |
82 | * Shortcut to find_best_apply_object_match(pl, params, AF_NULL); |
78 | */ |
83 | **/ |
79 | static object *find_best_apply_object_match(object *pl, char *params, enum apply_flag aflag) |
84 | object *find_best_object_match(object *pl, const char *params) |
80 | { |
85 | { |
81 | object *tmp, *best=NULL; |
86 | return find_best_apply_object_match(pl, params, AP_NULL); |
82 | int match_val=0,tmpmatch; |
|
|
83 | |
|
|
84 | for (tmp=pl->inv; tmp; tmp=tmp->below) { |
|
|
85 | if (tmp->invisible) continue; |
|
|
86 | if ((tmpmatch=item_matched_string(pl, tmp, params))>match_val) { |
|
|
87 | if ((aflag==AP_APPLY) && (QUERY_FLAG(tmp,FLAG_APPLIED))) continue; |
|
|
88 | if ((aflag==AP_UNAPPLY) && (!QUERY_FLAG(tmp,FLAG_APPLIED))) continue; |
|
|
89 | match_val=tmpmatch; |
|
|
90 | best=tmp; |
|
|
91 | } |
|
|
92 | } |
|
|
93 | return best; |
|
|
94 | } |
87 | } |
95 | |
88 | |
96 | /* |
89 | /* |
97 | * Notes about item creation: |
90 | * Notes about item creation: |
98 | * 1) It is similar in syntax to the dm create command. |
91 | * 1) It is similar in syntax to the dm create command. |